diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthProcessor.java @ 8854:7bbfb24e6eec

SINFO - first prototype of BArt Fließtiefen
author gernotbelger
date Thu, 18 Jan 2018 18:34:41 +0100
parents
children 7a8c12706834
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthProcessor.java	Thu Jan 18 18:34:41 2018 +0100
@@ -0,0 +1,105 @@
+/* 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.flowdepth;
+
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
+import org.dive4elements.artifacts.CallContext;
+import org.dive4elements.river.exports.DiagramGenerator;
+import org.dive4elements.river.exports.StyledSeriesBuilder;
+import org.dive4elements.river.exports.process.DefaultProcessor;
+import org.dive4elements.river.jfree.StyledXYSeries;
+import org.dive4elements.river.themes.ThemeDocument;
+
+public final class FlowDepthProcessor extends DefaultProcessor {
+
+	/* Theme name, usually defined in 'FacetTypes', but that is soooo bad dependencies... */
+    static String FACET_FLOW_DEPTH_FILTERED = "sinfo_flow_depth.filtered";
+
+    private final static Logger log = Logger.getLogger(FlowDepthProcessor.class);
+
+    private static final String I18N_AXIS_LABEL = "sinfo.chart.flow_depth.section.yaxis.label";
+    private String yAxisLabel;
+
+    @Override
+    public void doOut(
+            final DiagramGenerator generator,
+            final ArtifactAndFacet bundle,
+            final ThemeDocument    theme,
+            final boolean          visible) {
+
+        final CallContext context = generator.getCallContext();
+        final Map<String, String> metaData = bundle.getFacet().getMetaData();
+        
+        final StyledXYSeries series = new StyledXYSeries(bundle.getFacetDescription(), theme);
+        series.putMetaData(metaData, bundle.getArtifact(), context);
+
+        yAxisLabel = metaData.get("Y");
+
+        final String facetName = bundle.getFacetName();
+        final FlowDepthCalculationResult data = (FlowDepthCalculationResult) bundle.getData(context);
+        if (data == null) {
+            // Check has been here before so we keep it for security reasons
+            // this should never happen though.
+            log.error("Data is null for facet: " + facetName);
+            return;
+        }
+        
+        final double [][] points = generatePoints(data);
+
+        StyledSeriesBuilder.addPoints(series, points, true);
+        generator.addAxisSeries(series, axisName, visible);
+    }
+
+    private static double[][] generatePoints(final FlowDepthCalculationResult data) {
+
+    	// FIXME
+    	return data.getFlowDepthPoints();
+
+//        if (facetName.equals(FacetTypes.FLOW_VELOCITY_TOTALCHANNEL) ||
+//                facetName.equals(FacetTypes.FLOW_VELOCITY_TOTALCHANNEL_FILTERED)) {
+//            FlowVelocityData fData = (FlowVelocityData) data;
+//            points = fData.getTotalChannelPoints();
+//        } else if (facetName.equals(FacetTypes.FLOW_VELOCITY_MAINCHANNEL) ||
+//                facetName.equals(FacetTypes.FLOW_VELOCITY_MAINCHANNEL_FILTERED)) {
+//            FlowVelocityData fData = (FlowVelocityData) data;
+//            points = fData.getMainChannelPoints(); // I hate facets!
+//        } else if (facetName.equals(FacetTypes.FLOW_VELOCITY_MEASUREMENT)) {
+//            FastFlowVelocityMeasurementValue fData =
+//                (FastFlowVelocityMeasurementValue) data;
+//            points = new double[][] {{fData.getStation()},{fData.getV()}};
+//        } else {
+//            log.error("Unknown facet name: " + facetName);
+//            return;
+//        }
+	}
+
+	@Override
+    public boolean canHandle(String facettype) {
+        return FACET_FLOW_DEPTH_FILTERED.equals(facettype);
+    }
+
+    @Override
+    public String getAxisLabel(DiagramGenerator generator) {
+        if (yAxisLabel != null && !yAxisLabel.isEmpty()) {
+        	// REMARK/UNINTENDED: yAxisLabel may also be a resolved message (side-effect of StyledXYSeries#putMetadata),
+        	// and cannot be resolved, so we need to give the resolved value as default
+        	// In other implementations (i.e. FlowVelocityProcessor), an explicit (German) default label is given here, probably
+        	// the English version will also show German (CHECK)
+            return generator.msg(yAxisLabel, yAxisLabel);
+        }
+        return generator.msg(
+                I18N_AXIS_LABEL,
+                "MISSING");
+    }
+}
\ No newline at end of file

http://dive4elements.wald.intevation.org