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