Skip to content

Commit

Permalink
- Integrated OMPlot with OMNotebook.
Browse files Browse the repository at this point in the history
- Saving the embedded plots is reopening it is also possible now.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@11262 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Mar 1, 2012
1 parent 1846029 commit b506495
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 17 deletions.
23 changes: 19 additions & 4 deletions OMPlot/OMPlotGUI/Legend.cpp
Expand Up @@ -68,7 +68,7 @@ void Legend::legendMenu(const QPoint& pos)

if(lgdItem)
{
legendItem = lgdItem->text().text();
mLegendItemStr = lgdItem->text().text();

QMenu menu(mpPlot);
menu.addAction(mpChangeColorAction);
Expand All @@ -88,7 +88,7 @@ void Legend::selectColor()
{
for(int i = 0; i < list.length(); i++)
{
if(list[i]->title() == legendItem)
if(list[i]->title() == mLegendItemStr)
{
list[i]->setCustomColor(true);
QPen pen = list[i]->pen();
Expand All @@ -107,7 +107,7 @@ void Legend::toggleHide(bool hide)

for(int i = 0; i < list.length(); i++)
{
if(list[i]->title().text() == legendItem)
if(list[i]->title().text() == mLegendItemStr)
{
if (hide)
{
Expand All @@ -134,7 +134,7 @@ void Legend::automaticColor(bool automatic)

for(int i = 0; i < list.length(); i++)
{
if(list[i]->title().text() == legendItem)
if(list[i]->title().text() == mLegendItemStr)
{
if (automatic)
{
Expand All @@ -157,3 +157,18 @@ void Legend::automaticColor(bool automatic)
}
mpPlot->replot();
}

void Legend::setLegendItemStr(QString value)
{
mLegendItemStr = value;
}

QAction* Legend::getAutomaticColorAction()
{
return mpAutomaticColorAction;
}

QAction* Legend::getHideAction()
{
return mpHideAction;
}
5 changes: 4 additions & 1 deletion OMPlot/OMPlotGUI/Legend.h
Expand Up @@ -52,10 +52,13 @@ public slots:
void selectColor();
void toggleHide(bool hide);
void automaticColor(bool automatic);
void setLegendItemStr(QString value);
QAction* getAutomaticColorAction();
QAction* getHideAction();
private:
PlotCurve *mpPlotCurve;
Plot *mpPlot;
QString legendItem;
QString mLegendItemStr;
QAction *mpChangeColorAction;
QAction *mpAutomaticColorAction;
QAction *mpHideAction;
Expand Down
10 changes: 10 additions & 0 deletions OMPlot/OMPlotGUI/PlotCurve.cpp
Expand Up @@ -63,11 +63,21 @@ const double* PlotCurve::getXAxisVector() const
return mXAxisVector.data();
}

QVector<double> PlotCurve::getXAxisData()
{
return mXAxisVector;
}

void PlotCurve::setYAxisVector(QVector<double> vector)
{
mYAxisVector = vector;
}

QVector<double> PlotCurve::getYAxisData()
{
return mYAxisVector;
}

void PlotCurve::addYAxisValue(double value)
{
mYAxisVector.push_back(value);
Expand Down
2 changes: 2 additions & 0 deletions OMPlot/OMPlotGUI/PlotCurve.h
Expand Up @@ -56,7 +56,9 @@ class PlotCurve : public QwtPlotCurve
void setXAxisVector(QVector<double> vector);
void addXAxisValue(double value);
const double* getXAxisVector() const;
QVector<double> getXAxisData();
void setYAxisVector(QVector<double> vector);
QVector<double> getYAxisData();
void addYAxisValue(double value);
const double* getYAxisVector() const;
int getSize();
Expand Down
70 changes: 60 additions & 10 deletions OMPlot/OMPlotGUI/PlotWindow.cpp
Expand Up @@ -211,13 +211,13 @@ void PlotWindow::setupToolbar()
toolBar->addWidget(mpGridButton);
toolBar->addSeparator();
//LOG x LOG y
mpXCheckBox = new QCheckBox("Log X", this);
connect(mpXCheckBox, SIGNAL(toggled(bool)), SLOT(setLogX(bool)));
toolBar->addWidget(mpXCheckBox);
mpLogXCheckBox = new QCheckBox("Log X", this);
connect(mpLogXCheckBox, SIGNAL(toggled(bool)), SLOT(setLogX(bool)));
toolBar->addWidget(mpLogXCheckBox);
toolBar->addSeparator();
mpYCheckBox = new QCheckBox("Log Y", this);
connect(mpYCheckBox, SIGNAL(toggled(bool)), SLOT(setLogY(bool)));
toolBar->addWidget(mpYCheckBox);
mpLogYCheckBox = new QCheckBox("Log Y", this);
connect(mpLogYCheckBox, SIGNAL(toggled(bool)), SLOT(setLogY(bool)));
toolBar->addWidget(mpLogYCheckBox);
// finally add the tool bar to the mainwindow
addToolBar(toolBar);
}
Expand Down Expand Up @@ -392,6 +392,10 @@ void PlotWindow::plot()
double *vals = (double*) malloc(reader.nrows*sizeof(double));
memcpy(vals, omc_matlab4_read_vals(&reader,var->index), reader.nrows*sizeof(double));
// set plot curve data and attach it to plot
for (int i = 0 ; i < reader.nrows ; i++)
pPlotCurve->addXAxisValue(timeVals[i]);
for (int i = 0 ; i < reader.nrows ; i++)
pPlotCurve->addYAxisValue(vals[i]);
pPlotCurve->setData(timeVals, vals, reader.nrows);
pPlotCurve->attach(mpPlot);
mpPlot->replot();
Expand Down Expand Up @@ -593,6 +597,10 @@ void PlotWindow::plotParametric()
throw NoVariableException(QString("Variable doesn't exist : ").append(yVariable).toStdString().c_str());
double *yVals = (double*) malloc(reader.nrows*sizeof(double));
memcpy(yVals, omc_matlab4_read_vals(&reader,var->index), reader.nrows*sizeof(double));
for (int i = 0 ; i < reader.nrows ; i++)
pPlotCurve->addXAxisValue(xVals[i]);
for (int i = 0 ; i < reader.nrows ; i++)
pPlotCurve->addYAxisValue(yVals[i]);
pPlotCurve->setData(xVals, yVals, reader.nrows);
pPlotCurve->setTitle(yVariable + "(" + xVariable + ")");
pPlotCurve->attach(mpPlot);
Expand All @@ -611,6 +619,16 @@ void PlotWindow::setLegend(bool on)
mpPlot->getLegend()->setVisible(on);
}

QCheckBox* PlotWindow::getLogXCheckBox()
{
return mpLogXCheckBox;
}

QCheckBox* PlotWindow::getLogYCheckBox()
{
return mpLogYCheckBox;
}

void PlotWindow::setXLabel(QString label)
{
mpPlot->setAxisTitle(QwtPlot::xBottom, label);
Expand All @@ -625,12 +643,36 @@ void PlotWindow::setXRange(double min, double max)
{
if(!(max == 0 && min == 0))
mpPlot->setAxisScale(QwtPlot::xBottom, min, max);
mXRangeMin = QString::number(min);
mXRangeMax = QString::number(max);
}

QString PlotWindow::getXRangeMin()
{
return mXRangeMin;
}

QString PlotWindow::getXRangeMax()
{
return mXRangeMax;
}

void PlotWindow::setYRange(double min, double max)
{
if(!(max == 0 && min == 0))
mpPlot->setAxisScale(QwtPlot::yLeft, min, max);
mYRangeMin = QString::number(min);
mYRangeMax = QString::number(max);
}

QString PlotWindow::getYRangeMin()
{
return mYRangeMin;
}

QString PlotWindow::getYRangeMax()
{
return mYRangeMax;
}

void PlotWindow::checkForErrors(QStringList variables, QStringList variablesPlotted)
Expand Down Expand Up @@ -783,13 +825,17 @@ void PlotWindow::setLogX(bool on)
{
mpPlot->setAxisScaleEngine(QwtPlot::xBottom, new QwtLog10ScaleEngine);
mpPlot->setAxisAutoScale(QwtPlot::xBottom);
if(!mpXCheckBox->isChecked())
mpXCheckBox->setChecked(true);
mpLogXCheckBox->blockSignals(true);
mpLogXCheckBox->setChecked(true);
mpLogXCheckBox->blockSignals(false);
}
else
{
mpPlot->setAxisScaleEngine(QwtPlot::xBottom, new QwtLinearScaleEngine);
mpPlot->setAxisAutoScale(QwtPlot::xBottom);
mpLogXCheckBox->blockSignals(true);
mpLogXCheckBox->setChecked(false);
mpLogXCheckBox->blockSignals(false);
}
mpPlot->replot();
}
Expand All @@ -800,13 +846,17 @@ void PlotWindow::setLogY(bool on)
{
mpPlot->setAxisScaleEngine(QwtPlot::yLeft, new QwtLog10ScaleEngine);
mpPlot->setAxisAutoScale(QwtPlot::yLeft);
if(!mpYCheckBox->isChecked())
mpYCheckBox->setChecked(true);
mpLogYCheckBox->blockSignals(true);
mpLogYCheckBox->setChecked(true);
mpLogYCheckBox->blockSignals(false);
}
else
{
mpPlot->setAxisScaleEngine(QwtPlot::yLeft, new QwtLinearScaleEngine);
mpPlot->setAxisAutoScale(QwtPlot::yLeft);
mpLogYCheckBox->blockSignals(true);
mpLogYCheckBox->setChecked(false);
mpLogYCheckBox->blockSignals(false);
}
mpPlot->replot();
}
14 changes: 12 additions & 2 deletions OMPlot/OMPlotGUI/PlotWindow.h
Expand Up @@ -55,15 +55,19 @@ class PlotWindow : public QMainWindow
enum PlotType {PLOT, PLOTALL, PLOTPARAMETRIC};
private:
Plot *mpPlot;
QCheckBox *mpXCheckBox;
QCheckBox *mpYCheckBox;
QCheckBox *mpLogXCheckBox;
QCheckBox *mpLogYCheckBox;
QToolButton *mpGridButton;
QToolButton *mpZoomButton;
QToolButton *mpPanButton;
QTextStream *mpTextStream;
QFile mFile;
QStringList mVariablesList;
PlotType mPlotType;
QString mXRangeMin;
QString mXRangeMax;
QString mYRangeMin;
QString mYRangeMax;
public:
PlotWindow(QStringList arguments = QStringList(), QWidget *parent = 0);
~PlotWindow();
Expand All @@ -79,10 +83,16 @@ class PlotWindow : public QMainWindow
void plotParametric();
void setTitle(QString title);
void setLegend(bool on);
QCheckBox* getLogXCheckBox();
QCheckBox* getLogYCheckBox();
void setXLabel(QString label);
void setYLabel(QString label);
void setXRange(double min, double max);
QString getXRangeMin();
QString getXRangeMax();
void setYRange(double min, double max);
QString getYRangeMin();
QString getYRangeMax();
void checkForErrors(QStringList variables, QStringList variablesPlotted);
Plot* getPlot();
QToolButton* getPanButton();
Expand Down

0 comments on commit b506495

Please sign in to comment.