diff --git a/OMEdit/OMEditLIB/Plotting/PlotWindowContainer.cpp b/OMEdit/OMEditLIB/Plotting/PlotWindowContainer.cpp index 8ed73df3dbe..3cbeb45c2bb 100644 --- a/OMEdit/OMEditLIB/Plotting/PlotWindowContainer.cpp +++ b/OMEdit/OMEditLIB/Plotting/PlotWindowContainer.cpp @@ -559,7 +559,7 @@ void PlotWindowContainer::clearPlotWindow() return; } removePlotCurves(pPlotWindow); - pPlotWindow->fitInView(); + pPlotWindow->updatePlot(); MainWindow::instance()->getVariablesWidget()->updateVariablesTreeHelper(subWindowList(QMdiArea::ActivationHistoryOrder).last()); } @@ -657,11 +657,7 @@ void PlotWindowContainer::updatePlotWindows(QString variable) if (variable.compare(pPlotCurve->getFileName()) == 0) { pPlotWindow->getPlot()->removeCurve(pPlotCurve); pPlotCurve->detach(); - if (pPlotWindow->getAutoScaleButton()->isChecked()) { - pPlotWindow->fitInView(); - } else { - pPlotWindow->updatePlot(); - } + pPlotWindow->updatePlot(); } } } // is plotWidget diff --git a/OMEdit/OMEditLIB/Plotting/VariablesWidget.cpp b/OMEdit/OMEditLIB/Plotting/VariablesWidget.cpp index fae59cc100c..754a66eba3a 100644 --- a/OMEdit/OMEditLIB/Plotting/VariablesWidget.cpp +++ b/OMEdit/OMEditLIB/Plotting/VariablesWidget.cpp @@ -1620,11 +1620,7 @@ void VariablesWidget::variablesUpdated() } } } - if (pPlotWindow->getAutoScaleButton()->isChecked()) { - pPlotWindow->fitInView(); - } else { - pPlotWindow->updatePlot(); - } + pPlotWindow->updatePlot(); } } updateVariablesTreeHelper(MainWindow::instance()->getPlotWindowContainer()->currentSubWindow()); @@ -1682,11 +1678,7 @@ void VariablesWidget::updateVariablesTreeHelper(QMdiSubWindow *pSubWindow) mpVariablesTreeModel->setData(mpVariablesTreeModel->variablesTreeItemIndex(pVariablesTreeItem), Qt::Checked, Qt::CheckStateRole); } // if a simulation was left running, make a replot - if (pPlotWindow->getAutoScaleButton()->isChecked()) { - pPlotWindow->fitInView(); - } else { - pPlotWindow->updatePlot(); - } + pPlotWindow->updatePlot(); } } mpVariablesTreeModel->blockSignals(state); @@ -2024,22 +2016,14 @@ void VariablesWidget::plotVariables(const QModelIndex &index, qreal curveThickne pPlotCurve->setData(pPlotCurve->getXAxisVector(), pPlotCurve->getYAxisVector(), pPlotCurve->getSize()); } } - if (pPlotWindow->getAutoScaleButton()->isChecked()) { - pPlotWindow->fitInView(); - } else { - pPlotWindow->updatePlot(); - } + pPlotWindow->updatePlot(); } else if (!pVariablesTreeItem->isChecked()) { // if user unchecks the variable then remove it from the plot foreach (PlotCurve *pPlotCurve, pPlotWindow->getPlot()->getPlotCurvesList()) { QString curveTitle = pPlotCurve->getNameStructure(); if (curveTitle.compare(pVariablesTreeItem->getVariableName()) == 0) { pPlotWindow->getPlot()->removeCurve(pPlotCurve); pPlotCurve->detach(); - if (pPlotWindow->getAutoScaleButton()->isChecked()) { - pPlotWindow->fitInView(); - } else { - pPlotWindow->updatePlot(); - } + pPlotWindow->updatePlot(); break; } } @@ -2142,11 +2126,7 @@ void VariablesWidget::plotVariables(const QModelIndex &index, qreal curveThickne } } - if (pPlotWindow->getAutoScaleButton()->isChecked()) { - pPlotWindow->fitInView(); - } else { - pPlotWindow->updatePlot(); - } + pPlotWindow->updatePlot(); } } } else if (!pVariablesTreeItem->isChecked()) { // if user unchecks the variable then remove it from the plot @@ -2206,11 +2186,7 @@ void VariablesWidget::plotVariables(const QModelIndex &index, qreal curveThickne i++; } if (curveRemoved) { - if (pPlotWindow->getAutoScaleButton()->isChecked()) { - pPlotWindow->fitInView(); - } else { - pPlotWindow->updatePlot(); - } + pPlotWindow->updatePlot(); } } } else { // if plottype is INTERACTIVE then @@ -2262,11 +2238,7 @@ void VariablesWidget::plotVariables(const QModelIndex &index, qreal curveThickne if (pVariablesTreeItem->getVariableName().endsWith("." + pPlotCurve->getYVariable())) { pPlotWindow->getPlot()->removeCurve(pPlotCurve); pPlotCurve->detach(); - if (pPlotWindow->getAutoScaleButton()->isChecked()) { - pPlotWindow->fitInView(); - } else { - pPlotWindow->updatePlot(); - } + pPlotWindow->updatePlot(); break; } } @@ -2332,11 +2304,7 @@ void VariablesWidget::unitChanged(const QModelIndex &index) } } } - if (pPlotWindow->getAutoScaleButton()->isChecked()) { - pPlotWindow->fitInView(); - } else { - pPlotWindow->updatePlot(); - } + pPlotWindow->updatePlot(); } } catch (PlotException &e) { QMessageBox::critical(this, QString(Helper::applicationName).append(" - ").append(Helper::error), e.what(), Helper::ok); @@ -2679,11 +2647,7 @@ void VariablesWidget::timeUnitChanged(QString unit) } pPlotCurve->setData(pPlotCurve->getXAxisVector(), pPlotCurve->getYAxisVector(), pPlotCurve->getSize()); } - if (pPlotWindow->getAutoScaleButton()->isChecked()) { - pPlotWindow->fitInView(); - } else { - pPlotWindow->updatePlot(); - } + pPlotWindow->updatePlot(); } } } catch (PlotException &e) { diff --git a/OMNotebook/DrModelica/QuickTour/HelloWorld.onb b/OMNotebook/DrModelica/QuickTour/HelloWorld.onb index fd94a58dcd6..d3fd5805d96 100644 --- a/OMNotebook/DrModelica/QuickTour/HelloWorld.onb +++ b/OMNotebook/DrModelica/QuickTour/HelloWorld.onb @@ -33,7 +33,7 @@ p, li { white-space: pre-wrap; } <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Times New Roman'; font-size:12pt; color:#000000;">The program contains a declaration of a class called </span><span style=" font-family:'Courier New'; font-size:12pt; color:#000000;">HelloWorld</span><span style=" font-family:'Times New Roman'; font-size:12pt; color:#000000;"> with two fields and one equation. The first field is the variable x which is initialized to a start value 1 at the time when the simulation starts. The second field is the variable a, which is a constant that is initialized to 1 at the beginning of the simulation. Such a constant is prefixed by the keyword parameter in order to indicate that it is constant during simulation but is a model parameter that can be changed between simulations.<br /><br />The Modelica program solves a trivial differential equation:    </span><span style=" font-family:'Courier New'; font-size:12pt; color:#000000;">x' = - a * x. </span><span style=" font-family:'Times New Roman'; font-size:12pt; color:#000000;">The variable x is a state variable that can change value over time. The x ' is the time derivative of x.<br /></span></p></td></tr></table></body></html> - class HelloWorld + model HelloWorld Real x(start = 1,fixed=true); parameter Real a = 1; equation diff --git a/OMNotebook/OMNotebook/OMNotebookGUI/graphcell.cpp b/OMNotebook/OMNotebook/OMNotebookGUI/graphcell.cpp index f239f9a1953..013933a56c7 100644 --- a/OMNotebook/OMNotebook/OMNotebookGUI/graphcell.cpp +++ b/OMNotebook/OMNotebook/OMNotebookGUI/graphcell.cpp @@ -1494,7 +1494,7 @@ namespace IAEX { Fix for bug #2047. */ // mpPlotWindow->fitInView(); - mpPlotWindow->getPlot()->getPlotZoomer()->setZoomBase(false); + mpPlotWindow->updatePlot(); } catch (PlotException &e) { diff --git a/OMNotebook/OMNotebook/OMNotebookGUI/xmlparser.cpp b/OMNotebook/OMNotebook/OMNotebookGUI/xmlparser.cpp index 36912726718..f41900850b1 100644 --- a/OMNotebook/OMNotebook/OMNotebookGUI/xmlparser.cpp +++ b/OMNotebook/OMNotebook/OMNotebookGUI/xmlparser.cpp @@ -664,8 +664,7 @@ namespace IAEX } } gCell->mpPlotWindow->show(); - gCell->mpPlotWindow->fitInView(); - gCell->mpPlotWindow->getPlot()->getPlotZoomer()->setZoomBase(false); + gCell->mpPlotWindow->updatePlot(); } else { diff --git a/OMPlot/OMPlot/OMPlotGUI/Legend.cpp b/OMPlot/OMPlot/OMPlotGUI/Legend.cpp index 84da6f7d397..293abc8d62d 100644 --- a/OMPlot/OMPlot/OMPlotGUI/Legend.cpp +++ b/OMPlot/OMPlot/OMPlotGUI/Legend.cpp @@ -104,8 +104,7 @@ void Legend::toggleSign(bool checked) { if (mpPlotCurve) { mpPlot->getParentPlotWindow()->toggleSign(mpPlotCurve, checked); - mpPlot->replot(); - mpPlot->getParentPlotWindow()->fitInView(); + mpPlot->getParentPlotWindow()->updatePlot(); mpPlotCurve = 0; } } diff --git a/OMPlot/OMPlot/OMPlotGUI/PlotWindow.cpp b/OMPlot/OMPlot/OMPlotGUI/PlotWindow.cpp index 64428f76f52..dc839a27840 100644 --- a/OMPlot/OMPlot/OMPlotGUI/PlotWindow.cpp +++ b/OMPlot/OMPlot/OMPlotGUI/PlotWindow.cpp @@ -1402,15 +1402,19 @@ void PlotWindow::setTitle(QString title) /*! * \brief PlotWindow::updatePlot - * This function is called by OMEdit when auto scale is false. - * Updates the plot manually. + * Updates the plot. + * If auto scale is enabled then calls PlotWindow::fitInView() */ void PlotWindow::updatePlot() { - mpPlot->updateLayout(); - mpPlot->replot(); - if (mpPlot->getPlotZoomer()->zoomStack().size() == 1) { - mpPlot->getPlotZoomer()->setZoomBase(false); + if (mpAutoScaleButton->isChecked()) { + fitInView(); + } else { + mpPlot->updateLayout(); + mpPlot->replot(); + if (mpPlot->getPlotZoomer()->zoomStack().size() == 1) { + mpPlot->getPlotZoomer()->setZoomBase(false); + } } } @@ -1662,6 +1666,15 @@ void PlotWindow::closeEvent(QCloseEvent *event) event->accept(); } +void PlotWindow::fitInView() +{ + mpPlot->getPlotZoomer()->zoom(0); + mpPlot->setAxisAutoScale(QwtPlot::yLeft); + mpPlot->setAxisAutoScale(QwtPlot::xBottom); + mpPlot->replot(); + mpPlot->getPlotZoomer()->setZoomBase(false); +} + void PlotWindow::updateCurves() { for (auto & p : mpPlot->getPlotCurvesList()) { @@ -1805,15 +1818,6 @@ void PlotWindow::setGrid(int index) mpPlot->replot(); } -void PlotWindow::fitInView() -{ - mpPlot->getPlotZoomer()->zoom(0); - mpPlot->setAxisAutoScale(QwtPlot::yLeft); - mpPlot->setAxisAutoScale(QwtPlot::xBottom); - mpPlot->replot(); - mpPlot->getPlotZoomer()->setZoomBase(false); -} - void PlotWindow::setLogX(bool on) { if (on) { @@ -2215,40 +2219,36 @@ void SetupDialog::selectVariable(QString variable) } } -bool SetupDialog::setupPlotCurve(VariablePageWidget *pVariablePageWidget) +void SetupDialog::setupPlotCurve(VariablePageWidget *pVariablePageWidget) { - if (!pVariablePageWidget) { - return false; - } - - PlotCurve *pPlotCurve = pVariablePageWidget->getPlotCurve(); - - /* set the legend title */ - if (pPlotCurve->getCustomTitle().isEmpty() && pPlotCurve->title().text().compare(pVariablePageWidget->getLegendTextBox()->text()) == 0) { - pPlotCurve->setCustomTitle(""); - } else { - pPlotCurve->setCustomTitle(pVariablePageWidget->getLegendTextBox()->text()); - } - /* set the curve color title */ - pPlotCurve->setCustomColor(!pVariablePageWidget->getAutomaticColorCheckBox()->isChecked()); - if (pVariablePageWidget->getAutomaticColorCheckBox()->isChecked()) { - pVariablePageWidget->setCurveColor(pPlotCurve->pen().color()); - pVariablePageWidget->setCurvePickColorButtonIcon(); - } else { - QPen pen = pPlotCurve->pen(); - pen.setColor(pVariablePageWidget->getCurveColor()); - pPlotCurve->setPen(pen); + if (pVariablePageWidget) { + PlotCurve *pPlotCurve = pVariablePageWidget->getPlotCurve(); + /* set the legend title */ + if (pPlotCurve->getCustomTitle().isEmpty() && pPlotCurve->title().text().compare(pVariablePageWidget->getLegendTextBox()->text()) == 0) { + pPlotCurve->setCustomTitle(""); + } else { + pPlotCurve->setCustomTitle(pVariablePageWidget->getLegendTextBox()->text()); + } + /* set the curve color title */ + pPlotCurve->setCustomColor(!pVariablePageWidget->getAutomaticColorCheckBox()->isChecked()); + if (pVariablePageWidget->getAutomaticColorCheckBox()->isChecked()) { + pVariablePageWidget->setCurveColor(pPlotCurve->pen().color()); + pVariablePageWidget->setCurvePickColorButtonIcon(); + } else { + QPen pen = pPlotCurve->pen(); + pen.setColor(pVariablePageWidget->getCurveColor()); + pPlotCurve->setPen(pen); + } + /* set the curve style */ + QComboBox *pPatternComboBox = pVariablePageWidget->getPatternComboBox(); + pPlotCurve->setCurveStyle(pPatternComboBox->itemData(pPatternComboBox->currentIndex()).toInt()); + /* set the curve width */ + pPlotCurve->setCurveWidth(pVariablePageWidget->getThicknessSpinBox()->value()); + /* set the curve visibility */ + pPlotCurve->toggleVisibility(!pVariablePageWidget->getHideCheckBox()->isChecked()); + /* set the curve toggle sign */ + mpPlotWindow->toggleSign(pPlotCurve, pVariablePageWidget->getToggleSignCheckBox()->isChecked()); } - /* set the curve style */ - QComboBox *pPatternComboBox = pVariablePageWidget->getPatternComboBox(); - pPlotCurve->setCurveStyle(pPatternComboBox->itemData(pPatternComboBox->currentIndex()).toInt()); - /* set the curve width */ - pPlotCurve->setCurveWidth(pVariablePageWidget->getThicknessSpinBox()->value()); - /* set the curve visibility */ - pPlotCurve->toggleVisibility(!pVariablePageWidget->getHideCheckBox()->isChecked()); - /* set the curve toggle sign */ - bool toggleSign = mpPlotWindow->toggleSign(pPlotCurve, pVariablePageWidget->getToggleSignCheckBox()->isChecked()); - return toggleSign; } void SetupDialog::variableSelected(QListWidgetItem *current, QListWidgetItem *previous) @@ -2281,12 +2281,9 @@ void SetupDialog::saveSetup() void SetupDialog::applySetup() { // set the variables attributes - bool requiresFitInView = false; for (int i = 0 ; i < mpVariablePagesStackedWidget->count() ; i++) { // if any of the variable requires call to fitinview because of toggle sign. - if (setupPlotCurve(qobject_cast(mpVariablePagesStackedWidget->widget(i)))) { - requiresFitInView = true; - } + setupPlotCurve(qobject_cast(mpVariablePagesStackedWidget->widget(i))); } // set the font sizes. Don't move this line. We should set the font sizes before calling setLegendPosition mpPlotWindow->getPlot()->setFontSizes(mpTitleFontSizeSpinBox->value(), mpVerticalAxisTitleFontSizeSpinBox->value(), mpVerticalAxisNumbersFontSizeSpinBox->value(), @@ -2311,9 +2308,6 @@ void SetupDialog::applySetup() mpPlotWindow->setXRange(mpXMinimumTextBox->text().toDouble(), mpXMaximumTextBox->text().toDouble()); mpPlotWindow->setYRange(mpYMinimumTextBox->text().toDouble(), mpYMaximumTextBox->text().toDouble()); } - // replot - mpPlotWindow->getPlot()->replot(); - if (requiresFitInView) { - mpPlotWindow->fitInView(); - } + // update plot + mpPlotWindow->updatePlot(); } diff --git a/OMPlot/OMPlot/OMPlotGUI/PlotWindow.h b/OMPlot/OMPlot/OMPlotGUI/PlotWindow.h index 86cc9fe842f..99d4328fe97 100644 --- a/OMPlot/OMPlot/OMPlotGUI/PlotWindow.h +++ b/OMPlot/OMPlot/OMPlotGUI/PlotWindow.h @@ -213,6 +213,8 @@ class PlotWindow : public QMainWindow void setInteractiveControls(bool enabled); signals: void closingDown(); +private slots: + void fitInView(); public slots: void updateCurves(); void updateYAxis(QPair minMaxValues); @@ -221,7 +223,6 @@ public slots: void exportDocument(); void printPlot(); void setGrid(int index); - void fitInView(); void setLogX(bool on); void setLogY(bool on); void setAutoScale(bool on); @@ -353,7 +354,7 @@ class SetupDialog : public QDialog public: SetupDialog(PlotWindow *pPlotWindow); void selectVariable(QString variable); - bool setupPlotCurve(VariablePageWidget *pVariablePageWidget); + void setupPlotCurve(VariablePageWidget *pVariablePageWidget); public slots: void variableSelected(QListWidgetItem *current, QListWidgetItem *previous); void autoScaleChecked(bool checked);