]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.network.ui/src/org/simantics/district/network/ui/styles/DistrictNetworkStaticInfoStyle.java
Move remaining profiles to visualisations for perf
[simantics/district.git] / org.simantics.district.network.ui / src / org / simantics / district / network / ui / styles / DistrictNetworkStaticInfoStyle.java
index ebdc01418e848423c3d3f30b0fd3f4a3f38251c8..ca592acfdd52d58647b2da056949273a403485fd 100644 (file)
@@ -42,6 +42,7 @@ import org.simantics.structural.stubs.StructuralResource2;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@Deprecated
 public class DistrictNetworkStaticInfoStyle extends StyleBase<DistrictNetworkStaticInfoStyle.StyleResult> {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(DistrictNetworkStaticInfoStyle.class);
@@ -93,61 +94,65 @@ public class DistrictNetworkStaticInfoStyle extends StyleBase<DistrictNetworkSta
        @Override
        public StyleResult calculateStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource mapElement)
                        throws DatabaseException {
-               DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
-               Set<Resource> types = graph.getTypes(mapElement);
-               boolean isEdge = types.contains(DN.Edge);
-               boolean isVertex = types.contains(DN.Vertex);
-               if (!isEdge && !isVertex)
-                       return null;
-
-               if (isEdge) {
-                       Resource diagram = graph.getSingleObject(mapElement, Layer0.getInstance(graph).PartOf);
-                       Set<Resource> edgesToUse = graph.syncRequest(new MidBranchEdgeSetRequest(diagram), TransientCacheListener.instance());
-                       if (!edgesToUse.contains(mapElement))
-                               return null;
-               }
-
-               Resource module = DistrictNetworkUtil.getMappedComponentCached(graph, mapElement);
-               if (module == null)
-                       return null;
-
-               StructuralResource2 STR = StructuralResource2.getInstance(graph);
-               Resource moduleType = graph.getPossibleType(module, STR.Component);
-               if (moduleType == null)
-                       return null;
-
-               Function1<Variable, String> function = getUCPipelineInfoFunctionCached(graph, moduleType);
-               if (function == null)
-                       return null;
-
-               String result;
-               try {
-                       Variable variable = Variables.getVariable(graph, module);
-                       Variable moduleVariable = Variables.possibleActiveVariable(graph, variable);
-                       if (moduleVariable == null)
-                               moduleVariable = variable;
-
-                       result = Simantics.applySCLRead(graph, function, moduleVariable);
-               } catch (PendingVariableException | MissingVariableValueException e) {
-                       result = null;
-               } catch (MissingVariableException e) {
-                       // the requested variable is missing from the UC
-                       String message = e.getMessage();
-                       LOGGER.warn("Missing variable for calculating style with function {} {}", function, message);
-                       result = "<" + message + ">";
-               }
-
-               if (isVertex) {
-                       DiagramResource DIA = DiagramResource.getInstance(graph);
-                       double[] coords = graph.getRelatedValue(mapElement, DIA.HasLocation);
-                       Point2D p = DistrictNetworkNodeUtils.calculatePoint2D(new Point2D.Double(coords[0], coords[1]), null);
-                       return new StyleResult(mapElement, p, result);
-               } else if (isEdge) {
-                       return new StyleResult(mapElement, EDGE, result);
-               }
-               return null;
+           return calculateStyle(graph, entry, mapElement);
        }
 
+       public static StyleResult calculateStyle(ReadGraph graph, Resource entry, Resource mapElement) throws DatabaseException {
+        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+        Set<Resource> types = graph.getTypes(mapElement);
+        boolean isEdge = types.contains(DN.Edge);
+        boolean isVertex = types.contains(DN.Vertex);
+        if (!isEdge && !isVertex)
+            return null;
+
+        if (isEdge) {
+            Resource diagram = graph.getSingleObject(mapElement, Layer0.getInstance(graph).PartOf);
+            Set<Resource> edgesToUse = graph.syncRequest(new MidBranchEdgeSetRequest(diagram), TransientCacheListener.instance());
+            if (!edgesToUse.contains(mapElement))
+                return null;
+        }
+
+        Resource module = DistrictNetworkUtil.getMappedComponentCached(graph, mapElement);
+        if (module == null)
+            return null;
+
+        StructuralResource2 STR = StructuralResource2.getInstance(graph);
+        Resource moduleType = graph.getPossibleType(module, STR.Component);
+        if (moduleType == null)
+            return null;
+
+        Function1<Variable, String> function = getUCPipelineInfoFunctionCached(graph, moduleType);
+        if (function == null)
+            return null;
+
+        String result;
+        try {
+            Variable variable = Variables.getVariable(graph, module);
+            Variable moduleVariable = Variables.possibleActiveVariable(graph, variable);
+            if (moduleVariable == null)
+                moduleVariable = variable;
+
+            result = Simantics.applySCLRead(graph, function, moduleVariable);
+        } catch (PendingVariableException | MissingVariableValueException e) {
+            result = null;
+        } catch (MissingVariableException e) {
+            // the requested variable is missing from the UC
+            String message = e.getMessage();
+            LOGGER.warn("Missing variable for calculating style with function {} {}", function, message);
+            result = "<" + message + ">";
+        }
+
+        if (isVertex) {
+            DiagramResource DIA = DiagramResource.getInstance(graph);
+            double[] coords = graph.getRelatedValue(mapElement, DIA.HasLocation);
+            Point2D p = DistrictNetworkNodeUtils.calculatePoint2D(new Point2D.Double(coords[0], coords[1]), null);
+            return new StyleResult(mapElement, p, result);
+        } else if (isEdge) {
+            return new StyleResult(mapElement, EDGE, result);
+        }
+        return null;
+       }
+       
        @Override
        public void applyStyleForNode(EvaluationContext evaluationContext, INode parent, StyleResult result) {
                if (result == null) {