From e10fdeba47f1c3dcbfb2c19da636eae96449df6a Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Mon, 21 Aug 2017 19:00:23 +0300 Subject: [PATCH] Ignore stray route lines when loading diagram connections Prevents diagram rendering from failing unexpectedly due to invalid RouteGraph structure. refs #7443 Change-Id: I7fb8949c01fd5ff24853fa3e3332a999df549d45 --- .../diagram/adapter/RouteGraphUtils.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/RouteGraphUtils.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/RouteGraphUtils.java index 054db497d..9338e9172 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/RouteGraphUtils.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/RouteGraphUtils.java @@ -110,12 +110,21 @@ public class RouteGraphUtils { RouteGraph rg = new RouteGraph(); // Default capacity should be enough for common cases. - Set links = new THashSet(); - Map nodeByData = new THashMap(); + Set links = new THashSet<>(); + Map 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 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)) { -- 2.43.2