]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.network/src/org/simantics/district/network/profile/DiagramSettingsRequest.java
Added Edge.ThicknessProperty for generic edge-thickness styling
[simantics/district.git] / org.simantics.district.network / src / org / simantics / district / network / profile / DiagramSettingsRequest.java
diff --git a/org.simantics.district.network/src/org/simantics/district/network/profile/DiagramSettingsRequest.java b/org.simantics.district.network/src/org/simantics/district/network/profile/DiagramSettingsRequest.java
new file mode 100644 (file)
index 0000000..726005e
--- /dev/null
@@ -0,0 +1,54 @@
+package org.simantics.district.network.profile;
+
+import org.simantics.databoard.Bindings;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.ResourceRead;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.district.network.ontology.DistrictNetworkResource;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class DiagramSettingsRequest extends ResourceRead<DiagramSettings> {
+
+       protected DiagramSettingsRequest(Resource runtimeDiagram) {
+               super(runtimeDiagram);
+       }
+
+       @Override
+       public DiagramSettings perform(ReadGraph graph) throws DatabaseException {
+               DiagramResource DIA = DiagramResource.getInstance(graph);
+               DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+
+               Resource edgeThicknessProperty = null;
+               Resource nodeScalingProperty = null;
+               double edgeThicknessScale = 1;
+               double nodeScalingScale = 1;
+
+               Resource diagram = graph.getPossibleObject(resource, DIA.RuntimeDiagram_HasConfiguration);
+               if (diagram != null) {
+                       Resource etp = graph.getPossibleObject(diagram, DN.Diagram_edgeThicknessProperty);
+                       edgeThicknessProperty = graph.getPossibleObject(etp, DN.Edge_ThicknessProperty_value);
+//                     Resource nsp = graph.getPossibleObject(diagram, DN.Diagram_nodeScalingProperty);
+//                     nodeScalingProperty = graph.getPossibleObject(nsp, DN.Vertex_ScaleProperty_value);
+
+                       edgeThicknessScale =
+                                       safeDoubleProperty(graph, etp, DN.Edge_ThicknessProperty_scale, 1)
+                                       * safeDoubleProperty(graph, diagram, DN.Diagram_edgeThicknessScale, 1);
+
+//                     nodeScalingScale =
+//                                     safeDoubleProperty(graph, nsp, DN.Vertex_ScaleProperty_scale, 1)
+//                                     * safeDoubleProperty(graph, diagram, DN.Diagram_nodeScale, 1);
+               }
+
+               return new DiagramSettings(nodeScalingProperty, nodeScalingScale, edgeThicknessProperty, edgeThicknessScale);
+       }
+
+       private static double safeDoubleProperty(ReadGraph graph, Resource r, Resource property, double defaultValue) throws DatabaseException {
+               Double d = graph.getPossibleRelatedValue(r, property, Bindings.DOUBLE);
+               return d != null ? d : defaultValue;
+       }
+
+}