From f81f6ed24d92d7d6b45c236f12a9fddb8d68529d Mon Sep 17 00:00:00 2001 From: Adeel Asghar Date: Thu, 14 Sep 2023 13:01:58 +0200 Subject: [PATCH] Preserve the dynamic values while dumping the annotation (#11181) --- OMEdit/OMEditLIB/Element/Element.cpp | 43 ++++++++++++++-------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/OMEdit/OMEditLIB/Element/Element.cpp b/OMEdit/OMEditLIB/Element/Element.cpp index 66d93e46064..9d7273de7ca 100644 --- a/OMEdit/OMEditLIB/Element/Element.cpp +++ b/OMEdit/OMEditLIB/Element/Element.cpp @@ -1227,20 +1227,21 @@ QString Element::getTransformationAnnotation(bool ModelicaSyntax) } else if (mpGraphicsView->getViewType() == StringHandler::Diagram) { annotationString.append(ModelicaSyntax ? "transformation(" : "transformation=transformation("); } + QStringList annotationStringList; // add the origin - annotationString.append("origin={").append(QString::number(mTransformation.getOrigin().x())).append(","); - annotationString.append(QString::number(mTransformation.getOrigin().y())).append("}, "); + if (mTransformation.getOrigin().isDynamicSelectExpression() || mTransformation.getOrigin().toQString().compare(QStringLiteral("{0,0}")) != 0) { + annotationStringList.append(QString("origin=%1").arg(mTransformation.getOrigin().toQString())); + + } // add extent points - ExtentAnnotation extent = mTransformation.getExtent(); - QPointF extent1 = extent.at(0); - QPointF extent2 = extent.at(1); - annotationString.append("extent={").append("{").append(QString::number(extent1.x())); - annotationString.append(",").append(QString::number(extent1.y())).append("},"); - annotationString.append("{").append(QString::number(extent2.x())).append(","); - annotationString.append(QString::number(extent2.y())).append("}}, "); + if (mTransformation.getExtent().isDynamicSelectExpression() || mTransformation.getExtent().size() > 1) { + annotationStringList.append(QString("extent=%1").arg(mTransformation.getExtent().toQString())); + } // add icon rotation - annotationString.append("rotation=").append(QString::number(mTransformation.getRotateAngle())).append(")"); - return annotationString; + if (mTransformation.getRotateAngle().isDynamicSelectExpression() || mTransformation.getRotateAngle().toQString().compare(QStringLiteral("0")) != 0) { + annotationStringList.append(QString("rotation=%1").arg(mTransformation.getRotateAngle().toQString())); + } + return annotationString.append(annotationStringList.join(",")).append(")"); } /*! @@ -1254,30 +1255,30 @@ QString Element::getPlacementAnnotation(bool ModelicaSyntax) // create the placement annotation string QString placementAnnotationString = ModelicaSyntax ? "annotation(Placement(" : "annotate=Placement("; if (mTransformation.isValid()) { - placementAnnotationString.append("visible=").append(mTransformation.getVisible() ? "true" : "false"); + if (mTransformation.getVisible().isDynamicSelectExpression() || mTransformation.getVisible().toQString().compare(QStringLiteral("true")) != 0) { + placementAnnotationString.append(QString("visible=%1,").arg(mTransformation.getVisible().toQString())); + } } if ((mpLibraryTreeItem && mpLibraryTreeItem->isConnector()) || (mpGraphicsView->getModelWidget()->isNewApi() && mpModel->isConnector())) { if (mpGraphicsView->getViewType() == StringHandler::Icon) { // first get the component from diagram view and get the transformations - Element *pElement; - pElement = mpGraphicsView->getModelWidget()->getDiagramGraphicsView()->getElementObject(getName()); + Element *pElement = mpGraphicsView->getModelWidget()->getDiagramGraphicsView()->getElementObject(getName()); if (pElement) { - placementAnnotationString.append(", ").append(pElement->getTransformationAnnotation(ModelicaSyntax)); + placementAnnotationString.append(pElement->getTransformationAnnotation(ModelicaSyntax)).append(", "); } // then get the icon transformations - placementAnnotationString.append(", ").append(getTransformationAnnotation(ModelicaSyntax)); + placementAnnotationString.append(getTransformationAnnotation(ModelicaSyntax)); } else if (mpGraphicsView->getViewType() == StringHandler::Diagram) { // first get the component from diagram view and get the transformations - placementAnnotationString.append(", ").append(getTransformationAnnotation(ModelicaSyntax)); + placementAnnotationString.append(getTransformationAnnotation(ModelicaSyntax)).append(", "); // then get the icon transformations - Element *pElement; - pElement = mpGraphicsView->getModelWidget()->getIconGraphicsView()->getElementObject(getName()); + Element *pElement = mpGraphicsView->getModelWidget()->getIconGraphicsView()->getElementObject(getName()); if (pElement) { - placementAnnotationString.append(", ").append(pElement->getTransformationAnnotation(ModelicaSyntax)); + placementAnnotationString.append(pElement->getTransformationAnnotation(ModelicaSyntax)); } } } else { - placementAnnotationString.append(", ").append(getTransformationAnnotation(ModelicaSyntax)); + placementAnnotationString.append(getTransformationAnnotation(ModelicaSyntax)); } placementAnnotationString.append(ModelicaSyntax ? "))" : ")"); return placementAnnotationString;