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=2254b305706c6fb0d997fcbe9c65fba6384b4bfe;hb=fa8b6523f7dc37c548f0bdd614e74b71a624c276;hp=6fdb9721f059b20d32498e75f0f423659ebfa5be;hpb=29914be09d4a237840e5c793bdb562ec83093b8d;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 6fdb9721..2254b305 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 @@ -20,20 +20,41 @@ public class DiagramSettingsRequest extends ResourceRead { super(runtimeDiagram); } - @Override + @SuppressWarnings("unchecked") + @Override public DiagramSettings perform(ReadGraph graph) throws DatabaseException { DiagramResource DIA = DiagramResource.getInstance(graph); DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); + Function1 elementColoringFunction = null; + float elementColoringGradientHue = 0; + float elementColoringGradientSaturation = 1; Function1 edgeThicknessProperty = null; + Function1 arrowLengthProperty = null; Function1 nodeScaleProperty = null; double edgeThicknessGain = 1; double edgeThicknessBias = 0; + double arrowLengthGain = 1; + double arrowLengthBias = 0; double nodeScaleGain = 1; double nodeScaleBias = 0; Resource diagram = graph.getPossibleObject(resource, DIA.RuntimeDiagram_HasConfiguration); if (diagram != null) { + Variable dv = Variables.getPossibleVariable(graph, diagram); + if (dv != null) { + Object obj = dv.getPossiblePropertyValue(graph, DN.Diagram_elementColoringFunction); + if (obj instanceof Function1) { + elementColoringFunction = (Function1) obj; + } + } + elementColoringGradientHue = + limit(0, 360, safeFloatProperty(graph, diagram, DN.Diagram_elementColoringGradientHue, 0.0f)) + / 360.0f; + elementColoringGradientSaturation = + limit(0, 100, safeFloatProperty(graph, diagram, DN.Diagram_elementColoringGradientSaturation, 0.0f)) + / 100.0f; + Resource etp = graph.getPossibleObject(diagram, DN.Diagram_edgeThicknessProperty); //System.out.println("etp: " + NameUtils.getURIOrSafeNameInternal(graph, etp)); if (etp != null) { @@ -50,6 +71,22 @@ public class DiagramSettingsRequest extends ResourceRead { safeDoubleProperty(graph, etp, DN.Edge_ThicknessProperty_bias, 0) + safeDoubleProperty(graph, diagram, DN.Diagram_edgeThicknessBias, 0); } + 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); + } Resource nsp = graph.getPossibleObject(diagram, DN.Diagram_nodeScaleProperty); if (nsp != null) { Variable nspv = Variables.getPossibleVariable(graph, nsp); @@ -69,14 +106,32 @@ public class DiagramSettingsRequest extends ResourceRead { DiagramSettings ds = new DiagramSettings( nodeScaleProperty, nodeScaleGain, nodeScaleBias, - edgeThicknessProperty, edgeThicknessGain, edgeThicknessBias); + edgeThicknessProperty, edgeThicknessGain, edgeThicknessBias, + arrowLengthProperty, arrowLengthGain, arrowLengthBias, + elementColoringFunction, + elementColoringGradientHue, + elementColoringGradientSaturation); //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 { Double d = graph.getPossibleRelatedValue(r, property, Bindings.DOUBLE); 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)); + } + }