8854
|
1 /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
|
2 * Software engineering by |
|
3 * Björnsen Beratende Ingenieure GmbH |
|
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt |
|
5 * |
|
6 * This file is Free Software under the GNU AGPL (>=v3) |
|
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
|
8 * documentation coming with Dive4Elements River for details. |
|
9 */ |
|
10 |
|
11 package org.dive4elements.river.artifacts.sinfo.flowdepth; |
|
12 |
|
13 import java.util.Map; |
|
14 |
|
15 import org.apache.log4j.Logger; |
|
16 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; |
|
17 import org.dive4elements.artifacts.CallContext; |
|
18 import org.dive4elements.river.exports.DiagramGenerator; |
|
19 import org.dive4elements.river.exports.StyledSeriesBuilder; |
|
20 import org.dive4elements.river.exports.process.DefaultProcessor; |
|
21 import org.dive4elements.river.jfree.StyledXYSeries; |
|
22 import org.dive4elements.river.themes.ThemeDocument; |
|
23 |
|
24 public final class FlowDepthProcessor extends DefaultProcessor { |
|
25 |
|
26 /* Theme name, usually defined in 'FacetTypes', but that is soooo bad dependencies... */ |
|
27 static String FACET_FLOW_DEPTH_FILTERED = "sinfo_flow_depth.filtered"; |
|
28 |
|
29 private final static Logger log = Logger.getLogger(FlowDepthProcessor.class); |
|
30 |
|
31 private static final String I18N_AXIS_LABEL = "sinfo.chart.flow_depth.section.yaxis.label"; |
|
32 private String yAxisLabel; |
|
33 |
|
34 @Override |
|
35 public void doOut( |
|
36 final DiagramGenerator generator, |
|
37 final ArtifactAndFacet bundle, |
|
38 final ThemeDocument theme, |
|
39 final boolean visible) { |
|
40 |
|
41 final CallContext context = generator.getCallContext(); |
|
42 final Map<String, String> metaData = bundle.getFacet().getMetaData(); |
|
43 |
|
44 final StyledXYSeries series = new StyledXYSeries(bundle.getFacetDescription(), theme); |
|
45 series.putMetaData(metaData, bundle.getArtifact(), context); |
|
46 |
|
47 yAxisLabel = metaData.get("Y"); |
|
48 |
|
49 final String facetName = bundle.getFacetName(); |
|
50 final FlowDepthCalculationResult data = (FlowDepthCalculationResult) bundle.getData(context); |
|
51 if (data == null) { |
|
52 // Check has been here before so we keep it for security reasons |
|
53 // this should never happen though. |
|
54 log.error("Data is null for facet: " + facetName); |
|
55 return; |
|
56 } |
|
57 |
|
58 final double [][] points = generatePoints(data); |
|
59 |
|
60 StyledSeriesBuilder.addPoints(series, points, true); |
|
61 generator.addAxisSeries(series, axisName, visible); |
|
62 } |
|
63 |
|
64 private static double[][] generatePoints(final FlowDepthCalculationResult data) { |
|
65 |
|
66 // FIXME |
|
67 return data.getFlowDepthPoints(); |
|
68 |
|
69 // if (facetName.equals(FacetTypes.FLOW_VELOCITY_TOTALCHANNEL) || |
|
70 // facetName.equals(FacetTypes.FLOW_VELOCITY_TOTALCHANNEL_FILTERED)) { |
|
71 // FlowVelocityData fData = (FlowVelocityData) data; |
|
72 // points = fData.getTotalChannelPoints(); |
|
73 // } else if (facetName.equals(FacetTypes.FLOW_VELOCITY_MAINCHANNEL) || |
|
74 // facetName.equals(FacetTypes.FLOW_VELOCITY_MAINCHANNEL_FILTERED)) { |
|
75 // FlowVelocityData fData = (FlowVelocityData) data; |
|
76 // points = fData.getMainChannelPoints(); // I hate facets! |
|
77 // } else if (facetName.equals(FacetTypes.FLOW_VELOCITY_MEASUREMENT)) { |
|
78 // FastFlowVelocityMeasurementValue fData = |
|
79 // (FastFlowVelocityMeasurementValue) data; |
|
80 // points = new double[][] {{fData.getStation()},{fData.getV()}}; |
|
81 // } else { |
|
82 // log.error("Unknown facet name: " + facetName); |
|
83 // return; |
|
84 // } |
|
85 } |
|
86 |
|
87 @Override |
|
88 public boolean canHandle(String facettype) { |
|
89 return FACET_FLOW_DEPTH_FILTERED.equals(facettype); |
|
90 } |
|
91 |
|
92 @Override |
|
93 public String getAxisLabel(DiagramGenerator generator) { |
|
94 if (yAxisLabel != null && !yAxisLabel.isEmpty()) { |
|
95 // REMARK/UNINTENDED: yAxisLabel may also be a resolved message (side-effect of StyledXYSeries#putMetadata), |
|
96 // and cannot be resolved, so we need to give the resolved value as default |
|
97 // In other implementations (i.e. FlowVelocityProcessor), an explicit (German) default label is given here, probably |
|
98 // the English version will also show German (CHECK) |
|
99 return generator.msg(yAxisLabel, yAxisLabel); |
|
100 } |
|
101 return generator.msg( |
|
102 I18N_AXIS_LABEL, |
|
103 "MISSING"); |
|
104 } |
|
105 } |