Blame view

src/ParamOutputImpl/Plot/Panel.hh 5.29 KB
fbe3c2bb   Benjamin Renard   First commit
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
/*
 * 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"
8499fbdd   Benjamin Renard   Context file gene...
29
#include "ContextFileWriter.hh"
fbe3c2bb   Benjamin Renard   First commit
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

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:
fbe3c2bb   Benjamin Renard   First commit
49
50
51
52
53
54
55
	/**
	 * @brief Counter for panel unique id
	 */
	static int PANEL_COUNTER;

	/**
	 * @brief Transform coordinate from AMDA page to Plplot page.
f6eaec4e   Benjamin Renard   Optimize plot ele...
56
	 * !!!! WARNING !!!! This function modify the current plPlot font
fbe3c2bb   Benjamin Renard   First commit
57
	 */
f6eaec4e   Benjamin Renard   Optimize plot ele...
58
	Bounds getBoundsInPlPage();
fbe3c2bb   Benjamin Renard   First commit
59
60
61
62
63
64
65
66
67
68
69
70

	Panel();
	Panel(DefaultPlotConfiguration& defaults);
	Panel(Page* page);
	virtual ~Panel();

	/**
	 * @brief Draws panel.
	 */
	void draw(std::shared_ptr<plstream>& pls);

	/**
8499fbdd   Benjamin Renard   Context file gene...
71
72
73
74
75
	 * @brief Write panel context
	 */
	void writeContext(std::shared_ptr<plstream>& pls, ContextFileWriter& writer);

	/**
fbe3c2bb   Benjamin Renard   First commit
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
	 * @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;
	}

f6eaec4e   Benjamin Renard   Optimize plot ele...
94
95
96
97
98
99
100
101
	const Font& getFont() const {
		return _font;
	}

	void setFont(const Font& font) {
		_font = font;
	}

f6eaec4e   Benjamin Renard   Optimize plot ele...
102
103
104
105
106
107
108
109
110
111
	Label* getTitle() {
		return &_title;
	}

	void setTitleText(const char* text) {
		_title._text = text;
	}

	Font getTitleFont() ;

fbe3c2bb   Benjamin Renard   First commit
112
113
114
	/**
	 * @brief Reset for next time interval plot
	 */
20fef3b6   Benjamin Renard   Fix reset functio...
115
	void resetPlot() {
fbe3c2bb   Benjamin Renard   First commit
116
117
118
		for (auto axe : _axes)
		{
			if (axe.second != nullptr)
20fef3b6   Benjamin Renard   Fix reset functio...
119
				axe.second->resetPlot();
fbe3c2bb   Benjamin Renard   First commit
120
		}
20fef3b6   Benjamin Renard   Fix reset functio...
121
		_paramsLegendProperties.resetPlot();
fbe3c2bb   Benjamin Renard   First commit
122
		for (auto legend : _textLegendPropertiesList)
20fef3b6   Benjamin Renard   Fix reset functio...
123
			legend->resetPlot();
fbe3c2bb   Benjamin Renard   First commit
124
		for (auto text : _textPlots)
20fef3b6   Benjamin Renard   Fix reset functio...
125
			text->resetPlot();
fbe3c2bb   Benjamin Renard   First commit
126
		for (auto curve : _curvePlots)
20fef3b6   Benjamin Renard   Fix reset functio...
127
			curve->resetPlot();
fbe3c2bb   Benjamin Renard   First commit
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
		_drawn = false;
	}

	/**
	 * @brief Gets color axis
	 */
	boost::shared_ptr<ColorAxis> getColorAxis(void) { return _colorAxis; }


	/**
	 * @brief Panel unique identifier
	 */
	int _id;

	/**
99a73aaf   Benjamin Renard   Add panel index s...
143
144
145
146
147
	 * @brief Panel index
	 */
	int _index;

	/**
fbe3c2bb   Benjamin Renard   First commit
148
149
150
151
152
	 * @brief Number of points per plot
	 */
	int _resolution;

	/**
fbe3c2bb   Benjamin Renard   First commit
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
	 * @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;


b96aa975   Benjamin Renard   Draw border aroun...
245
246
	void drawEmptyPanel(std::shared_ptr<plstream>& pls);

d57f00dc   Benjamin Renard   Draw NO DATA
247
248
	void drawNoData(std::shared_ptr<plstream>& pls);

f6eaec4e   Benjamin Renard   Optimize plot ele...
249
	void reserveSpaceForTitle(double& top, double& bottom, double& titleHeight);
fbe3c2bb   Benjamin Renard   First commit
250

f6eaec4e   Benjamin Renard   Optimize plot ele...
251
252
253
254
255
private:
	/**
	 * @brief Panel font, may be different from page font
	 */
	Font _font;
fbe3c2bb   Benjamin Renard   First commit
256
257

	/**
f6eaec4e   Benjamin Renard   Optimize plot ele...
258
	 * @brief Panel title, may be empty
fbe3c2bb   Benjamin Renard   First commit
259
	 */
f6eaec4e   Benjamin Renard   Optimize plot ele...
260
261
	Label _title;

fbe3c2bb   Benjamin Renard   First commit
262

f6eaec4e   Benjamin Renard   Optimize plot ele...
263
	void fillBackground(std::shared_ptr<plstream>& pls);
fbe3c2bb   Benjamin Renard   First commit
264

f6eaec4e   Benjamin Renard   Optimize plot ele...
265
	void drawTitle(std::shared_ptr<plstream>& pls);
d57f00dc   Benjamin Renard   Draw NO DATA
266
267

	void drawMessage(std::shared_ptr<plstream>& pls, std::string& message);
fbe3c2bb   Benjamin Renard   First commit
268
269
270
271
272
273
};

std::ostream& operator <<(std::ostream& out, Panel& panel);

} /* namespace plot */
#endif /* PANEL_HH_ */