annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/CrossSectionWaterLineFacet.java @ 9425:3f49835a00c3

Extended CrossSectionFacet so it may fetch different data from within the artifact result. Also allows to have acces to the potentially already computed artifact result via its normal computation cache.
author gernotbelger
date Fri, 17 Aug 2018 15:31:02 +0200
parents 5e38e2924c07
children bd5f5d2220fa
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
6 * documentation coming with Dive4Elements River for details.
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4506
diff changeset
9 package org.dive4elements.river.artifacts.model;
1122
111794adf285 Get real (but yet not parameterized) data to display in CrossSection.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
10
9425
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
11 import java.io.Serializable;
1975
b30e1710df1d Server-side of interactive cross-section diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1802
diff changeset
12 import java.util.List;
b30e1710df1d Server-side of interactive cross-section diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1802
diff changeset
13
9425
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
14 import org.apache.log4j.Logger;
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
15 import org.dive4elements.artifactdatabase.state.Facet;
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4506
diff changeset
16 import org.dive4elements.artifacts.Artifact;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4506
diff changeset
17 import org.dive4elements.artifacts.CallContext;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4506
diff changeset
18 import org.dive4elements.artifacts.DataProvider;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4506
diff changeset
19 import org.dive4elements.river.artifacts.WaterLineArtifact;
9425
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
20 import org.dive4elements.river.artifacts.geom.Lines;
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
21 import org.dive4elements.river.artifacts.geom.Lines.LineData;
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
22 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4506
diff changeset
23 import org.dive4elements.river.model.FastCrossSectionLine;
1122
111794adf285 Get real (but yet not parameterized) data to display in CrossSection.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
24
111794adf285 Get real (but yet not parameterized) data to display in CrossSection.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
25 /**
111794adf285 Get real (but yet not parameterized) data to display in CrossSection.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
26 * Facet for Waterlines in Cross Sections.
111794adf285 Get real (but yet not parameterized) data to display in CrossSection.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
27 */
9425
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
28 public class CrossSectionWaterLineFacet extends DataFacet implements FacetTypes {
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
29
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
30 private static final LineData NO_LINE_DATA = new Lines.LineData(new double[][] {}, 0d, 0d);
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
31
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
32 private static final long serialVersionUID = 1L;
1122
111794adf285 Get real (but yet not parameterized) data to display in CrossSection.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
33
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
34 /** Private log to use. */
9425
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
35 private static Logger log = Logger.getLogger(CrossSectionWaterLineFacet.class);
1122
111794adf285 Get real (but yet not parameterized) data to display in CrossSection.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
36
9425
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
37 private final Serializable waterLineIndex;
1122
111794adf285 Get real (but yet not parameterized) data to display in CrossSection.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
38
111794adf285 Get real (but yet not parameterized) data to display in CrossSection.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
39 /** Trivial constructor, set (maybe localized) description. */
9425
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
40 public CrossSectionWaterLineFacet(final int idx, final String description, final ComputeType type, final String hash, final String stateId,
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
41 final Serializable waterLineIndex) {
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
42 this(idx, CROSS_SECTION_WATER_LINE, description, type, hash, stateId, waterLineIndex);
1122
111794adf285 Get real (but yet not parameterized) data to display in CrossSection.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
43 }
111794adf285 Get real (but yet not parameterized) data to display in CrossSection.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
44
3272
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3227
diff changeset
45 /**
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3227
diff changeset
46 * Trivial constructor, set (maybe localized) description.
9425
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
47 *
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
48 * @param facetIndex
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
49 * Index of this facet.
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
50 * @param waterLineIndex
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
51 * Determines which water-line the artifact will return. Depends on the implementation of the artifact.
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
52 * Is serializable because this class is, must be immutable because only the reference is copied in
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
53 * 'deepCopy'
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
54 * @param name
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
55 * 'type' of this facet.
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
56 * @param description
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
57 * (maybe) localized user-visible description.
3272
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3227
diff changeset
58 */
9425
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
59 public CrossSectionWaterLineFacet(final int facetIndex, final String name, final String description, final ComputeType type, final String hash,
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
60 final String stateId, final Serializable waterLineIndex) {
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
61 super(facetIndex, name, description, type, hash, stateId);
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
62
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
63 this.waterLineIndex = waterLineIndex;
3198
d35f28655fa6 Create and handle new manual line type facets.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3076
diff changeset
64 }
d35f28655fa6 Create and handle new manual line type facets.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3076
diff changeset
65
1122
111794adf285 Get real (but yet not parameterized) data to display in CrossSection.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
66 /**
1975
b30e1710df1d Server-side of interactive cross-section diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1802
diff changeset
67 * Gets waterline (crossed with cross section) of waterlevel.
9425
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
68 * FIXME: the cross section facets delgate fetching the data to the artifact, which in turn (in most cases) re-calculate
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
69 * the artifact on every call....
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
70 * Instead this should work like other facets that rely on the hashed computation.
1122
111794adf285 Get real (but yet not parameterized) data to display in CrossSection.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
71 */
9425
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
72 @Override
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
73 public Object getData(final Artifact artifact, final CallContext context) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
74 log.debug("Get data for cross section water line");
1122
111794adf285 Get real (but yet not parameterized) data to display in CrossSection.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
75
9425
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
76 final List<DataProvider> providers = context.getDataProvider(CrossSectionFacet.BLACKBOARD_CS_MASTER_DATA);
1975
b30e1710df1d Server-side of interactive cross-section diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1802
diff changeset
77 if (providers.size() < 1) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
78 log.warn("Could not find Cross-Section data provider.");
9425
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
79 return NO_LINE_DATA;
1975
b30e1710df1d Server-side of interactive cross-section diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1802
diff changeset
80 }
3076
5642a83420f2 FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2676
diff changeset
81
9425
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
82 final DataProvider dataProvider = providers.get(0);
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
83
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
84 final FastCrossSectionLine crossSection = (FastCrossSectionLine) dataProvider.provideData(CrossSectionFacet.BLACKBOARD_CS_MASTER_DATA, null, context);
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
85 if (crossSection == null)
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
86 return NO_LINE_DATA;
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
87
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
88 Object nextKm = dataProvider.provideData(CrossSectionFacet.BLACKBOARD_CS_NEXT_KM, null, context);
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
89 Object prevKm = dataProvider.provideData(CrossSectionFacet.BLACKBOARD_CS_PREV_KM, null, context);
3272
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3227
diff changeset
90 if (prevKm == null)
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3227
diff changeset
91 prevKm = new Double(-1d);
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3227
diff changeset
92 if (nextKm == null)
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3227
diff changeset
93 nextKm = new Double(-1d);
1975
b30e1710df1d Server-side of interactive cross-section diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1802
diff changeset
94
4506
719680a282e5 CrossSectionWaterLineFacet: Guard class cast.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4478
diff changeset
95 if (!(artifact instanceof WaterLineArtifact)) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
96 log.error("CrossSectionWaterLineFacet needs WaterLineArtifact");
9425
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
97 return NO_LINE_DATA;
4506
719680a282e5 CrossSectionWaterLineFacet: Guard class cast.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4478
diff changeset
98 }
1122
111794adf285 Get real (but yet not parameterized) data to display in CrossSection.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
99
9425
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
100 final WaterLineArtifact lineArtifact = (WaterLineArtifact) artifact;
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
101
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
102 final double currentKm = crossSection.getKm();
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
103
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
104 final double waterLevel = lineArtifact.getWaterLevel(this.type, this.hash, this.stateId, currentKm, this.waterLineIndex, (Double) nextKm,
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
105 (Double) prevKm,
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
106 context);
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
107 if (Double.isNaN(waterLevel))
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
108 return NO_LINE_DATA;
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
109
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
110 return Lines.createWaterLines(crossSection.getPoints(), waterLevel);
1122
111794adf285 Get real (but yet not parameterized) data to display in CrossSection.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
111 }
111794adf285 Get real (but yet not parameterized) data to display in CrossSection.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
112
1136
8da5f5a9ed3c Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1122
diff changeset
113 /** Do a deep copy. */
3076
5642a83420f2 FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2676
diff changeset
114 @Override
1122
111794adf285 Get real (but yet not parameterized) data to display in CrossSection.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
115 public Facet deepCopy() {
9425
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
116 final CrossSectionWaterLineFacet copy = new CrossSectionWaterLineFacet(this.getIndex(), this.name, this.description, this.type, this.hash, this.stateId,
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
117 this.waterLineIndex);
1122
111794adf285 Get real (but yet not parameterized) data to display in CrossSection.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
118 copy.set(this);
111794adf285 Get real (but yet not parameterized) data to display in CrossSection.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
119 return copy;
111794adf285 Get real (but yet not parameterized) data to display in CrossSection.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
120 }
9425
3f49835a00c3 Extended CrossSectionFacet so it may fetch different data from within the artifact result.
gernotbelger
parents: 8856
diff changeset
121 }

http://dive4elements.wald.intevation.org