From: jsimomaa Date: Mon, 22 Apr 2019 17:55:39 +0000 (+0300) Subject: Add default mappings for right/left click & prevent edge drawing X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F59%2F2859%2F1;p=simantics%2Fdistrict.git Add default mappings for right/left click & prevent edge drawing immediately after created new vertex by double click gitlab #42 APROS-15325 Change-Id: I2ca2921a86ecc9d4f2102dade9217d28553aa8fa --- diff --git a/org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph b/org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph index d9ab6d6e..99c1afce 100644 --- a/org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph +++ b/org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph @@ -112,6 +112,12 @@ DN.EdgeDefaultMapping { vertexMappingCombo.setItems(vertexMappings.keySet().toArray(new String[vertexMappings.size()])); + rightClickMappingCombo.setItems(vertexMappings.keySet().toArray(new String[vertexMappings.size()])); + leftClickMappingCombo.setItems(vertexMappings.keySet().toArray(new String[vertexMappings.size()])); edgeMappingCombo.setItems(edgeMappings.keySet().toArray(new String[edgeMappings.size()])); - crsCombo.setItems(crss.keySet().toArray(new String[crss.size()])); + //crsCombo.setItems(crss.keySet().toArray(new String[crss.size()])); compositeMappingCombo.setItems(composites.keySet().toArray(new String[composites.size()])); vertexMappingCombo.select(0); + rightClickMappingCombo.select(0); + leftClickMappingCombo.select(0); edgeMappingCombo.select(0); - crsCombo.select(0); + //crsCombo.select(0); if (!composites.isEmpty()) compositeMappingCombo.select(0); @@ -329,7 +354,19 @@ public class Functions { vertexMappingCombo = new Combo(cmposite, SWT.READ_ONLY | SWT.BORDER); GridDataFactory.fillDefaults().grab(true, false).applyTo(vertexMappingCombo); - + + Label rightClickMappingLabel = new Label(cmposite, SWT.NONE); + rightClickMappingLabel.setText("Default right click mapping"); + + rightClickMappingCombo = new Combo(cmposite, SWT.READ_ONLY | SWT.BORDER); + GridDataFactory.fillDefaults().grab(true, false).applyTo(vertexMappingCombo); + + Label leftClickMappingLabel = new Label(cmposite, SWT.NONE); + leftClickMappingLabel.setText("Default left click mapping"); + + leftClickMappingCombo = new Combo(cmposite, SWT.READ_ONLY | SWT.BORDER); + GridDataFactory.fillDefaults().grab(true, false).applyTo(vertexMappingCombo); + Label edgeMappingLabel = new Label(cmposite, SWT.NONE); edgeMappingLabel.setText("Default edge mapping"); @@ -397,9 +434,9 @@ public class Functions { Label vertexMappingLabel = new Label(cmposite, SWT.NONE); vertexMappingLabel.setText("Default CRS"); - crsCombo = new Combo(cmposite, SWT.READ_ONLY | SWT.BORDER); - GridData textData = new GridData(SWT.FILL, SWT.CENTER, true, false); - crsCombo.setLayoutData(textData); + //crsCombo = new Combo(cmposite, SWT.READ_ONLY | SWT.BORDER); + //GridData textData = new GridData(SWT.FILL, SWT.CENTER, true, false); + //crsCombo.setLayoutData(textData); } @@ -407,11 +444,13 @@ public class Functions { protected void computeResult() { defaultVertexMapping = vertexMappings.get(vertexMappingCombo.getItem(vertexMappingCombo.getSelectionIndex())); defaultEdgeMapping = edgeMappings.get(edgeMappingCombo.getItem(edgeMappingCombo.getSelectionIndex())); - defaultCRS = crss.get(crsCombo.getItem(crsCombo.getSelectionIndex())); + rightClickVertexMapping = vertexMappings.get(rightClickMappingCombo.getItem(rightClickMappingCombo.getSelectionIndex())); + leftClickVertexMapping = vertexMappings.get(leftClickMappingCombo.getItem(leftClickMappingCombo.getSelectionIndex())); + //defaultCRS = crss.get(crsCombo.getItem(crsCombo.getSelectionIndex())); } public Resource getCRS() { - return defaultCRS; + return crss.get("EPSG_4326"); // this is only supported } } @@ -437,6 +476,8 @@ public class Functions { Resource diagram = graph.getSingleObject(composite, ModelingResources.getInstance(graph).CompositeToDiagram); graph.claim(diagram, DN.EdgeDefaultMapping, dialog.getDefaultEdgeMapping()); graph.claim(diagram, DN.VertexDefaultMapping, dialog.getDefaultVertexMapping()); + graph.claim(diagram, DN.RightClickDefaultMapping, dialog.getRightClickVertexMapping()); + graph.claim(diagram, DN.LeftClickDefaultMapping, dialog.getLeftClickVertexMapping()); graph.claim(diagram, DN.HasSpatialRefSystem, dialog.getCRS()); // Generated name prefix from composite name 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..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 { @@ -163,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;