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;
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;
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";
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";
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);
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);
@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 {
@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();
}
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;
private Resource defaultVertexMapping;
private Resource defaultEdgeMapping;
- private Resource defaultCRS;
+ private Resource rightClickVertexMapping;
+ private Resource leftClickVertexMapping;
+ //private Resource defaultCRS;
private Combo compositeMappingCombo;
private Combo componentMappingCombo;
return defaultVertexMapping;
}
+ public Resource getRightClickVertexMapping() {
+ return rightClickVertexMapping;
+ }
+
+ public Resource getLeftClickVertexMapping() {
+ return leftClickVertexMapping;
+ }
+
public Resource getDefaultEdgeMapping() {
return defaultEdgeMapping;
}
composite = (Composite) super.createDialogArea(parent);
createMappingsGroup(composite);
- createExistingCompositeGroup(composite);
- createCRSSettingsGroup(composite);
+ //createExistingCompositeGroup(composite);
+ //createCRSSettingsGroup(composite);
// compute default values
Simantics.getSession().asyncRequest(new ReadRequest() {
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);
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");
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);
}
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
}
}
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
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 {
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;