Skip to content

Commit

Permalink
Track connections updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Oct 26, 2015
1 parent 311fcb4 commit 8a95887
Show file tree
Hide file tree
Showing 13 changed files with 159 additions and 115 deletions.
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Annotations/BitmapAnnotation.cpp
Expand Up @@ -212,7 +212,7 @@ void BitmapAnnotation::duplicate()
pBitmapAnnotation->drawCornerItems();
pBitmapAnnotation->setCornerItemsActiveOrPassive();
pBitmapAnnotation->update();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddShapeCommand(pBitmapAnnotation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddShapeCommand(pBitmapAnnotation));
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->emitShapeAdded(pBitmapAnnotation, mpGraphicsView);
setSelected(false);
pBitmapAnnotation->setSelected(true);
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Annotations/EllipseAnnotation.cpp
Expand Up @@ -235,7 +235,7 @@ void EllipseAnnotation::duplicate()
pEllipseAnnotation->drawCornerItems();
pEllipseAnnotation->setCornerItemsActiveOrPassive();
pEllipseAnnotation->update();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddShapeCommand(pEllipseAnnotation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddShapeCommand(pEllipseAnnotation));
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->emitShapeAdded(pEllipseAnnotation, mpGraphicsView);
setSelected(false);
pEllipseAnnotation->setSelected(true);
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Annotations/LineAnnotation.cpp
Expand Up @@ -734,7 +734,7 @@ void LineAnnotation::duplicate()
pLineAnnotation->drawCornerItems();
pLineAnnotation->setCornerItemsActiveOrPassive();
pLineAnnotation->update();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddShapeCommand(pLineAnnotation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddShapeCommand(pLineAnnotation));
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->emitShapeAdded(pLineAnnotation, mpGraphicsView);
setSelected(false);
pLineAnnotation->setSelected(true);
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Annotations/PolygonAnnotation.cpp
Expand Up @@ -290,7 +290,7 @@ void PolygonAnnotation::duplicate()
pPolygonAnnotation->drawCornerItems();
pPolygonAnnotation->setCornerItemsActiveOrPassive();
pPolygonAnnotation->update();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddShapeCommand(pPolygonAnnotation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddShapeCommand(pPolygonAnnotation));
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->emitShapeAdded(pPolygonAnnotation, mpGraphicsView);
setSelected(false);
pPolygonAnnotation->setSelected(true);
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Annotations/RectangleAnnotation.cpp
Expand Up @@ -230,7 +230,7 @@ void RectangleAnnotation::duplicate()
pRectangleAnnotation->drawCornerItems();
pRectangleAnnotation->setCornerItemsActiveOrPassive();
pRectangleAnnotation->update();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddShapeCommand(pRectangleAnnotation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddShapeCommand(pRectangleAnnotation));
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->emitShapeAdded(pRectangleAnnotation, mpGraphicsView);
setSelected(false);
pRectangleAnnotation->setSelected(true);
Expand Down
46 changes: 26 additions & 20 deletions OMEdit/OMEditGUI/Annotations/ShapeAnnotation.cpp
Expand Up @@ -772,7 +772,7 @@ void ShapeAnnotation::applyRotation(qreal angle)
QString oldAnnotation = getOMCShapeAnnotation();
setRotationAngle(angle);
QString newAnnotation = getOMCShapeAnnotation();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateShapeCommand(this, oldAnnotation, newAnnotation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateShapeCommand(this, oldAnnotation, newAnnotation));
}

/*!
Expand Down Expand Up @@ -938,10 +938,12 @@ void ShapeAnnotation::updateShape(ShapeAnnotation *pShapeAnnotation)
}

/*!
Slot activated when mpManhattanizeShapeAction triggered signal is raised.\n
Finds the curved lines in the Line shape and makes in manhattanize/right-angle line.
*/
void ShapeAnnotation::manhattanizeShape()
* \brief ShapeAnnotation::manhattanizeShape
* Slot activated when mpManhattanizeShapeAction triggered signal is raised.\n
* Finds the curved lines in the Line shape and makes in manhattanize/right-angle line.
* \param addToStack
*/
void ShapeAnnotation::manhattanizeShape(bool addToStack)
{
QString oldAnnotation = getOMCShapeAnnotation();
int startIndex = -1;
Expand Down Expand Up @@ -989,8 +991,10 @@ void ShapeAnnotation::manhattanizeShape()
for (int i = lastIndex ; i < oldPoints.size() ; i++) {
addPoint(oldPoints[i]);
}
ModelWidget *pModelWidget = mpGraphicsView->getModelWidget();
pModelWidget->getUndoStack()->push(new UpdateShapeCommand(this, oldAnnotation, getOMCShapeAnnotation(), mpGraphicsView));
if (addToStack) {
ModelWidget *pModelWidget = mpGraphicsView->getModelWidget();
pModelWidget->getUndoStack()->push(new UpdateShapeCommand(this, oldAnnotation, getOMCShapeAnnotation()));
}
cornerItemReleased();
}
}
Expand Down Expand Up @@ -1157,7 +1161,7 @@ void ShapeAnnotation::moveUp()
setTransform(mTransformation.getTransformationMatrix());
setOrigin(mTransformation.getPosition());
QString newAnnotation = getOMCShapeAnnotation();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateShapeCommand(this, oldAnnotation, newAnnotation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateShapeCommand(this, oldAnnotation, newAnnotation));
}

/*!
Expand All @@ -1173,7 +1177,7 @@ void ShapeAnnotation::moveShiftUp()
setTransform(mTransformation.getTransformationMatrix());
setOrigin(mTransformation.getPosition());
QString newAnnotation = getOMCShapeAnnotation();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateShapeCommand(this, oldAnnotation, newAnnotation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateShapeCommand(this, oldAnnotation, newAnnotation));
}

/*!
Expand All @@ -1189,7 +1193,7 @@ void ShapeAnnotation::moveCtrlUp()
setTransform(mTransformation.getTransformationMatrix());
setOrigin(mTransformation.getPosition());
QString newAnnotation = getOMCShapeAnnotation();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateShapeCommand(this, oldAnnotation, newAnnotation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateShapeCommand(this, oldAnnotation, newAnnotation));
}

/*!
Expand All @@ -1205,7 +1209,7 @@ void ShapeAnnotation::moveDown()
setTransform(mTransformation.getTransformationMatrix());
setOrigin(mTransformation.getPosition());
QString newAnnotation = getOMCShapeAnnotation();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateShapeCommand(this, oldAnnotation, newAnnotation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateShapeCommand(this, oldAnnotation, newAnnotation));
}

/*!
Expand All @@ -1221,7 +1225,7 @@ void ShapeAnnotation::moveShiftDown()
setTransform(mTransformation.getTransformationMatrix());
setOrigin(mTransformation.getPosition());
QString newAnnotation = getOMCShapeAnnotation();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateShapeCommand(this, oldAnnotation, newAnnotation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateShapeCommand(this, oldAnnotation, newAnnotation));
}

/*!
Expand All @@ -1237,7 +1241,7 @@ void ShapeAnnotation::moveCtrlDown()
setTransform(mTransformation.getTransformationMatrix());
setOrigin(mTransformation.getPosition());
QString newAnnotation = getOMCShapeAnnotation();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateShapeCommand(this, oldAnnotation, newAnnotation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateShapeCommand(this, oldAnnotation, newAnnotation));
}

/*!
Expand All @@ -1253,7 +1257,7 @@ void ShapeAnnotation::moveLeft()
setTransform(mTransformation.getTransformationMatrix());
setOrigin(mTransformation.getPosition());
QString newAnnotation = getOMCShapeAnnotation();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateShapeCommand(this, oldAnnotation, newAnnotation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateShapeCommand(this, oldAnnotation, newAnnotation));
}

/*!
Expand All @@ -1269,7 +1273,7 @@ void ShapeAnnotation::moveShiftLeft()
setTransform(mTransformation.getTransformationMatrix());
setOrigin(mTransformation.getPosition());
QString newAnnotation = getOMCShapeAnnotation();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateShapeCommand(this, oldAnnotation, newAnnotation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateShapeCommand(this, oldAnnotation, newAnnotation));
}

/*!
Expand All @@ -1285,7 +1289,7 @@ void ShapeAnnotation::moveCtrlLeft()
setTransform(mTransformation.getTransformationMatrix());
setOrigin(mTransformation.getPosition());
QString newAnnotation = getOMCShapeAnnotation();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateShapeCommand(this, oldAnnotation, newAnnotation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateShapeCommand(this, oldAnnotation, newAnnotation));
}

/*!
Expand All @@ -1301,7 +1305,7 @@ void ShapeAnnotation::moveRight()
setTransform(mTransformation.getTransformationMatrix());
setOrigin(mTransformation.getPosition());
QString newAnnotation = getOMCShapeAnnotation();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateShapeCommand(this, oldAnnotation, newAnnotation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateShapeCommand(this, oldAnnotation, newAnnotation));
}

/*!
Expand All @@ -1317,7 +1321,7 @@ void ShapeAnnotation::moveShiftRight()
setTransform(mTransformation.getTransformationMatrix());
setOrigin(mTransformation.getPosition());
QString newAnnotation = getOMCShapeAnnotation();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateShapeCommand(this, oldAnnotation, newAnnotation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateShapeCommand(this, oldAnnotation, newAnnotation));
}

/*!
Expand All @@ -1333,7 +1337,7 @@ void ShapeAnnotation::moveCtrlRight()
setTransform(mTransformation.getTransformationMatrix());
setOrigin(mTransformation.getPosition());
QString newAnnotation = getOMCShapeAnnotation();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateShapeCommand(this, oldAnnotation, newAnnotation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateShapeCommand(this, oldAnnotation, newAnnotation));
}

/*!
Expand Down Expand Up @@ -1502,7 +1506,9 @@ void ShapeAnnotation::contextMenuEvent(QGraphicsSceneContextMenuEvent *pEvent)
LineAnnotation::LineType lineType = LineAnnotation::ShapeType;
if (pLineAnnotation) {
lineType = pLineAnnotation->getLineType();
menu.addAction(mpGraphicsView->getManhattanizeAction());
if (lineType != LineAnnotation::ConnectionType) {
menu.addAction(mpGraphicsView->getManhattanizeAction());
}
}
menu.addAction(mpGraphicsView->getDeleteAction());
if (lineType != LineAnnotation::ConnectionType) {
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Annotations/ShapeAnnotation.h
Expand Up @@ -225,7 +225,7 @@ public slots:
LineGeometryType findLineGeometryType(QPointF point1, QPointF point2);
bool isLineStraight(QPointF point1, QPointF point2);
void showShapeProperties();
void manhattanizeShape();
void manhattanizeShape(bool addToStack = true);
void referenceShapeAdded();
void referenceShapeChanged();
void referenceShapeDeleted();
Expand Down
25 changes: 9 additions & 16 deletions OMEdit/OMEditGUI/Annotations/ShapePropertiesDialog.cpp
Expand Up @@ -829,26 +829,19 @@ bool ShapePropertiesDialog::applyShapeProperties()
if (mpLineAnnotation) {
lineType = mpLineAnnotation->getLineType();
}
// if (mpLineAnnotation && lineType == LineAnnotation::ConnectionType) {
// mpShapeAnnotation->removeCornerItems();
// mpShapeAnnotation->drawCornerItems();
// mpShapeAnnotation->adjustGeometries();
// mpLineAnnotation->updateConnectionAnnotation();
// mpLineAnnotation->update();
// } else {
// mpShapeAnnotation->initializeTransformation();
// mpShapeAnnotation->removeCornerItems();
// mpShapeAnnotation->drawCornerItems();
// mpShapeAnnotation->update();
// mpShapeAnnotation->getGraphicsView()->addClassAnnotation();
// }
// if nothing has changed then just simply return true.
if (mOldAnnotation.compare(mpShapeAnnotation->getOMCShapeAnnotation()) == 0) {
return true;
} else { // create a UpdateShapeCommand object and push it to the undo stack.
} else if (mpLineAnnotation && lineType == LineAnnotation::ConnectionType) {
// create a UpdateConnectionCommand object and push it to the undo stack.
UpdateConnectionCommand *pUpdateConnectionCommand;
pUpdateConnectionCommand = new UpdateConnectionCommand(mpLineAnnotation, mOldAnnotation, mpShapeAnnotation->getOMCShapeAnnotation());
mpShapeAnnotation->getGraphicsView()->getModelWidget()->getUndoStack()->push(pUpdateConnectionCommand);
mpShapeAnnotation->getGraphicsView()->getModelWidget()->updateModelicaText();
} else {
// create a UpdateShapeCommand object and push it to the undo stack.
UpdateShapeCommand *pUpdateShapeCommand;
pUpdateShapeCommand = new UpdateShapeCommand(mpShapeAnnotation, mOldAnnotation, mpShapeAnnotation->getOMCShapeAnnotation(),
mpShapeAnnotation->getGraphicsView());
pUpdateShapeCommand = new UpdateShapeCommand(mpShapeAnnotation, mOldAnnotation, mpShapeAnnotation->getOMCShapeAnnotation());
mpShapeAnnotation->getGraphicsView()->getModelWidget()->getUndoStack()->push(pUpdateShapeCommand);
mpShapeAnnotation->getGraphicsView()->getModelWidget()->updateClassAnnotationIfNeeded();
mpShapeAnnotation->getGraphicsView()->getModelWidget()->updateModelicaText();
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Annotations/TextAnnotation.cpp
Expand Up @@ -493,7 +493,7 @@ void TextAnnotation::duplicate()
pTextAnnotation->drawCornerItems();
pTextAnnotation->setCornerItemsActiveOrPassive();
pTextAnnotation->update();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddShapeCommand(pTextAnnotation, mpGraphicsView));
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddShapeCommand(pTextAnnotation));
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->emitShapeAdded(pTextAnnotation, mpGraphicsView);
setSelected(false);
pTextAnnotation->setSelected(true);
Expand Down
24 changes: 12 additions & 12 deletions OMEdit/OMEditGUI/Component/CornerItem.cpp
Expand Up @@ -63,7 +63,8 @@ CornerItem::CornerItem(qreal x, qreal y, int connectedPointIndex, ShapeAnnotatio
setFlag(QGraphicsItem::ItemIsMovable, false);
}
/* Only shapes manipulation via CornerItem's if the class is not a system library class OR not an inherited shape. */
if (!mpShapeAnnotation->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->isSystemLibrary() && !mpShapeAnnotation->isInheritedShape()) {
if (!mpShapeAnnotation->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->isSystemLibrary() &&
!mpShapeAnnotation->isInheritedShape()) {
connect(this, SIGNAL(cornerItemMoved(int,QPointF)), mpShapeAnnotation, SLOT(updateCornerItemPoint(int,QPointF)));
connect(this, SIGNAL(cornerItemPress()), mpShapeAnnotation, SLOT(cornerItemPressed()));
connect(this, SIGNAL(cornerItemRelease()), mpShapeAnnotation, SLOT(cornerItemReleased()));
Expand Down Expand Up @@ -124,11 +125,6 @@ void CornerItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
if (!signalsBlocked()) {
emit cornerItemPress();
}
LineAnnotation *pLineAnnotation = dynamic_cast<LineAnnotation*>(mpShapeAnnotation);
if (pLineAnnotation && pLineAnnotation->getLineType() == LineAnnotation::ConnectionType) {
mpShapeAnnotation->manhattanizeShape();
mpShapeAnnotation->removeRedundantPointsGeometriesAndCornerItems();
}
mOldAnnotation = mpShapeAnnotation->getOMCShapeAnnotation();
mClickPos = mapToScene(event->pos());
}
Expand All @@ -150,16 +146,20 @@ void CornerItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
emit cornerItemRelease();
}
if (mClickPos != mapToScene(event->pos())) {
ModelWidget *pModelWidget = mpShapeAnnotation->getGraphicsView()->getModelWidget();
LineAnnotation *pLineAnnotation = dynamic_cast<LineAnnotation*>(mpShapeAnnotation);
if (pLineAnnotation && pLineAnnotation->getLineType() == LineAnnotation::ConnectionType) {
mpShapeAnnotation->manhattanizeShape();
mpShapeAnnotation->manhattanizeShape(false);
mpShapeAnnotation->removeRedundantPointsGeometriesAndCornerItems();
QString newAnnotation = mpShapeAnnotation->getOMCShapeAnnotation();
pModelWidget->getUndoStack()->push(new UpdateConnectionCommand(pLineAnnotation, mOldAnnotation, newAnnotation));
pModelWidget->updateModelicaText();
} else {
QString newAnnotation = mpShapeAnnotation->getOMCShapeAnnotation();
pModelWidget->getUndoStack()->push(new UpdateShapeCommand(mpShapeAnnotation, mOldAnnotation, newAnnotation));
pModelWidget->updateClassAnnotationIfNeeded();
pModelWidget->updateModelicaText();
}
ModelWidget *pModelWidget = mpShapeAnnotation->getGraphicsView()->getModelWidget();
pModelWidget->getUndoStack()->push(new UpdateShapeCommand(mpShapeAnnotation, mOldAnnotation, mpShapeAnnotation->getOMCShapeAnnotation(),
mpShapeAnnotation->getGraphicsView()));
pModelWidget->updateClassAnnotationIfNeeded();
pModelWidget->updateModelicaText();
}
}
}
Expand Down

0 comments on commit 8a95887

Please sign in to comment.