Skip to content

Commit

Permalink
Snapshot based redo undo functionality for OMSimulator models
Browse files Browse the repository at this point in the history
Create new OMSimulator models by right clicking in the Libraries Browser
Improved the addsubmodel dialog. Let user first select the file and then propose name from filename.
Fixes ticket:5789
Fixes ticket:5984
Disable the text view if its not allowed to edit.
Tabs should be preserved when accepting text changes.
The open nodes of the tree view in the libraries browser should be preserved when accepting text changes.

Handle deletion of multiple components.
Convert dots to underscores in submodel name.
Set background-color to show the read-only ssp editor as disbaled.
Renamed OMSimulator menu item to SSP.
Use the same GUI buttons for simulation.
Separated instantiation from simulation setup.
Disable the changes once the model is in instantiated state.
Get rid of OMSSimulationOptions.h InstantiateDialog.h/.cpp
Accept text changes when user clicks in the libraries browser.
Open directly the file browser when adding a submodel.
Use just one setting for working directory.
  • Loading branch information
adeas31 committed Jun 12, 2020
1 parent 58e297e commit 1a78531
Show file tree
Hide file tree
Showing 36 changed files with 1,642 additions and 2,588 deletions.
28 changes: 15 additions & 13 deletions OMEdit/OMEditLIB/Annotations/LineAnnotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,7 @@ void LineAnnotation::updateOMSConnection()
connectionGeometry.pointsY[i] = points.at(i).y();
}

OMSProxy::instance()->setConnectionGeometry(getStartComponentName(), getEndComponentName(), &connectionGeometry);
OMSProxy::instance()->setConnectionGeometry(mpStartComponent->getLibraryTreeItem()->getNameStructure(), mpEndComponent->getLibraryTreeItem()->getNameStructure(), &connectionGeometry);
}

void LineAnnotation::updateToolTip()
Expand Down Expand Up @@ -1248,8 +1248,6 @@ void LineAnnotation::updateConnectionAnnotation()
if (mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getLibraryType()== LibraryTreeItem::CompositeModel) {
CompositeModelEditor *pCompositeModelEditor = dynamic_cast<CompositeModelEditor*>(mpGraphicsView->getModelWidget()->getEditor());
pCompositeModelEditor->updateConnection(this);
} else if (mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getLibraryType()== LibraryTreeItem::OMS) {
updateOMSConnection();
} else {
// get the connection line annotation.
QString annotationString = QString("annotate=$annotation(%1)").arg(getShapeAnnotation());
Expand Down Expand Up @@ -1278,16 +1276,20 @@ void LineAnnotation::updateConnectionTransformation()
mStartAndEndComponentsSelected = false;
}

assert(!mOldAnnotation.isEmpty());
if (mLineType == LineAnnotation::ConnectionType) {
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateConnectionCommand(this, mOldAnnotation, getOMCShapeAnnotation()));
} else if (mLineType == LineAnnotation::TransitionType) {
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateTransitionCommand(this, mCondition, mImmediate, mReset,
mSynchronize, mPriority, mOldAnnotation,
mCondition, mImmediate, mReset, mSynchronize,
mPriority, getOMCShapeAnnotation()));
} else if (mLineType == LineAnnotation::InitialStateType) {
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateInitialStateCommand(this, mOldAnnotation, getOMCShapeAnnotation()));
if (mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::OMS) {
updateOMSConnection();
} else {
assert(!mOldAnnotation.isEmpty());
if (mLineType == LineAnnotation::ConnectionType) {
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateConnectionCommand(this, mOldAnnotation, getOMCShapeAnnotation()));
} else if (mLineType == LineAnnotation::TransitionType) {
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateTransitionCommand(this, mCondition, mImmediate, mReset,
mSynchronize, mPriority, mOldAnnotation,
mCondition, mImmediate, mReset, mSynchronize,
mPriority, getOMCShapeAnnotation()));
} else if (mLineType == LineAnnotation::InitialStateType) {
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateInitialStateCommand(this, mOldAnnotation, getOMCShapeAnnotation()));
}
}
}

Expand Down
51 changes: 31 additions & 20 deletions OMEdit/OMEditLIB/Annotations/ShapeAnnotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,9 @@ void ShapeAnnotation::manhattanizeShape(bool addToStack)
}
if (addToStack) {
ModelWidget *pModelWidget = mpGraphicsView->getModelWidget();
pModelWidget->getUndoStack()->push(new UpdateShapeCommand(this, oldAnnotation, getOMCShapeAnnotation()));
if (pModelWidget->getLibraryTreeItem()->getLibraryType() != LibraryTreeItem::OMS) {
pModelWidget->getUndoStack()->push(new UpdateShapeCommand(this, oldAnnotation, getOMCShapeAnnotation()));
}
}
}
}
Expand Down Expand Up @@ -1543,26 +1545,35 @@ void ShapeAnnotation::cornerItemReleased(const bool changed)
if (changed) {
ModelWidget *pModelWidget = mpGraphicsView->getModelWidget();
LineAnnotation *pLineAnnotation = dynamic_cast<LineAnnotation*>(this);
if (pLineAnnotation && pLineAnnotation->getLineType() == LineAnnotation::ConnectionType) {
manhattanizeShape(false);
removeRedundantPointsGeometriesAndCornerItems();
// Call getOMCShapeAnnotation() after manhattanizeShape() and removeRedundantPointsGeometriesAndCornerItems() to get a correct new annotation
QString newAnnotation = getOMCShapeAnnotation();
pModelWidget->getUndoStack()->push(new UpdateConnectionCommand(pLineAnnotation, mOldAnnotation, newAnnotation));
} else if (pLineAnnotation && pLineAnnotation->getLineType() == LineAnnotation::TransitionType) {
manhattanizeShape(false);
removeRedundantPointsGeometriesAndCornerItems();
QString newAnnotation = getOMCShapeAnnotation();
pModelWidget->getUndoStack()->push(new UpdateTransitionCommand(pLineAnnotation, pLineAnnotation->getCondition(), pLineAnnotation->getImmediate(),
pLineAnnotation->getReset(), pLineAnnotation->getSynchronize(), pLineAnnotation->getPriority(),
mOldAnnotation, pLineAnnotation->getCondition(), pLineAnnotation->getImmediate(),
pLineAnnotation->getReset(), pLineAnnotation->getSynchronize(), pLineAnnotation->getPriority(), newAnnotation));
} else {
QString newAnnotation = getOMCShapeAnnotation();
pModelWidget->getUndoStack()->push(new UpdateShapeCommand(this, mOldAnnotation, newAnnotation));
pModelWidget->updateClassAnnotationIfNeeded();

if (pLineAnnotation) {
if (pModelWidget->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::OMS) {
pLineAnnotation->updateOMSConnection();
pModelWidget->createOMSimulatorUndoCommand(QString("Update OMS Connection connect(%1, %2)").arg(pLineAnnotation->getStartComponentName(), pLineAnnotation->getEndComponentName()));
pModelWidget->updateModelText();
} else {
if (pLineAnnotation->getLineType() == LineAnnotation::ConnectionType) {
manhattanizeShape(false);
removeRedundantPointsGeometriesAndCornerItems();
// Call getOMCShapeAnnotation() after manhattanizeShape() and removeRedundantPointsGeometriesAndCornerItems() to get a correct new annotation
QString newAnnotation = getOMCShapeAnnotation();
pModelWidget->getUndoStack()->push(new UpdateConnectionCommand(pLineAnnotation, mOldAnnotation, newAnnotation));
} else if (pLineAnnotation && pLineAnnotation->getLineType() == LineAnnotation::TransitionType) {
manhattanizeShape(false);
removeRedundantPointsGeometriesAndCornerItems();
QString newAnnotation = getOMCShapeAnnotation();
pModelWidget->getUndoStack()->push(new UpdateTransitionCommand(pLineAnnotation, pLineAnnotation->getCondition(), pLineAnnotation->getImmediate(),
pLineAnnotation->getReset(), pLineAnnotation->getSynchronize(), pLineAnnotation->getPriority(),
mOldAnnotation, pLineAnnotation->getCondition(), pLineAnnotation->getImmediate(),
pLineAnnotation->getReset(), pLineAnnotation->getSynchronize(), pLineAnnotation->getPriority(), newAnnotation));
} else {
QString newAnnotation = getOMCShapeAnnotation();
pModelWidget->getUndoStack()->push(new UpdateShapeCommand(this, mOldAnnotation, newAnnotation));
pModelWidget->updateClassAnnotationIfNeeded();
}
pModelWidget->updateModelText();
}
}
pModelWidget->updateModelText();
} else {
parseShapeAnnotation(mOldAnnotation);
applyTransformation();
Expand Down
11 changes: 11 additions & 0 deletions OMEdit/OMEditLIB/Editors/BaseEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ PlainTextEdit::PlainTextEdit(BaseEditor *pBaseEditor)
: QPlainTextEdit(pBaseEditor), mpBaseEditor(pBaseEditor)
{
setObjectName("BaseEditor");
setReadOnlyStyleSheet();
QTextDocument *pTextDocument = document();
pTextDocument->setDocumentMargin(2);
BaseEditorDocumentLayout *pModelicaTextDocumentLayout = new BaseEditorDocumentLayout(pTextDocument);
Expand Down Expand Up @@ -1557,6 +1558,16 @@ QCompleter *PlainTextEdit::completer()
return mpCompleter;
}

/*!
* \brief PlainTextEdit::setReadOnlyStyleSheet
* Sets the stylesheet for read-only editor to make it look like disabled.
*/
void PlainTextEdit::setReadOnlyStyleSheet()
{
// read-only PlainTextEdit with gray background
setStyleSheet(QString("QPlainTextEdit[readOnly=\"true\"] { background-color: #f0f0f0 }"));
}

/*!
* \brief PlainTextEdit::showCompletionItemToolTip
* \param index
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditLIB/Editors/BaseEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ class PlainTextEdit : public QPlainTextEdit
bool isUndoAvailable() {return mIsUndoAvailable;}
bool isRedoAvailable() {return mIsRedoAvailable;}
void setCompletionCharacters(QString chars) { mCompletionCharacters = chars; }
void setReadOnlyStyleSheet();
private:
BaseEditor *mpBaseEditor;
LineNumberArea *mpLineNumberArea;
Expand Down
24 changes: 18 additions & 6 deletions OMEdit/OMEditLIB/Element/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1712,11 +1712,23 @@ void Element::adjustInterfacePoints()
*/
void Element::updateElementTransformations(const Transformation &oldTransformation, const bool positionChanged)
{
mpGraphicsView->getModelWidget()->beginMacro("Update component transformations");
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation, positionChanged,
OptionsDialog::instance()->getGraphicalViewsPage()->getMoveConnectorsTogetherCheckBox()->isChecked()));
emit transformChanging();
mpGraphicsView->getModelWidget()->endMacro();
if (mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::OMS) {
resetTransform();
bool state = flags().testFlag(QGraphicsItem::ItemSendsGeometryChanges);
setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
setPos(0, 0);
setFlag(QGraphicsItem::ItemSendsGeometryChanges, state);
setTransform(mTransformation.getTransformationMatrix());
emit transformChange(positionChanged);
emit transformHasChanged();
emit transformChanging();
} else {
mpGraphicsView->getModelWidget()->beginMacro("Update component transformations");
const bool moveConnectorsTogether = OptionsDialog::instance()->getGraphicalViewsPage()->getMoveConnectorsTogetherCheckBox()->isChecked();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation, positionChanged, moveConnectorsTogether));
emit transformChanging();
mpGraphicsView->getModelWidget()->endMacro();
}
}

/*!
Expand Down Expand Up @@ -2719,7 +2731,7 @@ void Element::referenceElementChanged()

/*!
* \brief Element::referenceElementDeleted
* Delets the referenced components when reference component is deleted.
* Deletes the referenced components when reference component is deleted.
*/
void Element::referenceElementDeleted()
{
Expand Down
4 changes: 1 addition & 3 deletions OMEdit/OMEditLIB/Element/ElementProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1850,9 +1850,7 @@ void CompositeModelConnectionAttributes::createCompositeModelConnection()
newCompositeModelConnection.mAlpha = mpAlphaTextBox->text();
}

mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateCompositeModelConnection(mpConnectionLineAnnotation,
oldCompositeModelConnection,
newCompositeModelConnection));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateCompositeModelConnection(mpConnectionLineAnnotation, oldCompositeModelConnection, newCompositeModelConnection));
} else {
mpConnectionLineAnnotation->setDelay(mpDelayTextBox->text());
if(tlm) { //Only update TLM parameters if this is a TLM connection
Expand Down

0 comments on commit 1a78531

Please sign in to comment.