]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Fix detailed geometry center point caluclation and direction 08/3608/2
authorjsimomaa <jani.simomaa@gmail.com>
Sun, 24 Nov 2019 16:51:04 +0000 (18:51 +0200)
committerJani Simomaa <jani.simomaa@semantum.fi>
Sun, 24 Nov 2019 16:58:37 +0000 (16:58 +0000)
gitlab #70
gitlab #47

Change-Id: Icf51b2c0d87cb527fc3e12a84fd88a7be7147800

org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkEdgeElement.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkNodeUtils.java

index 20c86d8ddec6dbc4e83a88a5a630805bb8474e8f..726c0c85d561c2ac85c340bc3d5e6b52e537fbee 100644 (file)
@@ -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);
             }
         }
 
index 2cc0ee96ae4ffa89ad97b696c3661944f13146bc..09224291113365b76b67a5297767b5584d01f820 100644 (file)
@@ -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);