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%2FNetworkDrawingNode.java;h=335f9e118cd1d8c14bd640cc6bd850f6dadb3a18;hb=b3ffdf8a1d0e5bd9803c933e4b59170a019c90d9;hp=b94639e2311080c9881044f0228a4c06e14bbc6d;hpb=eb4a2e76ad8e8ed5ce69b251d48dff1f1dbbdeef;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 b94639e2..335f9e11 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; @@ -20,15 +21,17 @@ import org.simantics.db.exception.DatabaseException; import org.simantics.db.request.Write; import org.simantics.diagram.elements.DiagramNodeUtil; import org.simantics.diagram.ui.DiagramModelHints; +import org.simantics.district.network.DNEdgeBuilder; import org.simantics.district.network.DistrictNetworkUtil; import org.simantics.district.network.ModelledCRS; import org.simantics.district.network.ontology.DistrictNetworkResource; -import org.simantics.district.network.ui.DNEdgeBuilder; import org.simantics.district.network.ui.NetworkDrawingParticipant; import org.simantics.g2d.canvas.Hints; import org.simantics.g2d.canvas.ICanvasContext; import org.simantics.g2d.canvas.IToolMode; import org.simantics.g2d.diagram.IDiagram; +import org.simantics.maps.elevation.server.SingletonTiffTileInterface; +import org.simantics.maps.elevation.server.prefs.MapsElevationServerPreferences; import org.simantics.scenegraph.g2d.G2DNode; import org.simantics.scenegraph.g2d.events.EventTypes; import org.simantics.scenegraph.g2d.events.KeyEvent.KeyPressedEvent; @@ -38,9 +41,14 @@ 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; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class NetworkDrawingNode extends G2DNode { + private static final Logger LOGGER = LoggerFactory.getLogger(NetworkDrawingNode.class); + static class DrawingNode { private List routeNodes = new ArrayList<>(); @@ -163,15 +171,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 }, Double.MAX_VALUE, mapping); + } + }); + }, 100, TimeUnit.MILLISECONDS); } repaint(); return true; @@ -219,16 +240,16 @@ public class NetworkDrawingNode extends G2DNode { detailedGeometryCoords[i++] = lon; detailedGeometryCoords[i++] = lat; } - + DNEdgeBuilder builder = new DNEdgeBuilder(diagramResource, diagram); Simantics.getSession().asyncRequest(new WriteRequest() { - + @Override public void perform(WriteGraph graph) throws DatabaseException { - builder.create(graph, startCoords, 0, endCoords, 0, detailedGeometryCoords, padding); + builder.create(graph, startCoords, Double.MAX_VALUE, endCoords, Double.MAX_VALUE, detailedGeometryCoords, padding); } }); - + } @Override @@ -278,7 +299,8 @@ public class NetworkDrawingNode extends G2DNode { boolean repaint = false; Point2D p = NodeUtil.worldToLocal(this, e.controlPosition, new Point2D.Double()); boolean isConnectionTool = mode == Hints.CONNECTTOOL || e.hasAnyModifier(MouseEvent.ALT_MASK | MouseEvent.ALT_GRAPH_MASK); - if (participant.pickHoveredElement(p, isConnectionTool)) { + // To boost pan perf hovering is only considered if no mouse button is pressed) + if (e.buttons == 0 && participant.pickHoveredElement(p, isConnectionTool)) { repaint = true; } if (!nodes.isEmpty()) {