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