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