1 package org.simantics.district.imports;
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.CSVHeader;
15 public class CSVImportModel {
17 // First page fills these
18 private Resource targetDiagram;
21 // Second page fills these
22 private char delimiter;
23 private boolean readFirstAsHeader = true;
24 private Map<String, Character> delimiters;
25 // private Path wktFile;
28 private int xCoordIndex = -1;
29 private int yCoordIndex = -1;
30 private int zCoordIndex = -1;
31 private int altElevationIndex = -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 = -1;
74 private int lengthIndex = -1;
75 private int detailedGeometryIndex = -1;
76 private int peakPowerIndex = -1;
77 private int regionIndex = -1;
78 private int pipeTypeIndex = -1;
82 public CSVImportModel() {
83 delimiters = DistrictImportUtils.getSupportedCSVDelimiterFormats();
86 public void setSource(Path source) {
90 public void setDelimiter(char delimiter) {
91 this.delimiter = delimiter;
94 public void setReadFirstAsHeader(boolean read) {
95 this.readFirstAsHeader = read;
98 public Path getSource() {
102 public List<CSVRecord> getRows(int amount, boolean readFirstAsHeader) throws IOException {
104 return DistrictImportUtils.readRows(source, delimiter, readFirstAsHeader, amount);
106 return Collections.emptyList();
109 public Map<CSVHeader, List<String>> getHeaderAndRows(int amount) throws IOException {
111 return DistrictImportUtils.readCSVHeaderAndRows(source, delimiter, readFirstAsHeader, amount);
113 return Collections.emptyMap();
116 public Map<String, Integer> getHeader() throws IOException {
117 Map<String, Integer> header = null;
119 header = DistrictImportUtils.readCSVHeader(source, delimiter, readFirstAsHeader);
121 header = Collections.emptyMap();
125 public boolean getReadFirstAsHeader() {
126 return readFirstAsHeader;
129 public String[] getDelimiterFormats() {
130 return delimiters.keySet().toArray(new String[delimiters.size()]);
133 public void setDelimiterByLabel(String item) {
134 setDelimiter(delimiters.get(item));
137 public List<Map<String, String>> readRows(int amount) throws IOException {
139 return DistrictImportUtils.readRows(source, CSVFormat.newFormat(delimiter), readFirstAsHeader, amount);
141 return Collections.emptyList();
144 public char getDelimiter() {
148 // public Path getWKTFile() {
152 public int getXCoordIndex() {
156 public void setXCoordIndex(int xCoordIndex) {
157 this.xCoordIndex = xCoordIndex;
160 public int getYCoordIndex() {
164 public void setYCoordIndex(int yCoordIndex) {
165 this.yCoordIndex = yCoordIndex;
168 public int getZCoordIndex() {
172 public void setZCoordIndex(int zCoordIndex) {
173 this.zCoordIndex = zCoordIndex;
176 public int getComponentMappingIndex() {
177 return componentMappingIndex;
180 public void setComponentMappingIndex(int componentMappingIndex) {
181 this.componentMappingIndex = componentMappingIndex;
184 public void setParentDiagram(Resource diagram) {
185 this.targetDiagram = diagram;
188 public Resource getParentDiagram() {
189 return targetDiagram;
192 // public void setWKTFile(Path wktFile) {
193 // this.wktFile = wktFile;
196 public void setComponentMappings(String value, Resource resource) {
197 componentMappings.put(value, resource);
200 public Map<String, Resource> getComponentMappings() {
201 return componentMappings;
204 public boolean isVertexImport() {
205 return isVertexImport;
208 public void setVertexImport(boolean isVertexImport) {
209 this.isVertexImport = isVertexImport;
212 public void setStartXCoordIndex(int parseInt) {
213 this.startXCoordIndex = parseInt;
216 public int getStartXCoordIndex() {
217 return startXCoordIndex;
220 public void setStartYCoordIndex(int parseInt) {
221 this.startYCoordIndex = parseInt;
224 public int getStartYCoordIndex() {
225 return startYCoordIndex;
228 public void setStartZCoordIndex(int parseInt) {
229 this.startZCoordIndex = parseInt;
232 public int getStartZCoordIndex() {
233 return startZCoordIndex;
236 public void setEndXCoordIndex(int parseInt) {
237 this.endXCoordIndex = parseInt;
240 public int getEndXCoordIndex() {
241 return endXCoordIndex;
244 public void setEndYCoordIndex(int parseInt) {
245 this.endYCoordIndex = parseInt;
248 public int getEndYCoordIndex() {
249 return endYCoordIndex;
252 public void setEndZCoordIndex(int parseInt) {
253 this.endZCoordIndex = parseInt;
256 public int getEndZCoordIndex() {
257 return endZCoordIndex;
260 public void setSourceCRS(String crs) {
261 this.sourceCRS = crs;
264 public String getSourceCRS() {
268 public void setSupplyTempIndex(int supplyTempIndex) {
269 this.supplytempIndex = supplyTempIndex;
272 public int getSupplyTempIndex() {
273 return supplytempIndex;
276 public void setSupplyPressureIndex(int supplyPressureIndex) {
277 this.supplypressureIndex = supplyPressureIndex;
280 public int getSupplyPressureIndex() {
281 return supplypressureIndex;
284 public void setReturnTempIndex(int returnTempIndex) {
285 this.returnTempIndex = returnTempIndex;
288 public int getReturnTempIndex() {
289 return returnTempIndex;
292 public void setReturnPressureIndex(int returnPressureIndex) {
293 this.returnPressureIndex = returnPressureIndex;
296 public int getReturnPressureIndex() {
297 return returnPressureIndex;
300 public void setDiameterIndex(int parseInt) {
301 this.diameterIndex = parseInt;
304 public int getDiameterIndex() {
305 return diameterIndex;
308 public void setOuterDiameterIndex(int parseInt) {
309 this.outerDiamterIndex = parseInt;
312 public int getOuterDiamterIndex() {
313 return outerDiamterIndex;
316 public void setNominalMassFlowIndex(int parseInt) {
317 this.nominalMassFlowIndex = parseInt;
320 public int getNominalMassFlowIndex() {
321 return nominalMassFlowIndex;
324 public void setDeltaPressureIndex(int parseInt) {
325 this.deltaPressureIndex = parseInt;
328 public int getDeltaPressureIndex() {
329 return deltaPressureIndex;
332 public void setDeltaTemperatureIndex(int parseInt) {
333 this.deltaTemperatureIndex = parseInt;
336 public int getDeltaTemperatureIndex() {
337 return deltaTemperatureIndex;
340 public void setHeatPowerIndex(int parseInt) {
341 this.heatPowerIndex = parseInt;
344 public int getHeatPowerIndex() {
345 return heatPowerIndex;
348 public void setNominalHeadMIndex(int parseInt) {
349 this.nominalHeadMIndex = parseInt;
352 public int getNominalHeadMIndex() {
353 return nominalHeadMIndex;
356 public void setNominalHeadBIndex(int parseInt) {
357 this.nominalHeadBIndex = parseInt;
360 public int getNominalHeadBIndex() {
361 return nominalHeadBIndex;
364 public void setNominalFlowIndex(int parseInt) {
365 this.nominalFlowIndex = parseInt;
368 public int getNominalFlowIndex() {
369 return nominalFlowIndex;
372 public void setMaximumHeadMIndex(int parseInt) {
373 this.maximumHeadMIndex = parseInt;
376 public int getMaximumHeadMIndex() {
377 return maximumHeadMIndex;
380 public void setHeatLoadDsIndex(int parseInt) {
381 this.heatLoadDsIndex = parseInt;
384 public int getHeatLoadDsIndex() {
385 return heatLoadDsIndex;
388 public void setMassFlowIndex(int parseInt) {
389 this.massFlowIndex = parseInt;
392 public int getMassFlowIndex() {
393 return massFlowIndex;
396 public void setVolFlowIndex(int parseInt) {
397 this.volFlowIndex = parseInt;
400 public int getVolFlowIndex() {
404 public void setVelocityIndex(int parseInt) {
405 this.velocityIndex = parseInt;
408 public int getVelocityIndex() {
409 return velocityIndex;
412 public void setFlowAreaIndex(int parseInt) {
413 this.flowAreaIndex = parseInt;
416 public int getFlowAreaIndex() {
417 return flowAreaIndex;
420 public void setNominalPressureLossIndex(int parseInt) {
421 this.nominalPressureLossIndex = parseInt;
424 public int getNominalPressureLossIndex() {
425 return nominalPressureLossIndex;
428 public void setEdgeFlowAreaIndex(int parseInt) {
429 this.edgeFlowAreaIndex = parseInt;
432 public int getEdgeFlowAreaIndex() {
433 return edgeFlowAreaIndex;
436 public void setKReturnIndex(int parseInt) {
437 this.kReturnIndex = parseInt;
440 public int getkReturnIndex() {
444 public void setKSupplyIndex(int parseInt) {
445 this.kSupplyIndex = parseInt;
448 public int getkSupplyIndex() {
452 public void setTGroundIndex(int parseInt) {
453 this.tGroundIndex = parseInt;
456 public int gettGroundIndex() {
460 public int getIdIndex() {
464 public void setIdIndex(int idIndex) {
465 this.idIndex = idIndex;
468 public void setEdgePadding(double edgePadding) {
469 this.edgePadding = edgePadding;
472 public double getEdgePadding() {
476 public void setValvePositionIndex(int valvePositionIndx) {
477 this.valvePositionIndx = valvePositionIndx;
480 public int getValvePositionIndx() {
481 return valvePositionIndx;
484 public void setAddressIndex(int parseInt) {
485 this.addressIndex = parseInt;
488 public int getAddressIndex() {
492 public int getLengthIndex() {
496 public void setLengthIndex(int lengthIndex) {
497 this.lengthIndex = lengthIndex;
500 public void detailedGeometryIndex(int detailedGeometryIndex) {
501 this.detailedGeometryIndex = detailedGeometryIndex;
504 public int getDetailedGeometryIndex() {
505 return detailedGeometryIndex;
508 public int getAlternativeElevationIndex() {
509 return altElevationIndex;
512 public void setAltElevationIndex(int parseInt) {
513 this.altElevationIndex = parseInt;
516 public void setPeakPowerIndex(int parseInt) {
517 this.peakPowerIndex = parseInt;
520 public int getPeakPowerIndex() {
521 return peakPowerIndex;
524 public int getRegionIndex() {
528 public void setRegionIndex(int regionIndex) {
529 this.regionIndex = regionIndex;
532 public int getPipeTypeIndex() {
533 return pipeTypeIndex;
536 public void setPipeTypeIndex(int pipeTypeIndex) {
537 this.pipeTypeIndex = pipeTypeIndex;