Panel.hh
5.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/*
* Panel.hh
*
* Created on: 28 oct. 2013
* Author: CS
*/
#ifndef PANEL_HH_
#define PANEL_HH_
#include <string>
#include "Bounds.hh"
#include "Font.hh"
#include "Color.hh"
#include "PlotCommon.hh"
#include <boost/shared_ptr.hpp>
#include <memory>
#include <map>
#include "plplot/plstream.h"
#include "Axis.hh"
#include "ColorAxis.hh"
#include "TextPlot.hh"
#include "CurvePlot.hh"
#include "FillSerieConstant.hh"
#include "FillSerieSerie.hh"
#include "ParamsLegendProperties.hh"
#include "TextLegendProperties.hh"
#include "Layout.hh"
#include "ContextFileWriter.hh"
namespace plot {
class Page;
class DefaultPlotConfiguration;
typedef std::map<std::string, boost::shared_ptr<Axis>> Axes;
typedef std::list<boost::shared_ptr<TextPlot>> TextPlots;
typedef std::list<boost::shared_ptr<CurvePlot>> CurvePlots;
typedef std::list<boost::shared_ptr<FillSerieConstant>> FillSerieConstants;
typedef std::list<boost::shared_ptr<FillSerieSerie>> FillSerieSeries;
typedef std::list<boost::shared_ptr<TextLegendProperties>> TextLegendPropertiesList;
/**
* @brief A panel is a part of Page and owns a plot (and eventually
* its decorator).
*/
class Panel {
public:
/**
* @brief Counter for panel unique id
*/
static int PANEL_COUNTER;
/**
* @brief Transform coordinate from AMDA page to Plplot page.
* !!!! WARNING !!!! This function modify the current plPlot font
*/
Bounds getBoundsInPlPage();
Panel();
Panel(DefaultPlotConfiguration& defaults);
Panel(Page* page);
virtual ~Panel();
/**
* @brief Draws panel.
*/
void draw(std::shared_ptr<plstream>& pls);
/**
* @brief Write panel context
*/
void writeContext(std::shared_ptr<plstream>& pls, ContextFileWriter& writer);
/**
* @brief Adds axis to panel, depends on plot type.
*/
void addAxis(const std::string& pAxisId, boost::shared_ptr<Axis> pAxis) {
_axes[pAxisId] = pAxis; }
/**
* @brief Gets Axis from id, new axis is created if not found.
*/
boost::shared_ptr<Axis> getAxis(const std::string& pAxisId) { return _axes[pAxisId]; }
/**
* @brief Adds color axis to panel
*/
void addColorAxis(const std::string& pAxisId, boost::shared_ptr<ColorAxis> pColorAxis) {
_colorAxis = pColorAxis;
_axes[pAxisId] = pColorAxis;
}
const Font& getFont() const {
return _font;
}
void setFont(const Font& font) {
_font = font;
}
Label* getTitle() {
return &_title;
}
void setTitleText(const char* text) {
_title._text = text;
}
Font getTitleFont() ;
/**
* @brief Reset for next time interval plot
*/
void resetPlot() {
for (auto axe : _axes)
{
if (axe.second != nullptr)
axe.second->resetPlot();
}
_paramsLegendProperties.resetPlot();
for (auto legend : _textLegendPropertiesList)
legend->resetPlot();
for (auto text : _textPlots)
text->resetPlot();
for (auto curve : _curvePlots)
curve->resetPlot();
_drawn = false;
}
/**
* @brief Gets color axis
*/
boost::shared_ptr<ColorAxis> getColorAxis(void) { return _colorAxis; }
/**
* @brief Panel unique identifier
*/
int _id;
/**
* @brief Panel index
*/
int _index;
/**
* @brief Number of points per plot
*/
int _resolution;
/**
* @brief Flag to know if the title must be updated during the next interval plot
*/
bool _updateTitleOnNextInterval;
/**
* @brief Panel position and size.
*/
Bounds _bounds;
/**
* @brief Background color
*/
Color _backgroundColor;
/**
* @brief Panel title Align (center, left, right)
*/
PlotCommon::Align _titleAlign;
/**
* @brief Panel title Position (top, bottom)
*/
PlotCommon::Position _titlePosition;
/**
* @brief _drawn Define if panel is already drawn (true) or not (false).
*/
bool _drawn;
/**
* @brief Page container
*/
Page* _page;
/**
* @brief List of axis.
*/
Axes _axes;
/**
* @brief List of axis.
*/
boost::shared_ptr<ColorAxis> _colorAxis;
/**
* @brief Prefered panel width and height.
* @note Number set is in unit of panel character width or height.
*/
double _preferedWidth;
double _preferedHeight;
/**
* @brief Space between border of panel and border of plot area.
* @note Number set is in unit of panel character height.
*/
int _leftMargin;
int _rightMargin;
int _topMargin;
int _bottomMargin;
/**
* @brief List of textplots.
*/
TextPlots _textPlots;
/**
* @brief List of curveplots.
*/
CurvePlots _curvePlots;
/**
* @brief List of FillSerieConstant.
*/
FillSerieConstants _fillSerieConstants;
/**
* @brief List of FillSerieSerie.
*/
FillSerieSeries _fillSerieSeries;
/**
* @brief Parameter legend properties
*/
ParamsLegendProperties _paramsLegendProperties;
/**
* @brief Text legend properties list
*/
TextLegendPropertiesList _textLegendPropertiesList;
void drawEmptyPanel(std::shared_ptr<plstream>& pls);
void drawNoData(std::shared_ptr<plstream>& pls);
void reserveSpaceForTitle(double& top, double& bottom, double& titleHeight);
private:
/**
* @brief Panel font, may be different from page font
*/
Font _font;
/**
* @brief Panel title, may be empty
*/
Label _title;
void fillBackground(std::shared_ptr<plstream>& pls);
void drawTitle(std::shared_ptr<plstream>& pls);
void drawMessage(std::shared_ptr<plstream>& pls, std::string& message);
};
std::ostream& operator <<(std::ostream& out, Panel& panel);
} /* namespace plot */
#endif /* PANEL_HH_ */