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%2FConnectionLineStyle.java;fp=org.simantics.district.network.ui%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fui%2Fstyles%2FConnectionLineStyle.java;h=d8d2f11838e5ada7bb3302d5fa4aa4230b7f07a1;hb=05fb97a04278adf774281f05135eb6fc369dc3b5;hp=b74cbba676411b33bb6142c55ab10952014de696;hpb=ff5441dd6a85ef6fb92c6b3b0cf709bbce878e5e;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/styles/ConnectionLineStyle.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/styles/ConnectionLineStyle.java index b74cbba6..d8d2f118 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/styles/ConnectionLineStyle.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/styles/ConnectionLineStyle.java @@ -1,11 +1,6 @@ package org.simantics.district.network.ui.styles; -import java.awt.BasicStroke; -import java.awt.Color; -import java.awt.Graphics2D; -import java.awt.geom.Line2D; import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -21,137 +16,79 @@ import org.simantics.diagram.profile.StyleBase; import org.simantics.diagram.stubs.DiagramResource; import org.simantics.district.network.DistrictNetworkUtil; import org.simantics.district.network.ontology.DistrictNetworkResource; -import org.simantics.district.network.ui.nodes.DistrictNetworkNodeUtils; +import org.simantics.district.network.ui.nodes.ConnectionLineNode; import org.simantics.layer0.Layer0; import org.simantics.modeling.ModelingResources; import org.simantics.scenegraph.INode; -import org.simantics.scenegraph.g2d.G2DNode; import org.simantics.scenegraph.profile.EvaluationContext; import org.simantics.scenegraph.profile.common.ProfileVariables; -import org.simantics.scenegraph.utils.GeometryUtils; import org.simantics.scl.compiler.top.ValueNotFound; import org.simantics.scl.osgi.SCLOsgi; import org.simantics.scl.runtime.SCLContext; import org.simantics.scl.runtime.function.Function1; import org.simantics.structural.stubs.StructuralResource2; +@Deprecated public class ConnectionLineStyle extends StyleBase> { - public static class ConnectionLineNode extends G2DNode { - private static final BasicStroke STROKE = new BasicStroke(1.f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1.f, new float[] {4.f, 2.f}, 0.f); - private static final Color[] colors = { Color.RED, Color.GREEN, Color.BLUE, Color.ORANGE, Color.CYAN, Color.PINK }; - - private float strokeWidth; - private Line2D[] lines; + @Override + public List calculateStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource groupItem) + throws DatabaseException { + return doCalculateConnectedComponentPoints(graph, groupItem); + } - public ConnectionLineNode() { - super(); - } - - private static final long serialVersionUID = 1L; + public static List doCalculateConnectedComponentPoints(ReadGraph graph, Resource vertex) throws DatabaseException { + DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); + ModelingResources MOD = ModelingResources.getInstance(graph); + StructuralResource2 STR = StructuralResource2.getInstance(graph); + + if (!graph.isInstanceOf(vertex, DN.Vertex)) + return Collections.emptyList(); - @Override - public Rectangle2D getBoundsInLocal() { - return null; - } + double[] coords = graph.getRelatedValue(vertex, DiagramResource.getInstance(graph).HasLocation); - @Override - public Rectangle2D getBoundsInLocal(boolean b) { - return null; - } + Resource component = DistrictNetworkUtil.getMappedComponentCached(graph, vertex); + if (component == null) + return Collections.emptyList(); - @Override - public Rectangle2D getBounds() { - return null; - } - - public void setStrokeWidth(float w) { - strokeWidth = w; - } - - public void setPoints(List 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 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> fun = getConnectedComponentsFunctionCached(graph, componentType); - if (fun == null) - return Collections.emptyList(); + Resource componentType = graph.getPossibleType(component, STR.Component); + if (componentType == null) + return Collections.emptyList(); + + Function1> fun = getConnectedComponentsFunctionCached(graph, componentType); + if (fun == null) + return Collections.emptyList(); + + List components = Simantics.applySCLRead(graph, fun, component); + + if (components == null || components.isEmpty()) + return Collections.emptyList(); + + List 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; + } - List components = Simantics.applySCLRead(graph, fun, component); - - if (components == null || components.isEmpty()) - return Collections.emptyList(); - - List 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; - } - @Override public void applyStyleForNode(EvaluationContext observer, INode parent, List result) { if (result == null || result.size() < 2) { - ProfileVariables.denyChild(parent, "*", "districtNetworkConnection"); + ProfileVariables.denyChild(parent, "*", ConnectionLineNode.NODE_NAME); return; } - ConnectionLineNode node = ProfileVariables.claimChild(parent, "*", "districtNetworkConnection", ConnectionLineNode.class, observer); + ConnectionLineNode node = ProfileVariables.claimChild(parent, "*", ConnectionLineNode.NODE_NAME, ConnectionLineNode.class, observer); if (node == null) return; @@ -162,7 +99,7 @@ public class ConnectionLineStyle extends StyleBase> { @Override protected void cleanupStyleForNode(EvaluationContext evaluationContext, INode parent) { - ProfileVariables.denyChild(parent, "*", "districtNetworkConnection"); + ProfileVariables.denyChild(parent, "*", ConnectionLineNode.NODE_NAME); } private static Function1> getConnectedComponentsFunctionCached(ReadGraph graph, Resource componentType)