Mercurial > dive4elements > river
changeset 2758:b05faaa9099b
Create points for ref.curve in facet, handle these in generator.
flys-artifacts/trunk@4493 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Thu, 24 May 2012 04:41:57 +0000 |
parents | 6e89147f5ca3 |
children | 70465d9b8519 |
files | flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/RelativePointFacet.java flys-artifacts/src/main/java/de/intevation/flys/exports/ReferenceCurveGenerator.java |
diffstat | 2 files changed, 93 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/RelativePointFacet.java Thu May 24 04:38:49 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/RelativePointFacet.java Thu May 24 04:41:57 2012 +0000 @@ -12,7 +12,8 @@ import de.intevation.flys.artifacts.StaticWKmsArtifact; import de.intevation.flys.artifacts.math.Linear; import de.intevation.flys.artifacts.model.FacetTypes; -import de.intevation.flys.artifacts.model.RelativePointFacet; +import de.intevation.flys.artifacts.model.DurationCurveFacet; +import de.intevation.flys.artifacts.model.ReferenceCurveFacet; import de.intevation.flys.artifacts.model.WQDay; /** @@ -37,22 +38,13 @@ } - /** - * Returns the data this facet requires. - * - * @param artifact the owner artifact. - * @param context the CallContext (ignored). - * - * @return the data. - */ - @Override - public Object getData(Artifact artifact, CallContext context) { - // Find out whether we live in a duration curve context, there we would - // provide only a single point. + protected Point2D calculateDurationCurvePoint(CallContext context, + StaticWKmsArtifact artifact) + { Object wqdays = null; double km = 0d; List<DataProvider> providers = context. - getDataProvider("durationcurve"); + getDataProvider(DurationCurveFacet.BB_DURATIONCURVE); if (providers.size() < 1) { logger.warn("Could not find durationcurve data provider."); } @@ -76,12 +68,9 @@ km = Double.valueOf(dckm); } - StaticWKmsArtifact staticData = - (StaticWKmsArtifact) artifact; - if (wqdays != null) { // Which W at this km? - double w = staticData.getWAtKmLin(staticData.getWKms(0), km); + double w = artifact.getWAtKmLin(artifact.getWKms(0), km); if (w == -1) { logger.warn("w is -1, already bad sign!"); } @@ -112,7 +101,67 @@ return new Point2D.Double((double) day, w); } logger.warn("not wqkms / w / day found"); - + // TODO better signal failure. + return new Point2D.Double(0d, 0d); + //return null; + } + + + /** + * Calculate a reference curve point, that is, a point made of + * the Ws from start and end km param of the reference curve. + */ + public Point2D calculateReferenceCurvePoint(CallContext context, + StaticWKmsArtifact artifact) { + List<DataProvider> providers = context. + getDataProvider(ReferenceCurveFacet.BB_REFERENCECURVE_STARTKM); + if (providers.size() < 1) { + logger.warn("Could not find reference curve startkm data provider."); + } + + Double start = (Double) providers.get(0). + provideData(ReferenceCurveFacet.BB_REFERENCECURVE_STARTKM, null, context); + + providers = context. + getDataProvider(ReferenceCurveFacet.BB_REFERENCECURVE_ENDKMS); + if (providers.size() < 1) { + logger.warn("Could not find reference curve endkms data provider."); + } + double[] ends = (double[]) providers.get(0). + provideData(ReferenceCurveFacet.BB_REFERENCECURVE_ENDKMS, null, context); + + logger.debug("Got s " + start + " e " + ends); + double startW = artifact.getWAtKmLin(artifact.getWKms(0), start.doubleValue()); + // TODO handle multiple ends. + double endW = artifact.getWAtKmLin(artifact.getWKms(0), ends[0]); + logger.debug("Gotw s " + startW + " e " + endW); + return new Point2D.Double(startW, endW); + } + + + /** + * Returns the data this facet requires. + * + * @param artifact the owner artifact. + * @param context the CallContext (ignored). + * + * @return the data. + */ + @Override + public Object getData(Artifact artifact, CallContext context) { + StaticWKmsArtifact staticData = (StaticWKmsArtifact) artifact; + // Find out whether we live in a duration curve context, there we would + // provide only a single point. + + if (context.getDataProvider( + DurationCurveFacet.BB_DURATIONCURVE_KM).size() > 0) { + return calculateDurationCurvePoint(context, staticData); + } + else if (context.getDataProvider( + ReferenceCurveFacet.BB_REFERENCECURVE_STARTKM).size() > 0) { + return calculateReferenceCurvePoint(context, staticData); + } + // TODO better signal failure. return new Point2D.Double(0d, 0d); }
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ReferenceCurveGenerator.java Thu May 24 04:38:49 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ReferenceCurveGenerator.java Thu May 24 04:41:57 2012 +0000 @@ -1,5 +1,7 @@ package de.intevation.flys.exports; +import java.awt.geom.Point2D; + import org.w3c.dom.Document; import org.apache.log4j.Logger; @@ -167,6 +169,13 @@ visible, YAXIS.W.idx); } + else if (name.equals(RELATIVE_POINT)) { + doPointOut( + (Point2D) artifactFacet.getData(context), + artifactFacet, + theme, + visible); + } else { logger.warn("Unknown facet name: " + name); } @@ -206,6 +215,22 @@ addAxisSeries(series, YAXIS.W.idx, visible); } + // TODO resolve duplicate in DurationCurveGenerator + protected void doPointOut( + Point2D point, + ArtifactAndFacet aandf, + Document theme, + boolean visible + ){ + logger.debug("ReferenceCurveGenerator.doPointOut"); + + XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme); + + series.add(point.getX(), point.getY()); + + addAxisSeries(series, YAXIS.W.idx, visible); + } + protected void setAxisTickUnit(ValueAxis axis) { TickUnits units = new TickUnits(); units.add(new NumberTickUnit(1d, Formatter.getWaterlevelW(context)));