-
Notifications
You must be signed in to change notification settings - Fork 305
/
PlotWindow.h
368 lines (352 loc) · 12 KB
/
PlotWindow.h
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
//! @file plotwindow.h
//! @author harka011
//! @date 2011-02-03
//! @brief Tool drawing 2D plot graph, supports .plt .mat .csv and plot plotParametric plotAll
#ifndef PLOTWINDOW_H
#define PLOTWINDOW_H
#include <QtGlobal>
#include <QMainWindow>
#include <QCheckBox>
#include <QComboBox>
#include <QToolButton>
#include <QLabel>
#include <QFile>
#include <QMdiSubWindow>
#include <QGroupBox>
#include <QPushButton>
#include <QListWidget>
#include <QDoubleSpinBox>
#include <QDialog>
#include <QStackedWidget>
#include <QDialogButtonBox>
#include <qwt_plot.h>
#include <qwt_text.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_picker.h>
#include <qwt_scale_draw.h>
#include <qwt_picker_machine.h>
#include <qwt_plot_grid.h>
#include <qwt_curve_fitter.h>
#include <qwt_legend.h>
#include <qwt_plot_zoomer.h>
#include <qwt_plot_panner.h>
#include <qwt_scale_engine.h>
#if QWT_VERSION >= 0x060000
#include <qwt_compat.h>
#endif
#include <stdexcept>
#include "util/read_matlab4.h"
#include "util/read_csv.h"
#include "OMPlot.h"
namespace OMPlot
{
class Plot;
class PlotCurve;
class PlotWindow : public QMainWindow
{
Q_OBJECT
public:
enum PlotType {PLOT, PLOTALL, PLOTPARAMETRIC, PLOTINTERACTIVE, PLOTARRAY, PLOTARRAYPARAMETRIC};
private:
Plot *mpPlot;
QCheckBox *mpLogXCheckBox;
QCheckBox *mpLogYCheckBox;
QComboBox *mpGridComboBox;
QToolButton *mpAutoScaleButton;
QToolButton *mpSetupButton;
QToolButton *mpStartSimulationToolButton;
QToolButton *mpPauseSimulationToolButton;
QLabel *mpSimulationSpeedLabel;
QComboBox *mpSimulationSpeedComboBox;
QTextStream *mpTextStream;
QFile mFile;
QStringList mVariablesList;
PlotType mPlotType;
QString mGridType;
QString mXLabel;
QString mYLabel;
QString mXCustomLabel;
QString mYCustomLabel;
QString mXUnit;
QString mXDisplayUnit;
QString mYUnit;
QString mYDisplayUnit;
QString mTimeUnit;
QString mXRangeMin;
QString mXRangeMax;
QString mYRangeMin;
QString mYRangeMax;
double mCurveWidth;
int mCurveStyle;
QFont mLegendFont;
double mTime;
bool mIsInteractiveSimulation;
QString mInteractiveTreeItemOwner;
int mInteractivePort;
QwtSeriesData<QPointF>* mpInteractiveData;
QString mInteractiveModelName;
bool mPrefixUnits;
QMdiSubWindow *mpSubWindow;
public:
PlotWindow(QStringList arguments = QStringList(), QWidget *parent = 0, bool isInteractiveSimulation = false);
~PlotWindow();
void setUpWidget();
void initializePlot(QStringList arguments);
void setVariablesList(QStringList variables);
void setPlotType(PlotType type);
bool isPlot() const {return mPlotType == PlotWindow::PLOT;}
bool isPlotAll() const {return mPlotType == PlotWindow::PLOTALL;}
bool isPlotParametric() const {return mPlotType == PlotWindow::PLOTPARAMETRIC;}
bool isPlotInteractive() const {return mPlotType == PlotWindow::PLOTINTERACTIVE;}
bool isPlotArray() const {return mPlotType == PlotWindow::PLOTARRAY;}
bool isPlotArrayParametric() const {return mPlotType == PlotWindow::PLOTARRAYPARAMETRIC;}
PlotType getPlotType() const {return mPlotType;}
void initializeFile(QString file);
void getStartStopTime(double &start, double &stop);
void setupToolbar();
void plot(PlotCurve *pPlotCurve = 0);
void plotParametric(PlotCurve *pPlotCurve = 0);
void plotArray(double time, PlotCurve *pPlotCurve = 0);
void plotArrayParametric(double time, PlotCurve *pPlotCurve = 0);
QPair<QVector<double>*, QVector<double>*> plotInteractive(PlotCurve *pPlotCurve = 0);
void setInteractiveOwner(const QString &interactiveTreeItemOwner);
void setInteractivePort(const int port);
void setInteractivePlotData(QwtSeriesData<QPointF>* pInteractiveData);
void setSubWindow(QMdiSubWindow *pSubWindow) {mpSubWindow = pSubWindow;}
QMdiSubWindow* getSubWindow() {return mpSubWindow;}
void setInteractiveModelName(const QString &modelName);
QString getInteractiveOwner() {return mInteractiveTreeItemOwner;}
int getInteractivePort() {return mInteractivePort;}
void setTitle(QString title);
void setGrid(QString grid);
QString getGrid();
QCheckBox* getLogXCheckBox();
QCheckBox* getLogYCheckBox();
QToolButton* getAutoScaleButton() {return mpAutoScaleButton;}
QToolButton* getStartSimulationButton() {return mpStartSimulationToolButton;}
QToolButton* getPauseSimulationButton() {return mpPauseSimulationToolButton;}
QComboBox* getSimulationSpeedBox() {return mpSimulationSpeedComboBox;}
void setXLabel(const QString &label) {mXLabel = label;}
QString getXLabel() const {return mXLabel;}
void setYLabel(const QString &label) {mYLabel = label;}
QString getYLabel() const {return mYLabel;}
void setXCustomLabel(const QString &label) {mXCustomLabel = label;}
QString getXCustomLabel() const {return mXCustomLabel;}
void setYCustomLabel(const QString &label) {mYCustomLabel = label;}
QString getYCustomLabel() const {return mYCustomLabel;}
void setXUnit(QString xUnit) {mXUnit = xUnit;}
QString getXUnit() {return mXUnit;}
void setXDisplayUnit(QString xDisplayUnit) {mXDisplayUnit = xDisplayUnit;}
QString getXDisplayUnit() {return mXDisplayUnit;}
void setYUnit(QString yUnit) {mYUnit = yUnit;}
QString getYUnit() {return mYUnit;}
void setYDisplayUnit(QString yDisplayUnit) {mYDisplayUnit = yDisplayUnit;}
QString getYDisplayUnit() {return mYDisplayUnit;}
void setTimeUnit(QString timeUnit) {mTimeUnit = timeUnit;}
QString getTimeUnit() {return mTimeUnit;}
void setXRange(double min, double max);
QString getXRangeMin();
QString getXRangeMax();
void setYRange(double min, double max);
QString getYRangeMin();
QString getYRangeMax();
void setCurveWidth(double width);
double getCurveWidth();
void setCurveStyle(int style);
int getCurveStyle();
void setLegendFont(QFont font);
QFont getLegendFont();
void setLegendPosition(QString position);
QString getLegendPosition();
void setFooter(QString footer);
QString getFooter();
bool getPrefixUnits() const;
void setPrefixUnits(bool prefixUnits);
void checkForErrors(QStringList variables, QStringList variablesPlotted);
Plot* getPlot();
void receiveMessage(QStringList arguments);
void closeEvent(QCloseEvent *event);
void setTime(double time){mTime = time;}
double getTime() {return mTime;}
void updateTimeText();
void updatePlot();
private:
void setInteractiveControls(bool enabled);
signals:
void closingDown();
private slots:
void fitInView();
public slots:
void updateCurves();
void updateYAxis(QPair<double, double> minMaxValues);
void enableZoomMode(bool on);
void enablePanMode(bool on);
void exportDocument();
void printPlot();
void setGrid(int index);
void setLogX(bool on);
void setLogY(bool on);
void setAutoScale(bool on);
bool toggleSign(PlotCurve *pPlotCurve, bool checked);
void showSetupDialog();
void showSetupDialog(QString variable);
void interactiveSimulationStarted();
void interactiveSimulationPaused();
};
//Exception classes
class PlotException : public std::runtime_error
{
public:
PlotException(const char *e) : std::runtime_error(e) {}
PlotException(const QString str) : std::runtime_error(str.toStdString().c_str()) {}
};
class NoFileException : public PlotException
{
public:
NoFileException(const char *fileName) : PlotException(fileName) {}
};
class NoVariableException : public PlotException
{
public:
NoVariableException(const char *varName) : PlotException(varName) {}
};
class SetupDialog;
class VariablePageWidget : public QWidget
{
Q_OBJECT
private:
PlotCurve *mpPlotCurve;
QGroupBox *mpGeneralGroupBox;
QLabel *mpLegendLabel;
QLineEdit *mpLegendTextBox;
QPushButton *mpResetLabelButton;
QLabel *mpFileLabel;
QLabel *mpFileTextBox;
QGroupBox *mpAppearanceGroupBox;
QLabel *mpColorLabel;
QPushButton *mpPickColorButton;
QColor mCurveColor;
QCheckBox *mpAutomaticColorCheckBox;
QLabel *mpPatternLabel;
QComboBox *mpPatternComboBox;
QLabel *mpThicknessLabel;
QDoubleSpinBox *mpThicknessSpinBox;
QCheckBox *mpHideCheckBox;
QCheckBox *mpToggleSignCheckBox;
public:
VariablePageWidget(PlotCurve *pPlotCurve, SetupDialog *pSetupDialog);
void setCurvePickColorButtonIcon();
PlotCurve* getPlotCurve() {return mpPlotCurve;}
QLineEdit* getLegendTextBox() {return mpLegendTextBox;}
void setCurveColor(QColor color) {mCurveColor = color;}
QColor getCurveColor() {return mCurveColor;}
QCheckBox* getAutomaticColorCheckBox() {return mpAutomaticColorCheckBox;}
QComboBox* getPatternComboBox() {return mpPatternComboBox;}
QDoubleSpinBox* getThicknessSpinBox() {return mpThicknessSpinBox;}
QCheckBox* getHideCheckBox() {return mpHideCheckBox;}
QCheckBox* getToggleSignCheckBox() const {return mpToggleSignCheckBox;}
public slots:
void resetLabel();
void pickColor();
};
class SetupDialog : public QDialog
{
Q_OBJECT
private:
PlotWindow *mpPlotWindow;
QTabWidget *mpSetupTabWidget;
/* variables tab */
QWidget *mpVariablesTab;
QLabel *mpVariableLabel;
QListWidget *mpVariablesListWidget;
QStackedWidget *mpVariablePagesStackedWidget;
/* titles tab */
QWidget *mpTitlesTab;
QLabel *mpPlotTitleLabel;
QLineEdit *mpPlotTitleTextBox;
QLabel *mpTitleFontSizeLabel;
QDoubleSpinBox *mpTitleFontSizeSpinBox;
QLabel *mpVerticalAxisLabel;
QLineEdit *mpVerticalAxisTextBox;
QLabel *mpVerticalAxisTitleFontSizeLabel;
QDoubleSpinBox *mpVerticalAxisTitleFontSizeSpinBox;
QLabel *mpVerticalAxisNumbersFontSizeLabel;
QDoubleSpinBox *mpVerticalAxisNumbersFontSizeSpinBox;
QLabel *mpHorizontalAxisLabel;
QLineEdit *mpHorizontalAxisTextBox;
QLabel *mpHorizontalAxisTitleFontSizeLabel;
QDoubleSpinBox *mpHorizontalAxisTitleFontSizeSpinBox;
QLabel *mpHorizontalAxisNumbersFontSizeLabel;
QDoubleSpinBox *mpHorizontalAxisNumbersFontSizeSpinBox;
QLabel *mpPlotFooterLabel;
QLineEdit *mpPlotFooterTextBox;
QLabel *mpFooterFontSizeLabel;
QDoubleSpinBox *mpFooterFontSizeSpinBox;
/* legend tab */
QWidget *mpLegendTab;
QLabel *mpLegendPositionLabel;
QComboBox *mpLegendPositionComboBox;
QLabel *mpLegendFontSizeLabel;
QDoubleSpinBox *mpLegendFontSizeSpinBox;
/* range tab */
QWidget *mpRangeTab;
QCheckBox *mpAutoScaleCheckbox;
QGroupBox *mpXAxisGroupBox;
QLabel *mpXMinimumLabel;
QLineEdit *mpXMinimumTextBox;
QLabel *mpXMaximumLabel;
QLineEdit *mpXMaximumTextBox;
QGroupBox *mpYAxisGroupBox;
QLabel *mpYMinimumLabel;
QLineEdit *mpYMinimumTextBox;
QLabel *mpYMaximumLabel;
QLineEdit *mpYMaximumTextBox;
QCheckBox *mpPrefixUnitsCheckbox;
bool mPrefixUnitsChanged = false;
/* buttons */
QPushButton *mpOkButton;
QPushButton *mpApplyButton;
QPushButton *mpCancelButton;
QDialogButtonBox *mpButtonBox;
public:
SetupDialog(PlotWindow *pPlotWindow);
void selectVariable(QString variable);
void setupPlotCurve(VariablePageWidget *pVariablePageWidget);
public slots:
void variableSelected(QListWidgetItem *current, QListWidgetItem *previous);
void autoScaleChecked(bool checked);
void saveSetup();
void applySetup();
};
}
#endif // PLOTWINDOW_H