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;
80 public CSVImportModel() {
81 delimiters = DistrictImportUtils.getSupportedCSVDelimiterFormats();
84 public void setSource(Path source) {
88 public void setDelimiter(char delimiter) {
89 this.delimiter = delimiter;
92 public void setReadFirstAsHeader(boolean read) {
93 this.readFirstAsHeader = read;
96 public Path getSource() {
100 public List<CSVRecord> getRows(int amount, boolean readFirstAsHeader) throws IOException {
102 return DistrictImportUtils.readRows(source, delimiter, readFirstAsHeader, amount);
104 return Collections.emptyList();
107 public Map<CSVHeader, List<String>> getHeaderAndRows(int amount) throws IOException {
109 return DistrictImportUtils.readCSVHeaderAndRows(source, delimiter, readFirstAsHeader, amount);
111 return Collections.emptyMap();
114 public Map<String, Integer> getHeader() throws IOException {
115 Map<String, Integer> header = null;
117 header = DistrictImportUtils.readCSVHeader(source, delimiter, readFirstAsHeader);
119 header = Collections.emptyMap();
123 public boolean getReadFirstAsHeader() {
124 return readFirstAsHeader;
127 public String[] getDelimiterFormats() {
128 return delimiters.keySet().toArray(new String[delimiters.size()]);
131 public void setDelimiterByLabel(String item) {
132 setDelimiter(delimiters.get(item));
135 public List<Map<String, String>> readRows(int amount) throws IOException {
137 return DistrictImportUtils.readRows(source, CSVFormat.newFormat(delimiter), readFirstAsHeader, amount);
139 return Collections.emptyList();
142 public char getDelimiter() {
146 // public Path getWKTFile() {
150 public int getXCoordIndex() {
154 public void setXCoordIndex(int xCoordIndex) {
155 this.xCoordIndex = xCoordIndex;
158 public int getYCoordIndex() {
162 public void setYCoordIndex(int yCoordIndex) {
163 this.yCoordIndex = yCoordIndex;
166 public int getZCoordIndex() {
170 public void setZCoordIndex(int zCoordIndex) {
171 this.zCoordIndex = zCoordIndex;
174 public int getComponentMappingIndex() {
175 return componentMappingIndex;
178 public void setComponentMappingIndex(int componentMappingIndex) {
179 this.componentMappingIndex = componentMappingIndex;
182 public void setParentDiagram(Resource diagram) {
183 this.targetDiagram = diagram;
186 public Resource getParentDiagram() {
187 return targetDiagram;
190 // public void setWKTFile(Path wktFile) {
191 // this.wktFile = wktFile;
194 public void setComponentMappings(String value, Resource resource) {
195 componentMappings.put(value, resource);
198 public Map<String, Resource> getComponentMappings() {
199 return componentMappings;
202 public boolean isVertexImport() {
203 return isVertexImport;
206 public void setVertexImport(boolean isVertexImport) {
207 this.isVertexImport = isVertexImport;
210 public void setStartXCoordIndex(int parseInt) {
211 this.startXCoordIndex = parseInt;
214 public int getStartXCoordIndex() {
215 return startXCoordIndex;
218 public void setStartYCoordIndex(int parseInt) {
219 this.startYCoordIndex = parseInt;
222 public int getStartYCoordIndex() {
223 return startYCoordIndex;
226 public void setStartZCoordIndex(int parseInt) {
227 this.startZCoordIndex = parseInt;
230 public int getStartZCoordIndex() {
231 return startZCoordIndex;
234 public void setEndXCoordIndex(int parseInt) {
235 this.endXCoordIndex = parseInt;
238 public int getEndXCoordIndex() {
239 return endXCoordIndex;
242 public void setEndYCoordIndex(int parseInt) {
243 this.endYCoordIndex = parseInt;
246 public int getEndYCoordIndex() {
247 return endYCoordIndex;
250 public void setEndZCoordIndex(int parseInt) {
251 this.endZCoordIndex = parseInt;
254 public int getEndZCoordIndex() {
255 return endZCoordIndex;
258 public void setSourceCRS(String crs) {
259 this.sourceCRS = crs;
262 public String getSourceCRS() {
266 public void setSupplyTempIndex(int supplyTempIndex) {
267 this.supplytempIndex = supplyTempIndex;
270 public int getSupplyTempIndex() {
271 return supplytempIndex;
274 public void setSupplyPressureIndex(int supplyPressureIndex) {
275 this.supplypressureIndex = supplyPressureIndex;
278 public int getSupplyPressureIndex() {
279 return supplypressureIndex;
282 public void setReturnTempIndex(int returnTempIndex) {
283 this.returnTempIndex = returnTempIndex;
286 public int getReturnTempIndex() {
287 return returnTempIndex;
290 public void setReturnPressureIndex(int returnPressureIndex) {
291 this.returnPressureIndex = returnPressureIndex;
294 public int getReturnPressureIndex() {
295 return returnPressureIndex;
298 public void setDiameterIndex(int parseInt) {
299 this.diameterIndex = parseInt;
302 public int getDiameterIndex() {
303 return diameterIndex;
306 public void setOuterDiameterIndex(int parseInt) {
307 this.outerDiamterIndex = parseInt;
310 public int getOuterDiamterIndex() {
311 return outerDiamterIndex;
314 public void setNominalMassFlowIndex(int parseInt) {
315 this.nominalMassFlowIndex = parseInt;
318 public int getNominalMassFlowIndex() {
319 return nominalMassFlowIndex;
322 public void setDeltaPressureIndex(int parseInt) {
323 this.deltaPressureIndex = parseInt;
326 public int getDeltaPressureIndex() {
327 return deltaPressureIndex;
330 public void setDeltaTemperatureIndex(int parseInt) {
331 this.deltaTemperatureIndex = parseInt;
334 public int getDeltaTemperatureIndex() {
335 return deltaTemperatureIndex;
338 public void setHeatPowerIndex(int parseInt) {
339 this.heatPowerIndex = parseInt;
342 public int getHeatPowerIndex() {
343 return heatPowerIndex;
346 public void setNominalHeadMIndex(int parseInt) {
347 this.nominalHeadMIndex = parseInt;
350 public int getNominalHeadMIndex() {
351 return nominalHeadMIndex;
354 public void setNominalHeadBIndex(int parseInt) {
355 this.nominalHeadBIndex = parseInt;
358 public int getNominalHeadBIndex() {
359 return nominalHeadBIndex;
362 public void setNominalFlowIndex(int parseInt) {
363 this.nominalFlowIndex = parseInt;
366 public int getNominalFlowIndex() {
367 return nominalFlowIndex;
370 public void setMaximumHeadMIndex(int parseInt) {
371 this.maximumHeadMIndex = parseInt;
374 public int getMaximumHeadMIndex() {
375 return maximumHeadMIndex;
378 public void setHeatLoadDsIndex(int parseInt) {
379 this.heatLoadDsIndex = parseInt;
382 public int getHeatLoadDsIndex() {
383 return heatLoadDsIndex;
386 public void setMassFlowIndex(int parseInt) {
387 this.massFlowIndex = parseInt;
390 public int getMassFlowIndex() {
391 return massFlowIndex;
394 public void setVolFlowIndex(int parseInt) {
395 this.volFlowIndex = parseInt;
398 public int getVolFlowIndex() {
402 public void setVelocityIndex(int parseInt) {
403 this.velocityIndex = parseInt;
406 public int getVelocityIndex() {
407 return velocityIndex;
410 public void setFlowAreaIndex(int parseInt) {
411 this.flowAreaIndex = parseInt;
414 public int getFlowAreaIndex() {
415 return flowAreaIndex;
418 public void setNominalPressureLossIndex(int parseInt) {
419 this.nominalPressureLossIndex = parseInt;
422 public int getNominalPressureLossIndex() {
423 return nominalPressureLossIndex;
426 public void setEdgeFlowAreaIndex(int parseInt) {
427 this.edgeFlowAreaIndex = parseInt;
430 public int getEdgeFlowAreaIndex() {
431 return edgeFlowAreaIndex;
434 public void setKReturnIndex(int parseInt) {
435 this.kReturnIndex = parseInt;
438 public int getkReturnIndex() {
442 public void setKSupplyIndex(int parseInt) {
443 this.kSupplyIndex = parseInt;
446 public int getkSupplyIndex() {
450 public void setTGroundIndex(int parseInt) {
451 this.tGroundIndex = parseInt;
454 public int gettGroundIndex() {
458 public int getIdIndex() {
462 public void setIdIndex(int idIndex) {
463 this.idIndex = idIndex;
466 public void setEdgePadding(double edgePadding) {
467 this.edgePadding = edgePadding;
470 public double getEdgePadding() {
474 public void setValvePositionIndex(int valvePositionIndx) {
475 this.valvePositionIndx = valvePositionIndx;
478 public int getValvePositionIndx() {
479 return valvePositionIndx;
482 public void setAddressIndex(int parseInt) {
483 this.addressIndex = parseInt;
486 public int getAddressIndex() {
490 public int getLengthIndex() {
494 public void setLengthIndex(int lengthIndex) {
495 this.lengthIndex = lengthIndex;
498 public void detailedGeometryIndex(int detailedGeometryIndex) {
499 this.detailedGeometryIndex = detailedGeometryIndex;
502 public int getDetailedGeometryIndex() {
503 return detailedGeometryIndex;
506 public int getAlternativeElevationIndex() {
507 return altElevationIndex;
510 public void setAltElevationIndex(int parseInt) {
511 this.altElevationIndex = parseInt;
514 public void setPeakPowerIndex(int parseInt) {
515 this.peakPowerIndex = parseInt;
518 public int getPeakPowerIndex() {
519 return peakPowerIndex;