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