Skip to content

Commit

Permalink
Do not allow invalid connections (#10756)
Browse files Browse the repository at this point in the history
Fixes #4337
Show the error message and reject the connection
  • Loading branch information
adeas31 committed May 26, 2023
1 parent c2d037f commit 71367fb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
30 changes: 15 additions & 15 deletions OMEdit/OMEditLIB/Annotations/LineAnnotation.cpp
Expand Up @@ -2458,21 +2458,21 @@ void CreateConnectionDialog::createConnection()
mpConnectionLineAnnotation->setStartElementName(startElementName);
mpConnectionLineAnnotation->setEndElementName(endElementName);
if (mpGraphicsView->getModelWidget()->isNewApi()) {
mpConnectionLineAnnotation->setLine(new ModelInstance::Line(mpGraphicsView->getModelWidget()->getModelInstance()));
mpConnectionLineAnnotation->updateLine();
mpConnectionLineAnnotation->drawCornerItems();
mpConnectionLineAnnotation->setCornerItemsActiveOrPassive();
ModelInfo oldModelInfo = mpGraphicsView->getModelWidget()->createModelInfo();
mpGraphicsView->addConnectionToView(mpConnectionLineAnnotation, false);
mpGraphicsView->addConnectionToClass(mpConnectionLineAnnotation);
ModelInfo newModelInfo = mpGraphicsView->getModelWidget()->createModelInfo();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new OMCUndoCommand(mpGraphicsView->getModelWidget()->getLibraryTreeItem(), oldModelInfo, newModelInfo, "Add Connection"));
mpGraphicsView->getModelWidget()->updateModelText();

if (!mpGraphicsView->getModelWidget()->getModelInstance()->isValidConnection(startElementName, endElementName)) {
MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica,
GUIMessages::getMessage(GUIMessages::MISMATCHED_CONNECTORS_IN_CONNECT).arg(startElementName, endElementName),
Helper::scriptingKind, Helper::errorLevel));
if (mpGraphicsView->getModelWidget()->getModelInstance()->isValidConnection(startElementName, endElementName)) {
mpConnectionLineAnnotation->setLine(new ModelInstance::Line(mpGraphicsView->getModelWidget()->getModelInstance()));
mpConnectionLineAnnotation->updateLine();
mpConnectionLineAnnotation->drawCornerItems();
mpConnectionLineAnnotation->setCornerItemsActiveOrPassive();
ModelInfo oldModelInfo = mpGraphicsView->getModelWidget()->createModelInfo();
mpGraphicsView->addConnectionToView(mpConnectionLineAnnotation, false);
mpGraphicsView->addConnectionToClass(mpConnectionLineAnnotation);
ModelInfo newModelInfo = mpGraphicsView->getModelWidget()->createModelInfo();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new OMCUndoCommand(mpGraphicsView->getModelWidget()->getLibraryTreeItem(), oldModelInfo, newModelInfo, "Add Connection"));
mpGraphicsView->getModelWidget()->updateModelText();
} else {
QMessageBox::critical(MainWindow::instance(), QString("%1 - %2").arg(Helper::applicationName, Helper::error),
GUIMessages::getMessage(GUIMessages::MISMATCHED_CONNECTORS_IN_CONNECT).arg(startElementName, endElementName), Helper::ok);
reject();
}
} else {
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddConnectionCommand(mpConnectionLineAnnotation, true));
Expand Down
30 changes: 15 additions & 15 deletions OMEdit/OMEditLIB/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -3244,21 +3244,21 @@ void GraphicsView::addConnection(Element *pElement)
} else {
if (mpModelWidget->isNewApi()) {
if (!connectionExists(startElementName, endElementName, false)) {
mpConnectionLineAnnotation->setLine(new ModelInstance::Line(mpModelWidget->getModelInstance()));
mpConnectionLineAnnotation->updateLine();
mpConnectionLineAnnotation->drawCornerItems();
mpConnectionLineAnnotation->setCornerItemsActiveOrPassive();
ModelInfo oldModelInfo = mpModelWidget->createModelInfo();
addConnectionToView(mpConnectionLineAnnotation, false);
addConnectionToClass(mpConnectionLineAnnotation);
ModelInfo newModelInfo = mpModelWidget->createModelInfo();
mpModelWidget->getUndoStack()->push(new OMCUndoCommand(mpModelWidget->getLibraryTreeItem(), oldModelInfo, newModelInfo, "Add Connection"));
mpModelWidget->updateModelText();

if (!mpModelWidget->getModelInstance()->isValidConnection(startElementName, endElementName)) {
MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica,
GUIMessages::getMessage(GUIMessages::MISMATCHED_CONNECTORS_IN_CONNECT).arg(startElementName, endElementName),
Helper::scriptingKind, Helper::errorLevel));
if (mpModelWidget->getModelInstance()->isValidConnection(startElementName, endElementName)) {
mpConnectionLineAnnotation->setLine(new ModelInstance::Line(mpModelWidget->getModelInstance()));
mpConnectionLineAnnotation->updateLine();
mpConnectionLineAnnotation->drawCornerItems();
mpConnectionLineAnnotation->setCornerItemsActiveOrPassive();
ModelInfo oldModelInfo = mpModelWidget->createModelInfo();
addConnectionToView(mpConnectionLineAnnotation, false);
addConnectionToClass(mpConnectionLineAnnotation);
ModelInfo newModelInfo = mpModelWidget->createModelInfo();
mpModelWidget->getUndoStack()->push(new OMCUndoCommand(mpModelWidget->getLibraryTreeItem(), oldModelInfo, newModelInfo, "Add Connection"));
mpModelWidget->updateModelText();
} else {
QMessageBox::critical(MainWindow::instance(), QString("%1 - %2").arg(Helper::applicationName, Helper::error),
GUIMessages::getMessage(GUIMessages::MISMATCHED_CONNECTORS_IN_CONNECT).arg(startElementName, endElementName), Helper::ok);
removeCurrentConnection();
}
} else {
removeCurrentConnection();
Expand Down

0 comments on commit 71367fb

Please sign in to comment.