]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Final push of district changes 69/469/1
authorjsimomaa <jani.simomaa@gmail.com>
Fri, 28 Apr 2017 13:02:42 +0000 (16:02 +0300)
committerjsimomaa <jani.simomaa@gmail.com>
Fri, 28 Apr 2017 13:02:42 +0000 (16:02 +0300)
refs #6958

Change-Id: I5a6429a9bde4528f2fbc402c3483c2bea7789f70

32 files changed:
org.simantics.district.imports.ui/META-INF/MANIFEST.MF
org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportModel.java
org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizard.java
org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizardPage.java
org.simantics.district.imports/META-INF/MANIFEST.MF
org.simantics.district.imports/src/org/simantics/district/imports/DistrictImportUtils.java
org.simantics.district.maps/.classpath
org.simantics.district.maps/META-INF/MANIFEST.MF
org.simantics.district.maps/build.properties
org.simantics.district.network.ontology/graph.tg
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/META-INF/MANIFEST.MF
org.simantics.district.network.ui/fragment.e4xmi
org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkAdditionalColor.java [new file with mode: 0644]
org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkEdgeElement.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkEdgeElementFactory.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkVertexElement.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkVertexElementFactory.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/RunMappingHandler.java [deleted file]
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/DistrictNetworkEdgeNode.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/MapRulerNode.java [new file with mode: 0644]
org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/NetworkDrawingNode.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DNTranslateMode.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/MapRulerPainter.java [new file with mode: 0644]
org.simantics.district.network/META-INF/MANIFEST.MF
org.simantics.district.network/scl/Simantics/District.scl
org.simantics.district.network/src/org/simantics/district/network/ModelledCRS.java
org.simantics.maps.server.ui/src/org/simantics/maps/server/ui/prefs/MapsServerPreferencePage.java

index fb65af54a9f5f7686ff6620361e97b1c20c4aa81..48019c70ff4e951999eb0f462c1c3b3470486e5a 100644 (file)
@@ -8,5 +8,7 @@ Require-Bundle: org.eclipse.ui.ide,
  org.eclipse.jface,
  org.simantics.utils.ui,
  org.simantics.district.imports;bundle-version="1.0.0",
- org.simantics.db
+ org.simantics.db,
+ org.simantics.district.geotools;bundle-version="1.0.0",
+ org.simantics.district.network.ui;bundle-version="1.0.0"
 Bundle-ActivationPolicy: lazy
index 50c427c4d14f66138ec17246411ecae4d617294b..1521a926c233005eef708058f478dbd5f8641886 100644 (file)
@@ -1,73 +1,90 @@
-package org.simantics.district.imports.ui;\r
-\r
-import java.io.IOException;\r
-import java.nio.file.Path;\r
-import java.util.Collections;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import org.simantics.district.imports.DistrictImportUtils;\r
-import org.simantics.district.imports.DistrictImportUtils.CSVHeader;\r
-\r
-public class CSVImportModel {\r
-\r
-    private Path source;\r
-    private char delimiter;\r
-    private boolean read;\r
-    private Map<String, Character> delimiters;\r
-\r
-    public CSVImportModel() {\r
-        delimiters = DistrictImportUtils.getSupportedCSVDelimiterFormats();\r
-    }\r
-    \r
-    public void setSource(Path source) {\r
-        this.source = source;\r
-    }\r
-\r
-    public void setDelimiter(char delimiter) {\r
-        this.delimiter = delimiter;\r
-    }\r
-\r
-    public void setReadFirstAsHeader(boolean read) {\r
-        this.read = read;\r
-    }\r
-\r
-    public Path getSource() {\r
-        return source;\r
-    }\r
-\r
-    public Map<CSVHeader, List<String>> getHeaderAndRows(int amount) throws IOException {\r
-        if (source != null)\r
-            return DistrictImportUtils.readCSVHeaderAndRows(source, delimiter, read, amount);\r
-        else\r
-            return Collections.emptyMap();\r
-    }\r
-    \r
-    public Map<String, Integer> getHeader() throws IOException {\r
-        Map<String, Integer> header = null;\r
-        if (source != null)\r
-            header = DistrictImportUtils.readCSVHeader(source, delimiter, read);\r
-        if (header == null)\r
-            header = Collections.emptyMap();\r
-        return header;\r
-    }\r
-\r
-    public boolean getReadFirstAsHeader() {\r
-        return read;\r
-    }\r
-\r
-    public String[] getDelimiterFormats() {\r
-        return delimiters.keySet().toArray(new String[delimiters.size()]);\r
-    }\r
-\r
-    public void setDelimiterByLabel(String item) {\r
-        setDelimiter(delimiters.get(item));\r
-    }\r
-\r
-    public List<Map<String, String>> readRows(int amount) throws IOException {\r
-        if (source != null)\r
-            return DistrictImportUtils.readRows(source, delimiter, read, amount);\r
-        else\r
-            return Collections.emptyList();\r
-    }\r
-}\r
+package org.simantics.district.imports.ui;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.csv.CSVRecord;
+import org.simantics.district.imports.DistrictImportUtils;
+import org.simantics.district.imports.DistrictImportUtils.CSVHeader;
+
+public class CSVImportModel {
+
+    private Path source;
+    private char delimiter;
+    private boolean read;
+    private Map<String, Character> delimiters;
+    private Path wktFile;
+
+    public CSVImportModel() {
+        delimiters = DistrictImportUtils.getSupportedCSVDelimiterFormats();
+    }
+    
+    public void setSource(Path source) {
+        this.source = source;
+    }
+
+    public void setDelimiter(char delimiter) {
+        this.delimiter = delimiter;
+    }
+
+    public void setReadFirstAsHeader(boolean read) {
+        this.read = read;
+    }
+
+    public Path getSource() {
+        return source;
+    }
+
+    public List<CSVRecord> getRows(int amount) throws IOException {
+        if (source != null)
+            return DistrictImportUtils.readRows(source, delimiter, amount);
+        else
+            return Collections.emptyList();
+    }
+    
+    public Map<CSVHeader, List<String>> getHeaderAndRows(int amount) throws IOException {
+        if (source != null)
+            return DistrictImportUtils.readCSVHeaderAndRows(source, delimiter, read, amount);
+        else
+            return Collections.emptyMap();
+    }
+    
+    public Map<String, Integer> getHeader() throws IOException {
+        Map<String, Integer> header = null;
+        if (source != null)
+            header = DistrictImportUtils.readCSVHeader(source, delimiter, read);
+        if (header == null)
+            header = Collections.emptyMap();
+        return header;
+    }
+
+    public boolean getReadFirstAsHeader() {
+        return read;
+    }
+
+    public String[] getDelimiterFormats() {
+        return delimiters.keySet().toArray(new String[delimiters.size()]);
+    }
+
+    public void setDelimiterByLabel(String item) {
+        setDelimiter(delimiters.get(item));
+    }
+
+    public List<Map<String, String>> readRows(int amount) throws IOException {
+        if (source != null)
+            return DistrictImportUtils.readRows(source, delimiter, read, amount);
+        else
+            return Collections.emptyList();
+    }
+
+    public char getDelimiter() {
+        return delimiter;
+    }
+
+    public Path getWKTFile() {
+        return wktFile;
+    }
+}
index 97fa990aed619334c5d080e04b74b0e4ec2fb830..7a29e7505788c6b603a34f9dbf0c7cc76f30b896 100644 (file)
@@ -1,38 +1,61 @@
-package org.simantics.district.imports.ui;\r
-\r
-import java.io.IOException;\r
-import java.nio.file.Path;\r
-\r
-import org.eclipse.jface.viewers.IStructuredSelection;\r
-import org.eclipse.jface.wizard.Wizard;\r
-import org.eclipse.ui.IImportWizard;\r
-import org.eclipse.ui.IWorkbench;\r
-import org.simantics.district.imports.DistrictImportUtils;\r
-\r
-public class CSVImportWizard extends Wizard implements IImportWizard {\r
-\r
-    private CSVImportModel model;\r
-    \r
-    public CSVImportWizard() {\r
-        setWindowTitle("Import CSV data");\r
-    }\r
-    \r
-    \r
-    @Override\r
-    public void init(IWorkbench workbench, IStructuredSelection selection) {\r
-        model = new CSVImportModel();\r
-        addPage(new CSVImportWizardPage(model));\r
-    }\r
-    \r
-    @Override\r
-    public boolean performFinish() {\r
-        Path csvFile = model.getSource();\r
-        try {\r
-            DistrictImportUtils.importCSVAsLayer(csvFile);\r
-        } catch (IOException e) {\r
-            e.printStackTrace();\r
-        }\r
-        return false;\r
-    }\r
-\r
-}\r
+package org.simantics.district.imports.ui;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.List;
+
+import org.apache.commons.csv.CSVRecord;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.IImportWizard;
+import org.eclipse.ui.IWorkbench;
+import org.geotools.referencing.CRS;
+import org.opengis.referencing.FactoryException;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.simantics.district.imports.DistrictImportUtils;
+
+public class CSVImportWizard extends Wizard implements IImportWizard {
+
+    private CSVImportModel model;
+    
+    public CSVImportWizard() {
+        setWindowTitle("Import CSV data");
+    }
+    
+    
+    @Override
+    public void init(IWorkbench workbench, IStructuredSelection selection) {
+        model = new CSVImportModel();
+        addPage(new CSVImportWizardPage(model));
+    }
+    
+    @Override
+    public boolean performFinish() {
+        try {
+            
+            
+            Path csvFile = model.getSource();
+            char delim = model.getDelimiter();
+            
+            List<CSVRecord> rows = DistrictImportUtils.readRows(csvFile, delim, -1);
+            
+            Path wktFile = model.getWKTFile();
+            
+            try {
+                
+                
+                CoordinateReferenceSystem crs = CRS.decode(null);
+            } catch (FactoryException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+            
+            
+            DistrictImportUtils.importCSVAsLayer(csvFile);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return false;
+    }
+
+}
index 71017b321b90d9486974021f75d01ca4a764b517..e4a0612a2358e8b4a6a609d6146cb45ea084f504 100644 (file)
-package org.simantics.district.imports.ui;\r
-\r
-import java.io.IOException;\r
-import java.nio.file.Files;\r
-import java.nio.file.Path;\r
-import java.nio.file.Paths;\r
-import java.util.Collections;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import org.eclipse.jface.layout.GridDataFactory;\r
-import org.eclipse.jface.layout.TableColumnLayout;\r
-import org.eclipse.jface.layout.TreeColumnLayout;\r
-import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;\r
-import org.eclipse.jface.viewers.ColumnWeightData;\r
-import org.eclipse.jface.viewers.IContentProvider;\r
-import org.eclipse.jface.viewers.TableViewer;\r
-import org.eclipse.jface.viewers.TreeViewer;\r
-import org.eclipse.jface.viewers.Viewer;\r
-import org.eclipse.jface.wizard.WizardPage;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.events.SelectionEvent;\r
-import org.eclipse.swt.events.SelectionListener;\r
-import org.eclipse.swt.layout.GridData;\r
-import org.eclipse.swt.layout.GridLayout;\r
-import org.eclipse.swt.widgets.Button;\r
-import org.eclipse.swt.widgets.Combo;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Layout;\r
-import org.eclipse.swt.widgets.Table;\r
-import org.eclipse.swt.widgets.TableColumn;\r
-import org.eclipse.swt.widgets.TableItem;\r
-import org.simantics.district.imports.DistrictImportUtils.CSVHeader;\r
-import org.simantics.utils.ui.widgets.FileOrDirectorySelectionWidget;\r
-import org.simantics.utils.ui.widgets.FileSelectionListener;\r
-import org.simantics.utils.ui.widgets.FileSelectionWidget;\r
-\r
-public class CSVImportWizardPage extends WizardPage implements FileSelectionListener {\r
-\r
-    private CSVImportModel model;\r
-    private FileSelectionWidget csvSelection;\r
-    private Table headerTable;\r
-    private Button firstAsHeader;\r
-    private Combo delimiterCombo;\r
-    private TableColumnLayout tableColumnLayout;\r
-    private TableViewer tableViewer;\r
-    private Composite tableComposite;\r
-\r
-    protected CSVImportWizardPage(CSVImportModel model) {\r
-        super("Import CSV Data");\r
-        this.model = model;\r
-        setMessage("Select CSV file to import");\r
-    }\r
-\r
-    @Override\r
-    public void createControl(Composite parent) {\r
-        Composite composite = new Composite(parent, SWT.NONE);\r
-        composite.setLayout(new GridLayout(1,false));\r
-        GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(composite);\r
-        \r
-        csvSelection = new FileSelectionWidget(composite, "CSV file", SWT.OPEN);\r
-        csvSelection.addListener(this);\r
-        \r
-        delimiterCombo = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY);\r
-        delimiterCombo.setItems(model.getDelimiterFormats());\r
-        delimiterCombo.addSelectionListener(new SelectionListener() {\r
-            \r
-            @Override\r
-            public void widgetSelected(SelectionEvent e) {\r
-                model.setDelimiterByLabel(delimiterCombo.getItem(delimiterCombo.getSelectionIndex()));\r
-                updateHeaders();\r
-            }\r
-            \r
-            @Override\r
-            public void widgetDefaultSelected(SelectionEvent e) {\r
-                \r
-            }\r
-        });\r
-        \r
-        firstAsHeader = new Button(composite, SWT.CHECK);\r
-        firstAsHeader.setText("Read first row as header");\r
-        firstAsHeader.setSelection(model.getReadFirstAsHeader());\r
-        firstAsHeader.addSelectionListener(new SelectionListener() {\r
-            \r
-            @Override\r
-            public void widgetSelected(SelectionEvent e) {\r
-                model.setReadFirstAsHeader(firstAsHeader.getSelection());\r
-                updateHeaders();\r
-            }\r
-            \r
-            @Override\r
-            public void widgetDefaultSelected(SelectionEvent e) {\r
-                \r
-            }\r
-        });\r
-        \r
-        \r
-        tableComposite = new Composite(composite, SWT.BORDER);\r
-        tableColumnLayout = new TableColumnLayout();\r
-        tableComposite.setLayout(tableColumnLayout);\r
-\r
-        updateHeaders();\r
-        \r
-        setControl(composite);\r
-        \r
-        \r
-        \r
-        setPageComplete(false);\r
-    }\r
-\r
-    @Override\r
-    public void fileSelected(FileOrDirectorySelectionWidget source, String[] filename) {\r
-        String[] selection = csvSelection.getFilename();\r
-        if (selection != null && selection.length > 0) {\r
-            Path csvFile = Paths.get(selection[0]);\r
-            if (!Files.exists(csvFile)) {\r
-                setErrorMessage("File " + csvFile.toAbsolutePath() + " does not exist");\r
-            } else {\r
-                model.setSource(csvFile);\r
-                updateHeaders();\r
-                setPageComplete(true);\r
-            }\r
-        } else {\r
-            setPageComplete(false);\r
-        }\r
-    }\r
-\r
-    private void updateHeaders() {\r
-        if (headerTable != null)\r
-            headerTable.dispose();\r
-        headerTable = new Table(tableComposite, SWT.NONE);\r
-        headerTable.setHeaderVisible(true);\r
-        headerTable.setLinesVisible(true);\r
-        GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(tableComposite);\r
-        for (int i = 0; i < headerTable.getColumns().length; i++) {\r
-            TableColumn column = headerTable.getColumns()[i];\r
-            column.dispose();\r
-        }\r
-        for (int i = 0; i < headerTable.getItemCount(); i++) {\r
-            TableItem item = headerTable.getItem(i);\r
-            item.dispose();\r
-        }\r
-        try {\r
-            Map<CSVHeader, List<String>> headerAndValues = model.getHeaderAndRows(5);\r
-            \r
-            int coo = headerTable.getColumns().length;\r
-            int count = headerTable.getColumnCount();\r
-            \r
-            for (Map.Entry<CSVHeader, List<String>> entr : headerAndValues.entrySet()) {\r
-                CSVHeader he = entr.getKey();\r
-                int index = he.getIndex();\r
-                TableColumn headerCol = new TableColumn(headerTable, SWT.NONE);\r
-                headerCol.setText(he.getHeader());\r
-                \r
-                tableColumnLayout.setColumnData(headerCol, new ColumnWeightData(10));\r
-                headerCol.pack();\r
-                \r
-                for (String val : entr.getValue()) {\r
-                    TableItem item = new TableItem(headerTable, SWT.NONE);\r
-                    item.setText(val);\r
-                }\r
-            }\r
-        } catch (IOException e) {\r
-            setErrorMessage(e.getMessage());\r
-        }\r
-    }\r
-\r
-}\r
+package org.simantics.district.imports.ui;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+
+import org.apache.commons.csv.CSVRecord;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.TableColumnLayout;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+import org.simantics.district.network.ui.function.Functions;
+import org.simantics.utils.ui.widgets.FileOrDirectorySelectionWidget;
+import org.simantics.utils.ui.widgets.FileSelectionListener;
+import org.simantics.utils.ui.widgets.FileSelectionWidget;
+
+
+public class CSVImportWizardPage extends WizardPage implements FileSelectionListener {
+
+    private CSVImportModel model;
+    private FileSelectionWidget csvSelection;
+    private Table headerTable;
+    private Button firstAsHeader;
+    
+    private Combo diagramCombo;
+    
+    
+    private Combo delimiterCombo;
+    private Combo delimiterdCombo;
+    private TableColumnLayout tableColumnLayout;
+    private TableViewer tableViewer;
+    private Composite tableComposite;
+    private FileSelectionWidget wktFileSelection;
+    
+    private Path wktFile;
+
+    protected CSVImportWizardPage(CSVImportModel model) {
+        super("Import CSV Data");
+        this.model = model;
+        setMessage("Select CSV file to import");
+    }
+
+    @Override
+    public void createControl(Composite parent) {
+        Composite composite = new Composite(parent, SWT.NONE);
+        composite.setLayout(new GridLayout(1,false));
+        GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(composite);
+        
+        diagramCombo = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
+        diagramCombo.setItems(getDistrictDiagrams());
+        
+        
+        csvSelection = new FileSelectionWidget(composite, "CSV file", SWT.OPEN);
+        csvSelection.addListener(this);
+        
+        delimiterCombo = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
+        delimiterCombo.setItems(model.getDelimiterFormats());
+        delimiterCombo.addSelectionListener(new SelectionListener() {
+            
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                model.setDelimiterByLabel(delimiterCombo.getItem(delimiterCombo.getSelectionIndex()));
+                updateHeaders();
+            }
+            
+            @Override
+            public void widgetDefaultSelected(SelectionEvent e) {
+                
+            }
+        });
+        
+        firstAsHeader = new Button(composite, SWT.CHECK);
+        firstAsHeader.setText("Read first row as header");
+        firstAsHeader.setSelection(model.getReadFirstAsHeader());
+        firstAsHeader.addSelectionListener(new SelectionListener() {
+            
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                model.setReadFirstAsHeader(firstAsHeader.getSelection());
+                updateHeaders();
+            }
+            
+            @Override
+            public void widgetDefaultSelected(SelectionEvent e) {
+                
+            }
+        });
+        
+        
+        tableComposite = new Composite(composite, SWT.BORDER);
+        tableColumnLayout = new TableColumnLayout();
+        tableComposite.setLayout(tableColumnLayout);
+
+        
+        
+        wktFileSelection = new FileSelectionWidget(composite, "WKT file", SWT.OPEN);
+        wktFileSelection.addListener(new FileSelectionListener() {
+            
+            @Override
+            public void fileSelected(FileOrDirectorySelectionWidget source, String[] filename) {
+                String[] selection = wktFileSelection.getFilename();
+                if (selection != null && selection.length > 0) {
+                    Path wktFilee = Paths.get(selection[0]);
+                    if (!Files.exists(wktFilee)) {
+                        setErrorMessage("File " + wktFilee.toAbsolutePath() + " does not exist");
+                    } else {
+                        wktFile = wktFilee;
+                        setPageComplete(true);
+                    }
+                } else {
+                    setPageComplete(false);
+                } 
+            }
+        });
+        
+        updateHeaders();
+        
+        
+        
+        setControl(composite);
+        
+        
+        
+        setPageComplete(false);
+    }
+
+    private String[] getDistrictDiagrams() {
+        Functions.getDistrictDiagrams(null);
+        return null;
+    }
+
+    @Override
+    public void fileSelected(FileOrDirectorySelectionWidget source, String[] filename) {
+        String[] selection = csvSelection.getFilename();
+        if (selection != null && selection.length > 0) {
+            Path csvFile = Paths.get(selection[0]);
+            if (!Files.exists(csvFile)) {
+                setErrorMessage("File " + csvFile.toAbsolutePath() + " does not exist");
+            } else {
+                model.setSource(csvFile);
+                updateHeaders();
+                setPageComplete(true);
+            }
+        } else {
+            setPageComplete(false);
+        }
+    }
+
+    private void updateHeaders() {
+        if (headerTable != null)
+            headerTable.dispose();
+        headerTable = new Table(tableComposite, SWT.NONE);
+        headerTable.setHeaderVisible(true);
+        headerTable.setLinesVisible(true);
+        GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(tableComposite);
+        for (int i = 0; i < headerTable.getColumns().length; i++) {
+            TableColumn column = headerTable.getColumns()[i];
+            column.dispose();
+        }
+        for (int i = 0; i < headerTable.getItemCount(); i++) {
+            TableItem item = headerTable.getItem(i);
+            item.dispose();
+        }
+        try {
+            List<CSVRecord> rows = model.getRows(5);
+            
+            for (int k = 0; k < rows.size(); k++) {
+                CSVRecord row = rows.get(k);
+                
+                int columnCount = row.size();
+                for (int i = 0; i < columnCount; i++) {
+                    String value = row.get(i);
+                    if (k == 0) {
+                        TableColumn headerCol = new TableColumn(headerTable, SWT.NONE);
+                        headerCol.setText(value);
+                        
+                        tableColumnLayout.setColumnData(headerCol, new ColumnWeightData(10));
+                        headerCol.pack();
+                    } else {
+                        int actualK = k - 1;
+                        TableItem item;
+                        int itemCount = headerTable.getItemCount();
+                        if (actualK >= itemCount) {
+                            item = new TableItem(headerTable, SWT.NONE);
+                        } else {
+                            item = headerTable.getItem(actualK);
+                        }
+                        item.setText(i, value);
+                    }
+                }
+            }
+            
+//            Map<CSVHeader, List<String>> headerAndValues = model.getHeaderAndRows(5);
+//            
+//            int coo = headerTable.getColumns().length;
+//            int count = headerTable.getColumnCount();
+//            
+//            for (Map.Entry<CSVHeader, List<String>> entr : headerAndValues.entrySet()) {
+//                CSVHeader he = entr.getKey();
+//                int index = he.getIndex();
+//                TableColumn headerCol = new TableColumn(headerTable, SWT.NONE);
+//                headerCol.setText(he.getHeader());
+//                
+//                tableColumnLayout.setColumnData(headerCol, new ColumnWeightData(10));
+//                headerCol.pack();
+//                
+//                for (String val : entr.getValue()) {
+//                    TableItem item = new TableItem(headerTable, SWT.NONE);
+//                    item.setText(val);
+//                }
+//            }
+        } catch (IOException e) {
+            setErrorMessage(e.getMessage());
+        }
+    }
+
+}
index 50cc5d263d4d6e45f6cb45b62126e4f38b78e4c2..b04e92231529be57325cddb6a37e9eb05891d524 100644 (file)
@@ -5,6 +5,7 @@ Bundle-SymbolicName: org.simantics.district.imports
 Bundle-Version: 1.0.0.qualifier
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Require-Bundle: org.simantics.db
-Export-Package: org.simantics.district.imports
+Export-Package: org.apache.commons.csv,
+ org.simantics.district.imports
 Bundle-ClassPath: lib/commons-csv-1.4.jar,
  .
index 7c0d998c20e7f4688d3bed8b2397d2c85054f50f..1ad5b9a9487c0667d91a553cd6ecc461b1851156 100644 (file)
-package org.simantics.district.imports;\r
-\r
-import java.io.IOException;\r
-import java.nio.file.Files;\r
-import java.nio.file.Path;\r
-import java.util.ArrayList;\r
-import java.util.HashMap;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import org.apache.commons.csv.CSVFormat;\r
-import org.apache.commons.csv.CSVParser;\r
-import org.apache.commons.csv.CSVRecord;\r
-import org.simantics.db.Resource;\r
-\r
-public class DistrictImportUtils {\r
-\r
-    private DistrictImportUtils() { }\r
-    \r
-    \r
-    public static Resource importCSVAsLayer(Path csvFile) throws IOException {\r
-        \r
-        \r
-        try (CSVParser parser = CSVFormat.DEFAULT.withFirstRecordAsHeader().parse(Files.newBufferedReader(csvFile))) {\r
-            Map<String, Integer> header = parser.getHeaderMap();\r
-            System.out.println(header);\r
-        }\r
-        return null;\r
-    }\r
-    \r
-    public static Map<String, Integer> readCSVHeader(Path source, char delimiter, boolean firstAsHeader) throws IOException {\r
-        return readCSVHeader(source, CSVFormat.newFormat(delimiter), firstAsHeader);\r
-    }\r
-    \r
-    public static Map<String, Integer> readCSVHeader(Path source, CSVFormat format, boolean firstAsHeader) throws IOException {\r
-        if (firstAsHeader)\r
-            format = format.withFirstRecordAsHeader();\r
-        try (CSVParser parser = format.parse(Files.newBufferedReader(source))) {\r
-            return parser.getHeaderMap();\r
-        }\r
-    }\r
-\r
-\r
-    public static Map<String, Character> getSupportedCSVDelimiterFormats() {\r
-        Map<String, Character> delimiters = new HashMap<>();\r
-        delimiters.put("COMMA", ',');\r
-        delimiters.put("SEMICOMMA", ';');\r
-        return delimiters;\r
-    }\r
-\r
-    public static List<Map<String, String>> readRows(Path source, char delimiter, boolean firstAsHeader, int amount) throws IOException {\r
-        return readRows(source, CSVFormat.newFormat(delimiter), firstAsHeader, amount);\r
-    }\r
-\r
-    public static List<Map<String, String>> readRows(Path source, CSVFormat format, boolean firstAsHeader, int amount) throws IOException {\r
-        if (firstAsHeader)\r
-            format = format.withFirstRecordAsHeader();\r
-        try (CSVParser parser = format.parse(Files.newBufferedReader(source))) {\r
-            int start = 0;\r
-            List<Map<String, String>> results = new ArrayList<>(amount);\r
-            Iterator<CSVRecord> iter = parser.iterator();\r
-            while (start < amount && iter.hasNext()) {\r
-                CSVRecord record = iter.next();\r
-                results.add(record.toMap());\r
-                start++;\r
-            }\r
-            return results;\r
-        }\r
-    }\r
-\r
-\r
-    public static Map<CSVHeader, List<String>> readCSVHeaderAndRows(Path source, char delimiter, boolean firstAsHeader, int amount) throws IOException {\r
-        Map<CSVHeader, List<String>> results = new HashMap<>();\r
-        CSVFormat format = CSVFormat.newFormat(delimiter);\r
-        if (firstAsHeader)\r
-            format = format.withFirstRecordAsHeader();\r
-        try (CSVParser parser = format.parse(Files.newBufferedReader(source))) {\r
-            Map<String, Integer> headers = parser.getHeaderMap();\r
-            if (headers != null && !headers.isEmpty()) {\r
-                for (int index = 0; index < headers.size(); index++) {\r
-                    for (String head : headers.keySet()) {\r
-                        results.put(new CSVHeader(head, index), new ArrayList<>());\r
-                    }\r
-                }\r
-            }\r
-            \r
-            Iterator<CSVRecord> records = parser.iterator();\r
-            int rows = 0;\r
-            while (rows < amount && records.hasNext()) {\r
-                CSVRecord record = records.next();\r
-                for (int j = 0; j < record.size(); j++) {\r
-                    String value = record.get(j);\r
-                    String header = Integer.toString(j);\r
-                    CSVHeader csvHeader = new CSVHeader(header, j);\r
-                    List<String> vals = results.get(csvHeader);\r
-                    if (vals == null) {\r
-                        vals = new ArrayList<>();\r
-                        results.put(csvHeader, vals);\r
-                    }\r
-                    vals.add(value);\r
-                }\r
-                rows++;\r
-            }\r
-        }\r
-        return results;\r
-    }\r
-    \r
-    public static class CSVHeader {\r
-\r
-        private final String header;\r
-        private final int index;\r
-        \r
-        public CSVHeader(String header, int index) {\r
-            this.header = header;\r
-            this.index = index;\r
-        }\r
-\r
-        public String getHeader() {\r
-            return header;\r
-        }\r
-\r
-        public int getIndex() {\r
-            return index;\r
-        }\r
-        \r
-        @Override\r
-        public int hashCode() {\r
-            final int prime = 31;\r
-            int result = 1;\r
-            result = prime * result + ((header == null) ? 0 : header.hashCode());\r
-            result = prime * result + index;\r
-            return result;\r
-        }\r
-\r
-        @Override\r
-        public boolean equals(Object obj) {\r
-            if (this == obj)\r
-                return true;\r
-            if (obj == null)\r
-                return false;\r
-            if (getClass() != obj.getClass())\r
-                return false;\r
-            CSVHeader other = (CSVHeader) obj;\r
-            if (header == null) {\r
-                if (other.header != null)\r
-                    return false;\r
-            } else if (!header.equals(other.header))\r
-                return false;\r
-            if (index != other.index)\r
-                return false;\r
-            return true;\r
-        }\r
-    }\r
-\r
-}\r
+package org.simantics.district.imports;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.csv.CSVFormat;
+import org.apache.commons.csv.CSVParser;
+import org.apache.commons.csv.CSVRecord;
+import org.simantics.db.Resource;
+
+public class DistrictImportUtils {
+
+    private DistrictImportUtils() { }
+    
+    
+    public static Resource importCSVAsLayer(Path csvFile) throws IOException {
+        
+        try (CSVParser parser = CSVFormat.DEFAULT.withFirstRecordAsHeader().parse(Files.newBufferedReader(csvFile))) {
+            Map<String, Integer> header = parser.getHeaderMap();
+            System.out.println(header);
+        }
+        return null;
+    }
+    
+    public static Map<String, Integer> readCSVHeader(Path source, char delimiter, boolean firstAsHeader) throws IOException {
+        return readCSVHeader(source, CSVFormat.newFormat(delimiter), firstAsHeader);
+    }
+    
+    public static Map<String, Integer> readCSVHeader(Path source, CSVFormat format, boolean firstAsHeader) throws IOException {
+        if (firstAsHeader)
+            format = format.withFirstRecordAsHeader();
+        try (CSVParser parser = format.parse(Files.newBufferedReader(source))) {
+            return parser.getHeaderMap();
+        }
+    }
+
+    public static Map<String, Character> getSupportedCSVDelimiterFormats() {
+        Map<String, Character> delimiters = new HashMap<>();
+        delimiters.put("COMMA", ',');
+        delimiters.put("SEMICOMMA", ';');
+        return delimiters;
+    }
+
+    public static List<Map<String, String>> readRows(Path source, char delimiter, boolean firstAsHeader, int amount) throws IOException {
+        return readRows(source, CSVFormat.newFormat(delimiter), firstAsHeader, amount);
+    }
+
+    public static List<Map<String, String>> readRows(Path source, CSVFormat format, boolean firstAsHeader, int amount) throws IOException {
+        if (firstAsHeader)
+            format = format.withFirstRecordAsHeader();
+        try (CSVParser parser = format.parse(Files.newBufferedReader(source))) {
+            int start = 0;
+            List<Map<String, String>> results = new ArrayList<>(amount);
+            Iterator<CSVRecord> iter = parser.iterator();
+            while (start < amount && iter.hasNext()) {
+                CSVRecord record = iter.next();
+                results.add(record.toMap());
+                start++;
+            }
+            return results;
+        }
+    }
+
+    public static List<CSVRecord> readRows(Path source, char delim, int rowAmount) throws IOException {
+        List<CSVRecord> results = new ArrayList<>();
+        CSVFormat format = CSVFormat.newFormat(delim);
+        try (CSVParser parser = format.parse(Files.newBufferedReader(source))) {
+            Iterator<CSVRecord> records = parser.iterator();
+            int rows = 0;
+            if (rowAmount == -1) {
+                while (records.hasNext()) {
+                    results.add(records.next());
+                    rows++;
+                }
+            } else {
+                while (rows < rowAmount && records.hasNext()) {
+                    results.add(records.next());
+                    rows++;
+                }
+            }
+        }
+        return results;
+    }
+
+    
+    public static Map<CSVHeader, List<String>> readCSVHeaderAndRows(Path source, char delimiter, boolean firstAsHeader, int amount) throws IOException {
+        Map<CSVHeader, List<String>> results = new HashMap<>();
+        CSVFormat format = CSVFormat.newFormat(delimiter);
+        if (firstAsHeader)
+            format = format.withFirstRecordAsHeader();
+        try (CSVParser parser = format.parse(Files.newBufferedReader(source))) {
+            Map<String, Integer> headers = parser.getHeaderMap();
+            if (headers != null && !headers.isEmpty()) {
+                for (int index = 0; index < headers.size(); index++) {
+                    for (String head : headers.keySet()) {
+                        results.put(new CSVHeader(head, index), new ArrayList<>());
+                    }
+                }
+            }
+            
+            Iterator<CSVRecord> records = parser.iterator();
+            int rows = 0;
+            while (rows < amount && records.hasNext()) {
+                CSVRecord record = records.next();
+                for (int j = 0; j < record.size(); j++) {
+                    String value = record.get(j);
+                    String header = Integer.toString(j);
+                    CSVHeader csvHeader = new CSVHeader(header, j);
+                    List<String> vals = results.get(csvHeader);
+                    if (vals == null) {
+                        vals = new ArrayList<>();
+                        results.put(csvHeader, vals);
+                    }
+                    vals.add(value);
+                }
+                rows++;
+            }
+        }
+        return results;
+    }
+    
+    public static class CSVHeader {
+
+        private final String header;
+        private final int index;
+        
+        public CSVHeader(String header, int index) {
+            this.header = header;
+            this.index = index;
+        }
+
+        public String getHeader() {
+            return header;
+        }
+
+        public int getIndex() {
+            return index;
+        }
+        
+        @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = 1;
+            result = prime * result + ((header == null) ? 0 : header.hashCode());
+            result = prime * result + index;
+            return result;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj)
+                return true;
+            if (obj == null)
+                return false;
+            if (getClass() != obj.getClass())
+                return false;
+            CSVHeader other = (CSVHeader) obj;
+            if (header == null) {
+                if (other.header != null)
+                    return false;
+            } else if (!header.equals(other.header))
+                return false;
+            if (index != other.index)
+                return false;
+            return true;
+        }
+    }
+
+}
index 0e4c914299c53685204d28d36cf1b9e4580386b7..751c8f2e504c40d1c41ebbd87d8f8968529e9c30 100644 (file)
@@ -1,17 +1,6 @@
 <?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 9754d75797b3e5bfa9fac068168f1f991499f072..0ea8a6e610264c8de650096861833783b4d20be5 100644 (file)
@@ -11,28 +11,14 @@ Require-Bundle: org.simantics.scenegraph,
  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.eclipse.ui.workbench,
+ org.simantics.district.geotools;bundle-version="1.0.0"
+Export-Package: 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: .,
- 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 5fd55626dda41b579b99ca59e3d1ef83c50a3678..98bec33aed6d7f36d1b3faa87ec4ef3da8ef5bcc 100644 (file)
@@ -1,16 +1,3 @@
-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
index 6737f9afa6f4e786bede66c9973c396fddd9bfb8..ad5ff83b613216efd7c0fdfb2ce87698582b5da9 100644 (file)
Binary files a/org.simantics.district.network.ontology/graph.tg and b/org.simantics.district.network.ontology/graph.tg differ
index 5e17f658ed8f2cc0a3d5b454e11840d8ae7f62aa..a4144a808f895333c6ef14b09fd21fb8bc564048 100644 (file)
@@ -15,16 +15,11 @@ 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.Bidirectional false
-    @L0.assert DN.Edge.HasDiameter 1
+    @L0.assert DN.Edge.HasDiameter 0.1
+    @L0.assert DN.Edge.HasOuterDiameter 0.11
 
 DN.Vertex <T DIA.Element : L0.Type
-    @L0.assert DN.Bidirectional false
-
-DN.Bidirectional <R L0.HasProperty : SEL.GenericParameterType
-    L0.HasLabel "Is network bidirectional"
-    L0.HasRange L0.Boolean
-    L0.readOnly false
+    @L0.assert DN.Vertex.HasElevation 0.0
 
 DN.EdgeDefaultMapping <R L0.HasProperty : DN.EdgeMappingParameterType
     L0.HasLabel "Default Edge mapping"
@@ -60,6 +55,16 @@ DN.Edge.HasDiameter <R L0.HasProperty : SEL.GenericParameterType
     L0.HasRange L0.Double
     L0.readOnly false
 
+DN.Vertex.HasElevation <R L0.HasProperty : SEL.GenericParameterType
+    L0.HasLabel "Elevation"
+    L0.HasRange L0.Double
+    L0.readOnly false
+
+DN.Edge.HasOuterDiameter <R L0.HasProperty : SEL.GenericParameterType
+    L0.HasLabel "Outer Diameter"
+    L0.HasRange L0.Double
+    L0.readOnly false
+
 DN.InLayer
     @L0.defTag 
     @L0.tag L0.Abstract
@@ -169,7 +174,6 @@ DN.Mapping.VertexMapping <T DN.Mapping.Base
 
 DN.Mapping.EdgeMapping <T DN.Mapping.Base
     >-- DN.Mapping.ComponentType
-    >-- DN.Mapping.EdgeMapping.Bidirectional --> L0.Boolean <R L0.HasProperty
     >-- DN.Mapping.EdgeMapping.LengthAttribute --> L0.String <R L0.HasProperty
     >-- DN.Mapping.EdgeMapping.DiameterAttribute --> L0.String <R L0.HasProperty
     >-- DN.Mapping.Terminals
index 678f344b13eb772efecc075a381dff3ba8082b3a..8ac781ba9057509ba23ce50cc664f332ea05c686 100644 (file)
@@ -15,8 +15,6 @@ public class DistrictNetworkResource {
     public final Resource Actions;
     public final Resource Actions_NewDNDiagram;
     public final Resource AddLayerToDNDiagramTemplate;
-    public final Resource Bidirectional;
-    public final Resource Bidirectional_Inverse;
     public final Resource BrowseContext;
     public final Resource Composite;
     public final Resource Connection;
@@ -29,6 +27,8 @@ public class DistrictNetworkResource {
     public final Resource EdgeMappingParameterType;
     public final Resource Edge_HasDiameter;
     public final Resource Edge_HasDiameter_Inverse;
+    public final Resource Edge_HasOuterDiameter;
+    public final Resource Edge_HasOuterDiameter_Inverse;
     public final Resource Functions;
     public final Resource Functions_compositeInstantiator;
     public final Resource Functions_convertToValue;
@@ -61,8 +61,6 @@ public class DistrictNetworkResource {
     public final Resource Mapping_ComponentType;
     public final Resource Mapping_ComponentType_Inverse;
     public final Resource Mapping_EdgeMapping;
-    public final Resource Mapping_EdgeMapping_Bidirectional;
-    public final Resource Mapping_EdgeMapping_Bidirectional_Inverse;
     public final Resource Mapping_EdgeMapping_DiameterAttribute;
     public final Resource Mapping_EdgeMapping_DiameterAttribute_Inverse;
     public final Resource Mapping_EdgeMapping_LengthAttribute;
@@ -83,6 +81,8 @@ public class DistrictNetworkResource {
     public final Resource VertexDefaultMapping;
     public final Resource VertexDefaultMapping_Inverse;
     public final Resource VertexMappingParameterType;
+    public final Resource Vertex_HasElevation;
+    public final Resource Vertex_HasElevation_Inverse;
         
     public static class URIs {
         public static final String ActionContext = "http://www.simantics.org/DistrictNetwork-1.0/ActionContext";
@@ -90,8 +90,6 @@ public class DistrictNetworkResource {
         public static final String Actions = "http://www.simantics.org/DistrictNetwork-1.0/Actions";
         public static final String Actions_NewDNDiagram = "http://www.simantics.org/DistrictNetwork-1.0/Actions/NewDNDiagram";
         public static final String AddLayerToDNDiagramTemplate = "http://www.simantics.org/DistrictNetwork-1.0/AddLayerToDNDiagramTemplate";
-        public static final String Bidirectional = "http://www.simantics.org/DistrictNetwork-1.0/Bidirectional";
-        public static final String Bidirectional_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Bidirectional/Inverse";
         public static final String BrowseContext = "http://www.simantics.org/DistrictNetwork-1.0/BrowseContext";
         public static final String Composite = "http://www.simantics.org/DistrictNetwork-1.0/Composite";
         public static final String Connection = "http://www.simantics.org/DistrictNetwork-1.0/Connection";
@@ -104,6 +102,8 @@ public class DistrictNetworkResource {
         public static final String EdgeMappingParameterType = "http://www.simantics.org/DistrictNetwork-1.0/EdgeMappingParameterType";
         public static final String Edge_HasDiameter = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasDiameter";
         public static final String Edge_HasDiameter_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasDiameter/Inverse";
+        public static final String Edge_HasOuterDiameter = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasOuterDiameter";
+        public static final String Edge_HasOuterDiameter_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasOuterDiameter/Inverse";
         public static final String Functions = "http://www.simantics.org/DistrictNetwork-1.0/Functions";
         public static final String Functions_compositeInstantiator = "http://www.simantics.org/DistrictNetwork-1.0/Functions/compositeInstantiator";
         public static final String Functions_convertToValue = "http://www.simantics.org/DistrictNetwork-1.0/Functions/convertToValue";
@@ -136,8 +136,6 @@ public class DistrictNetworkResource {
         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_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";
         public static final String Mapping_EdgeMapping_DiameterAttribute = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/DiameterAttribute";
         public static final String Mapping_EdgeMapping_DiameterAttribute_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/DiameterAttribute/Inverse";
         public static final String Mapping_EdgeMapping_LengthAttribute = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/LengthAttribute";
@@ -158,6 +156,8 @@ public class DistrictNetworkResource {
         public static final String VertexDefaultMapping = "http://www.simantics.org/DistrictNetwork-1.0/VertexDefaultMapping";
         public static final String VertexDefaultMapping_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/VertexDefaultMapping/Inverse";
         public static final String VertexMappingParameterType = "http://www.simantics.org/DistrictNetwork-1.0/VertexMappingParameterType";
+        public static final String Vertex_HasElevation = "http://www.simantics.org/DistrictNetwork-1.0/Vertex/HasElevation";
+        public static final String Vertex_HasElevation_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Vertex/HasElevation/Inverse";
     }
     
     public static Resource getResourceOrNull(ReadGraph graph, String uri) {
@@ -175,8 +175,6 @@ public class DistrictNetworkResource {
         Actions = getResourceOrNull(graph, URIs.Actions);
         Actions_NewDNDiagram = getResourceOrNull(graph, URIs.Actions_NewDNDiagram);
         AddLayerToDNDiagramTemplate = getResourceOrNull(graph, URIs.AddLayerToDNDiagramTemplate);
-        Bidirectional = getResourceOrNull(graph, URIs.Bidirectional);
-        Bidirectional_Inverse = getResourceOrNull(graph, URIs.Bidirectional_Inverse);
         BrowseContext = getResourceOrNull(graph, URIs.BrowseContext);
         Composite = getResourceOrNull(graph, URIs.Composite);
         Connection = getResourceOrNull(graph, URIs.Connection);
@@ -189,6 +187,8 @@ public class DistrictNetworkResource {
         EdgeMappingParameterType = getResourceOrNull(graph, URIs.EdgeMappingParameterType);
         Edge_HasDiameter = getResourceOrNull(graph, URIs.Edge_HasDiameter);
         Edge_HasDiameter_Inverse = getResourceOrNull(graph, URIs.Edge_HasDiameter_Inverse);
+        Edge_HasOuterDiameter = getResourceOrNull(graph, URIs.Edge_HasOuterDiameter);
+        Edge_HasOuterDiameter_Inverse = getResourceOrNull(graph, URIs.Edge_HasOuterDiameter_Inverse);
         Functions = getResourceOrNull(graph, URIs.Functions);
         Functions_compositeInstantiator = getResourceOrNull(graph, URIs.Functions_compositeInstantiator);
         Functions_convertToValue = getResourceOrNull(graph, URIs.Functions_convertToValue);
@@ -221,8 +221,6 @@ public class DistrictNetworkResource {
         Mapping_ComponentType = getResourceOrNull(graph, URIs.Mapping_ComponentType);
         Mapping_ComponentType_Inverse = getResourceOrNull(graph, URIs.Mapping_ComponentType_Inverse);
         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);
         Mapping_EdgeMapping_DiameterAttribute = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_DiameterAttribute);
         Mapping_EdgeMapping_DiameterAttribute_Inverse = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_DiameterAttribute_Inverse);
         Mapping_EdgeMapping_LengthAttribute = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_LengthAttribute);
@@ -243,6 +241,8 @@ public class DistrictNetworkResource {
         VertexDefaultMapping = getResourceOrNull(graph, URIs.VertexDefaultMapping);
         VertexDefaultMapping_Inverse = getResourceOrNull(graph, URIs.VertexDefaultMapping_Inverse);
         VertexMappingParameterType = getResourceOrNull(graph, URIs.VertexMappingParameterType);
+        Vertex_HasElevation = getResourceOrNull(graph, URIs.Vertex_HasElevation);
+        Vertex_HasElevation_Inverse = getResourceOrNull(graph, URIs.Vertex_HasElevation_Inverse);
     }
     
     public static DistrictNetworkResource getInstance(ReadGraph graph) {
index 49df92f576410c8aa339578e332f7734f4a32aa1..b3aef5400f3e93c72ade1f550d8988eb79e96743 100644 (file)
@@ -4,7 +4,8 @@ Bundle-Name: Simantics District Network UI
 Bundle-SymbolicName: org.simantics.district.network.ui;singleton:=true
 Bundle-Version: 1.0.0.qualifier
 Bundle-Activator: org.simantics.district.network.ui.internal.Activator
-Export-Package: org.simantics.district.network.ui.adapters
+Export-Package: org.simantics.district.network.ui.adapters,
+ org.simantics.district.network.ui.function
 Require-Bundle: org.eclipse.e4.ui.model.workbench;bundle-version="1.1.100.v20150407-1430",
  org.eclipse.swt,
  org.simantics.g2d,
index 75ef8fa7b7f51d9f282fe8dede3634aa6282e582..f0c705c81dd7355a2c8f730a5eb5c2c5cc62c894 100644 (file)
@@ -6,7 +6,6 @@
   </fragments>
   <fragments xsi:type="fragment:StringModelFragment" xmi:id="_4mZBIML_Eea1mdgpHNVHMA" featurename="commands" parentElementId="xpath:/">
     <elements xsi:type="commands:Command" xmi:id="_6lrYUML_Eea1mdgpHNVHMA" elementId="org.simantics.district.network.ui.command.openDistrictEditor" commandName="Open District Editor"/>
-    <elements xsi:type="commands:Command" xmi:id="_zhiBwN16Eea73Pr1j_7O0Q" elementId="org.simantics.district.network.ui.command.runmapping" commandName="Run mapping"/>
     <elements xsi:type="commands:Command" xmi:id="_A1HBQOFYEeaJP6VyXP72Jw" elementId="org.simantics.district.network.ui.joinVertices" commandName="Join Vertices"/>
     <elements xsi:type="commands:Command" xmi:id="_QzdUQOIcEeaJP6VyXP72Jw" elementId="org.simantics.district.network.ui.setFocusable" commandName="Set Focusable"/>
   </fragments>
     </elements>
   </fragments>
   <fragments xsi:type="fragment:StringModelFragment" xmi:id="_dbiHcMMBEea1mdgpHNVHMA" featurename="handlers" parentElementId="xpath:/">
-    <elements xsi:type="commands:Handler" xmi:id="_ffHv0MMBEea1mdgpHNVHMA" elementId="org.simantics.district.network.ui.handler.runmapping" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.contributions.RunMappingHandler" command="_zhiBwN16Eea73Pr1j_7O0Q"/>
     <elements xsi:type="commands:Handler" xmi:id="_DPcVsOFYEeaJP6VyXP72Jw" elementId="org.simantics.district.network.ui.handler.joinVertices" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.contributions.JoinVerticesHandler" command="_A1HBQOFYEeaJP6VyXP72Jw"/>
     <elements xsi:type="commands:Handler" xmi:id="_VPgBwOIcEeaJP6VyXP72Jw" elementId="org.simantics.district.network.ui.handler.setFocusable" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.contributions.SetFocusableHandler" command="_QzdUQOIcEeaJP6VyXP72Jw"/>
   </fragments>
-  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_Rf7koN16Eea73Pr1j_7O0Q" featurename="trimContributions" parentElementId="xpath:/">
-    <elements xsi:type="menu:TrimContribution" xmi:id="_c57iwN16Eea73Pr1j_7O0Q" elementId="org.simantics.district.network.ui.trimcontribution.0" parentId="org.eclipse.ui.main.toolbar">
-      <children xsi:type="menu:ToolBar" xmi:id="_vdgLoN16Eea73Pr1j_7O0Q" elementId="org.simantics.district.network.ui.toolbar.0">
-        <children xsi:type="menu:HandledToolItem" xmi:id="_v99NUN16Eea73Pr1j_7O0Q" elementId="org.simantics.district.network.ui.handledtoolitem.domapping" label="Map network ontology" iconURI="platform:/plugin/org.simantics.district.network.ui/icons/map_go.png" tooltip="Map network ontology to simulator specific model" command="_zhiBwN16Eea73Pr1j_7O0Q"/>
-      </children>
-    </elements>
-  </fragments>
 </fragment:ModelFragments>
index 57480180f2e44807f5319ff878f1a93dea0f8061..486f87596e9e4bab0fb7ea47bc1d8332a2f76682 100644 (file)
@@ -3,6 +3,7 @@ package org.simantics.district.network.ui;
 import java.util.concurrent.TimeUnit;
 
 import org.simantics.district.network.ui.participants.DNPointerInteractor;
+import org.simantics.district.network.ui.participants.MapRulerPainter;
 import org.simantics.g2d.canvas.ICanvasContext;
 import org.simantics.g2d.canvas.impl.CanvasContext;
 import org.simantics.g2d.diagram.handler.PickRequest.PickFilter;
@@ -10,6 +11,8 @@ import org.simantics.g2d.diagram.participant.DelayedBatchElementPainter;
 import org.simantics.g2d.diagram.participant.ElementPainter;
 import org.simantics.g2d.diagram.participant.Selection;
 import org.simantics.g2d.diagram.participant.ZOrderHandler;
+import org.simantics.g2d.participant.BackgroundPainter;
+import org.simantics.g2d.participant.GridPainter;
 import org.simantics.g2d.participant.PanZoomRotateHandler;
 import org.simantics.g2d.participant.RenderingQualityInteractor;
 import org.simantics.maps.eclipse.MapPainter;
@@ -47,4 +50,11 @@ public class DistrictDiagramViewer extends DiagramViewer {
         ctx.add(new RenderingQualityInteractor());
         ctx.add(new DelayedBatchElementPainter(PickFilter.FILTER_MONITORS, 500, TimeUnit.MILLISECONDS));
     }
+    
+    @Override
+    protected void addGridRulerBackgroundParticipants(CanvasContext ctx) {
+        ctx.add(new GridPainter());
+        ctx.add(new MapRulerPainter());
+        ctx.add(new BackgroundPainter());
+    }
 }
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkAdditionalColor.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkAdditionalColor.java
new file mode 100644 (file)
index 0000000..ef3b10c
--- /dev/null
@@ -0,0 +1,42 @@
+package org.simantics.district.network.ui.adapters;
+
+import java.awt.Color;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.simantics.db.Resource;
+import org.simantics.g2d.element.IElement;
+import org.simantics.g2d.element.handler.AdditionalColor;
+import org.simantics.g2d.element.handler.ElementHandler;
+import org.simantics.utils.datastructures.hints.IHintContext.Key;
+import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
+import org.simantics.utils.ui.color.ColorPool;
+
+public class DistrictNetworkAdditionalColor implements AdditionalColor {
+
+    public static final Key KEY_DN_MAPPING_RESOURCE = new KeyOf(Resource.class, "DN_MAPPING_RESOURCE");
+    
+    private static final long serialVersionUID = -6290147660355075322L;
+
+    public static final ElementHandler INSTANCE = new DistrictNetworkAdditionalColor();
+
+    private ColorPool colorPool = new ColorPool();
+    private List<Resource> mappings = new ArrayList<>();
+    
+    @Override
+    public void setAdditionalColor(IElement e, Color c) {
+        throw new UnsupportedOperationException("Not needed!");
+    }
+
+    @Override
+    public Color getAdditionalColor(IElement e) {
+        Resource mapping = e.getHint(KEY_DN_MAPPING_RESOURCE);
+        if (!mappings.contains(mapping))
+            mappings.add(mapping);
+        
+        int index = mappings.indexOf(mapping);
+        Color color = colorPool.getColor(index).getAWTColor();
+        return color;
+    }
+
+}
index 12f26182dca15fe03cd4cf02ff6588a2a3954f3f..cf10ffab7c85923d8824b94fcbaefb4363e17e1c 100644 (file)
@@ -1,5 +1,6 @@
 package org.simantics.district.network.ui.adapters;
 
+import java.awt.Color;
 import java.awt.geom.Rectangle2D;
 import java.util.Collection;
 import java.util.Collections;
@@ -33,7 +34,8 @@ public class DistrictNetworkEdgeElement {
                     DNEdgeInternalSize.INSTANCE,
                     DNEdgeSceneGraph.INSTANCE,
                     DNEdgeConnectionHandler.INSTANCE,
-                    SimpleElementLayers.INSTANCE
+                    SimpleElementLayers.INSTANCE,
+                    DistrictNetworkAdditionalColor.INSTANCE
             ).setId(DistrictNetworkEdgeElement.class.getSimpleName());
     
     static final class DNEdgeSceneGraph implements SceneGraph {
@@ -53,6 +55,9 @@ public class DistrictNetworkEdgeElement {
                     node = parent.addNode(ElementUtils.generateNodeId(edgeElement), DistrictNetworkEdgeNode.class);
                     edgeElement.setHint(KEY_DN_EDGE_NODE, node);
                 }
+                
+                node.setColor(ElementUtils.getAdditionalColor(edgeElement, Color.BLUE));
+                
                 node.setDNEdge(edge);
             }
         }
index 63590990cd9ba421097cd65270be0b6cf8faaa4c..2899a0e7cf8db5911e54beb3ad1b9d39db55c2d3 100644 (file)
@@ -13,7 +13,7 @@ import org.simantics.diagram.synchronization.IModifiableSynchronizationContext;
 import org.simantics.diagram.synchronization.SynchronizationHints;
 import org.simantics.diagram.synchronization.graph.GraphSynchronizationHints;
 import org.simantics.diagram.synchronization.graph.layer.GraphLayerManager;
-import org.simantics.diagram.ui.DiagramModelHints;
+import org.simantics.district.network.ModelledCRS;
 import org.simantics.district.network.ontology.DistrictNetworkResource;
 import org.simantics.district.network.ui.DistrictNetworkEdge;
 import org.simantics.g2d.canvas.ICanvasContext;
@@ -49,19 +49,30 @@ public class DistrictNetworkEdgeElementFactory extends SyncElementFactory {
     @Override
     public void load(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource edgeResource, IElement element) throws DatabaseException {
         
-        Resource diagramRuntime = diagram.getHint(DiagramModelHints.KEY_DIAGRAM_RUNTIME_RESOURCE);
-        
         Resource startVertex = graph.getSingleObject(edgeResource, DN.HasStartVertex);
         Resource endVertex = graph.getSingleObject(edgeResource, DN.HasEndVertex);
         
+        // TODO: fix scale..
+        double scale = 100000;
+        
         double[] startCoords = graph.getRelatedValue2(startVertex, DIA.HasLocation);
+        
+        double startLon = ModelledCRS.longitudeToX(startCoords[0]) * scale;
+        double startLat = ModelledCRS.latitudeToY(startCoords[1]) * scale;
+        
         double[] endCoords = graph.getRelatedValue2(endVertex, DIA.HasLocation);
         
+        double endLon = ModelledCRS.longitudeToX(endCoords[0]) * scale;
+        double endLat = ModelledCRS.latitudeToY(endCoords[1]) * scale;
+        
         Path2D path = new Path2D.Double();
-        path.moveTo(startCoords[0], startCoords[1]);
-        path.lineTo(endCoords[0], endCoords[1]);
+        path.moveTo(startLon, startLat);
+        path.lineTo(endLon, endLat);
         
         DistrictNetworkEdge edge = new DistrictNetworkEdge(path);
+
+        Resource mapping = graph.getSingleObject(edgeResource, DistrictNetworkResource.getInstance(graph).HasMapping);
+        element.setHint(DistrictNetworkAdditionalColor.KEY_DN_MAPPING_RESOURCE, mapping);
         
         element.setHint(DistrictNetworkEdgeElement.KEY_DN_EDGE, edge);
         
index 3e64bc3193957d249df2d6371cc5dfbcbc422d65..24f8459dccba859c40590d1d2ab3a7e61e56e48c 100644 (file)
@@ -1,5 +1,6 @@
 package org.simantics.district.network.ui.adapters;
 
+import java.awt.Color;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Rectangle2D;
 
@@ -26,7 +27,8 @@ public class DistrictNetworkVertexElement {
                     DefaultTransform.INSTANCE,
                     DNVertexInternalSize.INSTANCE,
                     DNVertexSceneGraph.INSTANCE,
-                    SimpleElementLayers.INSTANCE
+                    SimpleElementLayers.INSTANCE,
+                    DistrictNetworkAdditionalColor.INSTANCE
             ).setId(DistrictNetworkVertexElement.class.getSimpleName());
     
     static final class DNVertexSceneGraph implements SceneGraph {
@@ -36,19 +38,21 @@ public class DistrictNetworkVertexElement {
         private static final long serialVersionUID = 8894367073815556871L;
 
         @Override
-        public void init(IElement edgeElement, G2DParentNode parent) {
-            DistrictNetworkVertex vertex = edgeElement.getHint(KEY_DN_VERTEX);
+        public void init(IElement vertexElement, G2DParentNode parent) {
+            DistrictNetworkVertex vertex = vertexElement.getHint(KEY_DN_VERTEX);
             if (vertex == null) {
-                cleanup(edgeElement);
+                cleanup(vertexElement);
             } else {
-                DistrictNetworkVertexNode node = edgeElement.getHint(KEY_DN_VERTEX_NODE);
+                DistrictNetworkVertexNode node = vertexElement.getHint(KEY_DN_VERTEX_NODE);
                 if (node == null) {
-                    node = parent.addNode(ElementUtils.generateNodeId(edgeElement), DistrictNetworkVertexNode.class);
-                    edgeElement.setHint(KEY_DN_VERTEX_NODE, node);
+                    node = parent.addNode(ElementUtils.generateNodeId(vertexElement), DistrictNetworkVertexNode.class);
+                    vertexElement.setHint(KEY_DN_VERTEX_NODE, node);
                 }
                 node.setVertex(vertex);
                 
-                AffineTransform at = ElementUtils.getTransform(edgeElement);
+                node.setColor(ElementUtils.getAdditionalColor(vertexElement, Color.BLUE));
+                
+                AffineTransform at = ElementUtils.getTransform(vertexElement);
                 if(at != null)
                     node.setTransform(at);
             }
@@ -69,9 +73,8 @@ public class DistrictNetworkVertexElement {
 
         @Override
         public Rectangle2D getBounds(IElement e, Rectangle2D size) {
-            if (size == null)
-                size = new Rectangle2D.Double();
-            size.setFrame(-0.5, -0.5, 1, 1);
+            DistrictNetworkVertexNode node = e.getHint(KEY_DN_VERTEX_NODE);
+            size.setFrame(node.getBoundsInLocal());
             return size;
         }
         
index 976abd48596ccf177065addfa8ffbc1914e1904e..6fa19c422a2d9439f36a265650f3b3cc051e7409 100644 (file)
@@ -13,6 +13,7 @@ import org.simantics.diagram.synchronization.IModifiableSynchronizationContext;
 import org.simantics.diagram.synchronization.SynchronizationHints;
 import org.simantics.diagram.synchronization.graph.GraphSynchronizationHints;
 import org.simantics.diagram.synchronization.graph.layer.GraphLayerManager;
+import org.simantics.district.network.ModelledCRS;
 import org.simantics.district.network.ontology.DistrictNetworkResource;
 import org.simantics.g2d.canvas.ICanvasContext;
 import org.simantics.g2d.diagram.DiagramHints;
@@ -28,7 +29,7 @@ public class DistrictNetworkVertexElementFactory extends SyncElementFactory {
     public static final ElementClass CLASS = DistrictNetworkVertexElement.CLASS;
     private DistrictNetworkResource DN;
     private DiagramResource DIA;
-
+    
     public DistrictNetworkVertexElementFactory(ReadGraph graph) {
         this.DN = DistrictNetworkResource.getInstance(graph);
         this.DIA = DiagramResource.getInstance(graph);
@@ -49,10 +50,19 @@ public class DistrictNetworkVertexElementFactory extends SyncElementFactory {
         
         double[] coords = graph.getRelatedValue(vertexResource, DIA.HasLocation);
         DistrictNetworkVertex vertex = new DistrictNetworkVertex(coords);
+        
+        Resource mapping = graph.getSingleObject(vertexResource, DistrictNetworkResource.getInstance(graph).HasMapping);
+        element.setHint(DistrictNetworkAdditionalColor.KEY_DN_MAPPING_RESOURCE, mapping);
         element.setHint(DistrictNetworkVertexElement.KEY_DN_VERTEX, vertex);
         
-        // set element transform based on layer SRS and coords
-        AffineTransform at = new AffineTransform(1, 0, 0, 1, coords[0], coords[1]);
+        // TODO: set element transform based on layer SRS and coords
+        
+        double x = ModelledCRS.longitudeToX(coords[0]);
+        double y = ModelledCRS.latitudeToY(coords[1]);
+        
+        double scale = 100000;
+        
+        AffineTransform at = new AffineTransform(1, 0, 0, 1, x * scale, y * scale);
         ElementUtils.setTransform(element, at);
         
         IModifiableSynchronizationContext context = diagram.getHint(SynchronizationHints.CONTEXT);
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/RunMappingHandler.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/RunMappingHandler.java
deleted file mode 100644 (file)
index 5ae0c0d..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-package org.simantics.district.network.ui.contributions;
-
-import javax.inject.Named;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.e4.core.di.annotations.CanExecute;
-import org.eclipse.e4.core.di.annotations.Execute;
-import org.eclipse.e4.ui.model.application.ui.basic.MPart;
-import org.eclipse.e4.ui.services.IServiceConstants;
-import org.eclipse.ui.IEditorPart;
-import org.simantics.DatabaseJob;
-import org.simantics.Simantics;
-import org.simantics.db.WriteGraph;
-import org.simantics.db.common.request.WriteRequest;
-import org.simantics.db.exception.DatabaseException;
-import org.simantics.district.network.ui.internal.Activator;
-import org.simantics.ui.workbench.IResourceEditorInput;
-import org.simantics.ui.workbench.e4.E4WorkbenchUtils;
-
-public class RunMappingHandler {
-
-    @CanExecute
-    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART) MPart mActiveEditorPart) {
-        IEditorPart activeEditorPart = E4WorkbenchUtils.getActiveIEditorPart(mActiveEditorPart);
-        return activeEditorPart != null;
-    }
-    
-    @Execute
-    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart mActiveEditorPart) {
-        Job job = new DatabaseJob("Map network to Apros") {
-            
-            @Override
-            protected IStatus run(IProgressMonitor monitor) {
-                try {
-                    IEditorPart activeEditorPart = E4WorkbenchUtils.getActiveIEditorPart(mActiveEditorPart);
-                    IResourceEditorInput input = (IResourceEditorInput) activeEditorPart.getEditorInput();
-                    Simantics.getSession().syncRequest(new WriteRequest() {
-                        
-                        @Override
-                        public void perform(WriteGraph graph) throws DatabaseException {
-                            Object result = Simantics.applySCL("Apros/District/DistrictMapping", "mapNetworkToAprosProgress", graph, monitor, input.getResource());
-                        }
-                    });
-                } catch (DatabaseException e) {
-                    return new Status(IStatus.ERROR, Activator.PLUGIN_ID, getName() + " failed.", e);
-                }
-                return Status.OK_STATUS;
-            }
-        };
-        job.setUser(true);
-        job.schedule();
-    }
-}
index f421c6735e5f48ea642894512d18442ce27d942c..4fc40dbb109253fb5a2a2bf01a9eea0624dc6013 100644 (file)
@@ -445,4 +445,8 @@ public class Functions {
                     }
                 });
     }
+
+    public static void getDistrictDiagrams(ReadGraph graph) {
+        
+    }
 }
index 408625f5aeeaa0bcafc139c636291d921860124d..11d883e91d560c77a4ceb2297ff4d51988aa657e 100644 (file)
@@ -26,6 +26,8 @@ public class DistrictNetworkEdgeNode extends G2DNode {
     private static final Stroke STROKE = new BasicStroke(4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
     private boolean scaleStroke = true;
 
+    private Color color;
+
     @Override
     public void init() {
 
@@ -54,7 +56,7 @@ public class DistrictNetworkEdgeNode extends G2DNode {
 //            g2d.fill(selectionShape);
 //        }
 //        
-        g2d.setColor(Color.BLUE);
+        g2d.setColor(color);
         if (STROKE != null) {
             if (scaleStroke && STROKE instanceof BasicStroke) {
                 BasicStroke bs = GeometryUtils.scaleStroke(STROKE, (float) (1.0 / GeometryUtils.getScale(g2d.getTransform())));
@@ -100,4 +102,12 @@ public class DistrictNetworkEdgeNode extends G2DNode {
         updateBounds();
     }
 
+    public void setColor(Color color) {
+        this.color = color;
+    }
+    
+    public Color getColor() {
+        return color;
+    }
+
 }
index 8dcd5183a6cb1545ad201b681f45fefbe9d5adc6..86c71857f16a860d93498bcf534c70f0d5239f7a 100644 (file)
@@ -27,12 +27,14 @@ public class DistrictNetworkVertexNode extends G2DNode {
     private static final double height = 1;
     
     private static final Rectangle2D NORMAL = new Rectangle2D.Double(left, top, width, height);
-    private static final Rectangle2D HOVERED = new Rectangle2D.Double(left * 2, top * 2, width * 2, height * 2);
+    private static final Rectangle2D HOVERED = new Rectangle2D.Double(left * 3, top * 3, width * 3, height * 3);
     
     private Stroke stroke = new BasicStroke(2);
     private boolean scaleStroke = true;
     private boolean hover;
 
+    private Color color;
+
     @Override
     public void init() {
         setZIndex(2);
@@ -53,7 +55,7 @@ public class DistrictNetworkVertexNode extends G2DNode {
         Color oldColor = g2d.getColor();
         Stroke oldStroke = g2d.getStroke();
         
-        g2d.setColor(Color.RED);
+        g2d.setColor(color);
         
         double scaleRecip = 1;
         if (scaleStroke) {
@@ -85,13 +87,15 @@ public class DistrictNetworkVertexNode extends G2DNode {
 
     @Override
     public Rectangle2D getBoundsInLocal() {
+        if (hover)
+            return HOVERED;
         return NORMAL;
     }
 
     public void setVertex(DistrictNetworkVertex vertex) {
         this.vertex = vertex;
     }
-
+    
     public boolean hover(boolean hover) {
 //        if (hover && LOGGER.isDebugEnabled())
 //            LOGGER.debug("Hovering " + this);
@@ -103,4 +107,12 @@ public class DistrictNetworkVertexNode extends G2DNode {
         return changed;
     }
 
+    public void setColor(Color color) {
+        this.color = color;
+    }
+    
+    public Color getColor() {
+        return color;
+    }
+
 }
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/MapRulerNode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/MapRulerNode.java
new file mode 100644 (file)
index 0000000..078c8eb
--- /dev/null
@@ -0,0 +1,24 @@
+package org.simantics.district.network.ui.nodes;
+
+import org.simantics.district.network.ModelledCRS;
+import org.simantics.scenegraph.g2d.nodes.RulerNode;
+
+public class MapRulerNode extends RulerNode {
+
+    private static final long serialVersionUID = -7140072658133605907L;
+
+    @Override
+    protected double modifyHorizontalValue(double value) {
+        // TODO: fix scale!
+        double scale = 100000;
+        return ModelledCRS.xToLongitude(value / scale);
+    }
+
+    @Override
+    protected double modifyVerticalValue(double value) {
+        // TODO: fix scale!
+        double scale = 100000;
+        return ModelledCRS.yToLatitude(value / scale);
+    }
+
+}
index 147442343c13b6b7c3dfa42ab04694757aa4f834..13bd2cbe9426a536e9ce3b8030a0a4b0ca1b5158 100644 (file)
@@ -17,6 +17,7 @@ import org.simantics.db.WriteGraph;
 import org.simantics.db.common.request.WriteRequest;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.diagram.ui.DiagramModelHints;
+import org.simantics.district.network.ModelledCRS;
 import org.simantics.district.network.ui.DNEdgeBuilder;
 import org.simantics.district.network.ui.NetworkDrawingParticipant;
 import org.simantics.g2d.canvas.Hints;
@@ -150,20 +151,34 @@ public class NetworkDrawingNode extends G2DNode {
         }
         return super.mouseDoubleClicked(e);
     }
-    
+
     private void createEdge(Point2D start, Point2D end) {
         
         double padding = GeometryUtils.getScale(getTransform());
         
-        double[] startCoords = new double[] { start.getX(), start.getY() };
-        double[] endCoords = new double[] { end.getX(), end.getY() };
+        /*
+         *  To convert y-coordinates to map coordinates in ruler, use:
+         *    double val = (y-offsetY)/scaleY;
+         *    val = Math.toDegrees(Math.atan(Math.sinh(Math.toRadians(val))));
+         *    String str = formatValue(val);
+         */
+        // TODO: fix scale
+        double scale = 100000;
+        double startLat = ModelledCRS.yToLatitude(start.getY() / scale);
+        double startLon = ModelledCRS.xToLongitude(start.getX() / scale);
+        
+        double endLat = ModelledCRS.yToLatitude(end.getY() / scale);
+        double endLon = ModelledCRS.xToLongitude(end.getX() / scale);
+        
+        double[] startCoords = new double[] { startLon, startLat };
+        double[] endCoords = new double[] { endLon, endLat };
         
         DNEdgeBuilder builder = new DNEdgeBuilder(diagramResource, diagram);
         Simantics.getSession().asyncRequest(new WriteRequest() {
             
             @Override
             public void perform(WriteGraph graph) throws DatabaseException {
-                builder.create(graph, startCoords, endCoords, padding);
+                builder.create(graph, startCoords, endCoords, padding / scale);
             }
         });
         
index 27de17e921f0ce9bb765a9f022075eee8504f9d3..12caba477724d4af843abc1e43413ab1536d0698 100644 (file)
@@ -14,6 +14,7 @@ import org.simantics.db.exception.DatabaseException;
 import org.simantics.diagram.elements.ElementTransforms;
 import org.simantics.diagram.elements.ElementTransforms.TransformedObject;
 import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.district.network.ModelledCRS;
 import org.simantics.district.network.ontology.DistrictNetworkResource;
 import org.simantics.g2d.canvas.Hints;
 import org.simantics.g2d.diagram.participant.pointertool.TranslateMode;
@@ -49,8 +50,16 @@ public class DNTranslateMode extends TranslateMode {
                             Resource res = (Resource) obj;
                             AffineTransform at = ElementUtils.getLocalTransform(e, new AffineTransform());
                             if (graph.isInstanceOf(res, DN.Vertex)) {
+                                
+                                double x = at.getTranslateX();
+                                double y = at.getTranslateY();
+                                // TODO: Fix scale!
+                                double scale = 100000;
+                                double lat = ModelledCRS.yToLatitude(y / scale);
+                                double lon = ModelledCRS.xToLongitude(x / scale);
+                                
                                 // write to db
-                                double[] coords = new double[] { at.getTranslateX(), at.getTranslateY() };
+                                double[] coords = new double[] { lon, lat };
                                 graph.claimLiteral(res, DIA.HasLocation, coords);
                             } else {
                                 // fallback to normal HasTransforms
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/MapRulerPainter.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/MapRulerPainter.java
new file mode 100644 (file)
index 0000000..d614610
--- /dev/null
@@ -0,0 +1,12 @@
+package org.simantics.district.network.ui.participants;
+
+import org.simantics.district.network.ui.nodes.MapRulerNode;
+import org.simantics.g2d.participant.RulerPainter;
+
+public class MapRulerPainter extends RulerPainter {
+
+    @Override
+    protected Class<MapRulerNode> getNodeClass() {
+        return MapRulerNode.class;
+    }
+}
index 60214a423b1380a93ec6ff9c93177d12fcd85ea2..51580d23a94406f23aee34c0c0bc49aff7c35d09 100644 (file)
@@ -10,5 +10,6 @@ Require-Bundle: org.simantics.db,
  org.simantics.diagram.ontology;bundle-version="2.2.0",
  org.simantics.db.common,
  org.simantics.db.layer0,
- org.simantics.district.maps
+ org.simantics.district.maps,
+ org.simantics.district.geotools;bundle-version="1.0.0"
 Export-Package: org.simantics.district.network
index ed1225138cbd09f84e39c286c68137e487be233e..8025c9adea127991bf78d7f98ff3b0644ec6998e 100644 (file)
@@ -1,4 +1,10 @@
 import "Simantics/DB"
 
 importJava "org.simantics.district.network.DistrictNetworkUtil" where
-    calculateDistance :: Resource -> Resource -> <ReadGraph> Double
\ No newline at end of file
+    calculateDistance :: Resource -> Resource -> <ReadGraph> Double
+
+importJava "org.simantics.district.network.ModelledCRS" where
+    xToLongitude :: Double -> <Proc> Double
+    yToLatitude :: Double -> <Proc> Double
+    longitudeToX :: Double -> <Proc> Double
+    latitudeToY :: Double -> <Proc> Double
\ No newline at end of file
index fd129ff095e3d86b5a92b0db0b0ab5d44819ef8c..23e68f2b273453c7a2636f2331c2bd417028447c 100644 (file)
@@ -16,15 +16,45 @@ public class ModelledCRS implements CRS {
     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();
+        calculator.setStartingGeographicPoint(start[0], start[1]);
+        calculator.setDestinationGeographicPoint(end[0], end[1]);
+        double dist = calculator.getOrthodromicDistance();
+        return dist;
     }
 
+    
+    // TODO: these only work with Spherical Mercator
+    public static double xToLongitude(double x) {
+        return x;
+    }
+    
+    public static double yToLatitude(double y) {
+        double rad = Math.toRadians(y);
+        double sinh = Math.sinh(rad);
+        double atan = Math.atan(sinh);
+        double finald = Math.toDegrees(atan);
+        return finald;
+    }
+    
+    public static double longitudeToX(double lon) {
+        return lon;
+    }
+    
+    private static double asinh(double x) {
+        return Math.log(x + Math.sqrt(x*x + 1.0));
+    }
+    
+    public static double latitudeToY(double lat) {
+        double frad = Math.toRadians(lat);
+        double ftan = Math.tan(frad);
+        double fsin = asinh(ftan);
+        double f = Math.toDegrees(fsin);
+        return f;
+    }
 }
index 645dbda925698ca5e2443f3955ec83d6fd58e09b..548daf310fe663ab277a96f2185d6a40c888d6e3 100644 (file)
@@ -118,7 +118,7 @@ public class MapsServerPreferencePage extends FieldEditorPreferencePage implemen
             
             @Override
             public void widgetSelected(SelectionEvent e) {
-                E4WorkbenchUtils.showInSystemExplorer("");
+//                E4WorkbenchUtils.showInSystemExplorer("");
             }
         });