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%2FDistrictNetworkVertexNode.java;h=221ed714ac562cfcf0aa38f2915f65c760db66ef;hb=6ca29dac1f155f35b5d246e4ad5dc8aa1d6198aa;hp=58e47f4bcf285dff9f5585aafc7d6a8e5f0eb49e;hpb=2cf7ae447c79df6240b67fd3ca4f0338bdae8c00;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 58e47f4b..221ed714 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 @@ -8,26 +8,28 @@ import java.awt.geom.AffineTransform; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; -import org.simantics.district.network.ModelledCRS; import org.simantics.district.network.ui.adapters.DistrictNetworkVertex; +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 DistrictNetworkVertexNode extends G2DNode implements ISelectionPainterNode { +public class DistrictNetworkVertexNode extends G2DParentNode implements ISelectionPainterNode { //private static final Logger LOGGER = LoggerFactory.getLogger(DistrictNetworkVertexNode.class); private static final long serialVersionUID = -2641639101400236719L; - private 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 static final double left = -0.00005; + private static final double top = left; + public static final double width = 0.0001; + private static final double height = width; - 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 BasicStroke STROKE = new BasicStroke((float)width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); + private static final Color SELECTION_COLOR = new Color(255, 0, 255, 96); 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); @@ -41,6 +43,9 @@ public class DistrictNetworkVertexNode extends G2DNode implements ISelectionPain private transient Color dynamicColor; private Rectangle2D bounds; + private transient Point2D point; + private transient Rectangle2D rect; + private transient AffineTransform symbolTransform; private double nodeSize = 1; @@ -58,7 +63,7 @@ public class DistrictNetworkVertexNode extends G2DNode implements ISelectionPain AffineTransform t = getTransform(); if (t != null && !t.isIdentity()) { ot = g2d.getTransform(); - g2d.transform(getTransform()); + g2d.transform(t); } Object oaaHint = null; @@ -69,40 +74,48 @@ public class DistrictNetworkVertexNode extends G2DNode implements ISelectionPain } Color oldColor = g2d.getColor(); + Color newColor = dynamicColor != null ? dynamicColor : color; + boolean changeColor = !oldColor.equals(newColor); - double scaleRecip = 1; + double viewScaleRecip = 1; if (scaleStroke) { - double scale = GeometryUtils.getScale(g2d.getTransform()); - scale = Math.max(10000, Math.min(scale, 50000)); - scaleRecip = 1.0 / scale; + viewScaleRecip *= DistrictNetworkNodeUtils.calculateScaleRecip(g2d.getTransform()); } - scaleRecip = scaleRecip * nodeSize; + double scaleRecip = viewScaleRecip * nodeSize; // Translate lat and lon to X and Y - Point2D res = calculatePoint2D(vertex); - - Rectangle2D toDraw; - if (hover) { - 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(res.getX() - (NORMAL.getWidth() / 2 * scaleRecip), res.getY() - (NORMAL.getHeight() / 2 * scaleRecip), NORMAL.getWidth() * scaleRecip, NORMAL.getHeight() * scaleRecip); - } + Point2D p = point = DistrictNetworkNodeUtils.calculatePoint2D(vertex.getPoint(), point); + Rectangle2D toDraw = rect = DistrictNetworkNodeUtils.calculateDrawnGeometry(p, hover ? HOVERED : NORMAL, rect, scaleRecip); if (NodeUtil.isSelected(this, 1)) { + changeColor = true; g2d.setColor(SELECTION_COLOR); - BasicStroke ss = GeometryUtils.scaleStroke(STROKE, (float) scaleRecip*2); + BasicStroke ss = GeometryUtils.scaleStroke(STROKE, (float) (viewScaleRecip*0.5)); g2d.setStroke(ss); g2d.draw(toDraw); } // render - g2d.setColor(dynamicColor != null ? dynamicColor : color); + if (changeColor) + g2d.setColor(newColor); g2d.fill(toDraw); - + // Reset settings - g2d.setColor(oldColor); + if (changeColor) + g2d.setColor(oldColor); if (oaaHint != null) - g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, aaHint); + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, aaHint); + + // Render SVG symbol + for (INode nn : getNodes()) { + G2DNode g2dNode = (G2DNode)nn; + if (nn instanceof SVGNode) { + symbolTransform = DistrictNetworkNodeUtils.getTransformToRectangle(toDraw, symbolTransform); + g2dNode.setTransform(symbolTransform); + } + g2dNode.render(g2d); + } + if (ot != null) g2d.setTransform(ot); } @@ -137,19 +150,13 @@ public class DistrictNetworkVertexNode extends G2DNode implements ISelectionPain } private Rectangle2D calculateBounds(Rectangle2D rect) { - Point2D calcPoint = calculatePoint2D(vertex); + Point2D calcPoint = DistrictNetworkNodeUtils.calculatePoint2D(vertex.getPoint(), point); AffineTransform at = getTransform(); - return new Rectangle2D.Double(calcPoint.getX(), calcPoint.getY(), width / at.getScaleX(), height / 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; + double x = calcPoint.getX(); + double y = calcPoint.getY(); + double widthh = width / at.getScaleX(); + double heighth = height / at.getScaleY(); + return new Rectangle2D.Double(x - widthh, y - heighth, widthh * 2, heighth * 2).getBounds2D(); } public void setVertex(DistrictNetworkVertex vertex) { @@ -176,6 +183,14 @@ public class DistrictNetworkVertexNode extends G2DNode implements ISelectionPain return color; } + @PropertySetter(value = "SVG") + public void setSVG(String value) { + for (INode nn : this.getNodes()) + if (nn instanceof SVGNode) + ((SVGNode)nn).setData(value); + } + + @PropertySetter(value = "size") public void setSize(Double size) { boolean changed = false;