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);
@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) {