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