1 package org.simantics.district.imports;
3 import java.io.IOException;
4 import java.nio.file.Path;
5 import java.util.Collections;
6 import java.util.HashMap;
10 import org.apache.commons.csv.CSVFormat;
11 import org.apache.commons.csv.CSVRecord;
12 import org.simantics.db.Resource;
13 import org.simantics.district.imports.DistrictImportUtils.CSVHeader;
15 public class CSVImportModel {
17 // First page fills these
18 private Resource targetDiagram;
21 // Second page fills these
22 private char delimiter;
23 private boolean readFirstAsHeader = true;
24 private Map<String, Character> delimiters;
25 // private Path wktFile;
28 private int xCoordIndex = -1;
29 private int yCoordIndex = -1;
30 private int zCoordIndex = -1;
33 private int startXCoordIndex = -1;
34 private int startYCoordIndex = -1;
35 private int startZCoordIndex = -1;
36 private int endXCoordIndex = -1;
37 private int endYCoordIndex = -1;
38 private int endZCoordIndex = -1;
41 private int componentMappingIndex = -1;
42 private Map<String, Resource> componentMappings = new HashMap<>();
43 private boolean isVertexImport;
44 private String sourceCRS;
45 private int supplytempIndex = -1;
46 private int supplypressureIndex= -1;
47 private int diameterIndex = -1;
48 private int outerDiamterIndex = -1;
49 private int nominalMassFlowIndex = -1;
50 private int returnTempIndex = -1;
51 private int returnPressureIndex = -1;
52 private int deltaPressureIndex = -1;
53 private int deltaTemperatureIndex = -1;
54 private int heatPowerIndex = -1;
55 private int nominalHeadMIndex = -1;
56 private int nominalHeadBIndex = -1;
57 private int nominalFlowIndex = -1;
58 private int maximumHeadMIndex = -1;
59 private int heatLoadDsIndex = -1;
60 private int massFlowIndex = -1;
61 private int volFlowIndex = -1;
62 private int velocityIndex = -1;
63 private int flowAreaIndex = -1;
64 private int nominalPressureLossIndex = -1;
65 private int edgeFlowAreaIndex = -1;
66 private int kReturnIndex = -1;
67 private int kSupplyIndex = -1;
68 private int tGroundIndex = -1;
69 private int idIndex = -1;
70 private double edgePadding = 0.0001; // default
71 private int valvePositionIndx = -1;
72 private int addressIndex = -1;
73 private int lengthIndex = -1;
74 private int detailedGeometryIndex = -1;
78 public CSVImportModel() {
79 delimiters = DistrictImportUtils.getSupportedCSVDelimiterFormats();
82 public void setSource(Path source) {
86 public void setDelimiter(char delimiter) {
87 this.delimiter = delimiter;
90 public void setReadFirstAsHeader(boolean read) {
91 this.readFirstAsHeader = read;
94 public Path getSource() {
98 public List<CSVRecord> getRows(int amount, boolean readFirstAsHeader) throws IOException {
100 return DistrictImportUtils.readRows(source, delimiter, readFirstAsHeader, amount);
102 return Collections.emptyList();
105 public Map<CSVHeader, List<String>> getHeaderAndRows(int amount) throws IOException {
107 return DistrictImportUtils.readCSVHeaderAndRows(source, delimiter, readFirstAsHeader, amount);
109 return Collections.emptyMap();
112 public Map<String, Integer> getHeader() throws IOException {
113 Map<String, Integer> header = null;
115 header = DistrictImportUtils.readCSVHeader(source, delimiter, readFirstAsHeader);
117 header = Collections.emptyMap();
121 public boolean getReadFirstAsHeader() {
122 return readFirstAsHeader;
125 public String[] getDelimiterFormats() {
126 return delimiters.keySet().toArray(new String[delimiters.size()]);
129 public void setDelimiterByLabel(String item) {
130 setDelimiter(delimiters.get(item));
133 public List<Map<String, String>> readRows(int amount) throws IOException {
135 return DistrictImportUtils.readRows(source, CSVFormat.newFormat(delimiter), readFirstAsHeader, amount);
137 return Collections.emptyList();
140 public char getDelimiter() {
144 // public Path getWKTFile() {
148 public int getXCoordIndex() {
152 public void setXCoordIndex(int xCoordIndex) {
153 this.xCoordIndex = xCoordIndex;
156 public int getYCoordIndex() {
160 public void setYCoordIndex(int yCoordIndex) {
161 this.yCoordIndex = yCoordIndex;
164 public int getZCoordIndex() {
168 public void setZCoordIndex(int zCoordIndex) {
169 this.zCoordIndex = zCoordIndex;
172 public int getComponentMappingIndex() {
173 return componentMappingIndex;
176 public void setComponentMappingIndex(int componentMappingIndex) {
177 this.componentMappingIndex = componentMappingIndex;
180 public void setParentDiagram(Resource diagram) {
181 this.targetDiagram = diagram;
184 public Resource getParentDiagram() {
185 return targetDiagram;
188 // public void setWKTFile(Path wktFile) {
189 // this.wktFile = wktFile;
192 public void setComponentMappings(String value, Resource resource) {
193 componentMappings.put(value, resource);
196 public Map<String, Resource> getComponentMappings() {
197 return componentMappings;
200 public boolean isVertexImport() {
201 return isVertexImport;
204 public void setVertexImport(boolean isVertexImport) {
205 this.isVertexImport = isVertexImport;
208 public void setStartXCoordIndex(int parseInt) {
209 this.startXCoordIndex = parseInt;
212 public int getStartXCoordIndex() {
213 return startXCoordIndex;
216 public void setStartYCoordIndex(int parseInt) {
217 this.startYCoordIndex = parseInt;
220 public int getStartYCoordIndex() {
221 return startYCoordIndex;
224 public void setStartZCoordIndex(int parseInt) {
225 this.startZCoordIndex = parseInt;
228 public int getStartZCoordIndex() {
229 return startZCoordIndex;
232 public void setEndXCoordIndex(int parseInt) {
233 this.endXCoordIndex = parseInt;
236 public int getEndXCoordIndex() {
237 return endXCoordIndex;
240 public void setEndYCoordIndex(int parseInt) {
241 this.endYCoordIndex = parseInt;
244 public int getEndYCoordIndex() {
245 return endYCoordIndex;
248 public void setEndZCoordIndex(int parseInt) {
249 this.endZCoordIndex = parseInt;
252 public int getEndZCoordIndex() {
253 return endZCoordIndex;
256 public void setSourceCRS(String crs) {
257 this.sourceCRS = crs;
260 public String getSourceCRS() {
264 public void setSupplyTempIndex(int supplyTempIndex) {
265 this.supplytempIndex = supplyTempIndex;
268 public int getSupplyTempIndex() {
269 return supplytempIndex;
272 public void setSupplyPressureIndex(int supplyPressureIndex) {
273 this.supplypressureIndex = supplyPressureIndex;
276 public int getSupplyPressureIndex() {
277 return supplypressureIndex;
280 public void setReturnTempIndex(int returnTempIndex) {
281 this.returnTempIndex = returnTempIndex;
284 public int getReturnTempIndex() {
285 return returnTempIndex;
288 public void setReturnPressureIndex(int returnPressureIndex) {
289 this.returnPressureIndex = returnPressureIndex;
292 public int getReturnPressureIndex() {
293 return returnPressureIndex;
296 public void setDiameterIndex(int parseInt) {
297 this.diameterIndex = parseInt;
300 public int getDiameterIndex() {
301 return diameterIndex;
304 public void setOuterDiameterIndex(int parseInt) {
305 this.outerDiamterIndex = parseInt;
308 public int getOuterDiamterIndex() {
309 return outerDiamterIndex;
312 public void setNominalMassFlowIndex(int parseInt) {
313 this.nominalMassFlowIndex = parseInt;
316 public int getNominalMassFlowIndex() {
317 return nominalMassFlowIndex;
320 public void setDeltaPressureIndex(int parseInt) {
321 this.deltaPressureIndex = parseInt;
324 public int getDeltaPressureIndex() {
325 return deltaPressureIndex;
328 public void setDeltaTemperatureIndex(int parseInt) {
329 this.deltaTemperatureIndex = parseInt;
332 public int getDeltaTemperatureIndex() {
333 return deltaTemperatureIndex;
336 public void setHeatPowerIndex(int parseInt) {
337 this.heatPowerIndex = parseInt;
340 public int getHeatPowerIndex() {
341 return heatPowerIndex;
344 public void setNominalHeadMIndex(int parseInt) {
345 this.nominalHeadMIndex = parseInt;
348 public int getNominalHeadMIndex() {
349 return nominalHeadMIndex;
352 public void setNominalHeadBIndex(int parseInt) {
353 this.nominalHeadBIndex = parseInt;
356 public int getNominalHeadBIndex() {
357 return nominalHeadBIndex;
360 public void setNominalFlowIndex(int parseInt) {
361 this.nominalFlowIndex = parseInt;
364 public int getNominalFlowIndex() {
365 return nominalFlowIndex;
368 public void setMaximumHeadMIndex(int parseInt) {
369 this.maximumHeadMIndex = parseInt;
372 public int getMaximumHeadMIndex() {
373 return maximumHeadMIndex;
376 public void setHeatLoadDsIndex(int parseInt) {
377 this.heatLoadDsIndex = parseInt;
380 public int getHeatLoadDsIndex() {
381 return heatLoadDsIndex;
384 public void setMassFlowIndex(int parseInt) {
385 this.massFlowIndex = parseInt;
388 public int getMassFlowIndex() {
389 return massFlowIndex;
392 public void setVolFlowIndex(int parseInt) {
393 this.volFlowIndex = parseInt;
396 public int getVolFlowIndex() {
400 public void setVelocityIndex(int parseInt) {
401 this.velocityIndex = parseInt;
404 public int getVelocityIndex() {
405 return velocityIndex;
408 public void setFlowAreaIndex(int parseInt) {
409 this.flowAreaIndex = parseInt;
412 public int getFlowAreaIndex() {
413 return flowAreaIndex;
416 public void setNominalPressureLossIndex(int parseInt) {
417 this.nominalPressureLossIndex = parseInt;
420 public int getNominalPressureLossIndex() {
421 return nominalPressureLossIndex;
424 public void setEdgeFlowAreaIndex(int parseInt) {
425 this.edgeFlowAreaIndex = parseInt;
428 public int getEdgeFlowAreaIndex() {
429 return edgeFlowAreaIndex;
432 public void setKReturnIndex(int parseInt) {
433 this.kReturnIndex = parseInt;
436 public int getkReturnIndex() {
440 public void setKSupplyIndex(int parseInt) {
441 this.kSupplyIndex = parseInt;
444 public int getkSupplyIndex() {
448 public void setTGroundIndex(int parseInt) {
449 this.tGroundIndex = parseInt;
452 public int gettGroundIndex() {
456 public int getIdIndex() {
460 public void setIdIndex(int idIndex) {
461 this.idIndex = idIndex;
464 public void setEdgePadding(double edgePadding) {
465 this.edgePadding = edgePadding;
468 public double getEdgePadding() {
472 public void setValvePositionIndex(int valvePositionIndx) {
473 this.valvePositionIndx = valvePositionIndx;
476 public int getValvePositionIndx() {
477 return valvePositionIndx;
480 public void setAddressIndex(int parseInt) {
481 this.addressIndex = parseInt;
484 public int getAddressIndex() {
488 public int getLengthIndex() {
492 public void setLengthIndex(int lengthIndex) {
493 this.lengthIndex = lengthIndex;
496 public void detailedGeometryIndex(int detailedGeometryIndex) {
497 this.detailedGeometryIndex = detailedGeometryIndex;
500 public int getDetailedGeometryIndex() {
501 return detailedGeometryIndex;