X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.network.ui%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fui%2Fnodes%2FDistrictNetworkEdgeNode.java;h=00a1427f5f2e6d07f72c6770364f94892afb64c1;hb=835710a4f22ec2d91c287295fb176a0af62d1186;hp=9f8c9a23ed192245813cdccd1ddbf2a0a61ddc16;hpb=2cf7ae447c79df6240b67fd3ca4f0338bdae8c00;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java index 9f8c9a23..00a1427f 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java @@ -7,16 +7,20 @@ import java.awt.RenderingHints; import java.awt.geom.AffineTransform; import java.awt.geom.Line2D; import java.awt.geom.Path2D; +import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import org.simantics.district.network.ModelledCRS; import org.simantics.district.network.ui.DistrictNetworkEdge; +import org.simantics.scenegraph.INode; import org.simantics.scenegraph.ISelectionPainterNode; import org.simantics.scenegraph.g2d.G2DNode; +import org.simantics.scenegraph.g2d.G2DParentNode; +import org.simantics.scenegraph.g2d.nodes.SVGNode; import org.simantics.scenegraph.utils.GeometryUtils; import org.simantics.scenegraph.utils.NodeUtil; -public class DistrictNetworkEdgeNode extends G2DNode implements ISelectionPainterNode { +public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelectionPainterNode { private static final long serialVersionUID = 8049769475036519806L; @@ -32,6 +36,18 @@ public class DistrictNetworkEdgeNode extends G2DNode implements ISelectionPainte private Double stroke; private transient Color dynamicColor = null; + // Dimensions for shut-off valve symbol + private static final double left = -0.25; + private static final double top = -0.25; + private static final double width = 0.5; + private static final double height = 0.5; + + private static final Rectangle2D NORMAL = new Rectangle2D.Double(left, top, width, height); + + private transient Point2D centerPoint; + private transient Rectangle2D symbolRect; + private transient AffineTransform symbolTransform; + @Override public void init() { } @@ -76,12 +92,40 @@ public class DistrictNetworkEdgeNode extends G2DNode implements ISelectionPainte // Reset g2d.setStroke(oldStroke); g2d.setColor(oldColor); + + // Render SVG symbol + double viewScaleRecip = 10; + if (scaleStroke) { + double scale = GeometryUtils.getScale(g2d.getTransform()); + scale = Math.max(10000, Math.min(scale, 50000)); + viewScaleRecip /= scale; + } + + Point2D p = getCenterPoint(); + symbolRect = DistrictNetworkNodeUtils.calculateDrawnGeometry(p, NORMAL, symbolRect, viewScaleRecip); + symbolTransform = DistrictNetworkNodeUtils.getTransformToRectangle(symbolRect, symbolTransform); + + for (INode nn : getNodes()) { + G2DNode g2dNode = (G2DNode)nn; + g2dNode.setTransform(symbolTransform); + g2dNode.render(g2d); + } + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, aaHint); if (ot != null) g2d.setTransform(ot); } + private Point2D getCenterPoint() { + if (centerPoint == null) + centerPoint = new Point2D.Double(); + + Rectangle2D bounds = path.getBounds2D(); + centerPoint.setLocation(bounds.getCenterX(), bounds.getCenterY()); + return centerPoint; + } + public static Line2D calculateLine(DistrictNetworkEdge edge, Line2D result) { // Convert to screen coordinates double startX = ModelledCRS.longitudeToX(edge.getStartPoint().getX()); @@ -155,4 +199,11 @@ public class DistrictNetworkEdgeNode extends G2DNode implements ISelectionPainte this.dynamicColor = color; } + @PropertySetter(value = "SVG") + public void setSVG(String value) { + for (INode nn : this.getNodes()) + if (nn instanceof SVGNode) + ((SVGNode)nn).setData(value); + } + }