X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.network.ui%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fui%2FNetworkDrawingParticipant.java;h=77ec735f6d2cc14c9f6013127244b6e82fac3ace;hb=900f0e33431c1e3ea7d94d73cbf4d21f533dac26;hp=91e48251bb7ed89efc0cf9fb5625a46b6dbbe335;hpb=731368eea74c3292199315a38d6914b09b813632;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/NetworkDrawingParticipant.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/NetworkDrawingParticipant.java index 91e48251..77ec735f 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/NetworkDrawingParticipant.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/NetworkDrawingParticipant.java @@ -7,18 +7,22 @@ import java.awt.geom.Rectangle2D; import java.util.ArrayList; import java.util.List; +import org.simantics.db.Resource; +import org.simantics.diagram.ui.DiagramModelHints; import org.simantics.district.network.ui.adapters.DistrictNetworkEdgeElement; import org.simantics.district.network.ui.adapters.DistrictNetworkVertexElement; import org.simantics.district.network.ui.nodes.DistrictNetworkEdgeNode; import org.simantics.district.network.ui.nodes.DistrictNetworkVertexNode; import org.simantics.district.network.ui.nodes.HoverSensitiveNode; import org.simantics.district.network.ui.nodes.NetworkDrawingNode; +import org.simantics.district.network.ui.participants.DynamicVisualisationContributionsParticipant; import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency; import org.simantics.g2d.canvas.impl.SGNodeReflection.SGInit; import org.simantics.g2d.diagram.IDiagram; import org.simantics.g2d.diagram.handler.PickContext; import org.simantics.g2d.diagram.handler.PickRequest; import org.simantics.g2d.diagram.participant.AbstractDiagramParticipant; +import org.simantics.g2d.element.ElementHints; import org.simantics.g2d.element.IElement; import org.simantics.scenegraph.Node; import org.simantics.scenegraph.g2d.G2DParentNode; @@ -28,7 +32,9 @@ import org.simantics.utils.datastructures.hints.IHintContext.KeyOf; public class NetworkDrawingParticipant extends AbstractDiagramParticipant { - @Dependency + public static final String NETWORK_DRAWING_NODE = "networkDrawingNode"; + + @Dependency PickContext pick; /** @@ -45,15 +51,17 @@ public class NetworkDrawingParticipant extends AbstractDiagramParticipant { private NetworkDrawingNode node; + private DynamicVisualisationContributionsParticipant dynamicVisualisationContributionsParticipant; private AffineTransform transform; - public NetworkDrawingParticipant(AffineTransform transform) { + public NetworkDrawingParticipant(DynamicVisualisationContributionsParticipant dynamicVisualisationContributionsParticipant, AffineTransform transform) { + this.dynamicVisualisationContributionsParticipant = dynamicVisualisationContributionsParticipant; this.transform = transform; } @SGInit public void initSG(G2DParentNode parent) { - node = parent.addNode("networkDrawingNode", NetworkDrawingNode.class); + node = parent.addNode(NETWORK_DRAWING_NODE, NetworkDrawingNode.class); node.setTransform(transform); node.setNetworkDrawingParticipant(this); } @@ -65,45 +73,66 @@ public class NetworkDrawingParticipant extends AbstractDiagramParticipant { public boolean pickHoveredElement(Point2D currentMousePos, boolean isConnectionTool) { PickRequest req = new PickRequest(new Rectangle2D.Double(currentMousePos.getX(), currentMousePos.getY(), 1e-8, 1e-8)).context(getContext()); - List pickables = new ArrayList(); + List pickables = new ArrayList<>(); pick.pick(diagram, req, pickables); + + List snap = diagram.getSnapshot(); + + hoverNodes2(pickables, true, isConnectionTool, currentMousePos); + // we repaint ourselves once the async calulation is ready + return false; - List snap = new ArrayList<>(diagram.getSnapshot()); - - // snap.removeAll(pickables); - - boolean changed = false; - changed = hoverVertexNodes(snap, false, isConnectionTool, changed); - changed = hoverEdgeNodes(snap, false, isConnectionTool, changed); - changed = hoverVertexNodes(pickables, true, isConnectionTool, changed); - changed = hoverEdgeNodes(pickables, true, isConnectionTool, changed); - return changed; +// boolean changed = false; +// changed |= hoverNodes(snap, false, isConnectionTool, currentMousePos); +// changed |= hoverNodes(pickables, true, isConnectionTool, currentMousePos); + //return changed; } - private boolean hoverVertexNodes(List elements, boolean hover, boolean isConnectionTool, boolean changed) { - for (IElement elem : elements) { - Node node = elem.getHint(DistrictNetworkVertexElement.KEY_DN_VERTEX_NODE); - if (node instanceof DistrictNetworkVertexNode) { - changed = ((DistrictNetworkVertexNode) node).hover(hover, isConnectionTool) || changed; + private boolean hoverNodes2(List elements, boolean hover, boolean isConnectionTool, Point2D p) { + if (elements == null || elements.isEmpty()) { + return dynamicVisualisationContributionsParticipant.doHover(false, isConnectionTool); + } else { + boolean changed = dynamicVisualisationContributionsParticipant.doHover(true, isConnectionTool); + if (changed) { + // we prefer the first picked element only + IElement elem = elements.get(0); + G2DParentNode node = elem.getHint(DistrictNetworkVertexElement.KEY_DN_VERTEX_NODE); + if (node instanceof DistrictNetworkVertexNode) { + } else { + node = elem.getHint(DistrictNetworkEdgeElement.KEY_DN_EDGE_NODE); + } + Resource mapElement = elem.getHint(ElementHints.KEY_OBJECT); + Resource runtimeDiagram = diagram.getHint(DiagramModelHints.KEY_DIAGRAM_RUNTIME_RESOURCE); + dynamicVisualisationContributionsParticipant.hoverNode(runtimeDiagram, mapElement, node); } + return changed; } - return changed; } - - private boolean hoverEdgeNodes(List elements, boolean hover, boolean isConnectionTool, boolean changed) { + + private boolean hoverNodes(List elements, boolean hover, boolean isConnectionTool, Point2D p) { + boolean changed = false; for (IElement elem : elements) { - Node node = elem.getHint(DistrictNetworkEdgeElement.KEY_DN_EDGE_NODE); - if (node instanceof DistrictNetworkEdgeNode) { - for (IG2DNode n : ((DistrictNetworkEdgeNode) node).getNodes()) { - if (n instanceof HoverSensitiveNode) { - changed = ((HoverSensitiveNode)n).hover(hover, isConnectionTool) || changed; + Node node = elem.getHint(DistrictNetworkVertexElement.KEY_DN_VERTEX_NODE); + if (node instanceof DistrictNetworkVertexNode) { + changed |= ((DistrictNetworkVertexNode) node).hover(hover, isConnectionTool); + if (hover) + ((DistrictNetworkVertexNode) node).setMousePosition(p); + } else { + node = elem.getHint(DistrictNetworkEdgeElement.KEY_DN_EDGE_NODE); + if (node instanceof DistrictNetworkEdgeNode) { + for (IG2DNode n : ((DistrictNetworkEdgeNode) node).getNodes()) { + if (n instanceof HoverSensitiveNode) { + changed |= ((HoverSensitiveNode)n).hover(hover, isConnectionTool); + if (hover) + ((HoverSensitiveNode)n).setMousePosition(p); + } } } } } return changed; } - + public boolean isHoveringOverNode(Point2D currentMousePos) { PickRequest req = new PickRequest(currentMousePos).context(getContext()); List pickables = new ArrayList();