Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Allow preserving the zoom level. Don't always auto rescale for new variables in plot.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@25480 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Apr 9, 2015
1 parent 3dd5a11 commit 3844793
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
23 changes: 22 additions & 1 deletion OMPlot/OMPlotGUI/PlotWindow.cpp
Expand Up @@ -110,9 +110,16 @@ void PlotWindow::initializePlot(QStringList arguments)
setCurveStyle(QString(arguments[14]).toInt());
setLegendPosition(QString(arguments[15]));
setFooter(QString(arguments[16]));
if (QString(arguments[17]) == "true") {
setAutoScale(true);
} else if (QString(arguments[17]) == "false") {
setAutoScale(false);
} else {
throw PlotException("Invalid input" + arguments[17]);
}
/* read variables */
QStringList variablesToRead;
for(int i = 17; i < arguments.length(); i++)
for(int i = 18; i < arguments.length(); i++)
variablesToRead.append(QString(arguments[i]));

setVariablesList(variablesToRead);
Expand Down Expand Up @@ -176,6 +183,13 @@ void PlotWindow::setupToolbar()
connect(mpPanButton, SIGNAL(toggled(bool)), SLOT(enablePanMode(bool)));
toolBar->addWidget(mpPanButton);
toolBar->addSeparator();
// Auto scale
mpAutoScaleButton = new QToolButton(toolBar);
mpAutoScaleButton->setText(tr("Auto Scale"));
mpAutoScaleButton->setCheckable(true);
connect(mpAutoScaleButton, SIGNAL(toggled(bool)), SLOT(setAutoScale(bool)));
toolBar->addWidget(mpAutoScaleButton);
toolBar->addSeparator();
//Fit in View
QToolButton *fitInViewButton = new QToolButton(toolBar);
fitInViewButton->setText(tr("Fit in View"));
Expand Down Expand Up @@ -1046,6 +1060,13 @@ void PlotWindow::setLogY(bool on)
mpPlot->replot();
}

void PlotWindow::setAutoScale(bool on)
{
bool state = mpAutoScaleButton->blockSignals(true);
mpAutoScaleButton->setChecked(on);
mpAutoScaleButton->blockSignals(state);
}

void PlotWindow::showSetupDialog()
{
SetupDialog *pSetupDialog = new SetupDialog(this);
Expand Down
3 changes: 3 additions & 0 deletions OMPlot/OMPlotGUI/PlotWindow.h
Expand Up @@ -63,6 +63,7 @@ class PlotWindow : public QMainWindow
QToolButton *mpNoGridButton;
QToolButton *mpZoomButton;
QToolButton *mpPanButton;
QToolButton *mpAutoScaleButton;
QToolButton *mpSetupButton;
QTextStream *mpTextStream;
QFile mFile;
Expand Down Expand Up @@ -94,6 +95,7 @@ class PlotWindow : public QMainWindow
QString getGrid();
QCheckBox* getLogXCheckBox();
QCheckBox* getLogYCheckBox();
QToolButton* getAutoScaleButton() {return mpAutoScaleButton;}
void setXLabel(QString label);
void setYLabel(QString label);
void setUnit(QString unit) {mUnit = unit;}
Expand Down Expand Up @@ -130,6 +132,7 @@ public slots:
void fitInView();
void setLogX(bool on);
void setLogY(bool on);
void setAutoScale(bool on);
void showSetupDialog();
void showSetupDialog(QString variable);
};
Expand Down
5 changes: 5 additions & 0 deletions OMPlot/OMPlotGUI/main.cpp
Expand Up @@ -64,6 +64,7 @@ void printUsage()
printf(" --curve-style=STYLE Sets the STYLE of the curve. SolidLine=1, DashLine=2, DotLine=3, DashDotLine=4, DashDotDotLine=5, Sticks=6, Steps=7\n");
printf(" --legend-position=POSITION Sets the POSITION of the legend i.e left, right, top, bottom, none\n");
printf(" --footer=FOOTER Sets the FOOTER of the plot window\n");
printf(" --auto-scale=[true|false] Use auto scale while plotting.\n");
}

int main(int argc, char *argv[])
Expand All @@ -86,6 +87,7 @@ int main(int argc, char *argv[])
int curveStyle = 1;
QString legendPosition = "top";
QString footer("");
bool autoScale = true;
QStringList vars;
QString filename;
for(int i = 1; i < argc; i++)
Expand Down Expand Up @@ -139,6 +141,8 @@ int main(int argc, char *argv[])
legendPosition = argv[i]+18;
} else if (strncmp(argv[i], "--footer=", 9) == 0) {
footer = argv[i]+9;
} else if (strncmp(argv[i], "--auto-scale=",13) == 0) {
CONSUME_BOOL_ARG(i,13,autoScale);
} else if (strncmp(argv[i], "--", 2) == 0) {
fprintf(stderr, "Error: Unknown option: %s\n", argv[i]);
return 1;
Expand Down Expand Up @@ -169,6 +173,7 @@ int main(int argc, char *argv[])
arguments.append(QString::number(curveStyle));
arguments.append(legendPosition);
arguments.append(footer);
arguments.append(autoScale ? "true" : "false");
arguments.append(vars);
// create the plot application object that is used to check that only one instance of application is running
PlotApplication app(argc, argv, "OMPlot");
Expand Down

0 comments on commit 3844793

Please sign in to comment.