# HG changeset patch # User Ingo Weinzierl # Date 1304355484 0 # Node ID dcc3cd962c0e67372a8120f3237fa9e7602600bd # Parent e07d1c3f76678e2dde0dbae9bb32fb2210d1bfe4 Enhanced the transition model to reach a state that creates duration curves. flys-artifacts/trunk@1799 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r e07d1c3f7667 -r dcc3cd962c0e flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Mon May 02 16:50:58 2011 +0000 +++ b/flys-artifacts/ChangeLog Mon May 02 16:58:04 2011 +0000 @@ -1,3 +1,19 @@ +2011-05-02 Ingo Weinzierl + + * doc/conf/artifacts/winfo.xml: Enhanced the transition model to reach the + final state for creating duration curves. + + * src/main/java/de/intevation/flys/artifacts/states/LocationSelect.java: + New. This state should be reached to just insert an array of locations. + + * src/main/java/de/intevation/flys/artifacts/states/DurationCurveState.java: + New. This state is reached if the duration curve calculation is + selected. + + * src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java: Adjusted + getDistance() so that it takes care on inserted locations - not just + inserted ranges. + 2011-05-02 Sascha L. Teichmann * src/main/java/de/intevation/flys/artifacts/cache/CacheFactory.java: diff -r e07d1c3f7667 -r dcc3cd962c0e flys-artifacts/doc/conf/artifacts/winfo.xml --- a/flys-artifacts/doc/conf/artifacts/winfo.xml Mon May 02 16:50:58 2011 +0000 +++ b/flys-artifacts/doc/conf/artifacts/winfo.xml Mon May 02 16:58:04 2011 +0000 @@ -15,11 +15,32 @@ - + + + + + + + + + + + + + + + + + + + + + + @@ -41,6 +62,11 @@ + + + + + @@ -50,6 +76,17 @@ + + + + + + + + + + + diff -r e07d1c3f7667 -r dcc3cd962c0e flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Mon May 02 16:50:58 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Mon May 02 16:58:04 2011 +0000 @@ -470,14 +470,72 @@ * @return the selected distance or points. */ public double[] getDistance() { - StateData dFrom = getData("ld_from"); - StateData dTo = getData("ld_to"); + StateData dFrom = getData("ld_from"); + StateData dTo = getData("ld_to"); + StateData dLocations = getData("ld_locations"); + if (dFrom != null && dTo != null) { + return getDistanceByRange(dFrom, dTo); + } + else if (dLocations != null) { + double[] locations = getLocations(); + return new double[] { locations[0], locations[locations.length-1] }; + } + + logger.warn("No data found for distance determination!"); + + return null; + } + + + /** + * Returns the selected locations based on a given array of locations. + * + * @param locations The StateData that contains the locations. + * + * @return the selected locations. + */ + public double[] getLocations() { + StateData dLocations = getData("ld_locations"); + String locationStr = dLocations != null + ? (String) dLocations.getValue() + : ""; + + if (locationStr == null || locationStr.length() == 0) { + logger.warn("No valid location string found!"); + return null; + } + + String[] tmp = locationStr.split(" "); + TDoubleArrayList locations = new TDoubleArrayList(); + + for (String l: tmp) { + try { + locations.add(Double.parseDouble(l)); + } + catch (NumberFormatException nfe) { + logger.warn(nfe, nfe); + } + } + + locations.sort(); + + return locations.toNativeArray(); + } + + + /** + * Returns the selected distance based on a given range (from, to). + * + * @param dFrom The StateData that contains the lower value. + * @param dTo The StateData that contains the upper value. + * + * @return the selected distance. + */ + protected double[] getDistanceByRange(StateData dFrom, StateData dTo) { double from = Double.parseDouble((String) dFrom.getValue()); double to = Double.parseDouble((String) dTo.getValue()); - // TODO take point selection into account - return new double[] { from, to }; } diff -r e07d1c3f7667 -r dcc3cd962c0e flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DurationCurveState.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DurationCurveState.java Mon May 02 16:58:04 2011 +0000 @@ -0,0 +1,35 @@ +package de.intevation.flys.artifacts.states; + +import org.apache.log4j.Logger; + +import org.w3c.dom.Element; + +import de.intevation.artifacts.Artifact; +import de.intevation.artifacts.CallContext; + +import de.intevation.artifacts.common.utils.XMLUtils; + + +/** + * The final state that will be reached after the duration curve calculation + * mode has been chosen. + * + * @author Ingo Weinzierl + */ +public class DurationCurveState extends DefaultState { + + /** The logger that is used in this state.*/ + private static Logger logger = Logger.getLogger(DurationCurveState.class); + + + protected Element[] createItems( + XMLUtils.ElementCreator cr, + Artifact artifact, + String name, + CallContext context) + { + logger.debug("DurationCurveState.createItems"); + return null; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : diff -r e07d1c3f7667 -r dcc3cd962c0e flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/LocationSelect.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/LocationSelect.java Mon May 02 16:58:04 2011 +0000 @@ -0,0 +1,93 @@ +package de.intevation.flys.artifacts.states; + +import java.util.Map; + +import gnu.trove.TDoubleArrayList; + +import org.apache.log4j.Logger; + +import de.intevation.artifacts.Artifact; +import de.intevation.artifacts.CallContext; + +import de.intevation.artifactdatabase.data.StateData; + + +/** + * This state is used to realize the input of multiple locations as string. The + * string should be a whitespace separated list of double values where each + * double value represents a location. + * + * @author Ingo Weinzierl + */ +public class LocationSelect extends LocationDistanceSelect { + + /** The logger used in this class.*/ + private static Logger logger = Logger.getLogger(LocationSelect.class); + + + /** The name of the StateData object that stores the location string.*/ + public static final String FIELD_LOCATIONS = "ld_locations"; + + + public LocationSelect() { + } + + + @Override + protected String getUIProvider() { + return "location_panel"; + } + + + @Override + public boolean validate(Artifact artifact, CallContext context) + throws IllegalArgumentException + { + logger.debug("LocationSelect.validate"); + + Map data = getData(); + + String locationStr = (String) data.get(FIELD_LOCATIONS).getValue(); + + if (locationStr == null || locationStr.length() == 0) { + logger.error("No locations given."); + throw new IllegalArgumentException("error_empty_state"); + } + + double[] minmax = getMinMaxDistance(artifact); + double[] mm = extractLocations(locationStr); + + logger.debug("Inserted min location: " + mm[0]); + logger.debug("Inserted max location: " + mm[mm.length-1]); + + return validateBounds(minmax[0], minmax[1], mm[0], mm[1], 0d); + } + + + /** + * This method takes a string that consist of whitespace separated double + * values and returns the double values as array. + * + * @param locationStr The locations inserted in this state. + * + * @return the locations as array. + */ + protected double[] extractLocations(String locationStr) { + String[] tmp = locationStr.split(" "); + TDoubleArrayList locations = new TDoubleArrayList(); + + for (String l: tmp) { + try { + locations.add(Double.parseDouble(l)); + } + catch (NumberFormatException nfe) { + logger.warn(nfe, nfe); + } + } + + locations.sort(); + + return locations.toNativeArray(); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :