]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.network/src/org/simantics/district/network/profile/ArrowLengthStyle.java
Remove unused profile throtting setting & assert diameter as Double
[simantics/district.git] / org.simantics.district.network / src / org / simantics / district / network / profile / ArrowLengthStyle.java
index 3b0524d406f6fe9c9a01d20df10e6587017c6b92..d180d77bd75a98328e7437ab48b57633b5e03a9f 100644 (file)
@@ -1,10 +1,13 @@
 package org.simantics.district.network.profile;
 
+import java.util.Set;
+
 import org.simantics.Simantics;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
-import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
+import org.simantics.db.common.procedure.adapter.TransientCacheListener;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.layer0.Layer0;
 import org.simantics.scenegraph.INode;
 import org.simantics.scenegraph.g2d.G2DSceneGraph;
 import org.simantics.scenegraph.g2d.nodes.ConnectionNode;
@@ -14,26 +17,25 @@ import org.simantics.scenegraph.profile.common.ProfileVariables;
 public class ArrowLengthStyle extends ThrottledStyleBase<Double> {
 
        private static final Double PENDING = Double.NaN;
-       private static final Double ONE = 1.0;
 
        @Override
        public Double calculateThrottledStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource groupItem) throws DatabaseException {
-               DiagramSettings ds = graph.syncRequest(new DiagramSettingsRequest(runtimeDiagram), TransientCacheAsyncListener.instance());
+               Resource diagram = graph.getSingleObject(groupItem, Layer0.getInstance(graph).PartOf);
+               Set<Resource> edgesToUse = graph.syncRequest(new MidBranchEdgeSetRequest(diagram), TransientCacheListener.instance());
+               if (!edgesToUse.contains(groupItem))
+                       return null;
+               
+               DiagramSettings ds = graph.syncRequest(new DiagramSettingsRequest(runtimeDiagram), TransientCacheListener.instance());
                // Prevent PendingVariableExceptions from coming through
                boolean wasSynchronous = graph.setSynchronous(true);
                try {
-                       Double length = ONE;
                        if (ds.arrowLengthProperty.isPresent()) {
-                               length = Simantics.applySCLRead(graph, ds.arrowLengthProperty.get(), groupItem);
-       //                      System.out.println("read thickness: " + thickness + " : " + ds.arrowLengthProperty);
-                               if (length == null) {
-                                       length = ONE;
-                               } else {
-                                       length = length * ds.arrowLengthGain + ds.arrowLengthBias;
-                               }
+                               Double length = Simantics.applySCLRead(graph, ds.arrowLengthProperty.get(), groupItem);
+                               return length != null ? length * ds.arrowLengthGain + ds.arrowLengthBias : null;
+                       }
+                       else {
+                               return null;
                        }
-                       
-                       return length;
                }
                finally {
                        graph.setSynchronous(wasSynchronous);
@@ -60,5 +62,4 @@ public class ArrowLengthStyle extends ThrottledStyleBase<Double> {
                for (INode nn : n.getNodes())
                        ProfileVariables.claimNodeProperty(nn, "arrowLength", null, evaluationContext);
        }
-
 }