X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.network.ui%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fui%2Fstyles%2FDistrictNetworkStaticInfoStyle.java;h=3dff9ad91ddc068a595b6da8176b03633224dc17;hb=a995d5d46f03f25bd77fb3f6d8349839886b2ec2;hp=ebdc01418e848423c3d3f30b0fd3f4a3f38251c8;hpb=2333f640dbaab4148fab8130515374aec9a27d9f;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/styles/DistrictNetworkStaticInfoStyle.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/styles/DistrictNetworkStaticInfoStyle.java index ebdc0141..3dff9ad9 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/styles/DistrictNetworkStaticInfoStyle.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/styles/DistrictNetworkStaticInfoStyle.java @@ -42,6 +42,7 @@ import org.simantics.structural.stubs.StructuralResource2; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Deprecated public class DistrictNetworkStaticInfoStyle extends StyleBase { private static final Logger LOGGER = LoggerFactory.getLogger(DistrictNetworkStaticInfoStyle.class); @@ -49,8 +50,6 @@ public class DistrictNetworkStaticInfoStyle extends StyleBase 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 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 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 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 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 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) { @@ -157,7 +160,7 @@ public class DistrictNetworkStaticInfoStyle extends StyleBase root = (ParentNode) NodeUtil.getNearestParentOfType(parent, RTreeNode.class); if (root != null) { - DeferredRenderingNode deferred = ProfileVariables.claimChild(root, "", STATIC_INFO_DEFERRED, DeferredRenderingNode.class, evaluationContext); + DeferredRenderingNode deferred = ProfileVariables.claimChild(root, "", DistrictNetworkStaticInfoNode.STATIC_INFO_DEFERRED, DeferredRenderingNode.class, evaluationContext); deferred.setZIndex(Integer.MAX_VALUE-1); }