X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fparticipant%2FConnectTool2.java;h=2165794e89c489c34e34daddf5613fa22d13e9ae;hp=71a8d28290f9b7e020ef3bbb368ccc994287f8bc;hb=b3da313f6d3b9143f8cbe90d4252e4347adc119a;hpb=5da68e793c68db0b155c4c505fe85716b5f31b6e 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 71a8d2829..2165794e8 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 @@ -99,7 +99,6 @@ import org.simantics.scenegraph.g2d.snap.ISnapAdvisor; import org.simantics.scenegraph.utils.GeometryUtils; import org.simantics.scenegraph.utils.Quality; import org.simantics.structural2.modelingRules.ConnectionJudgement; -import org.simantics.utils.datastructures.Callback; import org.simantics.utils.datastructures.Pair; import org.simantics.utils.logging.TimeLogger; import org.simantics.utils.ui.ErrorLogger; @@ -217,6 +216,13 @@ public class ConnectTool2 extends AbstractMode { */ protected ConnectionJudgement connectionJudgment; + /** + * The latest connectability judgment from the active + * {@link IConnectionAdvisor} should the connection happen between + * {@link #selectedStartTerminal} and {@link #lastRouteGraphTarget}. + */ + protected ConnectionJudgement attachToConnectionJudgement; + /** * If non-null during connection drawing this field tells the direction * forced for the current branch point by the user through the UI commands @@ -409,22 +415,6 @@ public class ConnectTool2 extends AbstractMode { updateSG(); } - static class Segment { - public final ControlPoint begin; - public final ControlPoint end; - public Path2D path; - - public Segment(ControlPoint begin, ControlPoint end) { - this.begin = begin; - this.end = end; - } - - @Override - public String toString() { - return "Segment[begin=" + begin + ", end=" + end + ", path=" + path + "]"; - } - } - private RouteTerminal addControlPoint(RouteGraph routeGraph, ControlPoint cp) { TerminalInfo ti = cp.getAttachedTerminal(); if(ti != null && ti != startFlag && ti != endFlag) { @@ -482,23 +472,6 @@ public class ConnectTool2 extends AbstractMode { return elementParent; } - private List toSegments(Deque points) { - if (points.isEmpty()) - return Collections.emptyList(); - - List segments = new ArrayList(); - - Iterator it = points.iterator(); - ControlPoint prev = it.next(); - while (it.hasNext()) { - ControlPoint next = it.next(); - segments.add(new Segment(prev, next)); - prev = next; - } - - return segments; - } - @SGCleanup public void cleanupSG() { ghostNode.remove(); @@ -620,7 +593,7 @@ public class ConnectTool2 extends AbstractMode { BranchPointNode.SHAPE); Pair canConnect = canConnect(ti.e, ti.t); if (canConnect != null) { - connectionJudgment = canConnect.first; + attachToConnectionJudgement = canConnect.first; controlPoints.getLast().setPosition(ti.posDia).setAttachedToTerminal(ti); endTerminal = ti; cp.getNode().showBranchPoint(isectPos); @@ -637,6 +610,7 @@ public class ConnectTool2 extends AbstractMode { } connectionJudgment = null; + attachToConnectionJudgement = null; if (isEndTerminalDefined()) { // CASE: Mouse was previously on top of a valid terminal to end // the connection. Now the mouse has been moved where there is @@ -688,16 +662,16 @@ public class ConnectTool2 extends AbstractMode { if (snapAdvisor != null) snapAdvisor.snap(mouseCanvasPos); - if (lastRouteGraphTarget != null) { - lastRouteGraphTarget.getNode().showBranchPoint(null); - attachToConnection(); - remove(); - return true; - } else if (isEndTerminalDefined()) { + if (isEndTerminalDefined() && connectionJudgment != null) { // Clicked on an allowed end terminal. End connection & end mode. createConnection(); remove(); return true; + } else if (lastRouteGraphTarget != null && attachToConnectionJudgement != null) { + lastRouteGraphTarget.getNode().showBranchPoint(null); + attachToConnection(); + remove(); + return true; } else { // Finish connection in thin air only if the // connection was started from a valid terminal. @@ -737,7 +711,7 @@ public class ConnectTool2 extends AbstractMode { } private void attachToConnection() { - ConnectionJudgement judgment = this.connectionJudgment; + ConnectionJudgement judgment = this.attachToConnectionJudgement; if (judgment == null) { ErrorLogger.defaultLogError("Cannot attach to connection, no judgment available on connection validity", null); return; @@ -774,12 +748,9 @@ public class ConnectTool2 extends AbstractMode { cps.add(iterator.next()); builder.attachToRouteGraph(graph, judgment, connection, line, cps, startTerminal, FlagClass.Type.In); } - }, new Callback() { - @Override - public void run(DatabaseException parameter) { - if (parameter != null) - ExceptionUtils.logAndShowError(parameter); - } + }, parameter -> { + if (parameter != null) + ExceptionUtils.logAndShowError(parameter); }); } @@ -1007,12 +978,9 @@ public class ConnectTool2 extends AbstractMode { public void perform(WriteGraph graph) throws DatabaseException { builder.create(graph, judgement, controlPoints, startTerminal, endTerminal); } - }, new Callback() { - @Override - public void run(DatabaseException parameter) { - if (parameter != null) - ExceptionUtils.logAndShowError(parameter); - } + }, parameter -> { + if (parameter != null) + ExceptionUtils.logAndShowError(parameter); }); }