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