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=0e5f30222a6f72682640dd0e70b0ae769ff727de;hb=e18075e5fda3ef81c260e4dd9f1211f468344a3c;hp=e724a68dc46b0063e1129ae9d31ba744083416fc;hpb=9b72e2f7a188fcb04add07251cbb0081edc3bfbe;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 e724a68d..0e5f3022 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 @@ -5,10 +5,10 @@ import java.awt.Color; import java.awt.Graphics2D; 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 java.util.Optional; import org.simantics.district.network.ModelledCRS; import org.simantics.district.network.ui.DistrictNetworkEdge; @@ -26,7 +26,7 @@ public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelection private static final long serialVersionUID = 8049769475036519806L; - private static final BasicStroke STROKE = new BasicStroke(4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); + public static final BasicStroke STROKE = new BasicStroke(4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); private static final Color SELECTION_COLOR = new Color(255, 0, 255, 96); private DistrictNetworkEdge edge; @@ -36,10 +36,11 @@ public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelection private transient int zoomLevel = 0; - private static boolean scaleStroke = true; + static final boolean scaleStroke = true; private Color color; private Double stroke; private transient Color dynamicColor = null; + private transient Color eventColor = null; // Dimensions for shut-off valve symbol private static final double left = -0.25; @@ -59,15 +60,11 @@ public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelection private boolean hidden = false; - private Double arrowLength; - private static double startX; private static double startY; private static double endX; private static double endY; - private Path2D arrowPath; - @Override public void init() { } @@ -116,49 +113,10 @@ public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelection } g2d.setColor(dynamicColor != null ? dynamicColor : color); + g2d.setColor(eventColor != null ? eventColor : g2d.getColor()); g2d.setStroke(bs); g2d.draw(path); - // Draw arrow - if (arrowLength != null) { - g2d.setColor(Color.BLACK); - float lw = STROKE.getLineWidth() / (float)scale; - g2d.setStroke(new BasicStroke(lw, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); - - double l = arrowLength; - double w = 2 * (double) lw * Math.signum(l); - if (Math.abs(w) > Math.abs(l)) w = l; - double offset = 2 * (double) lw; - - Point2D centerPoint = getCenterPoint(zoomLevel); - Point2D direction = getDirection(zoomLevel); - double centerX = centerPoint.getX(), centerY = centerPoint.getY(); - double deltaX = direction.getX(), deltaY = direction.getY(); - - // Ensure the line is always rendered on top of the edge - // to prevent overlap with static info rendered below it. - double odx = offset * deltaY; - double ody = offset * deltaX; - if (odx < 0) { - odx = -odx; - ody = -ody; - } - - double x0 = centerX - l/2 * deltaX + ody; - double y0 = centerY - l/2 * deltaY - odx; - double x1 = centerX + (l/2 - w) * deltaX + ody; - double y1 = centerY + (l/2 - w) * deltaY - odx; - - g2d.draw(new Line2D.Double(x0, y0, x1, y1)); - - arrowPath = new Path2D.Double(); - arrowPath.moveTo(x1 + w * deltaX, y1 + w * deltaY); - arrowPath.lineTo(x1 + w * deltaY, y1 - w * deltaX); - arrowPath.lineTo(x1 - w * deltaY, y1 + w * deltaX); - arrowPath.closePath(); - g2d.fill(arrowPath); - } - // Reset g2d.setStroke(oldStroke); g2d.setColor(oldColor); @@ -313,9 +271,18 @@ public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelection this.dynamicColor = color; } + @PropertySetter(value = "eventColor") + public void setEventColor(Color color) { + this.eventColor = color; + } + @PropertySetter(value = "arrowLength") public void setArrowLength(Double length) { - arrowLength = length; + // find if there is a child deferred arrow node + DistrictNetworkEdgeArrayNode child = getOrCreateNode(DistrictNetworkEdgeArrayNode.NODE_KEY, DistrictNetworkEdgeArrayNode.class); + child.setEdgeNode(this); + child.setArrowLength(length); + //arrowLength = length; } @PropertySetter(value = "SVG") @@ -330,4 +297,24 @@ public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelection this.hidden = value; } + public void setStaticInformation(Optional staticInformation) { + DistrictNetworkStaticInfoNode child = getOrCreateNode(DistrictNetworkStaticInfoNode.NODE_KEY, DistrictNetworkStaticInfoNode.class); + child.setEdgeNode(this); + if (staticInformation.isPresent()) { + child.setInfo(staticInformation.get()); + } else { + child.setInfo(null); + } + } + + public void setInSimulation(Optional isInSimulation) { + if (!isInSimulation.isPresent()) { + removeNode(NotInSimulationNode.NODE_NAME); + } else { + NotInSimulationNode child = getOrCreateNode(NotInSimulationNode.NODE_NAME, NotInSimulationNode.class); + child.setZIndex(1000); + child.setIsInSimulation(isInSimulation.get()); + } + } + }