]> gerrit.simantics Code Review - simantics/district.git/blob
08a1b01330642f3abbe99d37b426fb0c482c083c
[simantics/district.git] /
1 package org.simantics.district.network.profile;
2
3 import java.util.Collection;
4 import java.util.Map;
5 import java.util.stream.Collectors;
6
7 import org.simantics.databoard.Bindings;
8 import org.simantics.db.ReadGraph;
9 import org.simantics.db.Resource;
10 import org.simantics.db.common.request.ResourceRead;
11 import org.simantics.db.exception.DatabaseException;
12 import org.simantics.district.network.ontology.DistrictNetworkResource;
13 import org.simantics.district.network.visualisations.DynamicVisualisations;
14 import org.simantics.district.network.visualisations.DynamicVisualisationsContributions;
15 import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicArrowObject;
16 import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicColoringObject;
17 import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicSizingObject;
18 import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicSymbolContributionObject;
19 import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.StaticInformationContributionObject;
20 import org.simantics.district.network.visualisations.model.ColorBarOptions;
21 import org.simantics.district.network.visualisations.model.DynamicArrowContribution;
22 import org.simantics.district.network.visualisations.model.DynamicColorContribution;
23 import org.simantics.district.network.visualisations.model.DynamicSizeContribution;
24 import org.simantics.district.network.visualisations.model.DynamicVisualisation;
25 import org.simantics.district.network.visualisations.model.SizeBarOptions;
26 import org.simantics.layer0.Layer0;
27
28 /**
29  * @author Jani Simomaa
30  */
31 public class ActiveDynamicVisualisationsRequest extends ResourceRead<DynamicVisualisation> {
32
33     public ActiveDynamicVisualisationsRequest(Resource parent) {
34         super(parent);
35     }
36
37     @Override
38     public DynamicVisualisation perform(ReadGraph graph) throws DatabaseException {
39         DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
40         Resource visualisationFolder = DynamicVisualisations.getVisualisationFolder(graph, resource);
41         if (visualisationFolder != null) {
42             Resource visualisationResource = graph.getPossibleObject(visualisationFolder, DN.Diagram_hasActiveVisualisation);
43             if (visualisationResource != null) {
44                 String name = graph.getRelatedValue(visualisationResource, Layer0.getInstance(graph).HasName);
45                 
46                 Long interval = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_Interval, Bindings.LONG);
47                 Boolean disabledUpdates = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_DisabledUpdates, Bindings.BOOLEAN);
48                 Boolean resetVisualisation = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_ResetVisualisation, Bindings.BOOLEAN);
49                 
50                 Collection<DynamicColoringObject> dynamicColoringObjects = DynamicVisualisationsContributions.dynamicColoringObjects(graph);
51                 Map<String, DynamicColoringObject> defaultColoringObjects = dynamicColoringObjects.stream().collect(Collectors.toMap(dcc -> dcc.getColoringObject().getName(), dcc -> dcc));
52                 
53                 Collection<DynamicSizingObject> dynamicSizingObjects = DynamicVisualisationsContributions.dynamicSizingObjects(graph);
54                 Map<String, DynamicSizingObject> defaultSizingObjects = dynamicSizingObjects.stream().collect(Collectors.toMap(dcc -> dcc.getSizingObject().getName(), dcc -> dcc));
55                 
56                 Collection<DynamicArrowObject> dynamicArrowObjects = DynamicVisualisationsContributions.dynamicEdgeArrowObjects(graph);
57                 Map<String, DynamicArrowObject> defaultArrowObjects = dynamicArrowObjects.stream().collect(Collectors.toMap(dac -> dac.getArrowObject().getName(), dac -> dac));
58                 
59                 Map<String, DynamicColorContribution> colorContributions = DynamicVisualisations.colorContributions(graph, visualisationResource);
60                 ColorBarOptions colorBarOptions = DynamicVisualisations.colorBarOptions(graph, visualisationResource);
61                 Map<String, DynamicSizeContribution> sizeContributions = DynamicVisualisations.sizeContributions(graph, visualisationResource);
62                 SizeBarOptions sizeBarOptions = DynamicVisualisations.sizeBarOptions(graph, visualisationResource);
63                 Map<String, DynamicArrowContribution> arrowContributions = DynamicVisualisations.arrowContributions(graph, visualisationResource);
64                 
65                 Collection<StaticInformationContributionObject> staticInformationContributions = DynamicVisualisationsContributions.staticInformationContributionObjects(graph);
66                 Map<String, StaticInformationContributionObject> staticInformationContributionObjects = staticInformationContributions.stream().collect(Collectors.toMap(dcc -> dcc.getStaticInformationContributionObject().getName(), dcc -> dcc));
67
68                 Collection<DynamicSymbolContributionObject> dynamicSymbolContributions = DynamicVisualisationsContributions.dynamicSymbolContributionObjects(graph);
69                 Map<String, DynamicSymbolContributionObject> dynamicSymbolContributionObjects = dynamicSymbolContributions.stream().map(dsc -> {
70                     // here we resolve the symbol map with the help of readgraph
71                     dsc.resolveSymbols(graph);
72                     return dsc;
73                 }).collect(Collectors.toMap(dcc -> dcc.getDynamicSymbolContributionObject().getName(), dcc -> dcc));
74
75                 Boolean hideEdges = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_HideEdges, Bindings.BOOLEAN);
76                 Boolean hidePoints = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_HidePoints, Bindings.BOOLEAN);
77                 Boolean hideConsumers = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_HideConsumers, Bindings.BOOLEAN);
78                 Boolean hideProducers = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_HideProducers, Bindings.BOOLEAN);
79                 Boolean hideValves = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_HideValves, Bindings.BOOLEAN);
80                 Boolean hidePumpingStations = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_HidePumpingStations, Bindings.BOOLEAN);
81                 Boolean staticPropertiesNetworkBranch = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_StaticPropertiesNetworkBranches, Bindings.BOOLEAN);
82                 Boolean staticProperiesPoints = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_StaticPropertiesPoints, Bindings.BOOLEAN);
83                 Boolean staticPropertiesConsumers = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_StaticPropertiesConsumers, Bindings.BOOLEAN);
84                 Boolean dynamicSymbolsProducers = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_DynamicSymbolsProducers, Bindings.BOOLEAN);
85                 Boolean dynamicSymbolsShutoffValves = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_DynamicSymbolsShutoffValves, Bindings.BOOLEAN);
86                 Boolean dynamicSymbolsValves = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_DynamicSymbolsValves, Bindings.BOOLEAN);
87                 Boolean dynamicSymbolsPumpingStations = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_DynamicSymbolsPumpingStations, Bindings.BOOLEAN);
88
89                 Boolean keyVariablesVertexHover = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_KeyVariableVertexHover, Bindings.BOOLEAN);
90                 Boolean keyVariablesEdgesHover = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_KeyVariableEdgeHover, Bindings.BOOLEAN);
91                 
92                 Boolean showElevationServerBoundingBox = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_ShowElevationServerBoundingBox, Bindings.BOOLEAN);
93                 Boolean notInSimulation = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_NotInSimulation, Bindings.BOOLEAN);
94                 
95                 DynamicVisualisation visualisation = new DynamicVisualisation(name, visualisationResource,
96                         interval != null ? interval : 2000,
97                         disabledUpdates != null ? disabledUpdates : false,
98                         resetVisualisation != null ? resetVisualisation : false,
99                         colorContributions,
100                         defaultColoringObjects,
101                         colorBarOptions,
102                         sizeContributions,
103                         defaultSizingObjects,
104                         sizeBarOptions,
105                         defaultArrowObjects,
106                         arrowContributions,
107                         staticInformationContributionObjects,
108                         dynamicSymbolContributionObjects,
109                         hideEdges != null ? hideEdges : false,
110                         hidePoints != null ? hidePoints : false,
111                         hideConsumers != null ? hideConsumers : false,
112                         hideProducers != null ? hideProducers : false,
113                         hideValves != null ? hideValves : false,
114                         hidePumpingStations != null ? hidePumpingStations : false,
115                         staticPropertiesNetworkBranch != null ? staticPropertiesNetworkBranch : false,
116                         staticProperiesPoints != null ? staticProperiesPoints : false,
117                         staticPropertiesConsumers != null ? staticPropertiesConsumers : false,
118                         dynamicSymbolsProducers != null ? dynamicSymbolsProducers : false,
119                         dynamicSymbolsShutoffValves != null ? dynamicSymbolsShutoffValves : false,
120                         dynamicSymbolsValves != null ? dynamicSymbolsValves : false,
121                         dynamicSymbolsPumpingStations != null ? dynamicSymbolsPumpingStations : false,
122                         keyVariablesVertexHover != null ? keyVariablesVertexHover : false,
123                         keyVariablesEdgesHover != null ? keyVariablesEdgesHover : false,
124                         showElevationServerBoundingBox != null ? showElevationServerBoundingBox : false,
125                         notInSimulation != null ? notInSimulation : false
126                     );
127                 return visualisation; 
128             }
129         }
130         return null;
131     }
132
133 }