1 package org.simantics.district.network.profile;
3 import java.util.Collection;
5 import java.util.stream.Collectors;
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;
29 * @author Jani Simomaa
31 public class ActiveDynamicVisualisationsRequest extends ResourceRead<DynamicVisualisation> {
33 public ActiveDynamicVisualisationsRequest(Resource parent) {
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);
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);
50 Collection<DynamicColoringObject> dynamicColoringObjects = DynamicVisualisationsContributions.dynamicColoringObjects(graph);
51 Map<String, DynamicColoringObject> defaultColoringObjects = dynamicColoringObjects.stream().collect(Collectors.toMap(dcc -> dcc.getColoringObject().getName(), dcc -> dcc));
53 Collection<DynamicSizingObject> dynamicSizingObjects = DynamicVisualisationsContributions.dynamicSizingObjects(graph);
54 Map<String, DynamicSizingObject> defaultSizingObjects = dynamicSizingObjects.stream().collect(Collectors.toMap(dcc -> dcc.getSizingObject().getName(), dcc -> dcc));
56 Collection<DynamicArrowObject> dynamicArrowObjects = DynamicVisualisationsContributions.dynamicEdgeArrowObjects(graph);
57 Map<String, DynamicArrowObject> defaultArrowObjects = dynamicArrowObjects.stream().collect(Collectors.toMap(dac -> dac.getArrowObject().getName(), dac -> dac));
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);
65 Collection<StaticInformationContributionObject> staticInformationContributions = DynamicVisualisationsContributions.staticInformationContributionObjects(graph);
66 Map<String, StaticInformationContributionObject> staticInformationContributionObjects = staticInformationContributions.stream().collect(Collectors.toMap(dcc -> dcc.getStaticInformationContributionObject().getName(), dcc -> dcc));
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);
73 }).collect(Collectors.toMap(dcc -> dcc.getDynamicSymbolContributionObject().getName(), dcc -> dcc));
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);
89 Boolean keyVariablesVertexHover = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_KeyVariableVertexHover, Bindings.BOOLEAN);
90 Boolean keyVariablesEdgesHover = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_KeyVariableEdgeHover, Bindings.BOOLEAN);
92 Boolean showElevationServerBoundingBox = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_ShowElevationServerBoundingBox, Bindings.BOOLEAN);
93 Boolean notInSimulation = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_NotInSimulation, Bindings.BOOLEAN);
95 DynamicVisualisation visualisation = new DynamicVisualisation(name, visualisationResource,
96 interval != null ? interval : 2000,
97 disabledUpdates != null ? disabledUpdates : false,
98 resetVisualisation != null ? resetVisualisation : false,
100 defaultColoringObjects,
103 defaultSizingObjects,
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
127 return visualisation;