]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportModel.java
Updates to Simantics district CSV import
[simantics/district.git] / org.simantics.district.imports.ui / src / org / simantics / district / imports / ui / CSVImportModel.java
index 1521a926c233005eef708058f478dbd5f8641886..2f13692bd0af5f49dcc3f8289084c3bccc551a69 100644 (file)
@@ -3,20 +3,52 @@ package org.simantics.district.imports.ui;
 import java.io.IOException;
 import java.nio.file.Path;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import org.apache.commons.csv.CSVRecord;
+import org.simantics.db.Resource;
 import org.simantics.district.imports.DistrictImportUtils;
 import org.simantics.district.imports.DistrictImportUtils.CSVHeader;
 
 public class CSVImportModel {
 
+    // First page fills these
+    private Resource targetDiagram;
     private Path source;
+    
+    // Second page fills these
     private char delimiter;
-    private boolean read;
+    private boolean readFirstAsHeader = true;
     private Map<String, Character> delimiters;
-    private Path wktFile;
+//    private Path wktFile;
+    
+    // Vertex import
+    private int xCoordIndex = -1;
+    private int yCoordIndex = -1;
+    private int zCoordIndex = -1;
+    
+    // Edge import
+    private int startXCoordIndex = -1;
+    private int startYCoordIndex = -1;
+    private int startZCoordIndex = -1;
+    private int endXCoordIndex = -1;
+    private int endYCoordIndex = -1;
+    private int endZCoordIndex = -1;
+    
+    // common
+    private int componentMappingIndex = -1;
+    private Map<String, Resource> 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
 
     public CSVImportModel() {
         delimiters = DistrictImportUtils.getSupportedCSVDelimiterFormats();
@@ -31,7 +63,7 @@ public class CSVImportModel {
     }
 
     public void setReadFirstAsHeader(boolean read) {
-        this.read = read;
+        this.readFirstAsHeader = read;
     }
 
     public Path getSource() {
@@ -47,7 +79,7 @@ public class CSVImportModel {
     
     public Map<CSVHeader, List<String>> 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();
     }
@@ -55,14 +87,14 @@ public class CSVImportModel {
     public Map<String, Integer> getHeader() throws IOException {
         Map<String, Integer> 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() {
@@ -75,7 +107,7 @@ public class CSVImportModel {
 
     public List<Map<String, String>> 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();
     }
@@ -84,7 +116,164 @@ public class CSVImportModel {
         return delimiter;
     }
 
-    public Path getWKTFile() {
-        return wktFile;
+//    public Path getWKTFile() {
+//        return wktFile;
+//    }
+
+    public int getXCoordIndex() {
+        return xCoordIndex;
+    }
+
+    public void setXCoordIndex(int xCoordIndex) {
+        this.xCoordIndex = xCoordIndex;
+    }
+
+    public int getYCoordIndex() {
+        return yCoordIndex;
+    }
+
+    public void setYCoordIndex(int yCoordIndex) {
+        this.yCoordIndex = yCoordIndex;
+    }
+
+    public int getZCoordIndex() {
+        return zCoordIndex;
+    }
+
+    public void setZCoordIndex(int zCoordIndex) {
+        this.zCoordIndex = zCoordIndex;
+    }
+
+    public int getComponentMappingIndex() {
+        return componentMappingIndex;
+    }
+    
+    public void setComponentMappingIndex(int componentMappingIndex) {
+        this.componentMappingIndex = componentMappingIndex;
+    }
+
+    public void setParentDiagram(Resource diagram) {
+        this.targetDiagram = diagram;
+    }
+
+    public Resource getParentDiagram() {
+        return targetDiagram;
+    }
+
+//    public void setWKTFile(Path wktFile) {
+//        this.wktFile = wktFile;
+//    }
+
+    public void setComponentMappings(String value, Resource resource) {
+        componentMappings.put(value, resource);
+    }
+
+    public Map<String, Resource> getComponentMappings() {
+        return componentMappings;
+    }
+
+    public boolean isVertexImport() {
+        return isVertexImport;
+    }
+    
+    public void setVertexImport(boolean isVertexImport) {
+        this.isVertexImport = isVertexImport;
+    }
+
+    public void setStartXCoordIndex(int parseInt) {
+        this.startXCoordIndex = parseInt;
+    }
+    
+    public int getStartXCoordIndex() {
+        return startXCoordIndex;
+    }
+
+    public void setStartYCoordIndex(int parseInt) {
+        this.startYCoordIndex = parseInt;
+    }
+    
+    public int getStartYCoordIndex() {
+        return startYCoordIndex;
+    }
+
+    public void setStartZCoordIndex(int parseInt) {
+        this.startZCoordIndex = parseInt;
+    }
+    
+    public int getStartZCoordIndex() {
+        return startZCoordIndex;
+    }
+
+    public void setEndXCoordIndex(int parseInt) {
+        this.endXCoordIndex = parseInt;
     }
+    
+    public int getEndXCoordIndex() {
+        return endXCoordIndex;
+    }
+
+    public void setEndYCoordIndex(int parseInt) {
+        this.endYCoordIndex = parseInt;
+    }
+    
+    public int getEndYCoordIndex() {
+        return endYCoordIndex;
+    }
+
+    public void setEndZCoordIndex(int parseInt) {
+        this.endZCoordIndex = parseInt;
+    }
+    
+    public int getEndZCoordIndex() {
+        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;
+    }
+
 }