]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java
Move remaining profiles to visualisations for perf
[simantics/district.git] / org.simantics.district.network.ui / src / org / simantics / district / network / ui / nodes / DistrictNetworkVertexNode.java
index 2e2b4293871114144b53fb50e73d99065ac7c10e..b1bb1468dd63653ee1c423a9653fbc307088bc8e 100644 (file)
@@ -7,6 +7,7 @@ import java.awt.RenderingHints;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Point2D;
 import java.awt.geom.Rectangle2D;
+import java.util.Optional;
 
 import org.simantics.district.network.ui.adapters.DistrictNetworkVertex;
 import org.simantics.maps.MapScalingTransform;
@@ -14,6 +15,7 @@ import org.simantics.scenegraph.INode;
 import org.simantics.scenegraph.ISelectionPainterNode;
 import org.simantics.scenegraph.g2d.G2DNode;
 import org.simantics.scenegraph.g2d.G2DParentNode;
+import org.simantics.scenegraph.g2d.G2DRenderingHints;
 import org.simantics.scenegraph.g2d.IG2DNode;
 import org.simantics.scenegraph.g2d.nodes.SVGNode;
 import org.simantics.scenegraph.utils.GeometryUtils;
@@ -38,7 +40,7 @@ public class DistrictNetworkVertexNode extends G2DParentNode implements ISelecti
 
     private DistrictNetworkVertex vertex;
 
-    private boolean scaleStroke = true;
+    private static boolean scaleStroke = true;
     private boolean hover;
 
     private Color color;
@@ -62,19 +64,25 @@ public class DistrictNetworkVertexNode extends G2DParentNode implements ISelecti
     public void render(Graphics2D g2d) {
         AffineTransform ot = null;
         AffineTransform t = getTransform();
+        double viewScaleRecip = scaleStroke ? (Double) g2d.getRenderingHint(DistrictRenderingHints.KEY_VIEW_SCALE_RECIPROCAL_UNDER_SPATIAL_ROOT) : 1.0;
         if (t != null && !t.isIdentity()) {
-            ot = g2d.getTransform();
+            //ot = g2d.getTransform();
+            ot = (AffineTransform) g2d.getRenderingHint(G2DRenderingHints.KEY_TRANSFORM_UNDER_SPATIAL_ROOT);
+            if (ot == null)
+                ot = g2d.getTransform();
             g2d.transform(t);
+
+            if (scaleStroke) {
+                AffineTransform work = DistrictNetworkNodeUtils.sharedTransform.get();
+                work.setTransform(ot);
+                work.concatenate(t);
+                viewScaleRecip = DistrictNetworkNodeUtils.calculateScaleRecip(work);
+            }
         }
 
         // 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());
-        }
-        
+
         if (!hidden && nodeSize > 0.0) {
             Object oaaHint = null;
             Object aaHint = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
@@ -152,11 +160,6 @@ public class DistrictNetworkVertexNode extends G2DParentNode implements ISelecti
         updateBounds();
     }
 
-    @Override
-    public AffineTransform getTransform() {
-        return super.getTransform();
-    }
-
     private Rectangle2D calculateBounds(Rectangle2D rect) {
         Point2D calcPoint = DistrictNetworkNodeUtils.calculatePoint2D(vertex.getPoint(), point);
         AffineTransform at = NodeUtil.getLocalToGlobalTransform(this);
@@ -177,6 +180,10 @@ public class DistrictNetworkVertexNode extends G2DParentNode implements ISelecti
         updateBounds();
     }
 
+    public DistrictNetworkVertex getVertex() {
+        return vertex;
+    }
+
     @Override
     public boolean hover(boolean hover, boolean isConnectionTool) {
         // Only react to hover when the connection tool is active
@@ -239,4 +246,25 @@ public class DistrictNetworkVertexNode extends G2DParentNode implements ISelecti
     public void setHidden(Boolean value) {
         this.hidden = value;
     }
+
+    public void setStaticInformation(Optional<String> staticInformation) {
+        DistrictNetworkStaticInfoNode child = getOrCreateNode(DistrictNetworkStaticInfoNode.NODE_KEY, DistrictNetworkStaticInfoNode.class);
+        Point2D calculatePoint2D = DistrictNetworkNodeUtils.calculatePoint2D(vertex.getPoint(), null);
+        child.setLocation(calculatePoint2D, new Point2D.Double(1.0, 0.0));
+        if (staticInformation.isPresent()) {
+            child.setInfo(staticInformation.get());
+        } else {
+            child.setInfo(null);
+        }
+    }
+    
+    public void setInSimulation(Optional<Boolean> isInSimulation) {
+        if (!isInSimulation.isPresent()) {
+            removeNode(NotInSimulationNode.NODE_NAME);
+        } else {
+            NotInSimulationNode child = getOrCreateNode(NotInSimulationNode.NODE_NAME, NotInSimulationNode.class);
+            child.setZIndex(1000);
+            child.setIsInSimulation(isInSimulation.get());
+        }
+    }
 }