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
-package org.simantics.district.imports.ui;\r
-\r
-import java.io.IOException;\r
-import java.nio.file.Path;\r
-import java.util.Collections;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import org.simantics.district.imports.DistrictImportUtils;\r
-import org.simantics.district.imports.DistrictImportUtils.CSVHeader;\r
-\r
-public class CSVImportModel {\r
-\r
- private Path source;\r
- private char delimiter;\r
- private boolean read;\r
- private Map<String, Character> delimiters;\r
-\r
- public CSVImportModel() {\r
- delimiters = DistrictImportUtils.getSupportedCSVDelimiterFormats();\r
- }\r
- \r
- public void setSource(Path source) {\r
- this.source = source;\r
- }\r
-\r
- public void setDelimiter(char delimiter) {\r
- this.delimiter = delimiter;\r
- }\r
-\r
- public void setReadFirstAsHeader(boolean read) {\r
- this.read = read;\r
- }\r
-\r
- public Path getSource() {\r
- return source;\r
- }\r
-\r
- public Map<CSVHeader, List<String>> getHeaderAndRows(int amount) throws IOException {\r
- if (source != null)\r
- return DistrictImportUtils.readCSVHeaderAndRows(source, delimiter, read, amount);\r
- else\r
- return Collections.emptyMap();\r
- }\r
- \r
- public Map<String, Integer> getHeader() throws IOException {\r
- Map<String, Integer> header = null;\r
- if (source != null)\r
- header = DistrictImportUtils.readCSVHeader(source, delimiter, read);\r
- if (header == null)\r
- header = Collections.emptyMap();\r
- return header;\r
- }\r
-\r
- public boolean getReadFirstAsHeader() {\r
- return read;\r
- }\r
-\r
- public String[] getDelimiterFormats() {\r
- return delimiters.keySet().toArray(new String[delimiters.size()]);\r
- }\r
-\r
- public void setDelimiterByLabel(String item) {\r
- setDelimiter(delimiters.get(item));\r
- }\r
-\r
- public List<Map<String, String>> readRows(int amount) throws IOException {\r
- if (source != null)\r
- return DistrictImportUtils.readRows(source, delimiter, read, amount);\r
- else\r
- return Collections.emptyList();\r
- }\r
-}\r
+package org.simantics.district.imports.ui;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.csv.CSVRecord;
+import org.simantics.district.imports.DistrictImportUtils;
+import org.simantics.district.imports.DistrictImportUtils.CSVHeader;
+
+public class CSVImportModel {
+
+ private Path source;
+ private char delimiter;
+ private boolean read;
+ private Map<String, Character> delimiters;
+ private Path wktFile;
+
+ public CSVImportModel() {
+ delimiters = DistrictImportUtils.getSupportedCSVDelimiterFormats();
+ }
+
+ public void setSource(Path source) {
+ this.source = source;
+ }
+
+ public void setDelimiter(char delimiter) {
+ this.delimiter = delimiter;
+ }
+
+ public void setReadFirstAsHeader(boolean read) {
+ this.read = read;
+ }
+
+ public Path getSource() {
+ return source;
+ }
+
+ public List<CSVRecord> getRows(int amount) throws IOException {
+ if (source != null)
+ return DistrictImportUtils.readRows(source, delimiter, amount);
+ else
+ return Collections.emptyList();
+ }
+
+ public Map<CSVHeader, List<String>> getHeaderAndRows(int amount) throws IOException {
+ if (source != null)
+ return DistrictImportUtils.readCSVHeaderAndRows(source, delimiter, read, amount);
+ else
+ return Collections.emptyMap();
+ }
+
+ public Map<String, Integer> getHeader() throws IOException {
+ Map<String, Integer> header = null;
+ if (source != null)
+ header = DistrictImportUtils.readCSVHeader(source, delimiter, read);
+ if (header == null)
+ header = Collections.emptyMap();
+ return header;
+ }
+
+ public boolean getReadFirstAsHeader() {
+ return read;
+ }
+
+ public String[] getDelimiterFormats() {
+ return delimiters.keySet().toArray(new String[delimiters.size()]);
+ }
+
+ public void setDelimiterByLabel(String item) {
+ setDelimiter(delimiters.get(item));
+ }
+
+ public List<Map<String, String>> readRows(int amount) throws IOException {
+ if (source != null)
+ return DistrictImportUtils.readRows(source, delimiter, read, amount);
+ else
+ return Collections.emptyList();
+ }
+
+ public char getDelimiter() {
+ return delimiter;
+ }
+
+ public Path getWKTFile() {
+ return wktFile;
+ }
+}
-package org.simantics.district.imports.ui;\r
-\r
-import java.io.IOException;\r
-import java.nio.file.Path;\r
-\r
-import org.eclipse.jface.viewers.IStructuredSelection;\r
-import org.eclipse.jface.wizard.Wizard;\r
-import org.eclipse.ui.IImportWizard;\r
-import org.eclipse.ui.IWorkbench;\r
-import org.simantics.district.imports.DistrictImportUtils;\r
-\r
-public class CSVImportWizard extends Wizard implements IImportWizard {\r
-\r
- private CSVImportModel model;\r
- \r
- public CSVImportWizard() {\r
- setWindowTitle("Import CSV data");\r
- }\r
- \r
- \r
- @Override\r
- public void init(IWorkbench workbench, IStructuredSelection selection) {\r
- model = new CSVImportModel();\r
- addPage(new CSVImportWizardPage(model));\r
- }\r
- \r
- @Override\r
- public boolean performFinish() {\r
- Path csvFile = model.getSource();\r
- try {\r
- DistrictImportUtils.importCSVAsLayer(csvFile);\r
- } catch (IOException e) {\r
- e.printStackTrace();\r
- }\r
- return false;\r
- }\r
-\r
-}\r
+package org.simantics.district.imports.ui;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.List;
+
+import org.apache.commons.csv.CSVRecord;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.IImportWizard;
+import org.eclipse.ui.IWorkbench;
+import org.geotools.referencing.CRS;
+import org.opengis.referencing.FactoryException;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.simantics.district.imports.DistrictImportUtils;
+
+public class CSVImportWizard extends Wizard implements IImportWizard {
+
+ private CSVImportModel model;
+
+ public CSVImportWizard() {
+ setWindowTitle("Import CSV data");
+ }
+
+
+ @Override
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ model = new CSVImportModel();
+ addPage(new CSVImportWizardPage(model));
+ }
+
+ @Override
+ public boolean performFinish() {
+ try {
+
+
+ Path csvFile = model.getSource();
+ char delim = model.getDelimiter();
+
+ List<CSVRecord> rows = DistrictImportUtils.readRows(csvFile, delim, -1);
+
+ Path wktFile = model.getWKTFile();
+
+ try {
+
+
+ CoordinateReferenceSystem crs = CRS.decode(null);
+ } catch (FactoryException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+
+ DistrictImportUtils.importCSVAsLayer(csvFile);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return false;
+ }
+
+}
-package org.simantics.district.imports.ui;\r
-\r
-import java.io.IOException;\r
-import java.nio.file.Files;\r
-import java.nio.file.Path;\r
-import java.nio.file.Paths;\r
-import java.util.Collections;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import org.eclipse.jface.layout.GridDataFactory;\r
-import org.eclipse.jface.layout.TableColumnLayout;\r
-import org.eclipse.jface.layout.TreeColumnLayout;\r
-import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;\r
-import org.eclipse.jface.viewers.ColumnWeightData;\r
-import org.eclipse.jface.viewers.IContentProvider;\r
-import org.eclipse.jface.viewers.TableViewer;\r
-import org.eclipse.jface.viewers.TreeViewer;\r
-import org.eclipse.jface.viewers.Viewer;\r
-import org.eclipse.jface.wizard.WizardPage;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.events.SelectionEvent;\r
-import org.eclipse.swt.events.SelectionListener;\r
-import org.eclipse.swt.layout.GridData;\r
-import org.eclipse.swt.layout.GridLayout;\r
-import org.eclipse.swt.widgets.Button;\r
-import org.eclipse.swt.widgets.Combo;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Layout;\r
-import org.eclipse.swt.widgets.Table;\r
-import org.eclipse.swt.widgets.TableColumn;\r
-import org.eclipse.swt.widgets.TableItem;\r
-import org.simantics.district.imports.DistrictImportUtils.CSVHeader;\r
-import org.simantics.utils.ui.widgets.FileOrDirectorySelectionWidget;\r
-import org.simantics.utils.ui.widgets.FileSelectionListener;\r
-import org.simantics.utils.ui.widgets.FileSelectionWidget;\r
-\r
-public class CSVImportWizardPage extends WizardPage implements FileSelectionListener {\r
-\r
- private CSVImportModel model;\r
- private FileSelectionWidget csvSelection;\r
- private Table headerTable;\r
- private Button firstAsHeader;\r
- private Combo delimiterCombo;\r
- private TableColumnLayout tableColumnLayout;\r
- private TableViewer tableViewer;\r
- private Composite tableComposite;\r
-\r
- protected CSVImportWizardPage(CSVImportModel model) {\r
- super("Import CSV Data");\r
- this.model = model;\r
- setMessage("Select CSV file to import");\r
- }\r
-\r
- @Override\r
- public void createControl(Composite parent) {\r
- Composite composite = new Composite(parent, SWT.NONE);\r
- composite.setLayout(new GridLayout(1,false));\r
- GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(composite);\r
- \r
- csvSelection = new FileSelectionWidget(composite, "CSV file", SWT.OPEN);\r
- csvSelection.addListener(this);\r
- \r
- delimiterCombo = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY);\r
- delimiterCombo.setItems(model.getDelimiterFormats());\r
- delimiterCombo.addSelectionListener(new SelectionListener() {\r
- \r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- model.setDelimiterByLabel(delimiterCombo.getItem(delimiterCombo.getSelectionIndex()));\r
- updateHeaders();\r
- }\r
- \r
- @Override\r
- public void widgetDefaultSelected(SelectionEvent e) {\r
- \r
- }\r
- });\r
- \r
- firstAsHeader = new Button(composite, SWT.CHECK);\r
- firstAsHeader.setText("Read first row as header");\r
- firstAsHeader.setSelection(model.getReadFirstAsHeader());\r
- firstAsHeader.addSelectionListener(new SelectionListener() {\r
- \r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- model.setReadFirstAsHeader(firstAsHeader.getSelection());\r
- updateHeaders();\r
- }\r
- \r
- @Override\r
- public void widgetDefaultSelected(SelectionEvent e) {\r
- \r
- }\r
- });\r
- \r
- \r
- tableComposite = new Composite(composite, SWT.BORDER);\r
- tableColumnLayout = new TableColumnLayout();\r
- tableComposite.setLayout(tableColumnLayout);\r
-\r
- updateHeaders();\r
- \r
- setControl(composite);\r
- \r
- \r
- \r
- setPageComplete(false);\r
- }\r
-\r
- @Override\r
- public void fileSelected(FileOrDirectorySelectionWidget source, String[] filename) {\r
- String[] selection = csvSelection.getFilename();\r
- if (selection != null && selection.length > 0) {\r
- Path csvFile = Paths.get(selection[0]);\r
- if (!Files.exists(csvFile)) {\r
- setErrorMessage("File " + csvFile.toAbsolutePath() + " does not exist");\r
- } else {\r
- model.setSource(csvFile);\r
- updateHeaders();\r
- setPageComplete(true);\r
- }\r
- } else {\r
- setPageComplete(false);\r
- }\r
- }\r
-\r
- private void updateHeaders() {\r
- if (headerTable != null)\r
- headerTable.dispose();\r
- headerTable = new Table(tableComposite, SWT.NONE);\r
- headerTable.setHeaderVisible(true);\r
- headerTable.setLinesVisible(true);\r
- GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(tableComposite);\r
- for (int i = 0; i < headerTable.getColumns().length; i++) {\r
- TableColumn column = headerTable.getColumns()[i];\r
- column.dispose();\r
- }\r
- for (int i = 0; i < headerTable.getItemCount(); i++) {\r
- TableItem item = headerTable.getItem(i);\r
- item.dispose();\r
- }\r
- try {\r
- Map<CSVHeader, List<String>> headerAndValues = model.getHeaderAndRows(5);\r
- \r
- int coo = headerTable.getColumns().length;\r
- int count = headerTable.getColumnCount();\r
- \r
- for (Map.Entry<CSVHeader, List<String>> entr : headerAndValues.entrySet()) {\r
- CSVHeader he = entr.getKey();\r
- int index = he.getIndex();\r
- TableColumn headerCol = new TableColumn(headerTable, SWT.NONE);\r
- headerCol.setText(he.getHeader());\r
- \r
- tableColumnLayout.setColumnData(headerCol, new ColumnWeightData(10));\r
- headerCol.pack();\r
- \r
- for (String val : entr.getValue()) {\r
- TableItem item = new TableItem(headerTable, SWT.NONE);\r
- item.setText(val);\r
- }\r
- }\r
- } catch (IOException e) {\r
- setErrorMessage(e.getMessage());\r
- }\r
- }\r
-\r
-}\r
+package org.simantics.district.imports.ui;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+
+import org.apache.commons.csv.CSVRecord;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.TableColumnLayout;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+import org.simantics.district.network.ui.function.Functions;
+import org.simantics.utils.ui.widgets.FileOrDirectorySelectionWidget;
+import org.simantics.utils.ui.widgets.FileSelectionListener;
+import org.simantics.utils.ui.widgets.FileSelectionWidget;
+
+
+public class CSVImportWizardPage extends WizardPage implements FileSelectionListener {
+
+ private CSVImportModel model;
+ private FileSelectionWidget csvSelection;
+ private Table headerTable;
+ private Button firstAsHeader;
+
+ private Combo diagramCombo;
+
+
+ private Combo delimiterCombo;
+ private Combo delimiterdCombo;
+ private TableColumnLayout tableColumnLayout;
+ private TableViewer tableViewer;
+ private Composite tableComposite;
+ private FileSelectionWidget wktFileSelection;
+
+ private Path wktFile;
+
+ protected CSVImportWizardPage(CSVImportModel model) {
+ super("Import CSV Data");
+ this.model = model;
+ setMessage("Select CSV file to import");
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setLayout(new GridLayout(1,false));
+ GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(composite);
+
+ diagramCombo = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
+ diagramCombo.setItems(getDistrictDiagrams());
+
+
+ csvSelection = new FileSelectionWidget(composite, "CSV file", SWT.OPEN);
+ csvSelection.addListener(this);
+
+ delimiterCombo = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
+ delimiterCombo.setItems(model.getDelimiterFormats());
+ delimiterCombo.addSelectionListener(new SelectionListener() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ model.setDelimiterByLabel(delimiterCombo.getItem(delimiterCombo.getSelectionIndex()));
+ updateHeaders();
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+
+ }
+ });
+
+ firstAsHeader = new Button(composite, SWT.CHECK);
+ firstAsHeader.setText("Read first row as header");
+ firstAsHeader.setSelection(model.getReadFirstAsHeader());
+ firstAsHeader.addSelectionListener(new SelectionListener() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ model.setReadFirstAsHeader(firstAsHeader.getSelection());
+ updateHeaders();
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+
+ }
+ });
+
+
+ tableComposite = new Composite(composite, SWT.BORDER);
+ tableColumnLayout = new TableColumnLayout();
+ tableComposite.setLayout(tableColumnLayout);
+
+
+
+ wktFileSelection = new FileSelectionWidget(composite, "WKT file", SWT.OPEN);
+ wktFileSelection.addListener(new FileSelectionListener() {
+
+ @Override
+ public void fileSelected(FileOrDirectorySelectionWidget source, String[] filename) {
+ String[] selection = wktFileSelection.getFilename();
+ if (selection != null && selection.length > 0) {
+ Path wktFilee = Paths.get(selection[0]);
+ if (!Files.exists(wktFilee)) {
+ setErrorMessage("File " + wktFilee.toAbsolutePath() + " does not exist");
+ } else {
+ wktFile = wktFilee;
+ setPageComplete(true);
+ }
+ } else {
+ setPageComplete(false);
+ }
+ }
+ });
+
+ updateHeaders();
+
+
+
+ setControl(composite);
+
+
+
+ setPageComplete(false);
+ }
+
+ private String[] getDistrictDiagrams() {
+ Functions.getDistrictDiagrams(null);
+ return null;
+ }
+
+ @Override
+ public void fileSelected(FileOrDirectorySelectionWidget source, String[] filename) {
+ String[] selection = csvSelection.getFilename();
+ if (selection != null && selection.length > 0) {
+ Path csvFile = Paths.get(selection[0]);
+ if (!Files.exists(csvFile)) {
+ setErrorMessage("File " + csvFile.toAbsolutePath() + " does not exist");
+ } else {
+ model.setSource(csvFile);
+ updateHeaders();
+ setPageComplete(true);
+ }
+ } else {
+ setPageComplete(false);
+ }
+ }
+
+ private void updateHeaders() {
+ if (headerTable != null)
+ headerTable.dispose();
+ headerTable = new Table(tableComposite, SWT.NONE);
+ headerTable.setHeaderVisible(true);
+ headerTable.setLinesVisible(true);
+ GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(tableComposite);
+ for (int i = 0; i < headerTable.getColumns().length; i++) {
+ TableColumn column = headerTable.getColumns()[i];
+ column.dispose();
+ }
+ for (int i = 0; i < headerTable.getItemCount(); i++) {
+ TableItem item = headerTable.getItem(i);
+ item.dispose();
+ }
+ try {
+ List<CSVRecord> rows = model.getRows(5);
+
+ for (int k = 0; k < rows.size(); k++) {
+ CSVRecord row = rows.get(k);
+
+ int columnCount = row.size();
+ for (int i = 0; i < columnCount; i++) {
+ String value = row.get(i);
+ if (k == 0) {
+ TableColumn headerCol = new TableColumn(headerTable, SWT.NONE);
+ headerCol.setText(value);
+
+ tableColumnLayout.setColumnData(headerCol, new ColumnWeightData(10));
+ headerCol.pack();
+ } else {
+ int actualK = k - 1;
+ TableItem item;
+ int itemCount = headerTable.getItemCount();
+ if (actualK >= itemCount) {
+ item = new TableItem(headerTable, SWT.NONE);
+ } else {
+ item = headerTable.getItem(actualK);
+ }
+ item.setText(i, value);
+ }
+ }
+ }
+
+// Map<CSVHeader, List<String>> headerAndValues = model.getHeaderAndRows(5);
+//
+// int coo = headerTable.getColumns().length;
+// int count = headerTable.getColumnCount();
+//
+// for (Map.Entry<CSVHeader, List<String>> entr : headerAndValues.entrySet()) {
+// CSVHeader he = entr.getKey();
+// int index = he.getIndex();
+// TableColumn headerCol = new TableColumn(headerTable, SWT.NONE);
+// headerCol.setText(he.getHeader());
+//
+// tableColumnLayout.setColumnData(headerCol, new ColumnWeightData(10));
+// headerCol.pack();
+//
+// for (String val : entr.getValue()) {
+// TableItem item = new TableItem(headerTable, SWT.NONE);
+// item.setText(val);
+// }
+// }
+ } catch (IOException e) {
+ setErrorMessage(e.getMessage());
+ }
+ }
+
+}
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,
.
-package org.simantics.district.imports;\r
-\r
-import java.io.IOException;\r
-import java.nio.file.Files;\r
-import java.nio.file.Path;\r
-import java.util.ArrayList;\r
-import java.util.HashMap;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import org.apache.commons.csv.CSVFormat;\r
-import org.apache.commons.csv.CSVParser;\r
-import org.apache.commons.csv.CSVRecord;\r
-import org.simantics.db.Resource;\r
-\r
-public class DistrictImportUtils {\r
-\r
- private DistrictImportUtils() { }\r
- \r
- \r
- public static Resource importCSVAsLayer(Path csvFile) throws IOException {\r
- \r
- \r
- try (CSVParser parser = CSVFormat.DEFAULT.withFirstRecordAsHeader().parse(Files.newBufferedReader(csvFile))) {\r
- Map<String, Integer> header = parser.getHeaderMap();\r
- System.out.println(header);\r
- }\r
- return null;\r
- }\r
- \r
- public static Map<String, Integer> readCSVHeader(Path source, char delimiter, boolean firstAsHeader) throws IOException {\r
- return readCSVHeader(source, CSVFormat.newFormat(delimiter), firstAsHeader);\r
- }\r
- \r
- public static Map<String, Integer> readCSVHeader(Path source, CSVFormat format, boolean firstAsHeader) throws IOException {\r
- if (firstAsHeader)\r
- format = format.withFirstRecordAsHeader();\r
- try (CSVParser parser = format.parse(Files.newBufferedReader(source))) {\r
- return parser.getHeaderMap();\r
- }\r
- }\r
-\r
-\r
- public static Map<String, Character> getSupportedCSVDelimiterFormats() {\r
- Map<String, Character> delimiters = new HashMap<>();\r
- delimiters.put("COMMA", ',');\r
- delimiters.put("SEMICOMMA", ';');\r
- return delimiters;\r
- }\r
-\r
- public static List<Map<String, String>> readRows(Path source, char delimiter, boolean firstAsHeader, int amount) throws IOException {\r
- return readRows(source, CSVFormat.newFormat(delimiter), firstAsHeader, amount);\r
- }\r
-\r
- public static List<Map<String, String>> readRows(Path source, CSVFormat format, boolean firstAsHeader, int amount) throws IOException {\r
- if (firstAsHeader)\r
- format = format.withFirstRecordAsHeader();\r
- try (CSVParser parser = format.parse(Files.newBufferedReader(source))) {\r
- int start = 0;\r
- List<Map<String, String>> results = new ArrayList<>(amount);\r
- Iterator<CSVRecord> iter = parser.iterator();\r
- while (start < amount && iter.hasNext()) {\r
- CSVRecord record = iter.next();\r
- results.add(record.toMap());\r
- start++;\r
- }\r
- return results;\r
- }\r
- }\r
-\r
-\r
- public static Map<CSVHeader, List<String>> readCSVHeaderAndRows(Path source, char delimiter, boolean firstAsHeader, int amount) throws IOException {\r
- Map<CSVHeader, List<String>> results = new HashMap<>();\r
- CSVFormat format = CSVFormat.newFormat(delimiter);\r
- if (firstAsHeader)\r
- format = format.withFirstRecordAsHeader();\r
- try (CSVParser parser = format.parse(Files.newBufferedReader(source))) {\r
- Map<String, Integer> headers = parser.getHeaderMap();\r
- if (headers != null && !headers.isEmpty()) {\r
- for (int index = 0; index < headers.size(); index++) {\r
- for (String head : headers.keySet()) {\r
- results.put(new CSVHeader(head, index), new ArrayList<>());\r
- }\r
- }\r
- }\r
- \r
- Iterator<CSVRecord> records = parser.iterator();\r
- int rows = 0;\r
- while (rows < amount && records.hasNext()) {\r
- CSVRecord record = records.next();\r
- for (int j = 0; j < record.size(); j++) {\r
- String value = record.get(j);\r
- String header = Integer.toString(j);\r
- CSVHeader csvHeader = new CSVHeader(header, j);\r
- List<String> vals = results.get(csvHeader);\r
- if (vals == null) {\r
- vals = new ArrayList<>();\r
- results.put(csvHeader, vals);\r
- }\r
- vals.add(value);\r
- }\r
- rows++;\r
- }\r
- }\r
- return results;\r
- }\r
- \r
- public static class CSVHeader {\r
-\r
- private final String header;\r
- private final int index;\r
- \r
- public CSVHeader(String header, int index) {\r
- this.header = header;\r
- this.index = index;\r
- }\r
-\r
- public String getHeader() {\r
- return header;\r
- }\r
-\r
- public int getIndex() {\r
- return index;\r
- }\r
- \r
- @Override\r
- public int hashCode() {\r
- final int prime = 31;\r
- int result = 1;\r
- result = prime * result + ((header == null) ? 0 : header.hashCode());\r
- result = prime * result + index;\r
- return result;\r
- }\r
-\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (this == obj)\r
- return true;\r
- if (obj == null)\r
- return false;\r
- if (getClass() != obj.getClass())\r
- return false;\r
- CSVHeader other = (CSVHeader) obj;\r
- if (header == null) {\r
- if (other.header != null)\r
- return false;\r
- } else if (!header.equals(other.header))\r
- return false;\r
- if (index != other.index)\r
- return false;\r
- return true;\r
- }\r
- }\r
-\r
-}\r
+package org.simantics.district.imports;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.csv.CSVFormat;
+import org.apache.commons.csv.CSVParser;
+import org.apache.commons.csv.CSVRecord;
+import org.simantics.db.Resource;
+
+public class DistrictImportUtils {
+
+ private DistrictImportUtils() { }
+
+
+ public static Resource importCSVAsLayer(Path csvFile) throws IOException {
+
+ try (CSVParser parser = CSVFormat.DEFAULT.withFirstRecordAsHeader().parse(Files.newBufferedReader(csvFile))) {
+ Map<String, Integer> header = parser.getHeaderMap();
+ System.out.println(header);
+ }
+ return null;
+ }
+
+ public static Map<String, Integer> readCSVHeader(Path source, char delimiter, boolean firstAsHeader) throws IOException {
+ return readCSVHeader(source, CSVFormat.newFormat(delimiter), firstAsHeader);
+ }
+
+ public static Map<String, Integer> readCSVHeader(Path source, CSVFormat format, boolean firstAsHeader) throws IOException {
+ if (firstAsHeader)
+ format = format.withFirstRecordAsHeader();
+ try (CSVParser parser = format.parse(Files.newBufferedReader(source))) {
+ return parser.getHeaderMap();
+ }
+ }
+
+ public static Map<String, Character> getSupportedCSVDelimiterFormats() {
+ Map<String, Character> delimiters = new HashMap<>();
+ delimiters.put("COMMA", ',');
+ delimiters.put("SEMICOMMA", ';');
+ return delimiters;
+ }
+
+ public static List<Map<String, String>> readRows(Path source, char delimiter, boolean firstAsHeader, int amount) throws IOException {
+ return readRows(source, CSVFormat.newFormat(delimiter), firstAsHeader, amount);
+ }
+
+ public static List<Map<String, String>> readRows(Path source, CSVFormat format, boolean firstAsHeader, int amount) throws IOException {
+ if (firstAsHeader)
+ format = format.withFirstRecordAsHeader();
+ try (CSVParser parser = format.parse(Files.newBufferedReader(source))) {
+ int start = 0;
+ List<Map<String, String>> results = new ArrayList<>(amount);
+ Iterator<CSVRecord> iter = parser.iterator();
+ while (start < amount && iter.hasNext()) {
+ CSVRecord record = iter.next();
+ results.add(record.toMap());
+ start++;
+ }
+ return results;
+ }
+ }
+
+ public static List<CSVRecord> readRows(Path source, char delim, int rowAmount) throws IOException {
+ List<CSVRecord> results = new ArrayList<>();
+ CSVFormat format = CSVFormat.newFormat(delim);
+ try (CSVParser parser = format.parse(Files.newBufferedReader(source))) {
+ Iterator<CSVRecord> records = parser.iterator();
+ int rows = 0;
+ if (rowAmount == -1) {
+ while (records.hasNext()) {
+ results.add(records.next());
+ rows++;
+ }
+ } else {
+ while (rows < rowAmount && records.hasNext()) {
+ results.add(records.next());
+ rows++;
+ }
+ }
+ }
+ return results;
+ }
+
+
+ public static Map<CSVHeader, List<String>> readCSVHeaderAndRows(Path source, char delimiter, boolean firstAsHeader, int amount) throws IOException {
+ Map<CSVHeader, List<String>> results = new HashMap<>();
+ CSVFormat format = CSVFormat.newFormat(delimiter);
+ if (firstAsHeader)
+ format = format.withFirstRecordAsHeader();
+ try (CSVParser parser = format.parse(Files.newBufferedReader(source))) {
+ Map<String, Integer> headers = parser.getHeaderMap();
+ if (headers != null && !headers.isEmpty()) {
+ for (int index = 0; index < headers.size(); index++) {
+ for (String head : headers.keySet()) {
+ results.put(new CSVHeader(head, index), new ArrayList<>());
+ }
+ }
+ }
+
+ Iterator<CSVRecord> records = parser.iterator();
+ int rows = 0;
+ while (rows < amount && records.hasNext()) {
+ CSVRecord record = records.next();
+ for (int j = 0; j < record.size(); j++) {
+ String value = record.get(j);
+ String header = Integer.toString(j);
+ CSVHeader csvHeader = new CSVHeader(header, j);
+ List<String> vals = results.get(csvHeader);
+ if (vals == null) {
+ vals = new ArrayList<>();
+ results.put(csvHeader, vals);
+ }
+ vals.add(value);
+ }
+ rows++;
+ }
+ }
+ return results;
+ }
+
+ public static class CSVHeader {
+
+ private final String header;
+ private final int index;
+
+ public CSVHeader(String header, int index) {
+ this.header = header;
+ this.index = index;
+ }
+
+ public String getHeader() {
+ return header;
+ }
+
+ public int getIndex() {
+ return index;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((header == null) ? 0 : header.hashCode());
+ result = prime * result + index;
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ CSVHeader other = (CSVHeader) obj;
+ if (header == null) {
+ if (other.header != null)
+ return false;
+ } else if (!header.equals(other.header))
+ return false;
+ if (index != other.index)
+ return false;
+ return true;
+ }
+ }
+
+}
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
- <classpathentry exported="true" kind="lib" path="lib/gt-epsg-hsql-16.2.jar"/>
- <classpathentry exported="true" kind="lib" path="lib/hsqldb-2.3.0.jar"/>
- <classpathentry exported="true" kind="lib" path="lib/commons-pool-1.5.4.jar"/>
- <classpathentry exported="true" kind="lib" path="lib/core-0.26.jar"/>
- <classpathentry exported="true" kind="lib" path="lib/GeographicLib-Java-1.44.jar"/>
- <classpathentry exported="true" kind="lib" path="lib/gt-metadata-16.2.jar"/>
- <classpathentry exported="true" kind="lib" path="lib/gt-opengis-16.2.jar"/>
- <classpathentry exported="true" kind="lib" path="lib/gt-referencing-16.2.jar"/>
- <classpathentry exported="true" kind="lib" path="lib/jai_core-1.1.3.jar"/>
- <classpathentry exported="true" kind="lib" path="lib/jgridshift-1.0.jar"/>
- <classpathentry exported="true" kind="lib" path="lib/jsr-275-1.0-beta-2.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
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
-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
DN.Layer <T DIA.Layer
DN.Edge <T DIA.Element : L0.Type
- @L0.assert DN.Bidirectional false
- @L0.assert DN.Edge.HasDiameter 1
+ @L0.assert DN.Edge.HasDiameter 0.1
+ @L0.assert DN.Edge.HasOuterDiameter 0.11
DN.Vertex <T DIA.Element : L0.Type
- @L0.assert DN.Bidirectional false
-
-DN.Bidirectional <R L0.HasProperty : SEL.GenericParameterType
- L0.HasLabel "Is network bidirectional"
- L0.HasRange L0.Boolean
- L0.readOnly false
+ @L0.assert DN.Vertex.HasElevation 0.0
DN.EdgeDefaultMapping <R L0.HasProperty : DN.EdgeMappingParameterType
L0.HasLabel "Default Edge mapping"
L0.HasRange L0.Double
L0.readOnly false
+DN.Vertex.HasElevation <R L0.HasProperty : SEL.GenericParameterType
+ L0.HasLabel "Elevation"
+ L0.HasRange L0.Double
+ L0.readOnly false
+
+DN.Edge.HasOuterDiameter <R L0.HasProperty : SEL.GenericParameterType
+ L0.HasLabel "Outer Diameter"
+ L0.HasRange L0.Double
+ L0.readOnly false
+
DN.InLayer
@L0.defTag
@L0.tag L0.Abstract
DN.Mapping.EdgeMapping <T DN.Mapping.Base
>-- DN.Mapping.ComponentType
- >-- DN.Mapping.EdgeMapping.Bidirectional --> L0.Boolean <R L0.HasProperty
>-- DN.Mapping.EdgeMapping.LengthAttribute --> L0.String <R L0.HasProperty
>-- DN.Mapping.EdgeMapping.DiameterAttribute --> L0.String <R L0.HasProperty
>-- DN.Mapping.Terminals
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;
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;
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;
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";
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";
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";
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";
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) {
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);
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);
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);
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) {
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,
</fragments>
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_4mZBIML_Eea1mdgpHNVHMA" featurename="commands" parentElementId="xpath:/">
<elements xsi:type="commands:Command" xmi:id="_6lrYUML_Eea1mdgpHNVHMA" elementId="org.simantics.district.network.ui.command.openDistrictEditor" commandName="Open District Editor"/>
- <elements xsi:type="commands:Command" xmi:id="_zhiBwN16Eea73Pr1j_7O0Q" elementId="org.simantics.district.network.ui.command.runmapping" commandName="Run mapping"/>
<elements xsi:type="commands:Command" xmi:id="_A1HBQOFYEeaJP6VyXP72Jw" elementId="org.simantics.district.network.ui.joinVertices" commandName="Join Vertices"/>
<elements xsi:type="commands:Command" xmi:id="_QzdUQOIcEeaJP6VyXP72Jw" elementId="org.simantics.district.network.ui.setFocusable" commandName="Set Focusable"/>
</fragments>
</elements>
</fragments>
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_dbiHcMMBEea1mdgpHNVHMA" featurename="handlers" parentElementId="xpath:/">
- <elements xsi:type="commands:Handler" xmi:id="_ffHv0MMBEea1mdgpHNVHMA" elementId="org.simantics.district.network.ui.handler.runmapping" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.contributions.RunMappingHandler" command="_zhiBwN16Eea73Pr1j_7O0Q"/>
<elements xsi:type="commands:Handler" xmi:id="_DPcVsOFYEeaJP6VyXP72Jw" elementId="org.simantics.district.network.ui.handler.joinVertices" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.contributions.JoinVerticesHandler" command="_A1HBQOFYEeaJP6VyXP72Jw"/>
<elements xsi:type="commands:Handler" xmi:id="_VPgBwOIcEeaJP6VyXP72Jw" elementId="org.simantics.district.network.ui.handler.setFocusable" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.contributions.SetFocusableHandler" command="_QzdUQOIcEeaJP6VyXP72Jw"/>
</fragments>
- <fragments xsi:type="fragment:StringModelFragment" xmi:id="_Rf7koN16Eea73Pr1j_7O0Q" featurename="trimContributions" parentElementId="xpath:/">
- <elements xsi:type="menu:TrimContribution" xmi:id="_c57iwN16Eea73Pr1j_7O0Q" elementId="org.simantics.district.network.ui.trimcontribution.0" parentId="org.eclipse.ui.main.toolbar">
- <children xsi:type="menu:ToolBar" xmi:id="_vdgLoN16Eea73Pr1j_7O0Q" elementId="org.simantics.district.network.ui.toolbar.0">
- <children xsi:type="menu:HandledToolItem" xmi:id="_v99NUN16Eea73Pr1j_7O0Q" elementId="org.simantics.district.network.ui.handledtoolitem.domapping" label="Map network ontology" iconURI="platform:/plugin/org.simantics.district.network.ui/icons/map_go.png" tooltip="Map network ontology to simulator specific model" command="_zhiBwN16Eea73Pr1j_7O0Q"/>
- </children>
- </elements>
- </fragments>
</fragment:ModelFragments>
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;
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;
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());
+ }
}
--- /dev/null
+package org.simantics.district.network.ui.adapters;
+
+import java.awt.Color;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.simantics.db.Resource;
+import org.simantics.g2d.element.IElement;
+import org.simantics.g2d.element.handler.AdditionalColor;
+import org.simantics.g2d.element.handler.ElementHandler;
+import org.simantics.utils.datastructures.hints.IHintContext.Key;
+import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
+import org.simantics.utils.ui.color.ColorPool;
+
+public class DistrictNetworkAdditionalColor implements AdditionalColor {
+
+ public static final Key KEY_DN_MAPPING_RESOURCE = new KeyOf(Resource.class, "DN_MAPPING_RESOURCE");
+
+ private static final long serialVersionUID = -6290147660355075322L;
+
+ public static final ElementHandler INSTANCE = new DistrictNetworkAdditionalColor();
+
+ private ColorPool colorPool = new ColorPool();
+ private List<Resource> mappings = new ArrayList<>();
+
+ @Override
+ public void setAdditionalColor(IElement e, Color c) {
+ throw new UnsupportedOperationException("Not needed!");
+ }
+
+ @Override
+ public Color getAdditionalColor(IElement e) {
+ Resource mapping = e.getHint(KEY_DN_MAPPING_RESOURCE);
+ if (!mappings.contains(mapping))
+ mappings.add(mapping);
+
+ int index = mappings.indexOf(mapping);
+ Color color = colorPool.getColor(index).getAWTColor();
+ return color;
+ }
+
+}
package org.simantics.district.network.ui.adapters;
+import java.awt.Color;
import java.awt.geom.Rectangle2D;
import java.util.Collection;
import java.util.Collections;
DNEdgeInternalSize.INSTANCE,
DNEdgeSceneGraph.INSTANCE,
DNEdgeConnectionHandler.INSTANCE,
- SimpleElementLayers.INSTANCE
+ SimpleElementLayers.INSTANCE,
+ DistrictNetworkAdditionalColor.INSTANCE
).setId(DistrictNetworkEdgeElement.class.getSimpleName());
static final class DNEdgeSceneGraph implements SceneGraph {
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);
}
}
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;
@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);
package org.simantics.district.network.ui.adapters;
+import java.awt.Color;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
DefaultTransform.INSTANCE,
DNVertexInternalSize.INSTANCE,
DNVertexSceneGraph.INSTANCE,
- SimpleElementLayers.INSTANCE
+ SimpleElementLayers.INSTANCE,
+ DistrictNetworkAdditionalColor.INSTANCE
).setId(DistrictNetworkVertexElement.class.getSimpleName());
static final class DNVertexSceneGraph implements SceneGraph {
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);
}
@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;
}
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;
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);
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);
+++ /dev/null
-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();
- }
-}
}
});
}
+
+ public static void getDistrictDiagrams(ReadGraph graph) {
+
+ }
}
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() {
// 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())));
updateBounds();
}
+ public void setColor(Color color) {
+ this.color = color;
+ }
+
+ public Color getColor() {
+ return color;
+ }
+
}
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);
Color oldColor = g2d.getColor();
Stroke oldStroke = g2d.getStroke();
- g2d.setColor(Color.RED);
+ g2d.setColor(color);
double scaleRecip = 1;
if (scaleStroke) {
@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);
return changed;
}
+ public void setColor(Color color) {
+ this.color = color;
+ }
+
+ public Color getColor() {
+ return color;
+ }
+
}
--- /dev/null
+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);
+ }
+
+}
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;
}
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);
}
});
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;
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
--- /dev/null
+package org.simantics.district.network.ui.participants;
+
+import org.simantics.district.network.ui.nodes.MapRulerNode;
+import org.simantics.g2d.participant.RulerPainter;
+
+public class MapRulerPainter extends RulerPainter {
+
+ @Override
+ protected Class<MapRulerNode> getNodeClass() {
+ return MapRulerNode.class;
+ }
+}
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
import "Simantics/DB"
importJava "org.simantics.district.network.DistrictNetworkUtil" where
- calculateDistance :: Resource -> Resource -> <ReadGraph> Double
\ No newline at end of file
+ calculateDistance :: Resource -> Resource -> <ReadGraph> Double
+
+importJava "org.simantics.district.network.ModelledCRS" where
+ xToLongitude :: Double -> <Proc> Double
+ yToLatitude :: Double -> <Proc> Double
+ longitudeToX :: Double -> <Proc> Double
+ latitudeToY :: Double -> <Proc> Double
\ No newline at end of file
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;
+ }
}
@Override
public void widgetSelected(SelectionEvent e) {
- E4WorkbenchUtils.showInSystemExplorer("");
+// E4WorkbenchUtils.showInSystemExplorer("");
}
});