]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.network.ui/src/org/simantics/district/network/ui/NetworkDrawingParticipant.java
Optimization of district scene graph node rendering
[simantics/district.git] / org.simantics.district.network.ui / src / org / simantics / district / network / ui / NetworkDrawingParticipant.java
index 91e48251bb7ed89efc0cf9fb5625a46b6dbbe335..da2bf32aec1a6ab3170e1386da2dddda8a2e9b7b 100644 (file)
@@ -28,7 +28,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;
     
     /**
@@ -53,7 +55,7 @@ public class NetworkDrawingParticipant extends AbstractDiagramParticipant {
 
     @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 +67,41 @@ 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<IElement> pickables = new ArrayList<IElement>();
+        List<IElement> pickables = new ArrayList<>();
         pick.pick(diagram, req, pickables);
-        
-        List<IElement> snap = new ArrayList<>(diagram.getSnapshot());
-        
-        // snap.removeAll(pickables);
-        
+
+        List<IElement> snap = diagram.getSnapshot();
+
         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);
+        changed |= hoverNodes(snap, false, isConnectionTool, currentMousePos);
+        changed |= hoverNodes(pickables, true, isConnectionTool, currentMousePos);
         return changed;
     }
 
-    private boolean hoverVertexNodes(List<IElement> elements, boolean hover, boolean isConnectionTool, boolean changed) {
+    private boolean hoverNodes(List<IElement> elements, boolean hover, boolean isConnectionTool, Point2D p) {
+        boolean changed = false;
         for (IElement elem : elements) {
             Node node = elem.getHint(DistrictNetworkVertexElement.KEY_DN_VERTEX_NODE);
             if (node instanceof DistrictNetworkVertexNode) {
-                changed = ((DistrictNetworkVertexNode) node).hover(hover, isConnectionTool) || changed;
-            }
-        }
-        return changed;
-    }
-    
-    private boolean hoverEdgeNodes(List<IElement> elements, boolean hover, boolean isConnectionTool, boolean changed) {
-        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;
+                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<IElement> pickables = new ArrayList<IElement>();