mschaefer@9259: /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde mschaefer@9259: * Software engineering by mschaefer@9259: * Björnsen Beratende Ingenieure GmbH mschaefer@9259: * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt mschaefer@9259: * mschaefer@9259: * This file is Free Software under the GNU AGPL (>=v3) mschaefer@9259: * and comes with ABSOLUTELY NO WARRANTY! Check out the mschaefer@9259: * documentation coming with Dive4Elements River for details. mschaefer@9259: */ mschaefer@9259: mschaefer@9259: package org.dive4elements.river.artifacts.sinfo.flood_duration; mschaefer@9259: mschaefer@9259: import java.util.List; mschaefer@9259: mschaefer@9259: import org.apache.log4j.Logger; mschaefer@9259: import org.dive4elements.artifactdatabase.state.DefaultFacet; mschaefer@9259: import org.dive4elements.artifacts.Artifact; mschaefer@9259: import org.dive4elements.artifacts.CallContext; mschaefer@9259: import org.dive4elements.river.artifacts.D4EArtifact; mschaefer@9259: import org.dive4elements.river.artifacts.model.CalculationResult; mschaefer@9259: import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; mschaefer@9269: import org.dive4elements.river.exports.fixings.FixChartGenerator; mschaefer@9259: import org.dive4elements.river.jfree.RiverAnnotation; mschaefer@9259: import org.dive4elements.river.jfree.StickyAxisAnnotation; mschaefer@9376: import org.dive4elements.river.model.Attribute.AttributeKey; mschaefer@9259: mschaefer@9259: mschaefer@9259: /** mschaefer@9259: * Facet to show W and Q annotation lines of an infrastructure height. mschaefer@9259: */ mschaefer@9259: public class FloodDurationInfrastructureFacet extends DefaultFacet { mschaefer@9259: mschaefer@9259: /** Own log. */ mschaefer@9259: private static Logger log = Logger.getLogger(FloodDurationInfrastructureFacet.class); mschaefer@9259: mschaefer@9376: private final AttributeKey riverBankKey; mschaefer@9376: mschaefer@9376: private final boolean isW; mschaefer@9376: mschaefer@9376: public FloodDurationInfrastructureFacet(final String name, final String description, final AttributeKey riverside, final boolean isW) { mschaefer@9259: this.description = description; mschaefer@9259: this.name = name; mschaefer@9259: this.index = 0; mschaefer@9376: this.riverBankKey = riverside; mschaefer@9376: this.isW = isW; mschaefer@9259: } mschaefer@9259: mschaefer@9259: mschaefer@9259: /** mschaefer@9259: * Returns the data this facet requires. mschaefer@9259: */ mschaefer@9259: @Override mschaefer@9259: public Object getData(final Artifact artifact, final CallContext context) { mschaefer@9259: mschaefer@9259: log.debug("Get data for flood duration curve infrastructure"); mschaefer@9259: mschaefer@9259: final D4EArtifact flys = (D4EArtifact) artifact; mschaefer@9259: mschaefer@9259: final CalculationResult res = (CalculationResult) flys.compute(context, ComputeType.ADVANCE, false); mschaefer@9259: mschaefer@9259: final FloodDurationCalculationResults data = (FloodDurationCalculationResults) res.getData(); mschaefer@9259: mschaefer@9269: final double currentKm = FixChartGenerator.getCurrentKm(context); mschaefer@9266: mschaefer@9266: final List annotations = new FloodDurationCalculation(context).calcInfrastructureAnnotations(currentKm, mschaefer@9376: this.riverBankKey, this.isW, data.getResults().get(this.index)); mschaefer@9259: mschaefer@9269: return new RiverAnnotation(this.description, annotations); mschaefer@9266: } mschaefer@9266: mschaefer@9259: mschaefer@9259: /** mschaefer@9259: * Create a deep copy of this Facet. mschaefer@9259: * @return a deep copy. mschaefer@9259: */ mschaefer@9259: @Override mschaefer@9259: public FloodDurationInfrastructureFacet deepCopy() { mschaefer@9376: final FloodDurationInfrastructureFacet copy = new FloodDurationInfrastructureFacet(this.name, this.description, this.riverBankKey, this.isW); mschaefer@9259: copy.set(this); mschaefer@9259: return copy; mschaefer@9259: } mschaefer@9259: } mschaefer@9259: