X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=org.simantics.district.network.ui%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fui%2Fnodes%2FDistrictNetworkVertexNode.java;h=99eb3cc117b7fb91cbb8352016a62da7e9836249;hb=9f18f45e7d0b3bc1ca80a15a9d4c8fe8354f49ec;hp=e9d0713ddb2d4bb34758ad8e279cacae64308263;hpb=02ecca5e61d2eb17de40cc058be678b414aaad00;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java index e9d0713d..99eb3cc1 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java @@ -11,6 +11,7 @@ import java.awt.geom.Rectangle2D; import org.simantics.district.network.ModelledCRS; import org.simantics.district.network.ui.adapters.DistrictNetworkVertex; +import org.simantics.scenegraph.ParentNode; import org.simantics.scenegraph.g2d.G2DNode; import org.simantics.scenegraph.utils.GeometryUtils; import org.slf4j.Logger; @@ -23,10 +24,10 @@ public class DistrictNetworkVertexNode extends G2DNode { private static final long serialVersionUID = -2641639101400236719L; private DistrictNetworkVertex vertex; - private static final double left = -0.5; - private static final double top = -0.5; - private static final double width = 1; - private static final double height = 1; + 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 static final Rectangle2D HOVERED = new Rectangle2D.Double(left * 3, top * 3, width * 3, height * 3); @@ -37,6 +38,10 @@ public class DistrictNetworkVertexNode extends G2DNode { private Color color; + private Rectangle2D bounds; + + private Double strokee; + @Override public void init() { setZIndex(2); @@ -62,17 +67,24 @@ public class DistrictNetworkVertexNode extends G2DNode { double scaleRecip = 1; if (scaleStroke) { double scale = GeometryUtils.getScale(g2d.getTransform()); - + double str; + if (strokee != null) + str = strokee; + else + str = 1.0; //System.out.println("scale: " + scale); scaleRecip = 1.0 / scale; } scaleRecip = 8.0 * scaleRecip; + // Translate lat and lon to X and Y + Point2D res = calculatePoint2D(vertex); + Rectangle2D toDraw; if (hover) { - toDraw = new Rectangle2D.Double(HOVERED.getX() * scaleRecip, HOVERED.getY() * scaleRecip, HOVERED.getWidth() * scaleRecip, HOVERED.getHeight() * scaleRecip); + toDraw = new Rectangle2D.Double(res.getX() - (HOVERED.getWidth() / 2 * scaleRecip), res.getY() - (HOVERED.getHeight() / 2 * scaleRecip), HOVERED.getWidth() * scaleRecip, HOVERED.getHeight() * scaleRecip); } else { - toDraw = new Rectangle2D.Double(NORMAL.getX() * scaleRecip, NORMAL.getY() * scaleRecip, NORMAL.getWidth() * scaleRecip, NORMAL.getHeight() * scaleRecip); + toDraw = new Rectangle2D.Double(res.getX() - (NORMAL.getWidth() / 2 * scaleRecip), res.getY() - (NORMAL.getHeight() / 2 * scaleRecip), NORMAL.getWidth() * scaleRecip, NORMAL.getHeight() * scaleRecip); } // render g2d.fill(toDraw); @@ -87,15 +99,54 @@ public class DistrictNetworkVertexNode extends G2DNode { g2d.setTransform(ot); } + @Override + public Rectangle2D getBounds() { + return super.getBounds(); + } + @Override public Rectangle2D getBoundsInLocal() { - if (hover) - return HOVERED; - return NORMAL; + return bounds; + } + + private void updateBounds() { + Rectangle2D oldBounds = bounds; + if (oldBounds == null) + oldBounds = new Rectangle2D.Double(); + bounds = calculateBounds(oldBounds); + } + + @Override + public void setTransform(AffineTransform transform) { + super.setTransform(transform); + // Update bounds + updateBounds(); + } + + @Override + public AffineTransform getTransform() { + return super.getTransform(); + } + + private Rectangle2D calculateBounds(Rectangle2D rect) { + Point2D calcPoint = calculatePoint2D(vertex); + AffineTransform at = getTransform(); + return new Rectangle2D.Double(calcPoint.getX(), calcPoint.getY(), 1 / at.getScaleX(), 1 / at.getScaleY()).getBounds2D(); + } + + private static Point2D calculatePoint2D(DistrictNetworkVertex vertex) { + Point2D point= vertex.getPoint(); + double x = ModelledCRS.longitudeToX(point.getX()); + double y = ModelledCRS.latitudeToY(-point.getY()); // Inverse because Simantics Diagram is inverted + + // Apply the scaling + Point2D res = new Point2D.Double(x, y); + return res; } public void setVertex(DistrictNetworkVertex vertex) { this.vertex = vertex; + updateBounds(); } public boolean hover(boolean hover) { @@ -117,4 +168,8 @@ public class DistrictNetworkVertexNode extends G2DNode { return color; } + @PropertySetter(value = "stroke") + public void setStroke(Double stroke) { + this.strokee = stroke / 10; + } }