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%2FNetworkDrawingNode.java;h=35d76289b0ab000f18e36566e55e355c3c2a9042;hb=5c9576ee8401ef2dfa868c96bd0209004f9c3fc2;hp=00728e894e5f64c398c57ec3e86b953bff5bd81c;hpb=731368eea74c3292199315a38d6914b09b813632;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/NetworkDrawingNode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/NetworkDrawingNode.java index 00728e89..35d76289 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/NetworkDrawingNode.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/NetworkDrawingNode.java @@ -11,6 +11,7 @@ import java.awt.geom.Rectangle2D; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.concurrent.TimeUnit; import org.simantics.Simantics; import org.simantics.db.Resource; @@ -38,6 +39,7 @@ import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDoubleClickedEvent; import org.simantics.scenegraph.g2d.events.MouseEvent.MouseMovedEvent; import org.simantics.scenegraph.utils.GeometryUtils; import org.simantics.scenegraph.utils.NodeUtil; +import org.simantics.utils.threads.ThreadUtils; public class NetworkDrawingNode extends G2DNode { @@ -55,8 +57,6 @@ public class NetworkDrawingNode extends G2DNode { private Resource diagramResource; - private boolean committed; - private NetworkDrawingParticipant participant; private IDiagram diagram; @@ -67,6 +67,7 @@ public class NetworkDrawingNode extends G2DNode { 4.0f, new float[]{4.0f}, 0.0f); private static final Color BLUE_ALPHA = new Color(0, 0, 255, 100); + private static final Color RED_ALPHA = new Color(255, 0, 0, 100); private boolean scaleStroke = true; @@ -123,8 +124,13 @@ public class NetworkDrawingNode extends G2DNode { } g2d.setColor(BLUE_ALPHA); - g2d.draw(path); + + g2d.setColor(RED_ALPHA); + BasicStroke stroke = GeometryUtils.scaleStroke(DASHED_STROKE, (float) (1.0 / GeometryUtils.getScale(g2d.getTransform()))); + g2d.setStroke(stroke); + Point2D currentPoint = path.getCurrentPoint(); + g2d.draw(new Rectangle2D.Double(currentPoint.getX() - 0.0001 / 2, currentPoint.getY() - 0.0001 / 2, 0.0001, 0.0001)); } g2d.setStroke(oldStroke); @@ -159,15 +165,28 @@ public class NetworkDrawingNode extends G2DNode { double scale = getTransform().getScaleY(); double x = ModelledCRS.xToLongitude(pos.getX() / scale); double y = ModelledCRS.yToLatitude(-pos.getY() / scale); - Simantics.getSession().asyncRequest(new Write() { - - @Override - public void perform(WriteGraph graph) throws DatabaseException { - graph.markUndoPoint(); - Resource defaultMapping = graph.getSingleObject(diagramResource, DistrictNetworkResource.getInstance(graph).VertexDefaultMapping); - DistrictNetworkUtil.createVertex(graph, diagramResource, new double[] { x, y }, 0, defaultMapping); // TODO: elevation can be fetched from e.g. elevation API - } - }); + + boolean leftButton = e.button == MouseEvent.LEFT_BUTTON; + + ThreadUtils.getNonBlockingWorkExecutor().schedule(() -> { + Simantics.getSession().asyncRequest(new Write() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + Resource mapping = null; + if (leftButton) { + mapping = graph.getSingleObject(diagramResource, DistrictNetworkResource.getInstance(graph).LeftClickDefaultMapping); + } else { + mapping = graph.getSingleObject(diagramResource, DistrictNetworkResource.getInstance(graph).RightClickDefaultMapping); + } + if (mapping == null) { + mapping = graph.getSingleObject(diagramResource, DistrictNetworkResource.getInstance(graph).VertexDefaultMapping); + } + DistrictNetworkUtil.createVertex(graph, diagramResource, new double[] { x, y }, 0, mapping); // TODO: elevation can be fetched from e.g. elevation API + } + }); + }, 100, TimeUnit.MILLISECONDS); } repaint(); return true; @@ -232,10 +251,6 @@ public class NetworkDrawingNode extends G2DNode { // check ToolMode IToolMode mode = getToolMode(); if (mode == Hints.CONNECTTOOL || e.hasAnyModifier(MouseEvent.ALT_MASK | MouseEvent.ALT_GRAPH_MASK)) { - if (committed) { - committed = false; - return false; - } if (e.button == MouseEvent.RIGHT_BUTTON && !nodes.isEmpty()) { nodes.remove(nodes.size() - 1); } else if (e.button == MouseEvent.LEFT_BUTTON) { @@ -254,7 +269,6 @@ public class NetworkDrawingNode extends G2DNode { } currentRouteNode = null; nodes.clear(); - committed = true; } else if (currentRouteNode != null) { currentRouteNode.routeNodes.add(new Point2D.Double(localPos.getX(), localPos.getY())); }