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.scenegraph.Node;
20 import org.simantics.scenegraph.g2d.G2DParentNode;
21 import org.simantics.utils.datastructures.hints.IHintContext.Key;
22 import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
24 public class NetworkDrawingParticipant extends AbstractDiagramParticipant {
30 * A hint key for terminal pick distance in control pixels.
33 public static final Key KEY_PICK_DISTANCE = new KeyOf(Double.class, "PICK_DISTANCE");
36 * Default terminal pick distance in control pixels.
37 * @see #DEFAULT_PICK_DISTANCE
39 public static final double PICK_DIST = 10;
41 private NetworkDrawingNode node;
43 private AffineTransform transform;
45 public NetworkDrawingParticipant(AffineTransform transform) {
46 this.transform = transform;
50 public void initSG(G2DParentNode parent) {
51 node = parent.addNode("networkDrawingNode", NetworkDrawingNode.class);
52 node.setTransform(transform);
53 node.setNetworkDrawingParticipant(this);
57 protected void onDiagramSet(IDiagram newDiagram, IDiagram oldDiagram) {
58 node.setDiagram(newDiagram);
61 public boolean pickHoveredElement(Point2D currentMousePos) {
62 PickRequest req = new PickRequest(currentMousePos).context(getContext());
63 List<IElement> pickables = new ArrayList<IElement>();
64 pick.pick(diagram, req, pickables);
66 List<IElement> snap = new ArrayList<>(diagram.getSnapshot());
68 snap.removeAll(pickables);
70 boolean changed = false;
71 for (IElement sn : snap) {
72 Node node = sn.getHint(DistrictNetworkVertexElement.KEY_DN_VERTEX_NODE);
73 if (node instanceof DistrictNetworkVertexNode) {
74 if (((DistrictNetworkVertexNode) node).hover(false) && !changed) {
80 for (IElement elem : pickables) {
81 Node node = elem.getHint(DistrictNetworkVertexElement.KEY_DN_VERTEX_NODE);
82 if (node instanceof DistrictNetworkVertexNode) {
83 if (((DistrictNetworkVertexNode) node).hover(true) && !changed) {
91 public boolean isHoveringOverNode(Point2D currentMousePos) {
92 PickRequest req = new PickRequest(currentMousePos).context(getContext());
93 List<IElement> pickables = new ArrayList<IElement>();
94 pick.pick(diagram, req, pickables);
95 for (IElement elem : pickables) {
96 Node node = elem.getHint(DistrictNetworkVertexElement.KEY_DN_VERTEX_NODE);
97 if (node instanceof DistrictNetworkVertexNode) {
104 public AffineTransform getTransform() {