]> gerrit.simantics Code Review - simantics/district.git/blob
726005eef7e088dfcd0024153988d0c2f2b50fc9
[simantics/district.git] /
1 package org.simantics.district.network.profile;
2
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;
10
11 /**
12  * @author Tuukka Lehtonen
13  */
14 public class DiagramSettingsRequest extends ResourceRead<DiagramSettings> {
15
16         protected DiagramSettingsRequest(Resource runtimeDiagram) {
17                 super(runtimeDiagram);
18         }
19
20         @Override
21         public DiagramSettings perform(ReadGraph graph) throws DatabaseException {
22                 DiagramResource DIA = DiagramResource.getInstance(graph);
23                 DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
24
25                 Resource edgeThicknessProperty = null;
26                 Resource nodeScalingProperty = null;
27                 double edgeThicknessScale = 1;
28                 double nodeScalingScale = 1;
29
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);
36
37                         edgeThicknessScale =
38                                         safeDoubleProperty(graph, etp, DN.Edge_ThicknessProperty_scale, 1)
39                                         * safeDoubleProperty(graph, diagram, DN.Diagram_edgeThicknessScale, 1);
40
41 //                      nodeScalingScale =
42 //                                      safeDoubleProperty(graph, nsp, DN.Vertex_ScaleProperty_scale, 1)
43 //                                      * safeDoubleProperty(graph, diagram, DN.Diagram_nodeScale, 1);
44                 }
45
46                 return new DiagramSettings(nodeScalingProperty, nodeScalingScale, edgeThicknessProperty, edgeThicknessScale);
47         }
48
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;
52         }
53
54 }