- @Override
- public Rectangle2D getBounds() {
- return null;
- }
-
- public void setStrokeWidth(float w) {
- strokeWidth = w;
- }
-
- public void setPoints(List<Point2D> result) {
- Point2D p0 = DistrictNetworkNodeUtils.calculatePoint2D(result.get(0), null);
- lines = new Line2D[result.size() - 1];
- for (int i = 1; i < result.size(); i++)
- {
- Point2D p = result.get(i);
- lines[i-1] = p != null ? new Line2D.Double(p0, DistrictNetworkNodeUtils.calculatePoint2D(p, null)) : null;
- }
- }
-
- @Override
- public void render(Graphics2D g2d) {
- if (lines == null || lines.length == 0)
- return;
-
- // Keep fixed line width on screen
- float scaleRecip = (float) GeometryUtils.getScale(g2d.getTransform());
- g2d.setStroke(GeometryUtils.scaleStroke(STROKE, strokeWidth / scaleRecip));
-
- for (int i = 0; i < lines.length; i++) {
- if (lines[i] != null) {
- g2d.setColor(colors[i % colors.length]);
- g2d.draw(lines[i]);
- }
- }
- }
- }
-
- @Override
- public List<Point2D> calculateStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource groupItem)
- throws DatabaseException {
- DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
- ModelingResources MOD = ModelingResources.getInstance(graph);
- StructuralResource2 STR = StructuralResource2.getInstance(graph);
-
- Resource vertex = groupItem;
- if (!graph.isInstanceOf(vertex, DN.Vertex))
- return Collections.emptyList();
-
- double[] coords = graph.getRelatedValue(vertex, DiagramResource.getInstance(graph).HasLocation);
-
- Resource component = DistrictNetworkUtil.getMappedComponentCached(graph, vertex);
- if (component == null)
- return Collections.emptyList();
-
- Resource componentType = graph.getPossibleType(component, STR.Component);
- if (componentType == null)
- return Collections.emptyList();
-
- Function1<Resource, List<Resource>> fun = getConnectedComponentsFunctionCached(graph, componentType);
- if (fun == null)
- return Collections.emptyList();
+ Resource componentType = graph.getPossibleType(component, STR.Component);
+ if (componentType == null)
+ return Collections.emptyList();
+
+ Function1<Resource, List<Resource>> fun = getConnectedComponentsFunctionCached(graph, componentType);
+ if (fun == null)
+ return Collections.emptyList();
+
+ List<Resource> components = Simantics.applySCLRead(graph, fun, component);
+
+ if (components == null || components.isEmpty())
+ return Collections.emptyList();
+
+ List<Point2D> result = new ArrayList<>(components.size() + 1);
+ result.add(new Point2D.Double(coords[0], coords[1]));
+ for (Resource comp : components) {
+ Resource e = comp != null ? graph.getPossibleObject(comp, MOD.ComponentToElement) : null;
+ Resource mappingElement = e != null ? graph.getPossibleObject(e, DN.MappedFromElement) : null;
+ if (mappingElement != null) {
+ double[] coords2 = graph.getRelatedValue(mappingElement,
+ DiagramResource.getInstance(graph).HasLocation);
+ result.add(new Point2D.Double(coords2[0], coords2[1]));
+ } else {
+ result.add(null);
+ }
+ }
+
+ return result;
+ }