]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Add support for importing regions to district models 33/3733/1
authorjsimomaa <jani.simomaa@gmail.com>
Wed, 18 Dec 2019 09:11:52 +0000 (11:11 +0200)
committerJani Simomaa <jani.simomaa@semantum.fi>
Wed, 18 Dec 2019 10:08:29 +0000 (10:08 +0000)
gitlab #73

Change-Id: Icea73ce0f8aac0866dc0735a5756315e86e94439
(cherry picked from commit c98b9f92547d6e7d4cdf59e2f8f10b355300b7e9)

org.simantics.district.imports.ui/META-INF/MANIFEST.MF
org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizard.java
org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizardFirstPage.java
org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizardPage.java
org.simantics.district.imports/scl/Simantics/District/Import.scl
org.simantics.district.imports/src/org/simantics/district/imports/CSVImportModel.java
org.simantics.district.imports/src/org/simantics/district/imports/DistrictImportUtils.java
org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph
org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java

index dc0819b8e579afdef66c9ca7ce8352195245bb70..49a37894d735eb2ddcadecc4a67c87c5565fcd5f 100644 (file)
@@ -17,5 +17,6 @@ Require-Bundle: org.eclipse.ui.ide,
  org.simantics.modeling.ontology,
  org.simantics.district.network,
  org.simantics.district.network.ontology,
- org.simantics.district.maps
+ org.simantics.district.maps,
+ org.slf4j.api
 Bundle-ActivationPolicy: lazy
index a4d29fe1ae943e0cc31ba85ef7514c528d862ea9..6162314e21a91b3be6d4ba0e355482099f1d9085 100644 (file)
@@ -46,6 +46,7 @@ public class CSVImportWizard extends Wizard implements IImportWizard {
                         } else {
                             DistrictImportUtils.importEdges(model);
                         }
+
                     } catch (Exception e) {
                         throw new InvocationTargetException(e);
                     }
index a0cc023c58633434305c524ec963a547c8bdb476..eb0faef06225a4b8a5192b4a9b23aefcb273d48d 100644 (file)
@@ -28,9 +28,13 @@ import org.simantics.modeling.ModelingResources;
 import org.simantics.utils.ui.widgets.FileOrDirectorySelectionWidget;
 import org.simantics.utils.ui.widgets.FileSelectionListener;
 import org.simantics.utils.ui.widgets.FileSelectionWidget;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class CSVImportWizardFirstPage extends WizardPage implements FileSelectionListener {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(CSVImportWizardFirstPage.class);
+
     private final CSVImportModel model;
     
     private Map<String, Resource> diagrams = new HashMap<>();
@@ -107,7 +111,7 @@ public class CSVImportWizardFirstPage extends WizardPage implements FileSelectio
                 diagramCombo.getDisplay().asyncExec(() -> validateComplete());
             }
         } catch (DatabaseException e) {
-            e.printStackTrace();
+            LOGGER.error("Could not update available parents", e);
         }
     }
 
index 268ed310df432885378907646e6976046793c607..910ae428da266f2a5dde41a3d9f5171bf177852d 100644 (file)
@@ -68,6 +68,7 @@ public class CSVImportWizardPage extends WizardPage {
     private DynamicComboFieldEditor dtSelector;
     private DynamicComboFieldEditor heatPowerSelector;
     private DynamicComboFieldEditor peakPowerSelector;
+    private DynamicComboFieldEditor regionSelector;
     private DynamicComboFieldEditor nominalHeadMSelector;
     private DynamicComboFieldEditor nominalHeadBSelector;
     private DynamicComboFieldEditor nominalFlowSelector;
@@ -343,7 +344,20 @@ public class CSVImportWizardPage extends WizardPage {
                 validatePageComplete();
             }
         });
-        
+        regionSelector = new DynamicComboFieldEditor("regionValue", "Region", parent);
+        regionSelector.addComboListener(new SelectionListener() {
+
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                widgetDefaultSelected(e);
+            }
+
+            @Override
+            public void widgetDefaultSelected(SelectionEvent e) {
+                model.setRegionIndex(Integer.parseInt(regionSelector.getValue()));
+                validatePageComplete();
+            }
+        });
     }
 
     private void createVertexIndexMappingField(Group parent) {
@@ -518,6 +532,7 @@ public class CSVImportWizardPage extends WizardPage {
                 validatePageComplete();
             }
         });
+        
         nominalHeadMSelector = new DynamicComboFieldEditor("nominalHeadMValue", "nominalHeadM", parent);
         nominalHeadMSelector.addComboListener(new SelectionListener() {
 
index a3d36f4c28e96aefb1bb344e079cc82075512fb3..fc697d6f2daac0d4c11716924aef7542485d73db 100644 (file)
@@ -38,6 +38,7 @@ importJava "org.simantics.district.imports.CSVImportModel" where
     // Common
     setSourceCRS :: CSVImportModel -> String -> <Proc> ()
     setIdIndex :: CSVImportModel -> Integer -> <Proc> ()
+    setRegionIndex :: CSVImportModel -> Integer -> <Proc> ()
     setAddressIndex :: CSVImportModel -> Integer -> <Proc> ()
     setComponentMappingIndex :: CSVImportModel -> Integer -> <Proc> ()
     setComponentMappings :: CSVImportModel -> String -> Resource -> <Proc> ()
index 9f85225f3302fe51b83f6a65a9563932b22d7e9f..1acae8dec90326ce209476499afdb149e072d753 100644 (file)
@@ -74,6 +74,7 @@ public class CSVImportModel {
     private int lengthIndex = -1;
     private int detailedGeometryIndex = -1;
     private int peakPowerIndex = -1;
+    private int regionIndex = -1;
     
     // Third page
 
@@ -518,4 +519,12 @@ public class CSVImportModel {
     public int getPeakPowerIndex() {
         return peakPowerIndex;
     }
+    
+    public int getRegionIndex() {
+        return regionIndex;
+    }
+    
+    public void setRegionIndex(int regionIndex) {
+        this.regionIndex = regionIndex;
+    }
 }
index 7e2a0e1e23c8cbbb4cd258792f7201a02b044dbc..083b58d5fa1d91c7fad40bc53d2fc939aab1d9e5 100644 (file)
@@ -256,6 +256,7 @@ public class DistrictImportUtils {
         int flowAreaIndex = model.getFlowAreaIndex();
         int nominalPressureLossIndex = model.getNominalPressureLossIndex();
         int addressIndex = model.getAddressIndex();
+        int regionIndex = model.getRegionIndex();
         
         int mappingColumn = model.getComponentMappingIndex();
         int idColumn = model.getIdIndex();
@@ -345,6 +346,7 @@ public class DistrictImportUtils {
                             writeValue(graph, row, flowAreaIndex, vertex, DN.Vertex_HasFlowArea);
                             writeValue(graph, row, nominalPressureLossIndex, vertex, DN.Vertex_HasNominalPressureLoss);
                             writeStringValue(graph, row, addressIndex, vertex, DN.Vertex_HasAddress);
+                            writeStringValue(graph, row, regionIndex, vertex, DN.HasRegion);
                         } catch (DatabaseException | MismatchedDimensionException | TransformException e) {
                             throw new RuntimeException(e);
                         }
@@ -366,6 +368,7 @@ public class DistrictImportUtils {
         Path csvFile = model.getSource();
         char delim = model.getDelimiter();
 
+        Set<String> writtenIds = new HashSet<>();
         
         int startXCoordColumnIndex = model.getStartXCoordIndex();
         int startYCoordColumnIndex = model.getStartYCoordIndex();
@@ -382,6 +385,7 @@ public class DistrictImportUtils {
         int kSupplyIndex = model.getkSupplyIndex();
         int lengthIndex = model.getLengthIndex();
         int detailedGeometryIndex = model.getDetailedGeometryIndex();
+        int regionIndex = model.getRegionIndex();
         
         int mappingColumn = model.getComponentMappingIndex();
         int idColumn = model.getIdIndex();
@@ -435,60 +439,66 @@ public class DistrictImportUtils {
                     
                     DistrictImportUtils.consumeCSV(csvFile, delim, true, row -> {
                         try {
-                            String mappingValue = row.get(mappingColumn);
-                            
-                            String startXCoords = row.get(startXCoordColumnIndex);
-                            String startYCoords = row.get(startYCoordColumnIndex);
-                            String startZCoords = row.get(startZValueColumnIndex);
-                            String endXCoords = row.get(endXCoordColumnIndex);
-                            String endYCoords = row.get(endYCoordColumnIndex);
-                            String endZCoords = row.get(endZValueColumnIndex);
-                            
-                            double startXCoord = Double.parseDouble(startXCoords); // make negative
-                            double startYCoord = Double.parseDouble(startYCoords);
-                            double startZCoord = Double.parseDouble(startZCoords);
                             
-                            double endXCoord = Double.parseDouble(endXCoords); // make negative
-                            double endYCoord = Double.parseDouble(endYCoords);
-                            double endZCoord = Double.parseDouble(endZCoords);
-                            
-                            double[] startCoords;
-                            double[] endCoords;
-                            if (actualDoTransform) {
-                                DirectPosition2D startTargetPos = new DirectPosition2D();
-                                DirectPosition2D startSourcePos = new DirectPosition2D(startXCoord, startYCoord);
-                                DirectPosition startRes = actualTransform.transform(startSourcePos, startTargetPos);
-                                startCoords = startRes.getCoordinate();
+                            String idValue = row.get(idColumn);
+                            if (!writtenIds.contains(idValue)) {
+                                writtenIds.add(idValue);
+                                String mappingValue = row.get(mappingColumn);
                                 
-                                DirectPosition2D endTargetPos = new DirectPosition2D();
-                                DirectPosition2D endSourcePos = new DirectPosition2D(endXCoord, endYCoord);
-                                DirectPosition endRes = actualTransform.transform(endSourcePos, endTargetPos);
-                                endCoords = endRes.getCoordinate();
-                            } else {
-                                startCoords = new double[] { startXCoord , startYCoord };
-                                endCoords = new double[] { endXCoord , endYCoord };
-                            }
-                            
-                            // Switch to (longitude, latitude)
-                            flipAxes(startCoords);
-                            flipAxes(endCoords);
-                            
-                            Optional<Resource> oedge = DNEdgeBuilder.create(graph, vv, model.getParentDiagram(), model.getComponentMappings().get(mappingValue), startCoords, startZCoord, endCoords, endZCoord, new double[0], padding, true);
-                            if (oedge.isPresent()) {
-                                Resource edge = oedge.get();
-                                writeStringValue(graph, row, idColumn, edge, DN.HasId);
+                                String startXCoords = row.get(startXCoordColumnIndex);
+                                String startYCoords = row.get(startYCoordColumnIndex);
+                                String startZCoords = row.get(startZValueColumnIndex);
+                                String endXCoords = row.get(endXCoordColumnIndex);
+                                String endYCoords = row.get(endYCoordColumnIndex);
+                                String endZCoords = row.get(endZValueColumnIndex);
+                                
+                                double startXCoord = Double.parseDouble(startXCoords); // make negative
+                                double startYCoord = Double.parseDouble(startYCoords);
+                                double startZCoord = Double.parseDouble(startZCoords);
+                                
+                                double endXCoord = Double.parseDouble(endXCoords); // make negative
+                                double endYCoord = Double.parseDouble(endYCoords);
+                                double endZCoord = Double.parseDouble(endZCoords);
+                                
+                                double[] startCoords;
+                                double[] endCoords;
+                                if (actualDoTransform) {
+                                    DirectPosition2D startTargetPos = new DirectPosition2D();
+                                    DirectPosition2D startSourcePos = new DirectPosition2D(startXCoord, startYCoord);
+                                    DirectPosition startRes = actualTransform.transform(startSourcePos, startTargetPos);
+                                    startCoords = startRes.getCoordinate();
+                                    
+                                    DirectPosition2D endTargetPos = new DirectPosition2D();
+                                    DirectPosition2D endSourcePos = new DirectPosition2D(endXCoord, endYCoord);
+                                    DirectPosition endRes = actualTransform.transform(endSourcePos, endTargetPos);
+                                    endCoords = endRes.getCoordinate();
+                                } else {
+                                    startCoords = new double[] { startXCoord , startYCoord };
+                                    endCoords = new double[] { endXCoord , endYCoord };
+                                }
+                                
+                                // Switch to (longitude, latitude)
+                                flipAxes(startCoords);
+                                flipAxes(endCoords);
                                 
-                                writeValue(graph, row, diameterColumnIndex, edge, DN.Edge_HasDiameter);
-                                writeValue(graph, row, outerDiameterColumnIndex, edge, DN.Edge_HasOuterDiameter);
-                                writeValue(graph, row, nominalMassFlowIndex, edge, DN.Edge_HasNominalMassFlow);
-                                writeValue(graph, row, tGroundIndex, edge, DN.Edge_HasTGround);
-                                writeValue(graph, row, kReturnIndex, edge, DN.Edge_HasKReturn);
-                                writeValue(graph, row, kSupplyIndex, edge, DN.Edge_HasKSupply);
-                                writeValue(graph, row, edgeFlowAreaIndex, edge, DN.Edge_HasFlowArea);
-                                writeValue(graph, row, lengthIndex, edge, DN.Edge_HasLength);
-                                writeDoubleArrayFromString(graph, row, detailedGeometryIndex, edge, DN.Edge_HasGeometry, actualTransform);
+                                Optional<Resource> oedge = DNEdgeBuilder.create(graph, vv, model.getParentDiagram(), model.getComponentMappings().get(mappingValue), startCoords, startZCoord, endCoords, endZCoord, new double[0], padding, true);
+                                if (oedge.isPresent()) {
+                                    Resource edge = oedge.get();
+                                    
+                                    writeStringValue(graph, row, idColumn, edge, DN.HasId);
+                                    
+                                    writeValue(graph, row, diameterColumnIndex, edge, DN.Edge_HasDiameter);
+                                    writeValue(graph, row, outerDiameterColumnIndex, edge, DN.Edge_HasOuterDiameter);
+                                    writeValue(graph, row, nominalMassFlowIndex, edge, DN.Edge_HasNominalMassFlow);
+                                    writeValue(graph, row, tGroundIndex, edge, DN.Edge_HasTGround);
+                                    writeValue(graph, row, kReturnIndex, edge, DN.Edge_HasKReturn);
+                                    writeValue(graph, row, kSupplyIndex, edge, DN.Edge_HasKSupply);
+                                    writeValue(graph, row, edgeFlowAreaIndex, edge, DN.Edge_HasFlowArea);
+                                    writeValue(graph, row, lengthIndex, edge, DN.Edge_HasLength);
+                                    writeStringValue(graph, row, regionIndex, edge, DN.HasRegion);
+                                    writeDoubleArrayFromString(graph, row, detailedGeometryIndex, edge, DN.Edge_HasGeometry, actualTransform);
+                                }
                             }
-                            
                             return true;
                         } catch (DatabaseException | MismatchedDimensionException | TransformException e) {
                             throw new RuntimeException(e);
index e4aaeba992e10b6d7ccf52813c890062dfec8988..87547328b36afa7ea002841b4c35d1eb28e3fc8b 100644 (file)
@@ -201,6 +201,10 @@ DN.HasId --> L0.String <R L0.HasProperty : SEL.GenericParameterType
     L0.HasLabel "Id"
     L0.readOnly false
 
+DN.HasRegion --> L0.String <R L0.HasProperty : SEL.GenericParameterType
+    L0.HasLabel "Region"
+    L0.readOnly false
+
 DN.InLayer
     @L0.defTag 
     @L0.tag L0.Abstract
@@ -372,6 +376,7 @@ DN.Functions.convertToValue : L0.ExternalValue
 
 DN.Mapping.Base <T L0.Value
   >-- DN.Mapping.Id --> L0.String <R L0.HasProperty
+  >-- DN.Mapping.Region --> L0.String <R L0.HasProperty
   >-- DN.Mapping.ComponentType --> STR.ComponentType <R L0.DependsOn
   >-- DN.Mapping.Terminals --> DN.Mapping.TerminalPair <R L0.HasProperty
   @L0.assert L0.ConvertsToValueWith DN.Functions.convertToValue
index e41dd81705f489f71f2590989353ab1dffd6edf7..3632cb02b619a4b73d273863e40cb7f558408d96 100644 (file)
@@ -165,7 +165,6 @@ public class DistrictNetworkResource {
     public final Resource Diagram_splitToMultipleEnabled_Inverse;
     public final Resource Diagram_trackChangesEnabled;
     public final Resource Diagram_trackChangesEnabled_Inverse;
-    public final Resource DistrictNetworkHoverInfoStyle;
     public final Resource DistrictNetworkStaticInfoStyle;
     public final Resource DistrictNodeGroup;
     public final Resource DistrictNodeGroup_hasComponentTypeName;
@@ -218,6 +217,8 @@ public class DistrictNetworkResource {
     public final Resource HasInLayerTag_Inverse;
     public final Resource HasMapping;
     public final Resource HasMapping_Inverse;
+    public final Resource HasRegion;
+    public final Resource HasRegion_Inverse;
     public final Resource HasSRID;
     public final Resource HasSRID_Inverse;
     public final Resource HasSRTEXT;
@@ -266,6 +267,8 @@ public class DistrictNetworkResource {
     public final Resource Mapping_InputTerminal_Inverse;
     public final Resource Mapping_OutputTerminal;
     public final Resource Mapping_OutputTerminal_Inverse;
+    public final Resource Mapping_Region;
+    public final Resource Mapping_Region_Inverse;
     public final Resource Mapping_Terminal;
     public final Resource Mapping_TerminalPair;
     public final Resource Mapping_Terminals;
@@ -610,7 +613,6 @@ public class DistrictNetworkResource {
         public static final String Diagram_splitToMultipleEnabled_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/splitToMultipleEnabled/Inverse";
         public static final String Diagram_trackChangesEnabled = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/trackChangesEnabled";
         public static final String Diagram_trackChangesEnabled_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/trackChangesEnabled/Inverse";
-        public static final String DistrictNetworkHoverInfoStyle = "http://www.simantics.org/DistrictNetwork-1.0/DistrictNetworkHoverInfoStyle";
         public static final String DistrictNetworkStaticInfoStyle = "http://www.simantics.org/DistrictNetwork-1.0/DistrictNetworkStaticInfoStyle";
         public static final String DistrictNodeGroup = "http://www.simantics.org/DistrictNetwork-1.0/DistrictNodeGroup";
         public static final String DistrictNodeGroup_hasComponentTypeName = "http://www.simantics.org/DistrictNetwork-1.0/DistrictNodeGroup/hasComponentTypeName";
@@ -663,6 +665,8 @@ public class DistrictNetworkResource {
         public static final String HasInLayerTag_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasInLayerTag/Inverse";
         public static final String HasMapping = "http://www.simantics.org/DistrictNetwork-1.0/HasMapping";
         public static final String HasMapping_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasMapping/Inverse";
+        public static final String HasRegion = "http://www.simantics.org/DistrictNetwork-1.0/HasRegion";
+        public static final String HasRegion_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasRegion/Inverse";
         public static final String HasSRID = "http://www.simantics.org/DistrictNetwork-1.0/HasSRID";
         public static final String HasSRID_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasSRID/Inverse";
         public static final String HasSRTEXT = "http://www.simantics.org/DistrictNetwork-1.0/HasSRTEXT";
@@ -711,6 +715,8 @@ public class DistrictNetworkResource {
         public static final String Mapping_InputTerminal_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/InputTerminal/Inverse";
         public static final String Mapping_OutputTerminal = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/OutputTerminal";
         public static final String Mapping_OutputTerminal_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/OutputTerminal/Inverse";
+        public static final String Mapping_Region = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/Region";
+        public static final String Mapping_Region_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/Region/Inverse";
         public static final String Mapping_Terminal = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/Terminal";
         public static final String Mapping_TerminalPair = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/TerminalPair";
         public static final String Mapping_Terminals = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/Terminals";
@@ -1065,7 +1071,6 @@ public class DistrictNetworkResource {
         Diagram_splitToMultipleEnabled_Inverse = getResourceOrNull(graph, URIs.Diagram_splitToMultipleEnabled_Inverse);
         Diagram_trackChangesEnabled = getResourceOrNull(graph, URIs.Diagram_trackChangesEnabled);
         Diagram_trackChangesEnabled_Inverse = getResourceOrNull(graph, URIs.Diagram_trackChangesEnabled_Inverse);
-        DistrictNetworkHoverInfoStyle = getResourceOrNull(graph, URIs.DistrictNetworkHoverInfoStyle);
         DistrictNetworkStaticInfoStyle = getResourceOrNull(graph, URIs.DistrictNetworkStaticInfoStyle);
         DistrictNodeGroup = getResourceOrNull(graph, URIs.DistrictNodeGroup);
         DistrictNodeGroup_hasComponentTypeName = getResourceOrNull(graph, URIs.DistrictNodeGroup_hasComponentTypeName);
@@ -1118,6 +1123,8 @@ public class DistrictNetworkResource {
         HasInLayerTag_Inverse = getResourceOrNull(graph, URIs.HasInLayerTag_Inverse);
         HasMapping = getResourceOrNull(graph, URIs.HasMapping);
         HasMapping_Inverse = getResourceOrNull(graph, URIs.HasMapping_Inverse);
+        HasRegion = getResourceOrNull(graph, URIs.HasRegion);
+        HasRegion_Inverse = getResourceOrNull(graph, URIs.HasRegion_Inverse);
         HasSRID = getResourceOrNull(graph, URIs.HasSRID);
         HasSRID_Inverse = getResourceOrNull(graph, URIs.HasSRID_Inverse);
         HasSRTEXT = getResourceOrNull(graph, URIs.HasSRTEXT);
@@ -1166,6 +1173,8 @@ public class DistrictNetworkResource {
         Mapping_InputTerminal_Inverse = getResourceOrNull(graph, URIs.Mapping_InputTerminal_Inverse);
         Mapping_OutputTerminal = getResourceOrNull(graph, URIs.Mapping_OutputTerminal);
         Mapping_OutputTerminal_Inverse = getResourceOrNull(graph, URIs.Mapping_OutputTerminal_Inverse);
+        Mapping_Region = getResourceOrNull(graph, URIs.Mapping_Region);
+        Mapping_Region_Inverse = getResourceOrNull(graph, URIs.Mapping_Region_Inverse);
         Mapping_Terminal = getResourceOrNull(graph, URIs.Mapping_Terminal);
         Mapping_TerminalPair = getResourceOrNull(graph, URIs.Mapping_TerminalPair);
         Mapping_Terminals = getResourceOrNull(graph, URIs.Mapping_Terminals);