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