+
+ @Override
+ public Shape getElementShape(IElement e) {
+ DistrictNetworkEdge edge = e.getHint(KEY_DN_EDGE);
+ if (edge != null) {
+ return DistrictNetworkEdgeNode.calculatePath(edge, null);
+ } else {
+ return getBounds(e, null);
+ }
+ }
+
+ private Shape getSelectionShape(IElement e) {
+ for (SelectionOutline so : e.getElementClass().getItemsByClass(SelectionOutline.class)) {
+ Shape shape = so.getSelectionShape(e);
+ if (shape != null)
+ return shape;
+ }
+ // Using on-diagram coordinates because neither connections nor
+ // edges have a non-identity transform which means that
+ // coordinates are always absolute. Therefore branch point
+ // shape also needs to be calculated in absolute coordinates.
+ Shape shape = ElementUtils.getElementShapeOrBoundsOnDiagram(e);
+ return shape;
+ }
+
+ @Override
+ public boolean pickTest(IElement e, Shape s, PickPolicy policy) {
+ DistrictNetworkEdge edge = e.getHint(KEY_DN_EDGE);
+ if (edge != null) {
+ Rectangle2D bounds = getBounds(s);
+
+ switch (policy) {
+ case PICK_CONTAINED_OBJECTS:
+ Shape selectionShape = getSelectionShape(e);
+ return bounds.contains(selectionShape.getBounds2D());
+
+ case PICK_INTERSECTING_OBJECTS:
+ double tolerance = (bounds.getHeight() + bounds.getHeight()) * 0.25 / MapScalingTransform.getScaleX();
+ Line2D line = new Line2D.Double(edge.getStartPoint(), edge.getEndPoint());
+ double sx = bounds.getCenterX() / MapScalingTransform.getScaleX();
+ double sy = bounds.getCenterY() / MapScalingTransform.getScaleY();
+ double ssx = ModelledCRS.xToLongitude(sx);
+ double ssy = ModelledCRS.yToLatitude(-sy); // Invert for Simantics diagram coordinate system
+ double distSq = line.ptSegDistSq(ssx, ssy);
+// System.out.println("s: " + sx + ", " + sy);
+// System.out.println("ss: " + ssx + ", " + ssy);
+// System.out.println("p1: " + edge.getStartPoint());
+// System.out.println("p2: " + edge.getEndPoint());
+// System.out.println("line: " + "(" + line.getX1() + ", " + line.getY1() + ", " + line.getX2() + ", " + line.getY2() + ")");
+// System.out.println("distance from line is " + Math.sqrt(distSq) + " with tolerance " + tolerance);
+ if (distSq <= tolerance * tolerance) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ return false;
+ }
+
+ private Rectangle2D getBounds(Shape shape) {
+ if (shape instanceof Rectangle2D)
+ return (Rectangle2D) shape;
+ return shape.getBounds2D();
+ }
+