X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.network%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fprofile%2FDiagramSettingsRequest.java;h=eac9ce0814982b3d4bbd309f8532f8469fb8b4bc;hb=c208db116abb1f2f56859f3b0fee2e28d8fdb569;hp=726005eef7e088dfcd0024153988d0c2f2b50fc9;hpb=a3b6137601545ac6e3484995d0ec6d39224bbf3f;p=simantics%2Fdistrict.git 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 index 726005ee..eac9ce08 100644 --- 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 @@ -5,45 +5,62 @@ 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.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; import org.simantics.diagram.stubs.DiagramResource; import org.simantics.district.network.ontology.DistrictNetworkResource; +import org.simantics.scl.runtime.function.Function1; /** * @author Tuukka Lehtonen */ public class DiagramSettingsRequest extends ResourceRead { - protected DiagramSettingsRequest(Resource runtimeDiagram) { + public DiagramSettingsRequest(Resource runtimeDiagram) { super(runtimeDiagram); } - @Override + @SuppressWarnings("unchecked") + @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; + Function1 arrowLengthProperty = null; + double arrowLengthGain = 1; + double arrowLengthBias = 0; 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); + Variable dv = Variables.getPossibleVariable(graph, diagram); + + Resource alp = graph.getPossibleObject(diagram, DN.Diagram_arrowLengthProperty); + //System.out.println("alp: " + NameUtils.getURIOrSafeNameInternal(graph, alp)); + if (alp != null) { + Variable alpv = Variables.getPossibleVariable(graph, alp); + if (alpv != null) { + //System.out.println("alpv: " + alpv.getURI(graph)); + arrowLengthProperty = alpv.getPropertyValue(graph, DN.Edge_ArrowLengthProperty_value); + } + + arrowLengthGain = + safeDoubleProperty(graph, alp, DN.Edge_ArrowLengthProperty_gain, 1) + * safeDoubleProperty(graph, diagram, DN.Diagram_arrowLengthGain, 1); + arrowLengthBias = + safeDoubleProperty(graph, alp, DN.Edge_ArrowLengthProperty_bias, 0) + + safeDoubleProperty(graph, diagram, DN.Diagram_arrowLengthBias, 0); + } + } - return new DiagramSettings(nodeScalingProperty, nodeScalingScale, edgeThicknessProperty, edgeThicknessScale); + DiagramSettings ds = new DiagramSettings( arrowLengthProperty, arrowLengthGain, arrowLengthBias); + //System.out.println("new diagram settings: " + ds); + return ds; + } + + private static float safeFloatProperty(ReadGraph graph, Resource r, Resource property, float defaultValue) throws DatabaseException { + Float d = graph.getPossibleRelatedValue(r, property, Bindings.FLOAT); + return d != null ? d : defaultValue; } private static double safeDoubleProperty(ReadGraph graph, Resource r, Resource property, double defaultValue) throws DatabaseException { @@ -51,4 +68,13 @@ public class DiagramSettingsRequest extends ResourceRead { return d != null ? d : defaultValue; } + private static float limit(float min, float max, float value) { + return Math.max(min, Math.min(value, max)); + } + + @SuppressWarnings("unused") + private static double limit(double min, double max, double value) { + return Math.max(min, Math.min(value, max)); + } + }