changeset 319:d8558dd64152

The WQ state fills the DESCRIBE with default values for W and Q. flys-artifacts/trunk@1707 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 15 Apr 2011 13:47:10 +0000
parents 8a4360ccbe1c
children a8e7c351bdf1
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java
diffstat 2 files changed, 70 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Apr 15 13:46:22 2011 +0000
+++ b/flys-artifacts/ChangeLog	Fri Apr 15 13:47:10 2011 +0000
@@ -1,3 +1,8 @@
+2011-04-15  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/states/WQSelect.java: Fills
+	  the DESCRIBE with default values for W and Q.
+
 2011-04-15  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/model/WstFactory.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java	Fri Apr 15 13:46:22 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java	Fri Apr 15 13:47:10 2011 +0000
@@ -12,6 +12,12 @@
 import de.intevation.artifactdatabase.ProtocolUtils;
 import de.intevation.artifactdatabase.data.StateData;
 
+import de.intevation.flys.model.Gauge;
+import de.intevation.flys.model.River;
+import de.intevation.flys.model.Wst;
+
+import de.intevation.flys.artifacts.FLYSArtifact;
+import de.intevation.flys.artifacts.model.WstFactory;
 import de.intevation.flys.artifacts.resources.Resources;
 
 /**
@@ -70,15 +76,21 @@
         CallContext context)
     {
         // TODO Insert correct min/max values!
+        double[] minmaxW = determineMinMaxW(artifact);
+        double[] minmaxQ = determineMinMaxQ(artifact);
 
         if (name.equals("wq_from")) {
-            Element minW = createItem(cr, new String[] {"minW", "250"});
-            Element minQ = createItem(cr, new String[] {"minQ", "5.5"});
+            Element minW = createItem(
+                cr, new String[] {"minW", new Double(minmaxW[0]).toString()});
+            Element minQ = createItem(
+                cr, new String[] {"minQ", new Double(minmaxQ[0]).toString()});
             return new Element[] { minW, minQ };
         }
         else if (name.equals("wq_to")) {
-            Element maxW = createItem(cr, new String[] {"maxW", "850"});
-            Element maxQ = createItem(cr, new String[] {"maxQ", "1530"});
+            Element maxW = createItem(
+                cr, new String[] {"maxW", new Double(minmaxW[1]).toString()});
+            Element maxQ = createItem(
+                cr, new String[] {"maxQ", new Double(minmaxQ[1]).toString()});
             return new Element[] { maxW, maxQ };
         }
         else {
@@ -109,5 +121,54 @@
     protected String getUIProvider() {
         return "wq_panel";
     }
+
+
+    /**
+     * Determines the min and max W value for the current gauge. If no min and
+     * max values could be determined, this method will return
+     * [Double.MIN_VALUE, Double.MAX_VALUE].
+     *
+     * @param artifact The FLYSArtifact.
+     *
+     * @return the min and max W values for the current gauge.
+     */
+    protected double[] determineMinMaxW(Artifact artifact) {
+        logger.debug("WQSelect.determineCurrentGauge");
+
+        Gauge    gauge   = ((FLYSArtifact) artifact).getGauge();
+        double[] minmaxW = gauge.determineMinMaxW();
+
+        double minW = minmaxW != null ? minmaxW[0] : Double.MIN_VALUE;
+        double maxW = minmaxW != null ? minmaxW[1] : Double.MAX_VALUE;
+
+        return new double[] { minW, maxW };
+    }
+
+
+    /**
+     * Determines the min and max Q value for the current gauge. If no min and
+     * max values could be determined, this method will return
+     * [Double.MIN_VALUE, Double.MAX_VALUE].
+     *
+     * @param artifact The FLYSArtifact.
+     *
+     * @return the min and max Q values for the current gauge.
+     */
+    protected double[] determineMinMaxQ(Artifact artifact) {
+        logger.debug("WQSelect.determineMinMaxQ");
+
+        FLYSArtifact flysArtifact = (FLYSArtifact) artifact;
+
+        River    river = flysArtifact.getRiver();
+        Gauge    gauge = flysArtifact.getGauge();
+        Wst      wst   = WstFactory.getWst(river);
+
+        double[] minmaxQ = wst.determineMinMaxQ(gauge.getRange());
+
+        double minQ = minmaxQ != null ? minmaxQ[0] : Double.MIN_VALUE;
+        double maxQ = minmaxQ != null ? minmaxQ[1] : Double.MAX_VALUE;
+
+        return new double[] { minQ, maxQ };
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org