]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
ConnectionTool fixes for overlapping terminals 57/2357/1
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 12:29:06 +0000 (12:29 +0000)
gitlab #157

Change-Id: If011efcf774e18165e6ae1e62907dffe2c6a21f0
(cherry picked from commit 2deeabb9a7e3ff22bfd7abe2c7c812df9da45189)

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 ce2630df66d40a9b0a002815fe2fe6b5f219662c..38bdc706cb88e8b20a959b03d18bfac02ec17de9 100644 (file)
@@ -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();
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 d1ba2174143f17aec8d14e98cae838136793a6d7..e39c73d809120b760110c3476d44368f76e78336 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;
+                }
             }
         }