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 Collection<DynamicColoringObject> dynamicColoringObjects = DynamicVisualisationsContributions.dynamicColoringObjects(graph);
45 Map<String, DynamicColoringObject> defaultColoringObjects = dynamicColoringObjects.stream().collect(Collectors.toMap(dcc -> dcc.getColoringObject().getName(), dcc -> dcc));
47 Collection<DynamicSizingObject> dynamicSizingObjects = DynamicVisualisationsContributions.dynamicSizingObjects(graph);
48 Map<String, DynamicSizingObject> defaultSizingObjects = dynamicSizingObjects.stream().collect(Collectors.toMap(dcc -> dcc.getSizingObject().getName(), dcc -> dcc));
50 Collection<DynamicArrowObject> dynamicArrowObjects = DynamicVisualisationsContributions.dynamicEdgeArrowObjects(graph);
51 Map<String, DynamicArrowObject> defaultArrowObjects = dynamicArrowObjects.stream().collect(Collectors.toMap(dac -> dac.getArrowObject().getName(), dac -> dac));
53 Map<String, DynamicColorContribution> colorContributions = DynamicVisualisations.colorContributions(graph, visualisationResource);
54 ColorBarOptions colorBarOptions = DynamicVisualisations.colorBarOptions(graph, visualisationResource);
55 Map<String, DynamicSizeContribution> sizeContributions = DynamicVisualisations.sizeContributions(graph, visualisationResource);
56 SizeBarOptions sizeBarOptions = DynamicVisualisations.sizeBarOptions(graph, visualisationResource);
57 Map<String, DynamicArrowContribution> arrowContributions = DynamicVisualisations.arrowContributions(graph, visualisationResource);
59 Boolean hideEdges = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_HideEdges, Bindings.BOOLEAN);
60 Boolean hidePoints = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_HidePoints, Bindings.BOOLEAN);
61 Boolean hideConsumers = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_HideConsumers, Bindings.BOOLEAN);
62 Boolean hideProducers = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_HideProducers, Bindings.BOOLEAN);
63 Boolean hideValves = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_HideValves, Bindings.BOOLEAN);
64 Boolean hidePumpingStations = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_HidePumpingStations, Bindings.BOOLEAN);
65 Boolean staticPropertiesNetworkBranch = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_StaticPropertiesNetworkBranches, Bindings.BOOLEAN);
66 Boolean staticProperiesPoints = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_StaticPropertiesPoints, Bindings.BOOLEAN);
67 Boolean staticPropertiesConsumers = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_StaticPropertiesConsumers, Bindings.BOOLEAN);
68 Boolean dynamicSymbolsProducers = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_DynamicSymbolsProducers, Bindings.BOOLEAN);
69 Boolean dynamicSymbolsShutoffValves = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_DynamicSymbolsShutoffValves, Bindings.BOOLEAN);
70 Boolean dynamicSymbolsValves = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_DynamicSymbolsValves, Bindings.BOOLEAN);
71 Boolean dynamicSymbolsPumpingStations = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_DynamicSymbolsPumpingStations, Bindings.BOOLEAN);
73 DynamicVisualisation visualisation = new DynamicVisualisation(name, visualisationResource,
75 defaultColoringObjects,
82 hideEdges != null ? hideEdges : false,
83 hidePoints != null ? hidePoints : false,
84 hideConsumers != null ? hideConsumers : false,
85 hideProducers != null ? hideProducers : false,
86 hideValves != null ? hideValves : false,
87 hidePumpingStations != null ? hidePumpingStations : false,
88 staticPropertiesNetworkBranch != null ? staticPropertiesNetworkBranch : false,
89 staticProperiesPoints != null ? staticProperiesPoints : false,
90 staticPropertiesConsumers != null ? staticPropertiesConsumers : false,
91 dynamicSymbolsProducers != null ? dynamicSymbolsProducers : false,
92 dynamicSymbolsShutoffValves != null ? dynamicSymbolsShutoffValves : false,
93 dynamicSymbolsValves != null ? dynamicSymbolsValves : false,
94 dynamicSymbolsPumpingStations != null ? dynamicSymbolsPumpingStations : false