]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
ConnectionTool fixes for overlapping terminals 54/2354/2
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Thu, 25 Oct 2018 10:11:25 +0000 (13:11 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 25 Oct 2018 11:13:18 +0000 (11:13 +0000)
gitlab #157

Change-Id: If011efcf774e18165e6ae1e62907dffe2c6a21f0

bundles/org.simantics.diagram/src/org/simantics/diagram/participant/ConnectTool2.java
bundles/org.simantics.diagram/src/org/simantics/diagram/participant/ConnectionBuilder.java
bundles/org.simantics.diagram/src/org/simantics/diagram/participant/RouteGraphConnectTool.java

index 7d3a5a4005078f314f96d49b931978eabb5ad4c5..8ebd1edc56e992841f5ee9955f4ea7fed13eb674 100644 (file)
@@ -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();
index 599aba0d042d49b72c380fb8c66981a1869a9122..8da84709b6ee89be5dd29c9ee53697e9ca7a51a0 100644 (file)
@@ -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);
index 8f99207e19c77cb00f55288f8bd4d218aca06cdf..cff52a3d5d88ace604e559b54b591d649a9859e4 100644 (file)
@@ -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<TerminalInfo> 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;
+                }
             }
         }