From: Marko Luukkainen Date: Fri, 31 Jan 2020 13:35:50 +0000 (+0200) Subject: Support for random shaped terminals X-Git-Tag: v1.43.0~111 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=926168d3cbac101e34aa6dd918cc3f2f8ca3d4c4;p=simantics%2Fplatform.git Support for random shaped terminals This commit includes changes to support awt Path2D based terminals (currently external implementation). gitlab #456 Change-Id: Id266bba00fc8dd84e62157280143a0f18c0921e0 --- 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 249399d0a..9b707eae7 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 @@ -42,12 +42,12 @@ public class RouteGraph implements Serializable { public static final boolean RETURN_UNMODIFIABLE_COLLECTIONS = false; public static final boolean CHECK_PARAMERS = true; - ArrayList lines = new ArrayList(4); - ArrayList terminals = new ArrayList(4); - ArrayList transientLines = new ArrayList(4); - int caseId; - boolean isSimpleConnection; - boolean needsUpdate = false; + protected ArrayList lines = new ArrayList(4); + protected ArrayList terminals = new ArrayList(4); + protected ArrayList transientLines = new ArrayList(4); + protected int caseId; + protected boolean isSimpleConnection; + protected boolean needsUpdate = false; public void updateTerminals() { boolean changed = false; @@ -270,7 +270,7 @@ public class RouteGraph implements Serializable { needsUpdate = true; } - void removeTransientRouteLines() { + protected void removeTransientRouteLines() { for(RouteLine line : transientLines) line.remove(); transientLines.clear(); @@ -336,6 +336,11 @@ public class RouteGraph implements Serializable { line.addPoint(b); line.terminal = a; transientLines.add(line); + + // Path terminal + a.line = line; + b.line = line; + break; } case SimpleConnectionUtility.ONE_BEND_HORIZONTAL_VERTICAL: { @@ -348,6 +353,10 @@ public class RouteGraph implements Serializable { line2.terminal = b; transientLines.add(line1); transientLines.add(line2); + + // Path terminal + a.line = line1; + b.line = line2; break; } case SimpleConnectionUtility.ONE_BEND_VERTICAL_HORIZONTAL: { @@ -360,6 +369,10 @@ public class RouteGraph implements Serializable { line2.terminal = b; transientLines.add(line1); transientLines.add(line2); + + //Path terminal + a.line = line1; + b.line = line2; break; } case SimpleConnectionUtility.MORE_BENDS_BBS_DONT_INTERSECT: @@ -375,6 +388,7 @@ public class RouteGraph implements Serializable { break; } } + //routeFromTerminals(caseId==SimpleConnectionUtility.MORE_BENDS_BBS_INTERSECT); } else { caseId = SimpleConnectionUtility.COMPLEX_CONNECTION; @@ -396,7 +410,7 @@ public class RouteGraph implements Serializable { } } - static class Interval { + public static class Interval { public final double min; public final double max; public Interval(double min, double max) { @@ -405,7 +419,7 @@ public class RouteGraph implements Serializable { } } - class IntervalCache { + public class IntervalCache { THashMap cache = new THashMap(); public Interval get(RouteLine line) { @@ -457,7 +471,7 @@ public class RouteGraph implements Serializable { } } - private void routeFromTerminals(boolean boundingBoxesIntersect) { + protected void routeFromTerminals(boolean boundingBoxesIntersect) { IntervalCache cache = new IntervalCache(); for(RouteTerminal terminal : terminals) if(terminal.line != null) { 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 315b11c12..a6a4f22d2 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 @@ -34,7 +34,7 @@ public class RouteLine implements RouteNode, Serializable { RouteLine nextTransient; RouteTerminal terminal; - RouteLine(boolean isHorizontal, double position) { + public RouteLine(boolean isHorizontal, double position) { this.isHorizontal = isHorizontal; this.position = position; } @@ -57,6 +57,10 @@ public class RouteLine implements RouteNode, Serializable { return hidden; } + public void setHidden(boolean hidden) { + this.hidden = hidden; + } + public double getPosition() { return position; } @@ -68,7 +72,7 @@ public class RouteLine implements RouteNode, Serializable { return points; } - void addPoint(RoutePoint link) { + public void addPoint(RoutePoint link) { points.add(link); } @@ -77,7 +81,7 @@ public class RouteLine implements RouteNode, Serializable { point.removeFromOther(this); } - void setPointPositions() { + public void setPointPositions() { if(isHorizontal) { for(RoutePoint point : points) point.y = position; @@ -88,7 +92,7 @@ public class RouteLine implements RouteNode, Serializable { } } - void sortPoints() { + public void sortPoints() { Collections.sort(points, isHorizontal ? RoutePoint.X_COMPARATOR : RoutePoint.Y_COMPARATOR); @@ -158,7 +162,7 @@ public class RouteLine implements RouteNode, Serializable { return terminal != null; } - RouteLine copy(THashMap map) { + public RouteLine copy(THashMap map) { RouteLine copy = (RouteLine)map.get(this); if(copy == null) { copy = new RouteLine(isHorizontal, position); @@ -187,6 +191,10 @@ public class RouteLine implements RouteNode, Serializable { public RouteTerminal getTerminal() { return terminal; } + + public void setTerminal(RouteTerminal terminal) { + this.terminal = terminal; + } public RouteLine getNextTransient() { return nextTransient; diff --git a/bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/RouteLink.java b/bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/RouteLink.java index d3dccca5d..a108ba3a5 100644 --- a/bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/RouteLink.java +++ b/bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/RouteLink.java @@ -28,7 +28,7 @@ public class RouteLink extends RoutePoint implements Serializable { private RouteLink() { } - RouteLink(RouteLine a, RouteLine b) { + public RouteLink(RouteLine a, RouteLine b) { this.a = a; this.b = b; a.addPoint(this); 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 c43c7de1c..dd660d4aa 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 @@ -44,7 +44,7 @@ public class RouteTerminal extends RoutePoint implements RouteNode, Serializable RouteLine line; - RouteTerminal(double x, double y, double minX, double minY, + public RouteTerminal(double x, double y, double minX, double minY, double maxX, double maxY, int allowedDirections, boolean routeToBounds, ILineEndStyle style, RouteTerminalPosition dynamicPosition) { @@ -98,7 +98,7 @@ public class RouteTerminal extends RoutePoint implements RouteNode, Serializable * adding necessary transient route lines. * @param cache */ - void route(ArrayList lines, IntervalCache cache, boolean boundingBoxesIntersect) { + protected void route(ArrayList lines, IntervalCache cache, boolean boundingBoxesIntersect) { if(routeToBounds) { int lineDir; boolean routeLineDoesNotIntersectTerminal; @@ -139,7 +139,8 @@ public class RouteTerminal extends RoutePoint implements RouteNode, Serializable return; } else { - line.addPoint(this); + if (!line.getPoints().contains(this)) + line.addPoint(this); Interval interval = cache.get(line); if(line.isHorizontal) { if(interval.min < minX) @@ -257,7 +258,7 @@ public class RouteTerminal extends RoutePoint implements RouteNode, Serializable } } - private RouteLine createLine0(int dir) { + protected RouteLine createLine0(int dir) { RouteLine line0 = (dir&1) == 0 ? new RouteLine(true, y) : new RouteLine(false, x) @@ -377,7 +378,7 @@ public class RouteTerminal extends RoutePoint implements RouteNode, Serializable } } - RouteTerminal copy(THashMap map) { + public RouteTerminal copy(THashMap map) { RouteTerminal copy = (RouteTerminal)map.get(this); if(copy == null) { copy = new RouteTerminal(x, y, minX, minY, maxX, maxY, @@ -418,6 +419,10 @@ public class RouteTerminal extends RoutePoint implements RouteNode, Serializable return line; } + public void setLine(RouteLine line) { + this.line = line; + } + public void setMinX(double minX) { this.minX = minX; } @@ -456,6 +461,8 @@ public class RouteTerminal extends RoutePoint implements RouteNode, Serializable public RouteTerminalPosition getDynamicPosition() { return dynamicPosition; } + + public boolean updateDynamicPosition() { boolean changed = false; diff --git a/bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/SimpleConnectionUtility.java b/bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/SimpleConnectionUtility.java index 109f8fe73..0628573d0 100644 --- a/bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/SimpleConnectionUtility.java +++ b/bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/SimpleConnectionUtility.java @@ -17,7 +17,7 @@ package org.simantics.diagram.connection; * * @author Hannu Niemistö */ -class SimpleConnectionUtility { +public class SimpleConnectionUtility { public static boolean allowsDirection(RouteTerminal a, int dir) { return Directions.isAllowed(a.getAllowedDirections(), dir);