teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5863: * Software engineering by Intevation GmbH teichmann@5863: * teichmann@5994: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5994: * documentation coming with Dive4Elements River for details. teichmann@5863: */ teichmann@5863: teichmann@5831: package org.dive4elements.river.exports.minfo; raimund@3898: raimund@3898: import org.apache.log4j.Logger; raimund@3898: import org.jfree.data.xy.XYSeries; raimund@3898: import org.w3c.dom.Document; raimund@3898: teichmann@5831: import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; teichmann@5831: import org.dive4elements.artifactdatabase.state.Facet; teichmann@5867: import org.dive4elements.river.artifacts.D4EArtifact; teichmann@5831: import org.dive4elements.river.artifacts.access.FlowVelocityAccess; teichmann@5831: import org.dive4elements.river.artifacts.model.FacetTypes; teichmann@5831: import org.dive4elements.river.artifacts.model.WKms; teichmann@5831: import org.dive4elements.river.artifacts.model.minfo.BedDiffEpochResult; teichmann@5831: import org.dive4elements.river.exports.StyledSeriesBuilder; teichmann@5831: import org.dive4elements.river.exports.fixings.FixChartGenerator; teichmann@5831: import org.dive4elements.river.exports.process.KMIndexProcessor; teichmann@5831: import org.dive4elements.river.exports.process.Processor; teichmann@5831: import org.dive4elements.river.exports.process.WOutProcessor; teichmann@5831: import org.dive4elements.river.jfree.Bounds; teichmann@5831: import org.dive4elements.river.jfree.DoubleBounds; teichmann@5864: import org.dive4elements.river.jfree.RiverAnnotation; teichmann@5831: import org.dive4elements.river.jfree.StyledXYSeries; teichmann@5831: import org.dive4elements.river.utils.DataUtil; felix@6123: import org.dive4elements.river.utils.RiverUtils; raimund@3898: raimund@3898: raimund@3898: public class BedDifferenceEpochGenerator bjoern@4446: extends FixChartGenerator raimund@3898: implements FacetTypes raimund@3898: { raimund@3898: public enum YAXIS { rrenkert@5681: D(0), H(1), dW(2), W(3); raimund@3898: raimund@3898: protected int idx; raimund@3898: raimund@3898: private YAXIS(int c) { raimund@3898: idx = c; raimund@3898: } raimund@3898: } raimund@3898: raimund@3898: /** The logger that is used in this generator. */ raimund@3898: private static Logger logger = Logger.getLogger(BedQualityGenerator.class); raimund@3898: raimund@3898: public static final String I18N_CHART_TITLE = "chart.beddifference.epoch.title"; raimund@3898: public static final String I18N_XAXIS_LABEL = "chart.beddifference.xaxis.label"; raimund@3898: public static final String I18N_YAXIS_LABEL = "chart.beddifference.yaxis.label.diff"; raimund@3898: public static final String I18N_SECOND_YAXIS_LABEL = "chart.beddifference.yaxis.label.height"; raimund@3898: raimund@3898: public static final String I18N_CHART_TITLE_DEFAULT = "Sohlenhöhen Differenz"; raimund@3898: public static final String I18N_XAXIS_LABEL_DEFAULT = "Fluss-Km"; raimund@3898: public static final String I18N_YAXIS_LABEL_DEFAULT = "delta S [m]"; raimund@3898: public static final String I18N_SECOND_YAXIS_LABEL_DEFAULT = "Höhe [m]"; bjoern@4446: public static final String I18N_DW_YAXIS_LABEL_DEFAULT = bjoern@4446: "delta W [cm]"; bjoern@4446: public static final String I18N_DW_YAXIS_LABEL = bjoern@4446: "chart.fixings.longitudinalsection.yaxis.label"; bjoern@4446: rrenkert@5681: private static final String I18N_W_YAXIS_LABEL = rrenkert@5681: "chart.longitudinal.section.yaxis.label"; rrenkert@5681: private static final String I18N_W_YAXIS_LABEL_DEFAULT = "W [NN + m]"; rrenkert@5681: raimund@3898: raimund@3898: @Override raimund@3898: protected YAxisWalker getYAxisWalker() { raimund@3898: return new YAxisWalker() { raimund@3898: raimund@3898: @Override raimund@3898: public int length() { raimund@3898: return YAXIS.values().length; raimund@3898: } raimund@3898: raimund@3898: @Override raimund@3898: public String getId(int idx) { raimund@3898: YAXIS[] yaxes = YAXIS.values(); raimund@3898: return yaxes[idx].toString(); raimund@3898: } raimund@3898: }; raimund@3898: } raimund@3898: raimund@3898: @Override raimund@3898: public void doOut(ArtifactAndFacet bundle, Document attr, boolean visible) { raimund@3898: String name = bundle.getFacetName(); raimund@3898: raimund@3898: logger.debug("doOut: " + name); raimund@3898: raimund@3898: if (name == null) { raimund@3898: logger.error("No facet name for doOut(). No output generated!"); raimund@3898: return; raimund@3898: } raimund@3898: raimund@3898: Facet facet = bundle.getFacet(); raimund@3898: raimund@3898: if (facet == null) { raimund@3898: return; raimund@3898: } raimund@3898: rrenkert@4638: if (getXBounds(0) != null && getDomainAxisRange() != null) { rrenkert@4638: Bounds bounds = rrenkert@4638: calculateZoom(getXBounds(0), getDomainAxisRange()); rrenkert@4638: context.putContextValue("startkm", bounds.getLower()); rrenkert@4638: context.putContextValue("endkm", bounds.getUpper()); rrenkert@4638: } rrenkert@4638: else if (getXBounds(0) != null && getDomainAxisRange() == null) { rrenkert@4638: context.putContextValue("startkm", getXBounds(0).getLower()); rrenkert@4638: context.putContextValue("endkm", getXBounds(0).getUpper()); rrenkert@4638: } rrenkert@4638: else if (getXBounds(0) == null && getDomainAxisRange() == null) { teichmann@5867: D4EArtifact artifact = (D4EArtifact)bundle.getArtifact(); teichmann@6101: FlowVelocityAccess access = new FlowVelocityAccess(artifact); rrenkert@4638: context.putContextValue("startkm", access.getLowerKM()); rrenkert@4638: context.putContextValue("endkm", access.getUpperKM()); rrenkert@4638: } rrenkert@4638: else if (getXBounds(0) == null && getDomainAxisRange() != null){ teichmann@5867: D4EArtifact artifact = (D4EArtifact)bundle.getArtifact(); teichmann@6101: FlowVelocityAccess access = new FlowVelocityAccess(artifact); rrenkert@4638: Bounds b = new DoubleBounds(access.getLowerKM(), access.getUpperKM()); rrenkert@4638: Bounds bounds = rrenkert@4638: calculateZoom(b, getDomainAxisRange()); rrenkert@4638: context.putContextValue("startkm", bounds.getLower()); rrenkert@4638: context.putContextValue("endkm", bounds.getUpper()); rrenkert@4638: } bjoern@4446: Processor processor = new KMIndexProcessor(); rrenkert@5681: Processor woutp = new WOutProcessor(); raimund@3898: if (name.equals(BED_DIFFERENCE_EPOCH)) { raimund@3898: doBedDifferenceEpochOut( raimund@3898: (BedDiffEpochResult) bundle.getData(context), raimund@3898: bundle, attr, visible); raimund@3898: } raimund@3898: else if (name.equals(BED_DIFFERENCE_EPOCH_HEIGHT1)) { raimund@3898: doBedDifferenceHeightsOut((BedDiffEpochResult)bundle.getData(context), raimund@3898: bundle, attr, visible, 0); raimund@3898: } raimund@3898: else if (name.equals(BED_DIFFERENCE_EPOCH_HEIGHT2)) { raimund@3898: doBedDifferenceHeightsOut((BedDiffEpochResult)bundle.getData(context), raimund@3898: bundle, attr, visible, 1); raimund@3898: } rrenkert@4673: else if (name.equals(BED_DIFFERENCE_EPOCH_FILTERED)) { rrenkert@4673: doBedDifferenceEpochOut( rrenkert@4673: (BedDiffEpochResult) bundle.getData(context), rrenkert@4673: bundle, attr, visible); rrenkert@4673: } rrenkert@4673: else if (name.equals(BED_DIFFERENCE_EPOCH_HEIGHT1_FILTERED)) { rrenkert@4673: doBedDifferenceHeightsOut((BedDiffEpochResult)bundle.getData(context), rrenkert@4673: bundle, attr, visible, 0); rrenkert@4673: } rrenkert@4673: else if (name.equals(BED_DIFFERENCE_EPOCH_HEIGHT2_FILTERED)) { rrenkert@4673: doBedDifferenceHeightsOut((BedDiffEpochResult)bundle.getData(context), rrenkert@4673: bundle, attr, visible, 1); rrenkert@4673: } bjoern@4446: else if (processor.canHandle(name)) { bjoern@4446: processor.doOut(this, bundle, attr, visible, YAXIS.dW.idx); bjoern@4378: } rrenkert@5681: else if (woutp.canHandle(name)) { rrenkert@5681: woutp.doOut(this, bundle, attr, visible, YAXIS.W.idx); rrenkert@5681: } rrenkert@5681: else if (name.equals(W_DIFFERENCES)) { rrenkert@5681: doWDifferencesOut( rrenkert@5681: (WKms) bundle.getData(context), rrenkert@5681: bundle, rrenkert@5681: attr, rrenkert@5681: visible); rrenkert@5681: } raimund@3898: else if (name.equals(LONGITUDINAL_ANNOTATION)) { raimund@3898: doAnnotations( teichmann@5864: (RiverAnnotation) bundle.getData(context), raimund@3898: bundle, raimund@3898: attr, raimund@3898: visible); raimund@3898: } bjoern@4446: else { bjoern@4446: logger.warn("Unknown facet name " + name); bjoern@4446: } raimund@3898: } raimund@3898: raimund@3898: @Override raimund@3898: protected String getDefaultChartTitle() { raimund@3898: return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT); raimund@3898: } raimund@3898: raimund@3898: @Override raimund@3898: protected String getDefaultXAxisLabel() { felix@6166: return msg(I18N_XAXIS_LABEL, felix@6166: I18N_XAXIS_LABEL_DEFAULT, felix@6166: new Object[] {getRiverName()}); raimund@3898: } raimund@3898: raimund@3898: @Override raimund@3898: protected String getDefaultYAxisLabel(int pos) { raimund@3898: String label = "default"; raimund@3898: if (pos == YAXIS.D.idx) { raimund@3898: label = msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT); raimund@3898: } raimund@3898: else if (pos == YAXIS.H.idx) { felix@6123: D4EArtifact flys = (D4EArtifact) master; felix@6123: label = msg(I18N_SECOND_YAXIS_LABEL, felix@6123: I18N_SECOND_YAXIS_LABEL_DEFAULT, felix@6123: new Object[] felix@6123: { RiverUtils.getRiver(flys).getWstUnit().getName() }); raimund@3898: } bjoern@4378: else if (pos == YAXIS.dW.idx) { bjoern@4378: return msg(I18N_DW_YAXIS_LABEL, I18N_DW_YAXIS_LABEL_DEFAULT); bjoern@4378: } rrenkert@5681: else if (pos == YAXIS.W.idx) { rrenkert@5681: return msg(I18N_W_YAXIS_LABEL, I18N_W_YAXIS_LABEL_DEFAULT); rrenkert@5681: } raimund@3898: return label; raimund@3898: } raimund@3898: raimund@3898: protected void doBedDifferenceEpochOut(BedDiffEpochResult data, raimund@3898: ArtifactAndFacet aandf, Document theme, boolean visible) { raimund@3898: raimund@3898: XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme); raimund@3898: StyledSeriesBuilder.addPoints(series, data.getDifferencesData(), true); raimund@3898: raimund@3898: addAxisSeries(series, YAXIS.D.idx, visible); raimund@3898: } raimund@3898: raimund@3898: private void doBedDifferenceHeightsOut( raimund@3898: BedDiffEpochResult data, raimund@3898: ArtifactAndFacet bundle, raimund@3898: Document attr, raimund@3898: boolean visible, raimund@3898: int idx) { raimund@3898: logger.debug("doBedDifferenceHeightOut()"); raimund@3898: raimund@3898: XYSeries series = new StyledXYSeries(bundle.getFacetDescription(), attr); raimund@3898: if (idx == 0) { raimund@3898: StyledSeriesBuilder.addPoints(series, data.getHeights1Data(), true); raimund@3898: } raimund@3898: else { raimund@3898: StyledSeriesBuilder.addPoints(series, data.getHeights2Data(), true); raimund@3898: } raimund@3898: raimund@3898: addAxisSeries(series, YAXIS.H.idx, visible); raimund@3898: } rrenkert@5681: rrenkert@5681: protected void doWDifferencesOut( rrenkert@5681: WKms wkms, rrenkert@5681: ArtifactAndFacet aandf, rrenkert@5681: Document theme, rrenkert@5681: boolean visible rrenkert@5681: ) { rrenkert@5681: if (wkms == null) { rrenkert@5681: logger.warn("No data to add to WDifferencesChart."); rrenkert@5681: return; rrenkert@5681: } rrenkert@5681: rrenkert@5681: XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme); rrenkert@5681: StyledSeriesBuilder.addPoints(series, wkms); rrenkert@5681: rrenkert@5681: addAxisSeries(series, YAXIS.D.idx, visible); rrenkert@5681: if (DataUtil.guessWaterIncreasing(wkms.allWs())) { rrenkert@5681: setInverted(true); rrenkert@5681: } rrenkert@5681: } raimund@3898: } felix@6782: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :