]> gerrit.simantics Code Review - simantics/district.git/commitdiff
First version of district visualisations 81/3181/1
authorjsimomaa <jani.simomaa@gmail.com>
Mon, 2 Sep 2019 06:16:30 +0000 (09:16 +0300)
committerjsimomaa <jani.simomaa@gmail.com>
Mon, 2 Sep 2019 06:16:30 +0000 (09:16 +0300)
TODO:
* Saving of visualisation templates
* Disabling dynamic updates
* "Gappless" color/size values from maps
* Show/Hide ticks of color bars
* Perfomance tuning

gitlab #59
APROS-15038
APROS-15527
APROS-15528

Change-Id: I739d1b677351084c88820579a3a0ef3c985b8886

33 files changed:
org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph
org.simantics.district.network.ontology/graph/DistrictNetworkDiagramSettings.pgraph
org.simantics.district.network.ontology/graph/DistrictNetworkProfiles.pgraph
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/fragment.e4xmi
org.simantics.district.network.ui/plugin.xml
org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DynamicVisualisationContributionsNode.java [new file with mode: 0644]
org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DynamicVisualisationContributionsParticipant.java [new file with mode: 0644]
org.simantics.district.network.ui/src/org/simantics/district/network/ui/table/ImportCSVHandler.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java [new file with mode: 0644]
org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsView.java [new file with mode: 0644]
org.simantics.district.network/META-INF/MANIFEST.MF
org.simantics.district.network/adapters.xml
org.simantics.district.network/scl/Simantics/District/DynamicVisualisations/ColorContribution.scl [new file with mode: 0644]
org.simantics.district.network/scl/Simantics/District/DynamicVisualisations/ColorMap.scl [new file with mode: 0644]
org.simantics.district.network/scl/Simantics/District/DynamicVisualisations/SizeContribution.scl [new file with mode: 0644]
org.simantics.district.network/scl/Simantics/District/DynamicVisualisations/SizeMap.scl [new file with mode: 0644]
org.simantics.district.network/src/org/simantics/district/network/DistrictNetworkUtil.java
org.simantics.district.network/src/org/simantics/district/network/profile/DNElementColorStyle.java
org.simantics.district.network/src/org/simantics/district/network/profile/DNElementSizeStyle.java [new file with mode: 0644]
org.simantics.district.network/src/org/simantics/district/network/profile/DynamicVisualisationsRequest.java [new file with mode: 0644]
org.simantics.district.network/src/org/simantics/district/network/profile/RuntimeDynamicVisualisationsRequest.java [new file with mode: 0644]
org.simantics.district.network/src/org/simantics/district/network/visualisations/DynamicVisualisationsContributions.java [new file with mode: 0644]
org.simantics.district.network/src/org/simantics/district/network/visualisations/VisualisationColoringObject.java [new file with mode: 0644]
org.simantics.district.network/src/org/simantics/district/network/visualisations/model/ColorBarOptions.java [new file with mode: 0644]
org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicColorContribution.java [new file with mode: 0644]
org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicColorMap.java [new file with mode: 0644]
org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicSizeContribution.java [new file with mode: 0644]
org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicSizeMap.java [new file with mode: 0644]
org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicVisualisation.java [new file with mode: 0644]
org.simantics.district.network/src/org/simantics/district/network/visualisations/model/SizeBarOptions.java [new file with mode: 0644]

index 2a64b3dc15ba566b838cb17487c0869c5b8be820..128904c801bbdd9d3bc08840620fdd02bad2fa04 100644 (file)
@@ -156,6 +156,10 @@ DN.RightClickDefaultMapping <R L0.HasProperty : DN.VertexMappingParameterType
 DN.LeftClickDefaultMapping <R L0.HasProperty : DN.VertexMappingParameterType
     L0.HasLabel "Left click Vertex mapping"
 
+DN.Diagram.DefaultPipeTechTypeId <R L0.HasProperty : SEL.GenericParameterType
+    L0.HasLabel "Default Pipe Tech Type ID"
+
+
 // ----------------------------------------------------------------------------
 
 DN.Functions : L0.Library
@@ -208,6 +212,58 @@ DN.Diagram.splitToMultipleEnabled <R L0.HasProperty : SEL.GenericParameterType
     L0.HasRange L0.Boolean
     L0.HasLabel "Split To Multiple Diagrams"
 
+
+
+DN.Diagram.Visualisations <T L0.Entity
+    >-- DN.Diagram.Visualisations.ShowColorBars
+        @defProperty "Show Color Bars" L0.Boolean
+    >-- DN.Diagram.Visualisations.ShowColorBarTicks
+        @defProperty "Show Color Bar Ticks" L0.Boolean
+    >-- DN.Diagram.Visualisations.ColorBarLocation
+        @defProperty "Color Bar Location" L0.String
+    >-- DN.Diagram.Visualisations.ColorBarSize
+        @defProperty "Color Bar Size" L0.String
+    >-- DN.Diagram.Visualisations.ShowSizeBars
+        @defProperty "Show Size Bars" L0.Boolean
+    >-- DN.Diagram.Visualisations.ShowSizeBarTicks
+        @defProperty "Show Size Bar Ticks" L0.Boolean
+    >-- DN.Diagram.Visualisations.SizeBarLocation
+        @defProperty "Size Bar Location" L0.String
+    >-- DN.Diagram.Visualisations.SizeBarSize
+        @defProperty "Size Bar Size" L0.String
+
+DN.Diagram.Visualisations.colorContributions <R L0.HasProperty
+DN.Diagram.Visualisations.sizeContributions <R L0.HasProperty
+
+DN.Diagram.Visualisations.colorContributionContributorName <R L0.HasProperty
+DN.Diagram.Visualisations.colorContributionLabel <R L0.HasProperty
+DN.Diagram.Visualisations.colorContributionModuleName <R L0.HasProperty
+DN.Diagram.Visualisations.colorContributionModuleAttribute <R L0.HasProperty
+DN.Diagram.Visualisations.colorContributionUnit <R L0.HasProperty
+DN.Diagram.Visualisations.colorContributionVariableGain <R L0.HasProperty
+DN.Diagram.Visualisations.colorContributionVariableBias <R L0.HasProperty
+DN.Diagram.Visualisations.colorContributionDefaultColorMap <R L0.HasProperty
+DN.Diagram.Visualisations.colorContributionDefaultMin <R L0.HasProperty
+DN.Diagram.Visualisations.colorContributionDefaultMax <R L0.HasProperty
+// for graph persistence only
+DN.Diagram.Visualisations.colorContributionUsed <R L0.HasProperty
+DN.Diagram.Visualisations.colorContributionUseDefault <R L0.HasProperty
+
+DN.Diagram.Visualisations.sizeContributionContributorName <R L0.HasProperty
+DN.Diagram.Visualisations.sizeContributionLabel <R L0.HasProperty
+DN.Diagram.Visualisations.sizeContributionModuleName <R L0.HasProperty
+DN.Diagram.Visualisations.sizeContributionModuleAttribute <R L0.HasProperty
+DN.Diagram.Visualisations.sizeContributionUnit <R L0.HasProperty
+DN.Diagram.Visualisations.sizeContributionVariableGain <R L0.HasProperty
+DN.Diagram.Visualisations.sizeContributionVariableBias <R L0.HasProperty
+DN.Diagram.Visualisations.sizeContributionDefaultSizeMap <R L0.HasProperty
+DN.Diagram.Visualisations.sizeContributionDefaultMin <R L0.HasProperty
+DN.Diagram.Visualisations.sizeContributionDefaultMax <R L0.HasProperty
+// for graph persistence only
+DN.Diagram.Visualisations.sizeContributionUsed <R L0.HasProperty
+DN.Diagram.Visualisations.sizeContributionUseDefault <R L0.HasProperty
+
+
 DN.AddLayerToDNDiagramTemplate <T L0.Template
 
 DN.EPSG_4326 : DN.SpatialRefSystem
index 69cb2807cd32e30574c3e0a13910c697bf8054e6..a1ce3a0acbbd1ab0fc619dcaf23ac734fd8ad650 100644 (file)
@@ -106,6 +106,8 @@ DN.Diagram
         L0.HasLabel "Diagram Background Color"
     >-- DN.Diagram.drawMapEnabled ==> "Boolean" <R L0.HasProperty : SEL.GenericParameterType
         L0.HasLabel "Draw Map"
+    >-- DN.Diagram.hasVisualisation --> DN.Diagram.Visualisations <R L0.HasProperty
+        L0.HasLabel "Visualisation"
     >-- DN.Diagram.profileUpdateInterval ==> "Long" <R L0.HasProperty : SEL.GenericParameterType
         L0.HasLabel "Profile update interval"
     @L0.assert DN.Diagram.elementColoringGradientHue
@@ -127,6 +129,7 @@ DN.Diagram
     @L0.assert DN.Diagram.drawMapEnabled true
     @L0.assert DN.Diagram.profileUpdateInterval
         2000 : L0.Long
+    @L0.assert DN.Diagram.DefaultPipeTechTypeId 0
 
 // ----------------------------------------------------------------------------
 // Built-in enumerated ScaleProperty & ThicknessProperty instances
index 25c17f4d961dff0ca3525556873984ccd53bf97f..ecb8231180dfafa1ab05f4eaee1782b0c3db0595 100644 (file)
@@ -20,6 +20,7 @@ DN.Groups.EdgeGroup : DIA.TypeGroup
     DIA.TypeGroup.HasType DN.Edge
 
 DN.ElementColoringStyle : DIA.Style
+DN.ElementSizingStyle : DIA.Style
 DN.VertexSizeStyle : DIA.Style
 DN.EdgeThicknessStyle : DIA.Style
 DN.ArrowLengthStyle : DIA.Style
index 6ab3df7671685f273b86c442cbaf14a0053427ab..5bcf491bf81655928330ef7d423a31254fc80eed 100644 (file)
@@ -22,8 +22,79 @@ public class DistrictNetworkResource {
     public final Resource Connection;
     public final Resource ConnectionLineStyle;
     public final Resource Diagram;
+    public final Resource Diagram_DefaultPipeTechTypeId;
+    public final Resource Diagram_DefaultPipeTechTypeId_Inverse;
     public final Resource Diagram_MappedDiagram;
     public final Resource Diagram_MappedFromDiagram;
+    public final Resource Diagram_Visualisations;
+    public final Resource Diagram_Visualisations_ColorBarLocation;
+    public final Resource Diagram_Visualisations_ColorBarLocation_Inverse;
+    public final Resource Diagram_Visualisations_ColorBarSize;
+    public final Resource Diagram_Visualisations_ColorBarSize_Inverse;
+    public final Resource Diagram_Visualisations_ShowColorBarTicks;
+    public final Resource Diagram_Visualisations_ShowColorBarTicks_Inverse;
+    public final Resource Diagram_Visualisations_ShowColorBars;
+    public final Resource Diagram_Visualisations_ShowColorBars_Inverse;
+    public final Resource Diagram_Visualisations_ShowSizeBarTicks;
+    public final Resource Diagram_Visualisations_ShowSizeBarTicks_Inverse;
+    public final Resource Diagram_Visualisations_ShowSizeBars;
+    public final Resource Diagram_Visualisations_ShowSizeBars_Inverse;
+    public final Resource Diagram_Visualisations_SizeBarLocation;
+    public final Resource Diagram_Visualisations_SizeBarLocation_Inverse;
+    public final Resource Diagram_Visualisations_SizeBarSize;
+    public final Resource Diagram_Visualisations_SizeBarSize_Inverse;
+    public final Resource Diagram_Visualisations_colorContributionContributorName;
+    public final Resource Diagram_Visualisations_colorContributionContributorName_Inverse;
+    public final Resource Diagram_Visualisations_colorContributionDefaultColorMap;
+    public final Resource Diagram_Visualisations_colorContributionDefaultColorMap_Inverse;
+    public final Resource Diagram_Visualisations_colorContributionDefaultMax;
+    public final Resource Diagram_Visualisations_colorContributionDefaultMax_Inverse;
+    public final Resource Diagram_Visualisations_colorContributionDefaultMin;
+    public final Resource Diagram_Visualisations_colorContributionDefaultMin_Inverse;
+    public final Resource Diagram_Visualisations_colorContributionLabel;
+    public final Resource Diagram_Visualisations_colorContributionLabel_Inverse;
+    public final Resource Diagram_Visualisations_colorContributionModuleAttribute;
+    public final Resource Diagram_Visualisations_colorContributionModuleAttribute_Inverse;
+    public final Resource Diagram_Visualisations_colorContributionModuleName;
+    public final Resource Diagram_Visualisations_colorContributionModuleName_Inverse;
+    public final Resource Diagram_Visualisations_colorContributionUnit;
+    public final Resource Diagram_Visualisations_colorContributionUnit_Inverse;
+    public final Resource Diagram_Visualisations_colorContributionUseDefault;
+    public final Resource Diagram_Visualisations_colorContributionUseDefault_Inverse;
+    public final Resource Diagram_Visualisations_colorContributionUsed;
+    public final Resource Diagram_Visualisations_colorContributionUsed_Inverse;
+    public final Resource Diagram_Visualisations_colorContributionVariableBias;
+    public final Resource Diagram_Visualisations_colorContributionVariableBias_Inverse;
+    public final Resource Diagram_Visualisations_colorContributionVariableGain;
+    public final Resource Diagram_Visualisations_colorContributionVariableGain_Inverse;
+    public final Resource Diagram_Visualisations_colorContributions;
+    public final Resource Diagram_Visualisations_colorContributions_Inverse;
+    public final Resource Diagram_Visualisations_sizeContributionContributorName;
+    public final Resource Diagram_Visualisations_sizeContributionContributorName_Inverse;
+    public final Resource Diagram_Visualisations_sizeContributionDefaultMax;
+    public final Resource Diagram_Visualisations_sizeContributionDefaultMax_Inverse;
+    public final Resource Diagram_Visualisations_sizeContributionDefaultMin;
+    public final Resource Diagram_Visualisations_sizeContributionDefaultMin_Inverse;
+    public final Resource Diagram_Visualisations_sizeContributionDefaultSizeMap;
+    public final Resource Diagram_Visualisations_sizeContributionDefaultSizeMap_Inverse;
+    public final Resource Diagram_Visualisations_sizeContributionLabel;
+    public final Resource Diagram_Visualisations_sizeContributionLabel_Inverse;
+    public final Resource Diagram_Visualisations_sizeContributionModuleAttribute;
+    public final Resource Diagram_Visualisations_sizeContributionModuleAttribute_Inverse;
+    public final Resource Diagram_Visualisations_sizeContributionModuleName;
+    public final Resource Diagram_Visualisations_sizeContributionModuleName_Inverse;
+    public final Resource Diagram_Visualisations_sizeContributionUnit;
+    public final Resource Diagram_Visualisations_sizeContributionUnit_Inverse;
+    public final Resource Diagram_Visualisations_sizeContributionUseDefault;
+    public final Resource Diagram_Visualisations_sizeContributionUseDefault_Inverse;
+    public final Resource Diagram_Visualisations_sizeContributionUsed;
+    public final Resource Diagram_Visualisations_sizeContributionUsed_Inverse;
+    public final Resource Diagram_Visualisations_sizeContributionVariableBias;
+    public final Resource Diagram_Visualisations_sizeContributionVariableBias_Inverse;
+    public final Resource Diagram_Visualisations_sizeContributionVariableGain;
+    public final Resource Diagram_Visualisations_sizeContributionVariableGain_Inverse;
+    public final Resource Diagram_Visualisations_sizeContributions;
+    public final Resource Diagram_Visualisations_sizeContributions_Inverse;
     public final Resource Diagram_arrowLengthBias;
     public final Resource Diagram_arrowLengthBias_Inverse;
     public final Resource Diagram_arrowLengthGain;
@@ -46,6 +117,8 @@ public class DistrictNetworkResource {
     public final Resource Diagram_elementColoringGradientHue_Inverse;
     public final Resource Diagram_elementColoringGradientSaturation;
     public final Resource Diagram_elementColoringGradientSaturation_Inverse;
+    public final Resource Diagram_hasVisualisation;
+    public final Resource Diagram_hasVisualisation_Inverse;
     public final Resource Diagram_nodeScaleBias;
     public final Resource Diagram_nodeScaleBias_Inverse;
     public final Resource Diagram_nodeScaleGain;
@@ -110,6 +183,7 @@ public class DistrictNetworkResource {
     public final Resource Edge_ThicknessProperty_value_Inverse;
     public final Resource Element;
     public final Resource ElementColoringStyle;
+    public final Resource ElementSizingStyle;
     public final Resource ElevationRectangleStyle;
     public final Resource Functions;
     public final Resource Functions_arrowLengthPropertyEnumerationValues;
@@ -404,8 +478,79 @@ public class DistrictNetworkResource {
         public static final String Connection = "http://www.simantics.org/DistrictNetwork-1.0/Connection";
         public static final String ConnectionLineStyle = "http://www.simantics.org/DistrictNetwork-1.0/ConnectionLineStyle";
         public static final String Diagram = "http://www.simantics.org/DistrictNetwork-1.0/Diagram";
+        public static final String Diagram_DefaultPipeTechTypeId = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/DefaultPipeTechTypeId";
+        public static final String Diagram_DefaultPipeTechTypeId_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/DefaultPipeTechTypeId/Inverse";
         public static final String Diagram_MappedDiagram = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/MappedDiagram";
         public static final String Diagram_MappedFromDiagram = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/MappedFromDiagram";
+        public static final String Diagram_Visualisations = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations";
+        public static final String Diagram_Visualisations_ColorBarLocation = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/ColorBarLocation";
+        public static final String Diagram_Visualisations_ColorBarLocation_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/ColorBarLocation/Inverse";
+        public static final String Diagram_Visualisations_ColorBarSize = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/ColorBarSize";
+        public static final String Diagram_Visualisations_ColorBarSize_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/ColorBarSize/Inverse";
+        public static final String Diagram_Visualisations_ShowColorBarTicks = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/ShowColorBarTicks";
+        public static final String Diagram_Visualisations_ShowColorBarTicks_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/ShowColorBarTicks/Inverse";
+        public static final String Diagram_Visualisations_ShowColorBars = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/ShowColorBars";
+        public static final String Diagram_Visualisations_ShowColorBars_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/ShowColorBars/Inverse";
+        public static final String Diagram_Visualisations_ShowSizeBarTicks = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/ShowSizeBarTicks";
+        public static final String Diagram_Visualisations_ShowSizeBarTicks_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/ShowSizeBarTicks/Inverse";
+        public static final String Diagram_Visualisations_ShowSizeBars = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/ShowSizeBars";
+        public static final String Diagram_Visualisations_ShowSizeBars_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/ShowSizeBars/Inverse";
+        public static final String Diagram_Visualisations_SizeBarLocation = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/SizeBarLocation";
+        public static final String Diagram_Visualisations_SizeBarLocation_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/SizeBarLocation/Inverse";
+        public static final String Diagram_Visualisations_SizeBarSize = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/SizeBarSize";
+        public static final String Diagram_Visualisations_SizeBarSize_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/SizeBarSize/Inverse";
+        public static final String Diagram_Visualisations_colorContributionContributorName = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/colorContributionContributorName";
+        public static final String Diagram_Visualisations_colorContributionContributorName_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/colorContributionContributorName/Inverse";
+        public static final String Diagram_Visualisations_colorContributionDefaultColorMap = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/colorContributionDefaultColorMap";
+        public static final String Diagram_Visualisations_colorContributionDefaultColorMap_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/colorContributionDefaultColorMap/Inverse";
+        public static final String Diagram_Visualisations_colorContributionDefaultMax = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/colorContributionDefaultMax";
+        public static final String Diagram_Visualisations_colorContributionDefaultMax_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/colorContributionDefaultMax/Inverse";
+        public static final String Diagram_Visualisations_colorContributionDefaultMin = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/colorContributionDefaultMin";
+        public static final String Diagram_Visualisations_colorContributionDefaultMin_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/colorContributionDefaultMin/Inverse";
+        public static final String Diagram_Visualisations_colorContributionLabel = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/colorContributionLabel";
+        public static final String Diagram_Visualisations_colorContributionLabel_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/colorContributionLabel/Inverse";
+        public static final String Diagram_Visualisations_colorContributionModuleAttribute = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/colorContributionModuleAttribute";
+        public static final String Diagram_Visualisations_colorContributionModuleAttribute_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/colorContributionModuleAttribute/Inverse";
+        public static final String Diagram_Visualisations_colorContributionModuleName = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/colorContributionModuleName";
+        public static final String Diagram_Visualisations_colorContributionModuleName_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/colorContributionModuleName/Inverse";
+        public static final String Diagram_Visualisations_colorContributionUnit = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/colorContributionUnit";
+        public static final String Diagram_Visualisations_colorContributionUnit_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/colorContributionUnit/Inverse";
+        public static final String Diagram_Visualisations_colorContributionUseDefault = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/colorContributionUseDefault";
+        public static final String Diagram_Visualisations_colorContributionUseDefault_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/colorContributionUseDefault/Inverse";
+        public static final String Diagram_Visualisations_colorContributionUsed = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/colorContributionUsed";
+        public static final String Diagram_Visualisations_colorContributionUsed_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/colorContributionUsed/Inverse";
+        public static final String Diagram_Visualisations_colorContributionVariableBias = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/colorContributionVariableBias";
+        public static final String Diagram_Visualisations_colorContributionVariableBias_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/colorContributionVariableBias/Inverse";
+        public static final String Diagram_Visualisations_colorContributionVariableGain = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/colorContributionVariableGain";
+        public static final String Diagram_Visualisations_colorContributionVariableGain_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/colorContributionVariableGain/Inverse";
+        public static final String Diagram_Visualisations_colorContributions = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/colorContributions";
+        public static final String Diagram_Visualisations_colorContributions_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/colorContributions/Inverse";
+        public static final String Diagram_Visualisations_sizeContributionContributorName = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/sizeContributionContributorName";
+        public static final String Diagram_Visualisations_sizeContributionContributorName_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/sizeContributionContributorName/Inverse";
+        public static final String Diagram_Visualisations_sizeContributionDefaultMax = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/sizeContributionDefaultMax";
+        public static final String Diagram_Visualisations_sizeContributionDefaultMax_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/sizeContributionDefaultMax/Inverse";
+        public static final String Diagram_Visualisations_sizeContributionDefaultMin = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/sizeContributionDefaultMin";
+        public static final String Diagram_Visualisations_sizeContributionDefaultMin_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/sizeContributionDefaultMin/Inverse";
+        public static final String Diagram_Visualisations_sizeContributionDefaultSizeMap = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/sizeContributionDefaultSizeMap";
+        public static final String Diagram_Visualisations_sizeContributionDefaultSizeMap_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/sizeContributionDefaultSizeMap/Inverse";
+        public static final String Diagram_Visualisations_sizeContributionLabel = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/sizeContributionLabel";
+        public static final String Diagram_Visualisations_sizeContributionLabel_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/sizeContributionLabel/Inverse";
+        public static final String Diagram_Visualisations_sizeContributionModuleAttribute = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/sizeContributionModuleAttribute";
+        public static final String Diagram_Visualisations_sizeContributionModuleAttribute_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/sizeContributionModuleAttribute/Inverse";
+        public static final String Diagram_Visualisations_sizeContributionModuleName = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/sizeContributionModuleName";
+        public static final String Diagram_Visualisations_sizeContributionModuleName_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/sizeContributionModuleName/Inverse";
+        public static final String Diagram_Visualisations_sizeContributionUnit = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/sizeContributionUnit";
+        public static final String Diagram_Visualisations_sizeContributionUnit_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/sizeContributionUnit/Inverse";
+        public static final String Diagram_Visualisations_sizeContributionUseDefault = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/sizeContributionUseDefault";
+        public static final String Diagram_Visualisations_sizeContributionUseDefault_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/sizeContributionUseDefault/Inverse";
+        public static final String Diagram_Visualisations_sizeContributionUsed = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/sizeContributionUsed";
+        public static final String Diagram_Visualisations_sizeContributionUsed_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/sizeContributionUsed/Inverse";
+        public static final String Diagram_Visualisations_sizeContributionVariableBias = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/sizeContributionVariableBias";
+        public static final String Diagram_Visualisations_sizeContributionVariableBias_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/sizeContributionVariableBias/Inverse";
+        public static final String Diagram_Visualisations_sizeContributionVariableGain = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/sizeContributionVariableGain";
+        public static final String Diagram_Visualisations_sizeContributionVariableGain_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/sizeContributionVariableGain/Inverse";
+        public static final String Diagram_Visualisations_sizeContributions = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/sizeContributions";
+        public static final String Diagram_Visualisations_sizeContributions_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/sizeContributions/Inverse";
         public static final String Diagram_arrowLengthBias = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/arrowLengthBias";
         public static final String Diagram_arrowLengthBias_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/arrowLengthBias/Inverse";
         public static final String Diagram_arrowLengthGain = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/arrowLengthGain";
@@ -428,6 +573,8 @@ public class DistrictNetworkResource {
         public static final String Diagram_elementColoringGradientHue_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/elementColoringGradientHue/Inverse";
         public static final String Diagram_elementColoringGradientSaturation = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/elementColoringGradientSaturation";
         public static final String Diagram_elementColoringGradientSaturation_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/elementColoringGradientSaturation/Inverse";
+        public static final String Diagram_hasVisualisation = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/hasVisualisation";
+        public static final String Diagram_hasVisualisation_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/hasVisualisation/Inverse";
         public static final String Diagram_nodeScaleBias = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/nodeScaleBias";
         public static final String Diagram_nodeScaleBias_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/nodeScaleBias/Inverse";
         public static final String Diagram_nodeScaleGain = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/nodeScaleGain";
@@ -492,6 +639,7 @@ public class DistrictNetworkResource {
         public static final String Edge_ThicknessProperty_value_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Edge/ThicknessProperty/value/Inverse";
         public static final String Element = "http://www.simantics.org/DistrictNetwork-1.0/Element";
         public static final String ElementColoringStyle = "http://www.simantics.org/DistrictNetwork-1.0/ElementColoringStyle";
+        public static final String ElementSizingStyle = "http://www.simantics.org/DistrictNetwork-1.0/ElementSizingStyle";
         public static final String ElevationRectangleStyle = "http://www.simantics.org/DistrictNetwork-1.0/ElevationRectangleStyle";
         public static final String Functions = "http://www.simantics.org/DistrictNetwork-1.0/Functions";
         public static final String Functions_arrowLengthPropertyEnumerationValues = "http://www.simantics.org/DistrictNetwork-1.0/Functions/arrowLengthPropertyEnumerationValues";
@@ -796,8 +944,79 @@ public class DistrictNetworkResource {
         Connection = getResourceOrNull(graph, URIs.Connection);
         ConnectionLineStyle = getResourceOrNull(graph, URIs.ConnectionLineStyle);
         Diagram = getResourceOrNull(graph, URIs.Diagram);
+        Diagram_DefaultPipeTechTypeId = getResourceOrNull(graph, URIs.Diagram_DefaultPipeTechTypeId);
+        Diagram_DefaultPipeTechTypeId_Inverse = getResourceOrNull(graph, URIs.Diagram_DefaultPipeTechTypeId_Inverse);
         Diagram_MappedDiagram = getResourceOrNull(graph, URIs.Diagram_MappedDiagram);
         Diagram_MappedFromDiagram = getResourceOrNull(graph, URIs.Diagram_MappedFromDiagram);
+        Diagram_Visualisations = getResourceOrNull(graph, URIs.Diagram_Visualisations);
+        Diagram_Visualisations_ColorBarLocation = getResourceOrNull(graph, URIs.Diagram_Visualisations_ColorBarLocation);
+        Diagram_Visualisations_ColorBarLocation_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_ColorBarLocation_Inverse);
+        Diagram_Visualisations_ColorBarSize = getResourceOrNull(graph, URIs.Diagram_Visualisations_ColorBarSize);
+        Diagram_Visualisations_ColorBarSize_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_ColorBarSize_Inverse);
+        Diagram_Visualisations_ShowColorBarTicks = getResourceOrNull(graph, URIs.Diagram_Visualisations_ShowColorBarTicks);
+        Diagram_Visualisations_ShowColorBarTicks_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_ShowColorBarTicks_Inverse);
+        Diagram_Visualisations_ShowColorBars = getResourceOrNull(graph, URIs.Diagram_Visualisations_ShowColorBars);
+        Diagram_Visualisations_ShowColorBars_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_ShowColorBars_Inverse);
+        Diagram_Visualisations_ShowSizeBarTicks = getResourceOrNull(graph, URIs.Diagram_Visualisations_ShowSizeBarTicks);
+        Diagram_Visualisations_ShowSizeBarTicks_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_ShowSizeBarTicks_Inverse);
+        Diagram_Visualisations_ShowSizeBars = getResourceOrNull(graph, URIs.Diagram_Visualisations_ShowSizeBars);
+        Diagram_Visualisations_ShowSizeBars_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_ShowSizeBars_Inverse);
+        Diagram_Visualisations_SizeBarLocation = getResourceOrNull(graph, URIs.Diagram_Visualisations_SizeBarLocation);
+        Diagram_Visualisations_SizeBarLocation_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_SizeBarLocation_Inverse);
+        Diagram_Visualisations_SizeBarSize = getResourceOrNull(graph, URIs.Diagram_Visualisations_SizeBarSize);
+        Diagram_Visualisations_SizeBarSize_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_SizeBarSize_Inverse);
+        Diagram_Visualisations_colorContributionContributorName = getResourceOrNull(graph, URIs.Diagram_Visualisations_colorContributionContributorName);
+        Diagram_Visualisations_colorContributionContributorName_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_colorContributionContributorName_Inverse);
+        Diagram_Visualisations_colorContributionDefaultColorMap = getResourceOrNull(graph, URIs.Diagram_Visualisations_colorContributionDefaultColorMap);
+        Diagram_Visualisations_colorContributionDefaultColorMap_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_colorContributionDefaultColorMap_Inverse);
+        Diagram_Visualisations_colorContributionDefaultMax = getResourceOrNull(graph, URIs.Diagram_Visualisations_colorContributionDefaultMax);
+        Diagram_Visualisations_colorContributionDefaultMax_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_colorContributionDefaultMax_Inverse);
+        Diagram_Visualisations_colorContributionDefaultMin = getResourceOrNull(graph, URIs.Diagram_Visualisations_colorContributionDefaultMin);
+        Diagram_Visualisations_colorContributionDefaultMin_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_colorContributionDefaultMin_Inverse);
+        Diagram_Visualisations_colorContributionLabel = getResourceOrNull(graph, URIs.Diagram_Visualisations_colorContributionLabel);
+        Diagram_Visualisations_colorContributionLabel_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_colorContributionLabel_Inverse);
+        Diagram_Visualisations_colorContributionModuleAttribute = getResourceOrNull(graph, URIs.Diagram_Visualisations_colorContributionModuleAttribute);
+        Diagram_Visualisations_colorContributionModuleAttribute_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_colorContributionModuleAttribute_Inverse);
+        Diagram_Visualisations_colorContributionModuleName = getResourceOrNull(graph, URIs.Diagram_Visualisations_colorContributionModuleName);
+        Diagram_Visualisations_colorContributionModuleName_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_colorContributionModuleName_Inverse);
+        Diagram_Visualisations_colorContributionUnit = getResourceOrNull(graph, URIs.Diagram_Visualisations_colorContributionUnit);
+        Diagram_Visualisations_colorContributionUnit_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_colorContributionUnit_Inverse);
+        Diagram_Visualisations_colorContributionUseDefault = getResourceOrNull(graph, URIs.Diagram_Visualisations_colorContributionUseDefault);
+        Diagram_Visualisations_colorContributionUseDefault_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_colorContributionUseDefault_Inverse);
+        Diagram_Visualisations_colorContributionUsed = getResourceOrNull(graph, URIs.Diagram_Visualisations_colorContributionUsed);
+        Diagram_Visualisations_colorContributionUsed_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_colorContributionUsed_Inverse);
+        Diagram_Visualisations_colorContributionVariableBias = getResourceOrNull(graph, URIs.Diagram_Visualisations_colorContributionVariableBias);
+        Diagram_Visualisations_colorContributionVariableBias_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_colorContributionVariableBias_Inverse);
+        Diagram_Visualisations_colorContributionVariableGain = getResourceOrNull(graph, URIs.Diagram_Visualisations_colorContributionVariableGain);
+        Diagram_Visualisations_colorContributionVariableGain_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_colorContributionVariableGain_Inverse);
+        Diagram_Visualisations_colorContributions = getResourceOrNull(graph, URIs.Diagram_Visualisations_colorContributions);
+        Diagram_Visualisations_colorContributions_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_colorContributions_Inverse);
+        Diagram_Visualisations_sizeContributionContributorName = getResourceOrNull(graph, URIs.Diagram_Visualisations_sizeContributionContributorName);
+        Diagram_Visualisations_sizeContributionContributorName_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_sizeContributionContributorName_Inverse);
+        Diagram_Visualisations_sizeContributionDefaultMax = getResourceOrNull(graph, URIs.Diagram_Visualisations_sizeContributionDefaultMax);
+        Diagram_Visualisations_sizeContributionDefaultMax_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_sizeContributionDefaultMax_Inverse);
+        Diagram_Visualisations_sizeContributionDefaultMin = getResourceOrNull(graph, URIs.Diagram_Visualisations_sizeContributionDefaultMin);
+        Diagram_Visualisations_sizeContributionDefaultMin_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_sizeContributionDefaultMin_Inverse);
+        Diagram_Visualisations_sizeContributionDefaultSizeMap = getResourceOrNull(graph, URIs.Diagram_Visualisations_sizeContributionDefaultSizeMap);
+        Diagram_Visualisations_sizeContributionDefaultSizeMap_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_sizeContributionDefaultSizeMap_Inverse);
+        Diagram_Visualisations_sizeContributionLabel = getResourceOrNull(graph, URIs.Diagram_Visualisations_sizeContributionLabel);
+        Diagram_Visualisations_sizeContributionLabel_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_sizeContributionLabel_Inverse);
+        Diagram_Visualisations_sizeContributionModuleAttribute = getResourceOrNull(graph, URIs.Diagram_Visualisations_sizeContributionModuleAttribute);
+        Diagram_Visualisations_sizeContributionModuleAttribute_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_sizeContributionModuleAttribute_Inverse);
+        Diagram_Visualisations_sizeContributionModuleName = getResourceOrNull(graph, URIs.Diagram_Visualisations_sizeContributionModuleName);
+        Diagram_Visualisations_sizeContributionModuleName_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_sizeContributionModuleName_Inverse);
+        Diagram_Visualisations_sizeContributionUnit = getResourceOrNull(graph, URIs.Diagram_Visualisations_sizeContributionUnit);
+        Diagram_Visualisations_sizeContributionUnit_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_sizeContributionUnit_Inverse);
+        Diagram_Visualisations_sizeContributionUseDefault = getResourceOrNull(graph, URIs.Diagram_Visualisations_sizeContributionUseDefault);
+        Diagram_Visualisations_sizeContributionUseDefault_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_sizeContributionUseDefault_Inverse);
+        Diagram_Visualisations_sizeContributionUsed = getResourceOrNull(graph, URIs.Diagram_Visualisations_sizeContributionUsed);
+        Diagram_Visualisations_sizeContributionUsed_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_sizeContributionUsed_Inverse);
+        Diagram_Visualisations_sizeContributionVariableBias = getResourceOrNull(graph, URIs.Diagram_Visualisations_sizeContributionVariableBias);
+        Diagram_Visualisations_sizeContributionVariableBias_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_sizeContributionVariableBias_Inverse);
+        Diagram_Visualisations_sizeContributionVariableGain = getResourceOrNull(graph, URIs.Diagram_Visualisations_sizeContributionVariableGain);
+        Diagram_Visualisations_sizeContributionVariableGain_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_sizeContributionVariableGain_Inverse);
+        Diagram_Visualisations_sizeContributions = getResourceOrNull(graph, URIs.Diagram_Visualisations_sizeContributions);
+        Diagram_Visualisations_sizeContributions_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_sizeContributions_Inverse);
         Diagram_arrowLengthBias = getResourceOrNull(graph, URIs.Diagram_arrowLengthBias);
         Diagram_arrowLengthBias_Inverse = getResourceOrNull(graph, URIs.Diagram_arrowLengthBias_Inverse);
         Diagram_arrowLengthGain = getResourceOrNull(graph, URIs.Diagram_arrowLengthGain);
@@ -820,6 +1039,8 @@ public class DistrictNetworkResource {
         Diagram_elementColoringGradientHue_Inverse = getResourceOrNull(graph, URIs.Diagram_elementColoringGradientHue_Inverse);
         Diagram_elementColoringGradientSaturation = getResourceOrNull(graph, URIs.Diagram_elementColoringGradientSaturation);
         Diagram_elementColoringGradientSaturation_Inverse = getResourceOrNull(graph, URIs.Diagram_elementColoringGradientSaturation_Inverse);
+        Diagram_hasVisualisation = getResourceOrNull(graph, URIs.Diagram_hasVisualisation);
+        Diagram_hasVisualisation_Inverse = getResourceOrNull(graph, URIs.Diagram_hasVisualisation_Inverse);
         Diagram_nodeScaleBias = getResourceOrNull(graph, URIs.Diagram_nodeScaleBias);
         Diagram_nodeScaleBias_Inverse = getResourceOrNull(graph, URIs.Diagram_nodeScaleBias_Inverse);
         Diagram_nodeScaleGain = getResourceOrNull(graph, URIs.Diagram_nodeScaleGain);
@@ -884,6 +1105,7 @@ public class DistrictNetworkResource {
         Edge_ThicknessProperty_value_Inverse = getResourceOrNull(graph, URIs.Edge_ThicknessProperty_value_Inverse);
         Element = getResourceOrNull(graph, URIs.Element);
         ElementColoringStyle = getResourceOrNull(graph, URIs.ElementColoringStyle);
+        ElementSizingStyle = getResourceOrNull(graph, URIs.ElementSizingStyle);
         ElevationRectangleStyle = getResourceOrNull(graph, URIs.ElevationRectangleStyle);
         Functions = getResourceOrNull(graph, URIs.Functions);
         Functions_arrowLengthPropertyEnumerationValues = getResourceOrNull(graph, URIs.Functions_arrowLengthPropertyEnumerationValues);
index 71ba32e59882e6854754d24143df227cad847421..9399017efb7fe373f6488b058b2098c30fa4bc58 100644 (file)
@@ -38,7 +38,8 @@ Require-Bundle: org.eclipse.e4.ui.model.workbench;bundle-version="1.1.100.v20150
  org.simantics.maps.elevation.server,
  org.eclipse.e4.core.services,
  org.eclipse.osgi.services;bundle-version="3.6.0",
- org.eclipse.nebula.widgets.nattable.core
+ org.eclipse.nebula.widgets.nattable.core,
+ org.simantics.district.imports
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Import-Package: javax.annotation;version="1.0.0";resolution:=optional,
   javax.inject;version="1.0.0"
index c4357ea45278e790aa33415d4d21db8b04012f7a..89afdc5d9435258dd03c497252f391a7527069c9 100644 (file)
@@ -16,6 +16,7 @@
     <elements xsi:type="commands:Command" xmi:id="_CLKOUHVvEemS_rRAHnCQSw" elementId="org.simantics.district.network.ui.command.changeroutepointtovertex" commandName="Change Route Point to Vertex"/>
     <elements xsi:type="commands:Command" xmi:id="_Ee0TAHVvEemS_rRAHnCQSw" elementId="org.simantics.district.network.ui.command.changevertextoroutepoint" commandName="Change Vertex to Route Point"/>
     <elements xsi:type="commands:Command" xmi:id="_QcEKQIAGEemKlokjSaREFQ" elementId="org.simantics.district.network.ui.command.importcsv" commandName="Import CSV"/>
+    <elements xsi:type="commands:Command" xmi:id="_VWtY8LqWEemcscVaZzEyWw" elementId="org.simantics.district.network.ui.command.importtechtypecsv" commandName="Import Tech Type CSV"/>
   </fragments>
   <fragments xsi:type="fragment:StringModelFragment" xmi:id="_Js7rUMMAEea1mdgpHNVHMA" featurename="menuContributions" parentElementId="xpath:/">
     <elements xsi:type="menu:MenuContribution" xmi:id="_T-jiEN8NEeaigNyzMJBOrg" elementId="org.simantics.district.network.ui.menucontribution.districtDiagramPopup" parentId="#DistrictDiagramPopup">
@@ -48,5 +49,6 @@
     <elements xsi:type="commands:Handler" xmi:id="_F9vvIHVvEemS_rRAHnCQSw" elementId="org.simantics.district.network.ui.handler.7" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.contributions.ChangeRoutePointToVertexHandler" command="_CLKOUHVvEemS_rRAHnCQSw"/>
     <elements xsi:type="commands:Handler" xmi:id="_H7TA8HVvEemS_rRAHnCQSw" elementId="org.simantics.district.network.ui.handler.8" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.contributions.ChangeVertexToRoutePointHandler" command="_Ee0TAHVvEemS_rRAHnCQSw"/>
     <elements xsi:type="commands:Handler" xmi:id="_akE8EIAGEemKlokjSaREFQ" elementId="org.simantics.district.network.ui.handler.9" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.table.ImportCSVHandler" command="_QcEKQIAGEemKlokjSaREFQ"/>
+    <elements xsi:type="commands:Handler" xmi:id="_XjbIILqWEemcscVaZzEyWw" elementId="org.simantics.district.network.ui.handler.10" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.table.ImportTechTypeCSVHandler" command="_VWtY8LqWEemcscVaZzEyWw"/>
   </fragments>
 </fragment:ModelFragments>
index 1e596f545e1f91dedc85d23e841e451420f434a0..b8a712d8d12f7e06113e75bbcad20c7ce77c99d4 100644 (file)
             restorable="true"
             allowMultiple="false">
       </e4view>
+      <e4view
+            class="org.simantics.district.network.ui.techtype.table.TechTypeTableView"
+            icon="platform:/plugin/com.famfamfam.silk/icons/table_edit.png"
+            id="org.simantics.district.network.ui.techtype.table.techtypeTableView"
+            name="Tech Type Table"
+            restorable="true"
+            allowMultiple="false">
+      </e4view>
+      <e4view
+            class="org.simantics.district.network.ui.visualisations.DynamicVisualisationsView"
+            icon="platform:/plugin/com.famfamfam.silk/icons/table_edit.png"
+            id="org.simantics.district.network.ui.visualisations.dynamicVisualisationsView"
+            name="District Visualisations"
+            restorable="true"
+            allowMultiple="false">
+      </e4view>
    </extension>
   <extension
          point="org.eclipse.ui.preferencePages">
index 68b7aa791407b2efdfa68a2065a919baf4490fef..cc5b24e1652e69427b1c6a34a919f6e869cbc044 100644 (file)
@@ -2,6 +2,7 @@ package org.simantics.district.network.ui;
 
 import java.awt.Color;
 import java.awt.geom.AffineTransform;
+import java.util.Map;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Consumer;
 import java.util.function.Supplier;
@@ -15,8 +16,13 @@ import org.simantics.db.procedure.Listener;
 import org.simantics.diagram.ui.DiagramModelHints;
 import org.simantics.district.network.DistrictNetworkUtil;
 import org.simantics.district.network.ui.participants.DNPointerInteractor;
+import org.simantics.district.network.ui.participants.DynamicVisualisationContributionsParticipant;
 import org.simantics.district.network.ui.participants.ElevationServerParticipant;
 import org.simantics.district.network.ui.participants.MapRulerPainter;
+import org.simantics.district.network.visualisations.model.ColorBarOptions;
+import org.simantics.district.network.visualisations.model.DynamicColorContribution;
+import org.simantics.district.network.visualisations.model.DynamicSizeContribution;
+import org.simantics.district.network.visualisations.model.SizeBarOptions;
 import org.simantics.g2d.canvas.ICanvasContext;
 import org.simantics.g2d.canvas.impl.CanvasContext;
 import org.simantics.g2d.diagram.handler.PickRequest.PickFilter;
@@ -34,9 +40,12 @@ import org.simantics.maps.MapScalingTransform;
 import org.simantics.maps.eclipse.MapPainter;
 import org.simantics.maps.sg.commands.MapCommands;
 import org.simantics.modeling.ui.diagramEditor.DiagramViewer;
+import org.simantics.scenegraph.g2d.events.command.Command;
 import org.simantics.scenegraph.g2d.events.command.CommandEvent;
 import org.simantics.scenegraph.g2d.events.command.Commands;
 import org.simantics.utils.datastructures.hints.IHintContext;
+import org.simantics.utils.datastructures.hints.IHintContext.Key;
+import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -57,6 +66,7 @@ public class DistrictDiagramViewer extends DiagramViewer {
         
         ctx.add(new NetworkDrawingParticipant(tr));
         ctx.add(new ElevationServerParticipant(tr));
+        ctx.add(new DynamicVisualisationContributionsParticipant(tr));
     }
     
     protected String getPopupId() {
@@ -105,6 +115,10 @@ public class DistrictDiagramViewer extends DiagramViewer {
         // super.loadPageSettings() does async-db-operations
         setupDrawMapEnabled();
         setupBackgroundColor();
+        setupColoringObjects();
+        setupColorBarOptions();
+        setupSizingObjects();
+        setupSizeBarOptions();
     }
     
     private void setupDrawMapEnabled() {
@@ -118,7 +132,7 @@ public class DistrictDiagramViewer extends DiagramViewer {
                 result -> queueBackgroundColorChangeEvent(result),
                 () -> DistrictDiagramViewer.this.isDisposed()));
     }
-    
+
     private void queueBackgroundColorChangeEvent(RGB.Integer result) {
         if (result != null) {
             Color backgroundColor = new Color(result.red, result.green, result.blue);
@@ -127,6 +141,72 @@ public class DistrictDiagramViewer extends DiagramViewer {
         }
     }
 
+    private void setupColoringObjects() {
+        sessionContext.getSession().asyncRequest(new ColoringObjectsRequest(getInputResource()), new ColoringObjectsListener(
+                result -> queueColoringObjectsChangeEvent(result),
+                () -> DistrictDiagramViewer.this.isDisposed()));
+    }
+
+    
+    private void setupColorBarOptions() {
+        sessionContext.getSession().asyncRequest(new ColorBarOptionsRequest(getInputResource()), new ColorBarOptionsListener(
+                result -> queueColorBarOptionsChangeEvent(result),
+                () -> DistrictDiagramViewer.this.isDisposed()));
+    }
+
+    private void setupSizingObjects() {
+        sessionContext.getSession().asyncRequest(new SizingObjectsRequest(getInputResource()), new SizingObjectsListener(
+                result -> queueSizingObjectsChangeEvent(result),
+                () -> DistrictDiagramViewer.this.isDisposed()));
+    }
+
+    
+    private void setupSizeBarOptions() {
+        sessionContext.getSession().asyncRequest(new SizeBarOptionsRequest(getInputResource()), new SizeBarOptionsListener(
+                result -> queueSizeBarOptionsChangeEvent(result),
+                () -> DistrictDiagramViewer.this.isDisposed()));
+    }
+    
+    public static final Key KEY_MAP_COLOR_BAR_OPTIONS = new KeyOf(ColorBarOptions.class, "colorBarOptions");
+    public static final Command MAP_COLOR_BAR_OPTIONS_CHANGE = new Command("colorBarOptionsChange");
+    public static final Key KEY_MAP_SIZE_BAR_OPTIONS = new KeyOf(SizeBarOptions.class, "sizeBarOptions");
+    public static final Command MAP_SIZE_BAR_OPTIONS_CHANGE = new Command("sizeBarOptionsChange");
+    
+    public static final Key KEY_MAP_COLORING_OBJECTS = new KeyOf(Map.class, "coloringObjects");
+    public static final Command MAP_COLORING_OBJECTS_CHANGE = new Command("coloringObjectsChange");
+    
+    public static final Key KEY_MAP_SIZING_OBJECTS = new KeyOf(Map.class, "sizingObjects");
+    public static final Command MAP_SIZING_OBJECTS_CHANGE = new Command("sizingObjectsChange");
+
+    
+    private void queueColoringObjectsChangeEvent(Map<String, DynamicColorContribution> result) {
+        if (result != null) {
+            canvasContext.getDefaultHintContext().setHint(KEY_MAP_COLORING_OBJECTS, result);
+            canvasContext.getEventQueue().queueEvent(new CommandEvent(canvasContext, System.currentTimeMillis(), MAP_COLORING_OBJECTS_CHANGE));
+        }
+    }
+    
+    private void queueColorBarOptionsChangeEvent(ColorBarOptions result) {
+        if (result != null) {
+            canvasContext.getDefaultHintContext().setHint(KEY_MAP_COLOR_BAR_OPTIONS, result);
+            canvasContext.getEventQueue().queueEvent(new CommandEvent(canvasContext, System.currentTimeMillis(), MAP_COLOR_BAR_OPTIONS_CHANGE));
+        }
+    }
+
+    private void queueSizingObjectsChangeEvent(Map<String, DynamicSizeContribution> result) {
+        if (result != null) {
+            canvasContext.getDefaultHintContext().setHint(KEY_MAP_SIZING_OBJECTS, result);
+            canvasContext.getEventQueue().queueEvent(new CommandEvent(canvasContext, System.currentTimeMillis(), MAP_SIZING_OBJECTS_CHANGE));
+        }
+    }
+    
+    private void queueSizeBarOptionsChangeEvent(SizeBarOptions result) {
+        if (result != null) {
+            canvasContext.getDefaultHintContext().setHint(KEY_MAP_SIZE_BAR_OPTIONS, result);
+            canvasContext.getEventQueue().queueEvent(new CommandEvent(canvasContext, System.currentTimeMillis(), MAP_SIZE_BAR_OPTIONS_CHANGE));
+        }
+    }
+    
     private static class DrawMapEnabledRequest extends UnaryRead<Resource, Boolean> {
 
         public DrawMapEnabledRequest(Resource diagram) {
@@ -206,4 +286,164 @@ public class DistrictDiagramViewer extends DiagramViewer {
             return isDisposed.get();
         }
     }
+
+    private static class ColorBarOptionsRequest extends UnaryRead<Resource, ColorBarOptions> {
+
+        public ColorBarOptionsRequest(Resource diagram) {
+            super(diagram);
+        }
+
+        @Override
+        public ColorBarOptions perform(ReadGraph graph) throws DatabaseException {
+            return DistrictNetworkUtil.colorBarOptions(graph, parameter);
+        }
+    }
+
+    private static class ColoringObjectsRequest extends UnaryRead<Resource, Map<String,DynamicColorContribution>> {
+
+        public ColoringObjectsRequest(Resource diagram) {
+            super(diagram);
+        }
+
+        @Override
+        public Map<String, DynamicColorContribution> perform(ReadGraph graph) throws DatabaseException {
+            return DistrictNetworkUtil.colorContributions(graph, parameter);
+        }
+    }
+    
+    private static class ColoringObjectsListener implements Listener<Map<String,DynamicColorContribution>> {
+
+        private static final Logger LOGGER = LoggerFactory.getLogger(DrawMapEnabledListener.class);
+
+        private Consumer<Map<String,DynamicColorContribution>> callback;
+        private Supplier<Boolean> isDisposed;
+
+        public ColoringObjectsListener(Consumer<Map<String,DynamicColorContribution>> callback, Supplier<Boolean> isDisposed) {
+            this.callback = callback;
+            this.isDisposed = isDisposed;
+        }
+
+        @Override
+        public void execute(Map<String,DynamicColorContribution> result) {
+            callback.accept(result);
+        }
+
+        @Override
+        public void exception(Throwable t) {
+            LOGGER.error("Could not listen ColorBarOptions", t);
+        }
+
+        @Override
+        public boolean isDisposed() {
+            return isDisposed.get();
+        }
+    }
+    
+    private static class ColorBarOptionsListener implements Listener<ColorBarOptions> {
+
+        private static final Logger LOGGER = LoggerFactory.getLogger(DrawMapEnabledListener.class);
+
+        private Consumer<ColorBarOptions> callback;
+        private Supplier<Boolean> isDisposed;
+
+        public ColorBarOptionsListener(Consumer<ColorBarOptions> callback, Supplier<Boolean> isDisposed) {
+            this.callback = callback;
+            this.isDisposed = isDisposed;
+        }
+
+        @Override
+        public void execute(ColorBarOptions result) {
+            callback.accept(result);
+        }
+
+        @Override
+        public void exception(Throwable t) {
+            LOGGER.error("Could not listen ColorBarOptions", t);
+        }
+
+        @Override
+        public boolean isDisposed() {
+            return isDisposed.get();
+        }
+    }
+    
+    private static class SizeBarOptionsRequest extends UnaryRead<Resource, SizeBarOptions> {
+
+        public SizeBarOptionsRequest(Resource diagram) {
+            super(diagram);
+        }
+
+        @Override
+        public SizeBarOptions perform(ReadGraph graph) throws DatabaseException {
+            return DistrictNetworkUtil.sizeBarOptions(graph, parameter);
+        }
+    }
+
+    private static class SizeBarOptionsListener implements Listener<SizeBarOptions> {
+
+        private static final Logger LOGGER = LoggerFactory.getLogger(DrawMapEnabledListener.class);
+
+        private Consumer<SizeBarOptions> callback;
+        private Supplier<Boolean> isDisposed;
+
+        public SizeBarOptionsListener(Consumer<SizeBarOptions> callback, Supplier<Boolean> isDisposed) {
+            this.callback = callback;
+            this.isDisposed = isDisposed;
+        }
+
+        @Override
+        public void execute(SizeBarOptions result) {
+            callback.accept(result);
+        }
+
+        @Override
+        public void exception(Throwable t) {
+            LOGGER.error("Could not listen SizeBarOptions", t);
+        }
+
+        @Override
+        public boolean isDisposed() {
+            return isDisposed.get();
+        }
+    }
+    
+    private static class SizingObjectsRequest extends UnaryRead<Resource, Map<String, DynamicSizeContribution>> {
+
+        public SizingObjectsRequest(Resource diagram) {
+            super(diagram);
+        }
+
+        @Override
+        public Map<String, DynamicSizeContribution> perform(ReadGraph graph) throws DatabaseException {
+            return DistrictNetworkUtil.sizeContributions(graph, parameter);
+        }
+    }
+    
+    private static class SizingObjectsListener implements Listener<Map<String,DynamicSizeContribution>> {
+
+        private static final Logger LOGGER = LoggerFactory.getLogger(DrawMapEnabledListener.class);
+
+        private Consumer<Map<String,DynamicSizeContribution>> callback;
+        private Supplier<Boolean> isDisposed;
+
+        public SizingObjectsListener(Consumer<Map<String, DynamicSizeContribution>> callback, Supplier<Boolean> isDisposed) {
+            this.callback = callback;
+            this.isDisposed = isDisposed;
+        }
+
+        @Override
+        public void execute(Map<String, DynamicSizeContribution> result) {
+            callback.accept(result);
+        }
+
+        @Override
+        public void exception(Throwable t) {
+            LOGGER.error("Could not listen ColorBarOptions", t);
+        }
+
+        @Override
+        public boolean isDisposed() {
+            return isDisposed.get();
+        }
+    }
 }
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DynamicVisualisationContributionsNode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DynamicVisualisationContributionsNode.java
new file mode 100644 (file)
index 0000000..53d7862
--- /dev/null
@@ -0,0 +1,344 @@
+package org.simantics.district.network.ui.nodes;
+
+import java.awt.AlphaComposite;
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.Graphics2D;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Ellipse2D;
+import java.awt.geom.Rectangle2D;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.simantics.district.network.visualisations.model.ColorBarOptions;
+import org.simantics.district.network.visualisations.model.ColorBarOptions.ColorBarsLocation;
+import org.simantics.district.network.visualisations.model.ColorBarOptions.ColorBarsSize;
+import org.simantics.district.network.visualisations.model.DynamicColorContribution;
+import org.simantics.district.network.visualisations.model.DynamicColorMap;
+import org.simantics.district.network.visualisations.model.DynamicColorMap.RGBIntensity;
+import org.simantics.district.network.visualisations.model.DynamicSizeContribution;
+import org.simantics.district.network.visualisations.model.DynamicSizeMap;
+import org.simantics.district.network.visualisations.model.SizeBarOptions;
+import org.simantics.district.network.visualisations.model.SizeBarOptions.SizeBarsLocation;
+import org.simantics.district.network.visualisations.model.SizeBarOptions.SizeBarsSize;
+import org.simantics.scenegraph.g2d.G2DNode;
+import org.simantics.scenegraph.utils.DPIUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DynamicVisualisationContributionsNode extends G2DNode {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(DynamicVisualisationContributionsNode.class);
+
+    public static final String ID = "dynamicVisualisationContributionsNode";
+    
+    private static final long serialVersionUID = 7400966702826774761L;
+
+    protected boolean enabled = true;
+
+    private Map<String, DynamicColorContribution> dynamicColoringContributions;
+    private Map<String, DynamicSizeContribution> dynamicSizingContributions;
+    
+    private ColorBarOptions colorBarsOptions = ColorBarOptions.useDefault();
+    private SizeBarOptions sizeBarsOptions = SizeBarOptions.useDefault();
+
+    @Override
+    public void render(Graphics2D g2d) {
+        if (!enabled)
+            return;
+        
+        AffineTransform ot = g2d.getTransform();
+        Color oldColor = g2d.getColor();
+        
+        try {
+            g2d.transform(transform);
+            g2d.setTransform(new AffineTransform());
+            
+            Rectangle2D bounds = g2d.getClipBounds();
+            if (bounds == null)
+                return; // FIXME
+            
+            renderColors(g2d);
+            renderSizes(g2d);
+        } finally {
+            g2d.setColor(oldColor);
+            g2d.setTransform(ot);
+        }
+    }
+
+    private double colorBarBoxWidth = 300;
+    private double colorBarBoxHeight = 50;
+    private double colorBarBoxPadding = 20;
+
+    private void renderColors(Graphics2D g2d) {
+        if (colorBarsOptions == null || !colorBarsOptions.isShowColorBars()) {
+            return;
+        }
+        ColorBarsLocation location = colorBarsOptions.getLocation();
+        ColorBarsSize size = colorBarsOptions.getSize();
+        double colorBarBoxLeft = getColorBarBoxLeft(g2d, location, size);
+        double colorBarBoxTopInitial = getColorBarBoxTop(g2d, location, size);
+        double colorBarBoxWidth = getColorBarBoxWidth(size);
+        double colorBarBoxHeight = getColorBarBoxHeight(size);
+        
+        Rectangle2D bounds = g2d.getClipBounds();
+        if (bounds == null)
+            return; // FIXME
+        
+        int i = 0;
+        
+        if (dynamicColoringContributions != null) {
+            for (Entry<String, DynamicColorContribution> object : dynamicColoringContributions.entrySet()) {
+                DynamicColorContribution cc = object.getValue();
+                
+                if (!cc.isUsed())
+                    break;
+                
+                double min = cc.getDefaultMin();
+                double max = cc.getDefaultMax();
+                String unit = cc.getUnit();
+                String label = cc.getLabel();
+                
+                DynamicColorMap map = cc.getDefaultColorMap();
+                
+                double colorBarBoxTop = (colorBarBoxTopInitial + (colorBarBoxHeight * i));
+                i++;
+
+                g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
+                g2d.setColor(new Color(0.9f, 0.9f, 0.9f, 0.95f));
+                
+                Rectangle2D vertical = new Rectangle2D.Double(colorBarBoxLeft, colorBarBoxTop, colorBarBoxWidth, colorBarBoxHeight);
+                g2d.fill(vertical);
+                
+                double colorVerticalLeft = colorBarBoxLeft + 5;
+                double colorVerticalTop = colorBarBoxTop + 15;
+                double colorVerticalHeigth = colorBarBoxHeight - 30;
+                List<RGBIntensity> intensities = map.getIntensities();
+                double colorVerticalWidth = (colorBarBoxWidth - 10) / intensities.size();
+                
+                Font rulerFont = new Font("Tahoma", Font.PLAIN, DPIUtil.upscale(9));
+                g2d.setFont(rulerFont);
+                g2d.setColor(Color.BLACK);
+                
+                String str = Double.toString(max);
+                g2d.drawString(str, (int)(colorBarBoxLeft + colorBarBoxWidth - 30), (int)(colorBarBoxTop  + colorBarBoxHeight));
+                
+                str = Double.toString(min);
+                g2d.drawString(str, (int)colorBarBoxLeft + 1, (int)(colorBarBoxTop + colorBarBoxHeight));
+                
+                
+                for (RGBIntensity intensity : intensities) {
+                    
+                    g2d.setColor(new Color((float)intensity.getRed(), (float)intensity.getGreen(), (float)intensity.getBlue(), 1f));
+                    Rectangle2D colorVertical = new Rectangle2D.Double(colorVerticalLeft, colorVerticalTop, colorVerticalWidth, colorVerticalHeigth);
+                    g2d.fill(colorVertical);
+                    colorVerticalLeft = colorVerticalLeft + colorVerticalWidth;
+                }
+                g2d.setColor(Color.BLACK);
+                str = object.getKey() + " - " + label + " [" + unit + "]";
+                g2d.drawString(str, (int)colorBarBoxLeft + 5, (int)colorBarBoxTop + 10);
+            }
+        }
+    }
+
+    private double getColorBarBoxTop(Graphics2D g2d, ColorBarsLocation location, ColorBarsSize size) {
+        Rectangle2D bounds = g2d.getClipBounds();
+        if (bounds == null)
+            throw new IllegalStateException();
+        switch (location) {
+            case NORTH: {
+                return colorBarBoxPadding;
+            }
+            case SOUTH: {
+                return bounds.getMaxY() - colorBarBoxPadding;
+            }
+            case EAST:
+            case WEST: {
+                return (bounds.getMaxY() / 2) - (getColorBarBoxHeight(size) / 2);
+            }
+            default:
+                return 0;
+        }
+    }
+    
+    private double getColorBarBoxLeft(Graphics2D g2d, ColorBarsLocation location, ColorBarsSize size) {
+        Rectangle2D bounds = g2d.getClipBounds();
+        if (bounds == null)
+            throw new IllegalStateException();
+        switch (location) {
+            case EAST: {
+                double right = bounds.getMaxX() - colorBarBoxPadding;
+                return right - getColorBarBoxWidth(size);
+            }
+            case WEST: {
+                return colorBarBoxPadding;
+            }
+            case NORTH:
+            case SOUTH: {
+                double left = (bounds.getMaxX() / 2) - (getColorBarBoxWidth(size) / 2);
+                return left;
+            }
+            default:
+                return 0;
+        }
+    }
+
+    private double getColorBarBoxWidth(ColorBarsSize size) {
+        return size.getSize() * colorBarBoxWidth;
+    }
+
+    private double getColorBarBoxHeight(ColorBarsSize size) {
+        return size.getSize() * colorBarBoxHeight;
+    }
+
+    private void renderSizes(Graphics2D g2d) {
+        if (sizeBarsOptions == null || !sizeBarsOptions.isShowSizeBars()) {
+            return;
+        }
+        SizeBarsLocation location = sizeBarsOptions.getLocation();
+        SizeBarsSize sizeb = sizeBarsOptions.getSize();
+        double sizeBarBoxLeft = getSizeBarBoxLeft(g2d, location, sizeb);
+        double sizeBarBoxTopInitial = getSizeBarBoxTop(g2d, location, sizeb);
+        double sizeBarBoxWidth = getSizeBarBoxWidth(sizeb);
+        double sizeBarBoxHeight = getSizeBarBoxHeight(sizeb);
+        
+        Rectangle2D bounds = g2d.getClipBounds();
+        if (bounds == null)
+            return; // FIXME
+        
+        int i = 0;
+        
+        for (Entry<String, DynamicSizeContribution> object : dynamicSizingContributions.entrySet()) {
+            DynamicSizeContribution cc = object.getValue();
+            
+            double min = cc.getDefaultMin();
+            double max = cc.getDefaultMax();
+            String unit = cc.getUnit();
+            String label = cc.getLabel();
+            
+            DynamicSizeMap map = cc.getDefaultSizeMap();
+            
+            List<Double> sizes = map.getSizes();
+            
+            double sizeBarBoxTop = (sizeBarBoxTopInitial + (colorBarBoxHeight * i));
+            i++;
+//                double backgroundBoxPaddingRight = 20;
+//                double backgroundBoxHeight = 50;
+//                double backgroundBoxWidth = 300;
+//                double backgroundBoxRight = bounds.getMaxX() - backgroundBoxPaddingRight;
+//                double backgroundBoxLeft = backgroundBoxRight - backgroundBoxWidth;
+//                double backgroundBoxTop = bounds.getMaxY();// + (initialPosition + (position * i));
+            g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
+            g2d.setColor(new Color(0.9f, 0.9f, 0.9f, 0.95f));
+            
+            Rectangle2D vertical = new Rectangle2D.Double(sizeBarBoxLeft, sizeBarBoxTop, colorBarBoxWidth, colorBarBoxHeight);
+            g2d.fill(vertical);
+            
+            double sizeVerticalLeft = sizeBarBoxLeft + 5;
+            double sizeVerticalTop = sizeBarBoxTop + 15;
+            double sizeVerticalHeigth = colorBarBoxHeight - 30;
+
+            double sizeVerticalWidth = (sizeBarBoxWidth - 10) / sizes.size();
+            
+            Font rulerFont = new Font("Tahoma", Font.PLAIN, DPIUtil.upscale(9));
+            g2d.setFont(rulerFont);
+            g2d.setColor(Color.BLACK);
+            
+            String str = Double.toString(max);
+            g2d.drawString(str, (int)(sizeBarBoxLeft + sizeBarBoxWidth - 30), (int)(sizeBarBoxTop + sizeBarBoxHeight));
+            
+            str = Double.toString(min);
+            g2d.drawString(str, (int)sizeBarBoxLeft + 1, (int)(sizeBarBoxTop + sizeBarBoxHeight));
+            
+            
+            g2d.setColor(new Color((float)0, (float)0, (float)0.8, 0.8f));
+            for (Double size: sizes) {
+                
+                Ellipse2D ellipse = new Ellipse2D.Double(sizeVerticalLeft + sizeVerticalWidth / 2, (sizeVerticalTop), size * sizeVerticalHeigth, size * sizeVerticalHeigth);
+                g2d.fill(ellipse);
+                
+                sizeVerticalLeft = sizeVerticalLeft + sizeVerticalWidth;
+            }
+            g2d.setColor(Color.BLACK);
+            str = object.getKey() + " - " + label + " [" + unit + "]";
+            g2d.drawString(str, (int)sizeBarBoxLeft + 5, (int)sizeBarBoxTop + 10);
+        }
+    }
+    
+    private double getSizeBarBoxTop(Graphics2D g2d, SizeBarsLocation location, SizeBarsSize size) {
+        Rectangle2D bounds = g2d.getClipBounds();
+        if (bounds == null)
+            throw new IllegalStateException();
+        switch (location) {
+            case NORTH: {
+                return colorBarBoxPadding;
+            }
+            case SOUTH: {
+                return bounds.getMaxY() - colorBarBoxPadding;
+            }
+            case EAST:
+            case WEST: {
+                return (bounds.getMaxY() / 2) - (getSizeBarBoxHeight(size) / 2);
+            }
+            default:
+                return 0;
+        }
+    }
+    
+    private double getSizeBarBoxLeft(Graphics2D g2d, SizeBarsLocation location, SizeBarsSize size) {
+        Rectangle2D bounds = g2d.getClipBounds();
+        if (bounds == null)
+            throw new IllegalStateException();
+        switch (location) {
+            case EAST: {
+                double right = bounds.getMaxX() - colorBarBoxPadding;
+                return right - getSizeBarBoxWidth(size);
+            }
+            case WEST: {
+                return colorBarBoxPadding;
+            }
+            case NORTH:
+            case SOUTH: {
+                double left = (bounds.getMaxX() / 2) - (getSizeBarBoxWidth(size) / 2);
+                return left;
+            }
+            default:
+                return 0;
+        }
+    }
+
+    private double getSizeBarBoxWidth(SizeBarsSize size) {
+        return size.getSize() * colorBarBoxWidth;
+    }
+
+    private double getSizeBarBoxHeight(SizeBarsSize size) {
+        return size.getSize() * colorBarBoxHeight;
+    }
+
+    @Override
+    public Rectangle2D getBoundsInLocal() {
+        return null;
+    }
+
+    public void setEnabled(boolean enabled) {
+        this.enabled = enabled;
+    }
+
+    public void setDynamicColoringObjects(Map<String,DynamicColorContribution> dynamicColoringObjects) {
+        this.dynamicColoringContributions = dynamicColoringObjects;
+    }
+
+    public void setColorBarOptions(ColorBarOptions colorBarsOptions) {
+        this.colorBarsOptions = colorBarsOptions;
+    }
+
+    public void setDynamicSizingObjects(Map<String, DynamicSizeContribution> dynamicSizingObjects) {
+        this.dynamicSizingContributions = dynamicSizingObjects;
+    }
+
+    public void setSizeBarOptions(SizeBarOptions sizeBarOptions) {
+        this.sizeBarsOptions = sizeBarOptions;
+    }
+
+}
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DynamicVisualisationContributionsParticipant.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DynamicVisualisationContributionsParticipant.java
new file mode 100644 (file)
index 0000000..6908606
--- /dev/null
@@ -0,0 +1,116 @@
+package org.simantics.district.network.ui.participants;
+
+import java.awt.geom.AffineTransform;
+import java.util.Map;
+
+import org.simantics.district.network.ui.DistrictDiagramViewer;
+import org.simantics.district.network.ui.nodes.DynamicVisualisationContributionsNode;
+import org.simantics.district.network.visualisations.model.ColorBarOptions;
+import org.simantics.district.network.visualisations.model.DynamicColorContribution;
+import org.simantics.district.network.visualisations.model.DynamicSizeContribution;
+import org.simantics.district.network.visualisations.model.SizeBarOptions;
+import org.simantics.g2d.canvas.ICanvasContext;
+import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant;
+import org.simantics.g2d.canvas.impl.SGNodeReflection.SGInit;
+import org.simantics.scenegraph.g2d.G2DParentNode;
+import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler;
+import org.simantics.scenegraph.g2d.events.command.CommandEvent;
+import org.simantics.utils.datastructures.hints.HintListenerAdapter;
+import org.simantics.utils.datastructures.hints.IHintContext.Key;
+import org.simantics.utils.datastructures.hints.IHintListener;
+import org.simantics.utils.datastructures.hints.IHintObservable;
+
+public class DynamicVisualisationContributionsParticipant extends AbstractCanvasParticipant {
+
+    IHintListener hintListener = new HintListenerAdapter() {
+        public void hintChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) {
+            ICanvasContext cc = getContext();
+            if (cc != null) {
+                updateNode();
+                cc.getContentContext().setDirty();
+            }
+        }
+    };
+    
+    private DynamicVisualisationContributionsNode node;
+    private AffineTransform transform;
+    
+    public DynamicVisualisationContributionsParticipant(AffineTransform tr) {
+        this.transform = tr;
+    }
+
+    @Override
+    public void addedToContext(ICanvasContext ctx) {
+        super.addedToContext(ctx);
+        getHintStack().addKeyHintListener(getThread(), DistrictDiagramViewer.KEY_MAP_COLORING_OBJECTS, hintListener);
+        getHintStack().addKeyHintListener(getThread(), DistrictDiagramViewer.KEY_MAP_COLOR_BAR_OPTIONS, hintListener);
+        getHintStack().addKeyHintListener(getThread(), DistrictDiagramViewer.KEY_MAP_SIZING_OBJECTS, hintListener);
+        getHintStack().addKeyHintListener(getThread(), DistrictDiagramViewer.KEY_MAP_SIZE_BAR_OPTIONS, hintListener);
+    }
+    
+    @Override
+    public void removedFromContext(ICanvasContext ctx) {
+        getHintStack().removeKeyHintListener(getThread(), DistrictDiagramViewer.KEY_MAP_COLORING_OBJECTS, hintListener);
+        getHintStack().removeKeyHintListener(getThread(), DistrictDiagramViewer.KEY_MAP_COLOR_BAR_OPTIONS, hintListener);
+        getHintStack().removeKeyHintListener(getThread(), DistrictDiagramViewer.KEY_MAP_SIZING_OBJECTS, hintListener);
+        getHintStack().removeKeyHintListener(getThread(), DistrictDiagramViewer.KEY_MAP_SIZE_BAR_OPTIONS, hintListener);
+        super.removedFromContext(ctx);
+    }
+
+    @SGInit
+    public void initSG(G2DParentNode parent) {
+        node = parent.addNode(DynamicVisualisationContributionsNode.ID, DynamicVisualisationContributionsNode.class);
+        node.setTransform(transform);
+        node.setEnabled(true);
+        node.setZIndex(1000);
+    }
+    
+    @EventHandler(priority = 0)
+    protected boolean handleKeyEvent(CommandEvent e) {
+        if (e.command.equals(DistrictDiagramViewer.MAP_COLOR_BAR_OPTIONS_CHANGE)) {
+            System.out.println(e);
+            return true;
+        }
+        return false;
+    }
+    
+//    @Override
+//    protected boolean handleCommand(CommandEvent e) {
+//        if (e.command.equals(DistrictDiagramViewer.MAP_COLOR_BAR_OPTIONS_CHANGE)) {
+//            ICanvasContext context = (ICanvasContext) e.getContext();
+//            ColorBarOptions options = context.getHintStack().getHint(DistrictDiagramViewer.KEY_MAP_COLOR_BAR_OPTIONS);
+//            this.colorBarsOptions = options;
+//            repaint();
+//            return true;
+//        } else {
+//            return super.handleCommand(e);
+//        }
+//    }
+    
+    protected void updateNode() {
+        node.setDynamicColoringObjects(getDynamicColoringObjects());
+        node.setColorBarOptions(getColorBarOptions());
+        node.setDynamicSizingObjects(getDynamicSizingObjects());
+        node.setSizeBarOptions(getSizeBarOptions());
+    }
+
+    private Map<String,DynamicColorContribution> getDynamicColoringObjects() {
+        Map<String,DynamicColorContribution> objects = getHint(DistrictDiagramViewer.KEY_MAP_COLORING_OBJECTS);
+        return objects;
+    }
+
+    private ColorBarOptions getColorBarOptions() {
+        ColorBarOptions options = getHint(DistrictDiagramViewer.KEY_MAP_COLOR_BAR_OPTIONS);
+        return options;
+    }
+
+    private Map<String, DynamicSizeContribution> getDynamicSizingObjects() {
+        Map<String, DynamicSizeContribution> objects = getHint(DistrictDiagramViewer.KEY_MAP_SIZING_OBJECTS);
+        return objects;
+    }
+
+    private SizeBarOptions getSizeBarOptions() {
+        SizeBarOptions options = getHint(DistrictDiagramViewer.KEY_MAP_SIZE_BAR_OPTIONS);
+        return options;
+    }
+}
index a94d56a14443413270d9b478d9c3f33318e497c9..d484e1b1524505af75427a9f8cdd882f59d229d3 100644 (file)
@@ -79,7 +79,7 @@ public class ImportCSVHandler {
                        if (sourceEPSGCRS != null && !sourceEPSGCRS.isEmpty()) {
                                CoordinateReferenceSystem sourceCRS = CRS.decode(sourceEPSGCRS);
                                CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326");
-                               transform = CRS.findMathTransform(sourceCRS, targetCRS, true);
+                               transform = CRS.findMathTransform(sourceCRS, targetCRS, false);
                                doTransform = true;
                        }
                        
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java
new file mode 100644 (file)
index 0000000..4fe3d59
--- /dev/null
@@ -0,0 +1,778 @@
+package org.simantics.district.network.ui.visualisations;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Objects;
+import java.util.function.Supplier;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IEditorPart;
+import org.simantics.Simantics;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.UniqueRead;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.procedure.Listener;
+import org.simantics.district.network.DistrictNetworkUtil;
+import org.simantics.district.network.profile.DynamicVisualisationsRequest;
+import org.simantics.district.network.visualisations.DynamicVisualisationsContributions;
+import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicColoringObject;
+import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicSizingObject;
+import org.simantics.district.network.visualisations.model.ColorBarOptions;
+import org.simantics.district.network.visualisations.model.ColorBarOptions.ColorBarsLocation;
+import org.simantics.district.network.visualisations.model.ColorBarOptions.ColorBarsSize;
+import org.simantics.district.network.visualisations.model.DynamicColorContribution;
+import org.simantics.district.network.visualisations.model.DynamicColorMap;
+import org.simantics.district.network.visualisations.model.DynamicSizeContribution;
+import org.simantics.district.network.visualisations.model.DynamicSizeMap;
+import org.simantics.district.network.visualisations.model.DynamicVisualisation;
+import org.simantics.district.network.visualisations.model.SizeBarOptions;
+import org.simantics.district.network.visualisations.model.SizeBarOptions.SizeBarsLocation;
+import org.simantics.district.network.visualisations.model.SizeBarOptions.SizeBarsSize;
+import org.simantics.ui.workbench.IResourceEditorPart;
+import org.simantics.utils.datastructures.Pair;
+import org.simantics.utils.ui.workbench.WorkbenchUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DynamicVisualisationsUI extends Composite {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(DynamicVisualisationsUI.class);
+
+    private Resource diagramResource;
+    private VisualisationListener listener;
+    private DynamicVisualisation visualisation;
+
+    private Button showSizeButton;
+    private Button sizeTicksButton;
+    private Combo sizeLocationCombo;
+    private Combo sizeSizeCombo;
+    private Button showColorButton;
+    private Button colorTicksButton;
+    private Combo colorLocationCombo;
+    private Combo colorSizeCombo;
+
+    public DynamicVisualisationsUI(Composite parent, int style) {
+        super(parent, style);
+
+        defaultInitializeUI();
+    }
+
+    private void defaultInitializeUI() {
+        GridDataFactory.fillDefaults().grab(true, true).applyTo(this);
+        GridLayoutFactory.fillDefaults().numColumns(1).margins(5, 5).applyTo(this);
+        
+        Composite coloringObjectsComposite = new Composite(this, SWT.NONE);
+        GridDataFactory.fillDefaults().grab(true, false).applyTo(coloringObjectsComposite);
+        GridLayoutFactory.fillDefaults().numColumns(1).applyTo(coloringObjectsComposite);
+        initializeColoringObjects(coloringObjectsComposite);
+        
+        Composite colorBarsComposite = new Composite(this, SWT.NONE);
+        GridDataFactory.fillDefaults().grab(true, false).applyTo(colorBarsComposite);
+        GridLayoutFactory.fillDefaults().numColumns(1).applyTo(colorBarsComposite);
+        initializeColorBars(colorBarsComposite);
+        
+        Composite objectSizesComposite = new Composite(this, SWT.NONE);
+        GridDataFactory.fillDefaults().grab(true, false).applyTo(objectSizesComposite);
+        GridLayoutFactory.fillDefaults().numColumns(1).applyTo(objectSizesComposite);
+        initializeObjectSizes(objectSizesComposite);
+        
+        Composite sizeBarsComposite = new Composite(this, SWT.NONE);
+        GridDataFactory.fillDefaults().grab(true, false).applyTo(sizeBarsComposite);
+        GridLayoutFactory.fillDefaults().numColumns(1).applyTo(sizeBarsComposite);
+        initializeSizeBars(sizeBarsComposite);
+        
+    }
+
+    private void initializeColoringObjects(Composite parent) {
+        Group group = new Group(parent, SWT.NONE);
+        group.setText("Coloring Objects");
+        GridDataFactory.fillDefaults().grab(true, false).applyTo(group);
+        GridLayoutFactory.fillDefaults().numColumns(8).margins(5, 5).applyTo(group);
+        
+        {
+            createColoringObjectHeaderRow(group);
+        }
+        List<Supplier<Pair<String, DynamicColorContribution>>> suppliers = new ArrayList<>();
+        {
+            try {
+                Collection<DynamicColoringObject> result = Simantics.getSession().syncRequest(new UniqueRead<Collection<DynamicColoringObject>>() {
+
+                    @Override
+                    public Collection<DynamicColoringObject> perform(ReadGraph graph) throws DatabaseException {
+                        return DynamicVisualisationsContributions.dynamicColoringObjects(graph);
+                    }
+                });
+                
+                for (DynamicColoringObject object : result) {
+                    suppliers.add(createColoringObjectRow(group, object));
+                }
+
+            } catch (DatabaseException e) {
+                e.printStackTrace();
+            }
+        }
+        {
+            Button applyButton = new Button(group, SWT.NONE);
+            applyButton.setText("Apply");
+            applyButton.addSelectionListener(new SelectionAdapter() {
+                
+                @Override
+                public void widgetSelected(SelectionEvent e) {
+                    List<Pair<String, DynamicColorContribution>> collect = suppliers.stream().map(s -> s.get()).filter(Objects::nonNull).collect(Collectors.toList());
+                    Simantics.getSession().asyncRequest(new WriteRequest() {
+                        
+                        @Override
+                        public void perform(WriteGraph graph) throws DatabaseException {
+                            DistrictNetworkUtil.setColorContributions(graph, DynamicVisualisationsUI.this.diagramResource, collect);
+                        }
+                    });
+                }
+            });
+        }
+    }
+    
+    private void createColoringObjectHeaderRow(Composite parent) {
+
+        Label label = new Label(parent, SWT.NONE);
+        label.setText("Label");
+        GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(label);
+        
+        label = new Label(parent, SWT.NONE);
+        label.setText("Used");
+        GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(label);
+        
+        label = new Label(parent, SWT.NONE);
+        label.setText("Variable");
+        GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(label);
+        
+        label = new Label(parent, SWT.NONE);
+        label.setText("Min");
+        GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(label);
+        
+        label = new Label(parent, SWT.NONE);
+        label.setText("Max");
+        GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(label);
+        
+        label = new Label(parent, SWT.NONE);
+        label.setText("Unit");
+        GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(label);
+        
+        label = new Label(parent, SWT.NONE);
+        label.setText("ColorMap");
+        GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(label);
+        
+        label = new Label(parent, SWT.NONE);
+        label.setText("Default");
+        GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(label);
+    }
+
+    private Map<String, ColoringObjectRow> coloringRows = new HashMap<>();
+    private Map<String, SizingObjectRow> sizingRows = new HashMap<>();
+
+    private static class ColoringObjectRow {
+        
+        private final Label label;
+        private final Button usedButton;
+        private final Combo variableCombo;
+        private final Text minText;
+        private final Text maxText;
+        private final Label unit;
+        private final Combo colorMapCombo;
+        private final Button defaultButton;
+        
+        public ColoringObjectRow(Label label, Button usedButton, Combo variableCombo, Text minText, Text maxText, Label unit,
+                Combo colorMapCombo, Button defaultButton) {
+            super();
+            this.label = label;
+            this.usedButton = usedButton;
+            this.variableCombo = variableCombo;
+            this.minText = minText;
+            this.maxText = maxText;
+            this.unit = unit;
+            this.colorMapCombo = colorMapCombo;
+            this.defaultButton = defaultButton;
+        }
+
+        public void update(DynamicColorContribution colorContribution) {
+            String[] items = variableCombo.getItems();
+            for (int i = 0; i < items.length; i++) {
+                if (colorContribution.getLabel().equals(items[i])) {
+                    variableCombo.select(i);
+                    break;
+                }
+            }
+            minText.setText(Double.toString(colorContribution.getDefaultMin()));
+            maxText.setText(Double.toString(colorContribution.getDefaultMax()));
+            unit.setText(colorContribution.getUnit());
+            
+            // color map only supports single for now
+            colorMapCombo.setItems(colorContribution.getDefaultColorMap().getLabel());
+            colorMapCombo.select(0);
+//            String[] colorItems = colorMapCombo.getItems();
+//            for (int i = 0; i < colorItems.length; i++) {
+//                
+//                if (colorContribution.getDefaultColorMap().getLabel().equals(colorItems[i])) {
+//                    colorMapCombo.select(i);
+//                    break;
+//                }
+//            }
+        }
+    }
+
+    private static class SizingObjectRow {
+        
+        private final Label label;
+        private final Button usedButton;
+        private final Combo variableCombo;
+        private final Text minText;
+        private final Text maxText;
+        private final Label unit;
+        private final Combo sizeMapCombo;
+        private final Button defaultButton;
+        
+        public SizingObjectRow(Label label, Button usedButton, Combo variableCombo, Text minText, Text maxText, Label unit,
+                Combo sizeMapCombo, Button defaultButton) {
+            super();
+            this.label = label;
+            this.usedButton = usedButton;
+            this.variableCombo = variableCombo;
+            this.minText = minText;
+            this.maxText = maxText;
+            this.unit = unit;
+            this.sizeMapCombo = sizeMapCombo;
+            this.defaultButton = defaultButton;
+        }
+
+        public void update(DynamicSizeContribution sizeContribution) {
+            String[] items = variableCombo.getItems();
+            for (int i = 0; i < items.length; i++) {
+                if (sizeContribution.getLabel().equals(items[i])) {
+                    variableCombo.select(i);
+                    break;
+                }
+            }
+            minText.setText(Double.toString(sizeContribution.getDefaultMin()));
+            maxText.setText(Double.toString(sizeContribution.getDefaultMax()));
+            unit.setText(sizeContribution.getUnit());
+            
+            // color map only supports single for now
+            sizeMapCombo.setItems(sizeContribution.getDefaultSizeMap().getLabel());
+            sizeMapCombo.select(0);
+//            String[] colorItems = colorMapCombo.getItems();
+//            for (int i = 0; i < colorItems.length; i++) {
+//                
+//                if (colorContribution.getDefaultColorMap().getLabel().equals(colorItems[i])) {
+//                    colorMapCombo.select(i);
+//                    break;
+//                }
+//            }
+        }
+    }
+
+    private Supplier<Pair<String, DynamicColorContribution>> createColoringObjectRow(Composite parent, DynamicColoringObject object) {
+        Label label = new Label(parent, SWT.NONE);
+        label.setText(object.getColoringObject().getName());
+        GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(label);
+        
+        Map<String, DynamicColorContribution> colorContributions = object.getColorContributions();
+        
+        Button usedButton = new Button(parent, SWT.CHECK);
+        GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(usedButton);
+        
+        Combo variableCombo = new Combo(parent, SWT.READ_ONLY);
+        variableCombo.setItems(colorContributions.keySet().toArray(new String[colorContributions.size()]));
+        
+        GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(variableCombo);
+        
+        Text minText = new Text(parent, SWT.BORDER);
+        GridDataFactory.fillDefaults().grab(true, false).hint(150, SWT.DEFAULT).align(SWT.CENTER, SWT.CENTER).applyTo(minText);
+        
+        Text maxText = new Text(parent, SWT.BORDER);
+        GridDataFactory.fillDefaults().grab(true, false).hint(150, SWT.DEFAULT).align(SWT.CENTER, SWT.CENTER).applyTo(maxText);
+        
+        Label unit = new Label(parent, SWT.NONE);
+        unit.setText("");
+        GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(unit);
+        
+        Combo colorMapCombo = new Combo(parent, SWT.READ_ONLY);
+        GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(colorMapCombo);
+        
+        Button defaultButton = new Button(parent, SWT.CHECK);
+        GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(defaultButton);
+        
+        variableCombo.addSelectionListener(new SelectionAdapter() {
+            
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                // handle update for others
+                
+                DynamicColorContribution cont = colorContributions.get(variableCombo.getText());
+                
+                if (minText.getText().isEmpty()) {
+                    minText.setText(Double.toString(cont.getDefaultMin()));
+                }
+                if (maxText.getText().isEmpty()) {
+                    maxText.setText(Double.toString(cont.getDefaultMax()));
+                }
+                unit.setText(cont.getUnit());
+                
+                colorMapCombo.setItems(cont.getDefaultColorMap().getLabel());
+                colorMapCombo.select(0);
+                
+                defaultButton.setSelection(true);
+            }
+        });
+
+        coloringRows.put(object.getColoringObject().getName(), new ColoringObjectRow(label, usedButton, variableCombo, minText, maxText, unit, colorMapCombo, defaultButton));
+
+        return new Supplier<Pair<String, DynamicColorContribution>>() {
+
+            @Override
+            public Pair<String, DynamicColorContribution> get() {
+                DynamicColorContribution cont = colorContributions.get(variableCombo.getText());
+                if (cont != null) {
+                    String colorMap = colorMapCombo.getItem(colorMapCombo.getSelectionIndex());
+                    try {
+                        Map<String, DynamicColorMap> colorMaps = Simantics.getSession().syncRequest(new UniqueRead<Map<String, DynamicColorMap>>() {
+    
+                            @Override
+                            public Map<String, DynamicColorMap> perform(ReadGraph graph) throws DatabaseException {
+                                return DynamicVisualisationsContributions.dynamicColorMaps(graph);
+                            }
+                        });
+                        DynamicColorMap dColorMap = colorMaps.get(colorMap);
+                        String label = variableCombo.getItem(variableCombo.getSelectionIndex());
+                        
+                        DynamicColorContribution dcc = new DynamicColorContribution(label, cont.getModuleName(), cont.getAttributeName(), unit.getText(), cont.getVariableGain(), cont.getVariableBias(), dColorMap, Double.parseDouble(minText.getText()), Double.parseDouble(maxText.getText()));
+                        dcc.setUsed(usedButton.getSelection());
+                        dcc.setUseDefault(defaultButton.getSelection());
+                        
+                        return Pair.make(object.getColoringObject().getName(), dcc);
+                    } catch (DatabaseException e) {
+                        LOGGER.error("Could not get DynamicColorContribution", e);
+                    }
+                }
+                return null;
+            }
+        };
+    }
+    
+    private void createSizingObjectHeaderRow(Composite parent) {
+
+        Label label = new Label(parent, SWT.NONE);
+        label.setText("Label");
+        GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(label);
+        
+        label = new Label(parent, SWT.NONE);
+        label.setText("Used");
+        GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(label);
+        
+        label = new Label(parent, SWT.NONE);
+        label.setText("Variable");
+        GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(label);
+        
+        label = new Label(parent, SWT.NONE);
+        label.setText("Min");
+        GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(label);
+        
+        label = new Label(parent, SWT.NONE);
+        label.setText("Max");
+        GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(label);
+        
+        label = new Label(parent, SWT.NONE);
+        label.setText("Unit");
+        GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(label);
+        
+        label = new Label(parent, SWT.NONE);
+        label.setText("SizeMap");
+        GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(label);
+        
+        label = new Label(parent, SWT.NONE);
+        label.setText("Default");
+        GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(label);
+    }
+
+    private Supplier<Pair<String, DynamicSizeContribution>> createSizingObjectRow(Composite parent, DynamicSizingObject object) {
+        Label label = new Label(parent, SWT.NONE);
+        label.setText(object.getSizingObject().getName());
+        GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(label);
+        
+        Map<String, DynamicSizeContribution> sizeContributions = object.getSizeContributions();
+        
+        Button usedButton = new Button(parent, SWT.CHECK);
+        GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(usedButton);
+        
+        Combo variableCombo = new Combo(parent, SWT.READ_ONLY);
+        variableCombo.setItems(sizeContributions.keySet().toArray(new String[sizeContributions.size()]));
+        
+        GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(variableCombo);
+        
+        Text minText = new Text(parent, SWT.BORDER);
+        GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(minText);
+        
+        Text maxText = new Text(parent, SWT.BORDER);
+        GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(maxText);
+        
+        Label unit = new Label(parent, SWT.NONE);
+        unit.setText("");
+        GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(unit);
+        
+        Combo sizeMapCombo = new Combo(parent, SWT.READ_ONLY);
+        GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(sizeMapCombo);
+        
+        Button defaultButton = new Button(parent, SWT.CHECK);
+        GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(defaultButton);
+        
+        variableCombo.addSelectionListener(new SelectionAdapter() {
+            
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                // handle update for others
+                
+                DynamicSizeContribution cont = sizeContributions.get(variableCombo.getText());
+                
+                if (minText.getText().isEmpty()) {
+                    minText.setText(Double.toString(cont.getDefaultMin()));
+                }
+                if (maxText.getText().isEmpty()) {
+                    maxText.setText(Double.toString(cont.getDefaultMax()));
+                }
+                unit.setText(cont.getUnit());
+                
+                sizeMapCombo.setItems(cont.getDefaultSizeMap().getLabel());
+                sizeMapCombo.select(0);
+                
+                defaultButton.setSelection(true);
+            }
+        });
+        
+        sizingRows.put(object.getSizingObject().getName(), new SizingObjectRow(label, usedButton, variableCombo, minText, maxText, unit, sizeMapCombo, defaultButton));
+        
+        return new Supplier<Pair<String, DynamicSizeContribution>>() {
+
+            @Override
+            public Pair<String, DynamicSizeContribution> get() {
+                DynamicSizeContribution cont = sizeContributions.get(variableCombo.getText());
+                if (cont != null) {
+                    String sizeMap = sizeMapCombo.getItem(sizeMapCombo.getSelectionIndex());
+                    try {
+                        Map<String, DynamicSizeMap> sizeMaps = Simantics.getSession().syncRequest(new UniqueRead<Map<String, DynamicSizeMap>>() {
+    
+                            @Override
+                            public Map<String, DynamicSizeMap> perform(ReadGraph graph) throws DatabaseException {
+                                return DynamicVisualisationsContributions.dynamicSizeMaps(graph);
+                            }
+                        });
+                        DynamicSizeMap dColorMap = sizeMaps.get(sizeMap);
+                        String label = variableCombo.getItem(variableCombo.getSelectionIndex());
+                        
+                        DynamicSizeContribution dsc = new DynamicSizeContribution(label, cont.getModuleName(), cont.getAttributeName(), unit.getText(), cont.getVariableGain(), cont.getVariableBias(), dColorMap, Double.parseDouble(minText.getText()), Double.parseDouble(maxText.getText()));
+                        dsc.setUsed(usedButton.getSelection());
+                        dsc.setUseDefault(defaultButton.getSelection());
+                        
+                        return Pair.make(object.getSizingObject().getName(), dsc);
+                    } catch (DatabaseException e) {
+                        LOGGER.error("Could not get DynamicColorContribution", e);
+                    }
+                }
+                return null;
+            }
+        };
+    }
+    
+    private void initializeColorBars(Composite parent) {
+        Group group = new Group(parent, SWT.NONE);
+        group.setText("Color Bars");
+        GridDataFactory.fillDefaults().grab(true, false).applyTo(group);
+        GridLayoutFactory.fillDefaults().numColumns(2).margins(5, 5).applyTo(group);
+        
+        createColorBars(group);
+    }
+    
+    private void createColorBars(Composite parent) {
+        
+        showColorButton = new Button(parent, SWT.CHECK);
+        showColorButton.setText("Show");
+        
+        colorTicksButton = new Button(parent, SWT.CHECK);
+        colorTicksButton.setText("Ticks");
+        
+        Label label = new Label(parent, SWT.NONE);
+        label.setText("Location");
+        colorLocationCombo = new Combo(parent, SWT.READ_ONLY);
+        colorLocationCombo.setItems(Stream.of(ColorBarsLocation.values()).map(size -> size.toString()).toArray(String[]::new));
+        
+        label = new Label(parent, SWT.NONE);
+        label.setText("Size");
+        colorSizeCombo = new Combo(parent, SWT.READ_ONLY);
+        colorSizeCombo.setItems(Stream.of(ColorBarsSize.values()).map(size -> size.toString()).toArray(String[]::new));
+        
+        Button applyButton = new Button(parent, SWT.NONE);
+        applyButton.setText("Apply");
+        
+        applyButton.addSelectionListener(new SelectionAdapter() {
+            
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                // persist changes
+                IEditorPart activeEditor = WorkbenchUtils.getActiveEditor();
+                if (activeEditor instanceof IResourceEditorPart) {
+                    Resource diagram = ((IResourceEditorPart) activeEditor).getResourceInput().getResource();
+                    ColorBarOptions options = new ColorBarOptions()
+                            .showColorBars(showColorButton.getSelection())
+                            .showColorBarsTicks(colorTicksButton.getSelection())
+                            .withLocation(ColorBarsLocation.valueOf(colorLocationCombo.getText().toUpperCase()))
+                            .withSize(ColorBarsSize.valueOf(colorSizeCombo.getText().toUpperCase()));
+
+                    Simantics.getSession().asyncRequest(new WriteRequest() {
+                        
+                        @Override
+                        public void perform(WriteGraph graph) throws DatabaseException {
+                            DistrictNetworkUtil.setColorBarOptions(graph, diagram, options);
+                        }
+                    });
+                }
+            }
+        });
+    }
+
+    private void initializeObjectSizes(Composite parent) {
+        Group group = new Group(parent, SWT.NONE);
+        group.setText("Object Sizes");
+        GridDataFactory.fillDefaults().grab(true, false).applyTo(group);
+        GridLayoutFactory.fillDefaults().numColumns(8).margins(5, 5).applyTo(group);
+        
+        {
+            createSizingObjectHeaderRow(group);
+            createObjectSizes(group);
+        }
+    }
+    
+    private void createObjectSizes(Composite parent) {
+        
+        List<Supplier<Pair<String, DynamicSizeContribution>>> suppliers = new ArrayList<>(); 
+        try {
+            Collection<DynamicSizingObject> resultSizing = Simantics.getSession().syncRequest(new UniqueRead<Collection<DynamicSizingObject>>() {
+
+                @Override
+                public Collection<DynamicSizingObject> perform(ReadGraph graph) throws DatabaseException {
+                    return DynamicVisualisationsContributions.dynamicSizingObjects(graph);
+                }
+            });
+            
+            for (DynamicSizingObject object : resultSizing) {
+                suppliers.add(createSizingObjectRow(parent, object));
+            }
+        } catch (DatabaseException e) {
+            e.printStackTrace();
+        }
+        
+        {
+            Button applyButton = new Button(parent, SWT.NONE);
+            applyButton.setText("Apply");
+            applyButton.addSelectionListener(new SelectionAdapter() {
+                
+                @Override
+                public void widgetSelected(SelectionEvent e) {
+                    List<Pair<String, DynamicSizeContribution>> collect = suppliers.stream().map(s -> s.get()).filter(Objects::nonNull).collect(Collectors.toList());
+                    Simantics.getSession().asyncRequest(new WriteRequest() {
+                        
+                        @Override
+                        public void perform(WriteGraph graph) throws DatabaseException {
+                            DistrictNetworkUtil.setSizeContributions(graph, DynamicVisualisationsUI.this.diagramResource, collect);
+                        }
+                    });
+                }
+            });
+        }
+    }
+
+    private void initializeSizeBars(Composite parent) {
+        Group group = new Group(parent, SWT.NONE);
+        group.setText("Size Bars");
+        GridDataFactory.fillDefaults().grab(true, false).applyTo(group);
+        GridLayoutFactory.fillDefaults().numColumns(2).margins(5, 5).applyTo(group);
+        
+        createSizeBars(group);
+    }
+
+    private void createSizeBars(Composite parent) {
+        showSizeButton = new Button(parent, SWT.CHECK);
+        showSizeButton.setText("Show");
+        
+        sizeTicksButton = new Button(parent, SWT.CHECK);
+        sizeTicksButton.setText("Ticks");
+        
+        Label label = new Label(parent, SWT.NONE);
+        label.setText("Location");
+        sizeLocationCombo = new Combo(parent, SWT.READ_ONLY);
+        sizeLocationCombo.setItems(Stream.of(SizeBarsLocation.values()).map(size -> size.toString()).toArray(String[]::new));
+        
+        label = new Label(parent, SWT.NONE);
+        label.setText("Size");
+        sizeSizeCombo = new Combo(parent, SWT.NONE);
+        sizeSizeCombo.setItems(Stream.of(SizeBarsSize.values()).map(size -> size.toString()).toArray(String[]::new));
+        
+        Button applyButton = new Button(parent, SWT.READ_ONLY);
+        applyButton.setText("Apply");
+        
+        applyButton.addSelectionListener(new SelectionAdapter() {
+            
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                // persist changes
+                IEditorPart activeEditor = WorkbenchUtils.getActiveEditor();
+                if (activeEditor instanceof IResourceEditorPart) {
+                    Resource diagram = ((IResourceEditorPart) activeEditor).getResourceInput().getResource();
+                    SizeBarOptions options = new SizeBarOptions()
+                            .showSizeBars(showSizeButton.getSelection())
+                            .showSizeBarsTicks(sizeTicksButton.getSelection())
+                            .withLocation(SizeBarsLocation.valueOf(sizeLocationCombo.getText().toUpperCase()))
+                            .withSize(SizeBarsSize.valueOf(sizeSizeCombo.getText().toUpperCase()));
+
+                    Simantics.getSession().asyncRequest(new WriteRequest() {
+                        
+                        @Override
+                        public void perform(WriteGraph graph) throws DatabaseException {
+                            DistrictNetworkUtil.setSizeBarOptions(graph, diagram, options);
+                        }
+                    });
+                }
+            }
+        });
+    }
+
+    public void setDiagramResource(Resource diagramResource) {
+        if (this.diagramResource != diagramResource) {
+            this.diagramResource = diagramResource;
+            updateListening();
+        }
+    }
+
+    private void updateListening() {
+        if (listener != null) {
+            listener.dispose();
+        }
+        listener = new VisualisationListener(this);
+        Simantics.getSession().asyncRequest(new DynamicVisualisationsRequest(diagramResource), listener);
+    }
+
+    private static class VisualisationListener implements Listener<DynamicVisualisation> {
+
+        private static final Logger LOGGER = LoggerFactory.getLogger(VisualisationListener.class);
+
+        private boolean disposed;
+        private DynamicVisualisationsUI ui;
+        
+        public VisualisationListener(DynamicVisualisationsUI ui) {
+            this.ui = ui;
+        }
+
+        @Override
+        public void execute(DynamicVisualisation result) {
+            ui.updateVisualisation(result);
+        }
+
+        @Override
+        public void exception(Throwable t) {
+            LOGGER.error("Could not listen visualisation", t);
+        }
+
+        @Override
+        public boolean isDisposed() {
+            return disposed || ui.isDisposed();
+        }
+
+        public void dispose() {
+            this.disposed = true;
+        }
+    }
+
+    public void updateVisualisation(DynamicVisualisation result) {
+        this.visualisation = result;
+        Display.getDefault().asyncExec(() -> {
+            if (getParent().isDisposed())
+                return;
+            
+            Map<String, DynamicColorContribution> colorContributions = visualisation.getColorContributions();
+            for (Entry<String, DynamicColorContribution> entry : colorContributions.entrySet()) {
+                
+                ColoringObjectRow coloringObjectRow = coloringRows.get(entry.getKey());
+                if (coloringObjectRow != null) {
+                    
+                    coloringObjectRow.update(entry.getValue());
+                    
+                } else {
+                    LOGGER.info("No coloring object visualisation row for key {}", entry.getKey());
+                }
+            }
+            ColorBarOptions colorOptions = visualisation.getColorBarOptions();
+            showColorButton.setSelection(colorOptions.isShowColorBars());
+            colorTicksButton.setSelection(colorOptions.isShowColorBarsTicks());
+            for (int i = 0; i < colorLocationCombo.getItems().length; i++) {
+                String item = colorLocationCombo.getItem(i);
+                if (item.equals(colorOptions.getLocation().toString())) {
+                    colorLocationCombo.select(i);
+                    break;
+                }
+            }
+            for (int i = 0; i < colorSizeCombo.getItems().length; i++) {
+                String item = colorSizeCombo.getItem(i);
+                if (item.equals(colorOptions.getSize().toString())) {
+                    colorSizeCombo.select(i);
+                    break;
+                }
+            }
+            
+            Map<String, DynamicSizeContribution> sizeContributions = visualisation.getSizeContributions();
+            for (Entry<String, DynamicSizeContribution> entry : sizeContributions.entrySet()) {
+                
+                SizingObjectRow sizingObjectRow = sizingRows.get(entry.getKey());
+                if (sizingObjectRow != null) {
+                    
+                    sizingObjectRow.update(entry.getValue());
+                    
+                } else {
+                    LOGGER.info("No sizing object visualisation row for key {}", entry.getKey());
+                }
+            }
+            SizeBarOptions sizeOptions = visualisation.getSizeBarOptions();
+            showSizeButton.setSelection(sizeOptions.isShowSizeBars());
+            sizeTicksButton.setSelection(sizeOptions.isShowSizeBarsTicks());
+            for (int i = 0; i < sizeLocationCombo.getItems().length; i++) {
+                String item = sizeLocationCombo.getItem(i);
+                if (item.equals(sizeOptions.getLocation().toString())) {
+                    sizeLocationCombo.select(i);
+                    break;
+                }
+            }
+            for (int i = 0; i < sizeSizeCombo.getItems().length; i++) {
+                String item = sizeSizeCombo.getItem(i);
+                if (item.equals(sizeOptions.getSize().toString())) {
+                    sizeSizeCombo.select(i);
+                    break;
+                }
+            }
+        });
+    }
+}
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsView.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsView.java
new file mode 100644 (file)
index 0000000..d98a378
--- /dev/null
@@ -0,0 +1,86 @@
+package org.simantics.district.network.ui.visualisations;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.workbench.modeling.EPartService;
+import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
+import org.eclipse.e4.ui.workbench.modeling.IPartListener;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor;
+import org.simantics.district.network.ui.DistrictDiagramEditor;
+import org.simantics.ui.workbench.IResourceEditorInput;
+import org.simantics.utils.ui.workbench.WorkbenchUtils;
+
+public class DynamicVisualisationsView {
+
+    @Inject
+    ESelectionService selectionService;
+    
+    @Inject
+    EPartService partService;
+
+    private DynamicVisualisationsUI ui;
+
+    @PostConstruct
+    public void postConstruct(Composite parent) {
+        ui = new DynamicVisualisationsUI(parent, 0);
+        
+        IEditorPart editor = WorkbenchUtils.getActiveEditor();
+        if (editor instanceof DistrictDiagramEditor)
+            setDiagramResource(editor.getEditorInput());
+        
+        partService.addPartListener(partListener);
+    }
+
+    @PreDestroy
+    public void dispose() {
+        partService.removePartListener(partListener);
+        ui.dispose();
+        ui = null;
+    }
+
+    private void setDiagramResourceFromCompatibilityEditor(MPart part) {
+        if (part.getObject() instanceof CompatibilityEditor) {
+            CompatibilityEditor editor = (CompatibilityEditor) part.getObject();
+            IEditorPart editorPart = editor.getEditor();
+            setDiagramResource(editorPart.getEditorInput());
+        }
+    }
+    
+    private void setDiagramResource(IEditorInput input) {
+        if (input instanceof IResourceEditorInput) {
+            ui.setDiagramResource(((IResourceEditorInput) input).getResource());
+        }
+    }
+    
+    private IPartListener partListener = new IPartListener() {
+        
+        @Override
+        public void partVisible(MPart part) {
+            setDiagramResourceFromCompatibilityEditor(part);
+        }
+        
+        @Override
+        public void partHidden(MPart part) {
+        }
+        
+        @Override
+        public void partDeactivated(MPart part) {
+        }
+        
+        @Override
+        public void partBroughtToTop(MPart part) {
+            setDiagramResourceFromCompatibilityEditor(part);
+        }
+        
+        @Override
+        public void partActivated(MPart part) {
+            setDiagramResourceFromCompatibilityEditor(part);
+        }
+    };
+}
index ddf8bb900260333f32e2f1de20b2b1cb221d97da..77e7c464d2f1803028435f4ab298bc509ad6d7f0 100644 (file)
@@ -18,7 +18,10 @@ Require-Bundle: org.simantics.db,
  org.slf4j.api,
  org.simantics.maps.elevation.server;bundle-version="1.0.0",
  org.simantics.modeling,
- org.simantics.db.indexing
+ org.simantics.db.indexing,
+ org.simantics.scl.osgi
 Export-Package: org.simantics.district.network,
  org.simantics.district.network.changeset,
- org.simantics.district.network.profile
+ org.simantics.district.network.profile,
+ org.simantics.district.network.visualisations,
+ org.simantics.district.network.visualisations.model
index fddb3b74017fb050ee20173aaa4d28ef8cf5c007..dc464c88bc066c94dd1341cabf796e12e332be8b 100644 (file)
@@ -12,6 +12,9 @@
                <resource uri="http://www.simantics.org/DistrictNetwork-1.0/ElementColoringStyle"
                        class="org.simantics.district.network.profile.DNElementColorStyle">
                </resource>
+               <resource uri="http://www.simantics.org/DistrictNetwork-1.0/ElementSizingStyle"
+                       class="org.simantics.district.network.profile.DNElementSizeStyle">
+               </resource>
                <resource uri="http://www.simantics.org/DistrictNetwork-1.0/VertexSizeStyle"
                        class="org.simantics.district.network.profile.VertexSizeStyle">
                </resource>
diff --git a/org.simantics.district.network/scl/Simantics/District/DynamicVisualisations/ColorContribution.scl b/org.simantics.district.network/scl/Simantics/District/DynamicVisualisations/ColorContribution.scl
new file mode 100644 (file)
index 0000000..800aa2b
--- /dev/null
@@ -0,0 +1,21 @@
+// Example: (�p supply�, ï¿½S_PC�, ï¿½PO11_PRESSURE�, ï¿½bar(g)�, 0.1, 1.0, ï¿½summer�, 50.0, 120.0)
+// Above ï¿½p supply� is label and there may be several UC types contributing to the same label. Default colorMap ï¿½summer�.
+
+importJava "org.simantics.district.network.visualisations.model.DynamicColorMap" where
+    data DynamicColorMap
+    
+    @JavaName "<init>"
+    dynamicColorMap :: String -> [RGBIntensity] -> DynamicColorMap
+
+importJava "org.simantics.district.network.visualisations.model.DynamicColorMap$RGBIntensity" where
+    data RGBIntensity
+    
+    @JavaName "<init>"
+    rgbIntensity :: Double -> Double -> Double -> RGBIntensity 
+
+importJava "org.simantics.district.network.visualisations.model.DynamicColorContribution" where
+    data DynamicColorContribution
+    
+    @JavaName "<init>"
+    dynamicColorContribution :: String -> String -> String -> String -> Double -> Double -> DynamicColorMap -> Double -> Double -> DynamicColorContribution
+
diff --git a/org.simantics.district.network/scl/Simantics/District/DynamicVisualisations/ColorMap.scl b/org.simantics.district.network/scl/Simantics/District/DynamicVisualisations/ColorMap.scl
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/org.simantics.district.network/scl/Simantics/District/DynamicVisualisations/SizeContribution.scl b/org.simantics.district.network/scl/Simantics/District/DynamicVisualisations/SizeContribution.scl
new file mode 100644 (file)
index 0000000..e6b2ed3
--- /dev/null
@@ -0,0 +1,13 @@
+// Example: (�supply flow�, ï¿½S_FLOW�, ï¿½SP_VALUE�, ï¿½kg/s�, 1.0, 0.0, ï¿½linearSizesMedium�, 10.0, 1500.0)
+
+importJava "org.simantics.district.network.visualisations.model.DynamicSizeMap" where
+    data DynamicSizeMap
+    
+    @JavaName "<init>"
+    dynamicSizeMap :: String -> [Double] -> DynamicSizeMap
+
+importJava "org.simantics.district.network.visualisations.model.DynamicSizeContribution" where
+    data DynamicSizeContribution
+    
+    @JavaName "<init>"
+    dynamicSizeContribution :: String -> String -> String -> String -> Double -> Double -> DynamicSizeMap -> Double -> Double -> DynamicSizeContribution
diff --git a/org.simantics.district.network/scl/Simantics/District/DynamicVisualisations/SizeMap.scl b/org.simantics.district.network/scl/Simantics/District/DynamicVisualisations/SizeMap.scl
new file mode 100644 (file)
index 0000000..e69de29
index ae73e56bc2119806cd816e069dc0732e2e489e7d..22aa7266bb7bec89d5170395d24718062ac1e973 100644 (file)
@@ -3,8 +3,11 @@ package org.simantics.district.network;
 import java.awt.geom.Rectangle2D;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
@@ -30,12 +33,24 @@ import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;
 import org.simantics.diagram.synchronization.graph.layer.GraphLayer;
 import org.simantics.diagram.synchronization.graph.layer.IGraphLayerUtil;
 import org.simantics.district.network.ontology.DistrictNetworkResource;
+import org.simantics.district.network.visualisations.DynamicVisualisationsContributions;
+import org.simantics.district.network.visualisations.model.ColorBarOptions;
+import org.simantics.district.network.visualisations.model.ColorBarOptions.ColorBarsLocation;
+import org.simantics.district.network.visualisations.model.ColorBarOptions.ColorBarsSize;
+import org.simantics.district.network.visualisations.model.DynamicColorContribution;
+import org.simantics.district.network.visualisations.model.DynamicColorMap;
+import org.simantics.district.network.visualisations.model.DynamicSizeContribution;
+import org.simantics.district.network.visualisations.model.DynamicSizeMap;
+import org.simantics.district.network.visualisations.model.SizeBarOptions;
+import org.simantics.district.network.visualisations.model.SizeBarOptions.SizeBarsLocation;
+import org.simantics.district.network.visualisations.model.SizeBarOptions.SizeBarsSize;
 import org.simantics.layer0.Layer0;
 import org.simantics.maps.elevation.server.SingletonTiffTileInterface;
 import org.simantics.maps.elevation.server.prefs.MapsElevationServerPreferences;
 import org.simantics.modeling.ModelingResources;
 import org.simantics.modeling.adapters.NewCompositeActionFactory;
 import org.simantics.operation.Layer0X;
+import org.simantics.utils.datastructures.Pair;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -386,4 +401,203 @@ public class DistrictNetworkUtil {
         }
         return results;
     }
+
+    public static ColorBarOptions colorBarOptions(ReadGraph graph, Resource diagram) throws DatabaseException {
+        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+        Resource visualisation = graph.getPossibleObject(diagram, DN.Diagram_hasVisualisation);
+        if (visualisation != null) {
+            String colorBarLocation = graph.getPossibleRelatedValue(visualisation, DN.Diagram_Visualisations_ColorBarLocation, Bindings.STRING);
+            String colorBarSize = graph.getPossibleRelatedValue(visualisation, DN.Diagram_Visualisations_ColorBarSize, Bindings.STRING);
+            Boolean show = graph.getPossibleRelatedValue(visualisation, DN.Diagram_Visualisations_ShowColorBars, Bindings.BOOLEAN);
+            Boolean showTicks = graph.getPossibleRelatedValue(visualisation, DN.Diagram_Visualisations_ShowColorBarTicks, Bindings.BOOLEAN);
+            if (colorBarLocation != null) {
+                return new ColorBarOptions()
+                    .showColorBars(show != null ? show : false)
+                    .showColorBarsTicks(showTicks != null ? showTicks : false)
+                    .withLocation(ColorBarsLocation.valueOf(colorBarLocation))
+                    .withSize(ColorBarsSize.valueOf(colorBarSize));
+            }
+        }
+        return ColorBarOptions.useDefault();
+    }
+
+    public static void setColorBarOptions(WriteGraph graph, Resource diagram, ColorBarOptions options) throws DatabaseException {
+        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+        Resource visualisation = graph.getPossibleObject(diagram, DN.Diagram_hasVisualisation);
+        if (visualisation == null) {
+            Layer0 L0 = Layer0.getInstance(graph);
+            visualisation = graph.newResource();
+            graph.claim(visualisation, L0.InstanceOf, DN.Diagram_Visualisations);
+            graph.claimLiteral(visualisation, L0.HasName, "Visualisation");
+            graph.claim(diagram, DN.Diagram_hasVisualisation, visualisation);
+        }
+        graph.claimLiteral(visualisation, DN.Diagram_Visualisations_ColorBarLocation, options.getLocation().toString(), Bindings.STRING);
+        graph.claimLiteral(visualisation, DN.Diagram_Visualisations_ColorBarSize, options.getSize().toString(), Bindings.STRING);
+        graph.claimLiteral(visualisation, DN.Diagram_Visualisations_ShowColorBars, options.isShowColorBars(), Bindings.BOOLEAN);
+        graph.claimLiteral(visualisation, DN.Diagram_Visualisations_ShowColorBarTicks, options.isShowColorBarsTicks(), Bindings.BOOLEAN);
+    }
+
+    public static SizeBarOptions sizeBarOptions(ReadGraph graph, Resource diagram) throws DatabaseException {
+        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+        Resource visualisation = graph.getPossibleObject(diagram, DN.Diagram_hasVisualisation);
+        if (visualisation != null) {
+            String sizeBarLocation = graph.getPossibleRelatedValue(visualisation, DN.Diagram_Visualisations_SizeBarLocation, Bindings.STRING);
+            String sizeBarSize = graph.getPossibleRelatedValue(visualisation, DN.Diagram_Visualisations_SizeBarSize, Bindings.STRING);
+            Boolean show = graph.getPossibleRelatedValue(visualisation, DN.Diagram_Visualisations_ShowSizeBars, Bindings.BOOLEAN);
+            Boolean showTicks = graph.getPossibleRelatedValue(visualisation, DN.Diagram_Visualisations_ShowSizeBarTicks, Bindings.BOOLEAN);
+            if (sizeBarLocation != null) {
+                return new SizeBarOptions()
+                    .showSizeBars(show != null ? show : false)
+                    .showSizeBarsTicks(showTicks != null ? showTicks : false)
+                    .withLocation(SizeBarsLocation.valueOf(sizeBarLocation))
+                    .withSize(SizeBarsSize.valueOf(sizeBarSize));
+            }
+        }
+        return SizeBarOptions.useDefault();
+    }
+
+    public static void setSizeBarOptions(WriteGraph graph, Resource diagram, SizeBarOptions options) throws DatabaseException {
+        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+        Resource visualisation = graph.getPossibleObject(diagram, DN.Diagram_hasVisualisation);
+        if (visualisation == null) {
+            Layer0 L0 = Layer0.getInstance(graph);
+            visualisation = graph.newResource();
+            graph.claim(visualisation, L0.InstanceOf, DN.Diagram_Visualisations);
+            graph.claimLiteral(visualisation, L0.HasName, "Visualisation");
+            graph.claim(diagram, DN.Diagram_hasVisualisation, visualisation);
+        }
+        graph.claimLiteral(visualisation, DN.Diagram_Visualisations_SizeBarLocation, options.getLocation().toString(), Bindings.STRING);
+        graph.claimLiteral(visualisation, DN.Diagram_Visualisations_SizeBarSize, options.getSize().toString(), Bindings.STRING);
+        graph.claimLiteral(visualisation, DN.Diagram_Visualisations_ShowSizeBars, options.isShowSizeBars(), Bindings.BOOLEAN);
+        graph.claimLiteral(visualisation, DN.Diagram_Visualisations_ShowSizeBarTicks, options.isShowSizeBarsTicks(), Bindings.BOOLEAN);
+    }
+
+    public static Map<String, DynamicColorContribution> colorContributions(ReadGraph graph, Resource diagram) throws DatabaseException {
+        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+        Resource visualisation = graph.getPossibleObject(diagram, DN.Diagram_hasVisualisation);
+        if (visualisation == null) {
+            return Collections.emptyMap();
+        }
+        Map<String, DynamicColorContribution> contributions = new HashMap<>();
+        
+        Map<String, DynamicColorMap> colorMaps = DynamicVisualisationsContributions.dynamicColorMaps(graph);
+        
+        Collection<Resource> colorContributions = graph.getObjects(visualisation, DN.Diagram_Visualisations_colorContributions);
+        for (Resource colorContribution : colorContributions) {
+            String ucName = graph.getRelatedValue(colorContribution, DN.Diagram_Visualisations_colorContributionContributorName, Bindings.STRING);
+            String label = graph.getRelatedValue(colorContribution, DN.Diagram_Visualisations_colorContributionLabel, Bindings.STRING);
+            String moduleName = graph.getRelatedValue(colorContribution, DN.Diagram_Visualisations_colorContributionModuleName, Bindings.STRING);
+            String attributeName = graph.getRelatedValue(colorContribution, DN.Diagram_Visualisations_colorContributionModuleAttribute, Bindings.STRING);
+            String unit = graph.getRelatedValue(colorContribution, DN.Diagram_Visualisations_colorContributionUnit, Bindings.STRING);
+            Double variableGain = graph.getRelatedValue(colorContribution, DN.Diagram_Visualisations_colorContributionVariableGain, Bindings.DOUBLE);
+            Double variableBias = graph.getRelatedValue(colorContribution, DN.Diagram_Visualisations_colorContributionVariableBias, Bindings.DOUBLE);
+            String dynamicColorMap = graph.getRelatedValue(colorContribution, DN.Diagram_Visualisations_colorContributionDefaultColorMap, Bindings.STRING);
+            Double defaultMin = graph.getRelatedValue(colorContribution, DN.Diagram_Visualisations_colorContributionDefaultMin, Bindings.DOUBLE);
+            Double defaultMax = graph.getRelatedValue(colorContribution, DN.Diagram_Visualisations_colorContributionDefaultMax, Bindings.DOUBLE);
+            Boolean used = graph.getRelatedValue(colorContribution, DN.Diagram_Visualisations_colorContributionUsed, Bindings.BOOLEAN);
+            Boolean useDefault = graph.getRelatedValue(colorContribution, DN.Diagram_Visualisations_colorContributionUseDefault, Bindings.BOOLEAN);
+            DynamicColorContribution dynamicColorContribution = new DynamicColorContribution(label, moduleName, attributeName, unit, variableGain, variableBias, colorMaps.get(dynamicColorMap), defaultMin, defaultMax);
+            dynamicColorContribution.setUsed(used != null ? used : false);
+            dynamicColorContribution.setUseDefault(useDefault != null ? useDefault : false);
+            contributions.put(ucName, dynamicColorContribution);
+        }
+        return contributions;
+    }
+    
+    public static void setColorContributions(WriteGraph graph, Resource diagram, List<Pair<String, DynamicColorContribution>> collect) throws DatabaseException {
+        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+        Resource visualisation = graph.getPossibleObject(diagram, DN.Diagram_hasVisualisation);
+        if (visualisation == null) {
+            Layer0 L0 = Layer0.getInstance(graph);
+            visualisation = graph.newResource();
+            graph.claim(visualisation, L0.InstanceOf, DN.Diagram_Visualisations);
+            graph.claimLiteral(visualisation, L0.HasName, "Visualisation");
+            graph.claim(diagram, DN.Diagram_hasVisualisation, visualisation);
+        }
+        graph.deny(visualisation, DN.Diagram_Visualisations_colorContributions);
+        for (Pair<String, DynamicColorContribution> coll : collect) {
+            Resource colorContribution = graph.newResource();
+            
+            DynamicColorContribution contr = coll.second;
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionContributorName, coll.first);
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionLabel, contr.getLabel());
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionModuleName, contr.getModuleName());
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionModuleAttribute, contr.getAttributeName());
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionUnit, contr.getUnit());
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionVariableGain, contr.getVariableGain());
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionVariableBias, contr.getVariableBias());
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionDefaultColorMap, contr.getDefaultColorMap().getLabel());
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionDefaultMin, contr.getDefaultMin());
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionDefaultMax, contr.getDefaultMax());
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionUsed, contr.isUsed());
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionUseDefault, contr.isUseDefault());
+            
+            graph.claim(visualisation, DN.Diagram_Visualisations_colorContributions, colorContribution);
+        }
+    }
+
+    public static Map<String, DynamicSizeContribution> sizeContributions(ReadGraph graph, Resource diagram) throws DatabaseException {
+        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+        Resource visualisation = graph.getPossibleObject(diagram, DN.Diagram_hasVisualisation);
+        if (visualisation == null) {
+            return Collections.emptyMap();
+        }
+        Map<String, DynamicSizeContribution> contributions = new HashMap<>();
+        
+        Map<String, DynamicSizeMap> sizeMaps = DynamicVisualisationsContributions.dynamicSizeMaps(graph);
+        
+        Collection<Resource> colorContributions = graph.getObjects(visualisation, DN.Diagram_Visualisations_sizeContributions);
+        for (Resource colorContribution : colorContributions) {
+            String ucName = graph.getRelatedValue(colorContribution, DN.Diagram_Visualisations_sizeContributionContributorName, Bindings.STRING);
+            String label = graph.getRelatedValue(colorContribution, DN.Diagram_Visualisations_sizeContributionLabel, Bindings.STRING);
+            String moduleName = graph.getRelatedValue(colorContribution, DN.Diagram_Visualisations_sizeContributionModuleName, Bindings.STRING);
+            String attributeName = graph.getRelatedValue(colorContribution, DN.Diagram_Visualisations_sizeContributionModuleAttribute, Bindings.STRING);
+            String unit = graph.getRelatedValue(colorContribution, DN.Diagram_Visualisations_sizeContributionUnit, Bindings.STRING);
+            Double variableGain = graph.getRelatedValue(colorContribution, DN.Diagram_Visualisations_sizeContributionVariableGain, Bindings.DOUBLE);
+            Double variableBias = graph.getRelatedValue(colorContribution, DN.Diagram_Visualisations_sizeContributionVariableBias, Bindings.DOUBLE);
+            String dynamicSizeMap = graph.getRelatedValue(colorContribution, DN.Diagram_Visualisations_sizeContributionDefaultSizeMap, Bindings.STRING);
+            Double defaultMin = graph.getRelatedValue(colorContribution, DN.Diagram_Visualisations_sizeContributionDefaultMin, Bindings.DOUBLE);
+            Double defaultMax = graph.getRelatedValue(colorContribution, DN.Diagram_Visualisations_sizeContributionDefaultMax, Bindings.DOUBLE);
+            Boolean used = graph.getRelatedValue(colorContribution, DN.Diagram_Visualisations_sizeContributionUsed, Bindings.BOOLEAN);
+            Boolean useDefault = graph.getRelatedValue(colorContribution, DN.Diagram_Visualisations_sizeContributionUseDefault, Bindings.BOOLEAN);
+            DynamicSizeContribution dsc = new DynamicSizeContribution(label, moduleName, attributeName, unit, variableGain, variableBias, sizeMaps.get(dynamicSizeMap), defaultMin, defaultMax);
+            dsc.setUsed(used != null ? used : false);
+            dsc.setUseDefault(useDefault != null ? useDefault : false);
+            contributions.put(ucName, dsc);
+        }
+        return contributions;
+    }
+    
+    public static void setSizeContributions(WriteGraph graph, Resource diagram, List<Pair<String, DynamicSizeContribution>> collect) throws DatabaseException {
+        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+        Resource visualisation = graph.getPossibleObject(diagram, DN.Diagram_hasVisualisation);
+        if (visualisation == null) {
+            Layer0 L0 = Layer0.getInstance(graph);
+            visualisation = graph.newResource();
+            graph.claim(visualisation, L0.InstanceOf, DN.Diagram_Visualisations);
+            graph.claimLiteral(visualisation, L0.HasName, "Visualisation");
+            graph.claim(diagram, DN.Diagram_hasVisualisation, visualisation);
+        }
+        graph.deny(visualisation, DN.Diagram_Visualisations_sizeContributions);
+        for (Pair<String, DynamicSizeContribution> coll : collect) {
+            Resource colorContribution = graph.newResource();
+            
+            DynamicSizeContribution contr = coll.second;
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_sizeContributionContributorName, coll.first);
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_sizeContributionLabel, contr.getLabel());
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_sizeContributionModuleName, contr.getModuleName());
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_sizeContributionModuleAttribute, contr.getAttributeName());
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_sizeContributionUnit, contr.getUnit());
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_sizeContributionVariableGain, contr.getVariableGain());
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_sizeContributionVariableBias, contr.getVariableBias());
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_sizeContributionDefaultSizeMap, contr.getDefaultSizeMap().getLabel());
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_sizeContributionDefaultMin, contr.getDefaultMin());
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_sizeContributionDefaultMax, contr.getDefaultMax());
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_sizeContributionUsed, contr.isUsed());
+            graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_sizeContributionUseDefault, contr.isUseDefault());
+            
+            graph.claim(visualisation, DN.Diagram_Visualisations_sizeContributions, colorContribution);
+        }
+    }
+
 }
index 859faa67e999be5ae09b63dfdcfdab0b91d97302..fe0a1fe7f2ebce8bbbfdec501fce0a0032b6e544 100644 (file)
@@ -1,16 +1,28 @@
 package org.simantics.district.network.profile;
 
 import java.awt.Color;
+import java.util.Map;
 
 import org.simantics.Simantics;
+import org.simantics.databoard.Bindings;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.db.layer0.variable.Variables;
+import org.simantics.district.network.ontology.DistrictNetworkResource;
+import org.simantics.district.network.visualisations.model.DynamicColorContribution;
+import org.simantics.district.network.visualisations.model.DynamicColorMap;
+import org.simantics.district.network.visualisations.model.DynamicVisualisation;
+import org.simantics.layer0.Layer0;
+import org.simantics.modeling.ModelingResources;
 import org.simantics.scenegraph.INode;
 import org.simantics.scenegraph.g2d.nodes.SingleElementNode;
 import org.simantics.scenegraph.profile.EvaluationContext;
 import org.simantics.scenegraph.profile.common.ProfileVariables;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * @author Tuukka Lehtonen
@@ -18,14 +30,69 @@ import org.simantics.scenegraph.profile.common.ProfileVariables;
  */
 public class DNElementColorStyle extends ThrottledStyleBase<Color> {
 
-       private static final boolean DEBUG = false;
+    private static final Logger LOGGER = LoggerFactory.getLogger(DNElementColorStyle.class);
+
+    private static final boolean DEBUG = false;
 
        @Override
        public Color calculateThrottledStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource groupItem) throws DatabaseException {
-               DiagramSettings ds = graph.syncRequest(new DiagramSettingsRequest(runtimeDiagram), TransientCacheAsyncListener.instance());
-               // Prevent PendingVariableExceptions from coming through
-               boolean wasSynchronous = graph.setSynchronous(true);
-               try {
+           
+        DynamicVisualisation dv = graph.syncRequest(new RuntimeDynamicVisualisationsRequest(runtimeDiagram),
+                TransientCacheAsyncListener.instance());
+
+        DiagramSettings ds = graph.syncRequest(new DiagramSettingsRequest(runtimeDiagram), TransientCacheAsyncListener.instance());
+        // Prevent PendingVariableExceptions from coming through
+        boolean wasSynchronous = graph.setSynchronous(true);
+        try {
+            if (dv != null) {
+                Layer0 L0 = Layer0.getInstance(graph);
+                DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+                ModelingResources MOD = ModelingResources.getInstance(graph);
+                Resource mapping = graph.getSingleObject(groupItem, DN.HasMapping);
+            
+                Map<String, DynamicColorContribution> colorContributions = dv.getColorContributions();
+                String mappingName = graph.getRelatedValue(mapping, L0.HasName);
+                DynamicColorContribution dcc = colorContributions.get(mappingName);
+                if (dcc != null && dcc.isUsed()) {
+    
+                    Resource mappedComponent = graph.getPossibleObject(groupItem, DN.MappedComponent);
+                    if (mappedComponent != null) {
+    
+                        Resource component = graph.getSingleObject(mappedComponent, MOD.ElementToComponent);
+                        Variable variable = Variables.getVariable(graph, component);
+                        Variable possibleActiveVariable = Variables.possibleActiveVariable(graph, variable);
+                        if (possibleActiveVariable != null) {
+    
+                            Variable module = possibleActiveVariable.getPossibleChild(graph, dcc.getModuleName());
+                            if (module != null) {
+                                Variable attribute = module.getPossibleProperty(graph, dcc.getAttributeName());
+                                if (attribute != null) {
+                                    Double possibleValue = attribute.getPossibleValue(graph, Bindings.DOUBLE);
+                                    if (possibleValue != null) {
+                                        // here we do the adjusting according to spec in #15038
+                                        double adjustedValue = possibleValue.doubleValue() * dcc.getVariableGain() + dcc.getVariableBias();
+                                        DynamicColorMap defaultColorMap = dcc.getDefaultColorMap();
+                                        Color color = defaultColorMap.getColor(adjustedValue, dcc.getDefaultMin(), dcc.getDefaultMax());
+                                        return color;
+                                    } else {
+                                        LOGGER.warn("No value for {}", attribute.getURI(graph));
+                                    }
+                                } else {
+                                    LOGGER.warn("Wrong attribute name {} for {} !!", dcc.getAttributeName(), module.getURI(graph));
+                                }
+                            } else {
+                                LOGGER.warn("Wrong modulename {} for {} !!", dcc.getModuleName(), possibleActiveVariable.getURI(graph));
+                            }
+                        } else {
+                            LOGGER.debug("No active experiment for {}", variable.getURI(graph));
+                        }
+                    } else {
+                        LOGGER.debug("No mapped component for {} to calculate dynamic color style", groupItem);
+                    }
+                }
+            }
+                   
+            // the old implementation here
                        if (ds.elementColoringFunction.isPresent()) {
                                if (DEBUG)
                                        System.out.print("elementColoringFunction: " + ds.elementColoringFunction + "(" + groupItem + "): ");
diff --git a/org.simantics.district.network/src/org/simantics/district/network/profile/DNElementSizeStyle.java b/org.simantics.district.network/src/org/simantics/district/network/profile/DNElementSizeStyle.java
new file mode 100644 (file)
index 0000000..990aa4d
--- /dev/null
@@ -0,0 +1,127 @@
+package org.simantics.district.network.profile;
+
+import java.util.Map;
+
+import org.simantics.databoard.Bindings;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.db.layer0.variable.Variables;
+import org.simantics.district.network.ontology.DistrictNetworkResource;
+import org.simantics.district.network.visualisations.model.DynamicSizeContribution;
+import org.simantics.district.network.visualisations.model.DynamicSizeMap;
+import org.simantics.district.network.visualisations.model.DynamicVisualisation;
+import org.simantics.layer0.Layer0;
+import org.simantics.modeling.ModelingResources;
+import org.simantics.scenegraph.INode;
+import org.simantics.scenegraph.g2d.G2DSceneGraph;
+import org.simantics.scenegraph.g2d.nodes.SingleElementNode;
+import org.simantics.scenegraph.profile.EvaluationContext;
+import org.simantics.scenegraph.profile.common.ProfileVariables;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author Jani Simomaa
+ */
+public class DNElementSizeStyle extends ThrottledStyleBase<Double> {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(DNElementSizeStyle.class);
+    private static final boolean DEBUG = false;
+    
+    private static final Double PENDING = Double.NaN;
+    private static final Double ONE = 1.0;
+
+       @Override
+       public Double calculateThrottledStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource groupItem) throws DatabaseException {
+           
+        DynamicVisualisation dv = graph.syncRequest(new RuntimeDynamicVisualisationsRequest(runtimeDiagram),
+                TransientCacheAsyncListener.instance());
+
+        // Prevent PendingVariableExceptions from coming through
+        boolean wasSynchronous = graph.setSynchronous(true);
+        try {
+            if (dv != null) {
+                Layer0 L0 = Layer0.getInstance(graph);
+                DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+                ModelingResources MOD = ModelingResources.getInstance(graph);
+                Resource mapping = graph.getSingleObject(groupItem, DN.HasMapping);
+            
+                Map<String, DynamicSizeContribution> sizeContributions = dv.getSizeContributions();
+                String mappingName = graph.getRelatedValue(mapping, L0.HasName);
+                DynamicSizeContribution dsc = sizeContributions.get(mappingName);
+                if (dsc != null && dsc.isUsed()) {
+    
+                    Resource mappedComponent = graph.getPossibleObject(groupItem, DN.MappedComponent);
+                    if (mappedComponent != null) {
+    
+                        Resource component = graph.getSingleObject(mappedComponent, MOD.ElementToComponent);
+                        Variable variable = Variables.getVariable(graph, component);
+                        Variable possibleActiveVariable = Variables.possibleActiveVariable(graph, variable);
+                        if (possibleActiveVariable != null) {
+    
+                            Variable module = possibleActiveVariable.getPossibleChild(graph, dsc.getModuleName());
+                            if (module != null) {
+                                Variable attribute = module.getPossibleProperty(graph, dsc.getAttributeName());
+                                if (attribute != null) {
+                                    Double possibleValue = attribute.getPossibleValue(graph, Bindings.DOUBLE);
+                                    if (possibleValue != null) {
+                                        // here we do the adjusting according to spec in #15038
+                                        double adjustedValue = possibleValue.doubleValue() * dsc.getVariableGain() + dsc.getVariableBias();
+                                        DynamicSizeMap defaultSizeMap = dsc.getDefaultSizeMap();
+                                        double size = defaultSizeMap.getSize(adjustedValue, dsc.getDefaultMin(), dsc.getDefaultMax());
+                                        return size;
+                                    } else {
+                                        LOGGER.warn("No value for {}", attribute.getURI(graph));
+                                    }
+                                } else {
+                                    LOGGER.warn("Wrong attribute name {} for {} !!", dsc.getAttributeName(), module.getURI(graph));
+                                }
+                            } else {
+                                LOGGER.warn("Wrong modulename {} for {} !!", dsc.getModuleName(), possibleActiveVariable.getURI(graph));
+                            }
+                        } else {
+                            LOGGER.debug("No active experiment for {}", variable.getURI(graph));
+                        }
+                    } else {
+                        LOGGER.debug("No mapped component for {} to calculate dynamic size style", groupItem);
+                    }
+                }
+            }
+               }
+               finally {
+                       graph.setSynchronous(wasSynchronous);
+               }
+               return null;
+       }
+
+       @Override
+       public void applyThrottledStyleForNode(EvaluationContext observer, INode node, Double value) {
+        //System.out.println("apply: " + node + " : " + value);
+        SingleElementNode n = (SingleElementNode) node;
+        if (value == PENDING) {
+            ((G2DSceneGraph)node.getRootNode()).setPending(node);
+        } else {
+            ((G2DSceneGraph)node.getRootNode()).clearPending(node);
+        }
+        if (value == null)
+            value = ONE;
+        for (INode nn : n.getNodes()) {
+            ProfileVariables.claimNodeProperty(nn, "size", value, observer);
+            ProfileVariables.claimNodeProperty(nn, "stroke", value, observer);
+        }
+       }
+
+       @Override
+       protected void cleanupStyleForNode(EvaluationContext evaluationContext, INode node) {
+        ((G2DSceneGraph)node.getRootNode()).clearPending(node);
+        SingleElementNode n = (SingleElementNode) node;
+        for (INode nn : n.getNodes()) {
+            ProfileVariables.claimNodeProperty(nn, "size", ONE, evaluationContext);
+            ProfileVariables.claimNodeProperty(nn, "stroke", ONE, evaluationContext);
+        }
+       }
+
+}
diff --git a/org.simantics.district.network/src/org/simantics/district/network/profile/DynamicVisualisationsRequest.java b/org.simantics.district.network/src/org/simantics/district/network/profile/DynamicVisualisationsRequest.java
new file mode 100644 (file)
index 0000000..c4d9d20
--- /dev/null
@@ -0,0 +1,43 @@
+package org.simantics.district.network.profile;
+
+import java.util.Map;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.ResourceRead;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.district.network.DistrictNetworkUtil;
+import org.simantics.district.network.ontology.DistrictNetworkResource;
+import org.simantics.district.network.visualisations.model.ColorBarOptions;
+import org.simantics.district.network.visualisations.model.DynamicColorContribution;
+import org.simantics.district.network.visualisations.model.DynamicSizeContribution;
+import org.simantics.district.network.visualisations.model.DynamicVisualisation;
+import org.simantics.district.network.visualisations.model.SizeBarOptions;
+import org.simantics.layer0.Layer0;
+
+/**
+ * @author Jani Simomaa
+ */
+public class DynamicVisualisationsRequest extends ResourceRead<DynamicVisualisation> {
+
+    public DynamicVisualisationsRequest(Resource diagram) {
+        super(diagram);
+    }
+
+    @Override
+    public DynamicVisualisation perform(ReadGraph graph) throws DatabaseException {
+        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+        Resource visualisationResource = graph.getPossibleObject(resource, DN.Diagram_hasVisualisation);
+        if (visualisationResource != null) {
+            String name = graph.getRelatedValue(visualisationResource, Layer0.getInstance(graph).HasName);
+            Map<String, DynamicColorContribution> colorContributions = DistrictNetworkUtil.colorContributions(graph, resource);
+            ColorBarOptions colorBarOptions = DistrictNetworkUtil.colorBarOptions(graph, resource);
+            Map<String, DynamicSizeContribution> sizeContributions = DistrictNetworkUtil.sizeContributions(graph, resource);
+            SizeBarOptions sizeBarOptions = DistrictNetworkUtil.sizeBarOptions(graph, resource);
+            DynamicVisualisation visualisation = new DynamicVisualisation(name, colorContributions, colorBarOptions, sizeContributions, sizeBarOptions);
+            return visualisation; 
+        }
+        return null;
+    }
+
+}
diff --git a/org.simantics.district.network/src/org/simantics/district/network/profile/RuntimeDynamicVisualisationsRequest.java b/org.simantics.district.network/src/org/simantics/district/network/profile/RuntimeDynamicVisualisationsRequest.java
new file mode 100644 (file)
index 0000000..a29b311
--- /dev/null
@@ -0,0 +1,30 @@
+package org.simantics.district.network.profile;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
+import org.simantics.db.common.request.ResourceRead;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.district.network.visualisations.model.DynamicVisualisation;
+
+/**
+ * @author Jani Simomaa
+ */
+public class RuntimeDynamicVisualisationsRequest extends ResourceRead<DynamicVisualisation> {
+
+    public RuntimeDynamicVisualisationsRequest(Resource runtimeDiagram) {
+        super(runtimeDiagram);
+    }
+
+    @Override
+    public DynamicVisualisation perform(ReadGraph graph) throws DatabaseException {
+        DiagramResource DIA = DiagramResource.getInstance(graph);
+        Resource diagram = graph.getPossibleObject(resource, DIA.RuntimeDiagram_HasConfiguration);
+        if (diagram != null) {
+            return graph.syncRequest(new DynamicVisualisationsRequest(diagram), TransientCacheAsyncListener.instance());
+        }
+        return null;
+    }
+
+}
diff --git a/org.simantics.district.network/src/org/simantics/district/network/visualisations/DynamicVisualisationsContributions.java b/org.simantics.district.network/src/org/simantics/district/network/visualisations/DynamicVisualisationsContributions.java
new file mode 100644 (file)
index 0000000..45e52fb
--- /dev/null
@@ -0,0 +1,278 @@
+package org.simantics.district.network.visualisations;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Supplier;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.simantics.NameLabelUtil;
+import org.simantics.Simantics;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.NamedResource;
+import org.simantics.db.common.request.ObjectsWithSupertype;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.util.Layer0Utils;
+import org.simantics.district.network.visualisations.model.DynamicColorContribution;
+import org.simantics.district.network.visualisations.model.DynamicColorMap;
+import org.simantics.district.network.visualisations.model.DynamicSizeContribution;
+import org.simantics.district.network.visualisations.model.DynamicSizeMap;
+import org.simantics.layer0.Layer0;
+import org.simantics.scl.compiler.top.ValueNotFound;
+import org.simantics.scl.osgi.SCLOsgi;
+import org.simantics.scl.runtime.SCLContext;
+import org.simantics.scl.runtime.tuple.Tuple0;
+import org.simantics.structural.stubs.StructuralResource2;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DynamicVisualisationsContributions {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(DynamicVisualisationsContributions.class);
+
+    private static final String COMMON_DYNAMIC_VISUALISATIONS_MODULE = "CommonDynamicVisualisations";
+    private static final String COLOR_MAP_CONTRIBUTION = "colorMapContribution";
+    private static final String SIZE_MAP_CONTRIBUTION = "sizeMapContribution";
+    
+    private static final String DYNAMIC_VISUALISATIONS_CONTRIBUTION_MODULE = "DynamicVisualisationsContribution";
+    private static final String COLOR_CONTRIBUTION = "colorContribution";
+    private static final String SIZE_CONTRIBUTION = "sizeContribution";
+
+    public static Map<String, DynamicColorMap> dynamicColorMaps(ReadGraph graph) throws DatabaseException {
+        List<Resource> sharedOntologies = Simantics.applySCL("Simantics/SharedOntologies", "getSharedOntologies", graph, Tuple0.INSTANCE);
+        
+        Map<String, DynamicColorMap> results = new HashMap<>();
+        Layer0 L0 = Layer0.getInstance(graph);
+        for (Resource sharedOntology : sharedOntologies) {
+            Resource sclModule = Layer0Utils.getPossibleChild(graph, sharedOntology, L0.SCLModule, COMMON_DYNAMIC_VISUALISATIONS_MODULE);
+            if (sclModule != null) {
+                String moduleURI = graph.getURI(sclModule);
+                Object oldGraph = SCLContext.getCurrent().get("graph");
+                try {
+                    // let's put the graph to SCLContext for resolving the color maps
+                    SCLContext.getCurrent().put("graph", graph);
+                    @SuppressWarnings("unchecked")
+                    List<DynamicColorMap> result = (List<DynamicColorMap>) SCLOsgi.MODULE_REPOSITORY.getValue(moduleURI, COLOR_MAP_CONTRIBUTION);
+                    
+                    for (DynamicColorMap colorMap : result) {
+                        results.put(colorMap.getLabel(), colorMap);
+                    }
+                } catch (ValueNotFound e) {
+                    e.printStackTrace();
+                } finally {
+                    SCLContext.getCurrent().put("graph", oldGraph);
+                }
+            }
+        }
+        return results;
+    }
+
+    public static Map<String, DynamicSizeMap> dynamicSizeMaps(ReadGraph graph) throws DatabaseException {
+        List<Resource> sharedOntologies = Simantics.applySCL("Simantics/SharedOntologies", "getSharedOntologies", graph, Tuple0.INSTANCE);
+        
+        Map<String, DynamicSizeMap> results = new HashMap<>();
+        Layer0 L0 = Layer0.getInstance(graph);
+        for (Resource sharedOntology : sharedOntologies) {
+            Resource sclModule = Layer0Utils.getPossibleChild(graph, sharedOntology, L0.SCLModule, COMMON_DYNAMIC_VISUALISATIONS_MODULE);
+            if (sclModule != null) {
+                String moduleURI = graph.getURI(sclModule);
+                Object oldGraph = SCLContext.getCurrent().get("graph");
+                try {
+                    // let's put the graph to SCLContext for resolving the color maps
+                    SCLContext.getCurrent().put("graph", graph);
+                    @SuppressWarnings("unchecked")
+                    List<DynamicSizeMap> result = (List<DynamicSizeMap>) SCLOsgi.MODULE_REPOSITORY.getValue(moduleURI, SIZE_MAP_CONTRIBUTION);
+                    
+                    for (DynamicSizeMap sizeMap : result) {
+                        results.put(sizeMap.getLabel(), sizeMap);
+                    }
+                } catch (ValueNotFound e) {
+                    e.printStackTrace();
+                } finally {
+                    SCLContext.getCurrent().put("graph", oldGraph);
+                }
+            }
+        }
+        return results;
+    }
+
+    public static Collection<DynamicColoringObject> dynamicColoringObjects(ReadGraph graph) throws DatabaseException {
+        
+        List<Resource> sharedOntologies = Simantics.applySCL("Simantics/SharedOntologies", "getSharedOntologies", graph, Tuple0.INSTANCE);
+        
+        List<DynamicColoringObject> results = new ArrayList<>();
+        
+        for (Resource sharedOntology : sharedOntologies) {
+            Collection<Resource> findByType = graph.syncRequest(new ObjectsWithSupertype(sharedOntology, Layer0.getInstance(graph).ConsistsOf, StructuralResource2.getInstance(graph).Component));
+            //Collection<Resource> findByType = QueryIndexUtils.searchByType(graph, sharedOntology, );
+            for (Resource find : findByType) {
+                NamedResource moduleType = new NamedResource(NameLabelUtil.modalName(graph, find), find);
+                DynamicColoringObject dynamicColoringObject = dynamicColoringObject(graph, moduleType);
+                if (dynamicColoringObject != null)
+                    results.add(dynamicColoringObject);
+            }
+        }
+        return results;
+    }
+    
+    public static Collection<DynamicSizingObject> dynamicSizingObjects(ReadGraph graph) throws DatabaseException {
+        
+        List<Resource> sharedOntologies = Simantics.applySCL("Simantics/SharedOntologies", "getSharedOntologies", graph, Tuple0.INSTANCE);
+        
+        List<DynamicSizingObject> results = new ArrayList<>();
+        
+        for (Resource sharedOntology : sharedOntologies) {
+            Collection<Resource> findByType = graph.syncRequest(new ObjectsWithSupertype(sharedOntology, Layer0.getInstance(graph).ConsistsOf, StructuralResource2.getInstance(graph).Component));
+            //Collection<Resource> findByType = QueryIndexUtils.searchByType(graph, sharedOntology, );
+            for (Resource find : findByType) {
+                NamedResource moduleType = new NamedResource(NameLabelUtil.modalName(graph, find), find);
+                DynamicSizingObject dynamicSizingObject = dynamicSizingObject(graph, moduleType);
+                if (dynamicSizingObject != null)
+                    results.add(dynamicSizingObject);
+            }
+        }
+        return results;
+    }
+    
+    private static DynamicColoringObject dynamicColoringObject(ReadGraph graph, NamedResource moduleType) throws DatabaseException {
+        Layer0 L0 = Layer0.getInstance(graph);
+        Resource sclModule = Layer0Utils.getPossibleChild(graph, moduleType.getResource(), L0.SCLModule, DYNAMIC_VISUALISATIONS_CONTRIBUTION_MODULE);
+        if (sclModule != null) {
+            String moduleURI = graph.getURI(sclModule);
+            return new DynamicColoringObject(moduleType, getDynamicColorContributionSupplier(moduleURI, COLOR_CONTRIBUTION));
+        }
+        return null;
+    }
+    
+//    private static DynamicColoringMap dynamicColoringMap(ReadGraph graph, NamedResource moduleType) throws DatabaseException {
+//        Layer0 L0 = Layer0.getInstance(graph);
+//        Resource sclModule = Layer0Utils.getPossibleChild(graph, moduleType.getResource(), L0.SCLModule, DYNAMIC_VISUALISATIONS_CONTRIBUTION_MODULE);
+//        if (sclModule != null) {
+//            String moduleURI = graph.getURI(sclModule);
+//            return new DynamicColoringMap(moduleType, getDynamicColoringMapSupplier(moduleURI, COLOR_CONTRIBUTION));
+//        }
+//        return null;
+//    }
+    
+    private static DynamicSizingObject dynamicSizingObject(ReadGraph graph, NamedResource moduleType) throws DatabaseException {
+        Layer0 L0 = Layer0.getInstance(graph);
+        Resource sclModule = Layer0Utils.getPossibleChild(graph, moduleType.getResource(), L0.SCLModule, DYNAMIC_VISUALISATIONS_CONTRIBUTION_MODULE);
+        if (sclModule != null) {
+            String moduleURI = graph.getURI(sclModule);
+            return new DynamicSizingObject(moduleType, getDynamicSizeContributionSupplier(moduleURI, SIZE_CONTRIBUTION));
+        }
+        return null;
+    }
+
+    private static Supplier<Stream<DynamicColorMap>> getDynamicColorMapSupplier(String uri, String expressionText) {
+        return () -> {
+            try {
+                @SuppressWarnings("unchecked")
+                List<DynamicColorMap> result = (List<DynamicColorMap>) SCLOsgi.MODULE_REPOSITORY.getValue(uri, expressionText);
+                return result.stream();//result.stream().map(DynamicColorContribution::fromTuple9);
+            } catch (ValueNotFound e) {
+                LOGGER.error("Could not find contributions", e);
+                //throw new RuntimeException(e);
+                return Stream.empty();
+            }
+        };
+    }
+
+    private static Supplier<Stream<DynamicColorContribution>> getDynamicColorContributionSupplier(String uri, String expressionText) {
+        return () -> {
+            try {
+                @SuppressWarnings("unchecked")
+                List<DynamicColorContribution> result = (List<DynamicColorContribution>) SCLOsgi.MODULE_REPOSITORY.getValue(uri, expressionText);
+                return result.stream();//result.stream().map(DynamicColorContribution::fromTuple9);
+            } catch (ValueNotFound e) {
+                LOGGER.error("Could not find contributions", e);
+                //throw new RuntimeException(e);
+                return Stream.empty();
+            }
+        };
+    }
+
+    private static Supplier<Stream<DynamicSizeContribution>> getDynamicSizeContributionSupplier(String uri, String expressionText) {
+        return () -> {
+            try {
+                @SuppressWarnings("unchecked")
+                List<DynamicSizeContribution> result = (List<DynamicSizeContribution>) SCLOsgi.MODULE_REPOSITORY.getValue(uri, expressionText);
+                return result.stream();//result.stream().map(DynamicColorContribution::fromTuple9);
+            } catch (ValueNotFound e) {
+                LOGGER.error("Could not find contributions", e);
+                //throw new RuntimeException(e);
+                return Stream.empty();
+            }
+        };
+    }
+
+    public static class DynamicColoringObject {
+
+        private final NamedResource coloringObject;
+        private final Supplier<Stream<DynamicColorContribution>> colorContributionSupplier;
+        private Map<String, DynamicColorContribution> colorContributions;
+
+        public DynamicColoringObject(NamedResource coloringObject, Supplier<Stream<DynamicColorContribution>> colorContributionSupplier) {
+            this.coloringObject = coloringObject;
+            this.colorContributionSupplier = colorContributionSupplier;
+        }
+
+        public NamedResource getColoringObject() {
+            return coloringObject;
+        }
+
+        public Map<String, DynamicColorContribution> getColorContributions() {
+            if (colorContributions == null)
+                colorContributions = colorContributionSupplier.get().collect(Collectors.toMap(c -> c.getLabel(), c -> c));
+            return colorContributions;
+        }
+    }
+
+    public static class DynamicColoringMap {
+
+        private final NamedResource coloringObject;
+        private final Supplier<Stream<DynamicColorMap>> colorContributionSupplier;
+        private Map<String, DynamicColorMap> colorContributions;
+
+        public DynamicColoringMap(NamedResource coloringObject, Supplier<Stream<DynamicColorMap>> colorContributionSupplier) {
+            this.coloringObject = coloringObject;
+            this.colorContributionSupplier = colorContributionSupplier;
+        }
+
+        public NamedResource getColoringObject() {
+            return coloringObject;
+        }
+
+        public Map<String, DynamicColorMap> getColorContributions() {
+            if (colorContributions == null)
+                colorContributions = colorContributionSupplier.get().collect(Collectors.toMap(c -> c.getLabel(), c -> c));
+            return colorContributions;
+        }
+    }
+    
+    public static class DynamicSizingObject {
+
+        private final NamedResource sizingObject;
+        private final Supplier<Stream<DynamicSizeContribution>> sizeContributionSupplier;
+        private Map<String, DynamicSizeContribution> sizeContributions;
+        
+        public DynamicSizingObject(NamedResource coloringObject, Supplier<Stream<DynamicSizeContribution>> sizeContributionSupplier) {
+            this.sizingObject = coloringObject;
+            this.sizeContributionSupplier = sizeContributionSupplier;
+        }
+
+        public NamedResource getSizingObject() {
+            return sizingObject;
+        }
+
+        public Map<String, DynamicSizeContribution> getSizeContributions() {
+            if (sizeContributions == null)
+                sizeContributions = sizeContributionSupplier.get().collect(Collectors.toMap(c -> c.getLabel(), c -> c));
+            return sizeContributions;
+        }
+    }
+}
diff --git a/org.simantics.district.network/src/org/simantics/district/network/visualisations/VisualisationColoringObject.java b/org.simantics.district.network/src/org/simantics/district/network/visualisations/VisualisationColoringObject.java
new file mode 100644 (file)
index 0000000..c13bcd4
--- /dev/null
@@ -0,0 +1,56 @@
+package org.simantics.district.network.visualisations;
+
+public class VisualisationColoringObject {
+
+    private String label;
+    private boolean used;
+    private String variable;
+    private double min;
+    private double max;
+    private String unit;
+    private String colorMap;
+    private boolean isDefault;
+    
+    public VisualisationColoringObject(String label, boolean used, String variable, double min, double max, String unit, String colorMap, boolean isDefault) {
+        this.label = label;
+        this.used = used;
+        this.variable = variable;
+        this.min = min;
+        this.max = max;
+        this.unit = unit;
+        this.colorMap = colorMap;
+        this.isDefault = isDefault;
+    }
+    
+    public String getLabel() {
+        return label;
+    }
+    
+    public boolean isUsed() {
+        return used;
+    }
+    
+    public String getVariable() {
+        return variable;
+    }
+    
+    public double getMin() {
+        return min;
+    }
+    
+    public double getMax() {
+        return max;
+    }
+    
+    public String getUnit() {
+        return unit;
+    }
+    
+    public String getColorMap() {
+        return colorMap;
+    }
+    
+    public boolean isDefault() {
+        return isDefault;
+    }
+}
diff --git a/org.simantics.district.network/src/org/simantics/district/network/visualisations/model/ColorBarOptions.java b/org.simantics.district.network/src/org/simantics/district/network/visualisations/model/ColorBarOptions.java
new file mode 100644 (file)
index 0000000..a57ad91
--- /dev/null
@@ -0,0 +1,67 @@
+package org.simantics.district.network.visualisations.model;
+
+public class ColorBarOptions {
+
+    private boolean showColorBars;
+    private boolean showColorBarsTicks;
+    private ColorBarsLocation location;
+    private ColorBarsSize size;
+
+    public boolean isShowColorBars() {
+        return showColorBars;
+    }
+
+    public ColorBarOptions showColorBars(boolean show) {
+        this.showColorBars = show;
+        return this;
+    }
+
+    public boolean isShowColorBarsTicks() {
+        return showColorBarsTicks;
+    }
+
+    public ColorBarOptions showColorBarsTicks(boolean show) {
+        this.showColorBarsTicks = show;
+        return this;
+    }
+
+    public ColorBarsLocation getLocation() {
+        return location;
+    }
+
+    public ColorBarOptions withLocation(ColorBarsLocation location) {
+        this.location = location;
+        return this;
+    }
+
+    public ColorBarsSize getSize() {
+        return size;
+    }
+
+    public ColorBarOptions withSize(ColorBarsSize size) {
+        this.size = size;
+        return this;
+    }
+
+    public enum ColorBarsLocation {
+        NORTH, EAST, SOUTH, WEST
+    }
+
+    public enum ColorBarsSize {
+        SMALL(1), MEDIUM(2), LARGE(3);
+
+        int size;
+
+        ColorBarsSize(int size) {
+            this.size = size;
+        }
+
+        public int getSize() {
+            return size;
+        }
+    }
+
+    public static ColorBarOptions useDefault() {
+        return new ColorBarOptions().showColorBars(true).withLocation(ColorBarsLocation.EAST).withSize(ColorBarsSize.SMALL);
+    }
+}
diff --git a/org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicColorContribution.java b/org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicColorContribution.java
new file mode 100644 (file)
index 0000000..2839bcc
--- /dev/null
@@ -0,0 +1,83 @@
+package org.simantics.district.network.visualisations.model;
+
+public class DynamicColorContribution {
+
+    private String label;
+    private String moduleName;
+    private String attributeName;
+    private String unit;
+    private double variableGain;
+    private double variableBias;
+    private DynamicColorMap defaultColorMap;
+    private double defaultMin;
+    private double defaultMax;
+    
+    // for graph persistence only
+    private boolean used;
+    private boolean useDefault;
+
+    public DynamicColorContribution(String label, String moduleName, String attributeName, String unit,
+            double variableGain, double variableBias, DynamicColorMap defaultColorMap, double defaultMin, double defaultMax) {
+        this.label = label;
+        this.moduleName = moduleName;
+        this.attributeName = attributeName;
+        this.unit = unit;
+        this.variableGain = variableGain;
+        this.variableBias = variableBias;
+        this.defaultColorMap = defaultColorMap;
+        this.defaultMin = defaultMin;
+        this.defaultMax = defaultMax;
+    }
+
+    public String getLabel() {
+        return label;
+    }
+
+    public String getModuleName() {
+        return moduleName;
+    }
+
+    public String getAttributeName() {
+        return attributeName;
+    }
+
+    public String getUnit() {
+        return unit;
+    }
+    
+    public double getVariableGain() {
+        return variableGain;
+    }
+    
+    public double getVariableBias() {
+        return variableBias;
+    }
+    
+    public DynamicColorMap getDefaultColorMap() {
+        return defaultColorMap;
+    }
+    
+    public double getDefaultMin() {
+        return defaultMin;
+    }
+    
+    public double getDefaultMax() {
+        return defaultMax;
+    }
+    
+    public void setUsed(boolean used) {
+        this.used = used;
+    }
+    
+    public boolean isUsed() {
+        return used;
+    }
+    
+    public void setUseDefault(boolean useDefault) {
+        this.useDefault = useDefault;
+    }
+    
+    public boolean isUseDefault() {
+        return useDefault;
+    }
+}
\ No newline at end of file
diff --git a/org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicColorMap.java b/org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicColorMap.java
new file mode 100644 (file)
index 0000000..09cb579
--- /dev/null
@@ -0,0 +1,70 @@
+package org.simantics.district.network.visualisations.model;
+
+import java.awt.Color;
+import java.util.Arrays;
+import java.util.List;
+
+public class DynamicColorMap {
+    
+    static List<RGBIntensity> blues = Arrays.asList(new RGBIntensity(0, 0, 0.1), new RGBIntensity(0, 0, 0.5), new RGBIntensity(0, 0, 0.9));
+
+    public static final DynamicColorMap DEFAULT = new DynamicColorMap("default", blues);
+    
+    private String label;
+    private List<RGBIntensity> intensities;
+    
+    public DynamicColorMap(String label, List<RGBIntensity> intensities) {
+        this.label = label;
+        this.intensities = intensities;
+    }
+
+    public String getLabel() {
+        return label;
+    }
+
+    public List<RGBIntensity> getIntensities() {
+        return intensities;
+    }
+
+    public static class RGBIntensity {
+        
+        private double red;
+        private double green;
+        private double blue;
+        
+        public RGBIntensity(double red, double green, double blue) {
+            this.red = red;
+            this.green = green;
+            this.blue = blue;
+        }
+
+        public double getRed() {
+            return red;
+        }
+
+        public double getGreen() {
+            return green;
+        }
+
+        public double getBlue() {
+            return blue;
+        }
+    }
+
+    public Color getColor(double value, double defaultMin, double defaultMax) {
+        
+        double gap = defaultMax - defaultMin;
+        double singleGap = gap / getIntensities().size();
+        
+        int i = 0;
+        while (i < getIntensities().size() - 1) {
+            if (value <= defaultMin + (i * singleGap)) {
+                break;
+            }
+            i++;
+        }
+        
+        RGBIntensity intensity = getIntensities().get(i);
+        return new Color((float)intensity.getRed(), (float)intensity.getGreen(), (float)intensity.getBlue());
+    }
+}
diff --git a/org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicSizeContribution.java b/org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicSizeContribution.java
new file mode 100644 (file)
index 0000000..009c8c4
--- /dev/null
@@ -0,0 +1,83 @@
+package org.simantics.district.network.visualisations.model;
+
+public class DynamicSizeContribution {
+
+    private String label;
+    private String moduleName;
+    private String attributeName;
+    private String unit;
+    private double variableGain;
+    private double variableBias;
+    private DynamicSizeMap defaultSizeMap;
+    private double defaultMin;
+    private double defaultMax;
+    
+    // for graph persistence only
+    private boolean used;
+    private boolean useDefault;
+
+    public DynamicSizeContribution(String label, String moduleName, String attributeName, String unit,
+            double variableGain, double variableBias, DynamicSizeMap defaultSizeMap, double defaultMin, double defaultMax) {
+        this.label = label;
+        this.moduleName = moduleName;
+        this.attributeName = attributeName;
+        this.unit = unit;
+        this.variableGain = variableGain;
+        this.variableBias = variableBias;
+        this.defaultSizeMap = defaultSizeMap;
+        this.defaultMin = defaultMin;
+        this.defaultMax = defaultMax;
+    }
+
+    public String getLabel() {
+        return label;
+    }
+    
+    public String getModuleName() {
+        return moduleName;
+    }
+    
+    public String getAttributeName() {
+        return attributeName;
+    }
+
+    public String getUnit() {
+        return unit;
+    }
+    
+    public double getVariableGain() {
+        return variableGain;
+    }
+    
+    public double getVariableBias() {
+        return variableBias;
+    }
+    
+    public DynamicSizeMap getDefaultSizeMap() {
+        return defaultSizeMap;
+    }
+    
+    public double getDefaultMin() {
+        return defaultMin;
+    }
+    
+    public double getDefaultMax() {
+        return defaultMax;
+    }
+    
+    public boolean isUsed() {
+        return used;
+    }
+    
+    public void setUsed(boolean used) {
+        this.used = used;
+    }
+    
+    public boolean isUseDefault() {
+        return useDefault;
+    }
+    
+    public void setUseDefault(boolean useDefault) {
+        this.useDefault = useDefault;
+    }
+}
\ No newline at end of file
diff --git a/org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicSizeMap.java b/org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicSizeMap.java
new file mode 100644 (file)
index 0000000..7edb12b
--- /dev/null
@@ -0,0 +1,38 @@
+package org.simantics.district.network.visualisations.model;
+
+import java.util.List;
+
+public class DynamicSizeMap {
+
+    private String label;
+    private List<Double> sizes;
+
+    public DynamicSizeMap(String label, List<Double> sizes) {
+        this.label = label;
+        this.sizes = sizes;
+    }
+
+    public String getLabel() {
+        return label;
+    }
+    
+    public List<Double> getSizes() {
+        return sizes;
+    }
+
+    public double getSize(double value, double defaultMin, double defaultMax) {
+        
+        double gap = defaultMax - defaultMin;
+        double singleGap = gap / getSizes().size();
+        
+        int i = 0;
+        while (i < getSizes().size() - 1) {
+            if (value <= defaultMin + (i * singleGap)) {
+                break;
+            }
+            i++;
+        }
+        
+        return getSizes().get(i);
+    }
+}
diff --git a/org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicVisualisation.java b/org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicVisualisation.java
new file mode 100644 (file)
index 0000000..ea88e9d
--- /dev/null
@@ -0,0 +1,37 @@
+package org.simantics.district.network.visualisations.model;
+
+import java.util.Map;
+
+public class DynamicVisualisation {
+
+    private String name;
+
+    private Map<String, DynamicColorContribution> colorContributions;
+    private ColorBarOptions colorBarOptions;
+    private Map<String, DynamicSizeContribution> sizeContributions;
+    private SizeBarOptions sizeBarOptions;
+    
+    public DynamicVisualisation(String name, Map<String, DynamicColorContribution> colorContributions, ColorBarOptions colorBarOptions, Map<String, DynamicSizeContribution> sizeContributions, SizeBarOptions sizeBarOptions) {
+        this.name = name;
+        this.colorContributions = colorContributions;
+        this.colorBarOptions = colorBarOptions;
+        this.sizeContributions = sizeContributions;
+        this.sizeBarOptions = sizeBarOptions;
+    }
+
+    public Map<String, DynamicColorContribution> getColorContributions() {
+        return colorContributions;
+    }
+
+    public ColorBarOptions getColorBarOptions() {
+        return colorBarOptions;
+    }
+
+    public Map<String, DynamicSizeContribution> getSizeContributions() {
+        return sizeContributions;
+    }
+
+    public SizeBarOptions getSizeBarOptions() {
+        return sizeBarOptions;
+    }
+}
diff --git a/org.simantics.district.network/src/org/simantics/district/network/visualisations/model/SizeBarOptions.java b/org.simantics.district.network/src/org/simantics/district/network/visualisations/model/SizeBarOptions.java
new file mode 100644 (file)
index 0000000..14e9f47
--- /dev/null
@@ -0,0 +1,66 @@
+package org.simantics.district.network.visualisations.model;
+
+public class SizeBarOptions {
+
+    private boolean showColorBars;
+    private boolean showColorBarsTicks;
+    private SizeBarsLocation location;
+    private SizeBarsSize size;
+
+    public boolean isShowSizeBars() {
+        return showColorBars;
+    }
+
+    public SizeBarOptions showSizeBars(boolean show) {
+        this.showColorBars = show;
+        return this;
+    }
+
+    public boolean isShowSizeBarsTicks() {
+        return showColorBarsTicks;
+    }
+
+    public SizeBarOptions showSizeBarsTicks(boolean show) {
+        this.showColorBarsTicks = show;
+        return this;
+    }
+
+    public SizeBarsLocation getLocation() {
+        return location;
+    }
+
+    public SizeBarOptions withLocation(SizeBarsLocation location) {
+        this.location = location;
+        return this;
+    }
+
+    public SizeBarsSize getSize() {
+        return size;
+    }
+
+    public SizeBarOptions withSize(SizeBarsSize size) {
+        this.size = size;
+        return this;
+    }
+    public enum SizeBarsLocation {
+        NORTH, EAST, SOUTH, WEST
+    }
+
+    public enum SizeBarsSize {
+        SMALL(1), MEDIUM(2), LARGE(3);
+
+        int size;
+
+        SizeBarsSize(int size) {
+            this.size = size;
+        }
+
+        public double getSize() {
+            return size;
+        }
+    }
+
+    public static SizeBarOptions useDefault() {
+        return new SizeBarOptions().showSizeBars(true).withLocation(SizeBarsLocation.EAST).withSize(SizeBarsSize.SMALL);
+    }
+}