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.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<Point2D> routeNodes = new ArrayList<>();
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();
@Override
public void render(Graphics2D g2d) {
+ // Must store this for hover info functionality
+ lastViewTransform = g2d.getTransform();
+
if (nodes.isEmpty())
return;
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
+ DistrictNetworkUtil.createVertex(graph, diagramResource, new double[] { x, y }, Double.MAX_VALUE, mapping);
}
});
}, 100, TimeUnit.MILLISECONDS);
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
}
private boolean canStartEdge(Point2D currentPos) {
- return participant.isHoveringOverNode(currentPos);
+ return participant.isHoveringOverNode(currentPos, lastViewTransform);
}
private IToolMode getToolMode() {
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;
}
repaint();
return super.mouseMoved(e);
}
-
+
@Override
protected boolean keyPressed(KeyPressedEvent e) {
if (e.keyCode == java.awt.event.KeyEvent.VK_ESCAPE) {
return true;
}
return super.keyPressed(e);
-
}
}
\ No newline at end of file