]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Add support for gradients in dynamic visualisations 88/3288/1
authorjsimomaa <jani.simomaa@gmail.com>
Wed, 25 Sep 2019 11:13:07 +0000 (14:13 +0300)
committerJani Simomaa <jani.simomaa@semantum.fi>
Fri, 27 Sep 2019 08:01:46 +0000 (08:01 +0000)
gitlab #59

Change-Id: Id0c2037168819ab78a0acf944df87fc01ca6611f
(cherry picked from commit a2c485af95024784aa9de3378759ee94b8caea2e)

16 files changed:
org.simantics.district.network.ontology/graph/DistrictNetwork.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/src/org/simantics/district/network/ui/DistrictDiagramViewer.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DynamicVisualisationContributionsNode.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsView.java
org.simantics.district.network/src/org/simantics/district/network/DistrictNetworkUtil.java
org.simantics.district.network/src/org/simantics/district/network/profile/ActiveDynamicVisualisationsRequest.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
org.simantics.district.network/src/org/simantics/district/network/profile/DynamicVisualisationsRequest.java
org.simantics.district.network/src/org/simantics/district/network/profile/RuntimeDynamicVisualisationsRequest.java
org.simantics.district.network/src/org/simantics/district/network/profile/ThrottledStyleBase.java
org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicColorMap.java
org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicSizeMap.java

index 592053e514bce43d880efdab5bf2168b1cb7c045..33408b2f863a25a7fdede3d2614f1daaad9ec402 100644 (file)
@@ -212,13 +212,17 @@ DN.Diagram.splitToMultipleEnabled <R L0.HasProperty : SEL.GenericParameterType
     L0.HasRange L0.Boolean
     L0.HasLabel "Split To Multiple Diagrams"
 
+// Dynamic Visualisations
 
+DN.VisualisationsFolder <T L0.Entity
 
 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.UseColorBarGradients
+        @defProperty "Use Color Bar Gradients" L0.Boolean
     >-- DN.Diagram.Visualisations.ColorBarLocation
         @defProperty "Color Bar Location" L0.String
     >-- DN.Diagram.Visualisations.ColorBarSize
@@ -227,6 +231,8 @@ DN.Diagram.Visualisations <T L0.Entity
         @defProperty "Show Size Bars" L0.Boolean
     >-- DN.Diagram.Visualisations.ShowSizeBarTicks
         @defProperty "Show Size Bar Ticks" L0.Boolean
+    >-- DN.Diagram.Visualisations.UseSizeBarGradients
+        @defProperty "Use Size Bar Gradients" L0.Boolean
     >-- DN.Diagram.Visualisations.SizeBarLocation
         @defProperty "Size Bar Location" L0.String
     >-- DN.Diagram.Visualisations.SizeBarSize
@@ -267,6 +273,8 @@ DN.Diagram.Visualisations.sizeContributionUsed <R L0.HasProperty
 DN.Diagram.Visualisations.sizeContributionUseDefault <R L0.HasProperty
 
 
+// End of dynamic visualisations
+
 DN.AddLayerToDNDiagramTemplate <T L0.Template
 
 DN.EPSG_4326 : DN.SpatialRefSystem
index 496c9c582de5bb721640360721792940b0b57e87..d268272a27ec5e2b2621066fb38e9df90253dd59 100644 (file)
@@ -14,6 +14,8 @@ DN.Groups : L0.Library
 DN.DistrictNodeGroup <T DIA.TypeGroup
     >-- DN.DistrictNodeGroup.hasComponentTypeName ==> "String" <R L0.HasProperty
 
+DN.Groups.ElementGroup : DIA.TypeGroup
+    DIA.TypeGroup.HasType DN.Element
 DN.Groups.VertexGroup : DIA.TypeGroup
     DIA.TypeGroup.HasType DN.Vertex
 DN.Groups.EdgeGroup : DIA.TypeGroup
@@ -21,9 +23,7 @@ DN.Groups.EdgeGroup : DIA.TypeGroup
 
 DN.ElementColoringStyle : DIA.Style
 DN.ElementSizingStyle : DIA.Style
-// These are deprecated in favor of new dynamic visualisations
-//DN.VertexSizeStyle : DIA.Style
-//DN.EdgeThicknessStyle : DIA.Style
+
 DN.ArrowLengthStyle : DIA.Style
 DN.HideStyle : DIA.Style
 DN.VertexSymbolStyle : DIA.Style
index 39305f146e8e3d015cb975fda9f4127d1e5b0390..e40e24e8a14f258d93d7313cf85d697e7977a04c 100644 (file)
@@ -45,6 +45,10 @@ public class DistrictNetworkResource {
     public final Resource Diagram_Visualisations_SizeBarSize;
     public final Resource Diagram_Visualisations_SizeBarSize_Inverse;
     public final Resource Diagram_Visualisations_SizeContribution;
+    public final Resource Diagram_Visualisations_UseColorBarGradients;
+    public final Resource Diagram_Visualisations_UseColorBarGradients_Inverse;
+    public final Resource Diagram_Visualisations_UseSizeBarGradients;
+    public final Resource Diagram_Visualisations_UseSizeBarGradients_Inverse;
     public final Resource Diagram_Visualisations_colorContributionContributorName;
     public final Resource Diagram_Visualisations_colorContributionContributorName_Inverse;
     public final Resource Diagram_Visualisations_colorContributionDefaultColorMap;
@@ -173,6 +177,7 @@ public class DistrictNetworkResource {
     public final Resource Functions_mappingModifier;
     public final Resource Groups;
     public final Resource Groups_EdgeGroup;
+    public final Resource Groups_ElementGroup;
     public final Resource Groups_VertexGroup;
     public final Resource HasEndVertex;
     public final Resource HasEndVertex_Inverse;
@@ -417,6 +422,7 @@ public class DistrictNetworkResource {
     public final Resource Vertex_HasVelocity_Inverse;
     public final Resource Vertex_HasVolFlow;
     public final Resource Vertex_HasVolFlow_Inverse;
+    public final Resource VisualisationsFolder;
         
     public static class URIs {
         public static final String ActionContext = "http://www.simantics.org/DistrictNetwork-1.0/ActionContext";
@@ -454,6 +460,10 @@ public class DistrictNetworkResource {
         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_SizeContribution = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/SizeContribution";
+        public static final String Diagram_Visualisations_UseColorBarGradients = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/UseColorBarGradients";
+        public static final String Diagram_Visualisations_UseColorBarGradients_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/UseColorBarGradients/Inverse";
+        public static final String Diagram_Visualisations_UseSizeBarGradients = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/UseSizeBarGradients";
+        public static final String Diagram_Visualisations_UseSizeBarGradients_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/UseSizeBarGradients/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";
@@ -582,6 +592,7 @@ public class DistrictNetworkResource {
         public static final String Functions_mappingModifier = "http://www.simantics.org/DistrictNetwork-1.0/Functions/mappingModifier";
         public static final String Groups = "http://www.simantics.org/DistrictNetwork-1.0/Groups";
         public static final String Groups_EdgeGroup = "http://www.simantics.org/DistrictNetwork-1.0/Groups/EdgeGroup";
+        public static final String Groups_ElementGroup = "http://www.simantics.org/DistrictNetwork-1.0/Groups/ElementGroup";
         public static final String Groups_VertexGroup = "http://www.simantics.org/DistrictNetwork-1.0/Groups/VertexGroup";
         public static final String HasEndVertex = "http://www.simantics.org/DistrictNetwork-1.0/HasEndVertex";
         public static final String HasEndVertex_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasEndVertex_Inverse";
@@ -826,6 +837,7 @@ public class DistrictNetworkResource {
         public static final String Vertex_HasVelocity_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Vertex/HasVelocity/Inverse";
         public static final String Vertex_HasVolFlow = "http://www.simantics.org/DistrictNetwork-1.0/Vertex/HasVolFlow";
         public static final String Vertex_HasVolFlow_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Vertex/HasVolFlow/Inverse";
+        public static final String VisualisationsFolder = "http://www.simantics.org/DistrictNetwork-1.0/VisualisationsFolder";
     }
     
     public static Resource getResourceOrNull(ReadGraph graph, String uri) {
@@ -873,6 +885,10 @@ public class DistrictNetworkResource {
         Diagram_Visualisations_SizeBarSize = getResourceOrNull(graph, URIs.Diagram_Visualisations_SizeBarSize);
         Diagram_Visualisations_SizeBarSize_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_SizeBarSize_Inverse);
         Diagram_Visualisations_SizeContribution = getResourceOrNull(graph, URIs.Diagram_Visualisations_SizeContribution);
+        Diagram_Visualisations_UseColorBarGradients = getResourceOrNull(graph, URIs.Diagram_Visualisations_UseColorBarGradients);
+        Diagram_Visualisations_UseColorBarGradients_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_UseColorBarGradients_Inverse);
+        Diagram_Visualisations_UseSizeBarGradients = getResourceOrNull(graph, URIs.Diagram_Visualisations_UseSizeBarGradients);
+        Diagram_Visualisations_UseSizeBarGradients_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_UseSizeBarGradients_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);
@@ -1001,6 +1017,7 @@ public class DistrictNetworkResource {
         Functions_mappingModifier = getResourceOrNull(graph, URIs.Functions_mappingModifier);
         Groups = getResourceOrNull(graph, URIs.Groups);
         Groups_EdgeGroup = getResourceOrNull(graph, URIs.Groups_EdgeGroup);
+        Groups_ElementGroup = getResourceOrNull(graph, URIs.Groups_ElementGroup);
         Groups_VertexGroup = getResourceOrNull(graph, URIs.Groups_VertexGroup);
         HasEndVertex = getResourceOrNull(graph, URIs.HasEndVertex);
         HasEndVertex_Inverse = getResourceOrNull(graph, URIs.HasEndVertex_Inverse);
@@ -1245,6 +1262,7 @@ public class DistrictNetworkResource {
         Vertex_HasVelocity_Inverse = getResourceOrNull(graph, URIs.Vertex_HasVelocity_Inverse);
         Vertex_HasVolFlow = getResourceOrNull(graph, URIs.Vertex_HasVolFlow);
         Vertex_HasVolFlow_Inverse = getResourceOrNull(graph, URIs.Vertex_HasVolFlow_Inverse);
+        VisualisationsFolder = getResourceOrNull(graph, URIs.VisualisationsFolder);
     }
     
     public static DistrictNetworkResource getInstance(ReadGraph graph) {
index ffa48d36bee6c0e351ccc632fbec1a9b29f06af2..d7f530dfd025e8df8ff49a8e5077841ac4ceeec1 100644 (file)
@@ -11,6 +11,7 @@ import java.util.function.Supplier;
 import org.simantics.datatypes.literal.RGB;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
+import org.simantics.db.common.request.IndexRoot;
 import org.simantics.db.common.request.UnaryRead;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.procedure.Listener;
@@ -306,7 +307,9 @@ public class DistrictDiagramViewer extends DiagramViewer {
         @Override
         public ColorBarOptions perform(ReadGraph graph) throws DatabaseException {
             DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
-            Resource activeVisualisation = graph.getPossibleObject(parameter, DN.Diagram_hasActiveVisualisation);
+            Resource model = graph.syncRequest(new IndexRoot(parameter));
+            Resource vf = DistrictNetworkUtil.getVisualisationFolder(graph, model);
+            Resource activeVisualisation = graph.getPossibleObject(vf, DN.Diagram_hasActiveVisualisation);
             if (activeVisualisation != null) {
                 return DistrictNetworkUtil.colorBarOptions(graph, activeVisualisation);
             }
@@ -323,7 +326,9 @@ public class DistrictDiagramViewer extends DiagramViewer {
         @Override
         public Map<String, DynamicColorContribution> perform(ReadGraph graph) throws DatabaseException {
             DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
-            Resource activeVisualisation = graph.getPossibleObject(parameter, DN.Diagram_hasActiveVisualisation);
+            Resource model = graph.syncRequest(new IndexRoot(parameter));
+            Resource vf = DistrictNetworkUtil.getVisualisationFolder(graph, model);
+            Resource activeVisualisation = graph.getPossibleObject(vf, DN.Diagram_hasActiveVisualisation);
             if (activeVisualisation != null) {
                 return DistrictNetworkUtil.colorContributions(graph, activeVisualisation);
             }
@@ -396,7 +401,9 @@ public class DistrictDiagramViewer extends DiagramViewer {
         @Override
         public SizeBarOptions perform(ReadGraph graph) throws DatabaseException {
             DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
-            Resource activeVisualisation = graph.getPossibleObject(parameter, DN.Diagram_hasActiveVisualisation);
+            Resource model = graph.syncRequest(new IndexRoot(parameter));
+            Resource vf = DistrictNetworkUtil.getVisualisationFolder(graph, model);
+            Resource activeVisualisation = graph.getPossibleObject(vf, DN.Diagram_hasActiveVisualisation);
             if (activeVisualisation != null) {
                 return DistrictNetworkUtil.sizeBarOptions(graph, activeVisualisation);
             }
@@ -441,7 +448,9 @@ public class DistrictDiagramViewer extends DiagramViewer {
         @Override
         public Map<String, DynamicSizeContribution> perform(ReadGraph graph) throws DatabaseException {
             DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
-            Resource activeVisualisation = graph.getPossibleObject(parameter, DN.Diagram_hasActiveVisualisation);
+            Resource model = graph.syncRequest(new IndexRoot(parameter));
+            Resource vf = DistrictNetworkUtil.getVisualisationFolder(graph, model);
+            Resource activeVisualisation = graph.getPossibleObject(vf, DN.Diagram_hasActiveVisualisation);
             if (activeVisualisation != null) {
                 return DistrictNetworkUtil.sizeContributions(graph, activeVisualisation);
             }
index b3149324eb42fb342262a88f1831d194c0c5cdb6..d8d2e1d194a97d9f45c9bdeb8a2e85394392cf2b 100644 (file)
@@ -125,9 +125,41 @@ public class DynamicVisualisationContributionsNode extends G2DNode {
                     
                     RGBIntensity intensity = intensities.get(j);
                     
-                    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);
+                    if (colorBarsOptions.isUseGradients()) {
+                        
+                        RGBIntensity upperLimitIntensity;
+                        if (j + 1 != intensities.size())
+                            upperLimitIntensity = intensities.get(j + 1);
+                        else
+                            upperLimitIntensity = intensity;
+                        
+                        double minRed = intensity.getRed();
+                        double minGreen = intensity.getGreen();
+                        double minBlue = intensity.getBlue();
+                        
+                        double maxRed = upperLimitIntensity.getRed();
+                        double maxGreen = upperLimitIntensity.getGreen();
+                        double maxBlue = upperLimitIntensity.getBlue();
+                        
+                        double redDelta = (maxRed - minRed) / colorVerticalWidth;
+                        double greenDelta = (maxGreen - minGreen) / colorVerticalWidth;
+                        double blueDelta = (maxBlue - minBlue) / colorVerticalWidth;
+                        
+                        for (int k = 0; k < colorVerticalWidth; k++) {
+                            
+                            
+                            g2d.setColor(new Color((float)(minRed + (k * redDelta)), (float)(minGreen + (k * greenDelta)), (float)(minBlue + (k * blueDelta)), 1f));
+                            Rectangle2D colorVertical = new Rectangle2D.Double(colorVerticalLeft + k, colorVerticalTop, 1, colorVerticalHeigth);
+                            g2d.fill(colorVertical);
+                        }
+                        
+                    } else {
+                        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);
+                    }
+                    
+
                     
                     double value = min + j * interval;
                     String str = Double.toString(value);
index 5cb80a15d5fca59c50a72827a1bcbad7ac0dc94e..14a8f00fa61c0646d84e60107674f78dd1a0cb26 100644 (file)
@@ -39,7 +39,6 @@ import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.util.RemoverUtil;
 import org.simantics.db.procedure.Listener;
 import org.simantics.district.network.DistrictNetworkUtil;
-import org.simantics.district.network.ontology.DistrictNetworkResource;
 import org.simantics.district.network.profile.ActiveDynamicVisualisationsRequest;
 import org.simantics.district.network.profile.DynamicVisualisationsRequest;
 import org.simantics.district.network.visualisations.DynamicVisualisationsContributions;
@@ -65,7 +64,7 @@ public class DynamicVisualisationsUI extends Composite {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(DynamicVisualisationsUI.class);
 
-    private Resource diagramResource;
+    private Resource parentResource;
     private VisualisationListener listener;
     private DynamicVisualisation visualisation;
 
@@ -131,7 +130,8 @@ public class DynamicVisualisationsUI extends Composite {
                             
                             @Override
                             public void perform(WriteGraph graph) throws DatabaseException {
-                                DistrictNetworkUtil.setActiveVisualisation(graph, diagramResource, template.getResource());
+                                Resource vf = DistrictNetworkUtil.getVisualisationFolder(graph, parentResource);
+                                DistrictNetworkUtil.setActiveVisualisation(graph, vf, template.getResource());
                             }
                         });
                         break;
@@ -269,12 +269,11 @@ public class DynamicVisualisationsUI extends Composite {
             
             @Override
             public void perform(WriteGraph graph) throws DatabaseException {
-                DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
                 Resource exist;
                 if (existing.isPresent()) {
                     exist = existing.get();
                 } else {
-                    exist = DistrictNetworkUtil.createVisualisation(graph, diagramResource, templateName);
+                    exist = DistrictNetworkUtil.createVisualisation(graph, parentResource, templateName);
                 }
                 
                 DistrictNetworkUtil.setColorContributions(graph, exist, colorCollect);
@@ -298,16 +297,17 @@ public class DynamicVisualisationsUI extends Composite {
         colorSuppliers = new ArrayList<>();
         {
             try {
-                Collection<DynamicColoringObject> result = Simantics.getSession().syncRequest(new UniqueRead<Collection<DynamicColoringObject>>() {
+                Pair<Collection<DynamicColoringObject>, Map<String, DynamicColorMap>> result = Simantics.getSession().syncRequest(new UniqueRead<Pair<Collection<DynamicColoringObject>, Map<String, DynamicColorMap>>>() {
 
                     @Override
-                    public Collection<DynamicColoringObject> perform(ReadGraph graph) throws DatabaseException {
-                        return DynamicVisualisationsContributions.dynamicColoringObjects(graph);
+                    public Pair<Collection<DynamicColoringObject>, Map<String, DynamicColorMap>> perform(ReadGraph graph) throws DatabaseException {
+                        Map<String, DynamicColorMap> dynamicColorMaps = DynamicVisualisationsContributions.dynamicColorMaps(graph);
+                        return Pair.make(DynamicVisualisationsContributions.dynamicColoringObjects(graph), dynamicColorMaps);
                     }
                 });
                 
-                for (DynamicColoringObject object : result) {
-                    colorSuppliers.add(createColoringObjectRow(group, object));
+                for (DynamicColoringObject object : result.first) {
+                    colorSuppliers.add(createColoringObjectRow(group, object, result.second));
                 }
 
             } catch (DatabaseException e) {
@@ -367,11 +367,11 @@ public class DynamicVisualisationsUI extends Composite {
         private final Combo variableCombo;
         private final Text minText;
         private final Text maxText;
-        private final Label unit;
+        private final Text unit;
         private final Combo colorMapCombo;
         private final Button defaultButton;
         
-        public ColoringObjectRow(Label label, Button usedButton, Combo variableCombo, Text minText, Text maxText, Label unit,
+        public ColoringObjectRow(Label label, Button usedButton, Combo variableCombo, Text minText, Text maxText, Text unit,
                 Combo colorMapCombo, Button defaultButton) {
             super();
             this.label = label;
@@ -396,17 +396,14 @@ public class DynamicVisualisationsUI extends Composite {
             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;
-//                }
-//            }
+            String[] colorItems = colorMapCombo.getItems();
+            for (int i = 0; i < colorItems.length; i++) {
+                
+                if (colorContribution.getDefaultColorMap().getLabel().equals(colorItems[i])) {
+                    colorMapCombo.select(i);
+                    break;
+                }
+            }
             usedButton.setSelection(colorContribution.isUsed());
             defaultButton.setSelection(colorContribution.isUseDefault());
             
@@ -452,17 +449,13 @@ public class DynamicVisualisationsUI extends Composite {
             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;
-//                }
-//            }
+            String[] sizeItems = sizeMapCombo.getItems();
+            for (int i = 0; i < sizeItems.length; i++) {
+                if (sizeContribution.getDefaultSizeMap().getLabel().equals(sizeItems[i])) {
+                    sizeMapCombo.select(i);
+                    break;
+                }
+            }
             usedButton.setSelection(sizeContribution.isUsed());
             defaultButton.setSelection(sizeContribution.isUseDefault());
             
@@ -472,7 +465,7 @@ public class DynamicVisualisationsUI extends Composite {
         }
     }
 
-    private Supplier<Pair<String, DynamicColorContribution>> createColoringObjectRow(Composite parent, DynamicColoringObject object) {
+    private Supplier<Pair<String, DynamicColorContribution>> createColoringObjectRow(Composite parent, DynamicColoringObject object, Map<String, DynamicColorMap> colorMaps) {
         Label label = new Label(parent, SWT.NONE);
         label.setText(object.getColoringObject().getName());
         GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(label);
@@ -493,12 +486,12 @@ public class DynamicVisualisationsUI extends Composite {
         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);
+        Text unit = new Text(parent, SWT.READ_ONLY);
+        GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(unit);
         
         Combo colorMapCombo = new Combo(parent, SWT.READ_ONLY);
         GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(colorMapCombo);
+        colorMapCombo.setItems(colorMaps.keySet().toArray(new String[colorMaps.keySet().size()]));
         
         Button defaultButton = new Button(parent, SWT.CHECK);
         GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(defaultButton);
@@ -517,8 +510,14 @@ public class DynamicVisualisationsUI extends Composite {
                     maxText.setEnabled(!defaultButton.getSelection());
                     unit.setText(cont.getUnit());
                     
-                    colorMapCombo.setItems(cont.getDefaultColorMap().getLabel());
-                    colorMapCombo.select(0);
+                    String[] items = colorMapCombo.getItems();
+                    for (int i = 0; i < items.length; i++) {
+                        String item = items[i];
+                        if (item.equals(cont.getDefaultColorMap().getLabel())) {
+                            colorMapCombo.select(i);
+                            break;
+                        }
+                    }
                     colorMapCombo.setEnabled(!defaultButton.getSelection());
                 }
             }
@@ -542,8 +541,14 @@ public class DynamicVisualisationsUI extends Composite {
                     }
                     unit.setText(cont.getUnit());
                     
-                    colorMapCombo.setItems(cont.getDefaultColorMap().getLabel());
-                    colorMapCombo.select(0);
+                    String[] items = colorMapCombo.getItems();
+                    for (int i = 0; i < items.length; i++) {
+                        String item = items[i];
+                        if (item.equals(cont.getDefaultColorMap().getLabel())) {
+                            colorMapCombo.select(i);
+                            break;
+                        }
+                    }
                     
                     defaultButton.setSelection(true);
                 }
@@ -623,7 +628,7 @@ public class DynamicVisualisationsUI extends Composite {
         GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(label);
     }
 
-    private Supplier<Pair<String, DynamicSizeContribution>> createSizingObjectRow(Composite parent, DynamicSizingObject object) {
+    private Supplier<Pair<String, DynamicSizeContribution>> createSizingObjectRow(Composite parent, DynamicSizingObject object, Map<String, DynamicSizeMap> sizeMaps) {
         Label label = new Label(parent, SWT.NONE);
         label.setText(object.getSizingObject().getName());
         GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(label);
@@ -645,14 +650,41 @@ public class DynamicVisualisationsUI extends Composite {
         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);
+        GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(unit);
         
         Combo sizeMapCombo = new Combo(parent, SWT.READ_ONLY);
         GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(sizeMapCombo);
+        sizeMapCombo.setItems(sizeMaps.keySet().toArray(new String[sizeMaps.keySet().size()]));
         
         Button defaultButton = new Button(parent, SWT.CHECK);
         GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(defaultButton);
+        defaultButton.addSelectionListener(new SelectionAdapter() {
+            
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                int index = variableCombo.getSelectionIndex();
+                if (index >= 0) {
+                    String key = variableCombo.getItem(index);
+                    DynamicSizeContribution cont = sizeContributions.get(key);
+                    
+                    minText.setText(Double.toString(cont.getDefaultMin()));
+                    minText.setEnabled(!defaultButton.getSelection());
+                    maxText.setText(Double.toString(cont.getDefaultMax()));
+                    maxText.setEnabled(!defaultButton.getSelection());
+                    unit.setText(cont.getUnit());
+                    
+                    String[] items = sizeMapCombo.getItems();
+                    for (int i = 0; i < items.length; i++) {
+                        String item = items[i];
+                        if (item.equals(cont.getDefaultSizeMap().getLabel())) {
+                            sizeMapCombo.select(i);
+                            break;
+                        }
+                    }
+                    sizeMapCombo.setEnabled(!defaultButton.getSelection());
+                }
+            }
+        });
         
         variableCombo.addSelectionListener(new SelectionAdapter() {
             
@@ -670,8 +702,14 @@ public class DynamicVisualisationsUI extends Composite {
                 }
                 unit.setText(cont.getUnit());
                 
-                sizeMapCombo.setItems(cont.getDefaultSizeMap().getLabel());
-                sizeMapCombo.select(0);
+                String[] items = sizeMapCombo.getItems();
+                for (int i = 0; i < items.length; i++) {
+                    String item = items[i];
+                    if (item.equals(cont.getDefaultSizeMap().getLabel())) {
+                        sizeMapCombo.select(i);
+                        break;
+                    }
+                }
                 
                 defaultButton.setSelection(true);
             }
@@ -770,16 +808,17 @@ public class DynamicVisualisationsUI extends Composite {
         
         sizeSuppliers = new ArrayList<>(); 
         try {
-            Collection<DynamicSizingObject> resultSizing = Simantics.getSession().syncRequest(new UniqueRead<Collection<DynamicSizingObject>>() {
+            Pair<Collection<DynamicSizingObject>, Map<String, DynamicSizeMap>> resultSizing = Simantics.getSession().syncRequest(new UniqueRead<Pair<Collection<DynamicSizingObject>, Map<String, DynamicSizeMap>>>() {
 
                 @Override
-                public Collection<DynamicSizingObject> perform(ReadGraph graph) throws DatabaseException {
-                    return DynamicVisualisationsContributions.dynamicSizingObjects(graph);
+                public Pair<Collection<DynamicSizingObject>, Map<String, DynamicSizeMap>> perform(ReadGraph graph) throws DatabaseException {
+                    Map<String, DynamicSizeMap> dynamicSizeMaps = DynamicVisualisationsContributions.dynamicSizeMaps(graph);
+                    return Pair.make(DynamicVisualisationsContributions.dynamicSizingObjects(graph), dynamicSizeMaps);
                 }
             });
             
-            for (DynamicSizingObject object : resultSizing) {
-                sizeSuppliers.add(createSizingObjectRow(parent, object));
+            for (DynamicSizingObject object : resultSizing.first) {
+                sizeSuppliers.add(createSizingObjectRow(parent, object, resultSizing.second));
             }
         } catch (DatabaseException e) {
             LOGGER.error("Could not create object sizes", e);
@@ -824,9 +863,9 @@ public class DynamicVisualisationsUI extends Composite {
         }
     }
 
-    public void setDiagramResource(Resource diagramResource) {
-        if (this.diagramResource != diagramResource) {
-            this.diagramResource = diagramResource;
+    public void setParentResource(Resource parentResource) {
+        if (this.parentResource != parentResource) {
+            this.parentResource = parentResource;
             updateListening();
         }
     }
@@ -835,12 +874,12 @@ public class DynamicVisualisationsUI extends Composite {
         if (visualisationsListener != null)
             visualisationsListener.dispose();
         visualisationsListener = new VisualisationsListener(this);
-        Simantics.getSession().asyncRequest(new DynamicVisualisationsRequest(diagramResource), visualisationsListener);
+        Simantics.getSession().asyncRequest(new DynamicVisualisationsRequest(parentResource), visualisationsListener);
         
         if (listener != null)
             listener.dispose();
         listener = new VisualisationListener(this);
-        Simantics.getSession().asyncRequest(new ActiveDynamicVisualisationsRequest(diagramResource), listener);
+        Simantics.getSession().asyncRequest(new ActiveDynamicVisualisationsRequest(parentResource), listener);
     }
 
     private static class VisualisationsListener implements Listener<Collection<NamedResource>> {
@@ -938,6 +977,7 @@ public class DynamicVisualisationsUI extends Composite {
                 ColorBarOptions colorOptions = visualisation.getColorBarOptions();
                 showColorButton.setSelection(colorOptions.isShowColorBars());
                 colorTicksButton.setSelection(colorOptions.isShowColorBarsTicks());
+                colorGradientButton.setSelection(colorOptions.isUseGradients());
                 for (int i = 0; i < colorLocationCombo.getItems().length; i++) {
                     String item = colorLocationCombo.getItem(i);
                     if (item.equals(colorOptions.getLocation().toString())) {
@@ -968,6 +1008,7 @@ public class DynamicVisualisationsUI extends Composite {
                 SizeBarOptions sizeOptions = visualisation.getSizeBarOptions();
                 showSizeButton.setSelection(sizeOptions.isShowSizeBars());
                 sizeTicksButton.setSelection(sizeOptions.isShowSizeBarsTicks());
+                sizeGradientButton.setSelection(sizeOptions.isUseGradients());
                 for (int i = 0; i < sizeLocationCombo.getItems().length; i++) {
                     String item = sizeLocationCombo.getItem(i);
                     if (item.equals(sizeOptions.getLocation().toString())) {
index d98a37872651daef0c361948eda3ebad0060352f..6bdf00378fb726728b0e58e4279cbd386ec8cd8b 100644 (file)
@@ -2,85 +2,44 @@ 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;
+import org.simantics.Simantics;
+import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.procedure.adapter.AsyncListenerAdapter;
+import org.simantics.db.layer0.request.PossibleActiveModel;
 
 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);
+        Simantics.getSession().asyncRequest(new PossibleActiveModel(Simantics.getProjectResource()), new AsyncListenerAdapter<Resource>() {
+
+            @Override
+            public void execute(AsyncReadGraph graph, Resource result) {
+                if (ui != null && !ui.isDisposed()) {
+                    ui.getDisplay().asyncExec(() -> {
+                        ui.setParentResource(result);
+                    });
+                }
+            }
+
+            @Override
+            public boolean isDisposed() {
+                return ui != null ? ui.isDisposed() : true;
+            }
+        });
     }
 
     @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 596ac044f854b124f0c702066fe59c0dad4e088d..54d3a595cc9ead222f7a0f92d3091e9252573937 100644 (file)
@@ -8,6 +8,7 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.UUID;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
@@ -26,6 +27,7 @@ import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;
 import org.simantics.db.exception.ServiceException;
 import org.simantics.db.indexing.IndexUtils;
+import org.simantics.db.layer0.QueryIndexUtils;
 import org.simantics.db.layer0.request.PossibleVariable;
 import org.simantics.db.layer0.variable.Variable;
 import org.simantics.diagram.stubs.DiagramResource;
@@ -409,10 +411,12 @@ public class DistrictNetworkUtil {
             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);
+            Boolean useGradients = graph.getPossibleRelatedValue(visualisation, DN.Diagram_Visualisations_UseColorBarGradients, Bindings.BOOLEAN);
             if (colorBarLocation != null) {
                 return new ColorBarOptions()
                     .showColorBars(show != null ? show : false)
                     .showColorBarsTicks(showTicks != null ? showTicks : false)
+                    .useGradients(useGradients != null ? useGradients : false)
                     .withLocation(ColorBarsLocation.valueOf(colorBarLocation))
                     .withSize(ColorBarsSize.valueOf(colorBarSize));
             }
@@ -426,18 +430,40 @@ public class DistrictNetworkUtil {
         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);
+        graph.claimLiteral(visualisation, DN.Diagram_Visualisations_UseColorBarGradients, options.isUseGradients(), Bindings.BOOLEAN);
     }
     
-    public static Resource createVisualisation(WriteGraph graph, Resource diagram, String visualisationName) throws DatabaseException {
+    public static Resource createVisualisation(WriteGraph graph, Resource parent, String visualisationName) throws DatabaseException {
+        Resource vf = getOrCreateVisualisationsFolder(graph, parent);
         Layer0 L0 = Layer0.getInstance(graph);
         DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
         Resource visualisation = graph.newResource();
         graph.claim(visualisation, L0.InstanceOf, DN.Diagram_Visualisations);
         graph.claimLiteral(visualisation, L0.HasName, visualisationName);
-        graph.claim(diagram, DN.Diagram_hasVisualisation, visualisation);
+        graph.claim(vf, DN.Diagram_hasVisualisation, visualisation);
         return visualisation;
     }
 
+    public static Resource getOrCreateVisualisationsFolder(WriteGraph graph, Resource model) throws DatabaseException {
+        Resource rf = getVisualisationFolder(graph, model);
+        if (rf == null) {
+            Layer0 L0 = Layer0.getInstance(graph);
+            DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+            rf = graph.newResource();
+            graph.claim(rf, L0.InstanceOf, null, DN.VisualisationsFolder);
+            graph.claimLiteral(rf, L0.HasName, L0.NameOf, L0.String, UUID.randomUUID().toString(), Bindings.STRING);
+            graph.claim(model, L0.ConsistsOf, L0.PartOf, rf);
+        }
+        return rf;
+    }
+
+    public static Resource getVisualisationFolder(ReadGraph graph, Resource model) throws DatabaseException {
+        List<Resource> visualisationsFolders = QueryIndexUtils.searchByType(graph, model, DistrictNetworkResource.getInstance(graph).VisualisationsFolder);
+        if (visualisationsFolders.size() > 0)
+            return visualisationsFolders.get(0);
+        return null;
+    }
+
     public static SizeBarOptions sizeBarOptions(ReadGraph graph, Resource visualisation) throws DatabaseException {
         DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
         if (visualisation != null) {
@@ -445,10 +471,12 @@ public class DistrictNetworkUtil {
             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);
+            Boolean useGradients = graph.getPossibleRelatedValue(visualisation, DN.Diagram_Visualisations_UseSizeBarGradients, Bindings.BOOLEAN);
             if (sizeBarLocation != null) {
                 return new SizeBarOptions()
                     .showSizeBars(show != null ? show : false)
                     .showSizeBarsTicks(showTicks != null ? showTicks : false)
+                    .useGradients(useGradients != null ? useGradients : false)
                     .withLocation(SizeBarsLocation.valueOf(sizeBarLocation))
                     .withSize(SizeBarsSize.valueOf(sizeBarSize));
             }
@@ -462,6 +490,7 @@ public class DistrictNetworkUtil {
         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);
+        graph.claimLiteral(visualisation, DN.Diagram_Visualisations_UseSizeBarGradients, options.isUseGradients(), Bindings.BOOLEAN);
     }
 
     public static Map<String, DynamicColorContribution> colorContributions(ReadGraph graph, Resource visualisation) throws DatabaseException {
index 52cfd61ccc5951d496d3780a98ee9924571ca8fc..58499db07e91b6061691bddd38b6a489ead24ba3 100644 (file)
@@ -20,22 +20,25 @@ import org.simantics.layer0.Layer0;
  */
 public class ActiveDynamicVisualisationsRequest extends ResourceRead<DynamicVisualisation> {
 
-    public ActiveDynamicVisualisationsRequest(Resource diagram) {
-        super(diagram);
+    public ActiveDynamicVisualisationsRequest(Resource parent) {
+        super(parent);
     }
 
     @Override
     public DynamicVisualisation perform(ReadGraph graph) throws DatabaseException {
         DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
-        Resource visualisationResource = graph.getPossibleObject(resource, DN.Diagram_hasActiveVisualisation);
-        if (visualisationResource != null) {
-            String name = graph.getRelatedValue(visualisationResource, Layer0.getInstance(graph).HasName);
-            Map<String, DynamicColorContribution> colorContributions = DistrictNetworkUtil.colorContributions(graph, visualisationResource);
-            ColorBarOptions colorBarOptions = DistrictNetworkUtil.colorBarOptions(graph, visualisationResource);
-            Map<String, DynamicSizeContribution> sizeContributions = DistrictNetworkUtil.sizeContributions(graph, visualisationResource);
-            SizeBarOptions sizeBarOptions = DistrictNetworkUtil.sizeBarOptions(graph, visualisationResource);
-            DynamicVisualisation visualisation = new DynamicVisualisation(name, visualisationResource, colorContributions, colorBarOptions, sizeContributions, sizeBarOptions);
-            return visualisation; 
+        Resource visualisationFolder = DistrictNetworkUtil.getVisualisationFolder(graph, resource);
+        if (visualisationFolder != null) {
+            Resource visualisationResource = graph.getPossibleObject(visualisationFolder, DN.Diagram_hasActiveVisualisation);
+            if (visualisationResource != null) {
+                String name = graph.getRelatedValue(visualisationResource, Layer0.getInstance(graph).HasName);
+                Map<String, DynamicColorContribution> colorContributions = DistrictNetworkUtil.colorContributions(graph, visualisationResource);
+                ColorBarOptions colorBarOptions = DistrictNetworkUtil.colorBarOptions(graph, visualisationResource);
+                Map<String, DynamicSizeContribution> sizeContributions = DistrictNetworkUtil.sizeContributions(graph, visualisationResource);
+                SizeBarOptions sizeBarOptions = DistrictNetworkUtil.sizeBarOptions(graph, visualisationResource);
+                DynamicVisualisation visualisation = new DynamicVisualisation(name, visualisationResource, colorContributions, colorBarOptions, sizeContributions, sizeBarOptions);
+                return visualisation; 
+            }
         }
         return null;
     }
index 7ebff91e5874ba520889f0cbb1106ea6779d8ce7..9bcae2e5f42e907231694ca559d7b68e64184416 100644 (file)
@@ -70,7 +70,7 @@ public class DNElementColorStyle extends ThrottledStyleBase<Color> {
                                         // 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());
+                                        Color color = defaultColorMap.getColor(adjustedValue, dv.getColorBarOptions().isUseGradients(), dcc.getDefaultMin(), dcc.getDefaultMax());
                                         return color;
                                     } else {
                                         LOGGER.warn("No value for {}", attribute.getURI(graph));
index 5963954fda83087714608cba5ce07874605cb723..0a454eef8f57a577a5a33f8aaee79afe37295b51 100644 (file)
@@ -71,7 +71,7 @@ public class DNElementSizeStyle extends ThrottledStyleBase<Double> {
                                         // 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());
+                                        double size = defaultSizeMap.getSize(adjustedValue, dv.getSizeBarOptions().isUseGradients(), dsc.getDefaultMin(), dsc.getDefaultMax());
                                         return size;
                                     } else {
                                         LOGGER.warn("No value for {}", attribute.getURI(graph));
index 3c187a10db8045b3b2c996b523f0826cb052c77b..c2b473c5a50163668ad50af2c38a897c17f27cce 100644 (file)
@@ -9,6 +9,7 @@ import org.simantics.db.Resource;
 import org.simantics.db.common.NamedResource;
 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.layer0.Layer0;
 
@@ -17,19 +18,22 @@ import org.simantics.layer0.Layer0;
  */
 public class DynamicVisualisationsRequest extends ResourceRead<Collection<NamedResource>> {
 
-    public DynamicVisualisationsRequest(Resource diagram) {
-        super(diagram);
+    public DynamicVisualisationsRequest(Resource parent) {
+        super(parent);
     }
 
     @Override
     public Collection<NamedResource> perform(ReadGraph graph) throws DatabaseException {
         DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
-        Collection<Resource> visualisationResources = graph.getObjects(resource, DN.Diagram_hasVisualisation);
         List<NamedResource> results = new ArrayList<>();
-        if (visualisationResources != null && !visualisationResources.isEmpty()) {
-            for (Resource visualisationResource : visualisationResources) {
-                String name = graph.getRelatedValue(visualisationResource, Layer0.getInstance(graph).HasName);
-                results.add(new NamedResource(name, visualisationResource));
+        Resource visualisationFolder = DistrictNetworkUtil.getVisualisationFolder(graph, resource);
+        if (visualisationFolder != null) {
+            Collection<Resource> visualisationResources = graph.getObjects(visualisationFolder, DN.Diagram_hasVisualisation);
+            if (visualisationResources != null && !visualisationResources.isEmpty()) {
+                for (Resource visualisationResource : visualisationResources) {
+                    String name = graph.getRelatedValue(visualisationResource, Layer0.getInstance(graph).HasName);
+                    results.add(new NamedResource(name, visualisationResource));
+                }
             }
         }
         return results;
index 05ed85bd47e4c90b31323fab0de19415b3562b53..97d23147031aa035487882af75824ab61f368d13 100644 (file)
@@ -3,6 +3,7 @@ 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.IndexRoot;
 import org.simantics.db.common.request.ResourceRead;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.diagram.stubs.DiagramResource;
@@ -22,7 +23,8 @@ public class RuntimeDynamicVisualisationsRequest extends ResourceRead<DynamicVis
         DiagramResource DIA = DiagramResource.getInstance(graph);
         Resource diagram = graph.getPossibleObject(resource, DIA.RuntimeDiagram_HasConfiguration);
         if (diagram != null) {
-            return graph.syncRequest(new ActiveDynamicVisualisationsRequest(diagram), TransientCacheAsyncListener.instance());
+            Resource model = graph.syncRequest(new IndexRoot(diagram));
+            return graph.syncRequest(new ActiveDynamicVisualisationsRequest(model), TransientCacheAsyncListener.instance());
         }
         return null;
     }
index 40779e2037f70b9c691d15cf42c52eccb49a3a1e..f697a73f4322301e117503562aadc0052de470e1 100644 (file)
@@ -72,7 +72,7 @@ public abstract class ThrottledStyleBase<Result> extends StyleBase<Optional<Resu
 
     @Override
     public final void applyStyleForNode(EvaluationContext evaluationContext, INode node, Optional<Result> result) {
-        if (!Optional.empty().equals(result)) {
+        if (!Optional.empty().equals(result) && result != null) {
             applyThrottledStyleForNode(evaluationContext, node, result.get());
         } else {
             LOGGER.debug("Do not apply as results are unchanged for {} {} {}", evaluationContext, node, result);
index 09cb57943f6865ae8dd6f251c737c04d88f44588..4c4580979ef6f613c83c776d0f44819fbe4f2e16 100644 (file)
@@ -1,15 +1,10 @@
 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;
     
@@ -51,20 +46,49 @@ public class DynamicColorMap {
         }
     }
 
-    public Color getColor(double value, double defaultMin, double defaultMax) {
+    public Color getColor(double value, boolean useGradient, double defaultMin, double defaultMax) {
+        List<RGBIntensity> intensities = getIntensities();
         
         double gap = defaultMax - defaultMin;
-        double singleGap = gap / getIntensities().size();
+        double singleGap = gap / intensities.size();
         
+        double threshold = defaultMin;
         int i = 0;
-        while (i < getIntensities().size() - 1) {
-            if (value <= defaultMin + (i * singleGap)) {
+        while (i < intensities.size() - 1) {
+            threshold = threshold + singleGap;
+            if (value <= threshold) {
                 break;
             }
             i++;
         }
         
-        RGBIntensity intensity = getIntensities().get(i);
-        return new Color((float)intensity.getRed(), (float)intensity.getGreen(), (float)intensity.getBlue());
+        RGBIntensity intensity = intensities.get(i);
+        if (useGradient) {
+            
+            RGBIntensity upperLimitIntensity;
+            if (i + 1 != intensities.size())
+                upperLimitIntensity = intensities.get(i + 1);
+            else
+                upperLimitIntensity = intensity;
+            
+            double minRed = intensity.getRed();
+            double minGreen = intensity.getGreen();
+            double minBlue = intensity.getBlue();
+            
+            double maxRed = upperLimitIntensity.getRed();
+            double maxGreen = upperLimitIntensity.getGreen();
+            double maxBlue = upperLimitIntensity.getBlue();
+            
+            double delta = Math.max(value - (defaultMin + singleGap * i), 0);
+            
+            double d = delta / singleGap;
+            
+            double redDelta = (maxRed - minRed) * d;
+            double greenDelta = (maxGreen - minGreen) * d;
+            double blueDelta = (maxBlue - minBlue) * d;
+            return new Color((float)(minRed + redDelta), (float)(minGreen + greenDelta), (float)(minBlue + blueDelta));
+        } else {
+            return new Color((float)intensity.getRed(), (float)intensity.getGreen(), (float)intensity.getBlue());
+        }
     }
 }
index 7edb12b912faa63a9ce1b64422cef252b5a83195..e2adb88810d78574c9022d6e569c0cdb5765e5c4 100644 (file)
@@ -20,19 +20,39 @@ public class DynamicSizeMap {
         return sizes;
     }
 
-    public double getSize(double value, double defaultMin, double defaultMax) {
+    public double getSize(double value, boolean useGradient, double defaultMin, double defaultMax) {
+        List<Double> sizes = getSizes();
         
         double gap = defaultMax - defaultMin;
-        double singleGap = gap / getSizes().size();
+        double singleGap = gap / sizes.size();
         
+        double threshold = defaultMin;
         int i = 0;
-        while (i < getSizes().size() - 1) {
-            if (value <= defaultMin + (i * singleGap)) {
+        while (i < sizes.size() - 1) {
+            threshold = threshold + singleGap;
+            if (value <= threshold) {
                 break;
             }
             i++;
         }
         
-        return getSizes().get(i);
+        Double size = sizes.get(i);
+        if (useGradient) {
+            
+            Double upperSize;
+            if (i + 1 != sizes.size()) {
+                upperSize = sizes.get(i + 1);
+            } else {
+                upperSize = size;
+            }
+
+            double delta = Math.max(value - (defaultMin + singleGap * i), 0);
+            double d = delta / singleGap;
+            double sizeDelta = (upperSize - size) * d;
+            
+            return size + sizeDelta;
+        }
+        
+        return size;
     }
 }