Skip to content

Commit

Permalink
Copy the connector to both icon and diagram layer (#11966)
Browse files Browse the repository at this point in the history
Fix for #11961
Only paste the connections on diagram layer
  • Loading branch information
adeas31 committed Feb 8, 2024
1 parent 3a403cf commit ea459d0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
7 changes: 3 additions & 4 deletions OMEdit/OMEditLIB/Element/Element.cpp
Expand Up @@ -1233,7 +1233,6 @@ QString Element::getTransformationAnnotation(bool ModelicaSyntax)
// add the origin
if (mTransformation.getOrigin().isDynamicSelectExpression() || mTransformation.getOrigin().toQString().compare(QStringLiteral("{0,0}")) != 0) {
annotationStringList.append(QString("origin=%1").arg(mTransformation.getOrigin().toQString()));

}
// add extent points
if (mTransformation.getExtent().isDynamicSelectExpression() || mTransformation.getExtent().size() > 1) {
Expand Down Expand Up @@ -1261,7 +1260,7 @@ QString Element::getPlacementAnnotation(bool ModelicaSyntax)
placementAnnotationString.append(QString("visible=%1,").arg(mTransformation.getVisible().toQString()));
}
}
if ((mpLibraryTreeItem && mpLibraryTreeItem->isConnector()) || (mpGraphicsView->getModelWidget()->isNewApi() && mpModel->isConnector())) {
if ((mpLibraryTreeItem && mpLibraryTreeItem->isConnector()) || (mpGraphicsView->getModelWidget()->isNewApi() && mpModel && mpModel->isConnector())) {
if (mpGraphicsView->getViewType() == StringHandler::Icon) {
// first get the component from diagram view and get the transformations
Element *pElement = mpGraphicsView->getModelWidget()->getDiagramGraphicsView()->getElementObject(getName());
Expand Down Expand Up @@ -1327,7 +1326,7 @@ QString Element::getOMCPlacementAnnotation(QPointF position)
if (mTransformation.isValid()) {
placementAnnotationString.append(mTransformation.getVisible() ? "true" : "false");
}
if (mpLibraryTreeItem && mpLibraryTreeItem->isConnector()) {
if ((mpLibraryTreeItem && mpLibraryTreeItem->isConnector()) || (mpGraphicsView->getModelWidget()->isNewApi() && mpModel && mpModel->isConnector())) {
if (mpGraphicsView->getViewType() == StringHandler::Icon) {
// first get the component from diagram view and get the transformations
Element *pElement;
Expand Down Expand Up @@ -3585,7 +3584,7 @@ void Element::duplicate()
QPointF gridStep(mpGraphicsView->mMergedCoOrdinateSystem.getHorizontalGridStep() * 5, mpGraphicsView->mMergedCoOrdinateSystem.getVerticalGridStep() * 5);
// add component
if (mpGraphicsView->getModelWidget()->isNewApi()) {
ModelInstance::Component *pModelInstanceComponent = GraphicsView::createModelInstanceComponent(mpGraphicsView->getModelWidget()->getModelInstance(), name, getClassName());
ModelInstance::Component *pModelInstanceComponent = GraphicsView::createModelInstanceComponent(mpGraphicsView->getModelWidget()->getModelInstance(), name, getClassName(), false);
mpGraphicsView->addElementToView(pModelInstanceComponent, false, true, false, QPointF(0, 0), getOMCPlacementAnnotation(gridStep), false);
// set modifiers
if (mpModelComponent->getModifier()) {
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditLIB/Modeling/Model.h
Expand Up @@ -582,6 +582,7 @@ namespace ModelInstance
const QString &getName() const {return mName;}
const QString &getRootType() const;
bool isMissing() const {return mMissing;}
void setRestriction(const QString &restriction) {mRestriction = restriction;}
const QString &getRestriction() const {return mRestriction;}
bool isConnector() const;
bool isExpandableConnector() const;
Expand Down
25 changes: 18 additions & 7 deletions OMEdit/OMEditLIB/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -879,17 +879,20 @@ bool GraphicsView::performElementCreationChecks(LibraryTreeItem *pLibraryTreeIte
* \param pModelInstance
* \param name
* \param className
* \param isConnector
* \return
*/
ModelInstance::Component *GraphicsView::createModelInstanceComponent(ModelInstance::Model *pModelInstance, const QString &name, const QString &className)
ModelInstance::Component *GraphicsView::createModelInstanceComponent(ModelInstance::Model *pModelInstance, const QString &name, const QString &className, bool isConnector)
{
ModelInstance::Component *pComponent = new ModelInstance::Component(pModelInstance);
pComponent->setName(name);
pComponent->setType(className);
/* We use getModelInstanceAnnotation here for bettter performance
/* We use getModelInstance with icon flag for bettter performance
* This model will be updated right after this so it doesn't matter if the Component has complete model or not.
*/
pComponent->setModel(new ModelInstance::Model(MainWindow::instance()->getOMCProxy()->getModelInstance(className, "", false, true)));
ModelInstance::Model *pModel = new ModelInstance::Model(MainWindow::instance()->getOMCProxy()->getModelInstance(className, "", false, true));
pModel->setRestriction(isConnector ? "connector" : "model");
pComponent->setModel(pModel);
pModelInstance->addElement(pComponent);
return pComponent;
}
Expand Down Expand Up @@ -963,7 +966,7 @@ bool GraphicsView::addComponent(QString className, QPointF position)
|| (mViewType == StringHandler::Icon && (type == StringHandler::Connector || type == StringHandler::ExpandableConnector))) {
if (mpModelWidget->isNewApi()) {
ModelInfo oldModelInfo = mpModelWidget->createModelInfo();
ModelInstance::Component *pComponent = GraphicsView::createModelInstanceComponent(mpModelWidget->getModelInstance(), name, pLibraryTreeItem->getNameStructure());
ModelInstance::Component *pComponent = GraphicsView::createModelInstanceComponent(mpModelWidget->getModelInstance(), name, pLibraryTreeItem->getNameStructure(), pLibraryTreeItem->isConnector());
addElementToView(pComponent, false, true, true, position, "", true);
ModelInfo newModelInfo = mpModelWidget->createModelInfo();
mpModelWidget->getUndoStack()->push(new OMCUndoCommand(mpModelWidget->getLibraryTreeItem(), oldModelInfo, newModelInfo, "Add Element"));
Expand Down Expand Up @@ -3631,6 +3634,7 @@ void GraphicsView::copyItems(bool cut)
QJsonObject componentJsonObject;
componentJsonObject.insert(QLatin1String("classname"), pElement->getClassName());
componentJsonObject.insert(QLatin1String("name"), pElement->getName());
componentJsonObject.insert(QLatin1String("connector"), pElement->getModel() ? pElement->getModel()->isConnector() : false);
componentJsonObject.insert(QLatin1String("placement"), pElement->getOMCPlacementAnnotation(QPointF(0, 0)));
componentsJsonArray.append(componentJsonObject);
} else if (ShapeAnnotation *pShapeAnnotation = dynamic_cast<ShapeAnnotation*>(itemsList.at(i))) {
Expand Down Expand Up @@ -4049,8 +4053,11 @@ void GraphicsView::pasteItems()
QJsonObject componentObject = componentsArray.at(i).toObject();
const QString className = componentObject.value("classname").toString();
const QString name = componentObject.value("name").toString();
const bool connector = componentObject.value("connector").toBool();
const QString placement = componentObject.value("placement").toString();
addElementToView(GraphicsView::createModelInstanceComponent(mpModelWidget->getModelInstance(), name, className), false, false, false, QPointF(0, 0), placement, false);
const int numberOfElements = mElementsList.size();
addElementToView(GraphicsView::createModelInstanceComponent(mpModelWidget->getModelInstance(), name, className, connector), false, false, false, QPointF(0, 0), placement, false);
assert(mElementsList.size() > numberOfElements);
mElementsList.last()->setSelected(true);
}
}
Expand All @@ -4073,8 +4080,12 @@ void GraphicsView::pasteItems()
LineAnnotation *pConnectionLineAnnotation = new LineAnnotation(lineShape, 0, 0, this);
pConnectionLineAnnotation->setStartElementName(connectionObject.value("from").toString());
pConnectionLineAnnotation->setEndElementName(connectionObject.value("to").toString());
addConnectionToView(pConnectionLineAnnotation, false);
mConnectionsList.last()->setSelected(true);
// always add the connections to diagram layer.
GraphicsView *pDiagramGraphicsView = mpModelWidget->getDiagramGraphicsView();
pDiagramGraphicsView->addConnectionToView(pConnectionLineAnnotation, false);
if (mViewType == StringHandler::Diagram) {
mConnectionsList.last()->setSelected(true);
}
}
}
// add shapes
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditLIB/Modeling/ModelWidgetContainer.h
Expand Up @@ -249,7 +249,7 @@ class GraphicsView : public QGraphicsView
QAction* getFlipHorizontalAction() {return mpFlipHorizontalAction;}
QAction* getFlipVerticalAction() {return mpFlipVerticalAction;}
bool performElementCreationChecks(LibraryTreeItem *pLibraryTreeItem, QString *name, QString *defaultPrefix);
static ModelInstance::Component* createModelInstanceComponent(ModelInstance::Model *pModelInstance, const QString &name, const QString &className);
static ModelInstance::Component* createModelInstanceComponent(ModelInstance::Model *pModelInstance, const QString &name, const QString &className, bool isConnector);
bool addComponent(QString className, QPointF position);
void addComponentToView(QString name, LibraryTreeItem *pLibraryTreeItem, QString annotation, QPointF position,
ElementInfo *pComponentInfo, bool addObject, bool openingClass, bool emitComponentAdded);
Expand Down

0 comments on commit ea459d0

Please sign in to comment.