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=e54e5308e5a5e094d733c3e317bd04c096d0b7e7;hb=669fec715190918badd9d4f90575a6b703aa6b9f;hp=6c13f90d254668444cf668ffc73ef2237df3ef84;hpb=c6ddbec532645f52583c1ab9691cfb802724fca7;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 6c13f90d..e54e5308 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 @@ -21,17 +21,15 @@ 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; @@ -76,7 +74,8 @@ public class NetworkDrawingNode extends G2DNode { private static final Color RED_ALPHA = new Color(255, 0, 0, 100); private boolean scaleStroke = true; - + private AffineTransform lastViewTransform = new AffineTransform(); + @Override public void init() { super.init(); @@ -96,6 +95,9 @@ public class NetworkDrawingNode extends G2DNode { @Override public void render(Graphics2D g2d) { + // Must store this for hover info functionality + lastViewTransform = g2d.getTransform(); + if (nodes.isEmpty()) return; @@ -172,17 +174,6 @@ public class NetworkDrawingNode extends G2DNode { double x = ModelledCRS.xToLongitude(pos.getX() / scale); double y = ModelledCRS.yToLatitude(-pos.getY() / scale); - double elevation = 0; - if (MapsElevationServerPreferences.useElevationServer()) { - // ok! we use new elevation API to resolve possible elevations for the starting points - try { - elevation = SingletonTiffTileInterface.lookup(x, y).doubleValue(); - } catch (Exception ee) { - LOGGER.error("Could not get elevation from tiff interface", ee); - } - } - final double felevation = elevation; - boolean leftButton = e.button == MouseEvent.LEFT_BUTTON; ThreadUtils.getNonBlockingWorkExecutor().schedule(() -> { @@ -200,7 +191,7 @@ public class NetworkDrawingNode extends G2DNode { if (mapping == null) { mapping = graph.getSingleObject(diagramResource, DistrictNetworkResource.getInstance(graph).VertexDefaultMapping); } - DistrictNetworkUtil.createVertex(graph, diagramResource, new double[] { x, y }, felevation, mapping); + DistrictNetworkUtil.createVertex(graph, diagramResource, new double[] { x, y }, Double.MAX_VALUE, mapping); } }); }, 100, TimeUnit.MILLISECONDS); @@ -251,26 +242,13 @@ public class NetworkDrawingNode extends G2DNode { detailedGeometryCoords[i++] = lon; detailedGeometryCoords[i++] = lat; } - - double startElevation = 0; - double endElevation = 0; - if (MapsElevationServerPreferences.useElevationServer()) { - // ok! we use new elevation API to resolve possible elevations for the starting points - try { - startElevation = SingletonTiffTileInterface.lookup(startLat, startLon).doubleValue(); - endElevation = SingletonTiffTileInterface.lookup(endLat, endLon).doubleValue(); - } catch (Exception e) { - LOGGER.error("Could not get elevation from tiff interface", e); - } - } - final double se = startElevation; - final double ee = endElevation; + DNEdgeBuilder builder = new DNEdgeBuilder(diagramResource, diagram); Simantics.getSession().asyncRequest(new WriteRequest() { @Override public void perform(WriteGraph graph) throws DatabaseException { - builder.create(graph, startCoords, se, endCoords, ee, detailedGeometryCoords, padding); + builder.create(graph, startCoords, Double.MAX_VALUE, endCoords, Double.MAX_VALUE, detailedGeometryCoords, padding); } }); @@ -310,7 +288,7 @@ public class NetworkDrawingNode extends G2DNode { } private boolean canStartEdge(Point2D currentPos) { - return participant.isHoveringOverNode(currentPos); + return participant.isHoveringOverNode(currentPos, lastViewTransform); } private IToolMode getToolMode() { @@ -323,12 +301,12 @@ 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, lastViewTransform)) { repaint = true; } if (!nodes.isEmpty()) { currentMousePos = p; - repaint(); return true; } @@ -337,7 +315,7 @@ public class NetworkDrawingNode extends G2DNode { repaint(); return super.mouseMoved(e); } - + @Override protected boolean keyPressed(KeyPressedEvent e) { if (e.keyCode == java.awt.event.KeyEvent.VK_ESCAPE) { @@ -347,6 +325,5 @@ public class NetworkDrawingNode extends G2DNode { return true; } return super.keyPressed(e); - } } \ No newline at end of file