Skip to content

Commit

Permalink
Improve the moving of components in a diagram (#11901) (#11903)
Browse files Browse the repository at this point in the history
Partial fix for issue #11887
Do not try to detect the collision of connections and components whenever a component is updated.
In case of batch operation only do it once.
  • Loading branch information
adeas31 committed Jan 29, 2024
1 parent fc3c2d4 commit ce2ba6b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
5 changes: 3 additions & 2 deletions OMEdit/OMEditLIB/Annotations/RectangleAnnotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,11 @@ QPainterPath RectangleAnnotation::shape() const
{
QPainterPath path;
path.addRoundedRect(getBoundingRect(), mRadius, mRadius);
if (mFillPattern == StringHandler::FillNone)
if (mFillPattern == StringHandler::FillNone) {
return addPathStroker(path);
else
} else {
return path;
}
}

void RectangleAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
Expand Down
8 changes: 4 additions & 4 deletions OMEdit/OMEditLIB/Modeling/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,8 @@ void UpdateComponentTransformationsCommand::redoInternal()
mpComponent->mTransformation = mNewTransformation;
mpComponent->emitTransformChange(mPositionChanged);
mpComponent->emitTransformHasChanged();
if (mpComponent->getGraphicsView()->getViewType() == StringHandler::Diagram && mpComponent->getGraphicsView()->getModelWidget()->isNewApi()) {
mpComponent->getGraphicsView()->handleCollidingConnections();
if (mpComponent->getGraphicsView()->getViewType() == StringHandler::Diagram && pModelWidget->isNewApi()) {
pModelWidget->setHandleCollidingConnectionsNeeded(true);
}
}

Expand Down Expand Up @@ -405,8 +405,8 @@ void UpdateComponentTransformationsCommand::undo()
mpComponent->mTransformation = mOldTransformation;
mpComponent->emitTransformChange(mPositionChanged);
mpComponent->emitTransformHasChanged();
if (mpComponent->getGraphicsView()->getViewType() == StringHandler::Diagram && mpComponent->getGraphicsView()->getModelWidget()->isNewApi()) {
mpComponent->getGraphicsView()->handleCollidingConnections();
if (mpComponent->getGraphicsView()->getViewType() == StringHandler::Diagram && pModelWidget->isNewApi()) {
pModelWidget->setHandleCollidingConnectionsNeeded(true);
}
}

Expand Down
13 changes: 13 additions & 0 deletions OMEdit/OMEditLIB/Modeling/ModelWidgetContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7040,6 +7040,7 @@ void ModelWidget::updateModelText()
setWindowTitle(QString("%1*").arg(mpLibraryTreeItem->getName()));
mUpdateModelTimer.start();
if (isNewApi()) {
callHandleCollidingConnectionsIfNeeded();
// announce the change.
MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel()->emitModelStateChanged(mpLibraryTreeItem->getNameStructure());
}
Expand All @@ -7052,6 +7053,18 @@ void ModelWidget::updateModelText()
#endif
}

/*!
* \brief ModelWidget::callHandleCollidingConnectionsIfNeeded
* Calls GraphicsView::handleCollidingConnections if needed.
*/
void ModelWidget::callHandleCollidingConnectionsIfNeeded()
{
if (mpLibraryTreeItem->getLibraryType() == LibraryTreeItem::Modelica && mpDiagramGraphicsView && isHandleCollidingConnectionsNeeded()) {
mpDiagramGraphicsView->handleCollidingConnections();
setHandleCollidingConnectionsNeeded(false);
}
}

/*!
* \brief ModelWidget::updateUndoRedoActions
* Enables/disables the Undo/Redo actions based on the stack situation.
Expand Down
4 changes: 4 additions & 0 deletions OMEdit/OMEditLIB/Modeling/ModelWidgetContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,8 @@ class ModelWidget : public QWidget
bool isNewApi();
void addDependsOnModel(const QString &dependsOnModel);
void clearDependsOnModels() {mDependsOnModelsList.clear();}
void setHandleCollidingConnectionsNeeded(bool needed) {mHandleCollidingConnectionsNeeded = needed;}
bool isHandleCollidingConnectionsNeeded() {return mHandleCollidingConnectionsNeeded;}

void fetchExtendsModifiers(QString extendsClass);
void reDrawModelWidgetInheritedClasses();
Expand Down Expand Up @@ -614,6 +616,7 @@ class ModelWidget : public QWidget
void clearSelection();
void updateClassAnnotationIfNeeded();
void updateModelText();
void callHandleCollidingConnectionsIfNeeded();
void updateUndoRedoActions();
bool writeCoSimulationResultFile(QString fileName);
bool writeVisualXMLFile(QString fileName, bool canWriteVisualXMLFile = false);
Expand Down Expand Up @@ -671,6 +674,7 @@ class ModelWidget : public QWidget
QTimer mUpdateModelTimer;
QStringList mDependsOnModelsList;
bool mHasMissingType = false;
bool mHandleCollidingConnectionsNeeded = false;

void createUndoStack();
void handleCanUndoRedoChanged();
Expand Down

0 comments on commit ce2ba6b

Please sign in to comment.