From: jsimomaa Date: Fri, 28 Apr 2017 13:02:42 +0000 (+0300) Subject: Final push of district changes X-Git-Tag: v1.31.0~8 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=1bc60c2213f9b3fc7b4d935ba9afda2b767290e5;p=simantics%2Fdistrict.git Final push of district changes refs #6958 Change-Id: I5a6429a9bde4528f2fbc402c3483c2bea7789f70 --- 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 6737f9af..ad5ff83b 100644 Binary files a/org.simantics.district.network.ontology/graph.tg and b/org.simantics.district.network.ontology/graph.tg differ diff --git a/org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph b/org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph index 5e17f658..a4144a80 100644 --- a/org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph +++ b/org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph @@ -15,16 +15,11 @@ DN = : 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(""); } });