From: Marko Luukkainen Date: Thu, 25 Oct 2018 10:11:25 +0000 (+0300) Subject: ConnectionTool fixes for overlapping terminals X-Git-Tag: v1.43.0~136^2~317 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=05690e88acf9883a20f1480d4636c5cd037b49ea;p=simantics%2Fplatform.git ConnectionTool fixes for overlapping terminals gitlab #157 Change-Id: If011efcf774e18165e6ae1e62907dffe2c6a21f0 (cherry picked from commit 2deeabb9a7e3ff22bfd7abe2c7c812df9da45189) --- 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 ce2630df6..38bdc706c 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 @@ -602,6 +602,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 d1ba21741..e39c73d80 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; + } } }