]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Add default mappings for right/left click & prevent edge drawing 59/2859/1
authorjsimomaa <jani.simomaa@gmail.com>
Mon, 22 Apr 2019 17:55:39 +0000 (20:55 +0300)
committerjsimomaa <jani.simomaa@gmail.com>
Mon, 22 Apr 2019 17:55:39 +0000 (20:55 +0300)
immediately after created new vertex by double click

gitlab #42
APROS-15325

Change-Id: I2ca2921a86ecc9d4f2102dade9217d28553aa8fa

org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph
org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/function/Functions.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/NetworkDrawingNode.java

index d9ab6d6e842a8fe53c45ddfb6f977ae4c9c694c0..99c1afce431f3eb63f5be65b3d3ff74fc5ce7f61 100644 (file)
@@ -112,6 +112,12 @@ DN.EdgeDefaultMapping <R L0.HasProperty : DN.EdgeMappingParameterType
 DN.VertexDefaultMapping <R L0.HasProperty : DN.VertexMappingParameterType
     L0.HasLabel "Default Vertex mapping"
 
+DN.RightClickDefaultMapping <R L0.HasProperty : DN.VertexMappingParameterType
+    L0.HasLabel "Right click Vertex mapping"
+
+DN.LeftClickDefaultMapping <R L0.HasProperty : DN.VertexMappingParameterType
+    L0.HasLabel "Left click Vertex mapping"
+
 // ----------------------------------------------------------------------------
 
 DN.Functions : L0.Library
index bb84561785729ed5b258c7fe17c697142537cd4b..6ab5a10d9d74e58b2108be74d4aeadcbe77e3a91 100644 (file)
@@ -156,6 +156,8 @@ public class DistrictNetworkResource {
     public final Resource Images_MapImage;
     public final Resource InLayer;
     public final Resource Layer;
+    public final Resource LeftClickDefaultMapping;
+    public final Resource LeftClickDefaultMapping_Inverse;
     public final Resource MappedComponent;
     public final Resource MappedFromElement;
     public final Resource Mapping;
@@ -246,6 +248,8 @@ public class DistrictNetworkResource {
     public final Resource ReturnConnectionType;
     public final Resource ReturnInConnectionType;
     public final Resource ReturnOutConnectionType;
+    public final Resource RightClickDefaultMapping;
+    public final Resource RightClickDefaultMapping_Inverse;
     public final Resource SCLMain;
     public final Resource SpatialRefSystem;
     public final Resource SupplyConnectionType;
@@ -456,6 +460,8 @@ public class DistrictNetworkResource {
         public static final String Images_MapImage = "http://www.simantics.org/DistrictNetwork-1.0/Images/MapImage";
         public static final String InLayer = "http://www.simantics.org/DistrictNetwork-1.0/InLayer";
         public static final String Layer = "http://www.simantics.org/DistrictNetwork-1.0/Layer";
+        public static final String LeftClickDefaultMapping = "http://www.simantics.org/DistrictNetwork-1.0/LeftClickDefaultMapping";
+        public static final String LeftClickDefaultMapping_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/LeftClickDefaultMapping/Inverse";
         public static final String MappedComponent = "http://www.simantics.org/DistrictNetwork-1.0/MappedComponent";
         public static final String MappedFromElement = "http://www.simantics.org/DistrictNetwork-1.0/MappedFromElement";
         public static final String Mapping = "http://www.simantics.org/DistrictNetwork-1.0/Mapping";
@@ -546,6 +552,8 @@ public class DistrictNetworkResource {
         public static final String ReturnConnectionType = "http://www.simantics.org/DistrictNetwork-1.0/ReturnConnectionType";
         public static final String ReturnInConnectionType = "http://www.simantics.org/DistrictNetwork-1.0/ReturnInConnectionType";
         public static final String ReturnOutConnectionType = "http://www.simantics.org/DistrictNetwork-1.0/ReturnOutConnectionType";
+        public static final String RightClickDefaultMapping = "http://www.simantics.org/DistrictNetwork-1.0/RightClickDefaultMapping";
+        public static final String RightClickDefaultMapping_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/RightClickDefaultMapping/Inverse";
         public static final String SCLMain = "http://www.simantics.org/DistrictNetwork-1.0/SCLMain";
         public static final String SpatialRefSystem = "http://www.simantics.org/DistrictNetwork-1.0/SpatialRefSystem";
         public static final String SupplyConnectionType = "http://www.simantics.org/DistrictNetwork-1.0/SupplyConnectionType";
@@ -766,6 +774,8 @@ public class DistrictNetworkResource {
         Images_MapImage = getResourceOrNull(graph, URIs.Images_MapImage);
         InLayer = getResourceOrNull(graph, URIs.InLayer);
         Layer = getResourceOrNull(graph, URIs.Layer);
+        LeftClickDefaultMapping = getResourceOrNull(graph, URIs.LeftClickDefaultMapping);
+        LeftClickDefaultMapping_Inverse = getResourceOrNull(graph, URIs.LeftClickDefaultMapping_Inverse);
         MappedComponent = getResourceOrNull(graph, URIs.MappedComponent);
         MappedFromElement = getResourceOrNull(graph, URIs.MappedFromElement);
         Mapping = getResourceOrNull(graph, URIs.Mapping);
@@ -856,6 +866,8 @@ public class DistrictNetworkResource {
         ReturnConnectionType = getResourceOrNull(graph, URIs.ReturnConnectionType);
         ReturnInConnectionType = getResourceOrNull(graph, URIs.ReturnInConnectionType);
         ReturnOutConnectionType = getResourceOrNull(graph, URIs.ReturnOutConnectionType);
+        RightClickDefaultMapping = getResourceOrNull(graph, URIs.RightClickDefaultMapping);
+        RightClickDefaultMapping_Inverse = getResourceOrNull(graph, URIs.RightClickDefaultMapping_Inverse);
         SCLMain = getResourceOrNull(graph, URIs.SCLMain);
         SpatialRefSystem = getResourceOrNull(graph, URIs.SpatialRefSystem);
         SupplyConnectionType = getResourceOrNull(graph, URIs.SupplyConnectionType);
index 60dd3e22131ee17b4ba9890052d5c5d0fca6fe2e..89878c5b60c59041986f3a572fec0d96bc558236 100644 (file)
@@ -93,14 +93,25 @@ public class Functions {
     
     @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")
     public static Object defaultVertexMappingModifier(ReadGraph graph, Resource resource, final Variable context) throws DatabaseException {
-        System.out.println(graph.getURI(resource));
-        System.out.println(context.getURI(graph));
-        
         Resource diagram = resolveElement(graph, context);
         DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
         return baseMappingModifier(graph, diagram, DN.VertexDefaultMapping, DN.Mapping_VertexMapping, context);
     }
-    
+
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")
+    public static Object rightClickVertexMappingModifier(ReadGraph graph, Resource resource, final Variable context) throws DatabaseException {
+        Resource diagram = resolveElement(graph, context);
+        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+        return baseMappingModifier(graph, diagram, DN.RightClickDefaultMapping, DN.Mapping_VertexMapping, context);
+    }
+
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")
+    public static Object leftClickVertexMappingModifier(ReadGraph graph, Resource resource, final Variable context) throws DatabaseException {
+        Resource diagram = resolveElement(graph, context);
+        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+        return baseMappingModifier(graph, diagram, DN.LeftClickDefaultMapping, DN.Mapping_VertexMapping, context);
+    }
+
     @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")
     public static Object mappingModifier(ReadGraph graph, Resource resource, final Variable context) throws DatabaseException {
         
@@ -183,8 +194,6 @@ public class Functions {
     @SCLValue(type = "ReadGraph -> Resource -> a -> b")
     public static Object enumerationValues(ReadGraph graph, Resource resource, Object context) throws DatabaseException {
         Variable var = (Variable) context;
-        System.out.println(graph.getURI(resource));
-        System.out.println(var.getURI(graph));
         return Collections.emptyList();
     }
     
@@ -217,8 +226,10 @@ public class Functions {
     private static class DefaultMappingsDialog extends SelectionStatusDialog {
 
         private Combo vertexMappingCombo;
+        private Combo rightClickMappingCombo;
+        private Combo leftClickMappingCombo;
         private Combo edgeMappingCombo;
-        private Combo crsCombo;
+        //private Combo crsCombo;
         private Composite composite;
         
         private Resource configuration;
@@ -229,7 +240,9 @@ public class Functions {
         
         private Resource defaultVertexMapping;
         private Resource defaultEdgeMapping;
-        private Resource defaultCRS;
+        private Resource rightClickVertexMapping;
+        private Resource leftClickVertexMapping;
+        //private Resource defaultCRS;
         
         private Combo compositeMappingCombo;
         private Combo componentMappingCombo;
@@ -244,6 +257,14 @@ public class Functions {
             return defaultVertexMapping;
         }
 
+               public Resource getRightClickVertexMapping() {
+                       return rightClickVertexMapping;
+               }
+
+               public Resource getLeftClickVertexMapping() {
+                       return leftClickVertexMapping;
+               }
+
         public Resource getDefaultEdgeMapping() {
             return defaultEdgeMapping;
         }
@@ -253,8 +274,8 @@ public class Functions {
             composite = (Composite) super.createDialogArea(parent);
             
             createMappingsGroup(composite);
-            createExistingCompositeGroup(composite);
-            createCRSSettingsGroup(composite);
+            //createExistingCompositeGroup(composite);
+            //createCRSSettingsGroup(composite);
             
             // compute default values
             Simantics.getSession().asyncRequest(new ReadRequest() {
@@ -272,15 +293,19 @@ public class Functions {
                     composite.getDisplay().asyncExec(() -> {
                         
                         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
index b94639e2311080c9881044f0228a4c06e14bbc6d..35d76289b0ab000f18e36566e55e355c3c2a9042 100644 (file)
@@ -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;