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 { 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; } }