[PATCH 6 of 6] issue1020: When preparing wsts for wsplgen handle other than standard wqkms calculations

Wald Commits scm-commit at wald.intevation.org
Thu Dec 5 15:38:48 CET 2013


# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1386254315 -3600
# Node ID 786ff139de5eb968718496a49e31cd40aba82775
# Parent  f603a53e45dca2378b97e986f056dadaae19da08
issue1020: When preparing wsts for wsplgen handle other than standard wqkms calculations.

diff -r f603a53e45dc -r 786ff139de5e artifacts/src/main/java/org/dive4elements/river/artifacts/states/FloodMapState.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/FloodMapState.java	Thu Dec 05 15:35:53 2013 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/FloodMapState.java	Thu Dec 05 15:38:35 2013 +0100
@@ -30,6 +30,7 @@
 import org.dive4elements.artifacts.GlobalContext;
 import org.dive4elements.artifacts.common.utils.FileTools;
 import org.dive4elements.river.artifacts.D4EArtifact;
+import org.dive4elements.river.artifacts.StaticWKmsArtifact;
 import org.dive4elements.river.artifacts.access.DGMAccess;
 import org.dive4elements.river.artifacts.access.RangeAccess;
 import org.dive4elements.river.artifacts.context.RiverContext;
@@ -37,7 +38,9 @@
 import org.dive4elements.river.artifacts.model.CalculationResult;
 import org.dive4elements.river.artifacts.model.FacetTypes;
 import org.dive4elements.river.artifacts.model.LayerInfo;
+import org.dive4elements.river.artifacts.model.WKms;
 import org.dive4elements.river.artifacts.model.WQKms;
+import org.dive4elements.river.artifacts.model.fixings.FixRealizingResult;
 import org.dive4elements.river.artifacts.model.map.HWS;
 import org.dive4elements.river.artifacts.model.map.HWSContainer;
 import org.dive4elements.river.artifacts.model.map.HWSFactory;
@@ -936,27 +939,51 @@
         }
         catch (NumberFormatException nfe) { /* do nothing */ }
 
-        // issue1020: Other kinds of artifacts might calculate other stuff than
-        // WQKms or provide data in more static manner (shiver).
-
         D4EArtifact src = otherArtifact != null
             ? RiverUtils.getArtifact(otherArtifact, cc)
             : flys;
 
         logger.debug("Use waterlevel provided by Artifact: " + src.identifier());
 
-        CalculationResult rawData = (CalculationResult) src.compute(
+        // The state actually depends on the kind of artifact. E.g. StaticWQKmsArtifact needs other state
+        Object computed = src.compute(
             cc,
-            null,
-            WINFO_WSP_STATE_ID,
+            //null,
+            //WINFO_WSP_STATE_ID,
             ComputeType.ADVANCE,
             false);
 
-        WQKms[] wqkms = (WQKms[]) rawData.getData();
+        // Depending on the artifact and calculation we have different results
+        // in place. Note that the same conditions exist in
+        // WaterlevelSelectState#getLabel .
 
-        return wqkms == null || idx == -1 || idx >= wqkms.length
-            ? null
-            : wqkms[idx];
+        // Regular WSP calculation
+        if (computed instanceof CalculationResult) {
+            CalculationResult rawData = (CalculationResult) computed;
+            WQKms[] wqkms;
+            if (rawData.getData() instanceof FixRealizingResult) {
+                wqkms = (WQKms[]) ((FixRealizingResult) rawData.getData()).getWQKms();
+            }
+            else {
+                wqkms = (WQKms[]) rawData.getData();
+            }
+            return wqkms == null || idx == -1 || idx >= wqkms.length
+                ? null
+                : wqkms[idx];
+        }
+        else if (computed instanceof WQKms) {
+            // e.g. Fixations
+            WQKms wqkms = (WQKms) computed;
+            return (WQKms) computed;
+        }
+        else if (computed == null && src instanceof StaticWKmsArtifact) {
+            // Floodmarks and protection.
+            WQKms wqkms = WQKms.fromWKms(((StaticWKmsArtifact) src).getWKms(0), 1d);
+            return wqkms;
+        }
+
+        logger.warn("getWQKms cannot handle " + computed.getClass() + " " + src.getClass());
+        return null;
     }
 
 
@@ -990,8 +1017,6 @@
             writeWspTag = false;
         }
 
-        // TODO issue1020: data might be something different than wqkms,
-        // abstract this here a little away.
         for (int i = 0, num = data.size(); i < num; i++) {
             data.get(i, buf);
             writer.add(buf);


More information about the Dive4elements-commits mailing list