Mercurial > dive4elements > river
view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationInfrastructureFacet.java @ 9268:ae9dee74e43e
Fixed: current station of duration chart was not changed
author | gernotbelger |
---|---|
date | Wed, 18 Jul 2018 18:53:15 +0200 |
parents | 465347d12990 |
children | 83ebeb620b5a |
line wrap: on
line source
/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde * Software engineering by * Björnsen Beratende Ingenieure GmbH * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt * * This file is Free Software under the GNU AGPL (>=v3) * and comes with ABSOLUTELY NO WARRANTY! Check out the * documentation coming with Dive4Elements River for details. */ package org.dive4elements.river.artifacts.sinfo.flood_duration; import static org.dive4elements.river.exports.injector.InjectorConstants.CURRENT_KM; import java.util.List; import org.apache.log4j.Logger; import org.dive4elements.artifactdatabase.state.DefaultFacet; import org.dive4elements.artifacts.Artifact; import org.dive4elements.artifacts.CallContext; import org.dive4elements.river.artifacts.D4EArtifact; import org.dive4elements.river.artifacts.model.CalculationResult; import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; import org.dive4elements.river.jfree.RiverAnnotation; import org.dive4elements.river.jfree.StickyAxisAnnotation; /** * Facet to show W and Q annotation lines of an infrastructure height. */ public class FloodDurationInfrastructureFacet extends DefaultFacet { /** Own log. */ private static Logger log = Logger.getLogger(FloodDurationInfrastructureFacet.class); /** Trivial Constructor. */ public FloodDurationInfrastructureFacet(final String name, final String description) { this.description = description; this.name = name; this.index = 0; } /** * Returns the data this facet requires. * * @param artifact the owner artifact. * @param context the CallContext (can be used to find out if in * navigable fixation-setting, or durationcurve). * * @return the data. */ @Override public Object getData(final Artifact artifact, final CallContext context) { log.debug("Get data for flood duration curve infrastructure"); final D4EArtifact flys = (D4EArtifact) artifact; final CalculationResult res = (CalculationResult) flys.compute(context, ComputeType.ADVANCE, false); final FloodDurationCalculationResults data = (FloodDurationCalculationResults) res.getData(); // final List<StickyAxisAnnotation> annotations = new ArrayList<>(); // annotations.add(data.getInfrastructureWAnnotation()); // annotations.add(data.getInfrastructureQAnnotation()); final double currentKm = getCurrentKm(context); final List<StickyAxisAnnotation> annotations = new FloodDurationCalculation(context).calcInfrastructureAnnotations(currentKm, data.getResults().get(this.index)); if (annotations != null) { return new RiverAnnotation(this.description, annotations); } else return null; } /** * Returns the current km from the context. * If the context is null or doesn't contain a currentKm * then a double value of -1 will be returned. * * @param context * The CallContext instance * @return the current km as double */ // FIXME: copied from org.dive4elements.river.artifacts.model.fixings.FixingsFacet private double getCurrentKm(final CallContext context) { if (context == null) return Double.NaN; final Double dkm = (Double) context.getContextValue(CURRENT_KM); if (dkm == null) return Double.NaN; return dkm.doubleValue(); } /** * Create a deep copy of this Facet. * @return a deep copy. */ @Override public FloodDurationInfrastructureFacet deepCopy() { final FloodDurationInfrastructureFacet copy = new FloodDurationInfrastructureFacet(this.name, this.description); copy.set(this); return copy; } }