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.model.ColorBarOptions;
19 import org.simantics.district.network.visualisations.model.DynamicArrowContribution;
20 import org.simantics.district.network.visualisations.model.DynamicColorContribution;
21 import org.simantics.district.network.visualisations.model.DynamicSizeContribution;
22 import org.simantics.district.network.visualisations.model.DynamicVisualisation;
23 import org.simantics.district.network.visualisations.model.SizeBarOptions;
24 import org.simantics.layer0.Layer0;
27 * @author Jani Simomaa
29 public class ActiveDynamicVisualisationsRequest extends ResourceRead<DynamicVisualisation> {
31 public ActiveDynamicVisualisationsRequest(Resource parent) {
36 public DynamicVisualisation perform(ReadGraph graph) throws DatabaseException {
37 DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
38 Resource visualisationFolder = DynamicVisualisations.getVisualisationFolder(graph, resource);
39 if (visualisationFolder != null) {
40 Resource visualisationResource = graph.getPossibleObject(visualisationFolder, DN.Diagram_hasActiveVisualisation);
41 if (visualisationResource != null) {
42 String name = graph.getRelatedValue(visualisationResource, Layer0.getInstance(graph).HasName);
44 Long interval = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_Interval, Bindings.LONG);
45 Boolean disabled = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_Disabled, Bindings.BOOLEAN);
47 Collection<DynamicColoringObject> dynamicColoringObjects = DynamicVisualisationsContributions.dynamicColoringObjects(graph);
48 Map<String, DynamicColoringObject> defaultColoringObjects = dynamicColoringObjects.stream().collect(Collectors.toMap(dcc -> dcc.getColoringObject().getName(), dcc -> dcc));
50 Collection<DynamicSizingObject> dynamicSizingObjects = DynamicVisualisationsContributions.dynamicSizingObjects(graph);
51 Map<String, DynamicSizingObject> defaultSizingObjects = dynamicSizingObjects.stream().collect(Collectors.toMap(dcc -> dcc.getSizingObject().getName(), dcc -> dcc));
53 Collection<DynamicArrowObject> dynamicArrowObjects = DynamicVisualisationsContributions.dynamicEdgeArrowObjects(graph);
54 Map<String, DynamicArrowObject> defaultArrowObjects = dynamicArrowObjects.stream().collect(Collectors.toMap(dac -> dac.getArrowObject().getName(), dac -> dac));
56 Map<String, DynamicColorContribution> colorContributions = DynamicVisualisations.colorContributions(graph, visualisationResource);
57 ColorBarOptions colorBarOptions = DynamicVisualisations.colorBarOptions(graph, visualisationResource);
58 Map<String, DynamicSizeContribution> sizeContributions = DynamicVisualisations.sizeContributions(graph, visualisationResource);
59 SizeBarOptions sizeBarOptions = DynamicVisualisations.sizeBarOptions(graph, visualisationResource);
60 Map<String, DynamicArrowContribution> arrowContributions = DynamicVisualisations.arrowContributions(graph, visualisationResource);
62 Boolean hideEdges = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_HideEdges, Bindings.BOOLEAN);
63 Boolean hidePoints = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_HidePoints, Bindings.BOOLEAN);
64 Boolean hideConsumers = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_HideConsumers, Bindings.BOOLEAN);
65 Boolean hideProducers = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_HideProducers, Bindings.BOOLEAN);
66 Boolean hideValves = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_HideValves, Bindings.BOOLEAN);
67 Boolean hidePumpingStations = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_HidePumpingStations, Bindings.BOOLEAN);
68 Boolean staticPropertiesNetworkBranch = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_StaticPropertiesNetworkBranches, Bindings.BOOLEAN);
69 Boolean staticProperiesPoints = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_StaticPropertiesPoints, Bindings.BOOLEAN);
70 Boolean staticPropertiesConsumers = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_StaticPropertiesConsumers, Bindings.BOOLEAN);
71 Boolean dynamicSymbolsProducers = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_DynamicSymbolsProducers, Bindings.BOOLEAN);
72 Boolean dynamicSymbolsShutoffValves = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_DynamicSymbolsShutoffValves, Bindings.BOOLEAN);
73 Boolean dynamicSymbolsValves = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_DynamicSymbolsValves, Bindings.BOOLEAN);
74 Boolean dynamicSymbolsPumpingStations = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_DynamicSymbolsPumpingStations, Bindings.BOOLEAN);
76 DynamicVisualisation visualisation = new DynamicVisualisation(name, visualisationResource,
77 interval != null ? interval : 2000,
78 disabled != null ? disabled : false,
80 defaultColoringObjects,
87 hideEdges != null ? hideEdges : false,
88 hidePoints != null ? hidePoints : false,
89 hideConsumers != null ? hideConsumers : false,
90 hideProducers != null ? hideProducers : false,
91 hideValves != null ? hideValves : false,
92 hidePumpingStations != null ? hidePumpingStations : false,
93 staticPropertiesNetworkBranch != null ? staticPropertiesNetworkBranch : false,
94 staticProperiesPoints != null ? staticProperiesPoints : false,
95 staticPropertiesConsumers != null ? staticPropertiesConsumers : false,
96 dynamicSymbolsProducers != null ? dynamicSymbolsProducers : false,
97 dynamicSymbolsShutoffValves != null ? dynamicSymbolsShutoffValves : false,
98 dynamicSymbolsValves != null ? dynamicSymbolsValves : false,
99 dynamicSymbolsPumpingStations != null ? dynamicSymbolsPumpingStations : false
101 return visualisation;