<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
+ <classpathentry exported="true" kind="lib" path="lib/gt-epsg-hsql-16.2.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/hsqldb-2.3.0.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/commons-pool-1.5.4.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/core-0.26.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/GeographicLib-Java-1.44.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/gt-metadata-16.2.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/gt-opengis-16.2.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/gt-referencing-16.2.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/jai_core-1.1.3.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/jgridshift-1.0.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/jsr-275-1.0-beta-2.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Raster Mapping
-Bundle-SymbolicName: org.simantics.district.maps
+Bundle-SymbolicName: org.simantics.district.maps;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: VTT Technical Research Centre of Finland
Require-Bundle: org.simantics.scenegraph,
org.eclipse.core.runtime;bundle-version="3.5.0";resolution:=optional,
org.eclipse.core.net;bundle-version="1.2.1";resolution:=optional,
org.simantics.g2d;bundle-version="0.9.4",
- org.simantics.utils.datastructures;bundle-version="1.0.0"
-Export-Package: org.simantics.maps,
+ org.simantics.utils.datastructures;bundle-version="1.0.0",
+ org.eclipse.jface,
+ org.eclipse.ui.ide,
+ org.eclipse.ui.workbench
+Export-Package: org.geotools.referencing,
+ org.opengis.referencing,
+ org.opengis.referencing.crs,
+ org.simantics.maps,
org.simantics.maps.debug,
org.simantics.maps.eclipse,
org.simantics.maps.sg,
org.simantics.maps.tile,
org.simantics.maps.wms
-Bundle-ClassPath: .
+Bundle-ClassPath: .,
+ lib/commons-pool-1.5.4.jar,
+ lib/core-0.26.jar,
+ lib/GeographicLib-Java-1.44.jar,
+ lib/gt-metadata-16.2.jar,
+ lib/gt-opengis-16.2.jar,
+ lib/gt-referencing-16.2.jar,
+ lib/jai_core-1.1.3.jar,
+ lib/jgridshift-1.0.jar,
+ lib/jsr-275-1.0-beta-2.jar,
+ lib/gt-epsg-hsql-16.2.jar,
+ lib/hsqldb-2.3.0.jar
Import-Package: org.simantics.scenegraph.g2d
Bundle-RequiredExecutionEnvironment: JavaSE-1.6,
JavaSE-1.7
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
- .
+ .,\
+ lib/commons-pool-1.5.4.jar,\
+ lib/core-0.26.jar,\
+ lib/GeographicLib-Java-1.44.jar,\
+ lib/gt-metadata-16.2.jar,\
+ lib/gt-opengis-16.2.jar,\
+ lib/gt-referencing-16.2.jar,\
+ lib/jai_core-1.1.3.jar,\
+ lib/jgridshift-1.0.jar,\
+ lib/jsr-275-1.0-beta-2.jar,\
+ lib/gt-epsg-hsql-16.2.jar,\
+ lib/hsqldb-2.3.0.jar,\
+ plugin.xml
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.ui.preferencePages">
+ <page
+ category="org.simantics.district.network.ui.preferences"
+ class="org.simantics.maps.prefs.MapsClientPreferencePage"
+ id="org.simantics.district.maps.preferences"
+ name="Maps client">
+ </page>
+ </extension>
+ <extension
+ point="org.eclipse.core.runtime.preferences">
+ <initializer
+ class="org.simantics.maps.prefs.MapsClientPreferenceInitializer">
+ </initializer>
+ </extension>
+</plugin>
import org.simantics.g2d.canvas.impl.SGNodeReflection.SGCleanup;
import org.simantics.g2d.canvas.impl.SGNodeReflection.SGInit;
import org.simantics.maps.sg.MapNode;
+import org.simantics.maps.sg.MapScaleNode;
import org.simantics.scenegraph.g2d.G2DParentNode;
import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler;
import org.simantics.scenegraph.g2d.events.command.CommandEvent;
};
protected MapNode node = null;
+ protected MapScaleNode scaleNode = null;
private int scale;
node.setScale(scale);
node.setEnabled(true);
node.setZIndex(Integer.MIN_VALUE + 999); // Just under the grid
+
+ scaleNode = parent.addNode("mapScale", MapScaleNode.class);
+ scaleNode.setScale(scale);
+ scaleNode.setEnabled(true);
+ scaleNode.setZIndex(Integer.MAX_VALUE - 999); // Just under the grid
}
@SGCleanup
--- /dev/null
+package org.simantics.maps.prefs;
+
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.core.runtime.preferences.DefaultScope;
+import org.osgi.service.prefs.Preferences;
+
+public class MapsClientPreferenceInitializer extends AbstractPreferenceInitializer {
+
+ public MapsClientPreferenceInitializer() {
+ }
+
+ @Override
+ public void initializeDefaultPreferences() {
+ Preferences node = DefaultScope.INSTANCE.getNode(MapsClientPreferences.P_NODE);
+ node.put(MapsClientPreferences.P_TILESERVER_URL, "http://localhost:8088");
+ }
+}
--- /dev/null
+package org.simantics.maps.prefs;
+
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.jface.preference.FieldEditor;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.StringFieldEditor;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.eclipse.ui.preferences.ScopedPreferenceStore;
+
+public class MapsClientPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
+
+ public MapsClientPreferencePage() {
+ super(GRID);
+ setDescription("Maps client preferences");
+ }
+
+ @Override
+ public void init(IWorkbench workbench) {
+
+ }
+
+ @Override
+ protected IPreferenceStore doGetPreferenceStore() {
+ return new ScopedPreferenceStore(InstanceScope.INSTANCE, MapsClientPreferences.P_NODE);
+ }
+
+ @Override
+ protected void createFieldEditors() {
+ FieldEditor editor = new StringFieldEditor(MapsClientPreferences.P_TILESERVER_URL, "Tileserver URL", getFieldEditorParent());
+ editor.setPreferenceStore(getPreferenceStore());
+ addField(editor);
+ }
+
+}
--- /dev/null
+package org.simantics.maps.prefs;
+
+public class MapsClientPreferences {
+
+ public static final String P_NODE = "org.simantics.district.maps";
+
+ public static final String P_TILESERVER_URL = "org.simantics.district.maps.prefs.tileserverURL";
+}
--- /dev/null
+package org.simantics.maps.sg;
+
+import java.awt.AlphaComposite;
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Graphics2D;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+import java.util.Locale;
+
+import org.geotools.referencing.CRS;
+import org.geotools.referencing.GeodeticCalculator;
+import org.opengis.referencing.FactoryException;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.simantics.scenegraph.g2d.G2DNode;
+import org.simantics.scenegraph.utils.GridUtils;
+
+public class MapScaleNode extends G2DNode {
+
+ private static final long serialVersionUID = -2738682328944298290L;
+
+ private static final Color GRAY = new Color(100, 100, 100);
+
+ protected Boolean enabled = true;
+
+ protected double gridSize = 1.0;
+
+ private double scale;
+
+ @Override
+ public void render(Graphics2D g) {
+ if (!enabled)
+ return;
+
+ AffineTransform tr = g.getTransform();
+ double scaleX = Math.abs(tr.getScaleX());
+ double scaleY = Math.abs(tr.getScaleY());
+ if (scaleX <= 0 || scaleY <= 0) {
+ // Make sure that we don't end up in an eternal loop below.
+ return;
+ }
+ double offsetX = tr.getTranslateX();
+ double offsetY = tr.getTranslateY();
+ g.setTransform(new AffineTransform());
+
+ Font rulerFont = new Font("Tahoma", Font.PLAIN, 9);
+
+ //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+ g.setStroke(new BasicStroke(1));
+ g.setColor(new Color(0.9f, 0.9f, 0.9f, 0.75f));
+
+ Rectangle2D bounds = g.getClipBounds();
+ if(bounds == null) return; // FIXME
+
+ double previousText = -100;
+
+ double minY = bounds.getMaxY() - 30;
+
+ double scaleRight = bounds.getMaxX() - 30;
+
+ double meterPerPixel = getMeterPerPixel(scaleRight - offsetX, minY - offsetY, scaleX, scaleY);
+
+ double pixels = 0;
+ double value = 0;
+ for (int i = 0; i < SCALE_VALUES.length; i++) {
+ value = SCALE_VALUES[i];
+ pixels = value / meterPerPixel;
+ if (pixels > 100) {
+ break;
+ }
+ }
+
+
+ double newScaleLeft = scaleRight - pixels;
+ g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
+ Rectangle2D vertical = new Rectangle2D.Double(newScaleLeft, bounds.getMaxY() - 30, pixels, 20);
+ g.fill(vertical);
+
+ g.setColor(GRAY);
+ g.setFont(rulerFont);
+
+
+ // stepX and stepY should be something between 50 and 100
+ double stepX = 50;
+
+ stepX = GridUtils.limitedEvenGridSpacing(stepX, scaleX, 100, gridSize, true);
+ //while(stepX * scaleX > 100) stepX /= 2;
+ //while(stepY * scaleY > 100) stepY /= 2;
+
+ while(stepX * scaleX < 50) stepX *= 2;
+
+ stepX *= scaleX;
+
+ double gap = scaleRight -newScaleLeft;
+
+ stepX = gap / 2 - 0.00001;
+
+ // Horizontal ruler
+ double label = 0;
+ for(double x = newScaleLeft; x < scaleRight; x += stepX) {
+ String str = formatValue(label * meterPerPixel);
+ FontMetrics fm = g.getFontMetrics();
+ Rectangle2D r = fm.getStringBounds(str, g);
+ if((x - r.getWidth() / 2) > previousText) {
+ g.setColor(Color.BLACK);
+ g.drawString(str, (int)(x-r.getWidth()/2), (int)(minY+1+r.getHeight()));
+ previousText = x+r.getWidth()/2+stepX/4;
+ }
+
+ g.setColor(GRAY);
+ g.drawLine((int)x, (int)minY+12, (int)x, (int)minY+19);
+ if (x + 0.1 < scaleRight) {
+ if(stepX/5 > 2) {
+ for(double x2 = x+stepX/5; x2 < x+stepX; x2+=stepX/5) {
+ if(x2 > 20) {
+ g.drawLine((int)x2, (int)minY+15, (int)x2, (int)minY+19);
+ }
+ }
+ for(double x2 = x+stepX/10; x2 < x+stepX; x2+=stepX/5) {
+ if(x2 > 20) {
+ g.drawLine((int)x2, (int)minY+17, (int)x2, (int)minY+19);
+ }
+ }
+ }
+ }
+ label += stepX;
+ }
+
+ g.setTransform(tr);
+ }
+
+ @Override
+ public Rectangle2D getBoundsInLocal() {
+ return null;
+ }
+
+ private static final transient int MAX_DIGITS = 0;
+ private static final transient double EPSILON = 0.01;
+ private static final transient double TRIM_THRESHOLD_MAX_VALUE = Math.pow(10, 2);
+ private static final transient String[] SI_UNIT_LARGE_PREFIXES = { "m", "km" };
+
+ private static final transient double[] SCALE_VALUES = { 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000, 200000, 500000, 1000000, 2000000, 50000000 };
+
+ public static String formatValue(double value) {
+ int magnitude = (int) Math.round(Math.log10(value));
+ //System.out.println("magnitude: " + magnitude + ", " + value);
+ int allowedDecimals = MAX_DIGITS;
+ allowedDecimals -= Math.abs(magnitude);
+ if (allowedDecimals < 0)
+ allowedDecimals = 0;
+
+ String valueStr = String.format(Locale.US, "%." + allowedDecimals + "f", value);
+ if (allowedDecimals > 0) {
+ for (int trunc = valueStr.length() - 1; trunc > 0; --trunc) {
+ char ch = valueStr.charAt(trunc);
+ if (ch == '.') {
+ valueStr = valueStr.substring(0, trunc);
+ break;
+ }
+ if (valueStr.charAt(trunc) != '0') {
+ valueStr = valueStr.substring(0, trunc + 1);
+ break;
+ }
+ }
+ if (Math.abs(value) + EPSILON > TRIM_THRESHOLD_MAX_VALUE) {
+ // Cut anything beyond a possible decimal dot out since they
+ // should not show anyway. This is a complete hack that tries to
+ // circumvent floating-point inaccuracy problems.
+ int dotIndex = valueStr.lastIndexOf('.');
+ if (dotIndex > -1) {
+ valueStr = valueStr.substring(0, dotIndex);
+ }
+ }
+ }
+
+ if (valueStr.equals("-0"))
+ valueStr = "0";
+
+// if (!valueStr.equals("0")) {
+// double trimValue = value;
+// for (int i = 0; i < SI_UNIT_LARGE_PREFIXES.length; i++) {
+// double trim = trimValue / 1000;
+// if (Math.abs(trim)-EPSILON < TRIM_THRESHOLD_MAX_VALUE) {
+// valueStr = valueStr.substring(0, valueStr.length() - (i + 1) * 3);
+// valueStr += SI_UNIT_LARGE_PREFIXES[i];
+// break;
+// }
+// trimValue = trim;
+// }
+// }
+
+ return valueStr;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ public void setScale(double scale) {
+ this.scale = scale;
+ }
+
+ @Override
+ public void init() {
+ try {
+ EPSG4326 = CRS.decode("EPSG:4326");
+ calculator = new GeodeticCalculator(EPSG4326);
+ } catch (FactoryException e) {
+ e.printStackTrace();
+ }
+ super.init();
+ }
+
+ GeodeticCalculator calculator;
+ CoordinateReferenceSystem EPSG4326;
+
+ public Point2D scaleLeftmostPoint(double startLon, double startLat, double distance, double azimuth) {
+ GeodeticCalculator calculator = new GeodeticCalculator();
+ calculator.setStartingGeographicPoint(startLon, startLat);
+ calculator.setDirection(azimuth, distance);
+ return calculator.getDestinationGeographicPoint();
+ }
+
+ public double getMeterPerPixel(double screenX, double screenY, double scaleX, double scaleY) {
+ double startLon = (screenX / scaleX) / scale;
+ double val = (screenY / scaleY) / scale;
+ val = Math.toDegrees(Math.atan(Math.sinh(Math.toRadians(val))));
+ double startLat = val;
+ double endLon = ((screenX + 1) / scaleX) / scale;
+ double endLat = val;
+
+ calculator.setStartingGeographicPoint(startLon, startLat);
+ calculator.setDestinationGeographicPoint(endLon, endLat);
+ double distance = calculator.getOrthodromicDistance();
+
+ return distance;
+ }
+
+}
DN.Layer <T DIA.Layer
DN.Edge <T DIA.Element : L0.Type
- @L0.assert DN.HasMapping DN.Mapping.Dummy
@L0.assert DN.Bidirectional false
@L0.assert DN.Edge.HasDiameter 1
DN.Vertex <T DIA.Element : L0.Type
- @L0.assert DN.HasMapping DN.Mapping.Dummy
@L0.assert DN.Bidirectional false
DN.Bidirectional <R L0.HasProperty : SEL.GenericParameterType
DN.Connection <T DIA.Connection
-DN.Mapping.Dummy : DN.Mapping.Base
-
DN.Diagram <T DIA.Diagram
- @L0.assert DN.VertexDefaultMapping DN.Mapping.Dummy
- @L0.assert DN.EdgeDefaultMapping DN.Mapping.Dummy
DN.AddLayerToDNDiagramTemplate <T L0.Template
-DN.EPSG_4326 <T DN.SpatialRefSystem
+DN.EPSG_4326 : DN.SpatialRefSystem
+ L0.HasLabel "EPSG:4326"
DN.HasSRID 4326
DN.HasSRTEXT _ : L0.String
@L0.loadString "epsg/EPSG_4326"
-test
\ No newline at end of file
+GEOGCS["WGS 84",
+ DATUM["WGS_1984",
+ SPHEROID["WGS 84",6378137,298.257223563,
+ AUTHORITY["EPSG","7030"]],
+ AUTHORITY["EPSG","6326"]],
+ PRIMEM["Greenwich",0,
+ AUTHORITY["EPSG","8901"]],
+ UNIT["degree",0.01745329251994328,
+ AUTHORITY["EPSG","9122"]],
+ AUTHORITY["EPSG","4326"]]
\ No newline at end of file
-data VertexMapping = VertexMapping {\r
- componentType :: String,\r
- elevationAttribute :: String,\r
- terminals :: [TerminalPair]\r
-}\r
-\r
-data TerminalPair = TerminalPair {\r
- inputTerminal :: String,\r
- outputTerminal :: String\r
-}\r
-\r
-data EdgeMapping = EdgeMapping {\r
- componentType :: String,\r
- bidirectional :: Boolean,\r
- lengthAttribute :: String,\r
- diameterAttribute :: String,\r
- terminals :: [TerminalPair]\r
-}
\ No newline at end of file
+data VertexMapping = VertexMapping {
+ componentType :: String,
+ elevationAttribute :: String,
+ terminals :: [TerminalPair]
+}
+
+data TerminalPair = TerminalPair {
+ inputTerminal :: String,
+ outputTerminal :: String
+}
+
+data EdgeMapping = EdgeMapping {
+ componentType :: String,
+ bidirectional :: Boolean,
+ lengthAttribute :: String,
+ diameterAttribute :: String,
+ terminals :: [TerminalPair]
+}
public final Resource Mapping_Base;
public final Resource Mapping_ComponentType;
public final Resource Mapping_ComponentType_Inverse;
- public final Resource Mapping_Dummy;
public final Resource Mapping_EdgeMapping;
public final Resource Mapping_EdgeMapping_Bidirectional;
public final Resource Mapping_EdgeMapping_Bidirectional_Inverse;
public static final String Mapping_Base = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/Base";
public static final String Mapping_ComponentType = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/ComponentType";
public static final String Mapping_ComponentType_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/ComponentType/Inverse";
- public static final String Mapping_Dummy = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/Dummy";
public static final String Mapping_EdgeMapping = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping";
public static final String Mapping_EdgeMapping_Bidirectional = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/Bidirectional";
public static final String Mapping_EdgeMapping_Bidirectional_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/Bidirectional/Inverse";
Mapping_Base = getResourceOrNull(graph, URIs.Mapping_Base);
Mapping_ComponentType = getResourceOrNull(graph, URIs.Mapping_ComponentType);
Mapping_ComponentType_Inverse = getResourceOrNull(graph, URIs.Mapping_ComponentType_Inverse);
- Mapping_Dummy = getResourceOrNull(graph, URIs.Mapping_Dummy);
Mapping_EdgeMapping = getResourceOrNull(graph, URIs.Mapping_EdgeMapping);
Mapping_EdgeMapping_Bidirectional = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_Bidirectional);
Mapping_EdgeMapping_Bidirectional_Inverse = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_Bidirectional_Inverse);
--- /dev/null
+DistrictPreferencePage.name=District
id="org.simantics.district.network.ui.diagrameditor">
</editor>
</extension>
+ <extension
+ point="org.eclipse.ui.preferencePages">
+ <page
+ name="District"
+ class="org.simantics.district.network.ui.prefs.DistrictPreferencePage"
+ id="org.simantics.district.network.ui.preferences">
+ </page>
+ </extension>
<extension
point="org.simantics.ui.resourceEditorAdapter">
<adapterClass
}
public static Map<String, Resource> getVertexMappings(ReadGraph graph, Resource resource) throws DatabaseException {
- return getNetworkMappingsByType(graph, resource , DistrictNetworkResource.getInstance(graph).Mapping_VertexMapping);
+ Map<String, Resource> second = getNetworkMappingsByType(graph, resource , DistrictNetworkResource.getInstance(graph).Mapping_VertexMapping);
+ return second;
}
public static Map<String, Resource> getEdgeMappings(ReadGraph graph, Resource resource) throws DatabaseException {
- return getNetworkMappingsByType(graph, resource , DistrictNetworkResource.getInstance(graph).Mapping_EdgeMapping);
+ Map<String, Resource> second = getNetworkMappingsByType(graph, resource , DistrictNetworkResource.getInstance(graph).Mapping_EdgeMapping);
+ return second;
+ }
+
+ public static Map<String, Resource> getCRSs(ReadGraph graph, Resource resource) throws DatabaseException {
+ Map<String, Resource> result = getNetworkMappingsByType(graph, resource, DistrictNetworkResource.getInstance(graph).SpatialRefSystem);
+ return result;
+
}
public static Map<String, Resource> getNetworkMappingsByType(ReadGraph graph, Resource element, Resource mappingType) throws DatabaseException {
private Map<String, Resource> vertexMappings = new HashMap<>();
private Map<String, Resource> edgeMappings = new HashMap<>();
private Map<String, Resource> composites = new HashMap<>();
+ private Map<String, Resource> crss = new HashMap<>();
private Map<String, Map<String, Resource>> components = new HashMap<>();
private Resource defaultVertexMapping;
private Resource defaultEdgeMapping;
+ private Resource defaultCRS;
+
private Combo compositeMappingCombo;
private Combo componentMappingCombo;
components = getComponents(graph, composites.get(0));
}
+ crss = getCRSs(graph, configuration);
composite.getDisplay().asyncExec(() -> {
vertexMappingCombo.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()]));
+
compositeMappingCombo.setItems(composites.keySet().toArray(new String[composites.size()]));
vertexMappingCombo.select(0);
edgeMappingCombo.select(0);
+
+ crsCombo.select(0);
+
if (!composites.isEmpty())
compositeMappingCombo.select(0);
});
protected void computeResult() {
defaultVertexMapping = vertexMappings.get(vertexMappingCombo.getItem(vertexMappingCombo.getSelectionIndex()));
defaultEdgeMapping = edgeMappings.get(edgeMappingCombo.getItem(edgeMappingCombo.getSelectionIndex()));
+ defaultCRS = crss.get(crsCombo.getItem(crsCombo.getSelectionIndex()));
+ }
+
+ public Resource getCRS() {
+ return defaultCRS;
}
}
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.HasSpatialRefSystem, dialog.getCRS());
}
});
DefaultActions.asyncPerformDefaultAction(Simantics.getSession(), composite, false, false, true);
--- /dev/null
+package org.simantics.district.network.ui.prefs;
+
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.eclipse.ui.preferences.ScopedPreferenceStore;
+import org.simantics.district.network.ui.internal.Activator;
+
+public class DistrictPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
+
+ public DistrictPreferencePage() {
+ super(GRID);
+ setDescription("District preferences");
+ }
+
+ @Override
+ public void init(IWorkbench workbench) {
+
+ }
+
+ @Override
+ protected IPreferenceStore doGetPreferenceStore() {
+ return new ScopedPreferenceStore(InstanceScope.INSTANCE, Activator.PLUGIN_ID);
+ }
+
+ @Override
+ protected void createFieldEditors() {
+
+ }
+
+}
org.simantics.district.network.ontology,
org.simantics.diagram.ontology;bundle-version="2.2.0",
org.simantics.db.common,
- org.simantics.db.layer0
+ org.simantics.db.layer0,
+ org.simantics.district.maps
Export-Package: org.simantics.district.network
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<adapters>
+ <target interface="org.simantics.district.network.CRS">
+ <type
+ uri="http://www.simantics.org/DistrictNetwork-1.0/SpatialRefSystem"
+ class="org.simantics.district.network.ModelledCRS">
+ <graph/>
+ <this />
+ </type>
+ </target>
+</adapters>
\ No newline at end of file
--- /dev/null
+import "Simantics/DB"
+
+importJava "org.simantics.district.network.DistrictNetworkUtil" where
+ calculateDistance :: Resource -> Resource -> <ReadGraph> Double
\ No newline at end of file
--- /dev/null
+package org.simantics.district.network;
+
+public interface CRS {
+
+ public double calculateDistance(double[] start, double[] end);
+}
import java.util.Collection;
import java.util.Iterator;
+import org.simantics.databoard.Bindings;
+import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
import org.simantics.db.WriteGraph;
import org.simantics.db.common.utils.OrderedSetUtils;
import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.layer0.util.RemoverUtil;
import org.simantics.diagram.stubs.DiagramResource;
import org.simantics.district.network.ontology.DistrictNetworkResource;
import org.simantics.layer0.Layer0;
Resource edge = graph.newResource();
graph.claim(edge, L0.InstanceOf, DN.Edge);
+
+ Resource defaultEdgeMapping = graph.getPossibleObject(composite, DN.EdgeDefaultMapping);
+ graph.claim(edge, DN.HasMapping, defaultEdgeMapping);
+
OrderedSetUtils.add(graph, composite, edge);
graph.claim(composite, L0.ConsistsOf, L0.PartOf, edge);
return edge;
Resource vertex = graph.newResource();
graph.claim(vertex, L0.InstanceOf, DN.Vertex);
graph.claimLiteral(vertex, DIA.HasLocation, coords);
+
+ Resource defaultVertexMapping = graph.getPossibleObject(composite, DN.VertexDefaultMapping);
+ graph.claim(vertex, DN.HasMapping, defaultVertexMapping);
+
OrderedSetUtils.add(graph, composite, vertex);
graph.claim(composite, L0.ConsistsOf, L0.PartOf, vertex);
}
return master;
}
+
+ public static double calculateDistance(ReadGraph graph, Resource startVertex, Resource endVertex) throws DatabaseException {
+ Layer0 L0 = Layer0.getInstance(graph);
+ Resource startComposite = graph.getSingleObject(startVertex, L0.PartOf);
+ Resource endComposite = graph.getSingleObject(endVertex, L0.PartOf);
+ if (!startComposite.equalsResource(endComposite)) {
+ throw new DatabaseException("Can not calculate distance between vertices on different composites! " + startVertex + " -> " + endVertex);
+ }
+ Resource crs = graph.getSingleObject(startComposite, DistrictNetworkResource.getInstance(graph).HasSpatialRefSystem);
+
+ CRS crsClass = graph.adapt(crs, CRS.class);
+
+ double[] startCoords = graph.getRelatedValue2(startVertex, DiagramResource.getInstance(graph).HasLocation, Bindings.DOUBLE_ARRAY);
+ double[] endCoords = graph.getRelatedValue2(endVertex, DiagramResource.getInstance(graph).HasLocation, Bindings.DOUBLE_ARRAY);
+
+ return crsClass.calculateDistance(startCoords, endCoords);
+ }
}
--- /dev/null
+package org.simantics.district.network;
+
+import org.geotools.referencing.GeodeticCalculator;
+import org.opengis.referencing.FactoryException;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.simantics.databoard.Bindings;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.district.network.ontology.DistrictNetworkResource;
+
+public class ModelledCRS implements CRS {
+
+ private GeodeticCalculator calculator;
+
+ public ModelledCRS(ReadGraph graph, Resource type) throws DatabaseException, FactoryException {
+ String wkt = graph.getRelatedValue2(type, DistrictNetworkResource.getInstance(graph).HasSRTEXT, Bindings.STRING);
+ CoordinateReferenceSystem crs = org.geotools.referencing.CRS.parseWKT(wkt);
+ this.calculator = new GeodeticCalculator(crs);
+ }
+
+ @Override
+ public double calculateDistance(double[] start, double[] end) {
+ // TODO: fix the scale..
+ calculator.setStartingGeographicPoint(start[0] / 100000, start[1] / 100000);
+ calculator.setDestinationGeographicPoint(end[0] / 100000, end[1] / 100000);
+ return calculator.getOrthodromicDistance();
+ }
+
+}