ConnectionNode returns local bounds even if it has empty child nodes 39/2239/2
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 25 Sep 2018 21:15:41 +0000 (00:15 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 26 Sep 2018 08:28:52 +0000 (08:28 +0000)
This fixes a broken element selection case that came up in master, which
is an old problem but hasn't really surfaced before.

gitlab #134

Change-Id: I0bd3cb8beba9d3d5ccdcbf4b3f1b81d9910a575f

bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/ConnectionNode.java

index d4543c6d110546c08cf8709f94f3af81d9501810..9331a1edea5afea8ae5cc5b086d790bb92e02d95 100644 (file)
@@ -16,6 +16,7 @@ import java.awt.Composite;
 import java.awt.Graphics2D;
 import java.awt.Stroke;
 import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
 
 import org.simantics.diagram.connection.RouteGraph;
 import org.simantics.scenegraph.INode;
@@ -161,5 +162,17 @@ public class ConnectionNode extends SingleElementNode implements InitValueSuppor
     public void afterRender(Graphics2D g) {
         g.setRenderingHint(G2DRenderingHints.KEY_END_ELEMENT, "connection");
     }
-    
+
+    @Override
+    public Rectangle2D getBoundsInLocal() {
+        // #134: Route graph connections render their own selection.
+        // ElementPainter will place an empty G2DParentNode
+        // called "selection" under this ConnectionNode which
+        // should be ignored in bounds calculations.
+        // Otherwise this node will not support being inserted
+        // into a spatial search structure and further selections
+        // will fail.
+        return super.getBoundsInLocal(true);
+    }
+
 }