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=21f3d741e77d81755376faa7047b3762266d0a92;hb=7d92384ac5455e67e69c02bff9a53e1f0cc256b2;hp=00a1427f5f2e6d07f72c6770364f94892afb64c1;hpb=db34439af303d45eb67cee78cb3f68c9b6666da4;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 00a1427f..21f3d741 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 @@ -12,6 +12,8 @@ import java.awt.geom.Rectangle2D; import org.simantics.district.network.ModelledCRS; import org.simantics.district.network.ui.DistrictNetworkEdge; +import org.simantics.district.network.ui.adapters.DistrictNetworkEdgeElementFactory; +import org.simantics.maps.MapScalingTransform; import org.simantics.scenegraph.INode; import org.simantics.scenegraph.ISelectionPainterNode; import org.simantics.scenegraph.g2d.G2DNode; @@ -29,7 +31,7 @@ public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelection private DistrictNetworkEdge edge; private Rectangle2D bounds; - private transient Line2D path; + private transient Path2D path; private boolean scaleStroke = true; private Color color; @@ -43,11 +45,18 @@ public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelection 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; - + + private Double arrowLength; + + private static double startX; + private static double startY; + private static double endX; + private static double endY; + @Override public void init() { } @@ -76,8 +85,8 @@ public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelection } else { bs = STROKE; } - - path = calculateLine(edge, path); + int zoomLevel = MapScalingTransform.zoomLevel(ot); + path = calculatePath(edge, path, zoomLevel > 15); if (isSelected()) { g2d.setColor(SELECTION_COLOR); @@ -89,6 +98,37 @@ public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelection g2d.setStroke(bs); g2d.draw(path); + // Draw arrow + if (arrowLength != null) { + g2d.setColor(Color.BLACK); + g2d.setStroke(new BasicStroke(bs.getLineWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); + + double l = arrowLength; + double w = 2 * (double) bs.getLineWidth() * Math.signum(l); + if (Math.abs(w) > Math.abs(l)) w = l; + double offset = 2 * (double) bs.getLineWidth(); + + double centerX = (startX + endX) / 2, centerY = (startY + endY) / 2; + double deltaX = endX - startX, deltaY = endY - startY; + double length = Math.sqrt(deltaX * deltaX + deltaY * deltaY); + deltaX /= length; + deltaY /= length; + + double x0 = centerX - l/2 * deltaX + offset * deltaY; + double y0 = centerY - l/2 * deltaY - offset * deltaX; + double x1 = centerX + (l/2 - w) * deltaX + offset * deltaY; + double y1 = centerY + (l/2 - w) * deltaY - offset * deltaX; + + g2d.draw(new Line2D.Double(x0, y0, x1, y1)); + + Path2D path = new Path2D.Double(); + path.moveTo(x1 + w * deltaX, y1 + w * deltaY); + path.lineTo(x1 + w * deltaY, y1 - w * deltaX); + path.lineTo(x1 - w * deltaY, y1 + w * deltaX); + path.closePath(); + g2d.fill(path); + } + // Reset g2d.setStroke(oldStroke); g2d.setColor(oldColor); @@ -126,25 +166,24 @@ public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelection return centerPoint; } - public static Line2D calculateLine(DistrictNetworkEdge edge, Line2D result) { - // Convert to screen coordinates - double startX = ModelledCRS.longitudeToX(edge.getStartPoint().getX()); - double startY = ModelledCRS.latitudeToY(-edge.getStartPoint().getY()); // Invert for Simantics - double endX = ModelledCRS.longitudeToX(edge.getEndPoint().getX()); - double endY = ModelledCRS.latitudeToY(-edge.getEndPoint().getY());// Invert for Simantics - - if (result == null) - result = new Line2D.Double(); - result.setLine(startX, startY, endX, endY); - return result; - } - - public static Path2D calculatePath(DistrictNetworkEdge edge, Path2D result) { - // Convert to screen coordinates - double startX = ModelledCRS.longitudeToX(edge.getStartPoint().getX()); - double startY = ModelledCRS.latitudeToY(-edge.getStartPoint().getY()); // Invert for Simantics - double endX = ModelledCRS.longitudeToX(edge.getEndPoint().getX()); - double endY = ModelledCRS.latitudeToY(-edge.getEndPoint().getY());// Invert for Simantics +// public static Line2D calculateLine(DistrictNetworkEdge edge, Line2D result) { +// // Convert to screen coordinates +// double startX = ModelledCRS.longitudeToX(edge.getStartPoint().getX()); +// double startY = ModelledCRS.latitudeToY(-edge.getStartPoint().getY()); // Invert for Simantics +// double endX = ModelledCRS.longitudeToX(edge.getEndPoint().getX()); +// double endY = ModelledCRS.latitudeToY(-edge.getEndPoint().getY());// Invert for Simantics +// +// if (result == null) +// result = new Line2D.Double(); +// result.setLine(startX, startY, endX, endY); +// return result; +// } + + public static Path2D calculatePath(DistrictNetworkEdge edge, Path2D result, boolean detailed) { + startX = ModelledCRS.longitudeToX(edge.getStartPoint().getX()); + startY = ModelledCRS.latitudeToY(-edge.getStartPoint().getY()); + endX = ModelledCRS.longitudeToX(edge.getEndPoint().getX()); + endY = ModelledCRS.latitudeToY(-edge.getEndPoint().getY()); if (result == null) { result = new Path2D.Double(); @@ -152,6 +191,18 @@ public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelection result.reset(); } result.moveTo(startX, startY); + if (detailed) { + double[] detailedGeometry = edge.getGeometry(); + if (detailedGeometry != null && !DistrictNetworkEdgeElementFactory.EMPTY.equals(detailedGeometry)) { + // ok, lets do this + + for (int i = 0; i < detailedGeometry.length; i += 2) { + double x = ModelledCRS.longitudeToX(detailedGeometry[i]); + double y = ModelledCRS.latitudeToY(-detailedGeometry[i+1]);// Invert for Simantics + result.lineTo(x, y); + } + } + } result.lineTo(endX, endY); return result; } @@ -173,7 +224,7 @@ public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelection } private Rectangle2D calculateBounds(Rectangle2D rect) { - return calculatePath(edge, null).getBounds2D(); + return calculatePath(edge, null, false).getBounds2D(); } public void setDNEdge(DistrictNetworkEdge edge) { @@ -198,6 +249,11 @@ public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelection public void setDynamicColor(Color color) { this.dynamicColor = color; } + + @PropertySetter(value = "arrowLength") + public void setArroLength(Double length) { + arrowLength = length; + } @PropertySetter(value = "SVG") public void setSVG(String value) {