changeset 1138:d90f5bfa3ddf

Fix profile loading of cross section diagram. flys-artifacts/trunk@2659 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 07 Sep 2011 07:48:03 +0000
parents 073c36bb94ed
children 6d9b08b958e2
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java
diffstat 4 files changed, 112 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Sep 07 07:37:22 2011 +0000
+++ b/flys-artifacts/ChangeLog	Wed Sep 07 07:48:03 2011 +0000
@@ -1,3 +1,18 @@
+2011-09-07  Felix Wolfsteller <felix.wolfsteller@intevation.de>
+
+	Fix setting of kilometer for profile (not yet waterlevel) of cross section
+	diagram.
+
+	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java:
+	  (getCrossSectionData): Respect corss_section.km data; do naive linear
+	  search for profile data for this km.
+
+	* src/main/java/de/intevation/flys/artifacts/model/CrossSectionFacet.java:
+	  Declare a ComputeType.
+
+	* src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java:
+	  Implement computeFeed.
+
 2011-09-07  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java,
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Wed Sep 07 07:37:22 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Wed Sep 07 07:48:03 2011 +0000
@@ -655,7 +655,31 @@
      *         in the form {{x1, x2} {y1, y2}} ).
      */
     public double [][] getCrossSectionData() {
-        return getCrossSectionProfile(getCrossSections().get(0).getLines().get(0));
+        logger.info("getCrossSectionData(), also cross_section.km " + getDataAsString("cross_section.km"));
+        double wishKM = 0.0f;
+        try {
+            wishKM = Double.parseDouble(getDataAsString("cross_section.km"));
+        }
+        catch (Exception e) {
+            ;
+        }
+
+        // Get the cross section closest to requested km.
+        //
+        // Naive, linear approach.
+        List<CrossSectionLine> crossSectionLines =
+            getCrossSections().get(0).getLines();
+        CrossSectionLine oldLine = crossSectionLines.get(0);
+        double oldDiff = Math.abs(wishKM - oldLine.getKm().doubleValue());
+        for (CrossSectionLine line: crossSectionLines) {
+            double diff = Math.abs(wishKM - line.getKm().doubleValue());
+            if (diff > oldDiff) {
+                break;
+            }
+            oldDiff = diff;
+            oldLine = line;
+        }
+        return getCrossSectionProfile(oldLine);
     }
 
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionFacet.java	Wed Sep 07 07:37:22 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionFacet.java	Wed Sep 07 07:48:03 2011 +0000
@@ -22,10 +22,12 @@
 
     private static Logger logger = Logger.getLogger(CrossSectionFacet.class);
 
+    protected ComputeType type;
 
     /** Trivial constructor, set (maybe localized) description. */
     public CrossSectionFacet(String description) {
         super(0, CROSS_SECTION, description);
+        type = ComputeType.ADVANCE;
     }
 
 
@@ -40,6 +42,8 @@
         return winfo.getCrossSectionData();
     }
 
+
+    /** Do a deep copy. */
     @Override 
     public Facet deepCopy() {
         CrossSectionFacet copy = new CrossSectionFacet(this.description);
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java	Wed Sep 07 07:37:22 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java	Wed Sep 07 07:48:03 2011 +0000
@@ -36,6 +36,74 @@
     }
 
 
+    // TODO This is a duplicate of computeAdvance. Resolve.
+    public Object computeFeed(
+        FLYSArtifact artifact,
+        String       hash,
+        CallContext  context,
+        List<Facet>  facets,
+        Object       old
+    ) {
+        WINFOArtifact winfo = (WINFOArtifact)artifact;
+
+        String id = getID();
+
+        CalculationResult res = old instanceof CalculationResult
+            ? (CalculationResult)old
+            : winfo.getWaterlevelData();
+
+        if (facets == null) {
+            return res;
+        }
+
+        WQKms [] wqkms = (WQKms [])res.getData();
+
+        for (int i = 0; i < wqkms.length; i++) {
+            String nameW = null;
+            String nameQ = null;
+
+            if (winfo.isQ()) {
+                nameQ = wqkms[i].getName();
+                nameW = "W(" + nameQ + ")";
+            }
+            else {
+                nameW = wqkms[i].getName();
+                nameQ = "Q(" + nameQ + ")";
+            }
+
+            logger.debug("Create facet: " + nameW);
+            logger.debug("Create facet: " + nameQ);
+
+            Facet w = new WaterlevelFacet(
+                i, LONGITUDINAL_W, nameW, ComputeType.ADVANCE, id, hash);
+            Facet q = new WaterlevelFacet(
+                i, LONGITUDINAL_Q, nameQ, ComputeType.ADVANCE, id, hash);
+
+            facets.add(w);
+            facets.add(q);
+        }
+
+        if (wqkms.length > 0) {
+            Facet wst = new DataFacet(
+                WST, "WST data", ComputeType.ADVANCE, hash, id);
+            Facet csv = new DataFacet(
+                CSV, "CSV data", ComputeType.ADVANCE, hash, id);
+
+            facets.add(wst);
+            facets.add(csv);
+        }
+
+        if (res.getReport().hasProblems()) {
+            facets.add(new ReportFacet(ComputeType.ADVANCE, hash, id));
+        }
+
+        // Also register the CrossSectionFacet (added to respective out).
+        facets.add(new CrossSectionFacet("facet.cross_section"));
+        facets.add(new CrossSectionWaterLineFacet("facet.cross_section_water_line"));
+        return res;
+    }
+
+
     @Override
     public Object computeAdvance(
         FLYSArtifact artifact,

http://dive4elements.wald.intevation.org