2 package org.simantics.district.network.ui;
4 import java.awt.geom.AffineTransform;
5 import java.awt.geom.Point2D;
6 import java.util.ArrayList;
9 import org.simantics.district.network.ui.adapters.DistrictNetworkVertexElement;
10 import org.simantics.district.network.ui.nodes.DistrictNetworkVertexNode;
11 import org.simantics.district.network.ui.nodes.NetworkDrawingNode;
12 import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency;
13 import org.simantics.g2d.canvas.impl.SGNodeReflection.SGInit;
14 import org.simantics.g2d.diagram.IDiagram;
15 import org.simantics.g2d.diagram.handler.PickContext;
16 import org.simantics.g2d.diagram.handler.PickRequest;
17 import org.simantics.g2d.diagram.participant.AbstractDiagramParticipant;
18 import org.simantics.g2d.element.IElement;
19 import org.simantics.maps.MapScalingTransform;
20 import org.simantics.scenegraph.g2d.G2DNode;
21 import org.simantics.scenegraph.g2d.G2DParentNode;
22 import org.simantics.utils.datastructures.hints.IHintContext.Key;
23 import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
25 public class NetworkDrawingParticipant extends AbstractDiagramParticipant {
31 * A hint key for terminal pick distance in control pixels.
34 public static final Key KEY_PICK_DISTANCE = new KeyOf(Double.class, "PICK_DISTANCE");
37 * Default terminal pick distance in control pixels.
38 * @see #DEFAULT_PICK_DISTANCE
40 public static final double PICK_DIST = 10;
42 private NetworkDrawingNode node;
44 private AffineTransform transform;
46 public NetworkDrawingParticipant(AffineTransform transform) {
47 this.transform = transform;
51 public void initSG(G2DParentNode parent) {
52 node = parent.addNode("networkDrawingNode", NetworkDrawingNode.class);
53 node.setTransform(transform);
54 node.setNetworkDrawingParticipant(this);
58 protected void onDiagramSet(IDiagram newDiagram, IDiagram oldDiagram) {
59 node.setDiagram(newDiagram);
62 public boolean pickHoveredElement(Point2D currentMousePos) {
63 PickRequest req = new PickRequest(currentMousePos.getX(), currentMousePos.getY());
64 List<IElement> pickables = new ArrayList<IElement>();
65 pick.pick(diagram, req, pickables);
67 List<IElement> snap = new ArrayList<>(diagram.getSnapshot());
69 snap.removeAll(pickables);
71 boolean changed = false;
72 for (IElement sn : snap) {
73 G2DNode node = sn.getHint(DistrictNetworkVertexElement.KEY_DN_VERTEX_NODE);
74 if (node instanceof DistrictNetworkVertexNode) {
75 if (((DistrictNetworkVertexNode) node).hover(false) && !changed) {
81 for (IElement elem : pickables) {
82 G2DNode node = elem.getHint(DistrictNetworkVertexElement.KEY_DN_VERTEX_NODE);
83 if (node instanceof DistrictNetworkVertexNode) {
84 if (((DistrictNetworkVertexNode) node).hover(true) && !changed) {