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=d0bc9551f572df106d24b88704af53afd17874c0;hb=3730466cd1e90c50c988292e107639952448d6a6;hp=89e48813d5551130b6e37dc5a4bb66d7bbbb48c7;hpb=7f3b0d5297006df708f9169e473448ec6f85e211;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 89e48813..d0bc9551 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); @@ -93,61 +94,65 @@ 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) {