]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Make optional to calculate elevation for edge during CSV import 65/2165/1
authorjsimomaa <jani.simomaa@gmail.com>
Wed, 12 Sep 2018 17:32:15 +0000 (20:32 +0300)
committerjsimomaa <jani.simomaa@gmail.com>
Wed, 12 Sep 2018 17:32:15 +0000 (20:32 +0300)
gitlab #10

Change-Id: I64141c02990cf306acbec11d05833e8ed7890471

org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportModel.java
org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizard.java
org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizardPage.java
org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph
org.simantics.district.network.ui/src/org/simantics/district/network/ui/DNEdgeBuilder.java

index 9d5bd715c316b8ef2d6de0fb34251b8f3aee8592..7c660b4c70c9df6605bce156f87a2f041438eba2 100644 (file)
@@ -70,6 +70,7 @@ public class CSVImportModel {
     private double edgePadding = 0.0001; // default
     private int valvePositionIndx = -1;
     private int addressIndex;
+    private int lengthIndex;
     
     // Third page
 
@@ -482,4 +483,12 @@ public class CSVImportModel {
     public int getAddressIndex() {
         return addressIndex;
     }
+
+    public int getLengthIndex() {
+        return lengthIndex;
+    }
+    
+    public void setLengthIndex(int lengthIndex) {
+        this.lengthIndex = lengthIndex;
+    }
 }
index ffed0c3a14e21da671ab207b7cab185e6b5587f9..490c9505ecde9e459b1c9c2547d38e0e7b41278a 100644 (file)
@@ -107,6 +107,7 @@ public class CSVImportWizard extends Wizard implements IImportWizard {
                         int edgeFlowAreaIndex = model.getEdgeFlowAreaIndex();
                         int kReturnIndex = model.getkReturnIndex();
                         int kSupplyIndex = model.getkSupplyIndex();
+                        int lengthIndex = model.getLengthIndex();
                         
                         int mappingColumn = model.getComponentMappingIndex();
                         int idColumn = model.getIdIndex();
@@ -230,7 +231,7 @@ public class CSVImportWizard extends Wizard implements IImportWizard {
                                                 endCoords = new double[] { endXCoord , endYCoord };
                                             }
 
-                                            Resource edge = DNEdgeBuilder.create(graph, vv, model.getParentDiagram(), model.getComponentMappings().get(mappingValue), startCoords, endCoords, padding);
+                                            Resource edge = DNEdgeBuilder.create(graph, vv, model.getParentDiagram(), model.getComponentMappings().get(mappingValue), startCoords, endCoords, padding, true);
                                             writeStringValue(graph, row, idColumn, edge, DN.HasId);
                                             
                                             writeValue(graph, row, diameterColumnIndex, edge, DN.Edge_HasDiameter);
@@ -240,6 +241,7 @@ public class CSVImportWizard extends Wizard implements IImportWizard {
                                             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);
                                         }
                                     } catch (MismatchedDimensionException | TransformException | DatabaseException e) {
                                         throw new DatabaseException(e);
index e5cb3a6afba8f8ed2df8cab2e53214124f80a759..b7e46475dcec4f00c2b4069476de5084364b8b4e 100644 (file)
@@ -12,7 +12,6 @@ import org.eclipse.jface.dialogs.IPageChangeProvider;
 import org.eclipse.jface.dialogs.IPageChangedListener;
 import org.eclipse.jface.dialogs.PageChangedEvent;
 import org.eclipse.jface.layout.GridDataFactory;
-import org.eclipse.jface.layout.GridLayoutFactory;
 import org.eclipse.jface.layout.TableColumnLayout;
 import org.eclipse.jface.viewers.ColumnWeightData;
 import org.eclipse.jface.wizard.IWizardContainer;
@@ -79,6 +78,7 @@ public class CSVImportWizardPage extends WizardPage {
     private DynamicComboFieldEditor nominalPressureLossSelector;
     private DynamicComboFieldEditor valvePositionSelector;
     private DynamicComboFieldEditor addressSelector;
+    private DynamicComboFieldEditor lengthSelector;
 
     // For edge import
     private DynamicComboFieldEditor startXCoordSelector;
@@ -654,6 +654,8 @@ public class CSVImportWizardPage extends WizardPage {
                 validatePageComplete();
             }
         });
+        
+
     }
 
     private void createEdgeIndexMappingField(Group parent) {
@@ -846,6 +848,20 @@ public class CSVImportWizardPage extends WizardPage {
                 validatePageComplete();
             }
         });
+        lengthSelector = new DynamicComboFieldEditor("lengthValue", "lengthSelector", parent);
+        lengthSelector.addComboListener(new SelectionListener() {
+
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                widgetDefaultSelected(e);
+            }
+
+            @Override
+            public void widgetDefaultSelected(SelectionEvent e) {
+                model.setLengthIndex(Integer.parseInt(lengthSelector.getValue()));
+                validatePageComplete();
+            }
+        });
     }
 
     private void updateCombos() {
@@ -886,6 +902,7 @@ public class CSVImportWizardPage extends WizardPage {
         kReturnSelector.updateCombo(namesAndValues);
         kSupplySelector.updateCombo(namesAndValues);
         tGroundSelector.updateCombo(namesAndValues);
+        lengthSelector.updateCombo(namesAndValues);
     }
 
     private void updateVertexCombos(String[][] namesAndValues) {
@@ -910,7 +927,7 @@ public class CSVImportWizardPage extends WizardPage {
         velocitySelector.updateCombo(namesAndValues);              
         flowAreaSelector.updateCombo(namesAndValues);              
         nominalPressureLossSelector.updateCombo(namesAndValues);   
-        addressSelector.updateCombo(namesAndValues);   
+        addressSelector.updateCombo(namesAndValues);
     }
     
     
index 657ffc697edcb246eeb45d01da266764b14018f5..e9c52cc71ce56d6fadbd91cb0973ce877ae36006 100644 (file)
@@ -80,6 +80,8 @@ DN.Vertex <T DN.Element
     @L0.assert DN.Vertex.HasElevation 0.0
 
 DN.Edge <T DN.Element
+    >-- DN.Edge.HasElevation
+        @defProperty "Elevation" L0.Double
     >-- DN.Edge.HasLength 
         @defProperty "Length" L0.Double
         L0.readOnly true
@@ -249,4 +251,5 @@ DN.Mapping.EdgeMapping <T DN.Mapping.Base
     >-- DN.Mapping.EdgeMapping.KReturnAttribute --> L0.String <R L0.HasProperty
     >-- DN.Mapping.EdgeMapping.KSupplyAttribute --> L0.String <R L0.HasProperty
     >-- DN.Mapping.EdgeMapping.TGroundAttribute --> L0.String <R L0.HasProperty
+    >-- DN.Mapping.EdgeMapping.ElevationAttribute --> L0.String <R L0.HasProperty
     >-- DN.Mapping.Terminals
index 0270fea0277eaa0c799fb8556a4367bc50e6c578..0df72c517f533f79e89dbee085b64819ec76cb9f 100644 (file)
@@ -9,16 +9,16 @@ import org.simantics.databoard.Bindings;
 import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.common.request.ObjectsWithType;
+import org.simantics.db.exception.BindingException;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;
+import org.simantics.db.exception.ServiceException;
 import org.simantics.db.layer0.util.Layer0Utils;
 import org.simantics.diagram.stubs.DiagramResource;
 import org.simantics.diagram.synchronization.IModifiableSynchronizationContext;
 import org.simantics.diagram.synchronization.SynchronizationHints;
-import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;
 import org.simantics.diagram.synchronization.graph.GraphSynchronizationHints;
-import org.simantics.diagram.synchronization.graph.layer.GraphLayer;
 import org.simantics.diagram.synchronization.graph.layer.GraphLayerManager;
-import org.simantics.diagram.synchronization.graph.layer.IGraphLayerUtil;
 import org.simantics.district.network.DistrictNetworkUtil;
 import org.simantics.district.network.ontology.DistrictNetworkResource;
 import org.simantics.g2d.diagram.IDiagram;
@@ -45,10 +45,10 @@ public class DNEdgeBuilder {
             double[] existingCoords = graph.getRelatedValue2(vertex, DiagramResource.getInstance(graph).HasLocation, Bindings.DOUBLE_ARRAY);
             vv.add(new ResourceVertex(vertex, existingCoords));
         }
-        return create(graph, vv, diagramResource, null, start, end, padding);
+        return create(graph, vv, diagramResource, null, start, end, padding, false);
     }
     
-    public static Resource create(WriteGraph graph, Collection<ResourceVertex> vertices, Resource diagramResource, Resource mapping, double[] start, double[] end, double padding) throws DatabaseException {
+    public static Resource create(WriteGraph graph, Collection<ResourceVertex> vertices, Resource diagramResource, Resource mapping, double[] start, double[] end, double padding, boolean writeElevationToEdgeFromPoints) throws DatabaseException {
         
         DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
         
@@ -58,6 +58,9 @@ public class DNEdgeBuilder {
         // 2. Add vertices
         Resource startVertex = getOrCreateVertex(graph, diagramResource, vertices, start, padding, null);
         Resource endVertex = getOrCreateVertex(graph, diagramResource, vertices, end, padding, startVertex);
+        if (writeElevationToEdgeFromPoints) {
+            graph.claimLiteral(edge, DN.Edge_HasElevation, calculateElevationFromVertices(graph, startVertex, endVertex), Bindings.DOUBLE);
+        }
         
         graph.claim(edge, DN.HasStartVertex, startVertex);
         graph.claim(edge, DN.HasEndVertex, endVertex);
@@ -75,6 +78,16 @@ public class DNEdgeBuilder {
 //        
         return edge;
     }
+    private static double calculateElevationFromVertices(WriteGraph graph, Resource startVertex, Resource endVertex) throws ManyObjectsForFunctionalRelationException, BindingException, ServiceException {
+        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+        Double startElevation = graph.getPossibleRelatedValue(startVertex, DN.Vertex_HasElevation, Bindings.DOUBLE);
+        Double endElevation = graph.getPossibleRelatedValue(endVertex, DN.Vertex_HasElevation, Bindings.DOUBLE);
+        if (startElevation != null && endElevation != null) {
+            return (startElevation + endElevation) / 2;
+        }
+        return 0;
+    }
+
     public void create(WriteGraph graph,  double[] start, double[] end, double padding) throws DatabaseException {
         
         Resource edge = create(graph, diagramResource, start, end, padding);