From: jsimomaa Date: Sun, 24 Nov 2019 16:51:04 +0000 (+0200) Subject: Fix detailed geometry center point caluclation and direction X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F08%2F3608%2F2;p=simantics%2Fdistrict.git Fix detailed geometry center point caluclation and direction gitlab #70 gitlab #47 Change-Id: Icf51b2c0d87cb527fc3e12a84fd88a7be7147800 --- diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkEdgeElement.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkEdgeElement.java index 20c86d8d..726c0c85 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkEdgeElement.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkEdgeElement.java @@ -39,6 +39,8 @@ import org.slf4j.LoggerFactory; public class DistrictNetworkEdgeElement { + private static final Logger LOGGER = LoggerFactory.getLogger(DistrictNetworkEdgeElement.class); + public static final Key KEY_DN_EDGE = new KeyOf(DistrictNetworkEdge.class, "DN_EDGE"); public static final Key KEY_DN_EDGE_NODE = new SceneGraphNodeKey(DistrictNetworkEdgeNode.class, "DN_EDGE_NODE"); public static final Key KEY_DN_EDGE_SYMBOL_NODE = new SceneGraphNodeKey(DistrictNetworkEdgeNode.class, "DN_EDGE_SYMBOL_NODE"); @@ -63,25 +65,29 @@ public class DistrictNetworkEdgeElement { @Override public void init(IElement edgeElement, G2DParentNode parent) { - DistrictNetworkEdge edge = edgeElement.getHint(KEY_DN_EDGE); - if (edge == null) { - cleanup(edgeElement); - } else { - DistrictNetworkEdgeNode node = edgeElement.getHint(KEY_DN_EDGE_NODE); - if (node == null) { - node = parent.addNode(ElementUtils.generateNodeId(edgeElement), DistrictNetworkEdgeNode.class); - edgeElement.setHint(KEY_DN_EDGE_NODE, node); + try { + DistrictNetworkEdge edge = edgeElement.getHint(KEY_DN_EDGE); + if (edge == null) { + cleanup(edgeElement); + } else { + DistrictNetworkEdgeNode node = edgeElement.getHint(KEY_DN_EDGE_NODE); + if (node == null) { + node = parent.addNode(ElementUtils.generateNodeId(edgeElement), DistrictNetworkEdgeNode.class); + edgeElement.setHint(KEY_DN_EDGE_NODE, node); + + SVGNode symbol = node.addNode(ElementUtils.generateNodeId(edgeElement), SVGNode.class); + edgeElement.setHint(KEY_DN_EDGE_SYMBOL_NODE, symbol); + } + + node.setColor(ElementUtils.getAdditionalColor(edgeElement, Color.BLUE)); - SVGNode symbol = node.addNode(ElementUtils.generateNodeId(edgeElement), SVGNode.class); - edgeElement.setHint(KEY_DN_EDGE_SYMBOL_NODE, symbol); + node.setDNEdge(edge); + AffineTransform at = ElementUtils.getTransform(edgeElement); + if (at != null) + node.setTransform(at); } - - node.setColor(ElementUtils.getAdditionalColor(edgeElement, Color.BLUE)); - - node.setDNEdge(edge); - AffineTransform at = ElementUtils.getTransform(edgeElement); - if (at != null) - node.setTransform(at); + } catch (Exception e) { + LOGGER.error("Could not initialize element {} for parent {}", edgeElement, parent, e); } } diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkNodeUtils.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkNodeUtils.java index 2cc0ee96..09224291 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkNodeUtils.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkNodeUtils.java @@ -99,8 +99,8 @@ public class DistrictNetworkNodeUtils { return 1; } - int longest = 1; - double distance = 0.0; + int longest = 2; + double distance = -Double.MAX_VALUE; for (int i = 2; i < segCount; i += 2) { double dx = segments.getQuick(i) - segments.getQuick(i-2); double dy = segments.getQuick(i+1) - segments.getQuick(i-1);