From 452d45fd64c45cbfadc15e8edc11c0cda4e101e0 Mon Sep 17 00:00:00 2001 From: Jussi Koskela Date: Wed, 11 Mar 2020 15:35:51 +0200 Subject: [PATCH] Don't create degenerated transient RouteLines to RouteGraph This change addresses the trivial cases. If multiple bends are required we still get degenerated lines if the terminal is at the corner of the bounds. gitlab #495 Change-Id: Iac5d139ba805955c38d4b4e4906eda4795871a66 (cherry picked from commit 1aedad590d55facc132e458a578064300bac833c) --- .../simantics/diagram/connection/RouteGraph.java | 7 +++++++ .../simantics/diagram/connection/RouteLine.java | 4 ++++ .../diagram/connection/RouteTerminal.java | 15 ++++++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/RouteGraph.java b/bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/RouteGraph.java index fe9371766..6357e537a 100644 --- a/bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/RouteGraph.java +++ b/bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/RouteGraph.java @@ -277,6 +277,12 @@ public class RouteGraph implements Serializable { transientLines.clear(); } + protected void removeRouteTerminalsFromRouteLines() { + for(RouteLine line : lines) { + line.removeRouteTerminals(); + } + } + /** * Rotates given terminal clockwise by given amount * (also negative numbers are allowed). @@ -311,6 +317,7 @@ public class RouteGraph implements Serializable { public void update() { needsUpdate = false; removeTransientRouteLines(); + removeRouteTerminalsFromRouteLines(); //print(); diff --git a/bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/RouteLine.java b/bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/RouteLine.java index a6a4f22d2..2011bfa28 100644 --- a/bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/RouteLine.java +++ b/bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/RouteLine.java @@ -188,6 +188,10 @@ public class RouteLine implements RouteNode, Serializable { return lines; } + public void removeRouteTerminals() { + points.removeIf(p -> p instanceof RouteTerminal); + } + public RouteTerminal getTerminal() { return terminal; } diff --git a/bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/RouteTerminal.java b/bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/RouteTerminal.java index dd660d4aa..3d6bd182f 100644 --- a/bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/RouteTerminal.java +++ b/bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/RouteTerminal.java @@ -164,18 +164,31 @@ public class RouteTerminal extends RoutePoint implements RouteNode, Serializable boolean routeLineDoesNotIntersectTerminal; double linePosition = line.position; if(line.isHorizontal) { + if (linePosition == y) { + // direct route to terminal + line.addPoint(this); + return; + } lineDir = linePosition < y ? 3 : 1; routeLineDoesNotIntersectTerminal = linePosition <= minY || linePosition >= maxY || boundingBoxesIntersect /* we ignore intersection in this case */; } else { + if (linePosition == x) { + // direct route to terminal + line.addPoint(this); + return; + } lineDir = linePosition < x ? 2 : 0; routeLineDoesNotIntersectTerminal = linePosition <= minX || linePosition >= maxX || boundingBoxesIntersect /* we ignore intersection in this case */; } // We can route the connection directly to the right direction - if(routeLineDoesNotIntersectTerminal && + if((routeLineDoesNotIntersectTerminal || + (line.isHorizontal && (x == minX || x == maxX)) || // already on the top/bottom edge + (!line.isHorizontal && (y == minY || y == maxY)) // already on the left/right edge + ) && Directions.isAllowed(allowedDirections, lineDir)) { RouteLine line0 = createLine0(lineDir); new RouteLink(line0, line); -- 2.47.1