Skip to content

Commit

Permalink
Push the experiment annotation modifications to the undo stack
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Nov 3, 2015
1 parent e9d3ec4 commit eb7c065
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 14 deletions.
4 changes: 4 additions & 0 deletions OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -2872,6 +2872,8 @@ void MainWindow::switchToWelcomePerspective()
mpPlotWindowContainer->tileSubWindows();
mpCentralStackedWidget->setCurrentWidget(mpWelcomePageWidget);
mpModelWidgetContainer->currentModelWidgetChanged(0);
mpUndoAction->setEnabled(false);
mpRedoAction->setEnabled(false);
mpModelSwitcherToolButton->setEnabled(false);
mpVariablesDockWidget->hide();
mpPlotToolBar->setEnabled(false);
Expand Down Expand Up @@ -2907,6 +2909,8 @@ void MainWindow::switchToPlottingPerspective()
mPlotWindowsStatesList.clear();
mPlotWindowsGeometriesList.clear();
mpModelWidgetContainer->currentModelWidgetChanged(0);
mpUndoAction->setEnabled(false);
mpRedoAction->setEnabled(false);
mpModelSwitcherToolButton->setEnabled(false);
// if not plotwindow is opened then open one for user
if (mpPlotWindowContainer->subWindowList().size() == 0) {
Expand Down
30 changes: 30 additions & 0 deletions OMEdit/OMEditGUI/Modeling/Commands.cpp
Expand Up @@ -874,3 +874,33 @@ void DeleteConnectionCommand::undo()
mpConnectionLineAnnotation->emitAdded();
mpConnectionLineAnnotation->getGraphicsView()->addConnectionToClass(mpConnectionLineAnnotation);
}

UpdateClassExperimentAnnotationCommand::UpdateClassExperimentAnnotationCommand(MainWindow *pMainWindow, LibraryTreeItem *pLibraryTreeItem,
QString oldExperimentAnnotation, QString newExperimentAnnotaiton,
QUndoCommand *pParent)
: QUndoCommand(pParent)
{
mpMainWindow = pMainWindow;
mpLibraryTreeItem = pLibraryTreeItem;
mOldExperimentAnnotation = oldExperimentAnnotation;
mNewExperimentAnnotation = newExperimentAnnotaiton;
setText(QString("Update %1 experiment annotation").arg(mpLibraryTreeItem->getNameStructure()));
}

/*!
* \brief UpdateClassExperimentAnnotationCommand::redo
* Redo the UpdateClassExperimentAnnotationCommand.
*/
void UpdateClassExperimentAnnotationCommand::redo()
{
mpMainWindow->getOMCProxy()->addClassAnnotation(mpLibraryTreeItem->getNameStructure(), mNewExperimentAnnotation);
}

/*!
* \brief UpdateClassExperimentAnnotationCommand::undo
* Undo the UpdateClassExperimentAnnotationCommand.
*/
void UpdateClassExperimentAnnotationCommand::undo()
{
mpMainWindow->getOMCProxy()->addClassAnnotation(mpLibraryTreeItem->getNameStructure(), mOldExperimentAnnotation);
}
14 changes: 14 additions & 0 deletions OMEdit/OMEditGUI/Modeling/Commands.h
Expand Up @@ -183,4 +183,18 @@ class DeleteConnectionCommand : public QUndoCommand
GraphicsView *mpGraphicsView;
};

class UpdateClassExperimentAnnotationCommand : public QUndoCommand
{
public:
UpdateClassExperimentAnnotationCommand(MainWindow *pMainWindow, LibraryTreeItem *pLibraryTreeItem, QString oldExperimentAnnotation,
QString newExperimentAnnotaiton, QUndoCommand *pParent = 0);
void redo();
void undo();
private:
MainWindow *mpMainWindow;
LibraryTreeItem *mpLibraryTreeItem;
QString mOldExperimentAnnotation;
QString mNewExperimentAnnotation;
};

#endif // COMMANDS_H
8 changes: 6 additions & 2 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -3564,7 +3564,9 @@ bool ModelWidget::TLMEditorTextChanged()
*/
void ModelWidget::handleCanUndoChanged(bool canUndo)
{
mpModelWidgetContainer->getMainWindow()->getUndoAction()->setEnabled(canUndo);
if (isVisible()) {
mpModelWidgetContainer->getMainWindow()->getUndoAction()->setEnabled(canUndo);
}
}

/*!
Expand All @@ -3574,7 +3576,9 @@ void ModelWidget::handleCanUndoChanged(bool canUndo)
*/
void ModelWidget::handleCanRedoChanged(bool canRedo)
{
mpModelWidgetContainer->getMainWindow()->getRedoAction()->setEnabled(canRedo);
if (isVisible()) {
mpModelWidgetContainer->getMainWindow()->getRedoAction()->setEnabled(canRedo);
}
}

void ModelWidget::closeEvent(QCloseEvent *event)
Expand Down
40 changes: 28 additions & 12 deletions OMEdit/OMEditGUI/Simulation/SimulationDialog.cpp
Expand Up @@ -44,6 +44,7 @@
#include "SimulationDialog.h"
#include "SimulationOutputWidget.h"
#include "VariablesWidget.h"
#include "Commands.h"

/*!
\class SimulationDialog
Expand Down Expand Up @@ -1005,26 +1006,42 @@ void SimulationDialog::saveSimulationOptions()
if (mIsReSimulate || !mpSaveSimulationCheckbox->isChecked())
return;

QString annotationString;
QString oldExperimentAnnotation = "annotate=experiment(";
// if the class has experiment annotation then read it.
if (mpMainWindow->getOMCProxy()->isExperiment(mpLibraryTreeItem->getNameStructure())) {
// get the simulation options....
QStringList result = mpMainWindow->getOMCProxy()->getSimulationOptions(mpLibraryTreeItem->getNameStructure());
// since we always get simulationOptions so just get the values from array
oldExperimentAnnotation.append("StartTime=").append(QString::number(result.at(0).toFloat())).append(",");
oldExperimentAnnotation.append("StopTime=").append(QString::number(result.at(1).toFloat())).append(",");
oldExperimentAnnotation.append("Tolerance=").append(QString::number(result.at(2).toFloat())).append(",");
oldExperimentAnnotation.append("Interval=").append(QString::number(result.at(3).toFloat()));
}
oldExperimentAnnotation.append(")");
QString newExperimentAnnotation;
// create simulations options annotation
annotationString.append("annotate=experiment(");
annotationString.append("StartTime=").append(mpStartTimeTextBox->text()).append(",");
annotationString.append("StopTime=").append(mpStopTimeTextBox->text()).append(",");
annotationString.append("Tolerance=").append(mpToleranceTextBox->text()).append(",");
newExperimentAnnotation.append("annotate=experiment(");
newExperimentAnnotation.append("StartTime=").append(mpStartTimeTextBox->text()).append(",");
newExperimentAnnotation.append("StopTime=").append(mpStopTimeTextBox->text()).append(",");
newExperimentAnnotation.append("Tolerance=").append(mpToleranceTextBox->text()).append(",");
double interval, stopTime, startTime;
int numberOfIntervals;
stopTime = mpStopTimeTextBox->text().toDouble();
startTime = mpStartTimeTextBox->text().toDouble();
numberOfIntervals = mpNumberofIntervalsSpinBox->value();
interval = (numberOfIntervals == 0) ? 0 : (stopTime - startTime) / numberOfIntervals;
annotationString.append("Interval=").append(QString::number(interval));
annotationString.append(")");
// send the simulations options annotation to OMC
mpMainWindow->getOMCProxy()->addClassAnnotation(mpLibraryTreeItem->getNameStructure(), annotationString);
// make the model modified
if (mpLibraryTreeItem->getModelWidget()) {
newExperimentAnnotation.append("Interval=").append(QString::number(interval));
newExperimentAnnotation.append(")");
// if we have ModelWidget for class then put the change on undo stack.
if (mpLibraryTreeItem->getModelWidget() && !mpLibraryTreeItem->getModelWidget()->isReloadNeeded()) {
UpdateClassExperimentAnnotationCommand *pUpdateClassExperimentAnnotationCommand;
pUpdateClassExperimentAnnotationCommand = new UpdateClassExperimentAnnotationCommand(mpMainWindow, mpLibraryTreeItem,
oldExperimentAnnotation, newExperimentAnnotation);
mpLibraryTreeItem->getModelWidget()->getUndoStack()->push(pUpdateClassExperimentAnnotationCommand);
mpLibraryTreeItem->getModelWidget()->updateModelicaText();
} else {
// send the simulations options annotation to OMC
mpMainWindow->getOMCProxy()->addClassAnnotation(mpLibraryTreeItem->getNameStructure(), newExperimentAnnotation);
LibraryTreeModel *pLibraryTreeModel = mpMainWindow->getLibraryWidget()->getLibraryTreeModel();
pLibraryTreeModel->updateLibraryTreeItemClassText(mpLibraryTreeItem);
}
Expand Down Expand Up @@ -1076,7 +1093,6 @@ void SimulationDialog::simulationProcessFinished(SimulationOptions simulationOpt
if (list.size() > 0) {
mpMainWindow->getPerspectiveTabBar()->setCurrentIndex(2);
pVariablesWidget->insertVariablesItemsToTree(simulationOptions.getResultFileName(), workingDirectory, list, simulationOptions);
mpMainWindow->getVariablesDockWidget()->show();
}
}
}
Expand Down

0 comments on commit eb7c065

Please sign in to comment.