]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Implement district features to Simantics platform
authorjsimomaa <jani.simomaa@gmail.com>
Fri, 13 Jan 2017 07:48:14 +0000 (09:48 +0200)
committerjsimomaa <jani.simomaa@gmail.com>
Fri, 13 Jan 2017 07:48:14 +0000 (09:48 +0200)
refs #6958

Change-Id: I4200a696e3ddca7fafa5d2a1e3dd34aee8bac914

28 files changed:
org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/CSVImportWizardPage.java
org.simantics.district.network.ontology/META-INF/MANIFEST.MF
org.simantics.district.network.ontology/build.properties
org.simantics.district.network.ontology/graph.tg
org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph
org.simantics.district.network.ontology/graph/epsg/EPSG_4326 [new file with mode: 0644]
org.simantics.district.network.ontology/scl/Simantics/District/ComponentMapping.scl [new file with mode: 0644]
org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java
org.simantics.district.network.ui/META-INF/MANIFEST.MF
org.simantics.district.network.ui/adapters.xml
org.simantics.district.network.ui/icons/diagramEditor.png [new file with mode: 0644]
org.simantics.district.network.ui/src/org/simantics/district/network/ui/DNEdgeBuilder.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/DNElementRemover.java [new file with mode: 0644]
org.simantics.district.network.ui/src/org/simantics/district/network/ui/DNGraphLayerUtil.java [new file with mode: 0644]
org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictNetworkEdge.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/NetworkDrawingParticipant.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkEdgeElement.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkVertexElement.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkVertexElementFactory.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/NetworkDrawingNode.java [new file with mode: 0644]
org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DNPointerInteractor.java [new file with mode: 0644]
org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DNTranslateMode.java [new file with mode: 0644]
org.simantics.district.network.ui/src/org/simantics/district/network/ui/templates/AddLayerToDNDiagramTemplate.java [new file with mode: 0644]
org.simantics.district.network/src/org/simantics/district/network/DistrictNetworkUtil.java
org.simantics.district.ui.feature/feature.xml

index 85eeb942d13af1dd470deaf9795fc35e710f85ec..71017b321b90d9486974021f75d01ca4a764b517 100644 (file)
@@ -44,6 +44,7 @@ public class CSVImportWizardPage extends WizardPage implements FileSelectionList
     private Combo delimiterCombo;\r
     private TableColumnLayout tableColumnLayout;\r
     private TableViewer tableViewer;\r
+    private Composite tableComposite;\r
 \r
     protected CSVImportWizardPage(CSVImportModel model) {\r
         super("Import CSV Data");\r
@@ -94,37 +95,15 @@ public class CSVImportWizardPage extends WizardPage implements FileSelectionList
         });\r
         \r
         \r
-        Composite tableComposite = new Composite(composite, SWT.BORDER);\r
-        TreeColumnLayout treeColumnLayout = new TreeColumnLayout();\r
-        tableComposite.setLayout(treeColumnLayout);\r
-        \r
-        tableViewer = new TableViewer(tableComposite, SWT.V_SCROLL | SWT.H_SCROLL);\r
-        ColumnViewerToolTipSupport.enableFor(tableViewer);\r
-        tableViewer.setContentProvider(new IContentProvider() {\r
-            \r
-            @Override\r
-            public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {\r
-                \r
-            }\r
-            \r
-            @Override\r
-            public void dispose() {\r
-                \r
-            }\r
-        });\r
-        \r
-        Table table = tableViewer.getTable();\r
-        table.setHeaderVisible(true);\r
-        table.setLinesVisible(true);\r
-        \r
-        headerTable = new Table(tableComposite, SWT.NONE);\r
-        headerTable.setHeaderVisible(true);\r
-        headerTable.setLinesVisible(true);\r
-        GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(tableComposite);\r
+        tableComposite = new Composite(composite, SWT.BORDER);\r
+        tableColumnLayout = new TableColumnLayout();\r
+        tableComposite.setLayout(tableColumnLayout);\r
+\r
+        updateHeaders();\r
         \r
         setControl(composite);\r
         \r
-        updateHeaders();\r
+        \r
         \r
         setPageComplete(false);\r
     }\r
@@ -147,7 +126,12 @@ public class CSVImportWizardPage extends WizardPage implements FileSelectionList
     }\r
 \r
     private void updateHeaders() {\r
-        headerTable.setRedraw(false);\r
+        if (headerTable != null)\r
+            headerTable.dispose();\r
+        headerTable = new Table(tableComposite, SWT.NONE);\r
+        headerTable.setHeaderVisible(true);\r
+        headerTable.setLinesVisible(true);\r
+        GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(tableComposite);\r
         for (int i = 0; i < headerTable.getColumns().length; i++) {\r
             TableColumn column = headerTable.getColumns()[i];\r
             column.dispose();\r
@@ -179,7 +163,6 @@ public class CSVImportWizardPage extends WizardPage implements FileSelectionList
         } catch (IOException e) {\r
             setErrorMessage(e.getMessage());\r
         }\r
-        headerTable.setRedraw(true);\r
     }\r
 \r
 }\r
index 0302088ebd08f4d985b4f9548109e2b43f24bf03..18b8713dd065a7c6bf5458a757f604637ac44b6a 100644 (file)
@@ -8,6 +8,7 @@ Require-Bundle: org.simantics.layer0,
  org.simantics.structural.ontology;bundle-version="1.2.0",
  org.simantics.modeling.ontology;bundle-version="1.2.0",
  org.simantics.viewpoint.ontology;bundle-version="1.2.0",
- org.simantics.image2.ontology;bundle-version="1.2.0"
+ org.simantics.image2.ontology;bundle-version="1.2.0",
+ org.simantics.selectionview.ontology;bundle-version="1.2.0"
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Export-Package: org.simantics.district.network.ontology
index 022de1735b3f377a077bbc56b320d9bf79fb835c..73ce7d4196502a804ab48e9e78065de9d53b9e1c 100644 (file)
@@ -3,4 +3,5 @@ output.. = bin/
 bin.includes = plugin.xml,\\r
                META-INF/,\\r
                .,\\r
-               graph.tg\r
+               graph.tg,\\r
+               scl/\r
index 70e6cc2734910c8eb4ff548f61b94e7a3e617898..73e40a0a1923b4316f1a849382e9159d1cfdd0bd 100644 (file)
Binary files a/org.simantics.district.network.ontology/graph.tg and b/org.simantics.district.network.ontology/graph.tg differ
index 612fb30323812abd03502ef3869ee94fcb439dca..2c6ac584641ce3c3c2a2374b9b15fe3033481abe 100644 (file)
@@ -4,32 +4,98 @@ STR = <http://www.simantics.org/Structural-1.2>
 MOD = <http://www.simantics.org/Modeling-1.2>
 VP = <http://www.simantics.org/Viewpoint-1.2>
 IMAGE = <http://www.simantics.org/Image2-1.2>
+SEL = <http://www.simantics.org/SelectionView-1.2>
 
 MBC = MOD.ModelingBrowseContext
 
 DN = <http://www.simantics.org/DistrictNetwork-1.0> : L0.Ontology
     @L0.new
+    L0.Ontology.global true
     L0.HasResourceClass "org.simantics.district.network.ontology.DistrictNetworkResource"
 
+DN.Layer <T DIA.Layer
+
 DN.Edge <T DIA.Element : L0.Type
+    @L0.assert DN.HasMapping ""
+    @L0.assert DN.Bidirectional false
+    @L0.assert DN.Edge.HasDiameter 1
 
 DN.Vertex <T DIA.Element : L0.Type
+    @L0.assert DN.HasMapping ""
+    @L0.assert DN.Bidirectional false
+
+DN.Bidirectional <R L0.HasProperty : SEL.GenericParameterType
+    L0.HasLabel "Is network bidirectional"
+    L0.HasRange L0.Boolean
+    L0.readOnly false
+
+DN.EdgeDefaultMapping <R L0.HasProperty : SEL.GenericParameterType
+    L0.HasLabel "Default Edge mapping"
+    L0.HasRange L0.String
+    L0.readOnly false
+
+DN.VertexDefaultMapping <R L0.HasProperty : SEL.GenericParameterType
+    L0.HasLabel "Default Vertex mapping"
+    L0.HasRange L0.String
+    L0.readOnly false
+
+DN.HasMapping <R L0.HasProperty : SEL.GenericParameterType
+    L0.HasLabel "Mapping"
+    L0.HasRange DN.Mapping.EdgeMapping
+    L0.readOnly false
+
+DN.Edge.HasDiameter <R L0.HasProperty : SEL.GenericParameterType
+    L0.HasLabel "Diameter"
+    L0.HasRange L0.Double
+    L0.readOnly false
+
+DN.InLayer
+    @L0.defTag 
+    @L0.tag L0.Abstract
+
+DN.HasInLayerTag <R L0.HasProperty
+    L0.HasRange L0.Tag
 
 DN.Connection <T DIA.Connection
 
 DN.Diagram <T DIA.Diagram
+    @L0.assert DN.VertexDefaultMapping ""
+    @L0.assert DN.EdgeDefaultMapping ""
+
+DN.AddLayerToDNDiagramTemplate <T L0.Template
+
+DN.EPSG_4326 <T DN.SpatialRefSystem
+    DN.HasSRID 4326
+    DN.HasSRTEXT _ : L0.String
+        @L0.loadString "epsg/EPSG_4326"
 
+DN.SpatialRefSystem <T L0.Entity
+
+DN.HasSpatialRefSystem <R L0.HasProperty
+    L0.HasRange DN.SpatialRefSystem
+
+DN.HasSRID <R L0.HasProperty
+    L0.HasRange L0.Integer
+
+DN.HasSRTEXT <R L0.HasProperty
+    L0.HasRange L0.String
 
 DN.Composite <T STR.Composite
     @L0.assert MOD.HasModelingTemplate
         _ : MOD.DiagramTemplate
             MOD.HasDiagramType DN.Diagram
+    @L0.assert MOD.HasModelingTemplate
+        _ : DN.AddLayerToDNDiagramTemplate
 
-DN.HasStartVertex <R L0.HasProperty
+DN.HasStartVertex <R L0.DependsOn
+    L0.HasDomain DN.Edge
     L0.HasRange DN.Vertex
+    L0.InverseOf DN.HasStartVertex_Inverse <R L0.IsRelatedTo
 
-DN.HasEndVertex <R L0.HasProperty
+DN.HasEndVertex <R L0.DependsOn
+    L0.HasDomain DN.Edge
     L0.HasRange DN.Vertex
+    L0.InverseOf DN.HasEndVertex_Inverse <R L0.IsRelatedTo
 
 DNAC.newDiagramContribution : L0.Template
     @template %actionContext %label %image %action
@@ -55,3 +121,25 @@ IMAGES = DN.Images : L0.Library
 
 IMAGES.ConfigurationFolder : IMAGE.PngImage
     @L0.loadBytes "images/Configuration.png"
+
+    
+// Component MAPPING
+DN.Mapping <T L0.Library
+
+DN.Mapping.Terminal <T L0.Entity
+
+DN.Mapping.TerminalPair <T L0.Entity
+    >-- DN.Mapping.InputTerminal --> DN.Mapping.Terminal <R L0.HasProperty
+    >-- DN.Mapping.OutputTerminal --> DN.Mapping.Terminal <R L0.HasProperty
+
+DN.Mapping.VertexMapping <T L0.Entity
+    >-- DN.Mapping.ComponentType --> STR.ComponentType <R L0.HasProperty
+    >-- DN.Mapping.VertexMapping.ElevationAttribute --> L0.String <R L0.HasProperty
+    >-- DN.Mapping.Terminals --> DN.Mapping.TerminalPair <R L0.HasProperty
+
+DN.Mapping.EdgeMapping <T L0.Entity
+    >-- DN.Mapping.ComponentType
+    >-- DN.Mapping.EdgeMapping.Bidirectional --> L0.Boolean <R L0.HasProperty
+    >-- DN.Mapping.EdgeMapping.LengthAttribute --> L0.String <R L0.HasProperty
+    >-- DN.Mapping.EdgeMapping.DiameterAttribute --> L0.String <R L0.HasProperty
+    >-- DN.Mapping.Terminals
diff --git a/org.simantics.district.network.ontology/graph/epsg/EPSG_4326 b/org.simantics.district.network.ontology/graph/epsg/EPSG_4326
new file mode 100644 (file)
index 0000000..30d74d2
--- /dev/null
@@ -0,0 +1 @@
+test
\ No newline at end of file
diff --git a/org.simantics.district.network.ontology/scl/Simantics/District/ComponentMapping.scl b/org.simantics.district.network.ontology/scl/Simantics/District/ComponentMapping.scl
new file mode 100644 (file)
index 0000000..9219ba4
--- /dev/null
@@ -0,0 +1,18 @@
+data VertexMapping = VertexMapping {\r
+    componentType :: String,\r
+    elevationAttribute :: String,\r
+    terminals :: [TerminalPair]\r
+}\r
+\r
+data TerminalPair = TerminalPair {\r
+    inputTerminal :: String,\r
+    outputTerminal :: String\r
+}\r
+\r
+data EdgeMapping = EdgeMapping {\r
+    componentType :: String,\r
+    bidirectional :: Boolean,\r
+    lengthAttribute :: String,\r
+    diameterAttribute :: String,\r
+    terminals :: [TerminalPair]\r
+}
\ No newline at end of file
index 513891dfe47b99761638344c0e5f46019ab4df41..6ab511e1273b22b33522537c6ad5585f32f9e92a 100644 (file)
@@ -14,34 +14,122 @@ public class DistrictNetworkResource {
     public final Resource ActionContext_newDiagramContribution;\r
     public final Resource Actions;\r
     public final Resource Actions_NewDNDiagram;\r
+    public final Resource AddLayerToDNDiagramTemplate;\r
+    public final Resource Bidirectional;\r
+    public final Resource Bidirectional_Inverse;\r
     public final Resource Composite;\r
     public final Resource Connection;\r
     public final Resource Diagram;\r
+    public final Resource EPSG_4326;\r
     public final Resource Edge;\r
+    public final Resource EdgeDefaultMapping;\r
+    public final Resource EdgeDefaultMapping_Inverse;\r
+    public final Resource Edge_HasDiameter;\r
+    public final Resource Edge_HasDiameter_Inverse;\r
     public final Resource HasEndVertex;\r
     public final Resource HasEndVertex_Inverse;\r
+    public final Resource HasInLayerTag;\r
+    public final Resource HasInLayerTag_Inverse;\r
+    public final Resource HasMapping;\r
+    public final Resource HasMapping_Inverse;\r
+    public final Resource HasSRID;\r
+    public final Resource HasSRID_Inverse;\r
+    public final Resource HasSRTEXT;\r
+    public final Resource HasSRTEXT_Inverse;\r
+    public final Resource HasSpatialRefSystem;\r
+    public final Resource HasSpatialRefSystem_Inverse;\r
     public final Resource HasStartVertex;\r
     public final Resource HasStartVertex_Inverse;\r
     public final Resource Images;\r
     public final Resource Images_ConfigurationFolder;\r
+    public final Resource InLayer;\r
+    public final Resource Layer;\r
+    public final Resource Mapping;\r
+    public final Resource Mapping_ComponentType;\r
+    public final Resource Mapping_ComponentType_Inverse;\r
+    public final Resource Mapping_EdgeMapping;\r
+    public final Resource Mapping_EdgeMapping_Bidirectional;\r
+    public final Resource Mapping_EdgeMapping_Bidirectional_Inverse;\r
+    public final Resource Mapping_EdgeMapping_DiameterAttribute;\r
+    public final Resource Mapping_EdgeMapping_DiameterAttribute_Inverse;\r
+    public final Resource Mapping_EdgeMapping_LengthAttribute;\r
+    public final Resource Mapping_EdgeMapping_LengthAttribute_Inverse;\r
+    public final Resource Mapping_InputTerminal;\r
+    public final Resource Mapping_InputTerminal_Inverse;\r
+    public final Resource Mapping_OutputTerminal;\r
+    public final Resource Mapping_OutputTerminal_Inverse;\r
+    public final Resource Mapping_Terminal;\r
+    public final Resource Mapping_TerminalPair;\r
+    public final Resource Mapping_Terminals;\r
+    public final Resource Mapping_Terminals_Inverse;\r
+    public final Resource Mapping_VertexMapping;\r
+    public final Resource Mapping_VertexMapping_ElevationAttribute;\r
+    public final Resource Mapping_VertexMapping_ElevationAttribute_Inverse;\r
+    public final Resource SpatialRefSystem;\r
     public final Resource Vertex;\r
+    public final Resource VertexDefaultMapping;\r
+    public final Resource VertexDefaultMapping_Inverse;\r
         \r
     public static class URIs {\r
         public static final String ActionContext = "http://www.simantics.org/DistrictNetwork-1.0/ActionContext";\r
         public static final String ActionContext_newDiagramContribution = "http://www.simantics.org/DistrictNetwork-1.0/ActionContext/newDiagramContribution";\r
         public static final String Actions = "http://www.simantics.org/DistrictNetwork-1.0/Actions";\r
         public static final String Actions_NewDNDiagram = "http://www.simantics.org/DistrictNetwork-1.0/Actions/NewDNDiagram";\r
+        public static final String AddLayerToDNDiagramTemplate = "http://www.simantics.org/DistrictNetwork-1.0/AddLayerToDNDiagramTemplate";\r
+        public static final String Bidirectional = "http://www.simantics.org/DistrictNetwork-1.0/Bidirectional";\r
+        public static final String Bidirectional_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Bidirectional/Inverse";\r
         public static final String Composite = "http://www.simantics.org/DistrictNetwork-1.0/Composite";\r
         public static final String Connection = "http://www.simantics.org/DistrictNetwork-1.0/Connection";\r
         public static final String Diagram = "http://www.simantics.org/DistrictNetwork-1.0/Diagram";\r
+        public static final String EPSG_4326 = "http://www.simantics.org/DistrictNetwork-1.0/EPSG_4326";\r
         public static final String Edge = "http://www.simantics.org/DistrictNetwork-1.0/Edge";\r
+        public static final String EdgeDefaultMapping = "http://www.simantics.org/DistrictNetwork-1.0/EdgeDefaultMapping";\r
+        public static final String EdgeDefaultMapping_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/EdgeDefaultMapping/Inverse";\r
+        public static final String Edge_HasDiameter = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasDiameter";\r
+        public static final String Edge_HasDiameter_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasDiameter/Inverse";\r
         public static final String HasEndVertex = "http://www.simantics.org/DistrictNetwork-1.0/HasEndVertex";\r
-        public static final String HasEndVertex_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasEndVertex/Inverse";\r
+        public static final String HasEndVertex_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasEndVertex_Inverse";\r
+        public static final String HasInLayerTag = "http://www.simantics.org/DistrictNetwork-1.0/HasInLayerTag";\r
+        public static final String HasInLayerTag_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasInLayerTag/Inverse";\r
+        public static final String HasMapping = "http://www.simantics.org/DistrictNetwork-1.0/HasMapping";\r
+        public static final String HasMapping_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasMapping/Inverse";\r
+        public static final String HasSRID = "http://www.simantics.org/DistrictNetwork-1.0/HasSRID";\r
+        public static final String HasSRID_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasSRID/Inverse";\r
+        public static final String HasSRTEXT = "http://www.simantics.org/DistrictNetwork-1.0/HasSRTEXT";\r
+        public static final String HasSRTEXT_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasSRTEXT/Inverse";\r
+        public static final String HasSpatialRefSystem = "http://www.simantics.org/DistrictNetwork-1.0/HasSpatialRefSystem";\r
+        public static final String HasSpatialRefSystem_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasSpatialRefSystem/Inverse";\r
         public static final String HasStartVertex = "http://www.simantics.org/DistrictNetwork-1.0/HasStartVertex";\r
-        public static final String HasStartVertex_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasStartVertex/Inverse";\r
+        public static final String HasStartVertex_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasStartVertex_Inverse";\r
         public static final String Images = "http://www.simantics.org/DistrictNetwork-1.0/Images";\r
         public static final String Images_ConfigurationFolder = "http://www.simantics.org/DistrictNetwork-1.0/Images/ConfigurationFolder";\r
+        public static final String InLayer = "http://www.simantics.org/DistrictNetwork-1.0/InLayer";\r
+        public static final String Layer = "http://www.simantics.org/DistrictNetwork-1.0/Layer";\r
+        public static final String Mapping = "http://www.simantics.org/DistrictNetwork-1.0/Mapping";\r
+        public static final String Mapping_ComponentType = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/ComponentType";\r
+        public static final String Mapping_ComponentType_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/ComponentType/Inverse";\r
+        public static final String Mapping_EdgeMapping = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping";\r
+        public static final String Mapping_EdgeMapping_Bidirectional = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/Bidirectional";\r
+        public static final String Mapping_EdgeMapping_Bidirectional_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/Bidirectional/Inverse";\r
+        public static final String Mapping_EdgeMapping_DiameterAttribute = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/DiameterAttribute";\r
+        public static final String Mapping_EdgeMapping_DiameterAttribute_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/DiameterAttribute/Inverse";\r
+        public static final String Mapping_EdgeMapping_LengthAttribute = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/LengthAttribute";\r
+        public static final String Mapping_EdgeMapping_LengthAttribute_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/LengthAttribute/Inverse";\r
+        public static final String Mapping_InputTerminal = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/InputTerminal";\r
+        public static final String Mapping_InputTerminal_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/InputTerminal/Inverse";\r
+        public static final String Mapping_OutputTerminal = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/OutputTerminal";\r
+        public static final String Mapping_OutputTerminal_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/OutputTerminal/Inverse";\r
+        public static final String Mapping_Terminal = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/Terminal";\r
+        public static final String Mapping_TerminalPair = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/TerminalPair";\r
+        public static final String Mapping_Terminals = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/Terminals";\r
+        public static final String Mapping_Terminals_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/Terminals/Inverse";\r
+        public static final String Mapping_VertexMapping = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/VertexMapping";\r
+        public static final String Mapping_VertexMapping_ElevationAttribute = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/VertexMapping/ElevationAttribute";\r
+        public static final String Mapping_VertexMapping_ElevationAttribute_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/VertexMapping/ElevationAttribute/Inverse";\r
+        public static final String SpatialRefSystem = "http://www.simantics.org/DistrictNetwork-1.0/SpatialRefSystem";\r
         public static final String Vertex = "http://www.simantics.org/DistrictNetwork-1.0/Vertex";\r
+        public static final String VertexDefaultMapping = "http://www.simantics.org/DistrictNetwork-1.0/VertexDefaultMapping";\r
+        public static final String VertexDefaultMapping_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/VertexDefaultMapping/Inverse";\r
     }\r
     \r
     public static Resource getResourceOrNull(ReadGraph graph, String uri) {\r
@@ -58,17 +146,61 @@ public class DistrictNetworkResource {
         ActionContext_newDiagramContribution = getResourceOrNull(graph, URIs.ActionContext_newDiagramContribution);\r
         Actions = getResourceOrNull(graph, URIs.Actions);\r
         Actions_NewDNDiagram = getResourceOrNull(graph, URIs.Actions_NewDNDiagram);\r
+        AddLayerToDNDiagramTemplate = getResourceOrNull(graph, URIs.AddLayerToDNDiagramTemplate);\r
+        Bidirectional = getResourceOrNull(graph, URIs.Bidirectional);\r
+        Bidirectional_Inverse = getResourceOrNull(graph, URIs.Bidirectional_Inverse);\r
         Composite = getResourceOrNull(graph, URIs.Composite);\r
         Connection = getResourceOrNull(graph, URIs.Connection);\r
         Diagram = getResourceOrNull(graph, URIs.Diagram);\r
+        EPSG_4326 = getResourceOrNull(graph, URIs.EPSG_4326);\r
         Edge = getResourceOrNull(graph, URIs.Edge);\r
+        EdgeDefaultMapping = getResourceOrNull(graph, URIs.EdgeDefaultMapping);\r
+        EdgeDefaultMapping_Inverse = getResourceOrNull(graph, URIs.EdgeDefaultMapping_Inverse);\r
+        Edge_HasDiameter = getResourceOrNull(graph, URIs.Edge_HasDiameter);\r
+        Edge_HasDiameter_Inverse = getResourceOrNull(graph, URIs.Edge_HasDiameter_Inverse);\r
         HasEndVertex = getResourceOrNull(graph, URIs.HasEndVertex);\r
         HasEndVertex_Inverse = getResourceOrNull(graph, URIs.HasEndVertex_Inverse);\r
+        HasInLayerTag = getResourceOrNull(graph, URIs.HasInLayerTag);\r
+        HasInLayerTag_Inverse = getResourceOrNull(graph, URIs.HasInLayerTag_Inverse);\r
+        HasMapping = getResourceOrNull(graph, URIs.HasMapping);\r
+        HasMapping_Inverse = getResourceOrNull(graph, URIs.HasMapping_Inverse);\r
+        HasSRID = getResourceOrNull(graph, URIs.HasSRID);\r
+        HasSRID_Inverse = getResourceOrNull(graph, URIs.HasSRID_Inverse);\r
+        HasSRTEXT = getResourceOrNull(graph, URIs.HasSRTEXT);\r
+        HasSRTEXT_Inverse = getResourceOrNull(graph, URIs.HasSRTEXT_Inverse);\r
+        HasSpatialRefSystem = getResourceOrNull(graph, URIs.HasSpatialRefSystem);\r
+        HasSpatialRefSystem_Inverse = getResourceOrNull(graph, URIs.HasSpatialRefSystem_Inverse);\r
         HasStartVertex = getResourceOrNull(graph, URIs.HasStartVertex);\r
         HasStartVertex_Inverse = getResourceOrNull(graph, URIs.HasStartVertex_Inverse);\r
         Images = getResourceOrNull(graph, URIs.Images);\r
         Images_ConfigurationFolder = getResourceOrNull(graph, URIs.Images_ConfigurationFolder);\r
+        InLayer = getResourceOrNull(graph, URIs.InLayer);\r
+        Layer = getResourceOrNull(graph, URIs.Layer);\r
+        Mapping = getResourceOrNull(graph, URIs.Mapping);\r
+        Mapping_ComponentType = getResourceOrNull(graph, URIs.Mapping_ComponentType);\r
+        Mapping_ComponentType_Inverse = getResourceOrNull(graph, URIs.Mapping_ComponentType_Inverse);\r
+        Mapping_EdgeMapping = getResourceOrNull(graph, URIs.Mapping_EdgeMapping);\r
+        Mapping_EdgeMapping_Bidirectional = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_Bidirectional);\r
+        Mapping_EdgeMapping_Bidirectional_Inverse = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_Bidirectional_Inverse);\r
+        Mapping_EdgeMapping_DiameterAttribute = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_DiameterAttribute);\r
+        Mapping_EdgeMapping_DiameterAttribute_Inverse = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_DiameterAttribute_Inverse);\r
+        Mapping_EdgeMapping_LengthAttribute = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_LengthAttribute);\r
+        Mapping_EdgeMapping_LengthAttribute_Inverse = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_LengthAttribute_Inverse);\r
+        Mapping_InputTerminal = getResourceOrNull(graph, URIs.Mapping_InputTerminal);\r
+        Mapping_InputTerminal_Inverse = getResourceOrNull(graph, URIs.Mapping_InputTerminal_Inverse);\r
+        Mapping_OutputTerminal = getResourceOrNull(graph, URIs.Mapping_OutputTerminal);\r
+        Mapping_OutputTerminal_Inverse = getResourceOrNull(graph, URIs.Mapping_OutputTerminal_Inverse);\r
+        Mapping_Terminal = getResourceOrNull(graph, URIs.Mapping_Terminal);\r
+        Mapping_TerminalPair = getResourceOrNull(graph, URIs.Mapping_TerminalPair);\r
+        Mapping_Terminals = getResourceOrNull(graph, URIs.Mapping_Terminals);\r
+        Mapping_Terminals_Inverse = getResourceOrNull(graph, URIs.Mapping_Terminals_Inverse);\r
+        Mapping_VertexMapping = getResourceOrNull(graph, URIs.Mapping_VertexMapping);\r
+        Mapping_VertexMapping_ElevationAttribute = getResourceOrNull(graph, URIs.Mapping_VertexMapping_ElevationAttribute);\r
+        Mapping_VertexMapping_ElevationAttribute_Inverse = getResourceOrNull(graph, URIs.Mapping_VertexMapping_ElevationAttribute_Inverse);\r
+        SpatialRefSystem = getResourceOrNull(graph, URIs.SpatialRefSystem);\r
         Vertex = getResourceOrNull(graph, URIs.Vertex);\r
+        VertexDefaultMapping = getResourceOrNull(graph, URIs.VertexDefaultMapping);\r
+        VertexDefaultMapping_Inverse = getResourceOrNull(graph, URIs.VertexDefaultMapping_Inverse);\r
     }\r
     \r
     public static DistrictNetworkResource getInstance(ReadGraph graph) {\r
index 0e348e6bbbdc095a4a2c3a7e175906aa2049082d..267a0dd0a29d06b828200a8423bbfe3042e618b5 100644 (file)
@@ -13,7 +13,8 @@ Require-Bundle: org.eclipse.e4.ui.model.workbench;bundle-version="1.1.100.v20150
  org.simantics.modeling.ui,
  org.simantics.district.network.ontology,
  org.simantics.utils.datastructures,
- org.simantics.district.network;bundle-version="1.0.0"
+ org.simantics.district.network;bundle-version="1.0.0",
+ org.simantics.layer0.utils
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Export-Package: org.simantics.district.network.ui.adapters
 Bundle-ActivationPolicy: lazy
index 57243ce182ce874ed015055ee5edda70006a27c6..8fdfa320536d5f813632e6beaba8f75a653f22b3 100644 (file)
             <graph />\r
         </type>\r
     </target>\r
+    \r
+    <target interface="org.simantics.db.layer0.adapter.Remover">\r
+        <type uri="http://www.simantics.org/DistrictNetwork-1.0/Vertex"\r
+            class="org.simantics.district.network.ui.DNElementRemover">\r
+            <this />\r
+        </type>\r
+        <type uri="http://www.simantics.org/DistrictNetwork-1.0/Edge"\r
+            class="org.simantics.district.network.ui.DNElementRemover">\r
+            <this />\r
+        </type>\r
+    </target>\r
+    \r
+    <target interface="org.simantics.db.layer0.adapter.Template">\r
+        <type uri="http://www.simantics.org/DistrictNetwork-1.0/AddLayerToDNDiagramTemplate"\r
+            class="org.simantics.district.network.ui.templates.AddLayerToDNDiagramTemplate">\r
+            <this />\r
+        </type>\r
+    </target>\r
+    \r
+    <target interface="org.simantics.diagram.synchronization.graph.layer.IGraphLayerUtil">\r
+        <resource uri="http://www.simantics.org/DistrictNetwork-1.0/Layer"\r
+            class="org.simantics.district.network.ui.DNGraphLayerUtil">\r
+            <this />\r
+        </resource>\r
+    </target>\r
+    \r
 </adapters>
\ No newline at end of file
diff --git a/org.simantics.district.network.ui/icons/diagramEditor.png b/org.simantics.district.network.ui/icons/diagramEditor.png
new file mode 100644 (file)
index 0000000..aab17bb
Binary files /dev/null and b/org.simantics.district.network.ui/icons/diagramEditor.png differ
index 475269f8aa8e12c607d486135042ff546d4547a5..b9b73e542308882d51f0b2c0c925bcedd128f5c6 100644 (file)
@@ -3,17 +3,31 @@ package org.simantics.district.network.ui;
 import org.simantics.db.Resource;\r
 import org.simantics.db.WriteGraph;\r
 import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.exception.ServiceException;\r
 import org.simantics.db.layer0.util.Layer0Utils;\r
+import org.simantics.diagram.synchronization.IModifiableSynchronizationContext;\r
+import org.simantics.diagram.synchronization.SynchronizationHints;\r
 import org.simantics.diagram.synchronization.graph.AddElement;\r
+import org.simantics.diagram.synchronization.graph.GraphSynchronizationHints;\r
+import org.simantics.diagram.synchronization.graph.layer.GraphLayer;\r
+import org.simantics.diagram.synchronization.graph.layer.GraphLayerManager;\r
+import org.simantics.diagram.ui.DiagramModelHints;\r
 import org.simantics.district.network.DistrictNetworkUtil;\r
 import org.simantics.district.network.ontology.DistrictNetworkResource;\r
+import org.simantics.g2d.diagram.IDiagram;\r
 \r
 public class DNEdgeBuilder {\r
     \r
     private Resource diagramResource;\r
+    private IDiagram diagram;\r
+    private GraphLayerManager glm;\r
 \r
-    public DNEdgeBuilder(Resource diagramResource) {\r
+    public DNEdgeBuilder(Resource diagramResource, IDiagram diagram) {\r
         this.diagramResource = diagramResource;\r
+        this.diagram = diagram;\r
+        \r
+        IModifiableSynchronizationContext context = diagram.getHint(SynchronizationHints.CONTEXT);\r
+        glm = context.get(GraphSynchronizationHints.GRAPH_LAYER_MANAGER);\r
     }\r
 \r
     public void create(WriteGraph graph, double[] start, double[] end) throws DatabaseException {\r
@@ -33,9 +47,21 @@ public class DNEdgeBuilder {
         graph.claim(edge, DN.HasStartVertex, startVertex);\r
         graph.claim(edge, DN.HasEndVertex, endVertex);\r
         \r
+        // 7. Put the element on all the currently active layers if possible.\r
+        if (glm != null) {\r
+            putOnActiveLayer(graph, edge);\r
+            putOnActiveLayer(graph, startVertex);\r
+            putOnActiveLayer(graph, endVertex);\r
+        }\r
+        \r
         Layer0Utils.addCommentMetadata(graph, "Added edge " + edge);\r
         graph.markUndoPoint();\r
     }\r
+    \r
+    private void putOnActiveLayer(WriteGraph graph, Resource res) throws DatabaseException {\r
+        glm.removeFromAllLayers(graph, res);\r
+        glm.putElementOnVisibleLayers(diagram, graph, res);\r
+    }\r
 \r
     private Resource getOrCreateVertex(WriteGraph graph, double[] coords) throws DatabaseException {\r
         // TODO: check if vertex exists already, for now create always new\r
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DNElementRemover.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DNElementRemover.java
new file mode 100644 (file)
index 0000000..2cbfe98
--- /dev/null
@@ -0,0 +1,61 @@
+package org.simantics.district.network.ui;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.utils.OrderedSetUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.adapter.impl.EntityRemover;\r
+import org.simantics.district.network.ontology.DistrictNetworkResource;\r
+import org.simantics.layer0.utils.binaryPredicates.OrderedSetElementsPredicate;\r
+import org.simantics.modeling.adapters.ElementRemover;\r
+\r
+public class DNElementRemover extends ElementRemover {\r
+\r
+    public DNElementRemover(Resource element) {\r
+        super(element);\r
+    }\r
+    \r
+    @Override\r
+    public void removeConnection(WriteGraph graph) throws DatabaseException {\r
+        throw new UnsupportedOperationException("Distrct network should not have STR.Connection resources! " + resource);\r
+    }\r
+    \r
+    @Override\r
+    public void removeElement(WriteGraph graph) throws DatabaseException {\r
+        \r
+        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);\r
+        \r
+        if (graph.isInstanceOf(resource, DN.Vertex)) {\r
+            graph.getObjects(resource, DN.HasEndVertex_Inverse).forEach(res -> {\r
+                try {\r
+                    doRemove(graph, res);\r
+                } catch (DatabaseException e) {\r
+                    e.printStackTrace();\r
+                }\r
+            });\r
+            graph.getObjects(resource, DN.HasStartVertex_Inverse).forEach(res -> {\r
+                try {\r
+                    doRemove(graph, res);\r
+                } catch (DatabaseException e) {\r
+                    e.printStackTrace();\r
+                }\r
+            });\r
+        }\r
+        doRemove(graph, resource);\r
+    }\r
+    \r
+    private static void doRemove(WriteGraph graph, Resource resource) throws DatabaseException {\r
+        // 1. Disconnect element from diagrams\r
+        for (Resource diagram : OrderedSetElementsPredicate.INSTANCE.getSubjects(graph, resource)) {\r
+            OrderedSetUtils.remove(graph, diagram, resource);\r
+        }\r
+\r
+        // 2. Delete element itself\r
+        EntityRemover.remove(graph, resource);\r
+\r
+        // 3. Recursively remove all related degenerate connections\r
+        // i.e. connections that only have one connector after remove the\r
+        // one connected to this removed element.\r
+    }\r
+\r
+}\r
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DNGraphLayerUtil.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DNGraphLayerUtil.java
new file mode 100644 (file)
index 0000000..27905a5
--- /dev/null
@@ -0,0 +1,66 @@
+package org.simantics.district.network.ui;\r
+\r
+import java.util.Collections;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.diagram.stubs.DiagramResource;\r
+import org.simantics.diagram.synchronization.graph.layer.GraphLayer;\r
+import org.simantics.diagram.synchronization.graph.layer.GraphLayerUtil;\r
+import org.simantics.diagram.synchronization.graph.layer.IGraphLayerUtil;\r
+import org.simantics.district.network.ontology.DistrictNetworkResource;\r
+import org.simantics.layer0.Layer0;\r
+\r
+public class DNGraphLayerUtil implements IGraphLayerUtil {\r
+\r
+    public DNGraphLayerUtil(Resource layer) {\r
+        \r
+    }\r
+\r
+    @Override\r
+    public GraphLayer loadLayer(ReadGraph graph, Resource layer) throws DatabaseException {\r
+        Layer0 L0 = Layer0.getInstance(graph);\r
+        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);\r
+        String name = graph.getRelatedValue(layer, L0.HasName);\r
+        Resource inLayer = graph.getSingleObject(layer, DN.HasInLayerTag);\r
+        \r
+        Map<String, Resource> properties = new HashMap<>();\r
+        properties.put("IN_LAYER", inLayer);\r
+\r
+        return new GraphLayer(name, layer, properties);\r
+    }\r
+\r
+    @Override\r
+    public GraphLayer createLayer(WriteGraph graph, String layerName, boolean active) throws DatabaseException {\r
+        Layer0 L0 = Layer0.getInstance(graph);\r
+        DiagramResource DIA = DiagramResource.getInstance(graph);\r
+        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);\r
+        \r
+        \r
+        Resource layer = graph.newResource();\r
+        graph.claim(layer, L0.InstanceOf, null, DN.Layer);\r
+\r
+        // Assign tagging relations\r
+        Resource inLayerTag = GraphLayerUtil.newTag(graph, L0, DN.InLayer);\r
+        graph.claim(layer, DN.HasInLayerTag, inLayerTag);\r
+\r
+        // Assign shared name property for all, the layer and the tags\r
+        Resource name = graph.newResource();\r
+        graph.claim(name, L0.InstanceOf, null, L0.String);\r
+        graph.claimValue(name, layerName);\r
+\r
+        graph.claim(layer, L0.HasName, name);\r
+        graph.claim(inLayerTag, L0.HasName, name);\r
+        \r
+        graph.claim(layer, DN.HasSpatialRefSystem, DN.EPSG_4326);\r
+\r
+        GraphLayerUtil.setLayerActive(graph, DIA, layer, active);\r
+\r
+        return new GraphLayer(layerName, layer, Collections.emptyMap());\r
+    }\r
+\r
+}\r
index e536f3ccdb6381728f05d8c791c85a60e3ed2048..9acad52c4b6f11345c9f93767af4853996e7ac82 100644 (file)
@@ -2,6 +2,7 @@ package org.simantics.district.network.ui;
 \r
 import java.util.concurrent.TimeUnit;\r
 \r
+import org.simantics.district.network.ui.participants.DNPointerInteractor;\r
 import org.simantics.g2d.canvas.ICanvasContext;\r
 import org.simantics.g2d.diagram.handler.PickRequest.PickFilter;\r
 import org.simantics.g2d.diagram.participant.DelayedBatchElementPainter;\r
@@ -18,6 +19,7 @@ public class DistrictDiagramViewer extends DiagramViewer {
         ctx.add(new ZOrderHandler());\r
         ctx.add(new Selection());\r
         ctx.add(new ElementPainter());\r
+        ctx.add(new DNPointerInteractor());\r
         \r
         ctx.add(new NetworkDrawingParticipant());\r
     }\r
index 1a99ae3c7d10a74555518358cd3d42fa2b1f5373..e30b4cb0892286810c3452e9e426137df2e5d887 100644 (file)
@@ -16,6 +16,7 @@ public class DistrictNetworkEdge {
     }\r
 \r
     public Rectangle2D getBounds(Rectangle2D rect) {\r
-        return path.getBounds2D();\r
+        rect.setFrame(path.getBounds2D());\r
+        return rect;\r
     }\r
 }\r
index a8cd239b3d520edea52266c045979aa98d624a3d..6ae6097c183b5a3e8b4cef542a12794fd3cfc11f 100644 (file)
@@ -1,45 +1,11 @@
 \r
 package org.simantics.district.network.ui;\r
 \r
-import java.awt.Color;\r
-import java.awt.Graphics2D;\r
-import java.awt.Shape;\r
-import java.awt.geom.Path2D;\r
-import java.awt.geom.Point2D;\r
-import java.awt.geom.Rectangle2D;\r
-import java.util.ArrayList;\r
-import java.util.Collections;\r
-import java.util.HashSet;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import java.util.Set;\r
-\r
-import org.simantics.Simantics;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.request.WriteRequest;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.diagram.ui.DiagramModelHints;\r
-import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency;\r
+import org.simantics.district.network.ui.nodes.NetworkDrawingNode;\r
 import org.simantics.g2d.canvas.impl.SGNodeReflection.SGInit;\r
 import org.simantics.g2d.diagram.IDiagram;\r
-import org.simantics.g2d.diagram.handler.PickContext;\r
-import org.simantics.g2d.diagram.handler.PickRequest;\r
-import org.simantics.g2d.diagram.handler.PickRequest.PickPolicy;\r
 import org.simantics.g2d.diagram.participant.AbstractDiagramParticipant;\r
-import org.simantics.g2d.diagram.participant.Selection;\r
-import org.simantics.g2d.element.IElement;\r
-import org.simantics.g2d.participant.TransformUtil;\r
-import org.simantics.g2d.utils.GeometryUtils;\r
-import org.simantics.scenegraph.g2d.G2DNode;\r
 import org.simantics.scenegraph.g2d.G2DParentNode;\r
-import org.simantics.scenegraph.g2d.events.EventTypes;\r
-import org.simantics.scenegraph.g2d.events.MouseEvent;\r
-import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler;\r
-import org.simantics.scenegraph.g2d.events.MouseEvent.MouseClickEvent;\r
-import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDoubleClickedEvent;\r
-import org.simantics.scenegraph.g2d.events.MouseEvent.MouseMovedEvent;\r
-import org.simantics.scenegraph.utils.NodeUtil;\r
 import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
 import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;\r
 \r
@@ -59,195 +25,15 @@ public class NetworkDrawingParticipant extends AbstractDiagramParticipant {
     \r
     private NetworkDrawingNode node;\r
     \r
-    @Dependency Selection selection;\r
-    @Dependency TransformUtil util;\r
-    @Dependency PickContext pickContext;\r
-    \r
     @SGInit\r
     public void initSG(G2DParentNode parent) {\r
         node = parent.addNode("networkDrawingNode", NetworkDrawingNode.class);\r
+        node.setNetworkDrawingParticipant(this);\r
     }\r
     \r
     @Override\r
     protected void onDiagramSet(IDiagram newDiagram, IDiagram oldDiagram) {\r
         node.setDiagram(newDiagram);\r
     }\r
-    \r
-    @EventHandler(priority = 1 << 21)\r
-    public boolean handleClick(MouseClickEvent me) {\r
-        \r
-        boolean isLeft = me.button == MouseEvent.LEFT_BUTTON;\r
-        boolean isRight = me.button == MouseEvent.RIGHT_BUTTON;\r
-        if (!isLeft && !isRight)\r
-            return false;\r
-        boolean isShiftPressed = me.hasAllModifiers(MouseEvent.SHIFT_MASK);\r
-        \r
-        int selectionId = me.mouseId;\r
-        \r
-        double pickDist = getPickDistance();\r
-        Rectangle2D controlPickRect = new Rectangle2D.Double(me.controlPosition.getX()-pickDist, me.controlPosition.getY()-pickDist, pickDist*2+1, pickDist*2+1);\r
-        Shape canvasPickRect  = GeometryUtils.transformShape(controlPickRect, util.getInverseTransform());\r
-        \r
-        PickRequest req = new PickRequest(canvasPickRect);\r
-        req.pickPolicy = PickPolicy.PICK_INTERSECTING_OBJECTS;\r
-        //req.pickSorter = PickRequest.PickSorter.CONNECTIONS_LAST;\r
-        List<IElement> pickables = new ArrayList<IElement>();\r
-        pickContext.pick(diagram, req, pickables);\r
-        \r
-        Set<IElement> currentSelection = selection.getSelection(selectionId);\r
-        \r
-        if (!pickables.isEmpty()) {\r
-            /*\r
-             * Select the one object the mouse points to. If multiple object\r
-             * are picked, select the one that is after the earliest by\r
-             * index of the current selection when shift is pressed. Otherwise\r
-             * always pick the topmost element.\r
-             */\r
-            IElement selectedPick = isShiftPressed\r
-                    ? rotatingPick(currentSelection, pickables)\r
-                            : pickables.get(pickables.size() - 1);\r
-    \r
-            // Only select when\r
-            // 1. the selection would actually change\r
-            // AND\r
-            //   2.1. left button was pressed\r
-            //   OR\r
-            //   2.2. right button was pressed and the element to-be-selected\r
-            //        is NOT a part of the current selection\r
-            if (!Collections.singleton(selectedPick).equals(currentSelection)\r
-                    && (isLeft || (isRight && !currentSelection.contains(selectedPick)))) {\r
-                selection.setSelection(selectionId, selectedPick);\r
-            }\r
-        }\r
-        \r
-        return false;\r
-    }\r
-    \r
-    private double getPickDistance() {\r
-        Double pickDistance = getHint(KEY_PICK_DISTANCE);\r
-        return pickDistance == null ? PICK_DIST : Math.max(pickDistance, 0);\r
-    }\r
-    \r
-    private IElement rotatingPick(int selectionId, List<IElement> pickables) {\r
-        Set<IElement> sel = selection.getSelection(selectionId);\r
-        return rotatingPick(sel, pickables);\r
-    }\r
 \r
-    private IElement rotatingPick(Set<IElement> sel, List<IElement> pickables) {\r
-        int earliestIndex = pickables.size();\r
-        for (int i = pickables.size() - 1; i >= 0; --i) {\r
-            if (sel.contains(pickables.get(i))) {\r
-                earliestIndex = i;\r
-                break;\r
-            }\r
-        }\r
-        if (earliestIndex == 0)\r
-            earliestIndex = pickables.size();\r
-        IElement selectedPick = pickables.get(earliestIndex - 1);\r
-        return selectedPick;\r
-    }\r
-\r
-    public static class NetworkDrawingNode extends G2DNode {\r
-\r
-        private static final long serialVersionUID = -3475301184009620573L;\r
-        \r
-        private List<Point2D> nodes = new ArrayList<>();\r
-\r
-        private Rectangle2D rect = new Rectangle2D.Double(10, 10, 10, 10);\r
-\r
-        private Set<Path2D> paths = new HashSet<>();\r
-\r
-        private Resource diagramResource;\r
-\r
-        private boolean committed;\r
-        \r
-        @Override\r
-        public void init() {\r
-            super.init();\r
-            addEventHandler(this);\r
-        }\r
-        \r
-        public void setDiagram(IDiagram diagram) {\r
-            if (diagram != null)\r
-                this.diagramResource = diagram.getHint(DiagramModelHints.KEY_DIAGRAM_RESOURCE);\r
-        }\r
-\r
-        @Override\r
-        public void render(Graphics2D g2d) {\r
-            Color old = g2d.getColor();\r
-            g2d.setColor(Color.BLUE);\r
-            \r
-            paths.forEach(p -> {\r
-                g2d.draw(p);\r
-            });\r
-            \r
-            g2d.setColor(old);\r
-        }\r
-\r
-        @Override\r
-        public Rectangle2D getBoundsInLocal() {\r
-            return rect.getBounds2D();\r
-        }\r
-        \r
-        @Override\r
-        public int getEventMask() {\r
-            return EventTypes.MouseMask;\r
-        }\r
-        \r
-        @Override\r
-        protected boolean mouseDoubleClicked(MouseDoubleClickedEvent e) {\r
-            // nodes to path2d\r
-            Point2D start = null;\r
-            Point2D end = null;\r
-            Iterator<Point2D> nodeIter = nodes.iterator();\r
-            while (nodeIter.hasNext()) {\r
-                if (end == null) {\r
-                    start = nodeIter.next();\r
-                } else {\r
-                    start = end;\r
-                }\r
-                end = nodeIter.next();\r
-                \r
-                createEdge(start, end);\r
-            }\r
-            \r
-            nodes.clear();\r
-            committed = true;\r
-            \r
-            repaint();\r
-            \r
-            return true;\r
-        }\r
-        \r
-        private void createEdge(Point2D start, Point2D end) {\r
-            double[] startCoords = new double[] { start.getX(), start.getY() };\r
-            double[] endCoords = new double[] { end.getX(), end.getY() };\r
-            \r
-            DNEdgeBuilder builder = new DNEdgeBuilder(diagramResource);\r
-            Simantics.getSession().asyncRequest(new WriteRequest() {\r
-                \r
-                @Override\r
-                public void perform(WriteGraph graph) throws DatabaseException {\r
-                    builder.create(graph, startCoords, endCoords);\r
-                }\r
-            });\r
-            \r
-        }\r
-        \r
-        @Override\r
-        protected boolean mouseClicked(MouseClickEvent e) {\r
-            if (committed) {\r
-                committed = false;\r
-                return false;\r
-            }\r
-            Point2D localPos = NodeUtil.worldToLocal(this, e.controlPosition, new Point2D.Double());\r
-            nodes.add(new Point2D.Double(localPos.getX(), localPos.getY()));\r
-            return super.mouseClicked(e);\r
-        }\r
-        \r
-        @Override\r
-        protected boolean mouseMoved(MouseMovedEvent e) {\r
-            return super.mouseMoved(e);\r
-        }\r
-    }\r
 }\r
index 8ec1430b83c4e0de2d1bbbb5206505f8323c6b9c..a53c02d2e0ba98708b8661cf64379f4f6a232545 100644 (file)
@@ -10,7 +10,7 @@ import org.simantics.g2d.element.IElement;
 import org.simantics.g2d.element.SceneGraphNodeKey;\r
 import org.simantics.g2d.element.handler.InternalSize;\r
 import org.simantics.g2d.element.handler.SceneGraph;\r
-import org.simantics.g2d.elementclass.connection.EdgeClass.FixedTransform;\r
+import org.simantics.g2d.element.handler.impl.DefaultTransform;\r
 import org.simantics.scenegraph.g2d.G2DParentNode;\r
 import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
 import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;\r
@@ -22,7 +22,7 @@ public class DistrictNetworkEdgeElement {
     \r
     public static final ElementClass CLASS =\r
             ElementClass.compile(\r
-                    FixedTransform.INSTANCE,\r
+                    DefaultTransform.INSTANCE,\r
                     DNEdgeInternalSize.INSTANCE,\r
                     DNEdgeSceneGraph.INSTANCE\r
             ).setId(DistrictNetworkEdgeElement.class.getSimpleName());\r
@@ -64,7 +64,11 @@ public class DistrictNetworkEdgeElement {
         @Override\r
         public Rectangle2D getBounds(IElement e, Rectangle2D size) {\r
             DistrictNetworkEdge edge = e.getHint(KEY_DN_EDGE);\r
-            return edge.getBounds(size);\r
+            if (size == null)\r
+                size = new Rectangle2D.Double();\r
+            edge.getBounds(size);\r
+\r
+            return size;\r
         }\r
         \r
     }\r
index bb75ab0c4597d19705dec4a60e9af955f22e4c2c..339d51d4149d8f2664a2b154d87c4b48a5bd2a0e 100644 (file)
@@ -1,6 +1,7 @@
 package org.simantics.district.network.ui.adapters;\r
 \r
 import java.awt.Dimension;\r
+import java.awt.geom.AffineTransform;\r
 import java.awt.geom.Rectangle2D;\r
 \r
 import org.simantics.district.network.ui.nodes.DistrictNetworkVertexNode;\r
@@ -10,7 +11,7 @@ import org.simantics.g2d.element.IElement;
 import org.simantics.g2d.element.SceneGraphNodeKey;\r
 import org.simantics.g2d.element.handler.InternalSize;\r
 import org.simantics.g2d.element.handler.SceneGraph;\r
-import org.simantics.g2d.elementclass.connection.EdgeClass.FixedTransform;\r
+import org.simantics.g2d.element.handler.impl.DefaultTransform;\r
 import org.simantics.scenegraph.g2d.G2DParentNode;\r
 import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
 import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;\r
@@ -22,7 +23,7 @@ public class DistrictNetworkVertexElement {
     \r
     public static final ElementClass CLASS =\r
             ElementClass.compile(\r
-                    FixedTransform.INSTANCE,\r
+                    DefaultTransform.INSTANCE,\r
                     DNVertexInternalSize.INSTANCE,\r
                     DNVertexSceneGraph.INSTANCE\r
             ).setId(DistrictNetworkVertexElement.class.getSimpleName());\r
@@ -45,6 +46,10 @@ public class DistrictNetworkVertexElement {
                     edgeElement.setHint(KEY_DN_VERTEX_NODE, node);\r
                 }\r
                 node.setVertex(vertex);\r
+                \r
+                AffineTransform at = ElementUtils.getTransform(edgeElement);\r
+                if(at != null)\r
+                    node.setTransform(at);\r
             }\r
         }\r
 \r
@@ -63,10 +68,9 @@ public class DistrictNetworkVertexElement {
 \r
         @Override\r
         public Rectangle2D getBounds(IElement e, Rectangle2D size) {\r
-            DistrictNetworkVertex vertex = e.getHint(KEY_DN_VERTEX);\r
             if (size == null)\r
                 size = new Rectangle2D.Double();\r
-            size.setFrame(vertex.getPoint(), new Dimension(1, 1));\r
+            size.setFrame(-0.5, -0.5, 1, 1);\r
             return size;\r
         }\r
         \r
index 909f7fb1d2deb02cec0fa8ebb38e47f8c350d150..c19716469d243e81ce7f35ead2b7799310d49c46 100644 (file)
@@ -1,5 +1,7 @@
 package org.simantics.district.network.ui.adapters;\r
 \r
+import java.awt.geom.AffineTransform;\r
+\r
 import org.simantics.db.AsyncReadGraph;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
@@ -11,6 +13,7 @@ import org.simantics.district.network.ontology.DistrictNetworkResource;
 import org.simantics.g2d.canvas.ICanvasContext;\r
 import org.simantics.g2d.diagram.IDiagram;\r
 import org.simantics.g2d.element.ElementClass;\r
+import org.simantics.g2d.element.ElementUtils;\r
 import org.simantics.g2d.element.IElement;\r
 import org.simantics.g2d.element.handler.impl.StaticObjectAdapter;\r
 \r
@@ -26,8 +29,7 @@ public class DistrictNetworkVertexElementFactory extends SyncElementFactory {
     }\r
 \r
     @Override\r
-    public void create(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType,\r
-            AsyncProcedure<ElementClass> procedure) {\r
+    public void create(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType, AsyncProcedure<ElementClass> procedure) {\r
         procedure.execute(graph, CLASS.newClassWith(false, new StaticObjectAdapter(elementType)));\r
     }\r
 \r
@@ -40,9 +42,11 @@ public class DistrictNetworkVertexElementFactory extends SyncElementFactory {
     public void load(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource vertexResource, IElement element) throws DatabaseException {\r
         \r
         double[] coords = graph.getRelatedValue(vertexResource, DIA.HasLocation);\r
-        \r
         DistrictNetworkVertex vertex = new DistrictNetworkVertex(coords);\r
-        \r
         element.setHint(DistrictNetworkVertexElement.KEY_DN_VERTEX, vertex);\r
+        \r
+        // set element transform based on layer SRS and coords\r
+        AffineTransform at = new AffineTransform(1, 0, 0, 1, coords[0], coords[1]);\r
+        ElementUtils.setTransform(element, at);\r
     }\r
 }\r
index 6001365346506306827e10c10d4c8c7ed62e599c..eb1d26eb7359c9983c1183804b93f758bd5261fd 100644 (file)
@@ -38,14 +38,14 @@ public class DistrictNetworkEdgeNode extends G2DNode {
         g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);\r
 \r
         Color oldColor = g2d.getColor();\r
-        boolean selected = isSelected();\r
-        if (selected) {\r
-            Path2D selectionPath = edge.getPath();\r
-            Shape selectionShape = SELECTION_STROKE.createStrokedShape(selectionPath);\r
-            g2d.setColor(SELECTION_COLOR);\r
-            g2d.fill(selectionShape);\r
-        }\r
-        \r
+//        boolean selected = isSelected();\r
+//        if (selected) {\r
+//            Path2D selectionPath = edge.getPath();\r
+//            Shape selectionShape = SELECTION_STROKE.createStrokedShape(selectionPath);\r
+//            g2d.setColor(SELECTION_COLOR);\r
+//            g2d.fill(selectionShape);\r
+//        }\r
+//        \r
         g2d.setColor(Color.BLUE);\r
         // render\r
         g2d.draw(edge.getPath());\r
@@ -80,6 +80,7 @@ public class DistrictNetworkEdgeNode extends G2DNode {
 \r
     public void setDNEdge(DistrictNetworkEdge edge) {\r
         this.edge = edge;\r
+        updateBounds();\r
     }\r
 \r
 }\r
index 770385000b84705376c08cfcfa57d7a275710949..7365060b0254bc8c6f62d5c4cb4aeef8e1dcd6d5 100644 (file)
@@ -30,7 +30,7 @@ public class DistrictNetworkVertexNode extends G2DNode {
         g2d.setColor(Color.RED);\r
         // render\r
         \r
-        Rectangle2D.Double rect = new Rectangle2D.Double(vertex.getPoint().getX() - 0.5, vertex.getPoint().getY() - 0.5, 1, 1);\r
+        Rectangle2D.Double rect = new Rectangle2D.Double(-0.5, -0.5, 1, 1);\r
         g2d.draw(rect);\r
         \r
         // Reset stats\r
@@ -44,7 +44,7 @@ public class DistrictNetworkVertexNode extends G2DNode {
 \r
     @Override\r
     public Rectangle2D getBoundsInLocal() {\r
-        return new Rectangle2D.Double(vertex.getPoint().getX(), vertex.getPoint().getY(), 1, 1);\r
+        return new Rectangle2D.Double(-0.5, -0.5, 1, 1);\r
     }\r
 \r
     public void setVertex(DistrictNetworkVertex vertex) {\r
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/NetworkDrawingNode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/NetworkDrawingNode.java
new file mode 100644 (file)
index 0000000..4862942
--- /dev/null
@@ -0,0 +1,157 @@
+package org.simantics.district.network.ui.nodes;\r
+\r
+import java.awt.Color;\r
+import java.awt.Graphics2D;\r
+import java.awt.geom.Path2D;\r
+import java.awt.geom.Point2D;\r
+import java.awt.geom.Rectangle2D;\r
+import java.util.ArrayList;\r
+import java.util.HashSet;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import java.util.Set;\r
+\r
+import org.simantics.Simantics;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.diagram.ui.DiagramModelHints;\r
+import org.simantics.district.network.ui.DNEdgeBuilder;\r
+import org.simantics.district.network.ui.NetworkDrawingParticipant;\r
+import org.simantics.g2d.canvas.Hints;\r
+import org.simantics.g2d.canvas.IToolMode;\r
+import org.simantics.g2d.diagram.IDiagram;\r
+import org.simantics.scenegraph.g2d.G2DNode;\r
+import org.simantics.scenegraph.g2d.events.EventTypes;\r
+import org.simantics.scenegraph.g2d.events.MouseEvent;\r
+import org.simantics.scenegraph.g2d.events.MouseEvent.MouseClickEvent;\r
+import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDoubleClickedEvent;\r
+import org.simantics.scenegraph.g2d.events.MouseEvent.MouseMovedEvent;\r
+import org.simantics.scenegraph.utils.NodeUtil;\r
+\r
+public class NetworkDrawingNode extends G2DNode {\r
+\r
+    private static final long serialVersionUID = -3475301184009620573L;\r
+    \r
+    private List<Point2D> nodes = new ArrayList<>();\r
+\r
+    private Rectangle2D rect = new Rectangle2D.Double(10, 10, 10, 10);\r
+\r
+    private Set<Path2D> paths = new HashSet<>();\r
+\r
+    private Resource diagramResource;\r
+\r
+    private boolean committed;\r
+\r
+    private NetworkDrawingParticipant participant;\r
+\r
+    private IDiagram diagram;\r
+    \r
+    @Override\r
+    public void init() {\r
+        super.init();\r
+        addEventHandler(this);\r
+    }\r
+    \r
+    public void setNetworkDrawingParticipant(NetworkDrawingParticipant participant) {\r
+        this.participant = participant;\r
+    }\r
+    \r
+    public void setDiagram(IDiagram diagram) {\r
+        if (diagram != null) {\r
+            this.diagram = diagram;\r
+            this.diagramResource = diagram.getHint(DiagramModelHints.KEY_DIAGRAM_RESOURCE);\r
+        }\r
+    }\r
+\r
+    @Override\r
+    public void render(Graphics2D g2d) {\r
+        Color old = g2d.getColor();\r
+        g2d.setColor(Color.BLUE);\r
+        \r
+        paths.forEach(p -> {\r
+            g2d.draw(p);\r
+        });\r
+        \r
+        g2d.setColor(old);\r
+    }\r
+\r
+    @Override\r
+    public Rectangle2D getBoundsInLocal() {\r
+        return rect.getBounds2D();\r
+    }\r
+    \r
+    @Override\r
+    public int getEventMask() {\r
+        return EventTypes.MouseMask;\r
+    }\r
+    \r
+    @Override\r
+    protected boolean mouseDoubleClicked(MouseDoubleClickedEvent e) {\r
+        // nodes to path2d\r
+        IToolMode mode = getToolMode();\r
+        if (mode == Hints.CONNECTTOOL || e.hasAnyModifier(MouseEvent.ALT_MASK | MouseEvent.ALT_GRAPH_MASK)) {\r
+            Point2D start = null;\r
+            Point2D end = null;\r
+            Iterator<Point2D> nodeIter = nodes.iterator();\r
+            while (nodeIter.hasNext()) {\r
+                if (end == null) {\r
+                    start = nodeIter.next();\r
+                } else {\r
+                    start = end;\r
+                }\r
+                end = nodeIter.next();\r
+                \r
+                createEdge(start, end);\r
+            }\r
+            \r
+            nodes.clear();\r
+            committed = true;\r
+            \r
+            repaint();\r
+            \r
+            return true;\r
+        }\r
+        return super.mouseDoubleClicked(e);\r
+    }\r
+    \r
+    private void createEdge(Point2D start, Point2D end) {\r
+        double[] startCoords = new double[] { start.getX(), start.getY() };\r
+        double[] endCoords = new double[] { end.getX(), end.getY() };\r
+        \r
+        DNEdgeBuilder builder = new DNEdgeBuilder(diagramResource, diagram);\r
+        Simantics.getSession().asyncRequest(new WriteRequest() {\r
+            \r
+            @Override\r
+            public void perform(WriteGraph graph) throws DatabaseException {\r
+                builder.create(graph, startCoords, endCoords);\r
+            }\r
+        });\r
+        \r
+    }\r
+    \r
+    @Override\r
+    protected boolean mouseClicked(MouseClickEvent e) {\r
+        // check ToolMode\r
+        IToolMode mode = getToolMode();\r
+        if (mode == Hints.CONNECTTOOL || e.hasAnyModifier(MouseEvent.ALT_MASK | MouseEvent.ALT_GRAPH_MASK)) {\r
+            if (committed) {\r
+                committed = false;\r
+                return false;\r
+            }\r
+            Point2D localPos = NodeUtil.worldToLocal(this, e.controlPosition, new Point2D.Double());\r
+            nodes.add(new Point2D.Double(localPos.getX(), localPos.getY()));\r
+        }\r
+        return super.mouseClicked(e);\r
+    }\r
+    \r
+    private IToolMode getToolMode() {\r
+        return participant.getHint(Hints.KEY_TOOL);\r
+    }\r
+\r
+    @Override\r
+    protected boolean mouseMoved(MouseMovedEvent e) {\r
+        return super.mouseMoved(e);\r
+    }\r
+}
\ No newline at end of file
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DNPointerInteractor.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DNPointerInteractor.java
new file mode 100644 (file)
index 0000000..e8b8337
--- /dev/null
@@ -0,0 +1,22 @@
+package org.simantics.district.network.ui.participants;\r
+\r
+import java.awt.geom.Point2D;\r
+import java.util.Set;\r
+\r
+import org.simantics.g2d.canvas.ICanvasParticipant;\r
+import org.simantics.g2d.diagram.participant.pointertool.PointerInteractor;\r
+import org.simantics.g2d.diagram.participant.pointertool.TerminalUtil.TerminalInfo;\r
+import org.simantics.g2d.element.IElement;\r
+\r
+public class DNPointerInteractor extends PointerInteractor {\r
+\r
+    @Override\r
+    protected ICanvasParticipant createConnectTool(TerminalInfo ti, int mouseId, Point2D startCanvasPos) {\r
+        return super.createConnectTool(ti, mouseId, startCanvasPos);\r
+    }\r
+    \r
+    @Override\r
+    protected ICanvasParticipant createTranslateTool(int mouseId, Point2D startCanvasPos, Point2D curCanvasPos, Set<IElement> elementsToDrag) {\r
+        return new DNTranslateMode(startCanvasPos, curCanvasPos, mouseId, elementsToDrag);\r
+    }\r
+}\r
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DNTranslateMode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DNTranslateMode.java
new file mode 100644 (file)
index 0000000..74a4647
--- /dev/null
@@ -0,0 +1,83 @@
+package org.simantics.district.network.ui.participants;\r
+\r
+import java.awt.geom.AffineTransform;\r
+import java.awt.geom.Point2D;\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.Simantics;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.CommentMetadata;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.diagram.elements.ElementTransforms;\r
+import org.simantics.diagram.elements.ElementTransforms.TransformedObject;\r
+import org.simantics.diagram.stubs.DiagramResource;\r
+import org.simantics.district.network.ontology.DistrictNetworkResource;\r
+import org.simantics.g2d.canvas.Hints;\r
+import org.simantics.g2d.diagram.participant.pointertool.TranslateMode;\r
+import org.simantics.g2d.element.ElementUtils;\r
+import org.simantics.g2d.element.IElement;\r
+import org.simantics.g2d.element.handler.Move;\r
+\r
+public class DNTranslateMode extends TranslateMode {\r
+\r
+    public DNTranslateMode(Point2D startingPoint, Point2D currentPoint, int mouseId, Collection<IElement> elements) {\r
+        super(startingPoint, currentPoint, mouseId, elements);\r
+    }\r
+    \r
+    @Override\r
+    protected boolean commit() {\r
+        for (IElement el : elementsToReallyTranslate) {\r
+            Move move = el.getElementClass().getAtMostOneItemOfClass(Move.class);\r
+            if (move != null) {\r
+                Point2D oldPos = move.getPosition(el);\r
+                move.moveTo(el, oldPos.getX() + dx, oldPos.getY() + dy);\r
+            }\r
+        }\r
+        try {\r
+            Simantics.getSession().syncRequest(new WriteRequest() {\r
+                @Override\r
+                public void perform(WriteGraph graph) throws DatabaseException {\r
+                    Collection<TransformedObject> transformed = new ArrayList<TransformedObject>();\r
+                    DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);\r
+                    DiagramResource DIA = DiagramResource.getInstance(graph);\r
+                    for (IElement e : elementsToReallyTranslate) {\r
+                        Object obj = ElementUtils.getObject(e);\r
+                        if (obj instanceof Resource) {\r
+                            Resource res = (Resource) obj;\r
+                            if (graph.isInstanceOf(res, DN.Vertex)) {\r
+                                AffineTransform at = ElementUtils.getLocalTransform(e, new AffineTransform());\r
+                                transformed.add( new TransformedObject((Resource) obj, at) );\r
+                                \r
+                                \r
+                                // write to db\r
+                                double[] coords = new double[] { at.getTranslateX(), at.getTranslateY() };\r
+                                graph.claimLiteral(res, DIA.HasLocation, coords);\r
+                            }\r
+                        }\r
+                    }\r
+                    \r
+                    if (!transformed.isEmpty()) {\r
+                        CommentMetadata cm = graph.getMetadata(CommentMetadata.class);\r
+                        graph.addMetadata(cm.add("Translated " + transformed.size() + " "\r
+                                + (transformed.size() == 1 ? "element" : "elements")\r
+                                + " by (" + dx + "," + dy + ") mm."));\r
+                        graph.markUndoPoint();\r
+                    }\r
+                }\r
+            });\r
+        } catch (DatabaseException e) {\r
+            e.printStackTrace();\r
+        }\r
+        \r
+        for (IElement dirty : elementsToDirty)\r
+            dirty.setHint(Hints.KEY_DIRTY, Hints.VALUE_SG_DIRTY);\r
+\r
+        setDirty();\r
+        remove();\r
+        return false;\r
+    }\r
+\r
+}\r
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/templates/AddLayerToDNDiagramTemplate.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/templates/AddLayerToDNDiagramTemplate.java
new file mode 100644 (file)
index 0000000..4b846c3
--- /dev/null
@@ -0,0 +1,40 @@
+package org.simantics.district.network.ui.templates;\r
+\r
+import java.util.Map;\r
+import java.util.UUID;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.adapter.Template;\r
+import org.simantics.diagram.stubs.DiagramResource;\r
+import org.simantics.diagram.synchronization.graph.layer.GraphLayer;\r
+import org.simantics.diagram.synchronization.graph.layer.IGraphLayerUtil;\r
+import org.simantics.district.network.ontology.DistrictNetworkResource;\r
+\r
+public class AddLayerToDNDiagramTemplate implements Template {\r
+\r
+    Resource template;\r
+    \r
+    public AddLayerToDNDiagramTemplate(Resource template) {\r
+        this.template = template;\r
+    }\r
+    \r
+    @Override\r
+    public void apply(WriteGraph graph, Map<String, Object> parameters) throws DatabaseException {\r
+        Resource diagram = (Resource)parameters.get("diagram");\r
+        if (diagram == null) {\r
+            diagram = graph.newResource();\r
+            parameters.put("diagram", diagram);\r
+        }\r
+        \r
+        DiagramResource DIA = DiagramResource.getInstance(graph);\r
+        IGraphLayerUtil layerUtil = graph.adapt(DistrictNetworkResource.getInstance(graph).Layer, IGraphLayerUtil.class);\r
+        GraphLayer layer = layerUtil.createLayer(graph, UUID.randomUUID().toString(), true);\r
+        \r
+        // Create layer\r
+        graph.claim(diagram, DIA.HasLayer, layer.getLayer());\r
+        \r
+    }\r
+\r
+}\r
index f9e0439dc02656dfcd2f9ba711610bc91d3acf08..25503407e66f38f83b49d26dbdcd2334ccd59893 100644 (file)
@@ -13,7 +13,6 @@ public class DistrictNetworkUtil {
     public static Resource createEdge(WriteGraph graph, Resource composite) throws DatabaseException {\r
         Layer0 L0 = Layer0.getInstance(graph);\r
         DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);\r
-        DiagramResource DIA = DiagramResource.getInstance(graph);\r
         \r
         Resource edge = graph.newResource();\r
         graph.claim(edge, L0.InstanceOf, DN.Edge);\r
index e43314c8127c02549e9560f645787d6d10ff7a2c..8faefe0ebf75018666486301baf6d4644785011f 100644 (file)
          version="0.0.0"\r
          unpack="false"/>\r
 \r
+   <plugin\r
+         id="org.simantics.district.network.ui.ontology"\r
+         download-size="0"\r
+         install-size="0"\r
+         version="0.0.0"\r
+         unpack="false"/>\r
+\r
 </feature>\r