1 package org.simantics.district.network.profile;
3 import org.simantics.databoard.Bindings;
4 import org.simantics.db.ReadGraph;
5 import org.simantics.db.Resource;
6 import org.simantics.db.common.request.ResourceRead;
7 import org.simantics.db.exception.DatabaseException;
8 import org.simantics.db.layer0.variable.Variable;
9 import org.simantics.db.layer0.variable.Variables;
10 import org.simantics.diagram.stubs.DiagramResource;
11 import org.simantics.district.network.ontology.DistrictNetworkResource;
12 import org.simantics.scl.runtime.function.Function1;
15 * @author Tuukka Lehtonen
17 public class DiagramSettingsRequest extends ResourceRead<DiagramSettings> {
19 public DiagramSettingsRequest(Resource runtimeDiagram) {
20 super(runtimeDiagram);
24 public DiagramSettings perform(ReadGraph graph) throws DatabaseException {
25 DiagramResource DIA = DiagramResource.getInstance(graph);
26 DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
28 Function1<Resource, Double> edgeThicknessProperty = null;
29 Function1<Resource, Double> nodeScaleProperty = null;
30 double edgeThicknessGain = 1;
31 double edgeThicknessBias = 0;
32 double nodeScaleGain = 1;
33 double nodeScaleBias = 0;
35 Resource diagram = graph.getPossibleObject(resource, DIA.RuntimeDiagram_HasConfiguration);
36 if (diagram != null) {
37 Resource etp = graph.getPossibleObject(diagram, DN.Diagram_edgeThicknessProperty);
38 //System.out.println("etp: " + NameUtils.getURIOrSafeNameInternal(graph, etp));
40 Variable etpv = Variables.getPossibleVariable(graph, etp);
42 //System.out.println("etpv: " + etpv.getURI(graph));
43 edgeThicknessProperty = etpv.getPropertyValue(graph, DN.Edge_ThicknessProperty_value);
47 safeDoubleProperty(graph, etp, DN.Edge_ThicknessProperty_gain, 1)
48 * safeDoubleProperty(graph, diagram, DN.Diagram_edgeThicknessGain, 1);
50 safeDoubleProperty(graph, etp, DN.Edge_ThicknessProperty_bias, 0)
51 + safeDoubleProperty(graph, diagram, DN.Diagram_edgeThicknessBias, 0);
53 Resource nsp = graph.getPossibleObject(diagram, DN.Diagram_nodeScaleProperty);
55 Variable nspv = Variables.getPossibleVariable(graph, nsp);
57 //System.out.println("nspv: " + nspv.getURI(graph));
58 nodeScaleProperty = nspv.getPropertyValue(graph, DN.Vertex_ScaleProperty_value);
62 safeDoubleProperty(graph, nsp, DN.Vertex_ScaleProperty_gain, 1)
63 * safeDoubleProperty(graph, diagram, DN.Diagram_nodeScaleGain, 1);
65 safeDoubleProperty(graph, nsp, DN.Vertex_ScaleProperty_bias, 0)
66 + safeDoubleProperty(graph, diagram, DN.Diagram_nodeScaleBias, 0);
70 DiagramSettings ds = new DiagramSettings(
71 nodeScaleProperty, nodeScaleGain, nodeScaleBias,
72 edgeThicknessProperty, edgeThicknessGain, edgeThicknessBias);
73 //System.out.println("new diagram settings: " + ds);
77 private static double safeDoubleProperty(ReadGraph graph, Resource r, Resource property, double defaultValue) throws DatabaseException {
78 Double d = graph.getPossibleRelatedValue(r, property, Bindings.DOUBLE);
79 return d != null ? d : defaultValue;