Skip to content

Commit

Permalink
Store the update SubModelAttributes to undo stack.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Mar 9, 2016
1 parent 54c7cf6 commit d5769e2
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 42 deletions.
5 changes: 5 additions & 0 deletions OMEdit/OMEditGUI/Component/Component.cpp
Expand Up @@ -121,6 +121,11 @@ void ComponentInfo::updateComponentInfo(const ComponentInfo *pComponentInfo)
mModifiersMap = pComponentInfo->getModifiersMapWithoutFetching();
mParameterValueLoaded = pComponentInfo->isParameterValueLoaded();
mParameterValue = pComponentInfo->getParameterValueWithoutFetching();
mStartCommand = pComponentInfo->getStartCommand();
mExactStep = pComponentInfo->getExactStep();
mModelFile = pComponentInfo->getModelFile();
mPosition = pComponentInfo->getPosition();
mAngle321 = pComponentInfo->getAngle321();
}

/*!
Expand Down
30 changes: 19 additions & 11 deletions OMEdit/OMEditGUI/Component/ComponentProperties.cpp
Expand Up @@ -1305,21 +1305,29 @@ void SubModelAttributes::changeSimulationTool(QString simulationToolStartCommand
}

/*!
Updates subModel parameters.\n
Slot activated when mpOkButton clicked signal is raised.
*/
* \brief SubModelAttributes::updateSubModelParameters
* Updates subModel parameters.\n
* Slot activated when mpOkButton clicked signal is raised.
*/
void SubModelAttributes::updateSubModelParameters()
{
QString exactStepFlag = mpExactStepFlagCheckBox->isChecked() ? "true" : "false";
LibraryTreeItem *pLibraryTreeItem = mpComponent->getGraphicsView()->getModelWidget()->getLibraryTreeItem();
if (pLibraryTreeItem->getLibraryType()== LibraryTreeItem::TLM) {
TLMEditor *pTLMEditor = dynamic_cast<TLMEditor*>(mpComponent->getGraphicsView()->getModelWidget()->getEditor());
pTLMEditor->updateSubModelParameters(mpComponent->getName(), mpStartCommandTextBox->text(), exactStepFlag);
mpComponent->getComponentInfo()->setStartCommand(mpStartCommandTextBox->text());
mpComponent->getComponentInfo()->setExactStep(exactStepFlag.compare("true") == 0 ? true : false);
accept();
// save the old ComponentInfo
ComponentInfo oldComponentInfo(mpComponent->getComponentInfo());
// Create a new ComponentInfo
ComponentInfo newComponentInfo(mpComponent->getComponentInfo());
newComponentInfo.setStartCommand(mpStartCommandTextBox->text());
newComponentInfo.setExactStep(mpExactStepFlagCheckBox->isChecked());
// If user has really changed the Component's attributes then push that change on the stack.
if (oldComponentInfo != newComponentInfo) {
UpdateSubModelAttributesCommand *pUpdateSubModelAttributesCommand = new UpdateSubModelAttributesCommand(mpComponent, oldComponentInfo,
newComponentInfo);
ModelWidget *pModelWidget = mpComponent->getGraphicsView()->getModelWidget();
pModelWidget->getUndoStack()->push(pUpdateSubModelAttributesCommand);
pModelWidget->updateModelText();
}
accept();
}

TLMInterfacePointInfo::TLMInterfacePointInfo(QString name, QString className, QString interfaceName)
{
mName = name;
Expand Down
96 changes: 66 additions & 30 deletions OMEdit/OMEditGUI/Modeling/Commands.cpp
Expand Up @@ -914,36 +914,6 @@ void DeleteConnectionCommand::undo()
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);
}

UpdateCoOrdinateSystemCommand::UpdateCoOrdinateSystemCommand(GraphicsView *pGraphicsView, CoOrdinateSystem oldCoOrdinateSystem,
CoOrdinateSystem newCoOrdinateSystem, bool copyProperties, QString oldVersion,
QString newVersion, QString oldUsesAnnotationString,
Expand Down Expand Up @@ -1034,3 +1004,69 @@ void UpdateCoOrdinateSystemCommand::undo()
// uses annotation
pOMCProxy->addClassAnnotation(mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getNameStructure(), mOldUsesAnnotationString);
}

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);
}

UpdateSubModelAttributesCommand::UpdateSubModelAttributesCommand(Component *pComponent, const ComponentInfo &oldComponentInfo,
const ComponentInfo &newComponentInfo, QUndoCommand *pParent)
: QUndoCommand(pParent)
{
mpComponent = pComponent;
mOldComponentInfo.updateComponentInfo(&oldComponentInfo);
mNewComponentInfo.updateComponentInfo(&newComponentInfo);
setText(QString("Update SubModel %1 Attributes").arg(mpComponent->getName()));
}

/*!
* \brief UpdateSubModelAttributesCommand::redo
* Redo the UpdateSubModelAttributesCommand.
*/
void UpdateSubModelAttributesCommand::redo()
{
TLMEditor *pTLMEditor = dynamic_cast<TLMEditor*>(mpComponent->getGraphicsView()->getModelWidget()->getEditor());
pTLMEditor->updateSubModelParameters(mpComponent->getName(), mNewComponentInfo.getStartCommand(),
mNewComponentInfo.getExactStep() ? "true" : "false");
mpComponent->getComponentInfo()->setStartCommand(mNewComponentInfo.getStartCommand());
mpComponent->getComponentInfo()->setExactStep(mNewComponentInfo.getExactStep());
}

/*!
* \brief UpdateSubModelAttributesCommand::undo
* Undo the UpdateSubModelAttributesCommand.
*/
void UpdateSubModelAttributesCommand::undo()
{
TLMEditor *pTLMEditor = dynamic_cast<TLMEditor*>(mpComponent->getGraphicsView()->getModelWidget()->getEditor());
pTLMEditor->updateSubModelParameters(mpComponent->getName(), mOldComponentInfo.getStartCommand(),
mOldComponentInfo.getExactStep() ? "true" : "false");
mpComponent->getComponentInfo()->setStartCommand(mOldComponentInfo.getStartCommand());
mpComponent->getComponentInfo()->setExactStep(mOldComponentInfo.getExactStep());
}
14 changes: 13 additions & 1 deletion OMEdit/OMEditGUI/Modeling/Commands.h
Expand Up @@ -116,7 +116,6 @@ class UpdateComponentAttributesCommand : public QUndoCommand
bool mDuplicate;
};

class Parameter;
class UpdateComponentParametersCommand : public QUndoCommand
{
public:
Expand Down Expand Up @@ -215,4 +214,17 @@ class UpdateClassExperimentAnnotationCommand : public QUndoCommand
QString mNewExperimentAnnotation;
};

class UpdateSubModelAttributesCommand : public QUndoCommand
{
public:
UpdateSubModelAttributesCommand(Component *pComponent, const ComponentInfo &oldComponentInfo, const ComponentInfo &newComponentInfo,
QUndoCommand *pParent = 0);
void redo();
void undo();
private:
Component *mpComponent;
ComponentInfo mOldComponentInfo;
ComponentInfo mNewComponentInfo;
};

#endif // COMMANDS_H

0 comments on commit d5769e2

Please sign in to comment.