From 1bc60c2213f9b3fc7b4d935ba9afda2b767290e5 Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Fri, 28 Apr 2017 16:02:42 +0300 Subject: [PATCH] Final push of district changes refs #6958 Change-Id: I5a6429a9bde4528f2fbc402c3483c2bea7789f70 --- .../META-INF/MANIFEST.MF | 4 +- .../district/imports/ui/CSVImportModel.java | 163 +++---- .../district/imports/ui/CSVImportWizard.java | 99 +++-- .../imports/ui/CSVImportWizardPage.java | 398 ++++++++++-------- .../META-INF/MANIFEST.MF | 3 +- .../district/imports/DistrictImportUtils.java | 331 ++++++++------- org.simantics.district.maps/.classpath | 11 - .../META-INF/MANIFEST.MF | 20 +- org.simantics.district.maps/build.properties | 13 - .../graph.tg | Bin 12092 -> 12195 bytes .../graph/DistrictNetwork.pgraph | 22 +- .../ontology/DistrictNetworkResource.java | 24 +- .../META-INF/MANIFEST.MF | 3 +- .../fragment.e4xmi | 9 - .../network/ui/DistrictDiagramViewer.java | 10 + .../DistrictNetworkAdditionalColor.java | 42 ++ .../adapters/DistrictNetworkEdgeElement.java | 7 +- .../DistrictNetworkEdgeElementFactory.java | 21 +- .../DistrictNetworkVertexElement.java | 25 +- .../DistrictNetworkVertexElementFactory.java | 16 +- .../ui/contributions/RunMappingHandler.java | 56 --- .../network/ui/function/Functions.java | 4 + .../ui/nodes/DistrictNetworkEdgeNode.java | 12 +- .../ui/nodes/DistrictNetworkVertexNode.java | 18 +- .../network/ui/nodes/MapRulerNode.java | 24 ++ .../network/ui/nodes/NetworkDrawingNode.java | 23 +- .../ui/participants/DNTranslateMode.java | 11 +- .../ui/participants/MapRulerPainter.java | 12 + .../META-INF/MANIFEST.MF | 3 +- .../scl/Simantics/District.scl | 8 +- .../district/network/ModelledCRS.java | 38 +- .../ui/prefs/MapsServerPreferencePage.java | 2 +- 32 files changed, 831 insertions(+), 601 deletions(-) create mode 100644 org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkAdditionalColor.java delete mode 100644 org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/RunMappingHandler.java create mode 100644 org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/MapRulerNode.java create mode 100644 org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/MapRulerPainter.java diff --git a/org.simantics.district.imports.ui/META-INF/MANIFEST.MF b/org.simantics.district.imports.ui/META-INF/MANIFEST.MF index fb65af54..48019c70 100644 --- a/org.simantics.district.imports.ui/META-INF/MANIFEST.MF +++ b/org.simantics.district.imports.ui/META-INF/MANIFEST.MF @@ -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 diff --git a/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportModel.java b/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportModel.java index 50c427c4..1521a926 100644 --- a/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportModel.java +++ b/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportModel.java @@ -1,73 +1,90 @@ -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.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 delimiters; - - 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 Map> getHeaderAndRows(int amount) throws IOException { - if (source != null) - return DistrictImportUtils.readCSVHeaderAndRows(source, delimiter, read, amount); - else - return Collections.emptyMap(); - } - - public Map getHeader() throws IOException { - Map 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> readRows(int amount) throws IOException { - if (source != null) - return DistrictImportUtils.readRows(source, delimiter, read, amount); - else - return Collections.emptyList(); - } -} +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 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 getRows(int amount) throws IOException { + if (source != null) + return DistrictImportUtils.readRows(source, delimiter, amount); + else + return Collections.emptyList(); + } + + public Map> getHeaderAndRows(int amount) throws IOException { + if (source != null) + return DistrictImportUtils.readCSVHeaderAndRows(source, delimiter, read, amount); + else + return Collections.emptyMap(); + } + + public Map getHeader() throws IOException { + Map 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> 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; + } +} diff --git a/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizard.java b/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizard.java index 97fa990a..7a29e750 100644 --- a/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizard.java +++ b/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizard.java @@ -1,38 +1,61 @@ -package org.simantics.district.imports.ui; - -import java.io.IOException; -import java.nio.file.Path; - -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.ui.IImportWizard; -import org.eclipse.ui.IWorkbench; -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() { - Path csvFile = model.getSource(); - try { - DistrictImportUtils.importCSVAsLayer(csvFile); - } catch (IOException e) { - e.printStackTrace(); - } - return false; - } - -} +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 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; + } + +} diff --git a/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizardPage.java b/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizardPage.java index 71017b32..e4a0612a 100644 --- a/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizardPage.java +++ b/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizardPage.java @@ -1,168 +1,230 @@ -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.Collections; -import java.util.List; -import java.util.Map; - -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.layout.TableColumnLayout; -import org.eclipse.jface.layout.TreeColumnLayout; -import org.eclipse.jface.viewers.ColumnViewerToolTipSupport; -import org.eclipse.jface.viewers.ColumnWeightData; -import org.eclipse.jface.viewers.IContentProvider; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.jface.viewers.Viewer; -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.GridData; -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.Layout; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.swt.widgets.TableItem; -import org.simantics.district.imports.DistrictImportUtils.CSVHeader; -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 delimiterCombo; - private TableColumnLayout tableColumnLayout; - private TableViewer tableViewer; - private Composite tableComposite; - - 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); - - 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); - - updateHeaders(); - - setControl(composite); - - - - setPageComplete(false); - } - - @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 { - Map> headerAndValues = model.getHeaderAndRows(5); - - int coo = headerTable.getColumns().length; - int count = headerTable.getColumnCount(); - - for (Map.Entry> 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()); - } - } - -} +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 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> headerAndValues = model.getHeaderAndRows(5); +// +// int coo = headerTable.getColumns().length; +// int count = headerTable.getColumnCount(); +// +// for (Map.Entry> 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()); + } + } + +} diff --git a/org.simantics.district.imports/META-INF/MANIFEST.MF b/org.simantics.district.imports/META-INF/MANIFEST.MF index 50cc5d26..b04e9223 100644 --- a/org.simantics.district.imports/META-INF/MANIFEST.MF +++ b/org.simantics.district.imports/META-INF/MANIFEST.MF @@ -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, . diff --git a/org.simantics.district.imports/src/org/simantics/district/imports/DistrictImportUtils.java b/org.simantics.district.imports/src/org/simantics/district/imports/DistrictImportUtils.java index 7c0d998c..1ad5b9a9 100644 --- a/org.simantics.district.imports/src/org/simantics/district/imports/DistrictImportUtils.java +++ b/org.simantics.district.imports/src/org/simantics/district/imports/DistrictImportUtils.java @@ -1,156 +1,175 @@ -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 header = parser.getHeaderMap(); - System.out.println(header); - } - return null; - } - - public static Map readCSVHeader(Path source, char delimiter, boolean firstAsHeader) throws IOException { - return readCSVHeader(source, CSVFormat.newFormat(delimiter), firstAsHeader); - } - - public static Map 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 getSupportedCSVDelimiterFormats() { - Map delimiters = new HashMap<>(); - delimiters.put("COMMA", ','); - delimiters.put("SEMICOMMA", ';'); - return delimiters; - } - - public static List> readRows(Path source, char delimiter, boolean firstAsHeader, int amount) throws IOException { - return readRows(source, CSVFormat.newFormat(delimiter), firstAsHeader, amount); - } - - public static List> 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> results = new ArrayList<>(amount); - Iterator iter = parser.iterator(); - while (start < amount && iter.hasNext()) { - CSVRecord record = iter.next(); - results.add(record.toMap()); - start++; - } - return results; - } - } - - - public static Map> readCSVHeaderAndRows(Path source, char delimiter, boolean firstAsHeader, int amount) throws IOException { - Map> results = new HashMap<>(); - CSVFormat format = CSVFormat.newFormat(delimiter); - if (firstAsHeader) - format = format.withFirstRecordAsHeader(); - try (CSVParser parser = format.parse(Files.newBufferedReader(source))) { - Map 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 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 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; - } - } - -} +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 header = parser.getHeaderMap(); + System.out.println(header); + } + return null; + } + + public static Map readCSVHeader(Path source, char delimiter, boolean firstAsHeader) throws IOException { + return readCSVHeader(source, CSVFormat.newFormat(delimiter), firstAsHeader); + } + + public static Map 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 getSupportedCSVDelimiterFormats() { + Map delimiters = new HashMap<>(); + delimiters.put("COMMA", ','); + delimiters.put("SEMICOMMA", ';'); + return delimiters; + } + + public static List> readRows(Path source, char delimiter, boolean firstAsHeader, int amount) throws IOException { + return readRows(source, CSVFormat.newFormat(delimiter), firstAsHeader, amount); + } + + public static List> 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> results = new ArrayList<>(amount); + Iterator iter = parser.iterator(); + while (start < amount && iter.hasNext()) { + CSVRecord record = iter.next(); + results.add(record.toMap()); + start++; + } + return results; + } + } + + public static List readRows(Path source, char delim, int rowAmount) throws IOException { + List results = new ArrayList<>(); + CSVFormat format = CSVFormat.newFormat(delim); + try (CSVParser parser = format.parse(Files.newBufferedReader(source))) { + Iterator 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> readCSVHeaderAndRows(Path source, char delimiter, boolean firstAsHeader, int amount) throws IOException { + Map> results = new HashMap<>(); + CSVFormat format = CSVFormat.newFormat(delimiter); + if (firstAsHeader) + format = format.withFirstRecordAsHeader(); + try (CSVParser parser = format.parse(Files.newBufferedReader(source))) { + Map 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 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 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; + } + } + +} diff --git a/org.simantics.district.maps/.classpath b/org.simantics.district.maps/.classpath index 0e4c9142..751c8f2e 100644 --- a/org.simantics.district.maps/.classpath +++ b/org.simantics.district.maps/.classpath @@ -1,17 +1,6 @@ - - - - - - - - - - - diff --git a/org.simantics.district.maps/META-INF/MANIFEST.MF b/org.simantics.district.maps/META-INF/MANIFEST.MF index 9754d757..0ea8a6e6 100644 --- a/org.simantics.district.maps/META-INF/MANIFEST.MF +++ b/org.simantics.district.maps/META-INF/MANIFEST.MF @@ -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 diff --git a/org.simantics.district.maps/build.properties b/org.simantics.district.maps/build.properties index 5fd55626..98bec33a 100644 --- a/org.simantics.district.maps/build.properties +++ b/org.simantics.district.maps/build.properties @@ -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 diff --git a/org.simantics.district.network.ontology/graph.tg b/org.simantics.district.network.ontology/graph.tg index 6737f9afa6f4e786bede66c9973c396fddd9bfb8..ad5ff83b613216efd7c0fdfb2ce87698582b5da9 100644 GIT binary patch literal 12195 zcmeHNiGNg8magoTkd-7T$Py#CLLgyD0w^RTlG2cbY^camsd|J8m8wt+A>u;gf{I8t zA_|D2qK$&svWlcz!3|Uv1w^H3Z50>LVboE(aUA=6=iQUsJeZz;VCwffRrmYOa?jmg zRo$4zfU{+$&1Q=rvBlv{y<(CAM$jJ)xQucBurCw|I>DG5GJHXg-xrJrj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!|FVu7etzucpHKDKy85B@jZZCjY4D)h+K-R^@bEpgJ#24Y z)bZ}Mwv3MaUy6pO4cStBPw9vkme&sKX#e~_+eRNbGIQyw?1d4u9&8b}Y}(*Getgt# zW0%bx`Dowmi{GSa9^oh{FWy)*Yata|dEq6iKjSmh|3{>FoR<@82}RrKstn!P!2f3S zms*S$SNvjlSB*6_Wb{}Zy~*qUug6MH;Br^D3%=d2$KoKw3lFvS2(wRt(<8ciHX#%V0%HGdd3~tXpVKp?a>&}(P!LR zj0GL@zur$wX0Nl}xa7OQ(PzJL$+za>^&6Lb<0!t{jZ3~r7jL<7$rr4c)NWk%;3jpy zn8%k~dhkD^T^Et~5@L_;_qP(@+(W;c)}IKhhBWn!A5YZ4DGK8W7`Ugxcwz=lQrNC= zg2IUk+Z2u`97PhVFnsYUG(YG)m6z^Vx>T)Qv39GwH(BbG&7$SZmkzTmw{qm_83h{4 cfo$5J!${UVX|H6RcB5k_6R| : L0.Ontology DN.Layer -- DN.Mapping.ComponentType - >-- DN.Mapping.EdgeMapping.Bidirectional --> L0.Boolean -- DN.Mapping.EdgeMapping.LengthAttribute --> L0.String -- DN.Mapping.EdgeMapping.DiameterAttribute --> L0.String -- DN.Mapping.Terminals diff --git a/org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java b/org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java index 678f344b..8ac781ba 100644 --- a/org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java +++ b/org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java @@ -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) { diff --git a/org.simantics.district.network.ui/META-INF/MANIFEST.MF b/org.simantics.district.network.ui/META-INF/MANIFEST.MF index 49df92f5..b3aef540 100644 --- a/org.simantics.district.network.ui/META-INF/MANIFEST.MF +++ b/org.simantics.district.network.ui/META-INF/MANIFEST.MF @@ -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, diff --git a/org.simantics.district.network.ui/fragment.e4xmi b/org.simantics.district.network.ui/fragment.e4xmi index 75ef8fa7..f0c705c8 100644 --- a/org.simantics.district.network.ui/fragment.e4xmi +++ b/org.simantics.district.network.ui/fragment.e4xmi @@ -6,7 +6,6 @@ - @@ -21,15 +20,7 @@ - - - - - - - - diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java index 57480180..486f8759 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java @@ -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 index 00000000..ef3b10c9 --- /dev/null +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkAdditionalColor.java @@ -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 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; + } + +} diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkEdgeElement.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkEdgeElement.java index 12f26182..cf10ffab 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkEdgeElement.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkEdgeElement.java @@ -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); } } diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkEdgeElementFactory.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkEdgeElementFactory.java index 63590990..2899a0e7 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkEdgeElementFactory.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkEdgeElementFactory.java @@ -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); diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkVertexElement.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkVertexElement.java index 3e64bc31..24f8459d 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkVertexElement.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkVertexElement.java @@ -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; } diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkVertexElementFactory.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkVertexElementFactory.java index 976abd48..6fa19c42 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkVertexElementFactory.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkVertexElementFactory.java @@ -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 index 5ae0c0d0..00000000 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/RunMappingHandler.java +++ /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(); - } -} diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/function/Functions.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/function/Functions.java index f421c673..4fc40dbb 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/function/Functions.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/function/Functions.java @@ -445,4 +445,8 @@ public class Functions { } }); } + + public static void getDistrictDiagrams(ReadGraph graph) { + + } } diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java index 408625f5..11d883e9 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java @@ -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; + } + } diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java index 8dcd5183..86c71857 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java @@ -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 index 00000000..078c8ebb --- /dev/null +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/MapRulerNode.java @@ -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); + } + +} diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/NetworkDrawingNode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/NetworkDrawingNode.java index 14744234..13bd2cbe 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/NetworkDrawingNode.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/NetworkDrawingNode.java @@ -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); } }); diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DNTranslateMode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DNTranslateMode.java index 27de17e9..12caba47 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DNTranslateMode.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DNTranslateMode.java @@ -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 index 00000000..d614610f --- /dev/null +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/MapRulerPainter.java @@ -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 getNodeClass() { + return MapRulerNode.class; + } +} diff --git a/org.simantics.district.network/META-INF/MANIFEST.MF b/org.simantics.district.network/META-INF/MANIFEST.MF index 60214a42..51580d23 100644 --- a/org.simantics.district.network/META-INF/MANIFEST.MF +++ b/org.simantics.district.network/META-INF/MANIFEST.MF @@ -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 diff --git a/org.simantics.district.network/scl/Simantics/District.scl b/org.simantics.district.network/scl/Simantics/District.scl index ed122513..8025c9ad 100644 --- a/org.simantics.district.network/scl/Simantics/District.scl +++ b/org.simantics.district.network/scl/Simantics/District.scl @@ -1,4 +1,10 @@ import "Simantics/DB" importJava "org.simantics.district.network.DistrictNetworkUtil" where - calculateDistance :: Resource -> Resource -> Double \ No newline at end of file + calculateDistance :: Resource -> Resource -> Double + +importJava "org.simantics.district.network.ModelledCRS" where + xToLongitude :: Double -> Double + yToLatitude :: Double -> Double + longitudeToX :: Double -> Double + latitudeToY :: Double -> Double \ No newline at end of file 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 index fd129ff0..23e68f2b 100644 --- a/org.simantics.district.network/src/org/simantics/district/network/ModelledCRS.java +++ b/org.simantics.district.network/src/org/simantics/district/network/ModelledCRS.java @@ -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; + } } diff --git a/org.simantics.maps.server.ui/src/org/simantics/maps/server/ui/prefs/MapsServerPreferencePage.java b/org.simantics.maps.server.ui/src/org/simantics/maps/server/ui/prefs/MapsServerPreferencePage.java index 645dbda9..548daf31 100644 --- a/org.simantics.maps.server.ui/src/org/simantics/maps/server/ui/prefs/MapsServerPreferencePage.java +++ b/org.simantics.maps.server.ui/src/org/simantics/maps/server/ui/prefs/MapsServerPreferencePage.java @@ -118,7 +118,7 @@ public class MapsServerPreferencePage extends FieldEditorPreferencePage implemen @Override public void widgetSelected(SelectionEvent e) { - E4WorkbenchUtils.showInSystemExplorer(""); +// E4WorkbenchUtils.showInSystemExplorer(""); } }); -- 2.47.1