- DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
-
- boolean isEdge = graph.isInstanceOf(mapElement, DN.Edge);
- boolean isVertex = graph.isInstanceOf(mapElement, 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;
- }
-
- DiagramResource DIA = DiagramResource.getInstance(graph);
- StructuralResource2 STR = StructuralResource2.getInstance(graph);
-
- Resource module = DistrictNetworkUtil.getMappedComponentCached(graph, mapElement);
- if (module == null)
- return null;
-
- 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) {
- double[] coords = graph.getRelatedValue(mapElement, DIA.HasLocation);
- Point2D p = DistrictNetworkNodeUtils.calculatePoint2D(new Point2D.Double(coords[0], coords[1]), null);
- return new StyleResult(p, p, result);
- }
- else if (isEdge) {
- Resource v1 = graph.getSingleObject(mapElement, DN.HasStartVertex);
- double[] coords1 = graph.getRelatedValue(v1, DIA.HasLocation);
- Resource v2 = graph.getSingleObject(mapElement, DN.HasEndVertex);
- double[] coords2 = graph.getRelatedValue(v2, DIA.HasLocation);
- Point2D p1 = DistrictNetworkNodeUtils.calculatePoint2D(new Point2D.Double(coords1[0], coords1[1]), null);
- Point2D p2 = DistrictNetworkNodeUtils.calculatePoint2D(new Point2D.Double(coords2[0], coords2[1]), null);
-
- return new StyleResult(p1, p2, 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;