From 2deeabb9a7e3ff22bfd7abe2c7c812df9da45189 Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Thu, 25 Oct 2018 13:11:25 +0300 Subject: [PATCH] ConnectionTool fixes for overlapping terminals gitlab #157 Change-Id: If011efcf774e18165e6ae1e62907dffe2c6a21f0 --- .../diagram/participant/ConnectTool2.java | 1 + .../participant/ConnectionBuilder.java | 6 ++- .../participant/RouteGraphConnectTool.java | 39 ++++++++++--------- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/participant/ConnectTool2.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/participant/ConnectTool2.java index 7d3a5a400..8ebd1edc5 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/participant/ConnectTool2.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/participant/ConnectTool2.java @@ -601,6 +601,7 @@ public class ConnectTool2 extends AbstractMode { attachToConnectionJudgement = canConnect.first; controlPoints.getLast().setPosition(ti.posDia).setAttachedToTerminal(ti); endTerminal = ti; + startTerminal = canConnect.second; cp.getNode().showBranchPoint(isectPos); if (!endWithoutTerminal(lastMouseCanvasPos, shouldEndWithFlag(me))) updateSG(); diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/participant/ConnectionBuilder.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/participant/ConnectionBuilder.java index 599aba0d0..8da84709b 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/participant/ConnectionBuilder.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/participant/ConnectionBuilder.java @@ -497,7 +497,7 @@ public class ConnectionBuilder { Connector endConnector = null; if (endTerminal != null) { - endConnector = createConnectorForNode(graph, attachToConnection, endTerminal, EdgeEnd.End, judgment); + endConnector = createConnectorForNode(graph, attachToConnection, endTerminal, flagType == FlagClass.Type.In ? EdgeEnd.Begin : EdgeEnd.End, judgment); } else if (createFlags) { EdgeEnd end = flagType == FlagClass.Type.In ? EdgeEnd.Begin : EdgeEnd.End; IElement endFlag = createFlag(graph, attachToConnection, end, controlPoints.getLast(), flagType, null); @@ -763,7 +763,9 @@ public class ConnectionBuilder { EdgeEnd end, ConnectionJudgement judgment) throws DatabaseException { IConnectionPoint cp = ConnectionUtil.toConnectionPoint(graph, element, terminal); CPTerminal cpt = (cp instanceof CPTerminal) ? (CPTerminal) cp : null; - Resource attachment = judgment.attachmentRelations.get(graph, cpt); + Resource attachment = null; + if (judgment.attachmentRelations != null) + attachment = judgment.attachmentRelations.get(graph, cpt); if (attachment == null) attachment = cu.toHasConnectorRelation(end); Resource connector = cu.getOrCreateConnector(connection, element, terminal, end, attachment); diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/participant/RouteGraphConnectTool.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/participant/RouteGraphConnectTool.java index 8f99207e1..cff52a3d5 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/participant/RouteGraphConnectTool.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/participant/RouteGraphConnectTool.java @@ -24,6 +24,7 @@ import java.util.Collection; import java.util.Deque; import java.util.HashSet; import java.util.Iterator; +import java.util.List; import java.util.Set; import org.simantics.Simantics; @@ -502,29 +503,31 @@ public class RouteGraphConnectTool extends AbstractMode { endFlagNode.setTransform(AffineTransform.getTranslateInstance(mouseCanvasPos.getX(), mouseCanvasPos.getY())); } - TerminalInfo ti = pi.pickTerminal(me.controlPosition); - if (ti != null) { - Object canConnect = canConnect(ti.e, ti.t); - if (canConnect != null) { - connectionJudgment = (ConnectionJudgement) canConnect; + List tis = pi.pickTerminals(me.controlPosition); + tis = TerminalUtil.findNearestOverlappingTerminals(tis); + if (!tis.isEmpty()) { + for (TerminalInfo ti : tis) { + Object canConnect = canConnect(ti.e, ti.t); - if (!isEndingInFlag() || !TerminalUtil.isSameTerminal(ti, endTerminal)) { - controlPoints.getLast() - .setPosition(ti.posDia) - .setAttachedToTerminal(ti); + if (canConnect != null) { + connectionJudgment = (ConnectionJudgement) canConnect; - endTerminal = ti; + if (!isEndingInFlag() || !TerminalUtil.isSameTerminal(ti, endTerminal)) { + controlPoints.getLast().setPosition(ti.posDia).setAttachedToTerminal(ti); - connect(ti); - - } + endTerminal = ti; + + connect(ti); - // Make sure that we are ending with a flag if ALT is pressed - // and no end terminal is defined. - endWithoutTerminal(lastMouseCanvasPos, shouldEndWithFlag(me)); + } - updateSG(new Point2D.Double(ti.posDia.getTranslateX(), ti.posDia.getTranslateY())); - return false; + // Make sure that we are ending with a flag if ALT is pressed + // and no end terminal is defined. + endWithoutTerminal(lastMouseCanvasPos, shouldEndWithFlag(me)); + + updateSG(new Point2D.Double(ti.posDia.getTranslateX(), ti.posDia.getTranslateY())); + return false; + } } } -- 2.47.1