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