Skip to content

Commit

Permalink
Properly handle the parameters for parametric plot (OpenModelica#12378)
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed May 6, 2024
1 parent aeb2e67 commit 7739146
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 40 deletions.
2 changes: 1 addition & 1 deletion OMEdit/OMEditLIB/MainWindow.cpp
Expand Up @@ -4778,7 +4778,7 @@ void MainWindow::switchToPlottingPerspective()
mpModelSwitcherToolButton->setEnabled(false);
// if no plotwindow is opened then open one for user
if (mpPlotWindowContainer->subWindowList().size() == 0) {
mpPlotWindowContainer->addPlotWindow(true);
mpPlotWindowContainer->addPlotWindow();
}
if (pModelWidget) {
mpPlotWindowContainer->showDiagramWindow(pModelWidget);
Expand Down
38 changes: 24 additions & 14 deletions OMEdit/OMEditLIB/Plotting/PlotWindowContainer.cpp
Expand Up @@ -275,9 +275,8 @@ void PlotWindowContainer::showDiagramWindow(ModelWidget *pModelWidget)
/*!
* \brief PlotWindowContainer::addPlotWindow
* Adds a new Plot Window.
* \param maximized - sets the window state maximized
*/
void PlotWindowContainer::addPlotWindow(bool maximized)
void PlotWindowContainer::addPlotWindow()
{
try {
PlotWindow *pPlotWindow = new PlotWindow(QStringList(), this);
Expand All @@ -290,6 +289,7 @@ void PlotWindowContainer::addPlotWindow(bool maximized)
pPlotWindow->setTimeUnit(MainWindow::instance()->getVariablesWidget()->getSimulationTimeComboBox()->currentText());
pPlotWindow->setXLabel(QString("time"));
pPlotWindow->installEventFilter(this);
bool maximize = subWindowList().isEmpty();
QMdiSubWindow *pSubWindow = addSubWindow(pPlotWindow);
PlottingPage *pPlottingPage = OptionsDialog::instance()->getPlottingPage();
pPlotWindow->getPlot()->setFontSizes(pPlottingPage->getTitleFontSizeSpinBox()->value(), pPlottingPage->getVerticalAxisTitleFontSizeSpinBox()->value(), pPlottingPage->getVerticalAxisNumbersFontSizeSpinBox()->value(),
Expand All @@ -299,7 +299,7 @@ void PlotWindowContainer::addPlotWindow(bool maximized)
addRenameTabToSubWindowSystemMenu(pSubWindow);
pSubWindow->setWindowIcon(QIcon(":/Resources/icons/plot-window.svg"));
pPlotWindow->show();
if (maximized) {
if (maximize) {
pPlotWindow->setWindowState(Qt::WindowMaximized);
}
}
Expand All @@ -324,6 +324,7 @@ void PlotWindowContainer::addParametricPlotWindow()
pPlotWindow->setPrefixUnits(OptionsDialog::instance()->getPlottingPage()->getPrefixUnitsCheckbox()->isChecked());
pPlotWindow->setTimeUnit(MainWindow::instance()->getVariablesWidget()->getSimulationTimeComboBox()->currentText());
pPlotWindow->installEventFilter(this);
bool maximize = subWindowList().isEmpty();
QMdiSubWindow *pSubWindow = addSubWindow(pPlotWindow);
PlottingPage *pPlottingPage = OptionsDialog::instance()->getPlottingPage();
pPlotWindow->getPlot()->setFontSizes(pPlottingPage->getTitleFontSizeSpinBox()->value(), pPlottingPage->getVerticalAxisTitleFontSizeSpinBox()->value(), pPlottingPage->getVerticalAxisNumbersFontSizeSpinBox()->value(),
Expand All @@ -333,6 +334,9 @@ void PlotWindowContainer::addParametricPlotWindow()
addRenameTabToSubWindowSystemMenu(pSubWindow);
pSubWindow->setWindowIcon(QIcon(":/Resources/icons/parametric-plot-window.svg"));
pPlotWindow->show();
if (maximize) {
pPlotWindow->setWindowState(Qt::WindowMaximized);
}
}
catch (PlotException &e) {
MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, e.what(), Helper::scriptingKind, Helper::errorLevel));
Expand All @@ -342,9 +346,8 @@ void PlotWindowContainer::addParametricPlotWindow()
/*!
* \brief PlotWindowContainer::addArrayPlotWindow
* Adds a new ArrayPlot Window.
* \param maximized - sets the window state maximized
*/
void PlotWindowContainer::addArrayPlotWindow(bool maximized)
void PlotWindowContainer::addArrayPlotWindow()
{
try {
PlotWindow *pPlotWindow = new PlotWindow(QStringList(), this);
Expand All @@ -364,6 +367,7 @@ void PlotWindowContainer::addArrayPlotWindow(bool maximized)
pPlotWindow->setTimeUnit(unitComboBox->currentText());
pPlotWindow->setXLabel(QString("array element index"));
pPlotWindow->installEventFilter(this);
bool maximize = subWindowList().isEmpty();
QMdiSubWindow *pSubWindow = addSubWindow(pPlotWindow);
PlottingPage *pPlottingPage = OptionsDialog::instance()->getPlottingPage();
pPlotWindow->getPlot()->setFontSizes(pPlottingPage->getTitleFontSizeSpinBox()->value(), pPlottingPage->getVerticalAxisTitleFontSizeSpinBox()->value(), pPlottingPage->getVerticalAxisNumbersFontSizeSpinBox()->value(),
Expand All @@ -373,7 +377,7 @@ void PlotWindowContainer::addArrayPlotWindow(bool maximized)
addRenameTabToSubWindowSystemMenu(pSubWindow);
pSubWindow->setWindowIcon(QIcon(":/Resources/icons/array-plot-window.svg"));
pPlotWindow->show();
if (maximized) {
if (maximize) {
pPlotWindow->setWindowState(Qt::WindowMaximized);
}
}
Expand All @@ -385,7 +389,7 @@ void PlotWindowContainer::addArrayPlotWindow(bool maximized)
* \brief PlotWindowContainer::addInteractivePlotWindow
* Adds a new Interactive Plot Window
*/
PlotWindow* PlotWindowContainer::addInteractivePlotWindow(bool maximized, QString owner, int port)
PlotWindow* PlotWindowContainer::addInteractivePlotWindow(QString owner, int port)
{
try {
PlotWindow *pPlotWindow = new PlotWindow(QStringList(), this, true);
Expand All @@ -401,6 +405,7 @@ PlotWindow* PlotWindowContainer::addInteractivePlotWindow(bool maximized, QStrin
pPlotWindow->setTimeUnit(MainWindow::instance()->getVariablesWidget()->getSimulationTimeComboBox()->currentText());
pPlotWindow->setXLabel(QString("time"));
pPlotWindow->installEventFilter(this);
bool maximize = subWindowList().isEmpty();
QMdiSubWindow *pSubWindow = addSubWindow(pPlotWindow);
PlottingPage *pPlottingPage = OptionsDialog::instance()->getPlottingPage();
pPlotWindow->getPlot()->setFontSizes(pPlottingPage->getTitleFontSizeSpinBox()->value(), pPlottingPage->getVerticalAxisTitleFontSizeSpinBox()->value(), pPlottingPage->getVerticalAxisNumbersFontSizeSpinBox()->value(),
Expand All @@ -411,7 +416,7 @@ PlotWindow* PlotWindowContainer::addInteractivePlotWindow(bool maximized, QStrin
addRenameTabToSubWindowSystemMenu(pSubWindow);
pSubWindow->setWindowIcon(QIcon(":/Resources/icons/interaction.svg"));
pPlotWindow->show();
if (maximized) {
if (maximize) {
pPlotWindow->setWindowState(Qt::WindowMaximized);
}
return pPlotWindow;
Expand Down Expand Up @@ -445,6 +450,7 @@ void PlotWindowContainer::addArrayParametricPlotWindow()
}
pPlotWindow->setTimeUnit(unitComboBox->currentText());
pPlotWindow->installEventFilter(this);
bool maximize = subWindowList().isEmpty();
QMdiSubWindow *pSubWindow = addSubWindow(pPlotWindow);
PlottingPage *pPlottingPage = OptionsDialog::instance()->getPlottingPage();
pPlotWindow->getPlot()->setFontSizes(pPlottingPage->getTitleFontSizeSpinBox()->value(), pPlottingPage->getVerticalAxisTitleFontSizeSpinBox()->value(), pPlottingPage->getVerticalAxisNumbersFontSizeSpinBox()->value(),
Expand All @@ -454,6 +460,9 @@ void PlotWindowContainer::addArrayParametricPlotWindow()
addRenameTabToSubWindowSystemMenu(pSubWindow);
pSubWindow->setWindowIcon(QIcon(":/Resources/icons/array-parametric-plot-window.svg"));
pPlotWindow->show();
if (maximize) {
pPlotWindow->setWindowState(Qt::WindowMaximized);
}
}
catch (PlotException &e) {
MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, e.what(), Helper::scriptingKind, Helper::errorLevel));
Expand All @@ -463,19 +472,19 @@ void PlotWindowContainer::addArrayParametricPlotWindow()
/*!
* \brief PlotWindowContainer::addAnimationWindow
* Adds an animation widget as subwindow
* \param maximized - sets the window state maximized
*/
void PlotWindowContainer::addAnimationWindow(bool maximized)
void PlotWindowContainer::addAnimationWindow()
{
#if !defined(WITHOUT_OSG)
AnimationWindow *pAnimationWindow = new AnimationWindow(this);
pAnimationWindow->setWindowTitle(getUniqueName("Animation : "));
bool maximize = subWindowList().isEmpty();
QMdiSubWindow *pSubWindow = addSubWindow(pAnimationWindow);
addCloseActionsToSubWindowSystemMenu(pSubWindow);
addRenameTabToSubWindowSystemMenu(pSubWindow);
pSubWindow->setWindowIcon(QIcon(":/Resources/icons/animation.svg"));
pAnimationWindow->show();
if (maximized) {
if (maximize) {
pAnimationWindow->setWindowState(Qt::WindowMaximized);
}
#else
Expand All @@ -488,23 +497,24 @@ void PlotWindowContainer::addAnimationWindow(bool maximized)
* \brief PlotWindowContainer::addDiagramWindow
* Adds a diagram window as subwindow
* \param pModelWidget
* \param maximized - sets the window state maximized
*/
void PlotWindowContainer::addDiagramWindow(ModelWidget *pModelWidget, bool maximized)
void PlotWindowContainer::addDiagramWindow(ModelWidget *pModelWidget)
{
if (!mpDiagramWindow) {
mpDiagramWindow = new DiagramWindow(this);
}
showDiagramWindow(pModelWidget);
QMdiSubWindow *pSubWindow = getDiagramSubWindowFromMdi();
bool maximize = false;
if (!pSubWindow) {
maximize = subWindowList().isEmpty();
pSubWindow = addSubWindow(mpDiagramWindow);
addCloseActionsToSubWindowSystemMenu(pSubWindow);
addRenameTabToSubWindowSystemMenu(pSubWindow);
pSubWindow->setWindowIcon(QIcon(":/Resources/icons/modeling.png"));
}
mpDiagramWindow->show();
if (maximized) {
if (maximize) {
mpDiagramWindow->setWindowState(Qt::WindowMaximized);
}
setActiveSubWindow(pSubWindow);
Expand Down
10 changes: 5 additions & 5 deletions OMEdit/OMEditLIB/Plotting/PlotWindowContainer.h
Expand Up @@ -71,13 +71,13 @@ class PlotWindowContainer : public QMdiArea
void addRenameTabToSubWindowSystemMenu(QMdiSubWindow *pMdiSubWindow);
DiagramWindow *mpDiagramWindow;
public slots:
void addPlotWindow(bool maximized = false);
void addPlotWindow();
void addParametricPlotWindow();
void addArrayPlotWindow(bool maximized = false);
void addArrayPlotWindow();
void addArrayParametricPlotWindow();
OMPlot::PlotWindow* addInteractivePlotWindow(bool maximized = false, QString owner = QString(), int port = 0);
void addAnimationWindow(bool maximized = false);
void addDiagramWindow(ModelWidget *pModelWidget = 0, bool maximized = false);
OMPlot::PlotWindow* addInteractivePlotWindow(QString owner = QString(), int port = 0);
void addAnimationWindow();
void addDiagramWindow(ModelWidget *pModelWidget = 0);
void clearPlotWindow();
void removeInteractivePlotWindow();
void renamePlotWindow();
Expand Down
4 changes: 2 additions & 2 deletions OMEdit/OMEditLIB/Simulation/SimulationDialog.cpp
Expand Up @@ -1871,7 +1871,7 @@ bool SimulationDialog::createOpcUaClient(SimulationOptions simulationOptions, QS
MainWindow::instance()->getPlotWindowContainer()->setActiveSubWindow(pInteractivePlotWindow->getSubWindow());
pInteractivePlotWindow->interactiveSimulationPaused();
} else {
pInteractivePlotWindow = pPlotWindowContainer->addInteractivePlotWindow(true, owner, simulationOptions.getInteractiveSimulationPortNumber());
pInteractivePlotWindow = pPlotWindowContainer->addInteractivePlotWindow(owner, simulationOptions.getInteractiveSimulationPortNumber());
}
connect(pOpcUaWorker, SIGNAL(sendUpdateCurves()), pInteractivePlotWindow, SLOT(updateCurves()));
qRegisterMetaType<QPair<double,double>>();
Expand Down Expand Up @@ -1936,7 +1936,7 @@ void SimulationDialog::simulationProcessFinished(SimulationOptions simulationOpt
// if simulated with animation then open the animation directly.
if (simulationOptions.getSimulateWithAnimation()) {
if (simulationOptions.getFullResultFileName().endsWith(".mat")) {
MainWindow::instance()->getPlotWindowContainer()->addAnimationWindow(MainWindow::instance()->getPlotWindowContainer()->subWindowList().isEmpty());
MainWindow::instance()->getPlotWindowContainer()->addAnimationWindow();
AnimationWindow *pAnimationWindow = MainWindow::instance()->getPlotWindowContainer()->getCurrentAnimationWindow();
if (pAnimationWindow) {
pAnimationWindow->openAnimationFile(resultFileInfo.absoluteFilePath());
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditLIB/TLM/TLMCoSimulationDialog.cpp
Expand Up @@ -225,7 +225,7 @@ void TLMCoSimulationDialog::simulationProcessFinished(TLMCoSimulationOptions tlm
// only show the AnimationWindow if we have a visual xml file.
QFileInfo visualFileInfo(fileInfo.absoluteDir().absolutePath() + "/" + fileInfo.completeBaseName() + "_visual.xml");
if (visualFileInfo.exists()) {
MainWindow::instance()->getPlotWindowContainer()->addAnimationWindow(MainWindow::instance()->getPlotWindowContainer()->subWindowList().isEmpty());
MainWindow::instance()->getPlotWindowContainer()->addAnimationWindow();
AnimationWindow *pAnimationWindow = MainWindow::instance()->getPlotWindowContainer()->getCurrentAnimationWindow();
if (pAnimationWindow) {
pAnimationWindow->openAnimationFile(resultFileInfo.absoluteFilePath());
Expand Down
18 changes: 11 additions & 7 deletions OMPlot/OMPlot/OMPlotGUI/PlotCurve.cpp
Expand Up @@ -180,11 +180,16 @@ void PlotCurve::updateYAxisValue(int index, double value)
mYAxisVector.replace(index, value);
}

int PlotCurve::getSize()
int PlotCurve::getXAxisSize() const
{
return mXAxisVector.size();
}

int PlotCurve::getYAxisSize() const
{
return mYAxisVector.size();
}

void PlotCurve::setFileName(QString fileName)
{
mFileName = fileName;
Expand Down Expand Up @@ -270,9 +275,12 @@ void PlotCurve::plotData(bool toggleSign)
double yLowerBound = 0.0;
double yUpperBound = 0.0;

for (int i = 0 ; i < getSize() ; i++) {
for (int i = 0 ; i < getXAxisSize() ; i++) {
xLowerBound = qMin(xLowerBound, mXAxisVector.at(i));
xUpperBound = qMax(xUpperBound, mXAxisVector.at(i));
}

for (int i = 0 ; i < getYAxisSize() ; i++) {
yLowerBound = qMin(yLowerBound, mYAxisVector.at(i));
yUpperBound = qMax(yUpperBound, mYAxisVector.at(i));
}
Expand Down Expand Up @@ -315,11 +323,7 @@ void PlotCurve::plotData(bool toggleSign)
mYExponent = 0;
}
}
#if QWT_VERSION >= 0x060000
setRawSamples(mXAxisVector.data(), mYAxisVector.data(), getSize());
#else
setRawData(mXAxisVector.data(), mYAxisVector.data(), getSize());
#endif
setSamples(mXAxisVector, mYAxisVector);
}

#if QWT_VERSION < 0x060000
Expand Down
3 changes: 2 additions & 1 deletion OMPlot/OMPlot/OMPlotGUI/PlotCurve.h
Expand Up @@ -97,7 +97,8 @@ class PlotCurve : public QwtPlotCurve
void addYAxisValue(double value);
void updateYAxisValue(int index, double value);
void clearYAxisVector() {mYAxisVector.clear();}
int getSize();
int getXAxisSize() const;
int getYAxisSize() const;
void setFileName(QString fileName);
QString getFileName() const;
QString getAbsoluteFilePath() const;
Expand Down
20 changes: 11 additions & 9 deletions OMPlot/OMPlot/OMPlotGUI/PlotWindow.cpp
Expand Up @@ -796,12 +796,13 @@ void PlotWindow::plotParametric(PlotCurve *pPlotCurve)
// if variable is a parameter then
else
{
double xval;
if (omc_matlab4_val(&xval,&reader,var,0.0)) {
double xVal;
if (omc_matlab4_val(&xVal,&reader,var,0.0)) {
omc_free_matlab4_reader(&reader);
throw NoVariableException(QString("Parameter doesn't have a value : ").append(xVariable).toStdString().c_str());
}
pPlotCurve->addXAxisValue(xval);
for (uint32_t i = 0 ; i < reader.nrows ; i++)
pPlotCurve->addXAxisValue(xVal);
}
//Fill variable y with data
var = omc_matlab4_find_var(&reader, yVariable.toStdString().c_str());
Expand All @@ -823,12 +824,13 @@ void PlotWindow::plotParametric(PlotCurve *pPlotCurve)
// if variable is a parameter then
else
{
double yval;
if (omc_matlab4_val(&yval,&reader,var,0.0)) {
double yVal;
if (omc_matlab4_val(&yVal,&reader,var,0.0)) {
omc_free_matlab4_reader(&reader);
throw NoVariableException(QString("Parameter doesn't have a value : ").append(yVariable).toStdString().c_str());
}
pPlotCurve->addYAxisValue(yval);
for (uint32_t i = 0 ; i < reader.nrows ; i++)
pPlotCurve->addYAxisValue(yVal);
}
pPlotCurve->plotData();
pPlotCurve->attach(mpPlot);
Expand Down Expand Up @@ -1261,7 +1263,7 @@ void PlotWindow::plotArrayParametric(double time, PlotCurve *pPlotCurve)
pPlotCurve->addXAxisValue(res[i]);
}
else { //yVar
if (pPlotCurve->getSize()!=res.count()) {
if (pPlotCurve->getXAxisSize()!=res.count()) {
omc_free_csv_reader(csvReader);
throw PlotException(tr("Arrays must be of the same length in array parametric plot."));
}
Expand Down Expand Up @@ -1332,7 +1334,7 @@ void PlotWindow::plotArrayParametric(double time, PlotCurve *pPlotCurve)
for (int i = 0; i < vars.count(); i++)
pPlotCurve->addXAxisValue(res[i]);
else{
if (pPlotCurve->getSize()!=vars.count()) {
if (pPlotCurve->getXAxisSize()!=vars.count()) {
omc_free_matlab4_reader(&reader);
throw PlotException("Arrays must be of the same length in array parametric plot.");
}
Expand Down Expand Up @@ -1652,7 +1654,7 @@ void PlotWindow::updateCurves()
{
for (auto & p : mpPlot->getPlotCurvesList()) {
// append the last point to the plotting curve
p->getPlotDirectPainter()->drawSeries(p, p->getSize() - 2, -1);
p->getPlotDirectPainter()->drawSeries(p, p->getXAxisSize() - 2, -1);
}
}

Expand Down

0 comments on commit 7739146

Please sign in to comment.