From: jsimomaa Date: Thu, 29 Jun 2017 05:00:52 +0000 (+0300) Subject: Updates to Simantics district CSV import X-Git-Tag: v1.31.0~4 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=231b9da5dfd8129e24cb5a9d2ec87ff9afa7afd9;p=simantics%2Fdistrict.git Updates to Simantics district CSV import refs #6958 Change-Id: I7310b62f2b456d36c11d01b8c604b4e3e60b8b2a --- diff --git a/org.simantics.district.imports.ui/META-INF/MANIFEST.MF b/org.simantics.district.imports.ui/META-INF/MANIFEST.MF index b7d0aa63..dc0819b8 100644 --- a/org.simantics.district.imports.ui/META-INF/MANIFEST.MF +++ b/org.simantics.district.imports.ui/META-INF/MANIFEST.MF @@ -16,5 +16,6 @@ Require-Bundle: org.eclipse.ui.ide, org.simantics.diagram.ontology, org.simantics.modeling.ontology, org.simantics.district.network, - org.simantics.district.network.ontology + org.simantics.district.network.ontology, + org.simantics.district.maps Bundle-ActivationPolicy: lazy diff --git a/org.simantics.district.imports.ui/icons/database_table.png b/org.simantics.district.imports.ui/icons/database_table.png new file mode 100644 index 00000000..693709cb Binary files /dev/null and b/org.simantics.district.imports.ui/icons/database_table.png differ diff --git a/org.simantics.district.imports.ui/plugin.xml b/org.simantics.district.imports.ui/plugin.xml index fe77b996..338a79d9 100644 --- a/org.simantics.district.imports.ui/plugin.xml +++ b/org.simantics.district.imports.ui/plugin.xml @@ -1,15 +1,16 @@ - - - - - - - Imports CSV data to Simantics District network - - - - + + + + + + + Imports CSV data to Simantics District network + + + + 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 53de5cfe..2f13692b 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 @@ -20,9 +20,9 @@ public class CSVImportModel { // Second page fills these private char delimiter; - private boolean read; + private boolean readFirstAsHeader = true; private Map delimiters; - private Path wktFile; +// private Path wktFile; // Vertex import private int xCoordIndex = -1; @@ -41,6 +41,12 @@ public class CSVImportModel { private int componentMappingIndex = -1; private Map componentMappings = new HashMap<>(); private boolean isVertexImport; + private String sourceCRS; + private int tempIndex; + private int pressureIndex; + private int diameterIndex; + private int outerDiamterIndex; + private int nominalMassFlowIndex; // Third page @@ -57,7 +63,7 @@ public class CSVImportModel { } public void setReadFirstAsHeader(boolean read) { - this.read = read; + this.readFirstAsHeader = read; } public Path getSource() { @@ -73,7 +79,7 @@ public class CSVImportModel { public Map> getHeaderAndRows(int amount) throws IOException { if (source != null) - return DistrictImportUtils.readCSVHeaderAndRows(source, delimiter, read, amount); + return DistrictImportUtils.readCSVHeaderAndRows(source, delimiter, readFirstAsHeader, amount); else return Collections.emptyMap(); } @@ -81,14 +87,14 @@ public class CSVImportModel { public Map getHeader() throws IOException { Map header = null; if (source != null) - header = DistrictImportUtils.readCSVHeader(source, delimiter, read); + header = DistrictImportUtils.readCSVHeader(source, delimiter, readFirstAsHeader); if (header == null) header = Collections.emptyMap(); return header; } public boolean getReadFirstAsHeader() { - return read; + return readFirstAsHeader; } public String[] getDelimiterFormats() { @@ -101,7 +107,7 @@ public class CSVImportModel { public List> readRows(int amount) throws IOException { if (source != null) - return DistrictImportUtils.readRows(source, delimiter, read, amount); + return DistrictImportUtils.readRows(source, delimiter, readFirstAsHeader, amount); else return Collections.emptyList(); } @@ -110,9 +116,9 @@ public class CSVImportModel { return delimiter; } - public Path getWKTFile() { - return wktFile; - } +// public Path getWKTFile() { +// return wktFile; +// } public int getXCoordIndex() { return xCoordIndex; @@ -154,9 +160,9 @@ public class CSVImportModel { return targetDiagram; } - public void setWKTFile(Path wktFile) { - this.wktFile = wktFile; - } +// public void setWKTFile(Path wktFile) { +// this.wktFile = wktFile; +// } public void setComponentMappings(String value, Resource resource) { componentMappings.put(value, resource); @@ -222,4 +228,52 @@ public class CSVImportModel { return endZCoordIndex; } + public void setSourceCRS(String crs) { + this.sourceCRS = crs; + } + + public String getSourceCRS() { + return sourceCRS; + } + + public void setTempIndex(int tempIndex) { + this.tempIndex = tempIndex; + } + + public int getTempIndex() { + return tempIndex; + } + + public void setPressureIndex(int pressureIndex) { + this.pressureIndex = pressureIndex; + } + + public int getPressureIndex() { + return pressureIndex; + } + + public void setDiameterIndex(int parseInt) { + this.diameterIndex = parseInt; + } + + public int getDiameterIndex() { + return diameterIndex; + } + + public void setOuterDiameterIndex(int parseInt) { + this.outerDiamterIndex = parseInt; + } + + public int getOuterDiamterIndex() { + return outerDiamterIndex; + } + + public void setNominalMassFlowIndex(int parseInt) { + this.nominalMassFlowIndex = parseInt; + } + + public int getNominalMassFlowIndex() { + return nominalMassFlowIndex; + } + } 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 58fd168c..703ade17 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,19 +1,21 @@ package org.simantics.district.imports.ui; -import java.io.IOException; +import java.lang.reflect.InvocationTargetException; import java.nio.file.Path; import java.util.List; import org.apache.commons.csv.CSVRecord; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; +import org.eclipse.jface.wizard.WizardPage; import org.eclipse.ui.IImportWizard; import org.eclipse.ui.IWorkbench; import org.geotools.geometry.DirectPosition2D; import org.geotools.referencing.CRS; import org.opengis.geometry.DirectPosition; import org.opengis.geometry.MismatchedDimensionException; -import org.opengis.referencing.FactoryException; import org.opengis.referencing.crs.CoordinateReferenceSystem; import org.opengis.referencing.operation.MathTransform; import org.opengis.referencing.operation.TransformException; @@ -27,6 +29,8 @@ import org.simantics.district.imports.DistrictImportUtils; import org.simantics.district.network.DistrictNetworkUtil; import org.simantics.district.network.ontology.DistrictNetworkResource; import org.simantics.district.network.ui.DNEdgeBuilder; +import org.simantics.maps.MapScalingTransform; +import org.simantics.utils.ui.ExceptionUtils; public class CSVImportWizard extends Wizard implements IImportWizard { @@ -48,100 +52,191 @@ public class CSVImportWizard extends Wizard implements IImportWizard { @Override public boolean performFinish() { try { - - - Path csvFile = model.getSource(); - char delim = model.getDelimiter(); - - List rows = DistrictImportUtils.readRows(csvFile, delim, -1); - - Path wktFile = model.getWKTFile(); - - int xCoordColumnIndex = model.getXCoordIndex(); - int yCoordColumnIndex = model.getYCoordIndex(); - int zCoordColumnIndex = model.getZCoordIndex(); - - int startXCoordColumnIndex = model.getStartXCoordIndex(); - int startYCoordColumnIndex = model.getStartYCoordIndex(); - int startZValueColumnIndex = model.getStartZCoordIndex(); - int endXCoordColumnIndex = model.getEndXCoordIndex(); - int endYCoordColumnIndex = model.getEndYCoordIndex(); - int endZValueColumnIndex = model.getEndZCoordIndex(); - - int mappingColumn = model.getComponentMappingIndex(); - - try { - CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:3879"); - CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326"); - MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS, true); - - Simantics.getSession().syncRequest(new Write() { - - @Override - public void perform(WriteGraph graph) throws DatabaseException { - for (int k = 1; k < rows.size(); k++) { - CSVRecord row = rows.get(k); - - String mappingValue = row.get(mappingColumn); + getContainer().run(true, true, new IRunnableWithProgress() { - try { - if (model.isVertexImport()) { - String xCoords = row.get(xCoordColumnIndex); - String yCoords = row.get(yCoordColumnIndex); - double xCoord = Double.parseDouble(xCoords); - double yCoord = Double.parseDouble(yCoords); - - String zs = row.get(zCoordColumnIndex); - double z = Double.parseDouble(zs); - - DirectPosition2D targetPos = new DirectPosition2D(); - DirectPosition2D sourcePos = new DirectPosition2D(xCoord, yCoord); - DirectPosition res = transform.transform(sourcePos, targetPos); - double[] coords = res.getCoordinate(); - Resource vertex = DistrictNetworkUtil.createVertex(graph, model.getParentDiagram(), new double[] { coords[1], -coords[0]}, model.getComponentMappings().get(mappingValue)); - graph.claimLiteral(vertex, DistrictNetworkResource.getInstance(graph).Vertex_HasElevation, z, Bindings.DOUBLE); - } else { - String startXCoords = row.get(startXCoordColumnIndex); - String startYCoords = row.get(startYCoordColumnIndex); - String endXCoords = row.get(endXCoordColumnIndex); - String endYCoords = row.get(endYCoordColumnIndex); - - double startXCoord = Double.parseDouble(startXCoords); - double startYCoord = Double.parseDouble(startYCoords); - - double endXCoord = Double.parseDouble(endXCoords); - double endYCoord = Double.parseDouble(endYCoords); - - DirectPosition2D startTargetPos = new DirectPosition2D(); - DirectPosition2D startSourcePos = new DirectPosition2D(startXCoord, startYCoord); - DirectPosition startRes = transform.transform(startSourcePos, startTargetPos); - double[] startCoords = startRes.getCoordinate(); - - DirectPosition2D endTargetPos = new DirectPosition2D(); - DirectPosition2D endSourcePos = new DirectPosition2D(endXCoord, endYCoord); - DirectPosition endRes = transform.transform(endSourcePos, endTargetPos); - double[] endCoords = endRes.getCoordinate(); + @Override + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + try { + Path csvFile = model.getSource(); + char delim = model.getDelimiter(); + + List rows = DistrictImportUtils.readRows(csvFile, delim, -1); + + // Path wktFile = model.getWKTFile(); + + int xCoordColumnIndex = model.getXCoordIndex(); + int yCoordColumnIndex = model.getYCoordIndex(); + int zCoordColumnIndex = model.getZCoordIndex(); + int tempColumnIndex = model.getTempIndex(); + int pressureColumnIndex = model.getPressureIndex(); + + int startXCoordColumnIndex = model.getStartXCoordIndex(); + int startYCoordColumnIndex = model.getStartYCoordIndex(); + int startZValueColumnIndex = model.getStartZCoordIndex(); + int endXCoordColumnIndex = model.getEndXCoordIndex(); + int endYCoordColumnIndex = model.getEndYCoordIndex(); + int endZValueColumnIndex = model.getEndZCoordIndex(); + int diameterColumnIndex= model.getDiameterIndex(); + int outerDiameterColumnIndex = model.getOuterDiamterIndex(); + int nominalMassFlowIndex = model.getNominalMassFlowIndex(); + + int mappingColumn = model.getComponentMappingIndex(); + + String sourceEPSGCRS = model.getSourceCRS(); + + MathTransform transform = null; + boolean doTransform = false; + // if sourceEPSGCRS is empty || null then ignore transformation + if (sourceEPSGCRS != null && !sourceEPSGCRS.isEmpty()) { + CoordinateReferenceSystem sourceCRS = CRS.decode(sourceEPSGCRS); + CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326"); + transform = CRS.findMathTransform(sourceCRS, targetCRS, true); + doTransform = true; + } + final boolean actualDoTransform = doTransform; + final MathTransform actualTransform = transform; + Simantics.getSession().syncRequest(new Write() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + + DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); + + for (int k = 1; k < rows.size(); k++) { + CSVRecord row = rows.get(k); - Resource edge = DNEdgeBuilder.create(graph, model.getParentDiagram(), new double[] { startCoords[1], -startCoords[0]}, new double[] { endCoords[1], -endCoords[0]}, 0.0000001); - graph.claim(edge, DistrictNetworkResource.getInstance(graph).HasMapping, model.getComponentMappings().get(mappingValue)); -// graph.claimLiteral(edge, DistrictNetworkResource.getInstance(graph).Edge_HasDiameter, value); + String mappingValue = row.get(mappingColumn); + + try { + if (model.isVertexImport()) { + String xCoords = row.get(xCoordColumnIndex); + String yCoords = row.get(yCoordColumnIndex); + double xCoord = Double.parseDouble(xCoords); + double yCoord = Double.parseDouble(yCoords); + + String zs = row.get(zCoordColumnIndex); + double z = 0; + if (!zs.isEmpty()) { + try { + z = Double.parseDouble(zs); + } catch (NumberFormatException e) { + throw new DatabaseException(e); + } + } + + double[] coords; + if (actualDoTransform) { + DirectPosition2D targetPos = new DirectPosition2D(); + DirectPosition2D sourcePos = new DirectPosition2D(xCoord, yCoord); + DirectPosition res = actualTransform.transform(sourcePos, targetPos); + coords = res.getCoordinate(); + } else { + coords = new double[] { xCoord / MapScalingTransform.getScaleX(), yCoord / MapScalingTransform.getScaleY() }; + } + Resource vertex = DistrictNetworkUtil.createVertex(graph, model.getParentDiagram(), new double[] { coords[1], -coords[0]}, model.getComponentMappings().get(mappingValue)); + + graph.claimLiteral(vertex, DN.Vertex_HasElevation, z, Bindings.DOUBLE); + + String tempS = row.get(tempColumnIndex); + if (!tempS.isEmpty()) { + try { + double temp = Double.parseDouble(tempS); + graph.claimLiteral(vertex, DN.Vertex_HasTemperature, temp, Bindings.DOUBLE); + } catch (NumberFormatException e) { + throw new DatabaseException(e); + } + } + String pressureS = row.get(pressureColumnIndex); + if (!pressureS.isEmpty()) { + try { + double pressure = Double.parseDouble(pressureS); + graph.claimLiteral(vertex, DN.Vertex_HasPressure, pressure, Bindings.DOUBLE); + } catch (NumberFormatException e) { + throw new DatabaseException(e); + } + } + + } else { + String startXCoords = row.get(startXCoordColumnIndex); + String startYCoords = row.get(startYCoordColumnIndex); + String endXCoords = row.get(endXCoordColumnIndex); + String endYCoords = row.get(endYCoordColumnIndex); + + double startXCoord = Double.parseDouble(startXCoords); + double startYCoord = Double.parseDouble(startYCoords); + + double endXCoord = Double.parseDouble(endXCoords); + double endYCoord = Double.parseDouble(endYCoords); + + double[] startCoords; + double[] endCoords; + if (actualDoTransform) { + DirectPosition2D startTargetPos = new DirectPosition2D(); + DirectPosition2D startSourcePos = new DirectPosition2D(startXCoord, startYCoord); + DirectPosition startRes = actualTransform.transform(startSourcePos, startTargetPos); + startCoords = startRes.getCoordinate(); + + DirectPosition2D endTargetPos = new DirectPosition2D(); + DirectPosition2D endSourcePos = new DirectPosition2D(endXCoord, endYCoord); + DirectPosition endRes = actualTransform.transform(endSourcePos, endTargetPos); + endCoords = endRes.getCoordinate(); + } else { + startCoords = new double[] { startXCoord / MapScalingTransform.getScaleX(), startYCoord / MapScalingTransform.getScaleY() }; + endCoords = new double[] { endXCoord / MapScalingTransform.getScaleX(), endYCoord / MapScalingTransform.getScaleY() }; + } + + Resource edge = DNEdgeBuilder.create(graph, model.getParentDiagram(), new double[] { startCoords[1], -startCoords[0]}, new double[] { endCoords[1], -endCoords[0]}, 0.0000001); + graph.claim(edge, DistrictNetworkResource.getInstance(graph).HasMapping, model.getComponentMappings().get(mappingValue)); + + String diameterS = row.get(diameterColumnIndex); + if (!diameterS.isEmpty()) { + try { + double diameter = Double.parseDouble(diameterS); + graph.claimLiteral(edge, DN.Edge_HasDiameter, diameter); + } catch (NumberFormatException e) { + throw new DatabaseException(e); + } + } + String outerDiameterS = row.get(outerDiameterColumnIndex); + if (!outerDiameterS.isEmpty()) { + try { + double outerDiameter = Double.parseDouble(outerDiameterS); + graph.claimLiteral(edge, DN.Edge_HasOuterDiameter, outerDiameter); + } catch (NumberFormatException e) { + throw new DatabaseException(e); + } + } + String nominalMassFlowS = row.get(nominalMassFlowIndex); + if (!nominalMassFlowS.isEmpty()) { + try { + double nominalMassFlow = Double.parseDouble(nominalMassFlowS); + graph.claimLiteral(edge, DN.Edge_HasNominalMassFlow, nominalMassFlow); + } catch (NumberFormatException e) { + throw new DatabaseException(e); + } + } + } + } catch (MismatchedDimensionException | TransformException | DatabaseException e) { + throw new DatabaseException(e); + } } - } catch (MismatchedDimensionException | TransformException | DatabaseException e) { - e.printStackTrace(); } - - } + }); + } catch (Exception e) { + throw new InvocationTargetException(e); } - }); - return true; - } catch (FactoryException | DatabaseException e) { - e.printStackTrace(); - } - - } catch (IOException e) { - e.printStackTrace(); + } + }); + return true; + } catch (InvocationTargetException e) { + Throwable t = e.getTargetException(); + WizardPage cp = (WizardPage) getContainer().getCurrentPage(); + cp.setErrorMessage(t.getMessage()); + ExceptionUtils.logAndShowError(t); + return false; + } catch (InterruptedException e) { + ExceptionUtils.logAndShowError(e); + return false; } - 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 9d1d08c4..e1b81e0f 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,13 +1,11 @@ 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.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; import org.apache.commons.csv.CSVRecord; import org.eclipse.jface.dialogs.IPageChangeProvider; @@ -19,6 +17,7 @@ import org.eclipse.jface.viewers.ColumnWeightData; import org.eclipse.jface.wizard.IWizardContainer; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.GridLayout; @@ -26,13 +25,12 @@ import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableItem; +import org.geotools.referencing.CRS; import org.simantics.district.imports.ui.controls.DynamicComboFieldEditor; -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 { @@ -41,12 +39,12 @@ public class CSVImportWizardPage extends WizardPage { private Map headerIndexAndValues = new HashMap<>(); private Table headerTable; - private Button firstAsHeader; +// private Button firstAsHeader; private Combo delimiterCombo; private TableColumnLayout tableColumnLayout; private Composite tableComposite; - private FileSelectionWidget wktFileSelection; +// private FileSelectionWidget wktFileSelection; // Common for vertex and edge private DynamicComboFieldEditor componentMappingSelector; @@ -64,17 +62,25 @@ public class CSVImportWizardPage extends WizardPage { private DynamicComboFieldEditor endXCoordSelector; private DynamicComboFieldEditor endYCoordSelector; private DynamicComboFieldEditor endZValueSelector; + private DynamicComboFieldEditor tempValueSelector; + private DynamicComboFieldEditor pressureValueSelector; + + private DynamicComboFieldEditor outerDiameterSelector; + private DynamicComboFieldEditor diameterSelector; + private DynamicComboFieldEditor nominalMassFlowSelector; private Group indexMappingGroup; private Composite composite; private Button isVertexImport; + + private Combo sourceCRSCombo; protected CSVImportWizardPage(CSVImportModel model) { super("Import CSV Data"); this.model = model; - setMessage("Select columng index mappings"); + setMessage("Select column index mappings"); } @Override @@ -83,7 +89,11 @@ public class CSVImportWizardPage extends WizardPage { composite.setLayout(new GridLayout(1, false)); GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(composite); + Label label = new Label(composite, SWT.NONE); + label.setText("Select delimiter"); + delimiterCombo = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY); + delimiterCombo.setToolTipText("Select the delimiter that is used to separate elements in the CSV file"); delimiterCombo.setItems(model.getDelimiterFormats()); delimiterCombo.addSelectionListener(new SelectionListener() { @@ -100,48 +110,65 @@ public class CSVImportWizardPage extends WizardPage { } }); - 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(); - updateCombos(); - } - - @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(); +// updateCombos(); +// } +// +// @Override +// public void widgetDefaultSelected(SelectionEvent e) { +// widgetSelected(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() { - + label = new Label(composite, SWT.NONE); + label.setText("Select source Coordinate Reference System"); + + sourceCRSCombo = new Combo(composite, SWT.NONE); + sourceCRSCombo.setToolTipText("Select the coordinate reference system that is used in the source material for possible transformation to target coordinate reference system (EPSG:4326)"); + Set codes = CRS.getSupportedCodes("EPSG"); + sourceCRSCombo.setItems(codes.toArray(new String[codes.size()])); + sourceCRSCombo.addSelectionListener(new SelectionAdapter() { + @Override - public void fileSelected(FileOrDirectorySelectionWidget source, String[] filename) { - String[] selection = wktFileSelection.getFilename(); - if (selection != null && selection.length > 0) { - Path wktFile = Paths.get(selection[0]); - if (!Files.exists(wktFile)) { - setErrorMessage("File " + wktFile.toAbsolutePath() + " does not exist"); - } else { - model.setWKTFile(wktFile); - validatePageComplete(); - } - } + public void widgetSelected(SelectionEvent e) { + String current = sourceCRSCombo.getItem(sourceCRSCombo.getSelectionIndex()); + model.setSourceCRS("EPSG:" + current); } }); + +// 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 wktFile = Paths.get(selection[0]); +// if (!Files.exists(wktFile)) { +// setErrorMessage("File " + wktFile.toAbsolutePath() + " does not exist"); +// } else { +// model.setWKTFile(wktFile); +// validatePageComplete(); +// } +// } +// } +// }); isVertexImport = new Button(composite, SWT.CHECK); isVertexImport.setText("File contains vertices"); + isVertexImport.setToolTipText("Enable this if the file contains vertices, i.e. points"); isVertexImport.setSelection(model.isVertexImport()); isVertexImport.addSelectionListener(new SelectionListener() { @@ -263,6 +290,34 @@ public class CSVImportWizardPage extends WizardPage { validatePageComplete(); } }); + tempValueSelector = new DynamicComboFieldEditor("tempValue", "Temperature value", parent); + tempValueSelector.addComboListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + widgetDefaultSelected(e); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + model.setTempIndex(Integer.parseInt(tempValueSelector.getValue())); + validatePageComplete(); + } + }); + pressureValueSelector = new DynamicComboFieldEditor("pressureValue", "Pressure value", parent); + pressureValueSelector.addComboListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + widgetDefaultSelected(e); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + model.setPressureIndex(Integer.parseInt(pressureValueSelector.getValue())); + validatePageComplete(); + } + }); } private void createEdgeIndexMappingField(Group parent) { @@ -353,6 +408,48 @@ public class CSVImportWizardPage extends WizardPage { validatePageComplete(); } }); + diameterSelector = new DynamicComboFieldEditor("diameterValue", "Diameter value", parent); + diameterSelector.addComboListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + widgetDefaultSelected(e); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + model.setDiameterIndex(Integer.parseInt(diameterSelector.getValue())); + validatePageComplete(); + } + }); + outerDiameterSelector = new DynamicComboFieldEditor("outerDiameterValue", "Outer Diameter value", parent); + outerDiameterSelector.addComboListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + widgetDefaultSelected(e); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + model.setOuterDiameterIndex(Integer.parseInt(outerDiameterSelector.getValue())); + validatePageComplete(); + } + }); + nominalMassFlowSelector = new DynamicComboFieldEditor("nominalMassFlowValue", "Nominal Mass Flow", parent); + nominalMassFlowSelector.addComboListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + widgetDefaultSelected(e); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + model.setNominalMassFlowIndex(Integer.parseInt(nominalMassFlowSelector.getValue())); + validatePageComplete(); + } + }); } private void updateCombos() { @@ -370,7 +467,7 @@ public class CSVImportWizardPage extends WizardPage { } if (model.isVertexImport()) - updateVertexcombos(namesAndValues); + updateVertexCombos(namesAndValues); else updateEdgeCombos(namesAndValues); @@ -384,12 +481,17 @@ public class CSVImportWizardPage extends WizardPage { endYCoordSelector.updateCombo(namesAndValues); startZValueSelector.updateCombo(namesAndValues); endZValueSelector.updateCombo(namesAndValues); + diameterSelector.updateCombo(namesAndValues); + outerDiameterSelector.updateCombo(namesAndValues); + nominalMassFlowSelector.updateCombo(namesAndValues); } - private void updateVertexcombos(String[][] namesAndValues) { + private void updateVertexCombos(String[][] namesAndValues) { xCoordSelector.updateCombo(namesAndValues); yCoordSelector.updateCombo(namesAndValues); zValueSelector.updateCombo(namesAndValues); + pressureValueSelector.updateCombo(namesAndValues); + tempValueSelector.updateCombo(namesAndValues); } private void updateHeaders() { 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 100c307e..f123855d 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 @@ -44,8 +44,8 @@ public class DistrictImportUtils { public static Map getSupportedCSVDelimiterFormats() { Map delimiters = new HashMap<>(); - delimiters.put("COMMA", ','); - delimiters.put("SEMICOMMA", ';'); + delimiters.put("Comma", ','); + delimiters.put("Semicolon", ';'); return delimiters; } diff --git a/org.simantics.district.network.ontology/graph.tg b/org.simantics.district.network.ontology/graph.tg index e6067186..697cf7dd 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 63c5f1cc..e819f445 100644 --- a/org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph +++ b/org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph @@ -65,11 +65,27 @@ DN.Vertex.HasElevation -- DN.Mapping.ComponentType --> STR.ComponentType -- DN.Mapping.VertexMapping.ElevationAttribute --> L0.String -- DN.Mapping.VertexMapping.TemperatureAttribute --> L0.String -- DN.Mapping.VertexMapping.PressureAttribute --> L0.String -- DN.Mapping.Terminals --> DN.Mapping.TerminalPair -- DN.Mapping.ComponentType >-- DN.Mapping.EdgeMapping.LengthAttribute --> L0.String -- DN.Mapping.EdgeMapping.DiameterAttribute --> L0.String -- DN.Mapping.EdgeMapping.OuterDiameterAttribute --> L0.String -- DN.Mapping.EdgeMapping.NominalMassFlowAttribute --> 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 f75f51d1..4adb19d3 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 @@ -29,6 +29,8 @@ public class DistrictNetworkResource { public final Resource Edge_HasDiameter_Inverse; public final Resource Edge_HasLength; public final Resource Edge_HasLength_Inverse; + public final Resource Edge_HasNominalMassFlow; + public final Resource Edge_HasNominalMassFlow_Inverse; public final Resource Edge_HasOuterDiameter; public final Resource Edge_HasOuterDiameter_Inverse; public final Resource Functions; @@ -67,6 +69,10 @@ public class DistrictNetworkResource { public final Resource Mapping_EdgeMapping_DiameterAttribute_Inverse; public final Resource Mapping_EdgeMapping_LengthAttribute; public final Resource Mapping_EdgeMapping_LengthAttribute_Inverse; + public final Resource Mapping_EdgeMapping_NominalMassFlowAttribute; + public final Resource Mapping_EdgeMapping_NominalMassFlowAttribute_Inverse; + public final Resource Mapping_EdgeMapping_OuterDiameterAttribute; + public final Resource Mapping_EdgeMapping_OuterDiameterAttribute_Inverse; public final Resource Mapping_InputTerminal; public final Resource Mapping_InputTerminal_Inverse; public final Resource Mapping_OutputTerminal; @@ -78,6 +84,10 @@ public class DistrictNetworkResource { public final Resource Mapping_VertexMapping; public final Resource Mapping_VertexMapping_ElevationAttribute; public final Resource Mapping_VertexMapping_ElevationAttribute_Inverse; + public final Resource Mapping_VertexMapping_PressureAttribute; + public final Resource Mapping_VertexMapping_PressureAttribute_Inverse; + public final Resource Mapping_VertexMapping_TemperatureAttribute; + public final Resource Mapping_VertexMapping_TemperatureAttribute_Inverse; public final Resource SpatialRefSystem; public final Resource Vertex; public final Resource VertexDefaultMapping; @@ -85,6 +95,10 @@ public class DistrictNetworkResource { public final Resource VertexMappingParameterType; public final Resource Vertex_HasElevation; public final Resource Vertex_HasElevation_Inverse; + public final Resource Vertex_HasPressure; + public final Resource Vertex_HasPressure_Inverse; + public final Resource Vertex_HasTemperature; + public final Resource Vertex_HasTemperature_Inverse; public static class URIs { public static final String ActionContext = "http://www.simantics.org/DistrictNetwork-1.0/ActionContext"; @@ -106,6 +120,8 @@ public class DistrictNetworkResource { public static final String Edge_HasDiameter_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasDiameter/Inverse"; public static final String Edge_HasLength = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasLength"; public static final String Edge_HasLength_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasLength/Inverse"; + public static final String Edge_HasNominalMassFlow = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasNominalMassFlow"; + public static final String Edge_HasNominalMassFlow_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasNominalMassFlow/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"; @@ -144,6 +160,10 @@ public class DistrictNetworkResource { 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 Mapping_EdgeMapping_LengthAttribute_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/LengthAttribute/Inverse"; + public static final String Mapping_EdgeMapping_NominalMassFlowAttribute = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/NominalMassFlowAttribute"; + public static final String Mapping_EdgeMapping_NominalMassFlowAttribute_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/NominalMassFlowAttribute/Inverse"; + public static final String Mapping_EdgeMapping_OuterDiameterAttribute = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/OuterDiameterAttribute"; + public static final String Mapping_EdgeMapping_OuterDiameterAttribute_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/OuterDiameterAttribute/Inverse"; public static final String Mapping_InputTerminal = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/InputTerminal"; public static final String Mapping_InputTerminal_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/InputTerminal/Inverse"; public static final String Mapping_OutputTerminal = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/OutputTerminal"; @@ -155,6 +175,10 @@ public class DistrictNetworkResource { public static final String Mapping_VertexMapping = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/VertexMapping"; public static final String Mapping_VertexMapping_ElevationAttribute = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/VertexMapping/ElevationAttribute"; public static final String Mapping_VertexMapping_ElevationAttribute_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/VertexMapping/ElevationAttribute/Inverse"; + public static final String Mapping_VertexMapping_PressureAttribute = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/VertexMapping/PressureAttribute"; + public static final String Mapping_VertexMapping_PressureAttribute_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/VertexMapping/PressureAttribute/Inverse"; + public static final String Mapping_VertexMapping_TemperatureAttribute = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/VertexMapping/TemperatureAttribute"; + public static final String Mapping_VertexMapping_TemperatureAttribute_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/VertexMapping/TemperatureAttribute/Inverse"; public static final String SpatialRefSystem = "http://www.simantics.org/DistrictNetwork-1.0/SpatialRefSystem"; public static final String Vertex = "http://www.simantics.org/DistrictNetwork-1.0/Vertex"; public static final String VertexDefaultMapping = "http://www.simantics.org/DistrictNetwork-1.0/VertexDefaultMapping"; @@ -162,6 +186,10 @@ public class DistrictNetworkResource { 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 final String Vertex_HasPressure = "http://www.simantics.org/DistrictNetwork-1.0/Vertex/HasPressure"; + public static final String Vertex_HasPressure_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Vertex/HasPressure/Inverse"; + public static final String Vertex_HasTemperature = "http://www.simantics.org/DistrictNetwork-1.0/Vertex/HasTemperature"; + public static final String Vertex_HasTemperature_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Vertex/HasTemperature/Inverse"; } public static Resource getResourceOrNull(ReadGraph graph, String uri) { @@ -193,6 +221,8 @@ public class DistrictNetworkResource { Edge_HasDiameter_Inverse = getResourceOrNull(graph, URIs.Edge_HasDiameter_Inverse); Edge_HasLength = getResourceOrNull(graph, URIs.Edge_HasLength); Edge_HasLength_Inverse = getResourceOrNull(graph, URIs.Edge_HasLength_Inverse); + Edge_HasNominalMassFlow = getResourceOrNull(graph, URIs.Edge_HasNominalMassFlow); + Edge_HasNominalMassFlow_Inverse = getResourceOrNull(graph, URIs.Edge_HasNominalMassFlow_Inverse); Edge_HasOuterDiameter = getResourceOrNull(graph, URIs.Edge_HasOuterDiameter); Edge_HasOuterDiameter_Inverse = getResourceOrNull(graph, URIs.Edge_HasOuterDiameter_Inverse); Functions = getResourceOrNull(graph, URIs.Functions); @@ -231,6 +261,10 @@ public class DistrictNetworkResource { Mapping_EdgeMapping_DiameterAttribute_Inverse = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_DiameterAttribute_Inverse); Mapping_EdgeMapping_LengthAttribute = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_LengthAttribute); Mapping_EdgeMapping_LengthAttribute_Inverse = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_LengthAttribute_Inverse); + Mapping_EdgeMapping_NominalMassFlowAttribute = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_NominalMassFlowAttribute); + Mapping_EdgeMapping_NominalMassFlowAttribute_Inverse = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_NominalMassFlowAttribute_Inverse); + Mapping_EdgeMapping_OuterDiameterAttribute = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_OuterDiameterAttribute); + Mapping_EdgeMapping_OuterDiameterAttribute_Inverse = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_OuterDiameterAttribute_Inverse); Mapping_InputTerminal = getResourceOrNull(graph, URIs.Mapping_InputTerminal); Mapping_InputTerminal_Inverse = getResourceOrNull(graph, URIs.Mapping_InputTerminal_Inverse); Mapping_OutputTerminal = getResourceOrNull(graph, URIs.Mapping_OutputTerminal); @@ -242,6 +276,10 @@ public class DistrictNetworkResource { Mapping_VertexMapping = getResourceOrNull(graph, URIs.Mapping_VertexMapping); Mapping_VertexMapping_ElevationAttribute = getResourceOrNull(graph, URIs.Mapping_VertexMapping_ElevationAttribute); Mapping_VertexMapping_ElevationAttribute_Inverse = getResourceOrNull(graph, URIs.Mapping_VertexMapping_ElevationAttribute_Inverse); + Mapping_VertexMapping_PressureAttribute = getResourceOrNull(graph, URIs.Mapping_VertexMapping_PressureAttribute); + Mapping_VertexMapping_PressureAttribute_Inverse = getResourceOrNull(graph, URIs.Mapping_VertexMapping_PressureAttribute_Inverse); + Mapping_VertexMapping_TemperatureAttribute = getResourceOrNull(graph, URIs.Mapping_VertexMapping_TemperatureAttribute); + Mapping_VertexMapping_TemperatureAttribute_Inverse = getResourceOrNull(graph, URIs.Mapping_VertexMapping_TemperatureAttribute_Inverse); SpatialRefSystem = getResourceOrNull(graph, URIs.SpatialRefSystem); Vertex = getResourceOrNull(graph, URIs.Vertex); VertexDefaultMapping = getResourceOrNull(graph, URIs.VertexDefaultMapping); @@ -249,6 +287,10 @@ public class DistrictNetworkResource { VertexMappingParameterType = getResourceOrNull(graph, URIs.VertexMappingParameterType); Vertex_HasElevation = getResourceOrNull(graph, URIs.Vertex_HasElevation); Vertex_HasElevation_Inverse = getResourceOrNull(graph, URIs.Vertex_HasElevation_Inverse); + Vertex_HasPressure = getResourceOrNull(graph, URIs.Vertex_HasPressure); + Vertex_HasPressure_Inverse = getResourceOrNull(graph, URIs.Vertex_HasPressure_Inverse); + Vertex_HasTemperature = getResourceOrNull(graph, URIs.Vertex_HasTemperature); + Vertex_HasTemperature_Inverse = getResourceOrNull(graph, URIs.Vertex_HasTemperature_Inverse); } public static DistrictNetworkResource getInstance(ReadGraph graph) { 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 c150654c..8187002b 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 @@ -43,7 +43,7 @@ public class DistrictDiagramViewer extends DiagramViewer { super.initializeCanvasContext(ctx); IHintContext h = ctx.getDefaultHintContext(); h.setHint(PanZoomRotateHandler.KEY_ZOOM_IN_LIMIT, 1000000.0); - h.setHint(PanZoomRotateHandler.KEY_ZOOM_OUT_LIMIT, 0.01); + h.setHint(PanZoomRotateHandler.KEY_ZOOM_OUT_LIMIT, 0.003); } @Override