Skip to content

Commit

Permalink
Update the connection when component transformation is changed
Browse files Browse the repository at this point in the history
Avoid adding extra line to Modelica text
Preserve the text position with undo/redo
  • Loading branch information
adeas31 committed Oct 10, 2018
1 parent 53e32ce commit 3f512db
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 131 deletions.
17 changes: 12 additions & 5 deletions OMEdit/OMEditGUI/Annotations/LineAnnotation.cpp
Expand Up @@ -1177,16 +1177,23 @@ void LineAnnotation::updateConnectionAnnotation()
}
}

void LineAnnotation::updateConnectionTransformation(QUndoCommand *pUndoCommand)
/*!
* \brief LineAnnotation::updateConnectionTransformation
* Slot activated when Component transformChanging SIGNAL is emitted.\n
* Updates the connection.
*/
void LineAnnotation::updateConnectionTransformation()
{
assert(!mOldAnnotation.isEmpty());
if (mLineType == LineAnnotation::ConnectionType) {
new UpdateConnectionCommand(this, mOldAnnotation, getOMCShapeAnnotation(), pUndoCommand);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateConnectionCommand(this, mOldAnnotation, getOMCShapeAnnotation()));
} else if (mLineType == LineAnnotation::TransitionType) {
new UpdateTransitionCommand(this, mCondition, mImmediate, mReset, mSynchronize, mPriority, mOldAnnotation,
mCondition, mImmediate, mReset, mSynchronize, mPriority, getOMCShapeAnnotation(), pUndoCommand);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateTransitionCommand(this, mCondition, mImmediate, mReset,
mSynchronize, mPriority, mOldAnnotation,
mCondition, mImmediate, mReset, mSynchronize,
mPriority, getOMCShapeAnnotation()));
} else if (mLineType == LineAnnotation::InitialStateType) {
new UpdateInitialStateCommand(this, mOldAnnotation, getOMCShapeAnnotation(), pUndoCommand);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateInitialStateCommand(this, mOldAnnotation, getOMCShapeAnnotation()));
}
}

Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Annotations/LineAnnotation.h
Expand Up @@ -154,7 +154,7 @@ class LineAnnotation : public ShapeAnnotation
public slots:
void handleComponentMoved();
void updateConnectionAnnotation();
void updateConnectionTransformation(QUndoCommand *pUndoCommand);
void updateConnectionTransformation();
void updateTransitionAnnotation(QString oldCondition, bool oldImmediate, bool oldReset, bool oldSynchronize, int oldPriority);
void updateInitialStateAnnotation();
void duplicate();
Expand Down
52 changes: 31 additions & 21 deletions OMEdit/OMEditGUI/Component/Component.cpp
Expand Up @@ -1091,24 +1091,23 @@ void Component::applyRotation(qreal angle)
angle = 0;
}
mTransformation.setRotateAngle(angle);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
updateComponentTransformations(oldTransformation);
}

void Component::addConnectionDetails(LineAnnotation *pConnectorLineAnnotation)
{
// handle component position, rotation and scale changes
connect(this, SIGNAL(transformChange()), pConnectorLineAnnotation, SLOT(handleComponentMoved()), Qt::UniqueConnection);
if (!pConnectorLineAnnotation->isInheritedShape()) {
connect(this, SIGNAL(transformChanging(QUndoCommand*)), pConnectorLineAnnotation,
SLOT(updateConnectionTransformation(QUndoCommand*)), Qt::UniqueConnection);
connect(this, SIGNAL(transformChanging()), pConnectorLineAnnotation, SLOT(updateConnectionTransformation()), Qt::UniqueConnection);
}
}

void Component::removeConnectionDetails(LineAnnotation *pConnectorLineAnnotation)
{
disconnect(this, SIGNAL(transformChange()), pConnectorLineAnnotation, SLOT(handleComponentMoved()));
if (!pConnectorLineAnnotation->isInheritedShape()) {
disconnect(this, SIGNAL(transformChanging(QUndoCommand*)), pConnectorLineAnnotation, SLOT(updateConnectionTransformation(QUndoCommand*)));
disconnect(this, SIGNAL(transformChanging()), pConnectorLineAnnotation, SLOT(updateConnectionTransformation()));
}
}

Expand Down Expand Up @@ -1426,6 +1425,19 @@ void Component::adjustInterfacePoints()
}
}

/*!
* \brief Component::updateComponentTransformations
* Creates a UpdateComponentTransformationsCommand and emits the Component::transformChanging() SIGNAL.
* \param oldTransformation
*/
void Component::updateComponentTransformations(const Transformation &oldTransformation)
{
mpGraphicsView->getModelWidget()->beginMacro("Update component transformations");
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
emit transformChanging();
mpGraphicsView->getModelWidget()->endMacro();
}

/*!
* \brief Component::createNonExistingComponent
* Creates a non-existing component.
Expand Down Expand Up @@ -2317,9 +2329,7 @@ void Component::finishResizeComponent()
*/
void Component::resizedComponent()
{
UpdateComponentTransformationsCommand *pUpdateComponentCommand = new UpdateComponentTransformationsCommand(this, mOldTransformation,
mTransformation);
mpGraphicsView->getModelWidget()->getUndoStack()->push(pUpdateComponentCommand);
updateComponentTransformations(mOldTransformation);
mpGraphicsView->getModelWidget()->updateModelText();
}

Expand Down Expand Up @@ -2459,7 +2469,7 @@ void Component::flipHorizontal()
mTransformation.setExtent1(QPointF(extent1.x(), extent2.y()));
mTransformation.setExtent2(QPointF(extent2.x(), extent1.y()));
}
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
updateComponentTransformations(oldTransformation);
showResizerItems();
}

Expand All @@ -2482,7 +2492,7 @@ void Component::flipVertical()
mTransformation.setExtent1(QPointF(extent2.x(), extent1.y()));
mTransformation.setExtent2(QPointF(extent1.x(), extent2.y()));
}
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
updateComponentTransformations(oldTransformation);
showResizerItems();
}

Expand All @@ -2496,7 +2506,7 @@ void Component::moveUp()
{
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(0, mpGraphicsView->mCoOrdinateSystem.getVerticalGridStep());
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
updateComponentTransformations(oldTransformation);
}

/*!
Expand All @@ -2509,7 +2519,7 @@ void Component::moveShiftUp()
{
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(0, mpGraphicsView->mCoOrdinateSystem.getVerticalGridStep() * 5);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
updateComponentTransformations(oldTransformation);
}

/*!
Expand All @@ -2522,7 +2532,7 @@ void Component::moveCtrlUp()
{
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(0, 1);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
updateComponentTransformations(oldTransformation);
}

/*!
Expand All @@ -2535,7 +2545,7 @@ void Component::moveDown()
{
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(0, -mpGraphicsView->mCoOrdinateSystem.getVerticalGridStep());
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
updateComponentTransformations(oldTransformation);
}

/*!
Expand All @@ -2548,7 +2558,7 @@ void Component::moveShiftDown()
{
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(0, -(mpGraphicsView->mCoOrdinateSystem.getVerticalGridStep() * 5));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
updateComponentTransformations(oldTransformation);
}

/*!
Expand All @@ -2561,7 +2571,7 @@ void Component::moveCtrlDown()
{
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(0, -1);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
updateComponentTransformations(oldTransformation);
}

/*!
Expand All @@ -2574,7 +2584,7 @@ void Component::moveLeft()
{
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(-mpGraphicsView->mCoOrdinateSystem.getHorizontalGridStep(), 0);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
updateComponentTransformations(oldTransformation);
}

/*!
Expand All @@ -2587,7 +2597,7 @@ void Component::moveShiftLeft()
{
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(-(mpGraphicsView->mCoOrdinateSystem.getHorizontalGridStep() * 5), 0);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
updateComponentTransformations(oldTransformation);
}

/*!
Expand All @@ -2600,7 +2610,7 @@ void Component::moveCtrlLeft()
{
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(-1, 0);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
updateComponentTransformations(oldTransformation);
}

/*!
Expand All @@ -2613,7 +2623,7 @@ void Component::moveRight()
{
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(mpGraphicsView->mCoOrdinateSystem.getHorizontalGridStep(), 0);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
updateComponentTransformations(oldTransformation);
}

/*!
Expand All @@ -2626,7 +2636,7 @@ void Component::moveShiftRight()
{
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(mpGraphicsView->mCoOrdinateSystem.getHorizontalGridStep() * 5, 0);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
updateComponentTransformations(oldTransformation);
}

/*!
Expand All @@ -2639,7 +2649,7 @@ void Component::moveCtrlRight()
{
Transformation oldTransformation = mTransformation;
mTransformation.adjustPosition(1, 0);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateComponentTransformationsCommand(this, oldTransformation, mTransformation));
updateComponentTransformations(oldTransformation);
}

//! Slot that opens up the component parameters dialog.
Expand Down
4 changes: 2 additions & 2 deletions OMEdit/OMEditGUI/Component/Component.h
Expand Up @@ -231,7 +231,6 @@ class Component : public QObject, public QGraphicsItem
void emitAdded();
void emitTransformChange() {emit transformChange();}
void emitTransformHasChanged();
void emitTransformChanging(QUndoCommand *pUndoCommand) {emit transformChanging(pUndoCommand);}
void emitChanged();
void emitDeleted();
void componentParameterHasChanged();
Expand All @@ -243,6 +242,7 @@ class Component : public QObject, public QGraphicsItem
void insertInterfacePoint(QString interfaceName, QString position, QString angle321, int dimensions, QString causality, QString domain);
void removeInterfacePoint(QString interfaceName);
void adjustInterfacePoints();
void updateComponentTransformations(const Transformation &oldTransformation);

Transformation mTransformation;
Transformation mOldTransformation;
Expand Down Expand Up @@ -318,7 +318,7 @@ class Component : public QObject, public QGraphicsItem
void added();
void transformChange();
void transformHasChanged();
void transformChanging(QUndoCommand *pUndoCommand);
void transformChanging();
void displayTextChanged();
void changed();
void deleted();
Expand Down
62 changes: 6 additions & 56 deletions OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -1713,35 +1713,10 @@ void MainWindow::undo()
pModelWidget->clearSelection();
pModelWidget->getUndoStack()->undo();
pModelWidget->updateClassAnnotationIfNeeded();
pModelWidget->updateModelText(false);
/* We don't use the editor undo/redo for OMSimulator.
* So simply return from here now.
*/
if (pModelWidget->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::OMS) {
return;
}
}
if (pModelWidget && pModelWidget->getEditor() && (pModelWidget->getEditor()->getPlainTextEdit()->document()->isUndoAvailable())) {
if (pModelWidget &&
((pModelWidget->getIconGraphicsView() && pModelWidget->getIconGraphicsView()->isVisible()) ||
(pModelWidget->getDiagramGraphicsView() && pModelWidget->getDiagramGraphicsView()->isVisible()))) {
pModelWidget->getEditor()->setForceSetPlainText(true);
}
pModelWidget->updateModelText();
} else if (pModelWidget && pModelWidget->getEditor() && pModelWidget->getEditor()->isVisible()
&& pModelWidget->getEditor()->getPlainTextEdit()->document()->isUndoAvailable()) {
pModelWidget->getEditor()->getPlainTextEdit()->document()->undo();
// if (pModelWidget->getEditor()->isVisible() &&
// pModelWidget->getEditor()->getPlainTextEdit()->document()->availableUndoSteps() + 1 == pModelWidget->getUndoStack()->index()) {
// pModelWidget->clearSelection();
// pModelWidget->getUndoStack()->undo();
// pModelWidget->updateClassAnnotationIfNeeded();
// } else {
// pModelWidget->getEditor()->setTextChanged(true);
// }
// pModelWidget->updateModelText(false);
if (pModelWidget &&
((pModelWidget->getIconGraphicsView() && pModelWidget->getIconGraphicsView()->isVisible()) ||
(pModelWidget->getDiagramGraphicsView() && pModelWidget->getDiagramGraphicsView()->isVisible()))) {
pModelWidget->getEditor()->setForceSetPlainText(false);
}
}
}

Expand All @@ -1758,35 +1733,10 @@ void MainWindow::redo()
pModelWidget->clearSelection();
pModelWidget->getUndoStack()->redo();
pModelWidget->updateClassAnnotationIfNeeded();
pModelWidget->updateModelText(false);
/* We don't use the editor undo/redo for OMSimulator.
* So simply return from here now.
*/
if (pModelWidget->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::OMS) {
return;
}
}
if (pModelWidget && pModelWidget->getEditor() && (pModelWidget->getEditor()->getPlainTextEdit()->document()->isRedoAvailable())) {
if (pModelWidget &&
((pModelWidget->getIconGraphicsView() && pModelWidget->getIconGraphicsView()->isVisible()) ||
(pModelWidget->getDiagramGraphicsView() && pModelWidget->getDiagramGraphicsView()->isVisible()))) {
pModelWidget->getEditor()->setForceSetPlainText(true);
}
pModelWidget->updateModelText();
} else if (pModelWidget && pModelWidget->getEditor() && pModelWidget->getEditor()->isVisible()
&& pModelWidget->getEditor()->getPlainTextEdit()->document()->isRedoAvailable()) {
pModelWidget->getEditor()->getPlainTextEdit()->document()->redo();
// if (pModelWidget->getEditor()->isVisible() &&
// pModelWidget->getEditor()->getPlainTextEdit()->document()->availableRedoSteps() == pModelWidget->getUndoStack()->index()) {
// pModelWidget->clearSelection();
// pModelWidget->getUndoStack()->redo();
// pModelWidget->updateClassAnnotationIfNeeded();
// } else {
// pModelWidget->getEditor()->setTextChanged(true);
// }
// pModelWidget->updateModelText(false);
if (pModelWidget &&
((pModelWidget->getIconGraphicsView() && pModelWidget->getIconGraphicsView()->isVisible()) ||
(pModelWidget->getDiagramGraphicsView() && pModelWidget->getDiagramGraphicsView()->isVisible()))) {
pModelWidget->getEditor()->setForceSetPlainText(false);
}
}
}

Expand Down
20 changes: 6 additions & 14 deletions OMEdit/OMEditGUI/Modeling/Commands.cpp
Expand Up @@ -292,14 +292,6 @@ void AddComponentCommand::undo()
UpdateComponentTransformationsCommand::UpdateComponentTransformationsCommand(Component *pComponent, const Transformation &oldTransformation,
const Transformation &newTransformation, QUndoCommand *pParent)
: QUndoCommand(pParent)
{
pComponent->emitTransformChanging(this);
new UpdateComponentTransformationsCommandInternal(pComponent, oldTransformation, newTransformation, this);
}

UpdateComponentTransformationsCommand::UpdateComponentTransformationsCommandInternal::UpdateComponentTransformationsCommandInternal
(Component *pComponent, const Transformation &oldTransformation, const Transformation &newTransformation, QUndoCommand *pParent)
: QUndoCommand(pParent)
{
mpComponent = pComponent;
mpIconOrDiagramComponent = 0;
Expand All @@ -309,10 +301,10 @@ UpdateComponentTransformationsCommand::UpdateComponentTransformationsCommandInte
}

/*!
* \brief UpdateComponentTransformationsCommand::UpdateComponentTransformationsCommandInternal::redo
* Redo the UpdateComponentTransformationsCommandInternal.
* \brief UpdateComponentTransformationsCommand::redo
* Redo the UpdateComponentTransformationsCommand.
*/
void UpdateComponentTransformationsCommand::UpdateComponentTransformationsCommandInternal::redo()
void UpdateComponentTransformationsCommand::redo()
{
ModelWidget *pModelWidget = mpComponent->getGraphicsView()->getModelWidget();
if (mpComponent->getLibraryTreeItem() && mpComponent->getLibraryTreeItem()->isConnector() &&
Expand Down Expand Up @@ -342,10 +334,10 @@ void UpdateComponentTransformationsCommand::UpdateComponentTransformationsComman
}

/*!
* \brief UpdateComponentTransformationsCommand::UpdateComponentTransformationsCommandInternal::undo
* Undo the UpdateComponentTransformationsCommandInternal.
* \brief UpdateComponentTransformationsCommand::undo
* Undo the UpdateComponentTransformationsCommand.
*/
void UpdateComponentTransformationsCommand::UpdateComponentTransformationsCommandInternal::undo()
void UpdateComponentTransformationsCommand::undo()
{
ModelWidget *pModelWidget = mpComponent->getGraphicsView()->getModelWidget();
if (mpComponent->getLibraryTreeItem() && mpComponent->getLibraryTreeItem()->isConnector() &&
Expand Down
19 changes: 6 additions & 13 deletions OMEdit/OMEditGUI/Modeling/Commands.h
Expand Up @@ -96,20 +96,13 @@ class UpdateComponentTransformationsCommand : public QUndoCommand
public:
UpdateComponentTransformationsCommand(Component *pComponent, const Transformation &oldTransformation,
const Transformation &newTransformation, QUndoCommand *pParent = 0);
void redo();
void undo();
private:
class UpdateComponentTransformationsCommandInternal : public QUndoCommand
{
public:
UpdateComponentTransformationsCommandInternal(Component *pComponent, const Transformation &oldTransformation,
const Transformation &newTransformation, QUndoCommand *pParent = 0);
void redo();
void undo();
private:
Component *mpComponent;
Component *mpIconOrDiagramComponent;
Transformation mOldTransformation;
Transformation mNewTransformation;
};
Component *mpComponent;
Component *mpIconOrDiagramComponent;
Transformation mOldTransformation;
Transformation mNewTransformation;
};

class UpdateComponentAttributesCommand : public QUndoCommand
Expand Down

0 comments on commit 3f512db

Please sign in to comment.