aheinecke@7685: /* Copyright (C) 2013 by Bundesanstalt für Gewässerkunde aheinecke@7685: * Software engineering by Intevation GmbH aheinecke@7685: * aheinecke@7685: * This file is Free Software under the GNU AGPL (>=v3) aheinecke@7685: * and comes with ABSOLUTELY NO WARRANTY! Check out the aheinecke@7685: * documentation coming with Dive4Elements River for details. aheinecke@7685: */ aheinecke@7685: aheinecke@7685: package org.dive4elements.river.exports.process; aheinecke@7685: aheinecke@7685: import java.util.Set; aheinecke@7685: aheinecke@7685: import org.apache.log4j.Logger; aheinecke@7685: import org.jfree.data.xy.XYSeries; aheinecke@7685: aheinecke@7685: import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; aheinecke@7685: import org.dive4elements.artifacts.CallContext; aheinecke@7685: import org.dive4elements.river.artifacts.model.FacetTypes; aheinecke@7685: import org.dive4elements.river.exports.DiagramGenerator; aheinecke@7685: import org.dive4elements.river.exports.StyledSeriesBuilder; aheinecke@7685: import org.dive4elements.river.jfree.StyledXYSeries; aheinecke@7685: import org.dive4elements.river.themes.ThemeDocument; aheinecke@7685: aheinecke@7685: import org.dive4elements.river.artifacts.model.minfo.SedimentLoad; aheinecke@7685: import org.dive4elements.river.artifacts.model.minfo.SedimentLoadFraction; aheinecke@7685: aheinecke@7685: // Base class for SedimantLoad$UNITProcessors aheinecke@7685: public class SedimentLoadProcessor extends DefaultProcessor aheinecke@7685: { aheinecke@7685: private final static Logger logger = aheinecke@7685: Logger.getLogger(SedimentLoadProcessor.class); aheinecke@7685: aheinecke@7685: @Override aheinecke@7685: public void doOut( aheinecke@7685: DiagramGenerator generator, aheinecke@7685: ArtifactAndFacet bundle, aheinecke@7685: ThemeDocument theme, aheinecke@7685: boolean visible) { aheinecke@7685: logger.debug("doOut " + bundle.getFacetName()); aheinecke@7685: CallContext context = generator.getCallContext(); aheinecke@7685: XYSeries series = new StyledXYSeries(bundle.getFacetDescription(), aheinecke@7685: false, // Handle NaN aheinecke@7685: theme); aheinecke@7685: Object data = bundle.getData(context); aheinecke@7685: String facetName = bundle.getFacetName(); aheinecke@7685: double [][] points; aheinecke@7685: aheinecke@7685: if (FacetTypes.IS.SEDIMENT_LOAD_M3A(facetName) || aheinecke@7685: FacetTypes.IS.SEDIMENT_LOAD_TA(facetName)) { aheinecke@7685: points = (double[][]) data; aheinecke@7685: } else if (FacetTypes.IS.SEDIMENT_LOAD_UNKNOWN(facetName)) { aheinecke@7685: SedimentLoad load = (SedimentLoad) data; aheinecke@7685: Set kms = load.getKms(); aheinecke@7685: points = new double[2][kms.size()]; aheinecke@7685: int counter = 0; aheinecke@7685: for (Double km: kms) { aheinecke@7685: SedimentLoadFraction fraction = load.getFraction(km); aheinecke@7685: points[0][counter] = km; aheinecke@7685: points[1][counter] = fraction.getUnknown(); aheinecke@7685: counter++; aheinecke@7685: } aheinecke@7685: } else { aheinecke@7685: logger.error("Unknown facet name: " + facetName); aheinecke@7685: return; aheinecke@7685: } aheinecke@7685: aheinecke@7685: StyledSeriesBuilder.addPoints(series, points, false); // Keep NaN aheinecke@7685: aheinecke@7685: generator.addAxisSeries(series, axisName, visible); aheinecke@7685: } aheinecke@7685: } aheinecke@7685: