]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Lots of changes to district stuff 84/384/1
authorjsjani <jsjani@ESPVM5K1595.ad.vtt.fi>
Wed, 29 Mar 2017 16:28:19 +0000 (19:28 +0300)
committerjsjani <jsjani@ESPVM5K1595.ad.vtt.fi>
Wed, 29 Mar 2017 16:28:19 +0000 (19:28 +0300)
refs #6958

Change-Id: Ic44eba4146630d8364cc09c765e5413e130b34df

35 files changed:
org.simantics.district.maps/.classpath
org.simantics.district.maps/META-INF/MANIFEST.MF
org.simantics.district.maps/build.properties
org.simantics.district.maps/lib/GeographicLib-Java-1.44.jar [new file with mode: 0644]
org.simantics.district.maps/lib/commons-pool-1.5.4.jar [new file with mode: 0644]
org.simantics.district.maps/lib/core-0.26.jar [new file with mode: 0644]
org.simantics.district.maps/lib/gt-epsg-hsql-16.2.jar [new file with mode: 0644]
org.simantics.district.maps/lib/gt-metadata-16.2.jar [new file with mode: 0644]
org.simantics.district.maps/lib/gt-opengis-16.2.jar [new file with mode: 0644]
org.simantics.district.maps/lib/gt-referencing-16.2.jar [new file with mode: 0644]
org.simantics.district.maps/lib/hsqldb-2.3.0.jar [new file with mode: 0644]
org.simantics.district.maps/lib/jai_core-1.1.3.jar [new file with mode: 0644]
org.simantics.district.maps/lib/jgridshift-1.0.jar [new file with mode: 0644]
org.simantics.district.maps/lib/jsr-275-1.0-beta-2.jar [new file with mode: 0644]
org.simantics.district.maps/plugin.xml [new file with mode: 0644]
org.simantics.district.maps/src/org/simantics/maps/eclipse/MapPainter.java
org.simantics.district.maps/src/org/simantics/maps/prefs/MapsClientPreferenceInitializer.java [new file with mode: 0644]
org.simantics.district.maps/src/org/simantics/maps/prefs/MapsClientPreferencePage.java [new file with mode: 0644]
org.simantics.district.maps/src/org/simantics/maps/prefs/MapsClientPreferences.java [new file with mode: 0644]
org.simantics.district.maps/src/org/simantics/maps/sg/MapScaleNode.java [new file with mode: 0644]
org.simantics.district.network.ontology/graph.tg
org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph
org.simantics.district.network.ontology/graph/epsg/EPSG_4326
org.simantics.district.network.ontology/scl/Simantics/District/ComponentMapping.scl
org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java
org.simantics.district.network.ui/plugin.properties [new file with mode: 0644]
org.simantics.district.network.ui/plugin.xml
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/prefs/DistrictPreferencePage.java [new file with mode: 0644]
org.simantics.district.network/META-INF/MANIFEST.MF
org.simantics.district.network/adapters.xml [new file with mode: 0644]
org.simantics.district.network/scl/Simantics/District.scl [new file with mode: 0644]
org.simantics.district.network/src/org/simantics/district/network/CRS.java [new file with mode: 0644]
org.simantics.district.network/src/org/simantics/district/network/DistrictNetworkUtil.java
org.simantics.district.network/src/org/simantics/district/network/ModelledCRS.java [new file with mode: 0644]

index 751c8f2e504c40d1c41ebbd87d8f8968529e9c30..0e4c914299c53685204d28d36cf1b9e4580386b7 100644 (file)
@@ -1,6 +1,17 @@
 <?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"/>
index a5c4a10585f126a81c9b2d3349a5b191fbea404f..9754d75797b3e5bfa9fac068168f1f991499f072 100644 (file)
@@ -1,21 +1,38 @@
 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
index 34d2e4d2dad529ceaeb953bfcdb63c51d69ffed2..5fd55626dda41b579b99ca59e3d1ef83c50a3678 100644 (file)
@@ -1,4 +1,16 @@
 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
diff --git a/org.simantics.district.maps/lib/GeographicLib-Java-1.44.jar b/org.simantics.district.maps/lib/GeographicLib-Java-1.44.jar
new file mode 100644 (file)
index 0000000..338ca8e
Binary files /dev/null and b/org.simantics.district.maps/lib/GeographicLib-Java-1.44.jar differ
diff --git a/org.simantics.district.maps/lib/commons-pool-1.5.4.jar b/org.simantics.district.maps/lib/commons-pool-1.5.4.jar
new file mode 100644 (file)
index 0000000..43edf99
Binary files /dev/null and b/org.simantics.district.maps/lib/commons-pool-1.5.4.jar differ
diff --git a/org.simantics.district.maps/lib/core-0.26.jar b/org.simantics.district.maps/lib/core-0.26.jar
new file mode 100644 (file)
index 0000000..9452f17
Binary files /dev/null and b/org.simantics.district.maps/lib/core-0.26.jar differ
diff --git a/org.simantics.district.maps/lib/gt-epsg-hsql-16.2.jar b/org.simantics.district.maps/lib/gt-epsg-hsql-16.2.jar
new file mode 100644 (file)
index 0000000..ac961d9
Binary files /dev/null and b/org.simantics.district.maps/lib/gt-epsg-hsql-16.2.jar differ
diff --git a/org.simantics.district.maps/lib/gt-metadata-16.2.jar b/org.simantics.district.maps/lib/gt-metadata-16.2.jar
new file mode 100644 (file)
index 0000000..415bbc1
Binary files /dev/null and b/org.simantics.district.maps/lib/gt-metadata-16.2.jar differ
diff --git a/org.simantics.district.maps/lib/gt-opengis-16.2.jar b/org.simantics.district.maps/lib/gt-opengis-16.2.jar
new file mode 100644 (file)
index 0000000..67079c9
Binary files /dev/null and b/org.simantics.district.maps/lib/gt-opengis-16.2.jar differ
diff --git a/org.simantics.district.maps/lib/gt-referencing-16.2.jar b/org.simantics.district.maps/lib/gt-referencing-16.2.jar
new file mode 100644 (file)
index 0000000..8426bc3
Binary files /dev/null and b/org.simantics.district.maps/lib/gt-referencing-16.2.jar differ
diff --git a/org.simantics.district.maps/lib/hsqldb-2.3.0.jar b/org.simantics.district.maps/lib/hsqldb-2.3.0.jar
new file mode 100644 (file)
index 0000000..5069b5e
Binary files /dev/null and b/org.simantics.district.maps/lib/hsqldb-2.3.0.jar differ
diff --git a/org.simantics.district.maps/lib/jai_core-1.1.3.jar b/org.simantics.district.maps/lib/jai_core-1.1.3.jar
new file mode 100644 (file)
index 0000000..b29b8ee
Binary files /dev/null and b/org.simantics.district.maps/lib/jai_core-1.1.3.jar differ
diff --git a/org.simantics.district.maps/lib/jgridshift-1.0.jar b/org.simantics.district.maps/lib/jgridshift-1.0.jar
new file mode 100644 (file)
index 0000000..d9b8d32
Binary files /dev/null and b/org.simantics.district.maps/lib/jgridshift-1.0.jar differ
diff --git a/org.simantics.district.maps/lib/jsr-275-1.0-beta-2.jar b/org.simantics.district.maps/lib/jsr-275-1.0-beta-2.jar
new file mode 100644 (file)
index 0000000..68e19aa
Binary files /dev/null and b/org.simantics.district.maps/lib/jsr-275-1.0-beta-2.jar differ
diff --git a/org.simantics.district.maps/plugin.xml b/org.simantics.district.maps/plugin.xml
new file mode 100644 (file)
index 0000000..0b965be
--- /dev/null
@@ -0,0 +1,19 @@
+<?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>
index 3c4a9944fd628a95d979722b7fd2ee62267b9966..00f06dea21839e06859a1908524df132a02948d3 100644 (file)
@@ -17,6 +17,7 @@ import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant;
 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;
@@ -57,6 +58,7 @@ public class MapPainter extends AbstractCanvasParticipant {
     };
 
     protected MapNode node = null;
+    protected MapScaleNode scaleNode = null;
 
     private int scale;
 
@@ -103,6 +105,11 @@ public class MapPainter extends AbstractCanvasParticipant {
         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
diff --git a/org.simantics.district.maps/src/org/simantics/maps/prefs/MapsClientPreferenceInitializer.java b/org.simantics.district.maps/src/org/simantics/maps/prefs/MapsClientPreferenceInitializer.java
new file mode 100644 (file)
index 0000000..3350ebb
--- /dev/null
@@ -0,0 +1,17 @@
+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");
+    }
+}
diff --git a/org.simantics.district.maps/src/org/simantics/maps/prefs/MapsClientPreferencePage.java b/org.simantics.district.maps/src/org/simantics/maps/prefs/MapsClientPreferencePage.java
new file mode 100644 (file)
index 0000000..ba16836
--- /dev/null
@@ -0,0 +1,36 @@
+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);
+    }
+
+}
diff --git a/org.simantics.district.maps/src/org/simantics/maps/prefs/MapsClientPreferences.java b/org.simantics.district.maps/src/org/simantics/maps/prefs/MapsClientPreferences.java
new file mode 100644 (file)
index 0000000..5ecfe05
--- /dev/null
@@ -0,0 +1,8 @@
+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";
+}
diff --git a/org.simantics.district.maps/src/org/simantics/maps/sg/MapScaleNode.java b/org.simantics.district.maps/src/org/simantics/maps/sg/MapScaleNode.java
new file mode 100644 (file)
index 0000000..a0242c1
--- /dev/null
@@ -0,0 +1,242 @@
+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;
+    }
+
+}
index eb85b78f36866f49f02c868cfb4e77af829d8a24..c1cb1b6d1c219e7161f7bd853ee81def90644e73 100644 (file)
Binary files a/org.simantics.district.network.ontology/graph.tg and b/org.simantics.district.network.ontology/graph.tg differ
index ade6b1c5992bd63011cc5eabe4119e56b71e8e46..5c30822b1f856c9cbcc8d79611a23f619f9938cc 100644 (file)
@@ -15,12 +15,10 @@ DN = <http://www.simantics.org/DistrictNetwork-1.0> : L0.Ontology
 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
@@ -71,15 +69,12 @@ DN.HasInLayerTag <R L0.HasProperty
 
 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"
index 30d74d258442c7c65512eafab474568dd706c430..c8b3f1d10c0132e0d53df1d3f70631c993c03eea 100644 (file)
@@ -1 +1,10 @@
-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
index 9219ba476eb7a1cf154df814ddbe2c97726e79ed..c7766365a0e837e22e608171ee35c7709fb5384b 100644 (file)
@@ -1,18 +1,18 @@
-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]
+}
index 714f808578ff9116403d494689c9792e26a18bb3..1e73de182320ee60bf4cf2800d25c881b9f3afa6 100644 (file)
@@ -58,7 +58,6 @@ public class DistrictNetworkResource {
     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;
@@ -132,7 +131,6 @@ public class DistrictNetworkResource {
         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";
@@ -216,7 +214,6 @@ public class DistrictNetworkResource {
         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);
diff --git a/org.simantics.district.network.ui/plugin.properties b/org.simantics.district.network.ui/plugin.properties
new file mode 100644 (file)
index 0000000..072f946
--- /dev/null
@@ -0,0 +1 @@
+DistrictPreferencePage.name=District
index 826432f96becceff038bd996783d00e75299df63..db59f043e7acf5b71b3ba987acb1390e6123fee2 100644 (file)
             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
index 7ae651342eca629bd3f33266d90da798fc0a0050..0ea5adf7f7638173ba324b27a610bc931c946c33 100644 (file)
@@ -94,11 +94,19 @@ public class Functions {
     }
 
     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 {
@@ -196,10 +204,13 @@ public class Functions {
         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;
 
@@ -239,14 +250,21 @@ public class Functions {
                         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);
                     }); 
@@ -379,6 +397,11 @@ 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()));
+        }
+
+        public Resource getCRS() {
+            return defaultCRS;
         }
         
     }
@@ -404,6 +427,7 @@ 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.HasSpatialRefSystem, dialog.getCRS());
                             }
                         });
                         DefaultActions.asyncPerformDefaultAction(Simantics.getSession(), composite, false, false, true);
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/prefs/DistrictPreferencePage.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/prefs/DistrictPreferencePage.java
new file mode 100644 (file)
index 0000000..2d7154e
--- /dev/null
@@ -0,0 +1,33 @@
+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() {
+
+    }
+
+}
index 2aaaa26eb14aa3cd392ffb7812d2da74199b6fbe..60214a423b1380a93ec6ff9c93177d12fcd85ea2 100644 (file)
@@ -9,5 +9,6 @@ Require-Bundle: org.simantics.db,
  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
diff --git a/org.simantics.district.network/adapters.xml b/org.simantics.district.network/adapters.xml
new file mode 100644 (file)
index 0000000..590741a
--- /dev/null
@@ -0,0 +1,11 @@
+<?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
diff --git a/org.simantics.district.network/scl/Simantics/District.scl b/org.simantics.district.network/scl/Simantics/District.scl
new file mode 100644 (file)
index 0000000..ed12251
--- /dev/null
@@ -0,0 +1,4 @@
+import "Simantics/DB"
+
+importJava "org.simantics.district.network.DistrictNetworkUtil" where
+    calculateDistance :: Resource -> Resource -> <ReadGraph> Double
\ No newline at end of file
diff --git a/org.simantics.district.network/src/org/simantics/district/network/CRS.java b/org.simantics.district.network/src/org/simantics/district/network/CRS.java
new file mode 100644 (file)
index 0000000..e9a5a72
--- /dev/null
@@ -0,0 +1,6 @@
+package org.simantics.district.network;
+
+public interface CRS {
+
+    public double calculateDistance(double[] start, double[] end);
+}
index 9bdec1b590367107660947593d32e122d6cddf98..94799a97382e57a23a31b404f64e785f7d751245 100644 (file)
@@ -3,11 +3,12 @@ package org.simantics.district.network;
 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;
@@ -20,6 +21,10 @@ public class DistrictNetworkUtil {
         
         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;
@@ -32,6 +37,10 @@ public class DistrictNetworkUtil {
         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);
         
@@ -61,4 +70,21 @@ public class DistrictNetworkUtil {
         }
         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);
+    }
 }
diff --git a/org.simantics.district.network/src/org/simantics/district/network/ModelledCRS.java b/org.simantics.district.network/src/org/simantics/district/network/ModelledCRS.java
new file mode 100644 (file)
index 0000000..fd129ff
--- /dev/null
@@ -0,0 +1,30 @@
+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();
+    }
+
+}