Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/exports/LongitudinalSectionGenerator.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 | dd5355775ce1 |
children | 7089f338138a |
comparison
equal
deleted
inserted
replaced
6793:bdbe704dd433 | 6794:23ab795f2f0e |
---|---|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the | 5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
6 * documentation coming with Dive4Elements River for details. | 6 * documentation coming with Dive4Elements River for details. |
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.exports; | 9 package org.dive4elements.river.exports; |
10 | |
11 import java.util.Arrays; | |
10 | 12 |
11 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; | 13 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; |
12 import org.dive4elements.artifactdatabase.state.Facet; | 14 import org.dive4elements.artifactdatabase.state.Facet; |
13 import org.dive4elements.river.artifacts.D4EArtifact; | 15 import org.dive4elements.river.artifacts.D4EArtifact; |
14 import org.dive4elements.river.artifacts.geom.Lines; | 16 import org.dive4elements.river.artifacts.geom.Lines; |
21 import org.dive4elements.river.exports.process.BedDiffHeightYearProcessor; | 23 import org.dive4elements.river.exports.process.BedDiffHeightYearProcessor; |
22 import org.dive4elements.river.exports.process.BedDiffYearProcessor; | 24 import org.dive4elements.river.exports.process.BedDiffYearProcessor; |
23 import org.dive4elements.river.exports.process.BedheightProcessor; | 25 import org.dive4elements.river.exports.process.BedheightProcessor; |
24 import org.dive4elements.river.exports.process.WOutProcessor; | 26 import org.dive4elements.river.exports.process.WOutProcessor; |
25 | 27 |
28 import org.dive4elements.river.artifacts.access.FlowVelocityAccess; | |
29 import org.dive4elements.river.artifacts.model.FlowVelocityData; | |
30 import org.dive4elements.river.model.FlowVelocityMeasurementValue; | |
31 | |
32 import org.dive4elements.river.jfree.Bounds; | |
33 import org.dive4elements.river.jfree.DoubleBounds; | |
26 import org.dive4elements.river.jfree.RiverAnnotation; | 34 import org.dive4elements.river.jfree.RiverAnnotation; |
27 import org.dive4elements.river.jfree.StyledAreaSeriesCollection; | 35 import org.dive4elements.river.jfree.StyledAreaSeriesCollection; |
28 import org.dive4elements.river.jfree.StyledXYSeries; | 36 import org.dive4elements.river.jfree.StyledXYSeries; |
29 import org.dive4elements.river.utils.DataUtil; | 37 import org.dive4elements.river.utils.DataUtil; |
30 import org.dive4elements.river.utils.RiverUtils; | 38 import org.dive4elements.river.utils.RiverUtils; |
44 public class LongitudinalSectionGenerator | 52 public class LongitudinalSectionGenerator |
45 extends XYChartGenerator | 53 extends XYChartGenerator |
46 implements FacetTypes | 54 implements FacetTypes |
47 { | 55 { |
48 public enum YAXIS { | 56 public enum YAXIS { |
49 W(0), | 57 W(0), // waterlevel |
50 D(1), | 58 D(1), // waterlevel-difference |
51 Q(2); | 59 Q(2), // discharge |
60 V(3), // flow velocity | |
61 T(4), // tau (shear stress) | |
62 O(3); // diameter | |
52 protected int idx; | 63 protected int idx; |
53 private YAXIS(int c) { | 64 private YAXIS(int c) { |
54 idx = c; | 65 idx = c; |
55 } | 66 } |
56 } | 67 } |
65 | 76 |
66 /** | 77 /** |
67 * Key to look up internationalized String for LongitudinalSection diagrams | 78 * Key to look up internationalized String for LongitudinalSection diagrams |
68 * titles. | 79 * titles. |
69 */ | 80 */ |
81 /** TODO: | |
82 * create a class which extends this one to avoid following definition here | |
83 */ | |
70 public static final String I18N_CHART_TITLE = | 84 public static final String I18N_CHART_TITLE = |
71 "chart.longitudinal.section.title"; | 85 "chart.longitudinal.section.title"; |
86 public static final String I18N_CHART_TITLE_DEFAULT = | |
87 "L\u00e4ngsschnitt"; | |
72 | 88 |
73 /** | 89 /** |
74 * Key to look up internationalized String for LongitudinalSection diagrams | 90 * Key to look up internationalized String for LongitudinalSection diagrams |
75 * subtitles. | 91 * subtitles. |
76 */ | 92 */ |
82 * short subtitles. | 98 * short subtitles. |
83 */ | 99 */ |
84 public static final String I18N_CHART_SHORT_SUBTITLE = | 100 public static final String I18N_CHART_SHORT_SUBTITLE = |
85 "chart.longitudinal.section.shortsubtitle"; | 101 "chart.longitudinal.section.shortsubtitle"; |
86 | 102 |
103 /** | |
104 * Key to look up internationalized String for LongitudinalSection diagrams | |
105 * X-axis title. | |
106 */ | |
87 public static final String I18N_XAXIS_LABEL = | 107 public static final String I18N_XAXIS_LABEL = |
88 "chart.longitudinal.section.xaxis.label"; | 108 "chart.longitudinal.section.xaxis.label"; |
89 | 109 public static final String I18N_XAXIS_LABEL_DEFAULT = |
90 public static final String I18N_YAXIS_LABEL = | 110 "km"; |
91 "chart.longitudinal.section.yaxis.label"; | 111 |
92 | 112 /** |
93 public static final String I18N_2YAXIS_LABEL = | 113 * Key to look up internationalized String for LongitudinalSection diagrams |
94 "chart.longitudinal.section.yaxis.second.label"; | 114 * Y-axis titles. |
95 | 115 */ |
96 public static final String I18N_CHART_TITLE_DEFAULT = "W-L\u00e4ngsschnitt"; | 116 public static final String I18N_YAXIS_LABEL_W = |
97 public static final String I18N_XAXIS_LABEL_DEFAULT = "km"; | 117 "chart.longitudinal.section.yaxis.label.w"; |
98 public static final String I18N_YAXIS_LABEL_DEFAULT = "W [NN + m]"; | 118 public static final String I18N_YAXIS_LABEL_Q = |
99 public static final String I18N_2YAXIS_LABEL_DEFAULT = "Q [m\u00b3/s]"; | 119 "chart.longitudinal.section.yaxis.label.q"; |
100 | 120 public static final String I18N_YAXIS_LABEL_D = |
101 public final static String I18N_WDIFF_YAXIS_LABEL = | |
102 "chart.w_differences.yaxis.label"; | 121 "chart.w_differences.yaxis.label"; |
103 | 122 public static final String I18N_YAXIS_LABEL_V = |
104 public final static String I18N_WDIFF_YAXIS_LABEL_DEFAULT = "m"; | 123 "chart.flow_velocity.section.yaxis.label"; |
124 public static final String I18N_YAXIS_LABEL_T = | |
125 "chart.flow_velocity.section.yaxis.second.label"; | |
126 public static final String I18N_YAXIS_LABEL_DEFAULT = | |
127 "Y-axis"; | |
128 | |
105 | 129 |
106 public LongitudinalSectionGenerator() { | 130 public LongitudinalSectionGenerator() { |
107 super(); | 131 super(); |
108 } | 132 } |
109 | 133 |
216 I18N_XAXIS_LABEL_DEFAULT, | 240 I18N_XAXIS_LABEL_DEFAULT, |
217 new Object[] { RiverUtils.getRiver(flys).getName() }); | 241 new Object[] { RiverUtils.getRiver(flys).getName() }); |
218 } | 242 } |
219 | 243 |
220 | 244 |
245 /** | |
246 * Get internationalized label for the y axis. | |
247 */ | |
221 @Override | 248 @Override |
222 protected String getDefaultYAxisLabel(int index) { | 249 protected String getDefaultYAxisLabel(int index) { |
223 String label = "default"; | 250 |
251 D4EArtifact flys = (D4EArtifact) master; | |
252 String unit = RiverUtils.getRiver(flys).getWstUnit().getName(); | |
224 | 253 |
225 if (index == YAXIS.W.idx) { | 254 if (index == YAXIS.W.idx) { |
226 label = getWAxisLabel(); | 255 return msg( |
227 } | 256 I18N_YAXIS_LABEL_W, |
228 else if (index == YAXIS.Q.idx) { | 257 I18N_YAXIS_LABEL_DEFAULT, |
229 label = msg(getQAxisLabelKey(), getQAxisDefaultLabel()); | 258 new Object[] { unit }); |
230 } | 259 } |
231 else if (index == YAXIS.D.idx) { | 260 if (index == YAXIS.Q.idx) { |
232 label = msg(I18N_WDIFF_YAXIS_LABEL, I18N_WDIFF_YAXIS_LABEL_DEFAULT); | 261 return msg( |
233 } | 262 I18N_YAXIS_LABEL_Q, |
234 | 263 I18N_YAXIS_LABEL_DEFAULT); |
235 return label; | 264 } |
236 } | 265 if (index == YAXIS.D.idx) { |
237 | 266 return msg( |
238 | 267 I18N_YAXIS_LABEL_D, |
239 /** | 268 I18N_YAXIS_LABEL_DEFAULT); |
240 * Get internationalized label for the y axis. | 269 } |
241 */ | 270 if (index == YAXIS.V.idx) { |
242 protected String getWAxisLabel() { | 271 return msg( |
243 D4EArtifact flys = (D4EArtifact) master; | 272 I18N_YAXIS_LABEL_V, |
244 | 273 I18N_YAXIS_LABEL_DEFAULT); |
245 String unit = RiverUtils.getRiver(flys).getWstUnit().getName(); | 274 } |
246 | 275 if (index == YAXIS.T.idx) { |
247 return msg( | 276 return msg( |
248 I18N_YAXIS_LABEL, | 277 I18N_YAXIS_LABEL_T, |
249 I18N_YAXIS_LABEL_DEFAULT, | 278 I18N_YAXIS_LABEL_DEFAULT); |
250 new Object[] { unit }); | 279 } |
280 | |
281 return "default"; | |
251 } | 282 } |
252 | 283 |
253 | 284 |
254 /** | 285 /** |
255 * Create Axis for given index. | 286 * Create Axis for given index. |
266 else { | 297 else { |
267 axis.setAutoRangeIncludesZero(false); | 298 axis.setAutoRangeIncludesZero(false); |
268 } | 299 } |
269 | 300 |
270 return axis; | 301 return axis; |
271 } | |
272 | |
273 | |
274 /** | |
275 * Get default value for the second Y-Axis' label (if no translation was | |
276 * found). | |
277 */ | |
278 protected String getQAxisDefaultLabel() { | |
279 return I18N_2YAXIS_LABEL_DEFAULT; | |
280 } | |
281 | |
282 | |
283 /** | |
284 * Get key for internationalization of the second Y-Axis' label. | |
285 */ | |
286 protected String getQAxisLabelKey() { | |
287 return I18N_2YAXIS_LABEL; | |
288 } | 302 } |
289 | 303 |
290 | 304 |
291 /** | 305 /** |
292 * Trigger inversion. | 306 * Trigger inversion. |
397 artifactAndFacet, | 411 artifactAndFacet, |
398 attr, | 412 attr, |
399 visible, | 413 visible, |
400 YAXIS.W.idx); | 414 YAXIS.W.idx); |
401 } | 415 } |
416 | |
417 /* output for flow velocity */ | |
418 if (getXBounds(0) != null && getDomainAxisRange() != null) { | |
419 logger.debug(Arrays.toString(getDomainAxisRangeFromRequest())); | |
420 Bounds bounds = | |
421 calculateZoom(getXBounds(0), getDomainAxisRange()); | |
422 context.putContextValue("startkm", bounds.getLower()); | |
423 context.putContextValue("endkm", bounds.getUpper()); | |
424 } | |
425 else if (getXBounds(0) != null && getDomainAxisRange() == null) { | |
426 context.putContextValue("startkm", getXBounds(0).getLower()); | |
427 context.putContextValue("endkm", getXBounds(0).getUpper()); | |
428 } | |
429 else if (getXBounds(0) == null && getDomainAxisRange() == null) { | |
430 D4EArtifact artifact = (D4EArtifact)artifactAndFacet.getArtifact(); | |
431 FlowVelocityAccess access = new FlowVelocityAccess(artifact); | |
432 context.putContextValue("startkm", access.getLowerKM()); | |
433 context.putContextValue("endkm", access.getUpperKM()); | |
434 } | |
435 else if (getXBounds(0) == null && getDomainAxisRange() != null){ | |
436 D4EArtifact artifact = (D4EArtifact)artifactAndFacet.getArtifact(); | |
437 FlowVelocityAccess access = new FlowVelocityAccess(artifact); | |
438 Bounds b = new DoubleBounds(access.getLowerKM(), access.getUpperKM()); | |
439 Bounds bounds = | |
440 calculateZoom(b, getDomainAxisRange()); | |
441 context.putContextValue("startkm", bounds.getLower()); | |
442 context.putContextValue("endkm", bounds.getUpper()); | |
443 } | |
444 if (name.equals(FLOW_VELOCITY_MAINCHANNEL)) { | |
445 doMainChannelOut( | |
446 (FlowVelocityData) artifactAndFacet.getData(context), | |
447 artifactAndFacet, | |
448 attr, | |
449 visible); | |
450 } | |
451 else if (name.equals(FLOW_VELOCITY_TOTALCHANNEL)) { | |
452 doTotalChannelOut( | |
453 (FlowVelocityData) artifactAndFacet.getData(context), | |
454 artifactAndFacet, | |
455 attr, | |
456 visible); | |
457 } | |
458 else if (name.equals(FLOW_VELOCITY_MAINCHANNEL_FILTERED)) { | |
459 doMainChannelOut( | |
460 (FlowVelocityData) artifactAndFacet.getData(context), | |
461 artifactAndFacet, | |
462 attr, | |
463 visible); | |
464 } | |
465 else if (name.equals(FLOW_VELOCITY_TOTALCHANNEL_FILTERED)) { | |
466 doTotalChannelOut( | |
467 (FlowVelocityData) artifactAndFacet.getData(context), | |
468 artifactAndFacet, | |
469 attr, | |
470 visible); | |
471 } | |
472 else if (name.equals(FLOW_VELOCITY_DISCHARGE)) { | |
473 doQOut( | |
474 (FlowVelocityData) artifactAndFacet.getData(context), | |
475 artifactAndFacet, | |
476 attr, | |
477 visible); | |
478 } | |
479 else if (name.equals(FLOW_VELOCITY_TAU)) { | |
480 doTauOut( | |
481 (FlowVelocityData) artifactAndFacet.getData(context), | |
482 artifactAndFacet, | |
483 attr, | |
484 visible); | |
485 } | |
486 else if (name.equals(FLOW_VELOCITY_TAU_FILTERED)) { | |
487 doTauOut( | |
488 (FlowVelocityData) artifactAndFacet.getData(context), | |
489 artifactAndFacet, | |
490 attr, | |
491 visible); | |
492 } | |
493 else if (name.equals(FLOW_VELOCITY_MEASUREMENT)) { | |
494 doVPointOut( | |
495 artifactAndFacet.getData(context), | |
496 artifactAndFacet, | |
497 attr, | |
498 visible); | |
499 } | |
500 | |
501 | |
402 else { | 502 else { |
403 logger.warn("Unknown facet name: " + name); | 503 logger.warn("Unknown facet name: " + name); |
404 return; | 504 return; |
405 } | 505 } |
406 } | 506 } |
519 return YAXIS.W.idx; | 619 return YAXIS.W.idx; |
520 } | 620 } |
521 else if (FacetTypes.IS.Q(facetName)) { | 621 else if (FacetTypes.IS.Q(facetName)) { |
522 return YAXIS.Q.idx; | 622 return YAXIS.Q.idx; |
523 } | 623 } |
624 else if (FacetTypes.IS.V(facetName)) { | |
625 return YAXIS.V.idx; | |
626 } | |
627 else if (FacetTypes.IS.T(facetName)) { | |
628 return YAXIS.T.idx; | |
629 } | |
524 else { | 630 else { |
525 logger.warn("Could not find axis for facet " + facetName); | 631 logger.warn("Could not find axis for facet " + facetName); |
526 return YAXIS.W.idx; | 632 return YAXIS.W.idx; |
527 } | 633 } |
528 } | 634 } |
625 area.addSeries(down); | 731 area.addSeries(down); |
626 } | 732 } |
627 // Add area to the respective axis. | 733 // Add area to the respective axis. |
628 addAreaSeries(area, axisIdxForFacet(data.getRootFacetName()), visible); | 734 addAreaSeries(area, axisIdxForFacet(data.getRootFacetName()), visible); |
629 } | 735 } |
736 | |
737 | |
738 /** | |
739 * flow velocity specific outs | |
740 */ | |
741 | |
742 /** | |
743 * Process the output for flow velocity in main channel in a longitudinal section curve. | |
744 * | |
745 * @param data A FlowVelocityData object | |
746 * @param aandf The facet. This facet does NOT support any data objects. Use | |
747 * D4EArtifact.getNativeFacet() instead to retrieve a Facet which supports | |
748 * data. | |
749 * @param theme The theme that contains styling information. | |
750 * @param visible The visibility of the curve. | |
751 */ | |
752 protected void doMainChannelOut( | |
753 FlowVelocityData data, | |
754 ArtifactAndFacet aandf, | |
755 Document theme, | |
756 boolean visible | |
757 ) { | |
758 logger.debug("FlowVelocityGenerator.doMainChannelOut"); | |
759 | |
760 XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme); | |
761 | |
762 StyledSeriesBuilder.addPoints(series, data.getMainChannelPoints(), true); | |
763 | |
764 addAxisSeries(series, YAXIS.V.idx, visible); | |
765 } | |
766 | |
767 /** | |
768 * Process the output for flow velocity in total channel in a longitudinal section curve. | |
769 */ | |
770 protected void doTotalChannelOut( | |
771 FlowVelocityData data, | |
772 ArtifactAndFacet aandf, | |
773 Document theme, | |
774 boolean visible | |
775 ) { | |
776 logger.debug("FlowVelocityGenerator.doTotalChannelOut"); | |
777 | |
778 if (data == null) { | |
779 logger.warn("No data to add to FlowVelocity chart."); | |
780 return; | |
781 } | |
782 | |
783 XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme); | |
784 | |
785 StyledSeriesBuilder.addPoints(series, data.getTotalChannelPoints(), true); | |
786 | |
787 addAxisSeries(series, YAXIS.V.idx, visible); | |
788 } | |
789 | |
790 /** | |
791 * @param data A FlowVelocityData object | |
792 * @param aandf The facet. This facet does NOT support any data objects. Use | |
793 * D4EArtifact.getNativeFacet() instead to retrieve a Facet which supports | |
794 * data. | |
795 * @param theme The theme that contains styling information. | |
796 * @param visible The visibility of the curve. | |
797 */ | |
798 protected void doTauOut( | |
799 FlowVelocityData data, | |
800 ArtifactAndFacet aandf, | |
801 Document theme, | |
802 boolean visible | |
803 ) { | |
804 logger.debug("FlowVelocityGenerator.doTauOut"); | |
805 | |
806 XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme); | |
807 | |
808 StyledSeriesBuilder.addPoints(series, data.getTauPoints(), true); | |
809 | |
810 addAxisSeries(series, YAXIS.T.idx, visible); | |
811 } | |
812 | |
813 protected void doVPointOut ( | |
814 Object data, | |
815 ArtifactAndFacet aandf, | |
816 Document theme, | |
817 boolean visible | |
818 ) { | |
819 logger.debug("FlowVelocityGenerator.doVPointOut"); | |
820 | |
821 XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme); | |
822 | |
823 FlowVelocityMeasurementValue.FastFlowVelocityMeasurementValue | |
824 value = (FlowVelocityMeasurementValue.FastFlowVelocityMeasurementValue) | |
825 data; | |
826 | |
827 StyledSeriesBuilder.addPoints(series, new double[][] {{value.getStation()},{value.getV()}}, true); | |
828 | |
829 addAxisSeries(series, YAXIS.V.idx, visible); | |
830 } | |
831 | |
832 /** | |
833 * @param data A FlowVelocityData object | |
834 * @param aandf The facet. This facet does NOT support any data objects. Use | |
835 * D4EArtifact.getNativeFacet() instead to retrieve a Facet which supports | |
836 * data. | |
837 * @param theme The theme that contains styling information. | |
838 * @param visible The visibility of the curve. | |
839 */ | |
840 protected void doQOut( | |
841 FlowVelocityData data, | |
842 ArtifactAndFacet aandf, | |
843 Document theme, | |
844 boolean visible | |
845 ) { | |
846 logger.debug("FlowVelocityGenerator.doTauOut"); | |
847 | |
848 XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme); | |
849 | |
850 StyledSeriesBuilder.addPoints(series, data.getQPoints(), true); | |
851 | |
852 addAxisSeries(series, YAXIS.Q.idx, visible); | |
853 } | |
630 } | 854 } |
631 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 855 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |