]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.network/src/org/simantics/district/network/profile/DiagramSettingsRequest.java
Remove unused profile throtting setting & assert diameter as Double
[simantics/district.git] / org.simantics.district.network / src / org / simantics / district / network / profile / DiagramSettingsRequest.java
index 6fdb9721f059b20d32498e75f0f423659ebfa5be..eac9ce0814982b3d4bbd309f8532f8469fb8b4bc 100644 (file)
@@ -20,63 +20,61 @@ public class DiagramSettingsRequest extends ResourceRead<DiagramSettings> {
                super(runtimeDiagram);
        }
 
-       @Override
+       @SuppressWarnings("unchecked")
+    @Override
        public DiagramSettings perform(ReadGraph graph) throws DatabaseException {
                DiagramResource DIA = DiagramResource.getInstance(graph);
                DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
 
-               Function1<Resource, Double> edgeThicknessProperty = null;
-               Function1<Resource, Double> nodeScaleProperty = null;
-               double edgeThicknessGain = 1;
-               double edgeThicknessBias = 0;
-               double nodeScaleGain = 1;
-               double nodeScaleBias = 0;
+               Function1<Resource, Double> 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);
-                       //System.out.println("etp: " + NameUtils.getURIOrSafeNameInternal(graph, etp));
-                       if (etp != null) {
-                               Variable etpv = Variables.getPossibleVariable(graph, etp);
-                               if (etpv != null) {
-                                       //System.out.println("etpv: " + etpv.getURI(graph));
-                                       edgeThicknessProperty = etpv.getPropertyValue(graph, DN.Edge_ThicknessProperty_value);
-                               }
+                       Variable dv = Variables.getPossibleVariable(graph, diagram);
 
-                               edgeThicknessGain =
-                                               safeDoubleProperty(graph, etp, DN.Edge_ThicknessProperty_gain, 1)
-                                               * safeDoubleProperty(graph, diagram, DN.Diagram_edgeThicknessGain, 1);
-                               edgeThicknessBias =
-                                               safeDoubleProperty(graph, etp, DN.Edge_ThicknessProperty_bias, 0)
-                                               + safeDoubleProperty(graph, diagram, DN.Diagram_edgeThicknessBias, 0);
-                       }
-                       Resource nsp = graph.getPossibleObject(diagram, DN.Diagram_nodeScaleProperty);
-                       if (nsp != null) {
-                               Variable nspv = Variables.getPossibleVariable(graph, nsp);
-                               if (nspv != null) {
-                                       //System.out.println("nspv: " + nspv.getURI(graph));
-                                       nodeScaleProperty = nspv.getPropertyValue(graph, DN.Vertex_ScaleProperty_value);
+                       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);
                                }
 
-                               nodeScaleGain =
-                                               safeDoubleProperty(graph, nsp, DN.Vertex_ScaleProperty_gain, 1)
-                                               * safeDoubleProperty(graph, diagram, DN.Diagram_nodeScaleGain, 1);
-                               nodeScaleBias =
-                                               safeDoubleProperty(graph, nsp, DN.Vertex_ScaleProperty_bias, 0)
-                                               + safeDoubleProperty(graph, diagram, DN.Diagram_nodeScaleBias, 0);
+                               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);
                        }
+
                }
 
-               DiagramSettings ds = new DiagramSettings(
-                               nodeScaleProperty, nodeScaleGain, nodeScaleBias,
-                               edgeThicknessProperty, edgeThicknessGain, edgeThicknessBias);
+               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 {
                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));
+       }
+
 }