]> gerrit.simantics Code Review - simantics/district.git/commitdiff
New sewage system modelling features for the mapping tool. sewage-features
authorMiia Rantala <miia.rantala@vtt.fi>
Wed, 30 Aug 2017 09:40:15 +0000 (12:40 +0300)
committerMiia Rantala <miia.rantala@vtt.fi>
Wed, 30 Aug 2017 09:40:15 +0000 (12:40 +0300)
Change-Id: I275e90bd2fe3a15a65ffd22eb96fd3c83e5c25ae

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.ontology/scl/Simantics/District/ComponentMapping.scl
org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java
org.simantics.district.network.ui/fragment.e4xmi
org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/SimplifyPointVerticesHandler.java [new file with mode: 0644]
org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/SimplifySewageVerticesHandler.java [new file with mode: 0644]

index 2f13692bd0af5f49dcc3f8289084c3bccc551a69..eb27ebc1db5b34b34522c6c93272f6cd8a0f3d63 100644 (file)
@@ -47,6 +47,7 @@ public class CSVImportModel {
     private int diameterIndex;
     private int outerDiamterIndex;
     private int nominalMassFlowIndex;
+    private int sewageProductionIndex;
     
     // Third page
 
@@ -275,5 +276,13 @@ public class CSVImportModel {
     public int getNominalMassFlowIndex() {
         return nominalMassFlowIndex;
     }
+    
+    public void setSewageProductionIndex(int sewageProductionIndex) {
+        this.sewageProductionIndex = sewageProductionIndex;
+    }
+    
+    public int getSewageProductionIndex() {
+        return sewageProductionIndex;
+    }
 
 }
index 703ade176923886f2691d9fe47d034d9f5ef33b7..c6b4ba1637072e652ec5d6f7dd0d4e05ee3333de 100644 (file)
@@ -69,6 +69,7 @@ public class CSVImportWizard extends Wizard implements IImportWizard {
                         int zCoordColumnIndex = model.getZCoordIndex();
                         int tempColumnIndex = model.getTempIndex();
                         int pressureColumnIndex = model.getPressureIndex();
+                        int sewageProductionColumnIndex = model.getSewageProductionIndex();
                         
                         int startXCoordColumnIndex = model.getStartXCoordIndex();
                         int startYCoordColumnIndex = model.getStartYCoordIndex();
@@ -154,6 +155,15 @@ public class CSVImportWizard extends Wizard implements IImportWizard {
                                                 } catch (NumberFormatException e) {
                                                     throw new DatabaseException(e);
                                                 }
+                                            }
+                                                                                       String sewageProductionS = row.get(sewageProductionColumnIndex);
+                                            if (!sewageProductionS.isEmpty()) {
+                                                try {
+                                                    double sewageProduction = Double.parseDouble(sewageProductionS);
+                                                    graph.claimLiteral(vertex, DN.Vertex_HasSewageProduction, sewageProduction, Bindings.DOUBLE);
+                                                } catch (NumberFormatException e) {
+                                                    throw new DatabaseException(e);
+                                                }
                                             }
 
                                         } else {
index e1b81e0f10df3b6fad4729d26e77754c0460dd06..df04cb3258443391cbf38298185d8d84f845291c 100644 (file)
@@ -64,6 +64,7 @@ public class CSVImportWizardPage extends WizardPage {
     private DynamicComboFieldEditor endZValueSelector;
     private DynamicComboFieldEditor tempValueSelector;
     private DynamicComboFieldEditor pressureValueSelector;
+    private DynamicComboFieldEditor sewageProductionValueSelector;
     
     private DynamicComboFieldEditor outerDiameterSelector;
     private DynamicComboFieldEditor diameterSelector;
@@ -318,6 +319,21 @@ public class CSVImportWizardPage extends WizardPage {
                 validatePageComplete();
             }
         });
+        
+        sewageProductionValueSelector = new DynamicComboFieldEditor("sewageProductionValue", "Sewage production value", parent);
+        sewageProductionValueSelector.addComboListener(new SelectionListener() {
+
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                widgetDefaultSelected(e);
+            }
+
+            @Override
+            public void widgetDefaultSelected(SelectionEvent e) {
+                model.setSewageProductionIndex(Integer.parseInt(sewageProductionValueSelector.getValue()));
+                validatePageComplete();
+            }
+        });
     }
 
     private void createEdgeIndexMappingField(Group parent) {
@@ -492,6 +508,7 @@ public class CSVImportWizardPage extends WizardPage {
         zValueSelector.updateCombo(namesAndValues);
         pressureValueSelector.updateCombo(namesAndValues);
         tempValueSelector.updateCombo(namesAndValues);
+        sewageProductionValueSelector.updateCombo(namesAndValues);
     }
 
     private void updateHeaders() {
@@ -552,7 +569,7 @@ public class CSVImportWizardPage extends WizardPage {
         if (model.isVertexImport())
             setPageComplete(model.getXCoordIndex() != -1 && model.getYCoordIndex() != -1 && model.getComponentMappingIndex() != -1);
         else
-            setPageComplete(model.getStartXCoordIndex() != 1 && model.getStartYCoordIndex() != -1 && model.getEndXCoordIndex() != -1 && model.getEndYCoordIndex() != -1 && model.getComponentMappingIndex() != -1);
+            setPageComplete(model.getStartXCoordIndex() != -1 && model.getStartYCoordIndex() != -1 && model.getEndXCoordIndex() != -1 && model.getEndYCoordIndex() != -1 && model.getComponentMappingIndex() != -1);
     }
 
 }
index e819f445fb714a6e708e1dff5cb511bff56d62ec..138e72aed8ca4587a3518c2fcf7de3ca7452d95e 100644 (file)
@@ -20,6 +20,7 @@ DN.Edge <T DIA.Element : L0.Type
 
 DN.Vertex <T DIA.Element : L0.Type
     @L0.assert DN.Vertex.HasElevation 0.0
+    @L0.assert DN.Vertex.HasSewageProduction 0.0
 
 DN.EdgeDefaultMapping <R L0.HasProperty : DN.EdgeMappingParameterType
     L0.HasLabel "Default Edge mapping"
@@ -65,6 +66,11 @@ DN.Vertex.HasElevation <R L0.HasProperty : SEL.GenericParameterType
     L0.HasRange L0.Double
     L0.readOnly false
 
+DN.Vertex.HasSewageProduction <R L0.HasProperty : SEL.GenericParameterType
+    L0.HasLabel "Sewage Production"
+    L0.HasRange L0.Double
+    L0.readOnly false
+    
 DN.Vertex.HasTemperature <R L0.HasProperty : SEL.GenericParameterType
     L0.HasLabel "Temperature"
     L0.HasRange L0.Double
@@ -85,6 +91,10 @@ DN.Edge.HasNominalMassFlow <R L0.HasProperty : SEL.GenericParameterType
     L0.HasRange L0.Double
     L0.readOnly false
 
+DN.Edge.HasRevisedLength <R L0.HasProperty : SEL.GenericParameterType
+    L0.HasLabel "Revised Length"
+    L0.HasRange L0.Double
+    L0.readOnly true
 
 DN.InLayer
     @L0.defTag 
@@ -191,6 +201,7 @@ DN.Mapping.TerminalPair <T L0.Entity
 DN.Mapping.VertexMapping <T DN.Mapping.Base
     >-- DN.Mapping.ComponentType --> STR.ComponentType <R L0.DependsOn
     >-- DN.Mapping.VertexMapping.ElevationAttribute --> L0.String <R L0.HasProperty
+    >-- DN.Mapping.VertexMapping.SewageProductionAttribute --> L0.String <R L0.HasProperty
     >-- DN.Mapping.VertexMapping.TemperatureAttribute --> L0.String <R L0.HasProperty
     >-- DN.Mapping.VertexMapping.PressureAttribute --> L0.String <R L0.HasProperty
     >-- DN.Mapping.Terminals --> DN.Mapping.TerminalPair <R L0.HasProperty
index c7766365a0e837e22e608171ee35c7709fb5384b..cc742337f685f00f697f5ed379836986155066dd 100644 (file)
@@ -1,6 +1,7 @@
 data VertexMapping = VertexMapping {
     componentType :: String,
     elevationAttribute :: String,
+    sewageProductionAttribute :: String,
     terminals :: [TerminalPair]
 }
 
index 4adb19d3ad36d874f4ae381e1dd046bd0dadb8e8..b7a7b798bf5c44c69c91274e5768139d89ce45f6 100644 (file)
@@ -33,6 +33,8 @@ public class DistrictNetworkResource {
     public final Resource Edge_HasNominalMassFlow_Inverse;
     public final Resource Edge_HasOuterDiameter;
     public final Resource Edge_HasOuterDiameter_Inverse;
+    public final Resource Edge_HasRevisedLength;
+    public final Resource Edge_HasRevisedLength_Inverse;
     public final Resource Functions;
     public final Resource Functions_compositeInstantiator;
     public final Resource Functions_convertToValue;
@@ -86,6 +88,8 @@ public class DistrictNetworkResource {
     public final Resource Mapping_VertexMapping_ElevationAttribute_Inverse;
     public final Resource Mapping_VertexMapping_PressureAttribute;
     public final Resource Mapping_VertexMapping_PressureAttribute_Inverse;
+    public final Resource Mapping_VertexMapping_SewageProductionAttribute;
+    public final Resource Mapping_VertexMapping_SewageProductionAttribute_Inverse;
     public final Resource Mapping_VertexMapping_TemperatureAttribute;
     public final Resource Mapping_VertexMapping_TemperatureAttribute_Inverse;
     public final Resource SpatialRefSystem;
@@ -97,6 +101,8 @@ public class DistrictNetworkResource {
     public final Resource Vertex_HasElevation_Inverse;
     public final Resource Vertex_HasPressure;
     public final Resource Vertex_HasPressure_Inverse;
+    public final Resource Vertex_HasSewageProduction;
+    public final Resource Vertex_HasSewageProduction_Inverse;
     public final Resource Vertex_HasTemperature;
     public final Resource Vertex_HasTemperature_Inverse;
         
@@ -124,6 +130,8 @@ public class DistrictNetworkResource {
         public static final String Edge_HasNominalMassFlow_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasNominalMassFlow/Inverse";
         public static final String Edge_HasOuterDiameter = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasOuterDiameter";
         public static final String Edge_HasOuterDiameter_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasOuterDiameter/Inverse";
+        public static final String Edge_HasRevisedLength = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasRevisedLength";
+        public static final String Edge_HasRevisedLength_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasRevisedLength/Inverse";
         public static final String Functions = "http://www.simantics.org/DistrictNetwork-1.0/Functions";
         public static final String Functions_compositeInstantiator = "http://www.simantics.org/DistrictNetwork-1.0/Functions/compositeInstantiator";
         public static final String Functions_convertToValue = "http://www.simantics.org/DistrictNetwork-1.0/Functions/convertToValue";
@@ -177,6 +185,8 @@ public class DistrictNetworkResource {
         public static final String Mapping_VertexMapping_ElevationAttribute_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/VertexMapping/ElevationAttribute/Inverse";
         public static final String Mapping_VertexMapping_PressureAttribute = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/VertexMapping/PressureAttribute";
         public static final String Mapping_VertexMapping_PressureAttribute_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/VertexMapping/PressureAttribute/Inverse";
+        public static final String Mapping_VertexMapping_SewageProductionAttribute = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/VertexMapping/SewageProductionAttribute";
+        public static final String Mapping_VertexMapping_SewageProductionAttribute_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/VertexMapping/SewageProductionAttribute/Inverse";
         public static final String Mapping_VertexMapping_TemperatureAttribute = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/VertexMapping/TemperatureAttribute";
         public static final String Mapping_VertexMapping_TemperatureAttribute_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/VertexMapping/TemperatureAttribute/Inverse";
         public static final String SpatialRefSystem = "http://www.simantics.org/DistrictNetwork-1.0/SpatialRefSystem";
@@ -188,6 +198,8 @@ public class DistrictNetworkResource {
         public static final String Vertex_HasElevation_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Vertex/HasElevation/Inverse";
         public static final String Vertex_HasPressure = "http://www.simantics.org/DistrictNetwork-1.0/Vertex/HasPressure";
         public static final String Vertex_HasPressure_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Vertex/HasPressure/Inverse";
+        public static final String Vertex_HasSewageProduction = "http://www.simantics.org/DistrictNetwork-1.0/Vertex/HasSewageProduction";
+        public static final String Vertex_HasSewageProduction_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Vertex/HasSewageProduction/Inverse";
         public static final String Vertex_HasTemperature = "http://www.simantics.org/DistrictNetwork-1.0/Vertex/HasTemperature";
         public static final String Vertex_HasTemperature_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Vertex/HasTemperature/Inverse";
     }
@@ -225,6 +237,8 @@ public class DistrictNetworkResource {
         Edge_HasNominalMassFlow_Inverse = getResourceOrNull(graph, URIs.Edge_HasNominalMassFlow_Inverse);
         Edge_HasOuterDiameter = getResourceOrNull(graph, URIs.Edge_HasOuterDiameter);
         Edge_HasOuterDiameter_Inverse = getResourceOrNull(graph, URIs.Edge_HasOuterDiameter_Inverse);
+        Edge_HasRevisedLength = getResourceOrNull(graph, URIs.Edge_HasRevisedLength);
+        Edge_HasRevisedLength_Inverse = getResourceOrNull(graph, URIs.Edge_HasRevisedLength_Inverse);
         Functions = getResourceOrNull(graph, URIs.Functions);
         Functions_compositeInstantiator = getResourceOrNull(graph, URIs.Functions_compositeInstantiator);
         Functions_convertToValue = getResourceOrNull(graph, URIs.Functions_convertToValue);
@@ -278,6 +292,8 @@ public class DistrictNetworkResource {
         Mapping_VertexMapping_ElevationAttribute_Inverse = getResourceOrNull(graph, URIs.Mapping_VertexMapping_ElevationAttribute_Inverse);
         Mapping_VertexMapping_PressureAttribute = getResourceOrNull(graph, URIs.Mapping_VertexMapping_PressureAttribute);
         Mapping_VertexMapping_PressureAttribute_Inverse = getResourceOrNull(graph, URIs.Mapping_VertexMapping_PressureAttribute_Inverse);
+        Mapping_VertexMapping_SewageProductionAttribute = getResourceOrNull(graph, URIs.Mapping_VertexMapping_SewageProductionAttribute);
+        Mapping_VertexMapping_SewageProductionAttribute_Inverse = getResourceOrNull(graph, URIs.Mapping_VertexMapping_SewageProductionAttribute_Inverse);
         Mapping_VertexMapping_TemperatureAttribute = getResourceOrNull(graph, URIs.Mapping_VertexMapping_TemperatureAttribute);
         Mapping_VertexMapping_TemperatureAttribute_Inverse = getResourceOrNull(graph, URIs.Mapping_VertexMapping_TemperatureAttribute_Inverse);
         SpatialRefSystem = getResourceOrNull(graph, URIs.SpatialRefSystem);
@@ -289,6 +305,8 @@ public class DistrictNetworkResource {
         Vertex_HasElevation_Inverse = getResourceOrNull(graph, URIs.Vertex_HasElevation_Inverse);
         Vertex_HasPressure = getResourceOrNull(graph, URIs.Vertex_HasPressure);
         Vertex_HasPressure_Inverse = getResourceOrNull(graph, URIs.Vertex_HasPressure_Inverse);
+        Vertex_HasSewageProduction = getResourceOrNull(graph, URIs.Vertex_HasSewageProduction);
+        Vertex_HasSewageProduction_Inverse = getResourceOrNull(graph, URIs.Vertex_HasSewageProduction_Inverse);
         Vertex_HasTemperature = getResourceOrNull(graph, URIs.Vertex_HasTemperature);
         Vertex_HasTemperature_Inverse = getResourceOrNull(graph, URIs.Vertex_HasTemperature_Inverse);
     }
index 6271c820f9461fb62235ecd828909484d2c9e79c..b81f9adc656656096fabc02a66d08f3099ee97bd 100644 (file)
@@ -9,6 +9,8 @@
     <elements xsi:type="commands:Command" xmi:id="_A1HBQOFYEeaJP6VyXP72Jw" elementId="org.simantics.district.network.ui.joinVertices" commandName="Join Vertices"/>
     <elements xsi:type="commands:Command" xmi:id="_QzdUQOIcEeaJP6VyXP72Jw" elementId="org.simantics.district.network.ui.setFocusable" commandName="Set Focusable"/>
     <elements xsi:type="commands:Command" xmi:id="_4wJtADWxEeeVXaXEq4_qpA" elementId="org.simantics.district.network.ui.command.changemapping" commandName="Change Mapping"/>
+    <elements xsi:type="commands:Command" xmi:id="_XKNggHwjEeeX39AS-AGdqw" elementId="org.simantics.district.network.ui.command.simplifyPointVertices" commandName="Simplify Point Vertices"/>
+    <elements xsi:type="commands:Command" xmi:id="_OnqzgHwqEeeX39AS-AGdqw" elementId="org.simantics.district.network.ui.command.simplifySewageVertices" commandName="Simplify Sewage Vertices"/>
   </fragments>
   <fragments xsi:type="fragment:StringModelFragment" xmi:id="_Js7rUMMAEea1mdgpHNVHMA" featurename="menuContributions" parentElementId="xpath:/">
     <elements xsi:type="menu:MenuContribution" xmi:id="_MbrJgMMAEea1mdgpHNVHMA" elementId="org.simantics.district.network.ui.menucontribution.0" parentId="help">
       <children xsi:type="menu:HandledMenuItem" xmi:id="_O_UgUOIgEeaJP6VyXP72Jw" elementId="org.simantics.district.network.ui.handledmenuitem.joinvertices" label="Join Vertices" iconURI="platform:/plugin/org.simantics.ui/icons/etool16/arrow_join.png" tooltip="Join multiple vertices as one" command="_A1HBQOFYEeaJP6VyXP72Jw"/>
       <children xsi:type="menu:DynamicMenuContribution" xmi:id="_dieAsOIgEeaJP6VyXP72Jw" elementId="org.simantics.district.network.ui.dynamicmenucontribution.setFocusable" label="Set Focusable" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.contributions.SetFocusableDynamicMenuContribution"/>
       <children xsi:type="menu:HandledMenuItem" xmi:id="_QbF4UDWyEeeVXaXEq4_qpA" elementId="org.simantics.district.network.ui.handledmenuitem.changemapping" label="Change Mapping" tooltip="Change mapping of multiple elements" command="_4wJtADWxEeeVXaXEq4_qpA"/>
+      <children xsi:type="menu:HandledMenuItem" xmi:id="_oUGZoHwjEeeX39AS-AGdqw" elementId="org.simantics.district.network.ui.handledmenuitem.simplifypointvertices" label="Simplify Point Vertices" tooltip="Simplify Point Vertices" command="_XKNggHwjEeeX39AS-AGdqw"/>
+      <children xsi:type="menu:HandledMenuItem" xmi:id="_ZKZLYHwqEeeX39AS-AGdqw" elementId="org.simantics.district.network.ui.handledmenuitem.simplifysewagevertices" label="Simplify Sewage Vertices" tooltip="Simplify sewage vertices" command="_OnqzgHwqEeeX39AS-AGdqw"/>
     </elements>
   </fragments>
   <fragments xsi:type="fragment:StringModelFragment" xmi:id="_dbiHcMMBEea1mdgpHNVHMA" featurename="handlers" parentElementId="xpath:/">
     <elements xsi:type="commands:Handler" xmi:id="_DPcVsOFYEeaJP6VyXP72Jw" elementId="org.simantics.district.network.ui.handler.joinVertices" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.contributions.JoinVerticesHandler" command="_A1HBQOFYEeaJP6VyXP72Jw"/>
     <elements xsi:type="commands:Handler" xmi:id="_VPgBwOIcEeaJP6VyXP72Jw" elementId="org.simantics.district.network.ui.handler.setFocusable" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.contributions.SetFocusableHandler" command="_QzdUQOIcEeaJP6VyXP72Jw"/>
     <elements xsi:type="commands:Handler" xmi:id="_LojWYDWyEeeVXaXEq4_qpA" elementId="org.simantics.district.network.ui.handler.0" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.contributions.ChangeMappingTypeHandler" command="_4wJtADWxEeeVXaXEq4_qpA"/>
+    <elements xsi:type="commands:Handler" xmi:id="_euxeIHwjEeeX39AS-AGdqw" elementId="org.simantics.district.network.ui.handler.simplifyPointVertices" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.contributions.SimplifyPointVerticesHandler" command="_XKNggHwjEeeX39AS-AGdqw"/>
+    <elements xsi:type="commands:Handler" xmi:id="_UpVbAHwqEeeX39AS-AGdqw" elementId="org.simantics.district.network.ui.handler.simplifySewageVertices" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.contributions.SimplifySewageVerticesHandler" command="_OnqzgHwqEeeX39AS-AGdqw"/>
   </fragments>
 </fragment:ModelFragments>
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/SimplifyPointVerticesHandler.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/SimplifyPointVerticesHandler.java
new file mode 100644 (file)
index 0000000..14bb9e3
--- /dev/null
@@ -0,0 +1,50 @@
+package org.simantics.district.network.ui.contributions;
+
+import javax.inject.Named;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.ui.IEditorPart;
+import org.simantics.Simantics;
+import org.simantics.ui.workbench.IResourceEditorInput;
+import org.simantics.ui.workbench.e4.E4WorkbenchUtils;
+import org.simantics.district.network.ui.internal.Activator;
+import org.simantics.DatabaseJob;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.exception.DatabaseException;
+
+public class SimplifyPointVerticesHandler {
+
+    @Execute
+    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart mActiveEditorPart) {
+        IEditorPart activeEditorPart = E4WorkbenchUtils.getActiveIEditorPart(mActiveEditorPart);
+        IResourceEditorInput input = (IResourceEditorInput) activeEditorPart.getEditorInput();
+        
+        Job job = new DatabaseJob("Simplify Point Vertices") {
+            
+            @Override
+            protected IStatus run(IProgressMonitor monitor) {
+                try {
+                    Simantics.getSession().syncRequest(new WriteRequest() {
+                        
+                        @Override
+                        public void perform(WriteGraph graph) throws DatabaseException {
+                            Simantics.applySCL("Apros/District/SimplifyMapping", "simplifyPointVertices", graph, input.getResource());
+                        }
+                    });
+                } catch (DatabaseException e) {
+                    return new Status(IStatus.ERROR, Activator.PLUGIN_ID, getName() + " failed.", e);
+                }
+                return Status.OK_STATUS;
+            }
+        };
+        job.setUser(true);
+        job.schedule();
+    }
+
+}
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/SimplifySewageVerticesHandler.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/SimplifySewageVerticesHandler.java
new file mode 100644 (file)
index 0000000..308117b
--- /dev/null
@@ -0,0 +1,141 @@
+package org.simantics.district.network.ui.contributions;
+
+import javax.inject.Named;
+import java.util.HashMap;
+import java.util.Map;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.SelectionStatusDialog;
+import org.simantics.DatabaseJob;
+import org.simantics.Simantics;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.ui.workbench.IResourceEditorInput;
+import org.simantics.ui.workbench.e4.E4WorkbenchUtils;
+import org.simantics.district.network.ui.internal.Activator;
+import org.simantics.district.network.ui.function.Functions;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.ReadRequest;
+
+public class SimplifySewageVerticesHandler {
+    
+    @Execute
+    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart mActiveEditorPart) {
+        IEditorPart activeEditorPart = E4WorkbenchUtils.getActiveIEditorPart(mActiveEditorPart);
+        IResourceEditorInput input = (IResourceEditorInput) activeEditorPart.getEditorInput();
+        
+        SelectMappingDialog dialog = new SelectMappingDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), input.getResource());
+        if (dialog.open() != Dialog.OK)
+            return;
+        
+        Resource mapping = dialog.getSewageVertexMapping();
+        Job job = new DatabaseJob("Simplify Sewage Vertices") {
+            
+            @Override
+            protected IStatus run(IProgressMonitor monitor) {
+                try {
+                    Simantics.getSession().syncRequest(new WriteRequest() {
+                        
+                        @Override
+                        public void perform(WriteGraph graph) throws DatabaseException {
+                            Simantics.applySCL("Apros/District/SimplifyMapping", "simplifySewageVertices", graph, mapping, input.getResource());
+                        }
+                        
+                    });
+                } catch (DatabaseException e) {
+                    return new Status(IStatus.ERROR, Activator.PLUGIN_ID, getName() + " failed.", e);
+                }
+                return Status.OK_STATUS;
+            }
+        };
+        job.setUser(true);
+        job.schedule();
+    }
+    
+    private static class SelectMappingDialog extends SelectionStatusDialog {
+
+        private Combo vertexMappingCombo;
+        
+        private Composite composite;
+        
+        private Resource diagram;
+        private Map<String, Resource> vertexMappings = new HashMap<>();
+        
+        private Resource sewageVertexMapping;
+
+        protected SelectMappingDialog(Shell parentShell, Resource diagram) {
+            super(parentShell);
+            this.diagram = diagram;
+            setTitle("Select the sewage vertex mapping");
+        }
+
+        public Resource getSewageVertexMapping() {
+            return sewageVertexMapping;
+        }
+
+        @Override
+        protected Control createDialogArea(Composite parent) {
+            composite = (Composite) super.createDialogArea(parent);
+            
+            createMappingsGroup(composite);
+            
+            Simantics.getSession().asyncRequest(new ReadRequest() {
+
+                @Override
+                public void run(ReadGraph graph) throws DatabaseException {
+                    vertexMappings = Functions.getVertexMappings(graph, diagram);
+                    composite.getDisplay().asyncExec(() -> {
+                        vertexMappingCombo.setItems(vertexMappings.keySet().toArray(new String[vertexMappings.size()]));
+                        vertexMappingCombo.select(0);
+                    }); 
+                    
+                }
+            });
+            return composite;
+        }
+
+        @Override
+        protected void computeResult() {
+            sewageVertexMapping = vertexMappings.get(vertexMappingCombo.getItem(vertexMappingCombo.getSelectionIndex()));
+        }
+        
+        private void createMappingsGroup(Composite parent) {
+            Group group= new Group(parent, SWT.NONE);
+            group.setFont(parent.getFont());
+            group.setText("Default mappings");
+            GridDataFactory.fillDefaults().grab(true, false).applyTo(group);
+            group.setLayout(new GridLayout(1, false));
+            
+            Composite cmposite = new Composite(group, SWT.NONE);
+            cmposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
+            cmposite.setLayout(new GridLayout(2, false));
+            
+            Label vertexMappingLabel = new Label(cmposite, SWT.NONE);
+            vertexMappingLabel.setText("Sewage vertex mapping");
+
+            vertexMappingCombo = new Combo(cmposite, SWT.READ_ONLY | SWT.BORDER);
+            GridDataFactory.fillDefaults().grab(true, false).applyTo(vertexMappingCombo);
+            
+        }
+    }
+}
\ No newline at end of file