]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.district.imports/src/org/simantics/district/imports/CSVImportModel.java
ac422300f8b65a4c9586302b355cf3332e3a7ce0
[simantics/district.git] / org.simantics.district.imports / src / org / simantics / district / imports / CSVImportModel.java
1 package org.simantics.district.imports;
2
3 import java.io.IOException;
4 import java.nio.file.Path;
5 import java.util.Collections;
6 import java.util.HashMap;
7 import java.util.List;
8 import java.util.Map;
9
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;
14
15 public class CSVImportModel {
16
17     // First page fills these
18     private Resource targetDiagram;
19     private Path source;
20     
21     // Second page fills these
22     private char delimiter;
23     private boolean readFirstAsHeader = true;
24     private Map<String, Character> delimiters;
25 //    private Path wktFile;
26     
27     // Vertex import
28     private int xCoordIndex = -1;
29     private int yCoordIndex = -1;
30     private int zCoordIndex = -1;
31     private int altElevationIndex = -1;
32     
33     // Edge import
34     private int startXCoordIndex = -1;
35     private int startYCoordIndex = -1;
36     private int startZCoordIndex = -1;
37     private int endXCoordIndex = -1;
38     private int endYCoordIndex = -1;
39     private int endZCoordIndex = -1;
40     
41     // common
42     private int componentMappingIndex = -1;
43     private Map<String, Resource> componentMappings = new HashMap<>();
44     private boolean isVertexImport;
45     private String sourceCRS;
46     private int supplytempIndex = -1;
47     private int supplypressureIndex= -1;
48     private int diameterIndex = -1;
49     private int outerDiamterIndex = -1;
50     private int nominalMassFlowIndex = -1;
51     private int returnTempIndex = -1;
52     private int returnPressureIndex = -1;
53     private int deltaPressureIndex = -1;
54     private int deltaTemperatureIndex = -1;
55     private int heatPowerIndex = -1;
56     private int nominalHeadMIndex = -1;
57     private int nominalHeadBIndex = -1;
58     private int nominalFlowIndex = -1;
59     private int maximumHeadMIndex = -1;
60     private int heatLoadDsIndex = -1;
61     private int massFlowIndex = -1;
62     private int volFlowIndex = -1;
63     private int velocityIndex = -1;
64     private int flowAreaIndex = -1;
65     private int nominalPressureLossIndex = -1;
66     private int edgeFlowAreaIndex = -1;
67     private int kReturnIndex = -1;
68     private int kSupplyIndex = -1;
69     private int tGroundIndex = -1;
70     private int idIndex = -1;
71     private double edgePadding = 0.0001; // default
72     private int valvePositionIndx = -1;
73     private int addressIndex = -1;
74     private int lengthIndex = -1;
75     private int detailedGeometryIndex = -1;
76     private int peakPowerIndex = -1;
77     private int regionIndex = -1;
78     private int pipeTypeIndex = -1;
79     private int pipeCodeIndex = -1;
80     private int installationYearIndex = -1;
81     private int wallThicknessIndex = -1;
82     private int insulationConductivityIndex = -1;
83     private int pipeSizeDNIndex = -1;
84     private int roughnessIndex = -1;
85     private int structureIndex = -1;
86     
87     // Third page
88
89     public CSVImportModel() {
90         delimiters = DistrictImportUtils.getSupportedCSVDelimiterFormats();
91     }
92     
93     public void setSource(Path source) {
94         this.source = source;
95     }
96
97     public void setDelimiter(char delimiter) {
98         this.delimiter = delimiter;
99     }
100
101     public void setReadFirstAsHeader(boolean read) {
102         this.readFirstAsHeader = read;
103     }
104
105     public Path getSource() {
106         return source;
107     }
108
109     public List<CSVRecord> getRows(int amount, boolean readFirstAsHeader) throws IOException {
110         if (source != null)
111             return DistrictImportUtils.readRows(source, delimiter, readFirstAsHeader, amount);
112         else
113             return Collections.emptyList();
114     }
115     
116     public Map<CSVHeader, List<String>> getHeaderAndRows(int amount) throws IOException {
117         if (source != null)
118             return DistrictImportUtils.readCSVHeaderAndRows(source, delimiter, readFirstAsHeader, amount);
119         else
120             return Collections.emptyMap();
121     }
122     
123     public Map<String, Integer> getHeader() throws IOException {
124         Map<String, Integer> header = null;
125         if (source != null)
126             header = DistrictImportUtils.readCSVHeader(source, delimiter, readFirstAsHeader);
127         if (header == null)
128             header = Collections.emptyMap();
129         return header;
130     }
131
132     public boolean getReadFirstAsHeader() {
133         return readFirstAsHeader;
134     }
135
136     public String[] getDelimiterFormats() {
137         return delimiters.keySet().toArray(new String[delimiters.size()]);
138     }
139
140     public void setDelimiterByLabel(String item) {
141         setDelimiter(delimiters.get(item));
142     }
143
144     public List<Map<String, String>> readRows(int amount) throws IOException {
145         if (source != null)
146             return DistrictImportUtils.readRows(source, CSVFormat.newFormat(delimiter), readFirstAsHeader, amount);
147         else
148             return Collections.emptyList();
149     }
150
151     public char getDelimiter() {
152         return delimiter;
153     }
154
155 //    public Path getWKTFile() {
156 //        return wktFile;
157 //    }
158
159     public int getXCoordIndex() {
160         return xCoordIndex;
161     }
162
163     public void setXCoordIndex(int xCoordIndex) {
164         this.xCoordIndex = xCoordIndex;
165     }
166
167     public int getYCoordIndex() {
168         return yCoordIndex;
169     }
170
171     public void setYCoordIndex(int yCoordIndex) {
172         this.yCoordIndex = yCoordIndex;
173     }
174
175     public int getZCoordIndex() {
176         return zCoordIndex;
177     }
178
179     public void setZCoordIndex(int zCoordIndex) {
180         this.zCoordIndex = zCoordIndex;
181     }
182
183     public int getComponentMappingIndex() {
184         return componentMappingIndex;
185     }
186     
187     public void setComponentMappingIndex(int componentMappingIndex) {
188         this.componentMappingIndex = componentMappingIndex;
189     }
190
191     public void setParentDiagram(Resource diagram) {
192         this.targetDiagram = diagram;
193     }
194
195     public Resource getParentDiagram() {
196         return targetDiagram;
197     }
198
199 //    public void setWKTFile(Path wktFile) {
200 //        this.wktFile = wktFile;
201 //    }
202
203     public void setComponentMappings(String value, Resource resource) {
204         componentMappings.put(value, resource);
205     }
206
207     public Map<String, Resource> getComponentMappings() {
208         return componentMappings;
209     }
210
211     public boolean isVertexImport() {
212         return isVertexImport;
213     }
214     
215     public void setVertexImport(boolean isVertexImport) {
216         this.isVertexImport = isVertexImport;
217     }
218
219     public void setStartXCoordIndex(int parseInt) {
220         this.startXCoordIndex = parseInt;
221     }
222     
223     public int getStartXCoordIndex() {
224         return startXCoordIndex;
225     }
226
227     public void setStartYCoordIndex(int parseInt) {
228         this.startYCoordIndex = parseInt;
229     }
230     
231     public int getStartYCoordIndex() {
232         return startYCoordIndex;
233     }
234
235     public void setStartZCoordIndex(int parseInt) {
236         this.startZCoordIndex = parseInt;
237     }
238     
239     public int getStartZCoordIndex() {
240         return startZCoordIndex;
241     }
242
243     public void setEndXCoordIndex(int parseInt) {
244         this.endXCoordIndex = parseInt;
245     }
246     
247     public int getEndXCoordIndex() {
248         return endXCoordIndex;
249     }
250
251     public void setEndYCoordIndex(int parseInt) {
252         this.endYCoordIndex = parseInt;
253     }
254     
255     public int getEndYCoordIndex() {
256         return endYCoordIndex;
257     }
258
259     public void setEndZCoordIndex(int parseInt) {
260         this.endZCoordIndex = parseInt;
261     }
262     
263     public int getEndZCoordIndex() {
264         return endZCoordIndex;
265     }
266
267     public void setSourceCRS(String crs) {
268         this.sourceCRS = crs;
269     }
270
271     public String getSourceCRS() {
272         return sourceCRS;
273     }
274
275     public void setSupplyTempIndex(int supplyTempIndex) {
276         this.supplytempIndex = supplyTempIndex;
277     }
278     
279     public int getSupplyTempIndex() {
280         return supplytempIndex;
281     }
282
283     public void setSupplyPressureIndex(int supplyPressureIndex) {
284         this.supplypressureIndex = supplyPressureIndex;
285     }
286
287     public int getSupplyPressureIndex() {
288         return supplypressureIndex;
289     }
290
291     public void setReturnTempIndex(int returnTempIndex) {
292         this.returnTempIndex = returnTempIndex;
293     }
294     
295     public int getReturnTempIndex() {
296         return returnTempIndex;
297     }
298
299     public void setReturnPressureIndex(int returnPressureIndex) {
300         this.returnPressureIndex = returnPressureIndex;
301     }
302
303     public int getReturnPressureIndex() {
304         return returnPressureIndex;
305     }
306
307     public void setDiameterIndex(int parseInt) {
308         this.diameterIndex = parseInt;
309     }
310     
311     public int getDiameterIndex() {
312         return diameterIndex;
313     }
314
315     public void setOuterDiameterIndex(int parseInt) {
316         this.outerDiamterIndex = parseInt;
317     }
318     
319     public int getOuterDiamterIndex() {
320         return outerDiamterIndex;
321     }
322
323     public void setNominalMassFlowIndex(int parseInt) {
324         this.nominalMassFlowIndex = parseInt;
325     }
326     
327     public int getNominalMassFlowIndex() {
328         return nominalMassFlowIndex;
329     }
330
331     public void setDeltaPressureIndex(int parseInt) {
332         this.deltaPressureIndex = parseInt;
333     }
334     
335     public int getDeltaPressureIndex() {
336         return deltaPressureIndex;
337     }
338
339     public void setDeltaTemperatureIndex(int parseInt) {
340         this.deltaTemperatureIndex = parseInt;
341     }
342     
343     public int getDeltaTemperatureIndex() {
344         return deltaTemperatureIndex;
345     }
346
347     public void setHeatPowerIndex(int parseInt) {
348         this.heatPowerIndex = parseInt;
349     }
350     
351     public int getHeatPowerIndex() {
352         return heatPowerIndex;
353     }
354
355     public void setNominalHeadMIndex(int parseInt) {
356         this.nominalHeadMIndex = parseInt;
357     }
358     
359     public int getNominalHeadMIndex() {
360         return nominalHeadMIndex;
361     }
362
363     public void setNominalHeadBIndex(int parseInt) {
364         this.nominalHeadBIndex = parseInt;
365     }
366     
367     public int getNominalHeadBIndex() {
368         return nominalHeadBIndex;
369     }
370
371     public void setNominalFlowIndex(int parseInt) {
372         this.nominalFlowIndex = parseInt;
373     }
374     
375     public int getNominalFlowIndex() {
376         return nominalFlowIndex;
377     }
378
379     public void setMaximumHeadMIndex(int parseInt) {
380         this.maximumHeadMIndex = parseInt;
381     }
382     
383     public int getMaximumHeadMIndex() {
384         return maximumHeadMIndex;
385     }
386
387     public void setHeatLoadDsIndex(int parseInt) {
388         this.heatLoadDsIndex = parseInt;
389     }
390     
391     public int getHeatLoadDsIndex() {
392         return heatLoadDsIndex;
393     }
394
395     public void setMassFlowIndex(int parseInt) {
396         this.massFlowIndex = parseInt;
397     }
398     
399     public int getMassFlowIndex() {
400         return massFlowIndex;
401     }
402
403     public void setVolFlowIndex(int parseInt) {
404         this.volFlowIndex = parseInt;
405     }
406     
407     public int getVolFlowIndex() {
408         return volFlowIndex;
409     }
410
411     public void setVelocityIndex(int parseInt) {
412         this.velocityIndex = parseInt;
413     }
414     
415     public int getVelocityIndex() {
416         return velocityIndex;
417     }
418
419     public void setFlowAreaIndex(int parseInt) {
420         this.flowAreaIndex = parseInt;
421     }
422     
423     public int getFlowAreaIndex() {
424         return flowAreaIndex;
425     }
426
427     public void setNominalPressureLossIndex(int parseInt) {
428         this.nominalPressureLossIndex = parseInt;
429     }
430     
431     public int getNominalPressureLossIndex() {
432         return nominalPressureLossIndex;
433     }
434
435     public void setEdgeFlowAreaIndex(int parseInt) {
436         this.edgeFlowAreaIndex = parseInt;
437     }
438     
439     public int getEdgeFlowAreaIndex() {
440         return edgeFlowAreaIndex;
441     }
442
443     public void setKReturnIndex(int parseInt) {
444         this.kReturnIndex = parseInt;
445     }
446     
447     public int getkReturnIndex() {
448         return kReturnIndex;
449     }
450
451     public void setKSupplyIndex(int parseInt) {
452         this.kSupplyIndex = parseInt;
453     }
454     
455     public int getkSupplyIndex() {
456         return kSupplyIndex;
457     }
458
459     public void setTGroundIndex(int parseInt) {
460         this.tGroundIndex = parseInt;
461     }
462     
463     public int gettGroundIndex() {
464         return tGroundIndex;
465     }
466
467     public int getIdIndex() {
468         return idIndex;
469     }
470     
471     public void setIdIndex(int idIndex) {
472         this.idIndex = idIndex;
473     }
474
475     public void setEdgePadding(double edgePadding) {
476         this.edgePadding = edgePadding;
477     }
478     
479     public double getEdgePadding() {
480         return edgePadding;
481     }
482
483     public void setValvePositionIndex(int valvePositionIndx) {
484         this.valvePositionIndx = valvePositionIndx;
485     }
486     
487     public int getValvePositionIndx() {
488         return valvePositionIndx;
489     }
490
491     public void setAddressIndex(int parseInt) {
492         this.addressIndex = parseInt;
493     }
494     
495     public int getAddressIndex() {
496         return addressIndex;
497     }
498
499     public int getLengthIndex() {
500         return lengthIndex;
501     }
502     
503     public void setLengthIndex(int lengthIndex) {
504         this.lengthIndex = lengthIndex;
505     }
506
507     public void detailedGeometryIndex(int detailedGeometryIndex) {
508         this.detailedGeometryIndex = detailedGeometryIndex;
509     }
510     
511     public int getDetailedGeometryIndex() {
512         return detailedGeometryIndex;
513     }
514
515     public int getAlternativeElevationIndex() {
516         return altElevationIndex;
517     }
518
519     public void setAltElevationIndex(int parseInt) {
520         this.altElevationIndex = parseInt;
521     }
522
523     public void setPeakPowerIndex(int parseInt) {
524         this.peakPowerIndex = parseInt;
525     }
526
527     public int getPeakPowerIndex() {
528         return peakPowerIndex;
529     }
530
531     public int getRegionIndex() {
532         return regionIndex;
533     }
534
535     public void setRegionIndex(int regionIndex) {
536         this.regionIndex = regionIndex;
537     }
538
539     public int getPipeTypeIndex() {
540         return pipeTypeIndex;
541     }
542
543     public void setPipeTypeIndex(int pipeTypeIndex) {
544         this.pipeTypeIndex = pipeTypeIndex;
545     }
546
547     public int getPipeCodeIndex() {
548         return pipeCodeIndex;
549     }
550
551     public void setPipeCodeIndex(int pipeCodeIndex) {
552         this.pipeCodeIndex = pipeCodeIndex;
553     }
554
555     public int getInstallationYearIndex() {
556         return installationYearIndex;
557     }
558
559     public void setInstallationYearIndex(int installationYearIndex) {
560         this.installationYearIndex = installationYearIndex;
561     }
562
563     public int getWallThicknessIndex() {
564         return wallThicknessIndex;
565     }
566
567     public void setWallThicknessIndex(int wallThicknessIndex) {
568         this.wallThicknessIndex = wallThicknessIndex;
569     }
570
571     public int getInsulationConductivityIndex() {
572         return insulationConductivityIndex;
573     }
574
575     public void setInsulationConductivityIndex(int insulationConductivityIndex) {
576         this.insulationConductivityIndex = insulationConductivityIndex;
577     }
578
579     public int getPipeSizeDNIndex() {
580         return pipeSizeDNIndex;
581     }
582
583     public void setPipeSizeDNIndex(int pipeSizeDNIndex) {
584         this.pipeSizeDNIndex = pipeSizeDNIndex;
585     }
586
587     public int getRoughnessIndex() {
588         return roughnessIndex;
589     }
590
591     public void setRoughnessIndex(int roughnessIndex) {
592         this.roughnessIndex = roughnessIndex;
593     }
594
595     public int getStructureIndex() {
596         return structureIndex;
597     }
598
599     public void setStructureIndex(int structureIndex) {
600         this.structureIndex = structureIndex;
601     }
602 }