From b3da313f6d3b9143f8cbe90d4252e4347adc119a Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Wed, 16 Nov 2016 15:49:21 +0200 Subject: [PATCH] Sync git svn branch with SVN repository r33392. refs #6751 --- .../org/simantics/diagram/handler/Paster.java | 7 +- .../diagram/participant/ConnectTool2.java | 76 ++++++------------- 2 files changed, 28 insertions(+), 55 deletions(-) diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/Paster.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/Paster.java index a103ab8bc..153199d6c 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/Paster.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/Paster.java @@ -902,6 +902,7 @@ public class Paster { boolean external = FlagUtil.isExternal(graph, flag); boolean inSingleDiagram = FlagUtil.isJoinedInSingleDiagram(graph, flag); if (!external && inSingleDiagram) { + // FIXME: this doesn't take into account local merged flags, which is a corner case but still possible Resource counterpart = FlagUtil.getPossibleCounterpart(graph, flag); if (selectedFlags.containsKey(counterpart)) { flagSelectedCounterpart.put(flag, counterpart); @@ -1268,7 +1269,11 @@ public class Paster { Resource dst = (Resource) resourceMap.get(src); for (Resource connectedToSrc : graph.getObjects(src, DIA.AreConnected)) { Resource connectedToDst = (Resource) resourceMap.get(connectedToSrc); - graph.claim(dst, DIA.AreConnected, DIA.AreConnected, connectedToDst); + if (connectedToDst != null) { + graph.claim(dst, DIA.AreConnected, DIA.AreConnected, connectedToDst); + } else { + throw new DatabaseException("Connection copying failed due to an invalid DIA.AreConnected link between source resources " + src + " <-> " + connectedToSrc); + } } } for (Statement hasConnector : sourceHasConnectors) { 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); }); } -- 2.47.1