]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Ignore stray route lines when loading diagram connections 72/872/1
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 21 Aug 2017 16:00:23 +0000 (19:00 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 21 Aug 2017 16:00:23 +0000 (19:00 +0300)
Prevents diagram rendering from failing unexpectedly due to invalid
RouteGraph structure.

refs #7443

Change-Id: I7fb8949c01fd5ff24853fa3e3332a999df549d45

bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/RouteGraphUtils.java

index 054db497d2cf7a46f9d8b425cf84fa01eebdd7a0..9338e917221be3fcd06222e80ebf39f3288a7751 100644 (file)
@@ -110,12 +110,21 @@ public class RouteGraphUtils {
         RouteGraph rg = new RouteGraph();
 
         // Default capacity should be enough for common cases.
-        Set<EdgeResource> links = new THashSet<EdgeResource>();
-        Map<Object, RouteNode> nodeByData = new THashMap<Object, RouteNode>();
+        Set<EdgeResource> links = new THashSet<>();
+        Map<Object, RouteNode> nodeByData = new THashMap<>();
 
         // Load all route graph interior RouteNodes: route lines and points
         for (Resource interiorNode : graph.getObjects(connection, DIA.HasInteriorRouteNode)) {
             if (graph.isInstanceOf(interiorNode, DIA.RouteLine)) {
+                Collection<Resource> areConnected = graph.getObjects(interiorNode, DIA.AreConnected);
+                if (areConnected.size() < 2) {
+                    // Degenerated route line encountered, most likely due to a bug somewhere else.
+                    // Ignoring them because adding them to the RouteGraph structure would cause
+                    // problems during rendering.
+                    LOGGER.warn("Stray RouteLine found: " + NameUtils.getSafeName(graph, interiorNode));
+                    continue;
+                }
+
                 Boolean isHorizontal = graph.getRelatedValue(interiorNode, DIA.IsHorizontal, Bindings.BOOLEAN);
                 Double position = graph.getRelatedValue(interiorNode, DIA.HasPosition, Bindings.DOUBLE);
                 RouteLine line = rg.addLine(isHorizontal, position);
@@ -123,7 +132,7 @@ public class RouteGraphUtils {
 
                 nodeByData.put( interiorNode, line );
 
-                for (Resource connectedTo : graph.getObjects(interiorNode, DIA.AreConnected)) {
+                for (Resource connectedTo : areConnected) {
                     links.add( new EdgeResource(interiorNode, connectedTo) );
                 }
             } else if (graph.isInstanceOf(interiorNode, DIA.RoutePoint)) {