From: Tuukka Lehtonen Date: Wed, 20 Nov 2019 14:43:29 +0000 (+0200) Subject: Fixed two selection/picking related bugs X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F83%2F3583%2F1;p=simantics%2Fdistrict.git Fixed two selection/picking related bugs 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 --- diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java index 0e0a2f52..903c2ffa 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java @@ -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); 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 8fb105d8..8af6b20a 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 @@ -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); } diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java index 8f8c08e6..e112c536 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java @@ -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 index 00000000..80154dc2 --- /dev/null +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictSelectionNode.java @@ -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 + * null 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(); + } + +}