]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Fixed two selection/picking related bugs 85/3585/1
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 20 Nov 2019 14:43:29 +0000 (16:43 +0200)
committerReino Ruusu <reino.ruusu@semantum.fi>
Wed, 20 Nov 2019 15:17:55 +0000 (15:17 +0000)
1. RTreeNode bounds calculation now always uses the detailed geometry of
   district edge nodes to calculate their bounds. This fixes picking to
   work in cases where the detailed geometry falls much outside of the
   spanning rectangle of the edge's end vertices.
2. Introduced DistrictSelectionNode that tells G2DParentNode to ignore
   its bounds instead of nullifying them entirely. This caused the edge
   nodes to fall outside the R-tree as "boundless nodes" which caused
   the most optimized R-tree based picking to fail entirely for nodes
   that are selected when RTreeNode.decompose is executed.

gitlab #68
gitlab #69

Change-Id: I119f33a04923b9b4bf06a8229cfccedc520588cb

org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java
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/DistrictNetworkEdgeNode.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictSelectionNode.java [new file with mode: 0644]

index 0e0a2f5244e517c1dc2fbd9ccf3ab4eec345d4a9..903c2ffa3223b74c251d25154adab949e0a6470b 100644 (file)
@@ -21,6 +21,7 @@ import org.simantics.district.network.DistrictNetworkUtil;
 import org.simantics.district.network.ontology.DistrictNetworkResource;
 import org.simantics.district.network.ui.internal.Activator;
 import org.simantics.district.network.ui.nodes.DistrictRenderingPreparationNode;
+import org.simantics.district.network.ui.nodes.DistrictSelectionNode;
 import org.simantics.district.network.ui.participants.DNPointerInteractor;
 import org.simantics.district.network.ui.participants.DynamicVisualisationContributionsParticipant;
 import org.simantics.district.network.ui.participants.ElevationServerParticipant;
@@ -35,6 +36,7 @@ import org.simantics.g2d.canvas.impl.CanvasContext;
 import org.simantics.g2d.diagram.handler.PickRequest.PickFilter;
 import org.simantics.g2d.diagram.participant.DelayedBatchElementPainter;
 import org.simantics.g2d.diagram.participant.ElementPainter;
+import org.simantics.g2d.diagram.participant.ElementPainterConfiguration;
 import org.simantics.g2d.diagram.participant.Selection;
 import org.simantics.g2d.diagram.participant.ZOrderHandler;
 import org.simantics.g2d.participant.BackgroundPainter;
@@ -66,7 +68,7 @@ public class DistrictDiagramViewer extends DiagramViewer {
     protected void addDiagramParticipants(ICanvasContext ctx) {
         ctx.add(new ZOrderHandler());
         ctx.add(new Selection());
-        ctx.add(new ElementPainter());
+        ctx.add(new ElementPainter(new ElementPainterConfiguration().selectionNodeClass(DistrictSelectionNode.class)));
         ctx.add(new DNPointerInteractor());
         
         AffineTransform tr = new AffineTransform(MapScalingTransform.INSTANCE);
index 8fb105d8870f8f077b9f67407440e3c3b5bd89a7..8af6b20a2b873bbea91d2e15fb4f7a4b2b9af43a 100644 (file)
@@ -112,7 +112,7 @@ public class DistrictNetworkEdgeElement {
             if (size == null)
                 size = new Rectangle2D.Double();
             if (edge != null)
-                size.setFrame(DistrictNetworkEdgeNode.calculatePath(edge, path.get(), false).getBounds2D());
+                size.setFrame(DistrictNetworkEdgeNode.calculatePath(edge, path.get(), true).getBounds2D());
             else
                 LOGGER.debug("Element {} does not have edge!", e);
 
@@ -123,7 +123,7 @@ public class DistrictNetworkEdgeElement {
         public Shape getElementShape(IElement e) {
             DistrictNetworkEdge edge = e.getHint(KEY_DN_EDGE);
             if (edge != null) {
-                return DistrictNetworkEdgeNode.calculatePath(edge, null, false);
+                return DistrictNetworkEdgeNode.calculatePath(edge, null, true);
             } else {
                 return getBounds(e, null);
             }
index 8f8c08e6cc36f7f838e86c2254217f1fff1179fa..e112c536622a3ffdce0a4ad4af64271d865e4bd9 100644 (file)
@@ -263,7 +263,7 @@ public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelection
     }
 
     private Rectangle2D calculateBounds(Rectangle2D rect) {
-        return calculatePath(edge, null, false).getBounds2D();
+        return calculatePath(edge, null, true).getBounds2D();
     }
 
     public void setDNEdge(DistrictNetworkEdge edge) {
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictSelectionNode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictSelectionNode.java
new file mode 100644 (file)
index 0000000..80154dc
--- /dev/null
@@ -0,0 +1,25 @@
+package org.simantics.district.network.ui.nodes;
+
+import java.awt.geom.Rectangle2D;
+
+import org.simantics.scenegraph.g2d.G2DParentNode;
+import org.simantics.scenegraph.utils.GeometryUtils;
+
+/**
+ * Customized selection parent node that returns undefined bounds instead of
+ * <code>null</code> bounds to allow parent G2DNode to ignore these selection
+ * nodes that since they do not have any children in the District scene graph
+ * case.
+ * 
+ * @author Tuukka Lehtonen
+ */
+public class DistrictSelectionNode extends G2DParentNode {
+
+    private static final long serialVersionUID = -6030674263538134789L;
+
+    @Override
+    public Rectangle2D getBoundsInLocal() {
+        return GeometryUtils.undefinedRectangle();
+    }
+
+}