Skip to content

Commit

Permalink
Use setElementAnnotation instead of updateComponent (#11211)
Browse files Browse the repository at this point in the history
Fixes #11116
  • Loading branch information
adeas31 committed Sep 18, 2023
1 parent ba6e7df commit 3825633
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
6 changes: 3 additions & 3 deletions OMEdit/OMEditLIB/Element/Element.cpp
Expand Up @@ -1253,7 +1253,7 @@ QString Element::getTransformationAnnotation(bool ModelicaSyntax)
QString Element::getPlacementAnnotation(bool ModelicaSyntax)
{
// create the placement annotation string
QString placementAnnotationString = ModelicaSyntax ? "annotation(Placement(" : "annotate=Placement(";
QString placementAnnotationString = ModelicaSyntax ? "Placement(" : "annotate=Placement(";
if (mTransformation.isValid()) {
if (mTransformation.getVisible().isDynamicSelectExpression() || mTransformation.getVisible().toQString().compare(QStringLiteral("true")) != 0) {
placementAnnotationString.append(QString("visible=%1,").arg(mTransformation.getVisible().toQString()));
Expand All @@ -1280,7 +1280,7 @@ QString Element::getPlacementAnnotation(bool ModelicaSyntax)
} else {
placementAnnotationString.append(getTransformationAnnotation(ModelicaSyntax));
}
placementAnnotationString.append(ModelicaSyntax ? "))" : ")");
placementAnnotationString.append(ModelicaSyntax ? ")" : ")");
return placementAnnotationString;
}

Expand Down Expand Up @@ -3167,7 +3167,7 @@ void Element::updatePlacementAnnotation()
}
} else {
OMCProxy *pOMCProxy = MainWindow::instance()->getOMCProxy();
pOMCProxy->updateComponent(getName(), getClassName(), mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getNameStructure(), getPlacementAnnotation());
pOMCProxy->setElementAnnotation(mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getNameStructure() % "." % getName(), "$Code((" % getPlacementAnnotation(true) % "))");
}
/* When something is changed in the icon layer then update the LibraryTreeItem in the Library Browser */
if (mpGraphicsView->getViewType() == StringHandler::Icon) {
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditLIB/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -3579,7 +3579,7 @@ void GraphicsView::copyItems(bool cut)
pComponent->getElementInfo()->getModifiersMap(MainWindow::instance()->getOMCProxy(), pComponent->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getNameStructure(), pComponent);
}
pMimeData->addComponent(pComponent);
components << QString("%1 %2%3 %4;").arg(pComponent->getClassName(), pComponent->getName(), "", pComponent->getPlacementAnnotation(true));
components << pComponent->getClassName() % " " % pComponent->getName() % " " % "annotation(" % pComponent->getPlacementAnnotation(true) % ")";
} else if (ShapeAnnotation *pShapeAnnotation = dynamic_cast<ShapeAnnotation*>(selectedItems.at(i))) {
LineAnnotation *pLineAnnotation = dynamic_cast<LineAnnotation*>(selectedItems.at(i));
if (pLineAnnotation && pLineAnnotation->isConnection()) {
Expand Down
34 changes: 27 additions & 7 deletions OMEdit/OMEditLIB/OMC/OMCProxy.cpp
Expand Up @@ -2042,13 +2042,16 @@ bool OMCProxy::renameComponent(QString className, QString oldName, QString newNa
}

/*!
Updates the component annotations.
\param name - the component name
\param className - the component fully qualified name.
\param componentName - the name of the component to update.
\param annotation - the updated annotation.
\return true on success.
*/
* \brief OMCProxy::updateComponent
* Updates the component annotations.
* \param name - the component name
* \param className - the component fully qualified name.
* \param componentName - the name of the component to update.
* \param placementAnnotation - the updated annotation.
* \return true on success.
* \deprecated
* \see OMCProxy::setElementAnnotation(const QString &elementName, QString annotation)
*/
bool OMCProxy::updateComponent(QString name, QString className, QString componentName, QString placementAnnotation)
{
sendCommand("updateComponent(" + name + "," + className + "," + componentName + "," + placementAnnotation + ")");
Expand All @@ -2059,6 +2062,23 @@ bool OMCProxy::updateComponent(QString name, QString className, QString componen
}
}

/*!
* \brief OMCProxy::setElementAnnotation
* Sets the element annotation.
* \param elementName
* \param annotation
* \return true on success.
*/
bool OMCProxy::setElementAnnotation(const QString &elementName, QString annotation)
{
sendCommand("setElementAnnotation(" % elementName % "," + annotation + ")");
if (StringHandler::unparseBool(getResult())) {
return true;
} else {
return false;
}
}

/*!
Renames a component in a class.
\param className - the name of the class.
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditLIB/OMC/OMCProxy.h
Expand Up @@ -188,6 +188,7 @@ class OMCProxy : public QObject
bool deleteComponent(QString name, QString componentName);
bool renameComponent(QString className, QString oldName, QString newName);
bool updateComponent(QString name, QString className, QString componentName, QString placementAnnotation);
bool setElementAnnotation(const QString &elementName, QString annotation);
bool renameComponentInClass(QString className, QString oldName, QString newName);
bool updateConnection(QString className, QString from, QString to, QString annotation);
bool updateConnectionNames(QString className, QString from, QString to, QString fromNew, QString toNew);
Expand Down

0 comments on commit 3825633

Please sign in to comment.