comparison artifacts/src/main/java/org/dive4elements/river/exports/FlowVelocityGenerator.java @ 6794:23ab795f2f0e longitudinal-symmetry

Moved most of the functionality of FlowVelocityGenerator to LongitudinalSectionGenerator on the way to longitudinal-section symmetry. ToDos left.
author Tom Gottfried <tom@intevation.de>
date Fri, 09 Aug 2013 12:11:53 +0200
parents ef3b02034f6a
children 7089f338138a
comparison
equal deleted inserted replaced
6793:bdbe704dd433 6794:23ab795f2f0e
35 35
36 import org.dive4elements.river.utils.RiverUtils; 36 import org.dive4elements.river.utils.RiverUtils;
37 37
38 38
39 /** 39 /**
40 * An OutGenerator that generates flow velocity curves. 40 * An OutGenerator that generates flow velocity diagramms.
41 * 41 *
42 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 42 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
43 */ 43 */
44 public class FlowVelocityGenerator 44 public class FlowVelocityGenerator
45 extends LongitudinalSectionGenerator 45 extends LongitudinalSectionGenerator
46 implements FacetTypes 46 implements FacetTypes
47 { 47 {
48 public enum YAXIS { 48 public enum YAXIS {
49 V(0), 49 V(0), // flow velocity
50 T(1), 50 T(1), // tau (shear stress)
51 Q(2), 51 Q(2), // discharge
52 D(3); 52 O(3), // diameter
53 /* TODO Q and Density will come as 4th and 3rd axis. */ 53 W(4), // waterlevel
54 D(5); // waterlevel-difference
54 protected int idx; 55 protected int idx;
55 private YAXIS(int c) { 56 private YAXIS(int c) {
56 idx = c; 57 idx = c;
57 } 58 }
58 } 59 }
59 60
60 /** The logger that is used in this generator. */ 61 /** The logger that is used in this generator. */
61 private static Logger logger = Logger.getLogger(FlowVelocityGenerator.class); 62 private static Logger logger = Logger.getLogger(FlowVelocityGenerator.class);
62
63 /** Key to look up internationalized String for annotations label. */
64 public static final String I18N_ANNOTATIONS_LABEL =
65 "chart.flow_velocity.annotations.label";
66 63
67 /** 64 /**
68 * Key to look up internationalized String for LongitudinalSection diagrams 65 * Key to look up internationalized String for LongitudinalSection diagrams
69 * titles. 66 * titles.
70 */ 67 */
71 public static final String I18N_CHART_TITLE = 68 public static final String I18N_CHART_TITLE =
72 "chart.flow_velocity.section.title"; 69 "chart.flow_velocity.section.title";
73 70
74 /** 71 /** TODO:
75 * Key to look up internationalized String for LongitudinalSection diagrams 72 * are the following defined somewhere else too?
76 * subtitles. 73 * remove them here!
77 */ 74 */
78 public static final String I18N_CHART_SUBTITLE =
79 "chart.flow_velocity.section.subtitle";
80
81 /**
82 * Key to look up internationalized String for LongitudinalSection diagrams
83 * short subtitles.
84 */
85 public static final String I18N_CHART_SHORT_SUBTITLE =
86 "chart.flow_velocity.section.shortsubtitle";
87
88 public static final String I18N_YAXIS_LABEL =
89 "chart.flow_velocity.section.yaxis.label";
90
91 public static final String I18N_2YAXIS_LABEL =
92 "chart.flow_velocity.section.yaxis.second.label";
93
94 public static final String I18N_3YAXIS_LABEL =
95 "chart.flow_velocity.section.yaxis.third.label";
96 public static final String I18N_4YAXIS_LABEL = "chart.bedquality.yaxis.label.diameter";
97
98 public static final String I18N_CHART_TITLE_DEFAULT = "Geschwindigkeit- und Schubspannung";
99 public static final String I18N_YAXIS_LABEL_DEFAULT = "Geschwindigkeit v [m/s]";
100 public static final String I18N_2YAXIS_LABEL_DEFAULT = "Schubspannung Tau [N]";
101 public static final String I18N_3YAXIS_LABEL_DEFAULT = "Q [m³/s]";
102 public static final String I18N_4YAXIS_LABEL_DEFAULT = "Durchmesser [mm]";
103
104 @Override
105 protected YAxisWalker getYAxisWalker() {
106 return new YAxisWalker() {
107 @Override
108 public int length() {
109 return YAXIS.values().length;
110 }
111
112 @Override
113 public String getId(int idx) {
114 YAXIS[] yaxes = YAXIS.values();
115 return yaxes[idx].toString();
116 }
117 };
118 }
119
120
121 /**
122 * Returns the default title for this chart.
123 *
124 * @return the default title for this chart.
125 */
126 @Override
127 public String getDefaultChartTitle() {
128 Object[] args = new Object[] {
129 getRiverName()
130 };
131
132 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT, args);
133 }
134
135
136 /**
137 * Get internationalized label for the x axis.
138 */
139 @Override
140 protected String getDefaultXAxisLabel() {
141 D4EArtifact flys = (D4EArtifact) master;
142
143 return msg(
144 I18N_XAXIS_LABEL,
145 I18N_XAXIS_LABEL_DEFAULT,
146 new Object[] { RiverUtils.getRiver(flys).getName() });
147 }
148
149
150 @Override
151 protected String getDefaultYAxisLabel(int index) {
152 String label = "default";
153
154 if (index == YAXIS.V.idx) {
155 label = getVAxisLabel();
156 }
157 else if (index == YAXIS.T.idx) {
158 label = getTAxisLabel();
159 }
160 else if (index == YAXIS.Q.idx) {
161 label = getQAxisLabel();
162 }
163 else if (index == YAXIS.D.idx) {
164 label = getDAxisLabel();
165 }
166
167 return label;
168 }
169
170
171 /**
172 * Get internationalized label for the y axis.
173 */
174 protected String getVAxisLabel() {
175 return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT);
176 }
177
178
179 /**
180 * Get internationalized label for the y axis.
181 */
182 protected String getQAxisLabel() {
183 return msg(I18N_3YAXIS_LABEL, I18N_3YAXIS_LABEL_DEFAULT);
184 }
185
186 /**
187 * Get internationalized label for the y axis.
188 */
189 protected String getTAxisLabel() {
190 return msg(I18N_2YAXIS_LABEL, I18N_2YAXIS_LABEL_DEFAULT);
191 }
192
193 /**
194 * Get internationalized label for the y axis.
195 */
196 protected String getDAxisLabel() {
197 return msg(I18N_4YAXIS_LABEL, I18N_4YAXIS_LABEL_DEFAULT);
198 }
199
200 /**
201 * Produce output.
202 * @param artifactAndFacet current facet.
203 * @param attr theme for facet
204 * @param visible Whether this facets data is actually visible or not.
205 */
206 public void doOut(
207 ArtifactAndFacet artifactAndFacet,
208 Document attr,
209 boolean visible
210 ) {
211 String name = artifactAndFacet.getFacetName();
212
213 logger.debug("FlowVelocityGenerator.doOut: " + name);
214
215 if (name == null) {
216 logger.error("No facet name for doOut(). No output generated!");
217 return;
218 }
219
220 Facet facet = artifactAndFacet.getFacet();
221
222 if (facet == null) {
223 return;
224 }
225
226 if (getXBounds(0) != null && getDomainAxisRange() != null) {
227 logger.debug(Arrays.toString(getDomainAxisRangeFromRequest()));
228 Bounds bounds =
229 calculateZoom(getXBounds(0), getDomainAxisRange());
230 context.putContextValue("startkm", bounds.getLower());
231 context.putContextValue("endkm", bounds.getUpper());
232 }
233 else if (getXBounds(0) != null && getDomainAxisRange() == null) {
234 context.putContextValue("startkm", getXBounds(0).getLower());
235 context.putContextValue("endkm", getXBounds(0).getUpper());
236 }
237 else if (getXBounds(0) == null && getDomainAxisRange() == null) {
238 D4EArtifact artifact = (D4EArtifact)artifactAndFacet.getArtifact();
239 FlowVelocityAccess access = new FlowVelocityAccess(artifact);
240 context.putContextValue("startkm", access.getLowerKM());
241 context.putContextValue("endkm", access.getUpperKM());
242 }
243 else if (getXBounds(0) == null && getDomainAxisRange() != null){
244 D4EArtifact artifact = (D4EArtifact)artifactAndFacet.getArtifact();
245 FlowVelocityAccess access = new FlowVelocityAccess(artifact);
246 Bounds b = new DoubleBounds(access.getLowerKM(), access.getUpperKM());
247 Bounds bounds =
248 calculateZoom(b, getDomainAxisRange());
249 context.putContextValue("startkm", bounds.getLower());
250 context.putContextValue("endkm", bounds.getUpper());
251 }
252 if (name.equals(FLOW_VELOCITY_MAINCHANNEL)) {
253 doMainChannelOut(
254 (FlowVelocityData) artifactAndFacet.getData(context),
255 artifactAndFacet,
256 attr,
257 visible);
258 }
259 else if (name.equals(FLOW_VELOCITY_TOTALCHANNEL)) {
260 doTotalChannelOut(
261 (FlowVelocityData) artifactAndFacet.getData(context),
262 artifactAndFacet,
263 attr,
264 visible);
265 }
266 else if (name.equals(FLOW_VELOCITY_MAINCHANNEL_FILTERED)) {
267 doMainChannelOut(
268 (FlowVelocityData) artifactAndFacet.getData(context),
269 artifactAndFacet,
270 attr,
271 visible);
272 }
273 else if (name.equals(FLOW_VELOCITY_TOTALCHANNEL_FILTERED)) {
274 doTotalChannelOut(
275 (FlowVelocityData) artifactAndFacet.getData(context),
276 artifactAndFacet,
277 attr,
278 visible);
279 }
280 else if (name.equals(FLOW_VELOCITY_DISCHARGE)) {
281 doQOut(
282 (FlowVelocityData) artifactAndFacet.getData(context),
283 artifactAndFacet,
284 attr,
285 visible);
286 }
287 else if (name.equals(FLOW_VELOCITY_TAU)) {
288 doTauOut(
289 (FlowVelocityData) artifactAndFacet.getData(context),
290 artifactAndFacet,
291 attr,
292 visible);
293 }
294 else if (name.equals(FLOW_VELOCITY_TAU_FILTERED)) {
295 doTauOut(
296 (FlowVelocityData) artifactAndFacet.getData(context),
297 artifactAndFacet,
298 attr,
299 visible);
300 }
301
302 else if (name.equals(FLOW_VELOCITY_ANNOTATION)) {
303 doAnnotations(
304 (RiverAnnotation) artifactAndFacet.getData(context),
305 artifactAndFacet,
306 attr,
307 visible);
308 }
309 else if (FacetTypes.IS.AREA(name)) {
310 doArea(
311 artifactAndFacet.getData(context),
312 artifactAndFacet,
313 attr,
314 visible);
315 }
316 else if (FacetTypes.IS.MANUALPOINTS(name)) {
317 doPoints(
318 artifactAndFacet.getData(context),
319 artifactAndFacet,
320 attr,
321 visible,
322 YAXIS.V.idx);
323 }
324 else if (name.equals(LONGITUDINAL_ANNOTATION)) {
325 doAnnotations(
326 (RiverAnnotation) artifactAndFacet.getData(context),
327 artifactAndFacet,
328 attr,
329 visible);
330 }
331 else if (name.equals(FLOW_VELOCITY_MEASUREMENT)) {
332 doVPointOut(
333 artifactAndFacet.getData(context),
334 artifactAndFacet,
335 attr,
336 visible);
337 }
338 else if (name.equals(BED_QUALITY_BED_DIAMETER_SUBLAYER)) {
339 doBedQualitySubLayerOut(
340 (BedDiameterResult)artifactAndFacet.getData(context),
341 artifactAndFacet,
342 attr,
343 visible);
344 }
345 else if (name.equals(BED_QUALITY_BED_DIAMETER_TOPLAYER)) {
346 doBedQualityTopLayerOut(
347 (BedDiameterResult)artifactAndFacet.getData(context),
348 artifactAndFacet,
349 attr,
350 visible);
351 }
352 else if (name.equals(BED_QUALITY_BEDLOAD_DIAMETER)) {
353 doBedQualityLoadDiameter(
354 (BedloadDiameterResult)artifactAndFacet.getData(context),
355 artifactAndFacet,
356 attr,
357 visible);
358 }
359 else {
360 logger.warn("Unknown facet name: " + name);
361 return;
362 }
363 }
364
365
366 private void doBedQualityLoadDiameter( 75 private void doBedQualityLoadDiameter(
367 BedloadDiameterResult data, 76 BedloadDiameterResult data,
368 ArtifactAndFacet aandf, 77 ArtifactAndFacet aandf,
369 Document attr, 78 Document attr,
370 boolean visible) { 79 boolean visible) {
395 logger.debug("Do beddiametersubout"); 104 logger.debug("Do beddiametersubout");
396 XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), attr); 105 XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), attr);
397 StyledSeriesBuilder.addPoints(series, data.getDiameterSubData(), true); 106 StyledSeriesBuilder.addPoints(series, data.getDiameterSubData(), true);
398 addAxisSeries(series, YAXIS.D.idx, visible); 107 addAxisSeries(series, YAXIS.D.idx, visible);
399 } 108 }
400
401
402 /**
403 * Process the output for W facets in a longitudinal section curve.
404 *
405 * @param data A FlowVelocityData object
406 * @param aandf The facet. This facet does NOT support any data objects. Use
407 * D4EArtifact.getNativeFacet() instead to retrieve a Facet which supports
408 * data.
409 * @param theme The theme that contains styling information.
410 * @param visible The visibility of the curve.
411 */
412 protected void doMainChannelOut(
413 FlowVelocityData data,
414 ArtifactAndFacet aandf,
415 Document theme,
416 boolean visible
417 ) {
418 logger.debug("FlowVelocityGenerator.doMainChannelOut");
419
420 XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme);
421
422 StyledSeriesBuilder.addPoints(series, data.getMainChannelPoints(), true);
423
424 addAxisSeries(series, YAXIS.V.idx, visible);
425 }
426
427
428 /** Handle VWQKms. */
429 protected void doVPointOut (
430 Object data,
431 ArtifactAndFacet aandf,
432 Document theme,
433 boolean visible
434 ) {
435 logger.debug("FlowVelocityGenerator.doVPointOut");
436
437 XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme);
438
439 FlowVelocityMeasurementValue.FastFlowVelocityMeasurementValue
440 value = (FlowVelocityMeasurementValue.FastFlowVelocityMeasurementValue)
441 data;
442
443 StyledSeriesBuilder.addPoints(series, new double[][] {{value.getStation()},{value.getV()}}, true);
444
445 addAxisSeries(series, YAXIS.V.idx, visible);
446 }
447
448
449 /**
450 * Add items to dataseries which describes the differences.
451 */
452 protected void doTotalChannelOut(
453 FlowVelocityData data,
454 ArtifactAndFacet aandf,
455 Document theme,
456 boolean visible
457 ) {
458 logger.debug("FlowVelocityGenerator.doTotalChannelOut");
459
460 if (data == null) {
461 logger.warn("No data to add to FlowVelocity chart.");
462 return;
463 }
464
465 XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme);
466
467 StyledSeriesBuilder.addPoints(series, data.getTotalChannelPoints(), true);
468
469 addAxisSeries(series, YAXIS.V.idx, visible);
470 }
471
472
473
474 /**
475 * @param data A FlowVelocityData object
476 * @param aandf The facet. This facet does NOT support any data objects. Use
477 * D4EArtifact.getNativeFacet() instead to retrieve a Facet which supports
478 * data.
479 * @param theme The theme that contains styling information.
480 * @param visible The visibility of the curve.
481 */
482 protected void doQOut(
483 FlowVelocityData data,
484 ArtifactAndFacet aandf,
485 Document theme,
486 boolean visible
487 ) {
488 logger.debug("FlowVelocityGenerator.doTauOut");
489
490 XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme);
491
492 StyledSeriesBuilder.addPoints(series, data.getQPoints(), true);
493
494 addAxisSeries(series, YAXIS.Q.idx, visible);
495 }
496
497 /**
498 * @param data A FlowVelocityData object
499 * @param aandf The facet. This facet does NOT support any data objects. Use
500 * D4EArtifact.getNativeFacet() instead to retrieve a Facet which supports
501 * data.
502 * @param theme The theme that contains styling information.
503 * @param visible The visibility of the curve.
504 */
505 protected void doTauOut(
506 FlowVelocityData data,
507 ArtifactAndFacet aandf,
508 Document theme,
509 boolean visible
510 ) {
511 logger.debug("FlowVelocityGenerator.doTauOut");
512
513 XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme);
514
515 StyledSeriesBuilder.addPoints(series, data.getTauPoints(), true);
516
517 addAxisSeries(series, YAXIS.T.idx, visible);
518 }
519
520
521 /** Look up the axis identifier for a given facet type. */
522 public int axisIdxForFacet(String facetName) {
523 if (FacetTypes.IS.V(facetName)) {
524 return YAXIS.V.idx;
525 }
526 else if (FacetTypes.IS.T(facetName)) {
527 return YAXIS.T.idx;
528 }
529 else {
530 logger.warn("Could not find axis for facet " + facetName);
531 return YAXIS.V.idx;
532 }
533 }
534
535
536 /**
537 * Do Area out.
538 * @param theme styling information.
539 * @param visible whether or not visible.
540 */
541 protected void doArea(
542 Object o,
543 ArtifactAndFacet aandf,
544 Document theme,
545 boolean visible
546 ) {
547 logger.debug("FlowVelocityGenerator.doArea");
548 logger.warn("TODO: Implement FlowVelocityGenerator.doArea");
549 }
550 } 109 }
551 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 110 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org