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