diff options
author | Laurent Redor | 2017-10-10 09:50:31 +0000 |
---|---|---|
committer | Laurent Redor | 2017-10-11 09:52:19 +0000 |
commit | b9268fd32c89fd381c1c50625a4f4c92e4e2d683 (patch) | |
tree | 50f43c4e712002b7bc4ab558e9210038398b5671 | |
parent | 583ca53e8f7c671341042cba71808824289418b1 (diff) | |
download | org.eclipse.sirius-b9268fd32c89fd381c1c50625a4f4c92e4e2d683.tar.gz org.eclipse.sirius-b9268fd32c89fd381c1c50625a4f4c92e4e2d683.tar.xz org.eclipse.sirius-b9268fd32c89fd381c1c50625a4f4c92e4e2d683.zip |
[525799] Fix edge loop pb
The edge loop is created in
org.eclipse.gmf.runtime.draw2d.ui.internal.routers.ObliqueRouter.checkShapesIntersect(Connection,
PointList). If the source and the target intersect, additional points
are visually created to easily see the edge (with a "loop" between
source and target).
So in method
org.eclipse.sirius.diagram.ui.graphical.edit.policies.SetConnectionBendpointsAccordingToExtremityMoveCommmand.adaptPointListAndRefPoints(boolean,
Point, ConnectionEditPart, Point, Point, PointList) we must consider
this case, to only keep source point and target point, when moving
source node or target node, if we are in this case.
Bug: 525799
Change-Id: I180e26c1932a700b6dca2fde88020c0636e7e3fa
Signed-off-by: Laurent Redor <laurent.redor@obeo.fr>
4 files changed, 71 insertions, 3 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/ConnectionEditPartQuery.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/ConnectionEditPartQuery.java index 4efe8d315a..efa1d98834 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/ConnectionEditPartQuery.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/ConnectionEditPartQuery.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 THALES GLOBAL SERVICES. + * Copyright (c) 2012, 2017 THALES GLOBAL SERVICES. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,9 +10,16 @@ *******************************************************************************/ package org.eclipse.sirius.diagram.ui.business.api.query; +import org.eclipse.draw2d.Connection; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.geometry.PointList; +import org.eclipse.draw2d.geometry.PrecisionRectangle; import org.eclipse.gef.ConnectionEditPart; +import org.eclipse.gef.editparts.AbstractConnectionEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramRootEditPart; +import org.eclipse.gmf.runtime.draw2d.ui.figures.IOvalAnchorableFigure; +import org.eclipse.gmf.runtime.draw2d.ui.figures.IPolygonAnchorableFigure; import org.eclipse.gmf.runtime.notation.Diagram; import org.eclipse.gmf.runtime.notation.Edge; import org.eclipse.sirius.diagram.DSemanticDiagram; @@ -134,4 +141,40 @@ public class ConnectionEditPartQuery { } return isLayout; } + + /** + * Checks if source shape and target shape of the connection intersect (only intersect - not one contained in another). + * Method inspired from what is done in {@link org.eclipse.gmf.runtime.draw2d.ui.internal.routers.ObliqueRouter#checkShapesIntersect(Connection, PointList)}. + * + * @return true if the source and target intersect, false otherwise. + */ + @SuppressWarnings("restriction") + public boolean checkShapesIntersect() { + boolean result = false; + if (connectionEditPart instanceof AbstractConnectionEditPart) { + Connection conn = ((AbstractConnectionEditPart) connectionEditPart).getConnectionFigure(); + if (!(conn.getSourceAnchor().getOwner() == null || conn.getSourceAnchor().getOwner() instanceof Connection || conn.getTargetAnchor().getOwner() == null + || conn.getTargetAnchor().getOwner() instanceof Connection)) { + PrecisionRectangle sourceBounds = getShapeBounds(conn.getSourceAnchor().getOwner()); + PrecisionRectangle targetBounds = getShapeBounds(conn.getTargetAnchor().getOwner()); + conn.getSourceAnchor().getOwner().translateToAbsolute(sourceBounds); + conn.getTargetAnchor().getOwner().translateToAbsolute(targetBounds); + if (sourceBounds.intersects(targetBounds) && !sourceBounds.contains(targetBounds) && !targetBounds.contains(sourceBounds) || sourceBounds.equals(targetBounds)) { + result = true; + } + } + } + return result; + } + + private PrecisionRectangle getShapeBounds(IFigure figure) { + PrecisionRectangle result = new PrecisionRectangle(figure.getBounds()); + if (figure instanceof IOvalAnchorableFigure) { + result = new PrecisionRectangle(((IOvalAnchorableFigure) figure).getOvalBounds()); + } else if (figure instanceof IPolygonAnchorableFigure) { + result = new PrecisionRectangle(((IPolygonAnchorableFigure) figure).getPolygonPoints().getBounds()); + } + return result; + + } } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/SetConnectionBendpointsAccordingToExtremityMoveCommmand.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/SetConnectionBendpointsAccordingToExtremityMoveCommmand.java index 75363a83df..5282fa47ea 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/SetConnectionBendpointsAccordingToExtremityMoveCommmand.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/SetConnectionBendpointsAccordingToExtremityMoveCommmand.java @@ -21,6 +21,8 @@ import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.gmf.runtime.draw2d.ui.geometry.LineSeg; import org.eclipse.gmf.runtime.draw2d.ui.geometry.PointListUtilities; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.RelativeBendpoints; import org.eclipse.sirius.diagram.ui.business.api.query.ConnectionEditPartQuery; import org.eclipse.sirius.diagram.ui.provider.Messages; import org.eclipse.sirius.ext.base.Option; @@ -95,10 +97,28 @@ public class SetConnectionBendpointsAccordingToExtremityMoveCommmand extends Set */ public static void adaptPointListAndRefPoints(boolean sourceMove, Point moveDelta, org.eclipse.gef.ConnectionEditPart connectionEditPart, Point sourceRefPoint, Point targetRefPoint, PointList connectionPointList) { - // Get the bounds of the source and target nodes + ConnectionEditPartQuery connectionEditPartQuery = new ConnectionEditPartQuery(connectionEditPart); + // Check overlap case + if (connectionEditPart.getModel() instanceof Edge && ((Edge) connectionEditPart.getModel()).getBendpoints() instanceof RelativeBendpoints) { + // If visually the egde contains more points (connectionPointList) than the model (GMF Edge points) and the + // model contains only 2 points, we are probably in the case where the source and the target intersect and + // the router + // (org.eclipse.gmf.runtime.draw2d.ui.internal.routers.ObliqueRouter.checkShapesIntersect(Connection, + // PointList)) adds virtual bend-points to allow drawing of the edge. In this case, we ignore + // the intermediate points and only consider source and target. + int nbVisualPoints = connectionPointList.size(); + int nbModelPoints = ((RelativeBendpoints) ((Edge) connectionEditPart.getModel()).getBendpoints()).getPoints().size(); + if (nbVisualPoints > nbModelPoints && nbModelPoints == 2 && connectionEditPartQuery.checkShapesIntersect()) { + for (int i = 0; i < nbVisualPoints - 2; i++) { + // Remove intermediate points + connectionPointList.removePoint(1); + } + } + } + // Get the bounds of the source and target nodes. PrecisionRectangle sourceBounds = new PrecisionRectangle(GraphicalHelper.getAbsoluteBoundsIn100Percent((IGraphicalEditPart) connectionEditPart.getSource())); PrecisionRectangle targetBounds = new PrecisionRectangle(GraphicalHelper.getAbsoluteBoundsIn100Percent((IGraphicalEditPart) connectionEditPart.getTarget())); - boolean isEdgeWithRectilinearRoutingStyle = new ConnectionEditPartQuery(connectionEditPart).isEdgeWithRectilinearRoutingStyle(); + boolean isEdgeWithRectilinearRoutingStyle = connectionEditPartQuery.isEdgeWithRectilinearRoutingStyle(); if (sourceMove) { moveFirstSegmentAndRefPointAccordingToSourceMove(moveDelta, isEdgeWithRectilinearRoutingStyle, sourceBounds, targetBounds, sourceRefPoint, targetRefPoint, connectionPointList); } else { diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html index 3288cbe29b..f910602ba9 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html +++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html @@ -331,6 +331,10 @@ <code>org.eclipse.sirius.diagram.ui.tools.api.preferences.SiriusDiagramUiPreferencesKeys.PREF_SHOW_SYNCHRONIZE_STATUS_DECORATOR</code> has been added to say if the <a href="user/diagrams/Diagrams.html#synchronized_diagram">synchronize status</a> decorator must be shown or not. </li> + <li><span class="label label-success">Added</span> A new method + <code>checkShapesIntersect()</code> has been added in + <code>org.eclipse.sirius.diagram.ui.business.api.query.ConnectionEditPartQuery</code> to check if source and target of the connection intersect (only intersect – not one contained in another). + </li> </ul> <h4 id="Changesinorg.eclipse.sirius.ext.emf.edit">Changes in <code>org.eclipse.sirius.ext.emf.edit</code> diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile index 076f83def8..8fc77f9bdd 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile +++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile @@ -87,6 +87,7 @@ h4. Changes in @org.eclipse.sirius.diagram.ui@ ** @getScalingFactor()@: after the export has been performed, this can be used to obtain the scaling factor that was effectively used. * <span class="label label-success">Added</span> The class @org.eclipse.sirius.diagram.ui.business.api.DiagramExportResult@ has been added, which inherits from @ExportResult@. It is returned by the @DialectManager.exportWithResult()@ methods when the representation exported is a diagram, and in addition to the information provided by @ExportResult@ gives access to the scaling factor that was used when exporting the diagram. * <span class="label label-success">Added</span> The new preference @org.eclipse.sirius.diagram.ui.tools.api.preferences.SiriusDiagramUiPreferencesKeys.PREF_SHOW_SYNCHRONIZE_STATUS_DECORATOR@ has been added to say if the "synchronize status":user/diagrams/Diagrams.html#synchronized_diagram decorator must be shown or not. +* <span class="label label-success">Added</span> A new method @checkShapesIntersect()@ has been added in @org.eclipse.sirius.diagram.ui.business.api.query.ConnectionEditPartQuery@ to check if source and target of the connection intersect (only intersect - not one contained in another). h4. Changes in @org.eclipse.sirius.ext.emf.edit@ |