aheinecke@7155: /* Copyright (C) 2013 by Bundesanstalt für Gewässerkunde aheinecke@7155: * Software engineering by Intevation GmbH aheinecke@7155: * aheinecke@7155: * This file is Free Software under the GNU AGPL (>=v3) aheinecke@7155: * and comes with ABSOLUTELY NO WARRANTY! Check out the aheinecke@7155: * documentation coming with Dive4Elements River for details. aheinecke@7155: */ aheinecke@7155: aheinecke@7155: package org.dive4elements.river.exports.process; aheinecke@7155: aheinecke@7155: import org.apache.log4j.Logger; aheinecke@7155: import org.jfree.data.xy.XYSeries; aheinecke@7155: aheinecke@7155: import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; aheinecke@7155: import org.dive4elements.artifacts.CallContext; aheinecke@7155: import org.dive4elements.river.artifacts.model.FacetTypes; aheinecke@7155: import org.dive4elements.river.exports.DiagramGenerator; aheinecke@7155: import org.dive4elements.river.exports.StyledSeriesBuilder; aheinecke@7155: import org.dive4elements.river.jfree.StyledXYSeries; aheinecke@7155: import org.dive4elements.river.themes.ThemeDocument; aheinecke@7164: aheinecke@7162: import org.dive4elements.river.model.FlowVelocityMeasurementValue.FastFlowVelocityMeasurementValue; aheinecke@7155: import org.dive4elements.river.artifacts.model.FlowVelocityData; aheinecke@7155: aheinecke@7155: public class FlowVelocityProcessor extends DefaultProcessor { aheinecke@7155: aheinecke@7155: private final static Logger logger = aheinecke@7155: Logger.getLogger(FlowVelocityProcessor.class); aheinecke@7155: aheinecke@7155: public static final String I18N_AXIS_LABEL = aheinecke@7155: "chart.flow_velocity.section.yaxis.label"; aheinecke@7155: public static final String I18N_AXIS_LABEL_DEFAULT = aheinecke@7155: "Geschwindigkeit v [m/s]"; aheinecke@7155: aheinecke@7155: @Override aheinecke@7155: public void doOut( aheinecke@7155: DiagramGenerator generator, aheinecke@7155: ArtifactAndFacet bundle, aheinecke@7155: ThemeDocument theme, aheinecke@7155: boolean visible) { aheinecke@7155: CallContext context = generator.getCallContext(); aheinecke@7155: XYSeries series = new StyledXYSeries(bundle.getFacetDescription(), aheinecke@7155: theme); aheinecke@7162: String facetName = bundle.getFacetName(); aheinecke@7162: Object data = bundle.getData(context); aheinecke@7155: if (data == null) { aheinecke@7162: // Check has been here before so we keep it for security reasons aheinecke@7162: // this should never happen though. aheinecke@7162: logger.error("Data is null for facet: " + facetName); aheinecke@7155: return; aheinecke@7155: } aheinecke@7155: double [][] points; aheinecke@7155: aheinecke@7155: if (facetName.equals(FacetTypes.FLOW_VELOCITY_TOTALCHANNEL) || aheinecke@7155: facetName.equals(FacetTypes.FLOW_VELOCITY_TOTALCHANNEL_FILTERED)) { aheinecke@7162: FlowVelocityData fData = (FlowVelocityData) data; aheinecke@7162: points = fData.getTotalChannelPoints(); aheinecke@7155: } else if (facetName.equals(FacetTypes.FLOW_VELOCITY_MAINCHANNEL) || aheinecke@7155: facetName.equals(FacetTypes.FLOW_VELOCITY_MAINCHANNEL_FILTERED)) { aheinecke@7162: FlowVelocityData fData = (FlowVelocityData) data; aheinecke@7162: points = fData.getMainChannelPoints(); // I hate facets! aheinecke@7162: } else if (facetName.equals(FacetTypes.FLOW_VELOCITY_MEASUREMENT)) { aheinecke@7162: FastFlowVelocityMeasurementValue fData = aheinecke@7162: (FastFlowVelocityMeasurementValue) data; aheinecke@7162: points = new double[][] {{fData.getStation()},{fData.getV()}}; aheinecke@7155: } else { aheinecke@7155: logger.error("Unknown facet name: " + facetName); aheinecke@7155: return; aheinecke@7155: } aheinecke@7155: StyledSeriesBuilder.addPoints(series, points, true); aheinecke@7155: aheinecke@7155: generator.addAxisSeries(series, axisName, visible); aheinecke@7155: } aheinecke@7155: aheinecke@7155: @Override aheinecke@7155: public boolean canHandle(String facettype) { aheinecke@7155: return facettype.equals(FacetTypes.FLOW_VELOCITY_MAINCHANNEL_FILTERED) || aheinecke@7155: facettype.equals(FacetTypes.FLOW_VELOCITY_MAINCHANNEL) || aheinecke@7155: facettype.equals(FacetTypes.FLOW_VELOCITY_TOTALCHANNEL_FILTERED) || aheinecke@7162: facettype.equals(FacetTypes.FLOW_VELOCITY_TOTALCHANNEL) || aheinecke@7162: facettype.equals(FacetTypes.FLOW_VELOCITY_MEASUREMENT); aheinecke@7155: } aheinecke@7155: aheinecke@7155: @Override aheinecke@7155: public String getAxisLabel(DiagramGenerator generator) { aheinecke@7155: return generator.msg( aheinecke@7155: I18N_AXIS_LABEL, aheinecke@7155: I18N_AXIS_LABEL_DEFAULT); aheinecke@7155: } aheinecke@7155: }