]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkNodeUtils.java
Added symbol rendering for edges.
[simantics/district.git] / org.simantics.district.network.ui / src / org / simantics / district / network / ui / nodes / DistrictNetworkNodeUtils.java
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkNodeUtils.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkNodeUtils.java
new file mode 100644 (file)
index 0000000..8a369e2
--- /dev/null
@@ -0,0 +1,38 @@
+package org.simantics.district.network.ui.nodes;
+
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+
+import org.simantics.district.network.ModelledCRS;
+
+public class DistrictNetworkNodeUtils {
+
+    public static 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;
+    }
+
+    public static Point2D calculatePoint2D(Point2D point, Point2D result) {
+        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;
+    }
+
+    public static AffineTransform getTransformToRectangle(Rectangle2D toDraw, AffineTransform transform) {
+        if (transform == null)
+            transform = new AffineTransform();
+
+        transform.setTransform(toDraw.getWidth(), 0.0, 0.0, toDraw.getHeight(), toDraw.getCenterX(), toDraw.getCenterY());
+        return transform;
+    }
+
+}