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