1 package org.simantics.district.imports.ui;
3 import java.io.IOException;
4 import java.nio.file.Path;
5 import java.util.Collections;
6 import java.util.HashMap;
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;
16 public class CSVImportModel {
18 // First page fills these
19 private Resource targetDiagram;
22 // Second page fills these
23 private char delimiter;
24 private boolean readFirstAsHeader = true;
25 private Map<String, Character> delimiters;
26 // private Path wktFile;
29 private int xCoordIndex = -1;
30 private int yCoordIndex = -1;
31 private int zCoordIndex = -1;
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;
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;
79 public CSVImportModel() {
80 delimiters = DistrictImportUtils.getSupportedCSVDelimiterFormats();
83 public void setSource(Path source) {
87 public void setDelimiter(char delimiter) {
88 this.delimiter = delimiter;
91 public void setReadFirstAsHeader(boolean read) {
92 this.readFirstAsHeader = read;
95 public Path getSource() {
99 public List<CSVRecord> getRows(int amount, boolean readFirstAsHeader) throws IOException {
101 return DistrictImportUtils.readRows(source, delimiter, readFirstAsHeader, amount);
103 return Collections.emptyList();
106 public Map<CSVHeader, List<String>> getHeaderAndRows(int amount) throws IOException {
108 return DistrictImportUtils.readCSVHeaderAndRows(source, delimiter, readFirstAsHeader, amount);
110 return Collections.emptyMap();
113 public Map<String, Integer> getHeader() throws IOException {
114 Map<String, Integer> header = null;
116 header = DistrictImportUtils.readCSVHeader(source, delimiter, readFirstAsHeader);
118 header = Collections.emptyMap();
122 public boolean getReadFirstAsHeader() {
123 return readFirstAsHeader;
126 public String[] getDelimiterFormats() {
127 return delimiters.keySet().toArray(new String[delimiters.size()]);
130 public void setDelimiterByLabel(String item) {
131 setDelimiter(delimiters.get(item));
134 public List<Map<String, String>> readRows(int amount) throws IOException {
136 return DistrictImportUtils.readRows(source, CSVFormat.newFormat(delimiter), readFirstAsHeader, amount);
138 return Collections.emptyList();
141 public char getDelimiter() {
145 // public Path getWKTFile() {
149 public int getXCoordIndex() {
153 public void setXCoordIndex(int xCoordIndex) {
154 this.xCoordIndex = xCoordIndex;
157 public int getYCoordIndex() {
161 public void setYCoordIndex(int yCoordIndex) {
162 this.yCoordIndex = yCoordIndex;
165 public int getZCoordIndex() {
169 public void setZCoordIndex(int zCoordIndex) {
170 this.zCoordIndex = zCoordIndex;
173 public int getComponentMappingIndex() {
174 return componentMappingIndex;
177 public void setComponentMappingIndex(int componentMappingIndex) {
178 this.componentMappingIndex = componentMappingIndex;
181 public void setParentDiagram(Resource diagram) {
182 this.targetDiagram = diagram;
185 public Resource getParentDiagram() {
186 return targetDiagram;
189 // public void setWKTFile(Path wktFile) {
190 // this.wktFile = wktFile;
193 public void setComponentMappings(String value, Resource resource) {
194 componentMappings.put(value, resource);
197 public Map<String, Resource> getComponentMappings() {
198 return componentMappings;
201 public boolean isVertexImport() {
202 return isVertexImport;
205 public void setVertexImport(boolean isVertexImport) {
206 this.isVertexImport = isVertexImport;
209 public void setStartXCoordIndex(int parseInt) {
210 this.startXCoordIndex = parseInt;
213 public int getStartXCoordIndex() {
214 return startXCoordIndex;
217 public void setStartYCoordIndex(int parseInt) {
218 this.startYCoordIndex = parseInt;
221 public int getStartYCoordIndex() {
222 return startYCoordIndex;
225 public void setStartZCoordIndex(int parseInt) {
226 this.startZCoordIndex = parseInt;
229 public int getStartZCoordIndex() {
230 return startZCoordIndex;
233 public void setEndXCoordIndex(int parseInt) {
234 this.endXCoordIndex = parseInt;
237 public int getEndXCoordIndex() {
238 return endXCoordIndex;
241 public void setEndYCoordIndex(int parseInt) {
242 this.endYCoordIndex = parseInt;
245 public int getEndYCoordIndex() {
246 return endYCoordIndex;
249 public void setEndZCoordIndex(int parseInt) {
250 this.endZCoordIndex = parseInt;
253 public int getEndZCoordIndex() {
254 return endZCoordIndex;
257 public void setSourceCRS(String crs) {
258 this.sourceCRS = crs;
261 public String getSourceCRS() {
265 public void setSupplyTempIndex(int supplyTempIndex) {
266 this.supplytempIndex = supplyTempIndex;
269 public int getSupplyTempIndex() {
270 return supplytempIndex;
273 public void setSupplyPressureIndex(int supplyPressureIndex) {
274 this.supplypressureIndex = supplyPressureIndex;
277 public int getSupplyPressureIndex() {
278 return supplypressureIndex;
281 public void setReturnTempIndex(int returnTempIndex) {
282 this.returnTempIndex = returnTempIndex;
285 public int getReturnTempIndex() {
286 return returnTempIndex;
289 public void setReturnPressureIndex(int returnPressureIndex) {
290 this.returnPressureIndex = returnPressureIndex;
293 public int getReturnPressureIndex() {
294 return returnPressureIndex;
297 public void setDiameterIndex(int parseInt) {
298 this.diameterIndex = parseInt;
301 public int getDiameterIndex() {
302 return diameterIndex;
305 public void setOuterDiameterIndex(int parseInt) {
306 this.outerDiamterIndex = parseInt;
309 public int getOuterDiamterIndex() {
310 return outerDiamterIndex;
313 public void setNominalMassFlowIndex(int parseInt) {
314 this.nominalMassFlowIndex = parseInt;
317 public int getNominalMassFlowIndex() {
318 return nominalMassFlowIndex;
321 public void setDeltaPressureIndex(int parseInt) {
322 this.deltaPressureIndex = parseInt;
325 public int getDeltaPressureIndex() {
326 return deltaPressureIndex;
329 public void setDeltaTemperatureIndex(int parseInt) {
330 this.deltaTemperatureIndex = parseInt;
333 public int getDeltaTemperatureIndex() {
334 return deltaTemperatureIndex;
337 public void setHeatPowerIndex(int parseInt) {
338 this.heatPowerIndex = parseInt;
341 public int getHeatPowerIndex() {
342 return heatPowerIndex;
345 public void setNominalHeadMIndex(int parseInt) {
346 this.nominalHeadMIndex = parseInt;
349 public int getNominalHeadMIndex() {
350 return nominalHeadMIndex;
353 public void setNominalHeadBIndex(int parseInt) {
354 this.nominalHeadBIndex = parseInt;
357 public int getNominalHeadBIndex() {
358 return nominalHeadBIndex;
361 public void setNominalFlowIndex(int parseInt) {
362 this.nominalFlowIndex = parseInt;
365 public int getNominalFlowIndex() {
366 return nominalFlowIndex;
369 public void setMaximumHeadMIndex(int parseInt) {
370 this.maximumHeadMIndex = parseInt;
373 public int getMaximumHeadMIndex() {
374 return maximumHeadMIndex;
377 public void setHeatLoadDsIndex(int parseInt) {
378 this.heatLoadDsIndex = parseInt;
381 public int getHeatLoadDsIndex() {
382 return heatLoadDsIndex;
385 public void setMassFlowIndex(int parseInt) {
386 this.massFlowIndex = parseInt;
389 public int getMassFlowIndex() {
390 return massFlowIndex;
393 public void setVolFlowIndex(int parseInt) {
394 this.volFlowIndex = parseInt;
397 public int getVolFlowIndex() {
401 public void setVelocityIndex(int parseInt) {
402 this.velocityIndex = parseInt;
405 public int getVelocityIndex() {
406 return velocityIndex;
409 public void setFlowAreaIndex(int parseInt) {
410 this.flowAreaIndex = parseInt;
413 public int getFlowAreaIndex() {
414 return flowAreaIndex;
417 public void setNominalPressureLossIndex(int parseInt) {
418 this.nominalPressureLossIndex = parseInt;
421 public int getNominalPressureLossIndex() {
422 return nominalPressureLossIndex;
425 public void setEdgeFlowAreaIndex(int parseInt) {
426 this.edgeFlowAreaIndex = parseInt;
429 public int getEdgeFlowAreaIndex() {
430 return edgeFlowAreaIndex;
433 public void setKReturnIndex(int parseInt) {
434 this.kReturnIndex = parseInt;
437 public int getkReturnIndex() {
441 public void setKSupplyIndex(int parseInt) {
442 this.kSupplyIndex = parseInt;
445 public int getkSupplyIndex() {
449 public void setTGroundIndex(int parseInt) {
450 this.tGroundIndex = parseInt;
453 public int gettGroundIndex() {
457 public int getIdIndex() {
461 public void setIdIndex(int idIndex) {
462 this.idIndex = idIndex;
465 public void setEdgePapping(double edgePadding) {
466 this.edgePadding = edgePadding;
469 public double getEdgePadding() {
473 public void setValvePositionIndex(int valvePositionIndx) {
474 this.valvePositionIndx = valvePositionIndx;
477 public int getValvePositionIndx() {
478 return valvePositionIndx;
481 public void setAddressIndex(int parseInt) {
482 this.addressIndex = parseInt;
485 public int getAddressIndex() {
489 public int getLengthIndex() {
493 public void setLengthIndex(int lengthIndex) {
494 this.lengthIndex = lengthIndex;
497 public void detailedGeometryIndex(int detailedGeometryIndex) {
498 this.detailedGeometryIndex = detailedGeometryIndex;
501 public int getDetailedGeometryIndex() {
502 return detailedGeometryIndex;