From afb86a3e4c64eb5304dfe15f6f4f83cc9c0860d8 Mon Sep 17 00:00:00 2001 From: Adeel Asghar Date: Thu, 14 Sep 2023 19:34:51 +0200 Subject: [PATCH] Improve the drawing of connection start and end points (#11185) --- .../OMEditLIB/Annotations/LineAnnotation.cpp | 45 +++++++++++----- OMEdit/OMEditLIB/Annotations/LineAnnotation.h | 6 +++ .../OMEditLIB/Annotations/ShapeAnnotation.cpp | 22 ++++---- .../Annotations/ShapePropertiesDialog.cpp | 53 +++++++------------ .../OMEditLIB/Annotations/TextAnnotation.cpp | 2 +- OMEdit/OMEditLIB/Element/CornerItem.cpp | 5 +- .../Modeling/ModelWidgetContainer.cpp | 38 ++++++------- 7 files changed, 89 insertions(+), 82 deletions(-) diff --git a/OMEdit/OMEditLIB/Annotations/LineAnnotation.cpp b/OMEdit/OMEditLIB/Annotations/LineAnnotation.cpp index d0c7acb3d4b..72e720c6662 100644 --- a/OMEdit/OMEditLIB/Annotations/LineAnnotation.cpp +++ b/OMEdit/OMEditLIB/Annotations/LineAnnotation.cpp @@ -661,33 +661,34 @@ void LineAnnotation::parseShapeAnnotation() QPainterPath LineAnnotation::getShape() const { + PointArrayAnnotation points = adjustPointsForDrawing(); QPainterPath path; - if (mPoints.size() > 0) { + if (points.size() > 0) { // mPoints.size() is at least 1 - path.moveTo(mPoints.at(0)); + path.moveTo(points.at(0)); if (mSmooth) { - if (mPoints.size() == 2) { + if (points.size() == 2) { // if points are only two then spline acts as simple line - path.lineTo(mPoints.at(1)); + path.lineTo(points.at(1)); } else { - for (int i = 2 ; i < mPoints.size() ; i++) { - QPointF point3 = mPoints.at(i); + for (int i = 2 ; i < points.size() ; i++) { + QPointF point3 = points.at(i); // calculate middle points for bezier curves - QPointF point2 = mPoints.at(i - 1); - QPointF point1 = mPoints.at(i - 2); + QPointF point2 = points.at(i - 1); + QPointF point1 = points.at(i - 2); QPointF point12((point1.x() + point2.x())/2, (point1.y() + point2.y())/2); QPointF point23((point2.x() + point3.x())/2, (point2.y() + point3.y())/2); path.lineTo(point12); path.cubicTo(point12, point2, point23); // if its the last point - if (i == mPoints.size() - 1) { + if (i == points.size() - 1) { path.lineTo(point3); } } } } else { - for (int i = 1 ; i < mPoints.size() ; i++) { - path.lineTo(mPoints.at(i)); + for (int i = 1 ; i < points.size() ; i++) { + path.lineTo(points.at(i)); } } } @@ -752,7 +753,7 @@ void LineAnnotation::drawAnnotation(QPainter *painter, bool scene) applyLinePattern(painter); QPainterPath path = getShape(); - PointArrayAnnotation points = mPoints; + PointArrayAnnotation points = adjustPointsForDrawing(); if (scene) { path = mapToScene(path); for (int i = 0; i < points.size(); ++i) { @@ -1410,6 +1411,26 @@ QColor LineAnnotation::findLineColorForConnection(Element *pComponent) return lineColor; } +/*! + * \brief LineAnnotation::adjustPointsForDrawing + * Adjusts the start and end points of the connection to the center of start and end connectors. + * This only updates the points for drawing and does not modify the actual values for Modelica code. + * \return + */ +PointArrayAnnotation LineAnnotation::adjustPointsForDrawing() const +{ + PointArrayAnnotation points = mPoints; + if (isConnection()) { + if (mpStartElement && points.size() > 0) { + points.setPoint(0, mpStartElement->sceneBoundingRect().center()); + } + if (mpEndElement && points.size() > 1) { + points.setPoint(points.size() - 1, mpEndElement->sceneBoundingRect().center()); + } + } + return points; +} + QVariant LineAnnotation::itemChange(GraphicsItemChange change, const QVariant &value) { ShapeAnnotation::itemChange(change, value); diff --git a/OMEdit/OMEditLIB/Annotations/LineAnnotation.h b/OMEdit/OMEditLIB/Annotations/LineAnnotation.h index 9020521df8a..a568e41192a 100644 --- a/OMEdit/OMEditLIB/Annotations/LineAnnotation.h +++ b/OMEdit/OMEditLIB/Annotations/LineAnnotation.h @@ -107,6 +107,10 @@ class LineAnnotation : public ShapeAnnotation ModelInstance::Line* getLine() {return mpLine;} void setLineType(LineType lineType) {mLineType = lineType;} LineType getLineType() {return mLineType;} + bool isConnection() const {return mLineType == LineAnnotation::ConnectionType;} + bool isTransition() const {return mLineType == LineAnnotation::TransitionType;} + bool isInitialState() const {return mLineType == LineAnnotation::InitialStateType;} + bool isLineShape() const {return mLineType == LineAnnotation::ShapeType;} void setStartElement(Element *pStartElement) {mpStartElement = pStartElement;} Element* getStartElement() {return mpStartElement;} void setStartElementName(QString name) {mStartElementName = name;} @@ -154,6 +158,8 @@ class LineAnnotation : public ShapeAnnotation static QColor findLineColorForConnection(Element *pComponent); private: ModelInstance::Line *mpLine; + + PointArrayAnnotation adjustPointsForDrawing() const; protected: QVariant itemChange(GraphicsItemChange change, const QVariant &value) override; diff --git a/OMEdit/OMEditLIB/Annotations/ShapeAnnotation.cpp b/OMEdit/OMEditLIB/Annotations/ShapeAnnotation.cpp index fffd3f27135..d87326319bb 100644 --- a/OMEdit/OMEditLIB/Annotations/ShapeAnnotation.cpp +++ b/OMEdit/OMEditLIB/Annotations/ShapeAnnotation.cpp @@ -687,7 +687,7 @@ void ShapeAnnotation::applyTransformation() pGraphicsView = mpReferenceShapeAnnotation->getGraphicsView(); } - if (!mpParentComponent && pGraphicsView && !(pLineAnnotation && pLineAnnotation->getLineType() != LineAnnotation::ShapeType) + if (!mpParentComponent && pGraphicsView && (pLineAnnotation && pLineAnnotation->isLineShape()) && ((mpReferenceShapeAnnotation && mpReferenceShapeAnnotation->getGraphicsView()) || (pGraphicsView->getModelWidget()->isNewApi() && mIsInheritedShape))) { QList extendsCoOrdinateExtents = getExtentsForInheritedShapeFromIconDiagramMap(pGraphicsView, mpReferenceShapeAnnotation); ExtentAnnotation extent = pGraphicsView->mMergedCoOrdinateSystem.getExtent(); @@ -1312,11 +1312,11 @@ void ShapeAnnotation::deleteMe() { // delete the shape LineAnnotation *pLineAnnotation = dynamic_cast(this); - if (pLineAnnotation && pLineAnnotation->getLineType() == LineAnnotation::ConnectionType) { + if (pLineAnnotation && pLineAnnotation->isConnection()) { mpGraphicsView->deleteConnection(pLineAnnotation); - } else if (pLineAnnotation && pLineAnnotation->getLineType() == LineAnnotation::TransitionType) { + } else if (pLineAnnotation && pLineAnnotation->isTransition()) { mpGraphicsView->deleteTransition(pLineAnnotation); - } else if (pLineAnnotation && pLineAnnotation->getLineType() == LineAnnotation::InitialStateType) { + } else if (pLineAnnotation && pLineAnnotation->isInitialState()) { mpGraphicsView->deleteInitialState(pLineAnnotation); } else { mpGraphicsView->deleteShape(this); @@ -1562,13 +1562,13 @@ void ShapeAnnotation::cornerItemReleased(const bool changed) return; } } else { - if (pLineAnnotation && pLineAnnotation->getLineType() == LineAnnotation::ConnectionType) { + if (pLineAnnotation && pLineAnnotation->isConnection()) { 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) { + } else if (pLineAnnotation && pLineAnnotation->isTransition()) { manhattanizeShape(false); removeRedundantPointsGeometriesAndCornerItems(); QString newAnnotation = getOMCShapeAnnotation(); @@ -1610,7 +1610,7 @@ void ShapeAnnotation::updateCornerItemPoint(int index, QPointF point) if (dynamic_cast(this)) { point = mapFromScene(point); LineAnnotation *pLineAnnotation = dynamic_cast(this); - if (pLineAnnotation->getLineType() == LineAnnotation::ConnectionType) { + if (pLineAnnotation && pLineAnnotation->isConnection()) { if (mPoints.size() > index) { // if moving the 2nd last point then we need to add more points after it to keep the last point manhattanized with connector int secondLastIndex = mPoints.size() - 2; @@ -1868,10 +1868,6 @@ QVariant ShapeAnnotation::itemChange(GraphicsItemChange change, const QVariant & QGraphicsItem::itemChange(change, value); if (change == QGraphicsItem::ItemSelectedHasChanged) { LineAnnotation *pLineAnnotation = dynamic_cast(this); - LineAnnotation::LineType lineType = LineAnnotation::ShapeType; - if (pLineAnnotation) { - lineType = pLineAnnotation->getLineType(); - } if (isSelected()) { setCornerItemsActiveOrPassive(); setCursor(Qt::SizeAllCursor); @@ -1881,7 +1877,7 @@ QVariant ShapeAnnotation::itemChange(GraphicsItemChange change, const QVariant & connect(mpGraphicsView, SIGNAL(manhattanize()), this, SLOT(manhattanizeShape()), Qt::UniqueConnection); } connect(mpGraphicsView, SIGNAL(deleteSignal()), this, SLOT(deleteMe()), Qt::UniqueConnection); - if (lineType == LineAnnotation::ShapeType) { + if (pLineAnnotation && pLineAnnotation->isLineShape()) { connect(mpGraphicsView, SIGNAL(duplicate()), this, SLOT(duplicate()), Qt::UniqueConnection); connect(mpGraphicsView->getBringToFrontAction(), SIGNAL(triggered()), this, SLOT(bringToFront()), Qt::UniqueConnection); connect(mpGraphicsView->getBringForwardAction(), SIGNAL(triggered()), this, SLOT(bringForward()), Qt::UniqueConnection); @@ -1914,7 +1910,7 @@ QVariant ShapeAnnotation::itemChange(GraphicsItemChange change, const QVariant & disconnect(mpGraphicsView, SIGNAL(manhattanize()), this, SLOT(manhattanizeShape())); } disconnect(mpGraphicsView, SIGNAL(deleteSignal()), this, SLOT(deleteMe())); - if (lineType == LineAnnotation::ShapeType) { + if (pLineAnnotation && pLineAnnotation->isLineShape()) { disconnect(mpGraphicsView, SIGNAL(duplicate()), this, SLOT(duplicate())); disconnect(mpGraphicsView->getBringToFrontAction(), SIGNAL(triggered()), this, SLOT(bringToFront())); disconnect(mpGraphicsView->getBringForwardAction(), SIGNAL(triggered()), this, SLOT(bringForward())); diff --git a/OMEdit/OMEditLIB/Annotations/ShapePropertiesDialog.cpp b/OMEdit/OMEditLIB/Annotations/ShapePropertiesDialog.cpp index f3185750c71..efc2b80c6b3 100644 --- a/OMEdit/OMEditLIB/Annotations/ShapePropertiesDialog.cpp +++ b/OMEdit/OMEditLIB/Annotations/ShapePropertiesDialog.cpp @@ -419,18 +419,16 @@ ShapePropertiesDialog::ShapePropertiesDialog(ShapeAnnotation *pShapeAnnotation, QVector points = mpShapeAnnotation->getPoints(); mpPointsTableWidget->setRowCount(points.size()); int rowIndex = 0; - LineAnnotation::LineType lineType = LineAnnotation::ShapeType; - if (mpLineAnnotation) lineType = mpLineAnnotation->getLineType(); foreach (QPointF point, points) { QTableWidgetItem *pTableWidgetItemX = new QTableWidgetItem(QString::number(point.x())); - if ((rowIndex == 0 || rowIndex == points.size() - 1) && (lineType == LineAnnotation::ConnectionType)) { + if ((rowIndex == 0 || rowIndex == points.size() - 1) && (mpLineAnnotation && mpLineAnnotation->isConnection())) { pTableWidgetItemX->setFlags(Qt::NoItemFlags); } else { pTableWidgetItemX->setFlags(pTableWidgetItemX->flags() | Qt::ItemIsEditable); } mpPointsTableWidget->setItem(rowIndex, 0, pTableWidgetItemX); QTableWidgetItem *pTableWidgetItemY = new QTableWidgetItem(QString::number(point.y())); - if ((rowIndex == 0 || rowIndex == points.size() - 1) && (lineType == LineAnnotation::ConnectionType)) { + if ((rowIndex == 0 || rowIndex == points.size() - 1) && (mpLineAnnotation && mpLineAnnotation->isConnection())) { pTableWidgetItemY->setFlags(Qt::NoItemFlags); } else { pTableWidgetItemY->setFlags(pTableWidgetItemY->flags() | Qt::ItemIsEditable); @@ -439,7 +437,7 @@ ShapePropertiesDialog::ShapePropertiesDialog(ShapeAnnotation *pShapeAnnotation, rowIndex++; } if (rowIndex > 0) { - if (lineType == LineAnnotation::ConnectionType) { + if (mpLineAnnotation && mpLineAnnotation->isConnection()) { mpPointsTableWidget->setCurrentCell(1, 1); } else { mpPointsTableWidget->setCurrentCell(0, 0); @@ -540,11 +538,11 @@ ShapePropertiesDialog::ShapePropertiesDialog(ShapeAnnotation *pShapeAnnotation, QString ShapePropertiesDialog::getTitle() { if (mpLineAnnotation) { - if (mpLineAnnotation->getLineType() == LineAnnotation::ConnectionType) { + if (mpLineAnnotation->isConnection()) { return "Connection"; - } else if (mpLineAnnotation->getLineType() == LineAnnotation::TransitionType) { + } else if (mpLineAnnotation->isTransition()) { return "Transition"; - } else if (mpLineAnnotation->getLineType() == LineAnnotation::InitialStateType) { + } else if (mpLineAnnotation->isInitialState()) { return "Initial State"; } else { return "Line"; @@ -640,9 +638,7 @@ void ShapePropertiesDialog::fillPickColor() void ShapePropertiesDialog::movePointUp() { - LineAnnotation::LineType lineType = LineAnnotation::ShapeType; - if (mpLineAnnotation) lineType = mpLineAnnotation->getLineType(); - if (lineType == LineAnnotation::InitialStateType) { + if (mpLineAnnotation && mpLineAnnotation->isInitialState()) { return; } if (mpPointsTableWidget->selectedItems().size() > 0) { @@ -650,7 +646,7 @@ void ShapePropertiesDialog::movePointUp() if (row == 0) { return; } - if (row == 1 && (lineType == LineAnnotation::ConnectionType || lineType == LineAnnotation::TransitionType)) { + if (row == 1 && (mpLineAnnotation && (mpLineAnnotation->isConnection() || mpLineAnnotation->isTransition()))) { return; } QTableWidgetItem *pSourceItemX = mpPointsTableWidget->takeItem(row, 0); @@ -667,9 +663,7 @@ void ShapePropertiesDialog::movePointUp() void ShapePropertiesDialog::movePointDown() { - LineAnnotation::LineType lineType = LineAnnotation::ShapeType; - if (mpLineAnnotation) lineType = mpLineAnnotation->getLineType(); - if (lineType == LineAnnotation::InitialStateType) { + if (mpLineAnnotation && mpLineAnnotation->isInitialState()) { return; } if (mpPointsTableWidget->selectedItems().size() > 0) { @@ -677,7 +671,7 @@ void ShapePropertiesDialog::movePointDown() if (row == mpPointsTableWidget->rowCount() - 1) { return; } - if (row == mpPointsTableWidget->rowCount() - 2 && (lineType == LineAnnotation::ConnectionType || lineType == LineAnnotation::TransitionType)) { + if (row == mpPointsTableWidget->rowCount() - 2 && (mpLineAnnotation && (mpLineAnnotation->isConnection() || mpLineAnnotation->isTransition()))) { return; } QTableWidgetItem *pSourceItemX = mpPointsTableWidget->takeItem(row, 0); @@ -695,9 +689,7 @@ void ShapePropertiesDialog::movePointDown() void ShapePropertiesDialog::addPoint() { if (mpPointsTableWidget->selectedItems().size() > 0) { - LineAnnotation::LineType lineType = LineAnnotation::ShapeType; - if (mpLineAnnotation) lineType = mpLineAnnotation->getLineType(); - if (lineType == LineAnnotation::InitialStateType) { + if (mpLineAnnotation && mpLineAnnotation->isInitialState()) { return; } int row = mpPointsTableWidget->selectedItems().at(0)->row(); @@ -726,9 +718,7 @@ void ShapePropertiesDialog::addPoint() mpPointsTableWidget->setItem(row + 1, 1, pTableWidgetItemY); mpPointsTableWidget->setCurrentCell(row + 1, 0); } - } else if (mpLineAnnotation && mpPointsTableWidget->rowCount() == 2 && - (mpLineAnnotation->getLineType() == LineAnnotation::ConnectionType || - mpLineAnnotation->getLineType() == LineAnnotation::TransitionType)) { + } else if (mpLineAnnotation && mpPointsTableWidget->rowCount() == 2 && (mpLineAnnotation->isConnection() || mpLineAnnotation->isTransition())) { /* get middle of two surronding points */ QPointF point1(mpPointsTableWidget->item(0, 0)->text().toDouble(), mpPointsTableWidget->item(0, 1)->text().toDouble()); QPointF point2(mpPointsTableWidget->item(1, 0)->text().toDouble(), mpPointsTableWidget->item(1, 1)->text().toDouble()); @@ -749,10 +739,8 @@ void ShapePropertiesDialog::removePoint() { if (mpPointsTableWidget->selectedItems().size() > 0) { if ((mpLineAnnotation && mpPointsTableWidget->rowCount() > 2) || (mpPolygonAnnotation && mpPointsTableWidget->rowCount() > 4)) { - LineAnnotation::LineType lineType = LineAnnotation::ShapeType; - if (mpLineAnnotation) lineType = mpLineAnnotation->getLineType(); int row = mpPointsTableWidget->selectedItems().at(0)->row(); - if (lineType == LineAnnotation::InitialStateType && row == 0) { + if (mpLineAnnotation && mpLineAnnotation->isInitialState() && row == 0) { return; } mpPointsTableWidget->removeRow(row); @@ -914,23 +902,20 @@ bool ShapePropertiesDialog::applyShapeProperties() #endif // QT_VERSION_CHECK } } - LineAnnotation::LineType lineType = LineAnnotation::ShapeType; - if (mpLineAnnotation) { - lineType = mpLineAnnotation->getLineType(); - if (lineType == LineAnnotation::ConnectionType || lineType == LineAnnotation::TransitionType) { - mpLineAnnotation->adjustGeometries(); - } + + if (mpLineAnnotation && (mpLineAnnotation->isConnection() || mpLineAnnotation->isTransition())) { + mpLineAnnotation->adjustGeometries(); } // if nothing has changed then just simply return true. if (mOldAnnotation.compare(mpShapeAnnotation->getOMCShapeAnnotation()) == 0) { return true; - } else if (mpLineAnnotation && lineType == LineAnnotation::ConnectionType) { + } else if (mpLineAnnotation && mpLineAnnotation->isConnection()) { // 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()->updateModelText(); - } else if (mpLineAnnotation && lineType == LineAnnotation::TransitionType) { + } else if (mpLineAnnotation && mpLineAnnotation->isTransition()) { // create a UpdateTransitionCommand object and push it to the undo stack. UpdateTransitionCommand *pUpdateTransitionCommand; pUpdateTransitionCommand = new UpdateTransitionCommand(mpLineAnnotation, mpLineAnnotation->getCondition(), mpLineAnnotation->getImmediate(), mpLineAnnotation->getReset(), @@ -939,7 +924,7 @@ bool ShapePropertiesDialog::applyShapeProperties() mpLineAnnotation->getPriority(), mpShapeAnnotation->getOMCShapeAnnotation()); mpShapeAnnotation->getGraphicsView()->getModelWidget()->getUndoStack()->push(pUpdateTransitionCommand); mpShapeAnnotation->getGraphicsView()->getModelWidget()->updateModelText(); - } else if (mpLineAnnotation && lineType == LineAnnotation::InitialStateType) { + } else if (mpLineAnnotation && mpLineAnnotation->isInitialState()) { // create a UpdateInitialStateCommand object and push it to the undo stack. UpdateInitialStateCommand *pUpdateInitialStateCommand; pUpdateInitialStateCommand = new UpdateInitialStateCommand(mpLineAnnotation, mOldAnnotation, mpShapeAnnotation->getOMCShapeAnnotation()); diff --git a/OMEdit/OMEditLIB/Annotations/TextAnnotation.cpp b/OMEdit/OMEditLIB/Annotations/TextAnnotation.cpp index 152f8ff9769..152d68e1bf8 100644 --- a/OMEdit/OMEditLIB/Annotations/TextAnnotation.cpp +++ b/OMEdit/OMEditLIB/Annotations/TextAnnotation.cpp @@ -343,7 +343,7 @@ void TextAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsItem *op } // text annotation on a transition LineAnnotation *pTransitionLineAnnotation = dynamic_cast(parentItem()); - if (pTransitionLineAnnotation && pTransitionLineAnnotation->getLineType() == LineAnnotation::TransitionType + if (pTransitionLineAnnotation && pTransitionLineAnnotation->isTransition() && pTransitionLineAnnotation->getGraphicsView() && pTransitionLineAnnotation->getGraphicsView()->isVisualizationView()) { if (pTransitionLineAnnotation->isActiveState()) { painter->setOpacity(1.0); diff --git a/OMEdit/OMEditLIB/Element/CornerItem.cpp b/OMEdit/OMEditLIB/Element/CornerItem.cpp index 7fbf5561fa4..37908dbf995 100644 --- a/OMEdit/OMEditLIB/Element/CornerItem.cpp +++ b/OMEdit/OMEditLIB/Element/CornerItem.cpp @@ -155,9 +155,8 @@ void CornerItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) LineAnnotation *pLineAnnotation = dynamic_cast(mpShapeAnnotation); if (pLineAnnotation) { QVector points = pLineAnnotation->getPoints(); - LineAnnotation::LineType lineType = pLineAnnotation->getLineType(); - if ((((lineType == LineAnnotation::ConnectionType || lineType == LineAnnotation::TransitionType) && (mConnectedPointIndex == 0 || mConnectedPointIndex == points.size() - 1)) - || (lineType == LineAnnotation::InitialStateType && mConnectedPointIndex == 0))) { + if ((((pLineAnnotation->isConnection() || pLineAnnotation->isTransition()) && (mConnectedPointIndex == 0 || mConnectedPointIndex == points.size() - 1)) + || (pLineAnnotation->isInitialState() && mConnectedPointIndex == 0))) { QGraphicsItem::mouseMoveEvent(event); return; } diff --git a/OMEdit/OMEditLIB/Modeling/ModelWidgetContainer.cpp b/OMEdit/OMEditLIB/Modeling/ModelWidgetContainer.cpp index 62c22b543fe..82759f0677f 100644 --- a/OMEdit/OMEditLIB/Modeling/ModelWidgetContainer.cpp +++ b/OMEdit/OMEditLIB/Modeling/ModelWidgetContainer.cpp @@ -1449,16 +1449,16 @@ void GraphicsView::addConnectionDetails(LineAnnotation *pConnectionLineAnnotatio if (pStartElement) { if (pStartElement->getRootParentElement()) { pStartElement->getRootParentElement()->addConnectionDetails(pConnectionLineAnnotation); - if (pConnectionLineAnnotation->getLineType() == LineAnnotation::TransitionType) { + if (pConnectionLineAnnotation->isTransition()) { pStartElement->getRootParentElement()->setHasTransition(true); - } else if (pConnectionLineAnnotation->getLineType() == LineAnnotation::InitialStateType) { + } else if (pConnectionLineAnnotation->isInitialState()) { pStartElement->getRootParentElement()->setIsInitialState(true); } } else { pStartElement->addConnectionDetails(pConnectionLineAnnotation); - if (pConnectionLineAnnotation->getLineType() == LineAnnotation::TransitionType) { + if (pConnectionLineAnnotation->isTransition()) { pStartElement->setHasTransition(true); - } else if (pConnectionLineAnnotation->getLineType() == LineAnnotation::InitialStateType) { + } else if (pConnectionLineAnnotation->isInitialState()) { pStartElement->setIsInitialState(false); } } @@ -1468,12 +1468,12 @@ void GraphicsView::addConnectionDetails(LineAnnotation *pConnectionLineAnnotatio if (pEndElement) { if (pEndElement->getRootParentElement()) { pEndElement->getRootParentElement()->addConnectionDetails(pConnectionLineAnnotation); - if (pConnectionLineAnnotation->getLineType() == LineAnnotation::TransitionType) { + if (pConnectionLineAnnotation->isTransition()) { pEndElement->getRootParentElement()->setHasTransition(true); } } else { pEndElement->addConnectionDetails(pConnectionLineAnnotation); - if (pConnectionLineAnnotation->getLineType() == LineAnnotation::TransitionType) { + if (pConnectionLineAnnotation->isTransition()) { pEndElement->setHasTransition(true); } } @@ -1711,16 +1711,16 @@ void GraphicsView::removeConnectionDetails(LineAnnotation *pConnectionLineAnnota if (pStartElement) { if (pStartElement->getRootParentElement()) { pStartElement->getRootParentElement()->removeConnectionDetails(pConnectionLineAnnotation); - if (pConnectionLineAnnotation->getLineType() == LineAnnotation::TransitionType) { + if (pConnectionLineAnnotation->isTransition()) { pStartElement->getRootParentElement()->setHasTransition(false); - } else if (pConnectionLineAnnotation->getLineType() == LineAnnotation::InitialStateType) { + } else if (pConnectionLineAnnotation->isInitialState()) { pStartElement->getRootParentElement()->setIsInitialState(false); } } else { pStartElement->removeConnectionDetails(pConnectionLineAnnotation); - if (pConnectionLineAnnotation->getLineType() == LineAnnotation::TransitionType) { + if (pConnectionLineAnnotation->isTransition()) { pStartElement->setHasTransition(false); - } else if (pConnectionLineAnnotation->getLineType() == LineAnnotation::InitialStateType) { + } else if (pConnectionLineAnnotation->isInitialState()) { pStartElement->setIsInitialState(false); } } @@ -1730,12 +1730,12 @@ void GraphicsView::removeConnectionDetails(LineAnnotation *pConnectionLineAnnota if (pEndElement) { if (pEndElement->getRootParentElement()) { pEndElement->getRootParentElement()->removeConnectionDetails(pConnectionLineAnnotation); - if (pConnectionLineAnnotation->getLineType() == LineAnnotation::TransitionType) { + if (pConnectionLineAnnotation->isTransition()) { pEndElement->getRootParentElement()->setHasTransition(false); } } else { pEndElement->removeConnectionDetails(pConnectionLineAnnotation); - if (pConnectionLineAnnotation->getLineType() == LineAnnotation::TransitionType) { + if (pConnectionLineAnnotation->isTransition()) { pEndElement->setHasTransition(false); } } @@ -2922,7 +2922,7 @@ bool GraphicsView::isAnyItemSelectedAndEditable(int key) if (pShapeAnnotation && !pShapeAnnotation->isInheritedShape()) { LineAnnotation *pLineAnnotation = dynamic_cast(pShapeAnnotation); // if the shape is connection line then we only return true for certain cases. - if (pLineAnnotation && pLineAnnotation->getLineType() == LineAnnotation::ConnectionType) { + if (pLineAnnotation && pLineAnnotation->isConnection()) { switch (key) { case Qt::Key_Delete: selectedAndEditable = true; @@ -3582,7 +3582,7 @@ void GraphicsView::copyItems(bool cut) components << QString("%1 %2%3 %4;").arg(pComponent->getClassName(), pComponent->getName(), "", pComponent->getPlacementAnnotation(true)); } else if (ShapeAnnotation *pShapeAnnotation = dynamic_cast(selectedItems.at(i))) { LineAnnotation *pLineAnnotation = dynamic_cast(selectedItems.at(i)); - if (pLineAnnotation && pLineAnnotation->getLineType() == LineAnnotation::ConnectionType) { + if (pLineAnnotation && pLineAnnotation->isConnection()) { // Only consider the connection for copying if both the start and the end components are selected. if (pLineAnnotation->getStartElement()->getRootParentElement()->isSelected() && pLineAnnotation->getEndElement()->getRootParentElement()->isSelected()) { pMimeData->addConnection(pLineAnnotation); @@ -3642,12 +3642,12 @@ void GraphicsView::modelicaOneShapeContextMenu(ShapeAnnotation *pShapeAnnotation pMenu->addSeparator(); pMenu->addAction(mpCutAction); pMenu->addAction(mpCopyAction); - if (pLineAnnotation && pLineAnnotation->getLineType() == LineAnnotation::ConnectionType) { + if (pLineAnnotation && pLineAnnotation->isConnection()) { // nothing special for connection - } else if (pLineAnnotation && pLineAnnotation->getLineType() == LineAnnotation::TransitionType) { + } else if (pLineAnnotation && pLineAnnotation->isTransition()) { pMenu->addSeparator(); pMenu->addAction(pShapeAnnotation->getEditTransitionAction()); - } else if (pLineAnnotation && pLineAnnotation->getLineType() == LineAnnotation::ShapeType) { + } else if (pLineAnnotation && pLineAnnotation->isLineShape()) { pMenu->addAction(mpDuplicateAction); pMenu->addSeparator(); pMenu->addAction(mpManhattanizeAction); @@ -4739,7 +4739,7 @@ void GraphicsView::mouseDoubleClickEvent(QMouseEvent *event) if (!isCreatingConnection() && !isCreatingTransition() && pShapeAnnotation && pShapeAnnotation->getGraphicsView()) { if (mpModelWidget->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::Modelica) { LineAnnotation *pTransitionLineAnnotation = dynamic_cast(pShapeAnnotation); - if (pTransitionLineAnnotation && pTransitionLineAnnotation->getLineType() == LineAnnotation::TransitionType) { + if (pTransitionLineAnnotation && pTransitionLineAnnotation->isTransition()) { pShapeAnnotation->editTransition(); } else { pShapeAnnotation->showShapeProperties(); @@ -4748,7 +4748,7 @@ void GraphicsView::mouseDoubleClickEvent(QMouseEvent *event) } if (mpModelWidget->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::OMS) { LineAnnotation *pConnectionLineAnnotation = dynamic_cast(pShapeAnnotation); - if (pConnectionLineAnnotation && pConnectionLineAnnotation->getLineType() == LineAnnotation::ConnectionType) { + if (pConnectionLineAnnotation && pConnectionLineAnnotation->isConnection()) { pConnectionLineAnnotation->showOMSConnection(); } } else if (mpModelWidget->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::CompositeModel) {