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;
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 {
private Resource diagramResource;
- private boolean committed;
-
private NetworkDrawingParticipant participant;
private IDiagram diagram;
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;
}
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);
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;
// 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) {
}
currentRouteNode = null;
nodes.clear();
- committed = true;
} else if (currentRouteNode != null) {
currentRouteNode.routeNodes.add(new Point2D.Double(localPos.getX(), localPos.getY()));
}