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