changeset 3198:d35f28655fa6

Create and handle new manual line type facets. flys-artifacts/trunk@4814 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 27 Jun 2012 15:22:01 +0000
parents 3e7911a02645
children b29d7bb8eb8c
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/ManualPointsArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionWaterLineFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ManualPointsSingleState.java flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java
diffstat 5 files changed, 137 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Jun 27 15:11:23 2012 +0000
+++ b/flys-artifacts/ChangeLog	Wed Jun 27 15:22:01 2012 +0000
@@ -1,3 +1,20 @@
+2012-06-27	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	Create and handle new manual line facets.
+
+	* src/main/java/de/intevation/flys/artifacts/model/CrossSectionWaterLineFacet.java:
+	  Added new constructor to play nice with upcoming facet-type.
+
+	* src/main/java/de/intevation/flys/artifacts/ManualPointsArtifact.java:
+	  Added functionality to serve as WaterLineFacet (calculate water
+	  line against cross section profile).
+
+	* src/main/java/de/intevation/flys/artifacts/states/ManualPointsSingleState.java:
+	  Extended to generate cross section water line facets, too.
+
+	* src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java:
+	  Handle new Facet Type.
+
 2012-06-27	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	FacetType for upcoming cross_section.manualline facet.
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/ManualPointsArtifact.java	Wed Jun 27 15:11:23 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/ManualPointsArtifact.java	Wed Jun 27 15:22:01 2012 +0000
@@ -3,10 +3,15 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import java.awt.geom.Point2D;
+
 import org.apache.log4j.Logger;
 
 import org.w3c.dom.Document;
 
+import org.json.JSONArray;
+import org.json.JSONException;
+
 import de.intevation.artifactdatabase.state.Facet;
 
 import de.intevation.artifacts.Artifact;
@@ -17,6 +22,9 @@
 
 import de.intevation.flys.artifacts.states.DefaultState;
 
+import de.intevation.flys.model.FastCrossSectionLine;
+
+import de.intevation.flys.geom.Lines;
 
 
 /**
@@ -24,7 +32,7 @@
  */
 public class ManualPointsArtifact
 extends      StaticFLYSArtifact
-implements   FacetTypes
+implements   FacetTypes, WaterLineArtifact
 {
     /** The logger for this class. */
     private static Logger logger = Logger.getLogger(ManualPointsArtifact.class);
@@ -70,6 +78,20 @@
     }
 
 
+    /**
+     * Access state data storing the jsonstring with lines.
+     * @param facetName Name of facet or null if the so far
+     *                  only known case should be picked.
+     * @return (String) value of data element (expect json).
+     */
+    public String getLinesData(String facetName) {
+        if (facetName == null)
+            return getDataAsString("cross_section.manualpoints.lines");
+        // TODO .lineS?
+        return getDataAsString(facetName + ".line");
+    }
+
+
     /** Setup state and facet. */
     @Override
     protected void initialize(Artifact artifact, Object context, CallMeta meta) {
@@ -90,6 +112,34 @@
 
 
     /**
+     * Get value of line at index.
+     * @param index index in json array defining lines.
+     * @return water height of line at given index.
+     */
+    protected double getLine(int index) {
+        try {
+            JSONArray lines = new JSONArray((String) getLinesData(null));
+            JSONArray array = lines.getJSONArray(index);
+
+            return array.getDouble(0);
+        }
+        catch(JSONException e){
+            logger.error("Could not decode json for line.");
+            return 0d;
+        }
+    }
+
+
+    /**
+     * Get the water line "surface".
+     */
+    @Override
+    public Lines.LineData getWaterLines(int index, FastCrossSectionLine csl) {
+        List<Point2D> points = csl.getPoints();
+        return Lines.createWaterLines(points, getLine(index));
+    }
+
+    /**
      * Determines Facets initial disposition regarding activity (think of
      * selection in Client ThemeList GUI). This will be checked one time
      * when the facet enters a collections describe document.
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionWaterLineFacet.java	Wed Jun 27 15:11:23 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionWaterLineFacet.java	Wed Jun 27 15:22:01 2012 +0000
@@ -32,6 +32,13 @@
     }
 
 
+    /** Trivial constructor, set (maybe localized) description. */
+    public CrossSectionWaterLineFacet(int idx, String name, String description) {
+        super(idx, name, description);
+    }
+
+
+
     /**
      * Gets waterline (crossed with cross section) of waterlevel.
      */
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ManualPointsSingleState.java	Wed Jun 27 15:11:23 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ManualPointsSingleState.java	Wed Jun 27 15:22:01 2012 +0000
@@ -4,6 +4,9 @@
 
 import org.apache.log4j.Logger;
 
+import org.json.JSONArray;
+import org.json.JSONException;
+
 import de.intevation.artifacts.CallMeta;
 import de.intevation.artifacts.CallContext;
 
@@ -12,12 +15,12 @@
 import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.artifacts.ManualPointsArtifact;
 
+import de.intevation.flys.artifacts.model.CrossSectionWaterLineFacet;
+import de.intevation.flys.artifacts.model.FacetTypes;
 import de.intevation.flys.artifacts.model.ManualPointsFacet;
-import de.intevation.flys.artifacts.model.FacetTypes;
 
 import de.intevation.flys.artifacts.resources.Resources;
 
-
 /**
  * The only state for an ManualPointArtifact.
  */
@@ -26,18 +29,27 @@
 implements   FacetTypes
 {
     /** Developer-centric description of facet. */
-    public static final String I18N_DESCRIPTION = "facet.longitudinal_section.manualpoint";
+    public static final String I18N_DESCRIPTION
+        = "facet.longitudinal_section.manualpoint";
+
+    /** Part of data key. */
+    protected static final String DOT_DATA
+        = ".data";
+
+    /** Part of data key. */
+    protected static final String DOT_LINES
+        = ".lines";
 
     /** The logger that is used in this state. */
-    private static final Logger logger = Logger.getLogger(ManualPointsSingleState.class);
+    private static final Logger logger =
+        Logger.getLogger(ManualPointsSingleState.class);
 
 
     /**
-     * Add an ManualPointsFacet to list of Facets.
+     * Add ManualPointsFacets to list of Facets.
      *
      * @param artifact Ignored.
      * @param hash Ignored.
-     * @param context Ignored.
      * @param meta CallMeta to be used for internationalization.
      * @param facets List to add ManualPointsFacet to.
      *
@@ -54,8 +66,11 @@
 
         // Add Facet per Diagram type if data given.
         for (ChartType ct: ChartType.values()) {
-            String pointData = points.getDataAsString(ct + "." + MANUALPOINTS + ".data");
-            if (pointData != null && !pointData.equals("") && !pointData.equals("[]")) {
+            // Handle points.
+            String pointData = points.getDataAsString(ct + "." + MANUALPOINTS +
+                DOT_DATA);
+            if (pointData != null && !pointData.equals("")
+                && !pointData.equals("[]")) {
                 String fName = ct + "." + MANUALPOINTS;
                 ManualPointsFacet facet = new ManualPointsFacet(
                     0,
@@ -67,12 +82,43 @@
             else {
                 //logger.debug("No points for " + ct);
             }
+
+            // Handle lines.
+            String linesData = points.getDataAsString(ct + "." + MANUALPOINTS +
+                DOT_LINES);
+            if (linesData != null && !linesData.equals("")
+                && !linesData.equals("[]")) {
+                try {
+                    JSONArray lines = new JSONArray((String) linesData);
+                    for (int i = 0, P = lines.length(); i < P; i++) {
+                        JSONArray array = lines.getJSONArray(i);
+                        double y    = array.getDouble(0);
+                        String name = array.getString(1);
+                        String fName = ct + "." + MANUALLINE;
+                        logger.debug("have facet: " + y + " / " + name + " -> " + fName);
+                        CrossSectionWaterLineFacet facet = new CrossSectionWaterLineFacet(
+                            i,
+                            fName,
+                            name);
+
+                        facets.add(facet);
+                    }
+                }
+                catch(JSONException e){
+                    logger.error("Could not decode json.");
+                }
+
+            }
+            else {
+                //logger.debug("No points for " + ct);
+            }
         }
 
         return null;
     }
 
 
+    /** Call compute. */
     @Override
     public Object computeInit(
         FLYSArtifact artifact,
@@ -85,6 +131,7 @@
     }
 
 
+    /** Call compute. */
     @Override
     public Object computeFeed(
         FLYSArtifact artifact,
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java	Wed Jun 27 15:11:23 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java	Wed Jun 27 15:22:01 2012 +0000
@@ -189,6 +189,13 @@
                 attr,
                 visible);
         }
+        else if (FacetTypes.IS.MANUALLINE(name)) {
+            doCrossSectionWaterLineOut(
+                artifactFacet.getData(context),
+                artifactFacet.getFacetDescription(),
+                attr,
+                visible);
+        }
         else if (FacetTypes.IS.MANUALPOINTS(name)) {
             doPoints(artifactFacet.getData(context),
                 artifactFacet,

http://dive4elements.wald.intevation.org