]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Show dynamic symbols when vertices and/or edges are hidden.
authorReino Ruusu <reino.ruusu@semantum.fi>
Fri, 19 Jul 2019 11:24:28 +0000 (14:24 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Sat, 31 Aug 2019 20:10:10 +0000 (23:10 +0300)
gitlab #27

Change-Id: Id9cda3403d1f318b7fd29dd31eeea632749328a5

org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java
org.simantics.district.network/src/org/simantics/district/network/profile/HideStyle.java

index 3e2cb079560489ed7ae1e4495c360b74d4fa858e..5cdc775dd2c07da1aac4bc543fd82fb4ea7836b3 100644 (file)
@@ -16,6 +16,7 @@ import org.simantics.district.network.ui.adapters.DistrictNetworkEdgeElementFact
 import org.simantics.maps.MapScalingTransform;
 import org.simantics.scenegraph.INode;
 import org.simantics.scenegraph.ISelectionPainterNode;
+import org.simantics.scenegraph.INode.PropertySetter;
 import org.simantics.scenegraph.g2d.G2DNode;
 import org.simantics.scenegraph.g2d.G2DParentNode;
 import org.simantics.scenegraph.g2d.nodes.SVGNode;
@@ -50,6 +51,8 @@ public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelection
     private transient Rectangle2D symbolRect;
     private transient AffineTransform symbolTransform;
 
+    private boolean hidden = false;
+    
     private Double arrowLength;
 
     private static double startX;
@@ -70,89 +73,95 @@ public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelection
             g2d.transform(getTransform());
         }
 
-        Object aaHint = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
-        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
-
-        Color oldColor = g2d.getColor();
-        BasicStroke oldStroke = (BasicStroke) g2d.getStroke();
-
-        BasicStroke bs = null;
+        double scale = 1.0;
         if (scaleStroke) {
             AffineTransform tr = g2d.getTransform();
             scale = DistrictNetworkNodeUtils.getScale(tr);
-            bs = GeometryUtils.scaleStroke(STROKE, getStrokeWidth(scale));
-        } else {
-            bs = STROKE;
-        }
-        int zoomLevel = MapScalingTransform.zoomLevel(ot);
-        path = calculatePath(edge, path, zoomLevel > 15);
-
-        if (isSelected()) {
-            g2d.setColor(SELECTION_COLOR);
-            g2d.setStroke(GeometryUtils.scaleAndOffsetStrokeWidth(bs, 1.f, (float)(2 * STROKE.getLineWidth() / scale)));
-            g2d.draw(path);
         }
-
-        g2d.setColor(dynamicColor != null ? dynamicColor : color);
-        g2d.setStroke(bs);
-        g2d.draw(path);
-
-        // Draw arrow
-        if (arrowLength != null) {
-            g2d.setColor(Color.BLACK);
-            g2d.setStroke(new BasicStroke(bs.getLineWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
-            
-            double l = arrowLength;
-            double w = 2 * (double) bs.getLineWidth() * Math.signum(l);
-            if (Math.abs(w) > Math.abs(l)) w = l;
-            double offset = 2 * (double) bs.getLineWidth();
-            
-            double centerX = (startX + endX) / 2, centerY = (startY + endY) / 2;
-            double deltaX = endX - startX, deltaY = endY - startY;
-            double length = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
-            deltaX /= length;
-            deltaY /= length;
-            
-            double x0 = centerX - l/2 * deltaX + offset * deltaY;
-            double y0 = centerY - l/2 * deltaY - offset * deltaX;
-            double x1 = centerX + (l/2 - w) * deltaX + offset * deltaY;
-            double y1 = centerY + (l/2 - w) * deltaY - offset * deltaX;
+       
+        if (!hidden) {
+            Object aaHint = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
+            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+    
+            Color oldColor = g2d.getColor();
+            BasicStroke oldStroke = (BasicStroke) g2d.getStroke();
+    
+            BasicStroke bs = null;
+            if (scaleStroke) {
+                bs = GeometryUtils.scaleStroke(STROKE, getStrokeWidth(scale));
+            } else {
+                bs = STROKE;
+            }
             
-            g2d.draw(new Line2D.Double(x0, y0, x1, y1));
+            int zoomLevel = MapScalingTransform.zoomLevel(ot);
+            path = calculatePath(edge, path, zoomLevel > 15);
+    
+            if (isSelected()) {
+                g2d.setColor(SELECTION_COLOR);
+                g2d.setStroke(GeometryUtils.scaleAndOffsetStrokeWidth(bs, 1.f, (float)(2 * STROKE.getLineWidth() / scale)));
+                g2d.draw(path);
+            }
+    
+            g2d.setColor(dynamicColor != null ? dynamicColor : color);
+            g2d.setStroke(bs);
+            g2d.draw(path);
+    
+            // Draw arrow
+            if (arrowLength != null) {
+                g2d.setColor(Color.BLACK);
+                float lw = STROKE.getLineWidth() / (float)scale;
+                g2d.setStroke(new BasicStroke(lw, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
+                
+                double l = arrowLength;
+                double w = 2 * (double) lw * Math.signum(l);
+                if (Math.abs(w) > Math.abs(l)) w = l;
+                double offset = 2 * (double) lw;
+                
+                double centerX = (startX + endX) / 2, centerY = (startY + endY) / 2;
+                double deltaX = endX - startX, deltaY = endY - startY;
+                double length = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
+                deltaX /= length;
+                deltaY /= length;
+                
+                double x0 = centerX - l/2 * deltaX + offset * deltaY;
+                double y0 = centerY - l/2 * deltaY - offset * deltaX;
+                double x1 = centerX + (l/2 - w) * deltaX + offset * deltaY;
+                double y1 = centerY + (l/2 - w) * deltaY - offset * deltaX;
+                
+                g2d.draw(new Line2D.Double(x0, y0, x1, y1));
+                
+                Path2D path = new Path2D.Double();
+                path.moveTo(x1 + w * deltaX, y1 + w * deltaY);
+                path.lineTo(x1 + w * deltaY, y1 - w * deltaX);
+                path.lineTo(x1 - w * deltaY, y1 + w * deltaX);
+                path.closePath();
+                g2d.fill(path);
+            }
             
-            Path2D path = new Path2D.Double();
-            path.moveTo(x1 + w * deltaX, y1 + w * deltaY);
-            path.lineTo(x1 + w * deltaY, y1 - w * deltaX);
-            path.lineTo(x1 - w * deltaY, y1 + w * deltaX);
-            path.closePath();
-            g2d.fill(path);
-        }
-        
-        // Reset
-        g2d.setStroke(oldStroke);
-        g2d.setColor(oldColor);
-        
-        // Render SVG symbol
-        double viewScaleRecip = 10;
-        if (scaleStroke) {
-            double scale = GeometryUtils.getScale(g2d.getTransform());
-            scale = Math.max(10000, Math.min(scale, 50000));
-            viewScaleRecip /= scale;
+            // Reset
+            g2d.setStroke(oldStroke);
+            g2d.setColor(oldColor);
+            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, aaHint);
         }
-        
-        Point2D p = getCenterPoint();
-        symbolRect = DistrictNetworkNodeUtils.calculateDrawnGeometry(p, NORMAL, symbolRect, viewScaleRecip);
-        symbolTransform = DistrictNetworkNodeUtils.getTransformToRectangle(symbolRect, symbolTransform);
-        
+            
         for (INode nn : getNodes()) {
             G2DNode g2dNode = (G2DNode)nn;
-            if (g2dNode instanceof SVGNode)
+            if (g2dNode instanceof SVGNode) {
+                // Render SVG symbol
+                double viewScaleRecip = 10;
+                if (scaleStroke) {
+                    viewScaleRecip /= scale;
+                }
+                
+                Point2D p = getCenterPoint();
+                symbolRect = DistrictNetworkNodeUtils.calculateDrawnGeometry(p, NORMAL, symbolRect, viewScaleRecip);
+                symbolTransform = DistrictNetworkNodeUtils.getTransformToRectangle(symbolRect, symbolTransform);
+                
                 g2dNode.setTransform(symbolTransform);
+            }
             g2dNode.render(g2d);
         }
         
-        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, aaHint);
-
         if (ot != null)
             g2d.setTransform(ot);
     }
@@ -284,4 +293,9 @@ public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelection
                 ((SVGNode)nn).setData(value);
     }
     
+
+    @PropertySetter(value = "hidden")
+    public void setHidden(Boolean value) {
+        this.hidden = value;
+    }
 }
index 061a883e427f52a3f096098d3db01d0f4c0253d8..2e2b4293871114144b53fb50e73d99065ac7c10e 100644 (file)
@@ -51,6 +51,8 @@ public class DistrictNetworkVertexNode extends G2DParentNode implements ISelecti
 
     private double nodeSize = 1.0;
 
+    private boolean hidden = false;
+
     @Override
     public void init() {
         setZIndex(2);
@@ -58,9 +60,6 @@ public class DistrictNetworkVertexNode extends G2DParentNode implements ISelecti
 
     @Override
     public void render(Graphics2D g2d) {
-        if (nodeSize <= 0.0)
-            return;
-
         AffineTransform ot = null;
         AffineTransform t = getTransform();
         if (t != null && !t.isIdentity()) {
@@ -68,50 +67,55 @@ public class DistrictNetworkVertexNode extends G2DParentNode implements ISelecti
             g2d.transform(t);
         }
 
-        Object oaaHint = null;
-        Object aaHint = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
-        if (aaHint != RenderingHints.VALUE_ANTIALIAS_OFF) {
-            oaaHint = aaHint;
-            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
-        }
-
-        Color oldColor = g2d.getColor();
-        Color newColor = dynamicColor != null ? dynamicColor : color;
-        boolean changeColor = !oldColor.equals(newColor);
-
+        // Translate lat and lon to X and Y
+        Point2D p = point = DistrictNetworkNodeUtils.calculatePoint2D(vertex.getPoint(), point);
+        
         double viewScaleRecip = 1;
         if (scaleStroke) {
             viewScaleRecip *= DistrictNetworkNodeUtils.calculateScaleRecip(g2d.getTransform());
         }
-        double scaleRecip = viewScaleRecip * nodeSize;
-
-        // Translate lat and lon to X and Y
-        Point2D p = point = DistrictNetworkNodeUtils.calculatePoint2D(vertex.getPoint(), point);
-        Rectangle2D toDraw = rect = DistrictNetworkNodeUtils.calculateDrawnGeometry(p, hover ? HOVERED : NORMAL, rect, scaleRecip);
-
-        if (NodeUtil.isSelected(this, 1)) {
-            changeColor = true;
-            g2d.setColor(SELECTION_COLOR);
-            BasicStroke ss = GeometryUtils.scaleStroke(STROKE, (float)viewScaleRecip);
-            g2d.setStroke(ss);
-            g2d.draw(toDraw);
-        }
-
-        // render
-        if (changeColor)
-            g2d.setColor(newColor);
-        g2d.fill(toDraw);
         
-        // Reset settings
-        if (changeColor)
-            g2d.setColor(oldColor);
-        if (oaaHint != null)
-            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, aaHint);
+        if (!hidden && nodeSize > 0.0) {
+            Object oaaHint = null;
+            Object aaHint = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
+            if (aaHint != RenderingHints.VALUE_ANTIALIAS_OFF) {
+                oaaHint = aaHint;
+                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
+            }
+    
+            Color oldColor = g2d.getColor();
+            Color newColor = dynamicColor != null ? dynamicColor : color;
+            boolean changeColor = !oldColor.equals(newColor);
+    
+            double scaleRecip = viewScaleRecip * nodeSize;
+    
+            Rectangle2D toDraw = rect = DistrictNetworkNodeUtils.calculateDrawnGeometry(p, hover ? HOVERED : NORMAL, rect, scaleRecip);
+    
+            if (NodeUtil.isSelected(this, 1)) {
+                changeColor = true;
+                g2d.setColor(SELECTION_COLOR);
+                BasicStroke ss = GeometryUtils.scaleStroke(STROKE, (float)viewScaleRecip);
+                g2d.setStroke(ss);
+                g2d.draw(toDraw);
+            }
+    
+            // render
+            if (changeColor)
+                g2d.setColor(newColor);
+            g2d.fill(toDraw);
+            
+            // Reset settings
+            if (changeColor)
+                g2d.setColor(oldColor);
+            if (oaaHint != null)
+                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, aaHint);
+        }
 
         // Render SVG symbol
         for (INode nn : getNodes()) {
             G2DNode g2dNode = (G2DNode)nn;
             if (nn instanceof SVGNode) {
+                Rectangle2D toDraw = rect = DistrictNetworkNodeUtils.calculateDrawnGeometry(p, hover ? HOVERED : NORMAL, rect, viewScaleRecip);
                 symbolTransform = DistrictNetworkNodeUtils.getTransformToRectangle(toDraw, symbolTransform);
                 g2dNode.setTransform(symbolTransform);
             }
@@ -231,4 +235,8 @@ public class DistrictNetworkVertexNode extends G2DParentNode implements ISelecti
         this.dynamicColor = color;
     }
 
+    @PropertySetter(value = "hidden")
+    public void setHidden(Boolean value) {
+        this.hidden = value;
+    }
 }
index e1d8bd046444ef222ed103563ea0b2de312f110f..d5f57c8296efcb157a5665ef9432bf45968643f8 100644 (file)
@@ -3,16 +3,11 @@ package org.simantics.district.network.profile;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.exception.DatabaseException;
-import org.simantics.diagram.profile.ProfileKeys;
 import org.simantics.diagram.profile.StyleBase;
-import org.simantics.g2d.diagram.IDiagram;
-import org.simantics.g2d.diagram.handler.DataElementMap;
-import org.simantics.g2d.element.ElementUtils;
-import org.simantics.g2d.element.IElement;
 import org.simantics.scenegraph.INode;
 import org.simantics.scenegraph.g2d.nodes.SingleElementNode;
-import org.simantics.scenegraph.profile.DataNodeMap;
 import org.simantics.scenegraph.profile.EvaluationContext;
+import org.simantics.scenegraph.profile.common.ProfileVariables;
 
 /**
  * @author Tuukka Lehtonen
@@ -25,51 +20,17 @@ public class HideStyle extends StyleBase<Boolean> {
     }
 
     @Override
-    public void applyStyleForItem(EvaluationContext evaluationContext, DataNodeMap map, Object item, Boolean value) {
-        INode node = map.getNode(item);
-        if (node == null) {
-            evaluationContext.update();
-            return;
-        }
-
-        IDiagram diagram = evaluationContext.getConstant(ProfileKeys.DIAGRAM);
-        DataElementMap emap = diagram.getDiagramClass().getSingleItem(DataElementMap.class);
-        IElement element = emap.getElement(diagram, item);
-        if (element == null)
-            return;
-
-        hideElements(evaluationContext, diagram, element, node);
+    public void applyStyleForNode(EvaluationContext evaluationContext, INode node, Boolean result) {
+        SingleElementNode n = (SingleElementNode) node;
+        for (INode nn : n.getNodes())
+            ProfileVariables.claimNodeProperty(nn, "hidden", true, evaluationContext);
     }
-
+    
     @Override
-    protected void cleanupStyleForItem(EvaluationContext evaluationContext, DataNodeMap map, Object item) {
-        IDiagram diagram = evaluationContext.getConstant(ProfileKeys.DIAGRAM);
-        DataElementMap emap = diagram.getDiagramClass().getSingleItem(DataElementMap.class);
-
-        INode node = map.getNode(item);
-        if (node == null)
-            return;
-        IElement element = emap.getElement(diagram, item);
-        if (element == null)
-            return;
-
-        showElements(diagram, element, node);
-    }
-
-    protected void hideElements(EvaluationContext evaluationContext, IDiagram diagram, IElement element, INode node) {
-        setVisibility(element, node, false);
-    }
-
-    protected void showElements(IDiagram diagram, IElement element, INode node) {
-        setVisibility(element, node, true);
-    }
-
-    protected void setVisibility(IElement element, INode node, boolean visible) {
-        if (element != null)
-            ElementUtils.setHidden(element, !visible);
-        if (node instanceof SingleElementNode) {
-            ((SingleElementNode) node).setHidden(!visible);
-        }
+    protected void cleanupStyleForNode(EvaluationContext evaluationContext, INode node) {
+        SingleElementNode n = (SingleElementNode) node;
+        for (INode nn : n.getNodes())
+            ProfileVariables.claimNodeProperty(nn, "hidden", false, evaluationContext);
     }
 
     @Override