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.CSVRecord;
11 import org.simantics.db.Resource;
12 import org.simantics.district.imports.DistrictImportUtils;
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;
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;
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;
75 public CSVImportModel() {
76 delimiters = DistrictImportUtils.getSupportedCSVDelimiterFormats();
79 public void setSource(Path source) {
83 public void setDelimiter(char delimiter) {
84 this.delimiter = delimiter;
87 public void setReadFirstAsHeader(boolean read) {
88 this.readFirstAsHeader = read;
91 public Path getSource() {
95 public List<CSVRecord> getRows(int amount) throws IOException {
97 return DistrictImportUtils.readRows(source, delimiter, amount);
99 return Collections.emptyList();
102 public Map<CSVHeader, List<String>> getHeaderAndRows(int amount) throws IOException {
104 return DistrictImportUtils.readCSVHeaderAndRows(source, delimiter, readFirstAsHeader, amount);
106 return Collections.emptyMap();
109 public Map<String, Integer> getHeader() throws IOException {
110 Map<String, Integer> header = null;
112 header = DistrictImportUtils.readCSVHeader(source, delimiter, readFirstAsHeader);
114 header = Collections.emptyMap();
118 public boolean getReadFirstAsHeader() {
119 return readFirstAsHeader;
122 public String[] getDelimiterFormats() {
123 return delimiters.keySet().toArray(new String[delimiters.size()]);
126 public void setDelimiterByLabel(String item) {
127 setDelimiter(delimiters.get(item));
130 public List<Map<String, String>> readRows(int amount) throws IOException {
132 return DistrictImportUtils.readRows(source, delimiter, readFirstAsHeader, amount);
134 return Collections.emptyList();
137 public char getDelimiter() {
141 // public Path getWKTFile() {
145 public int getXCoordIndex() {
149 public void setXCoordIndex(int xCoordIndex) {
150 this.xCoordIndex = xCoordIndex;
153 public int getYCoordIndex() {
157 public void setYCoordIndex(int yCoordIndex) {
158 this.yCoordIndex = yCoordIndex;
161 public int getZCoordIndex() {
165 public void setZCoordIndex(int zCoordIndex) {
166 this.zCoordIndex = zCoordIndex;
169 public int getComponentMappingIndex() {
170 return componentMappingIndex;
173 public void setComponentMappingIndex(int componentMappingIndex) {
174 this.componentMappingIndex = componentMappingIndex;
177 public void setParentDiagram(Resource diagram) {
178 this.targetDiagram = diagram;
181 public Resource getParentDiagram() {
182 return targetDiagram;
185 // public void setWKTFile(Path wktFile) {
186 // this.wktFile = wktFile;
189 public void setComponentMappings(String value, Resource resource) {
190 componentMappings.put(value, resource);
193 public Map<String, Resource> getComponentMappings() {
194 return componentMappings;
197 public boolean isVertexImport() {
198 return isVertexImport;
201 public void setVertexImport(boolean isVertexImport) {
202 this.isVertexImport = isVertexImport;
205 public void setStartXCoordIndex(int parseInt) {
206 this.startXCoordIndex = parseInt;
209 public int getStartXCoordIndex() {
210 return startXCoordIndex;
213 public void setStartYCoordIndex(int parseInt) {
214 this.startYCoordIndex = parseInt;
217 public int getStartYCoordIndex() {
218 return startYCoordIndex;
221 public void setStartZCoordIndex(int parseInt) {
222 this.startZCoordIndex = parseInt;
225 public int getStartZCoordIndex() {
226 return startZCoordIndex;
229 public void setEndXCoordIndex(int parseInt) {
230 this.endXCoordIndex = parseInt;
233 public int getEndXCoordIndex() {
234 return endXCoordIndex;
237 public void setEndYCoordIndex(int parseInt) {
238 this.endYCoordIndex = parseInt;
241 public int getEndYCoordIndex() {
242 return endYCoordIndex;
245 public void setEndZCoordIndex(int parseInt) {
246 this.endZCoordIndex = parseInt;
249 public int getEndZCoordIndex() {
250 return endZCoordIndex;
253 public void setSourceCRS(String crs) {
254 this.sourceCRS = crs;
257 public String getSourceCRS() {
261 public void setSupplyTempIndex(int supplyTempIndex) {
262 this.supplytempIndex = supplyTempIndex;
265 public int getSupplyTempIndex() {
266 return supplytempIndex;
269 public void setSupplyPressureIndex(int supplyPressureIndex) {
270 this.supplypressureIndex = supplyPressureIndex;
273 public int getSupplyPressureIndex() {
274 return supplypressureIndex;
277 public void setReturnTempIndex(int returnTempIndex) {
278 this.returnTempIndex = returnTempIndex;
281 public int getReturnTempIndex() {
282 return returnTempIndex;
285 public void setReturnPressureIndex(int returnPressureIndex) {
286 this.returnPressureIndex = returnPressureIndex;
289 public int getReturnPressureIndex() {
290 return returnPressureIndex;
293 public void setDiameterIndex(int parseInt) {
294 this.diameterIndex = parseInt;
297 public int getDiameterIndex() {
298 return diameterIndex;
301 public void setOuterDiameterIndex(int parseInt) {
302 this.outerDiamterIndex = parseInt;
305 public int getOuterDiamterIndex() {
306 return outerDiamterIndex;
309 public void setNominalMassFlowIndex(int parseInt) {
310 this.nominalMassFlowIndex = parseInt;
313 public int getNominalMassFlowIndex() {
314 return nominalMassFlowIndex;
317 public void setDeltaPressureIndex(int parseInt) {
318 this.deltaPressureIndex = parseInt;
321 public int getDeltaPressureIndex() {
322 return deltaPressureIndex;
325 public void setDeltaTemperatureIndex(int parseInt) {
326 this.deltaTemperatureIndex = parseInt;
329 public int getDeltaTemperatureIndex() {
330 return deltaTemperatureIndex;
333 public void setHeatPowerIndex(int parseInt) {
334 this.heatPowerIndex = parseInt;
337 public int getHeatPowerIndex() {
338 return heatPowerIndex;
341 public void setNominalHeadMIndex(int parseInt) {
342 this.nominalHeadMIndex = parseInt;
345 public int getNominalHeadMIndex() {
346 return nominalHeadMIndex;
349 public void setNominalHeadBIndex(int parseInt) {
350 this.nominalHeadBIndex = parseInt;
353 public int getNominalHeadBIndex() {
354 return nominalHeadBIndex;
357 public void setNominalFlowIndex(int parseInt) {
358 this.nominalFlowIndex = parseInt;
361 public int getNominalFlowIndex() {
362 return nominalFlowIndex;
365 public void setMaximumHeadMIndex(int parseInt) {
366 this.maximumHeadMIndex = parseInt;
369 public int getMaximumHeadMIndex() {
370 return maximumHeadMIndex;
373 public void setHeatLoadDsIndex(int parseInt) {
374 this.heatLoadDsIndex = parseInt;
377 public int getHeatLoadDsIndex() {
378 return heatLoadDsIndex;
381 public void setMassFlowIndex(int parseInt) {
382 this.massFlowIndex = parseInt;
385 public int getMassFlowIndex() {
386 return massFlowIndex;
389 public void setVolFlowIndex(int parseInt) {
390 this.volFlowIndex = parseInt;
393 public int getVolFlowIndex() {
397 public void setVelocityIndex(int parseInt) {
398 this.velocityIndex = parseInt;
401 public int getVelocityIndex() {
402 return velocityIndex;
405 public void setFlowAreaIndex(int parseInt) {
406 this.flowAreaIndex = parseInt;
409 public int getFlowAreaIndex() {
410 return flowAreaIndex;
413 public void setNominalPressureLossIndex(int parseInt) {
414 this.nominalPressureLossIndex = parseInt;
417 public int getNominalPressureLossIndex() {
418 return nominalPressureLossIndex;
421 public void setEdgeFlowAreaIndex(int parseInt) {
422 this.edgeFlowAreaIndex = parseInt;
425 public int getEdgeFlowAreaIndex() {
426 return edgeFlowAreaIndex;
429 public void setKReturnIndex(int parseInt) {
430 this.kReturnIndex = parseInt;
433 public int getkReturnIndex() {
437 public void setKSupplyIndex(int parseInt) {
438 this.kSupplyIndex = parseInt;
441 public int getkSupplyIndex() {
445 public void setTGroundIndex(int parseInt) {
446 this.tGroundIndex = parseInt;
449 public int gettGroundIndex() {
453 public int getIdIndex() {
457 public void setIdIndex(int idIndex) {
458 this.idIndex = idIndex;
461 public void setEdgePapping(double edgePadding) {
462 this.edgePadding = edgePadding;
465 public double getEdgePadding() {
469 public void setValvePositionIndex(int valvePositionIndx) {
470 this.valvePositionIndx = valvePositionIndx;
473 public int getValvePositionIndx() {
474 return valvePositionIndx;