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.diagram.stubs.DiagramResource;
9 import org.simantics.district.network.ontology.DistrictNetworkResource;
12 * @author Tuukka Lehtonen
14 public class DiagramSettingsRequest extends ResourceRead<DiagramSettings> {
16 protected DiagramSettingsRequest(Resource runtimeDiagram) {
17 super(runtimeDiagram);
21 public DiagramSettings perform(ReadGraph graph) throws DatabaseException {
22 DiagramResource DIA = DiagramResource.getInstance(graph);
23 DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
25 Resource edgeThicknessProperty = null;
26 Resource nodeScalingProperty = null;
27 double edgeThicknessScale = 1;
28 double nodeScalingScale = 1;
30 Resource diagram = graph.getPossibleObject(resource, DIA.RuntimeDiagram_HasConfiguration);
31 if (diagram != null) {
32 Resource etp = graph.getPossibleObject(diagram, DN.Diagram_edgeThicknessProperty);
33 edgeThicknessProperty = graph.getPossibleObject(etp, DN.Edge_ThicknessProperty_value);
34 // Resource nsp = graph.getPossibleObject(diagram, DN.Diagram_nodeScalingProperty);
35 // nodeScalingProperty = graph.getPossibleObject(nsp, DN.Vertex_ScaleProperty_value);
38 safeDoubleProperty(graph, etp, DN.Edge_ThicknessProperty_scale, 1)
39 * safeDoubleProperty(graph, diagram, DN.Diagram_edgeThicknessScale, 1);
42 // safeDoubleProperty(graph, nsp, DN.Vertex_ScaleProperty_scale, 1)
43 // * safeDoubleProperty(graph, diagram, DN.Diagram_nodeScale, 1);
46 return new DiagramSettings(nodeScalingProperty, nodeScalingScale, edgeThicknessProperty, edgeThicknessScale);
49 private static double safeDoubleProperty(ReadGraph graph, Resource r, Resource property, double defaultValue) throws DatabaseException {
50 Double d = graph.getPossibleRelatedValue(r, property, Bindings.DOUBLE);
51 return d != null ? d : defaultValue;