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;
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);
private Rectangle2D bounds;
private transient Point2D point;
private transient Rectangle2D rect;
+ private transient AffineTransform symbolTransform;
private double nodeSize = 1;
AffineTransform t = getTransform();
if (t != null && !t.isIdentity()) {
ot = g2d.getTransform();
- g2d.transform(getTransform());
+ g2d.transform(t);
}
Object oaaHint = null;
double viewScaleRecip = 1;
if (scaleStroke) {
- double scale = GeometryUtils.getScale(g2d.getTransform());
- scale = Math.max(10000, Math.min(scale, 50000));
- viewScaleRecip = 1.0 / scale;
+ viewScaleRecip *= DistrictNetworkNodeUtils.calculateScaleRecip(g2d.getTransform());
}
double scaleRecip = viewScaleRecip * nodeSize;
// Translate lat and lon to X and Y
- Point2D p = point = calculatePoint2D(vertex, point);
- Rectangle2D toDraw = calculateDrawnGeometry(p, hover ? HOVERED : NORMAL, rect, 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) viewScaleRecip*5);
+ BasicStroke ss = GeometryUtils.scaleStroke(STROKE, (float) (viewScaleRecip*0.5));
g2d.setStroke(ss);
g2d.draw(toDraw);
}
// Render SVG symbol
for (INode nn : getNodes()) {
- ((G2DNode)nn).setTransform(new AffineTransform(toDraw.getWidth(), 0.0, 0.0, toDraw.getHeight(), toDraw.getCenterX(), toDraw.getCenterY()));
- ((G2DNode)nn).render(g2d);
+ 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);
}
- private Rectangle2D calculateDrawnGeometry(Point2D p, Rectangle2D margin, Rectangle2D result, double scaleRecip) {
- if (result == null)
- result = new Rectangle2D.Double();
- double mw = margin.getWidth();
- double mh = margin.getHeight();
- result.setFrame(p.getX() - (mw / 2 * scaleRecip), p.getY() - (mh / 2 * scaleRecip), mw * scaleRecip, mh * scaleRecip);
- return result;
- }
-
@Override
public Rectangle2D getBounds() {
return super.getBounds();
}
private Rectangle2D calculateBounds(Rectangle2D rect) {
- Point2D calcPoint = calculatePoint2D(vertex, point);
+ 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 result) {
- Point2D point = vertex.getPoint();
- double x = ModelledCRS.longitudeToX(point.getX());
- double y = ModelledCRS.latitudeToY(-point.getY()); // Inverse because Simantics Diagram is inverted
- if (result == null)
- result = new Point2D.Double(x, y);
- else
- result.setLocation(x, y);
- return result;
+ 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) {