annotate artifacts/src/main/java/org/dive4elements/river/artifacts/CrossSectionArtifact.java @ 8856:5e38e2924c07 3.2.x

Fix code style.
author Tom Gottfried <tom@intevation.de>
date Thu, 18 Jan 2018 20:12:01 +0100
parents e4606eae8ea5
children 8d6e56e57c4a 0a5239a1e46e
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: 5867
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: 5867
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: 4863
diff changeset
9 package org.dive4elements.river.artifacts;
1964
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
10
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
11 import java.util.ArrayList;
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
12 import java.util.List;
2120
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
13 import java.util.NavigableMap;
1964
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
14
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
15 import org.apache.log4j.Logger;
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
16
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
17 import org.w3c.dom.Document;
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
18
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4863
diff changeset
19 import org.dive4elements.artifacts.Artifact;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4863
diff changeset
20 import org.dive4elements.artifacts.ArtifactFactory;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4863
diff changeset
21 import org.dive4elements.artifacts.CallMeta;
2126
d626ae185305 Use the fast cross section lines from backend now.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2120
diff changeset
22
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4863
diff changeset
23 import org.dive4elements.river.artifacts.access.RangeAccess;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4863
diff changeset
24 import org.dive4elements.river.artifacts.model.CrossSectionFacet;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4863
diff changeset
25 import org.dive4elements.river.artifacts.model.FastCrossSectionLineFactory;
1964
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
26
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4863
diff changeset
27 import org.dive4elements.river.model.FastCrossSectionLine;
1964
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
28
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4863
diff changeset
29 import org.dive4elements.river.model.CrossSection;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4863
diff changeset
30 import org.dive4elements.river.model.CrossSectionLine;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4863
diff changeset
31 import org.dive4elements.river.artifacts.model.CrossSectionFactory;
1964
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
32
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4863
diff changeset
33 import org.dive4elements.river.artifacts.states.StaticState;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4863
diff changeset
34
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4863
diff changeset
35 import org.dive4elements.artifactdatabase.state.Facet;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4863
diff changeset
36 import org.dive4elements.artifactdatabase.state.FacetActivity;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4863
diff changeset
37 import org.dive4elements.artifactdatabase.state.State;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4863
diff changeset
38
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4863
diff changeset
39 import org.dive4elements.river.artifacts.services.CrossSectionKMService;
2120
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
40
1964
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
41
1985
07b176b14205 Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1982
diff changeset
42 /**
07b176b14205 Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1982
diff changeset
43 * Artifact describing a cross-section.
07b176b14205 Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1982
diff changeset
44 */
5867
59ff03ff48f1 River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
45 public class CrossSectionArtifact extends StaticD4EArtifact {
1964
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
46
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
47 /** Name of Artifact. */
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
48 public static final String CS_ARTIFACT_NAME = "cross_section";
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
49
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
50 /** Name of state. */
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
51 public static final String STATIC_STATE_NAME = "state.cross_section";
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
52
1967
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
53 /** Name of data item keeping the position. */
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
54 public static final String DATA_KM = "cross_section.km";
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
55
6537
f2722602936c issue1157: Store parents initial km at CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6101
diff changeset
56 /** Name of data item keeping the 'parents' km. */
f2722602936c issue1157: Store parents initial km at CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6101
diff changeset
57 public static final String PARENT_KM = "cross_section.parent.km";
f2722602936c issue1157: Store parents initial km at CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6101
diff changeset
58
1967
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
59 /** Name of data item keeping the database id of this c.s.. */
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
60 public static final String DATA_DBID = "cross_section.dbid";
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
61
2040
cd9bcdcf6597 Make only newest CrossSection intially active in diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2037
diff changeset
62 /** Name of data item flagging whether we think that we are master. */
1967
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
63 public static final String DATA_IS_MASTER = "cross_section.master?";
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
64
2040
cd9bcdcf6597 Make only newest CrossSection intially active in diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2037
diff changeset
65 /** Name of data item flagging whether we are the newest. */
cd9bcdcf6597 Make only newest CrossSection intially active in diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2037
diff changeset
66 public static final String DATA_IS_NEWEST = "cross_section.newest?";
cd9bcdcf6597 Make only newest CrossSection intially active in diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2037
diff changeset
67
3272
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
68 /** Name of data item storing the previous possible km. */
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
69 public static final String DATA_PREV_KM = "cross_section.km.previous";
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
70
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
71 /** Name of data item storing the next possible km. */
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
72 public static final String DATA_NEXT_KM = "cross_section.km.next";
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
73
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7842
diff changeset
74 /** Own log. */
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7842
diff changeset
75 private static final Logger log =
1964
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
76 Logger.getLogger(CrossSectionArtifact.class);
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
77
3556
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3405
diff changeset
78 static {
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3405
diff changeset
79 // TODO: Move to configuration.
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3405
diff changeset
80 FacetActivity.Registry.getInstance().register(
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3405
diff changeset
81 CS_ARTIFACT_NAME,
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3405
diff changeset
82 new FacetActivity() {
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3405
diff changeset
83 @Override
3558
c3cd414982fe Adjusted to follow the Chain-of-responsibility pattern in figuring out facet activities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3556
diff changeset
84 public Boolean isInitialActive(
3556
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3405
diff changeset
85 Artifact artifact,
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3405
diff changeset
86 Facet facet,
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3405
diff changeset
87 String outputName
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3405
diff changeset
88 ) {
5867
59ff03ff48f1 River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
89 if (artifact instanceof D4EArtifact) {
59ff03ff48f1 River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
90 D4EArtifact flys = (D4EArtifact)artifact;
3556
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3405
diff changeset
91 String data = flys.getDataAsString(DATA_IS_NEWEST);
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3405
diff changeset
92 return data != null && data.equals("1");
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3405
diff changeset
93 }
3558
c3cd414982fe Adjusted to follow the Chain-of-responsibility pattern in figuring out facet activities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3556
diff changeset
94 return null;
3556
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3405
diff changeset
95 }
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3405
diff changeset
96 });
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3405
diff changeset
97 }
1964
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
98
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
99 /** Return given name. */
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
100 @Override
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
101 public String getName() {
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
102 return CS_ARTIFACT_NAME;
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
103 }
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
104
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
105
1985
07b176b14205 Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1982
diff changeset
106 /** Store ids, create a CrossSectionFacet. */
1964
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
107 @Override
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
108 public void setup(
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
109 String identifier,
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
110 ArtifactFactory factory,
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
111 Object context,
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
112 CallMeta callMeta,
7842
8d5ca5175038 Updated signature of artifacts setup method; Removed unnecessary setup overrides.
Raimund Renkert <rrenkert@intevation.de>
parents: 6936
diff changeset
113 Document data,
8d5ca5175038 Updated signature of artifacts setup method; Removed unnecessary setup overrides.
Raimund Renkert <rrenkert@intevation.de>
parents: 6936
diff changeset
114 List<Class> loadFacets)
1964
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
115 {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7842
diff changeset
116 log.info("CrossSectionArtifact.setup");
1964
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
117
7842
8d5ca5175038 Updated signature of artifacts setup method; Removed unnecessary setup overrides.
Raimund Renkert <rrenkert@intevation.de>
parents: 6936
diff changeset
118 super.setup(identifier, factory, context, callMeta, data, loadFacets);
1964
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
119
2741
0251393f037c Refactor usage of now static xpath, other artifacts will follow in later commits.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2740
diff changeset
120 String ids = getDatacageIDValue(data);
1964
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
121
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
122 if (ids != null && ids.length() > 0) {
1967
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
123 addStringData(DATA_DBID, ids);
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7842
diff changeset
124 log.debug("CrossSectionArtifacts db-id: " + ids);
1964
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
125 }
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
126 else {
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
127 throw new IllegalArgumentException("No attribute 'ids' found!");
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
128 }
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
129
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
130 List<Facet> fs = new ArrayList<Facet>();
2120
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
131 CrossSection cs = CrossSectionFactory.getCrossSection(
3405
b0ba96bbf01d Use Integer.parseInt() instead of Integer.valueOf() + Autounboxing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3284
diff changeset
132 Integer.parseInt(ids));
2120
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
133
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
134 List<CrossSectionLine> csls = cs.getLines();
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
135 if (!csls.isEmpty()) {
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
136 CrossSectionLine csl = csls.get(0);
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
137 // Find min-km of cross sections,
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
138 // then set DATA_KM to min(DATA_KM, minCross).
6936
332d2dfa783f issue1460: prevent NPEs when backstepping and changing Q values for WINFO
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6574
diff changeset
139 String dataKmValue = getDataAsString(DATA_KM);
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
140 double dataKm = (dataKmValue != null)
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
141 ? Double.valueOf(dataKmValue)
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
142 : Double.MIN_VALUE;
3272
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
143 if (dataKm < csl.getKm().doubleValue()) {
2036
c03aeb0cf46b Initialize km of cross-section artifact to a better value (not all cases covered, yet).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1985
diff changeset
144 addStringData(DATA_KM, csl.getKm().toString());
c03aeb0cf46b Initialize km of cross-section artifact to a better value (not all cases covered, yet).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1985
diff changeset
145 }
c03aeb0cf46b Initialize km of cross-section artifact to a better value (not all cases covered, yet).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1985
diff changeset
146 }
1971
741d2067cfe1 Given CrossSections a name, let crosssection facets survive.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1967
diff changeset
147 fs.add(new CrossSectionFacet(0, cs.getDescription()));
1964
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
148
3272
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
149 // Find out if we are newest and become master if so.
6539
4c463ca9b36e issue1157: Make a better choice for master and active CrossSection.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6537
diff changeset
150 boolean isNewest = cs.shouldBeMaster(getParentKm());
2040
cd9bcdcf6597 Make only newest CrossSection intially active in diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2037
diff changeset
151 String newString = (isNewest) ? "1" : "0";
cd9bcdcf6597 Make only newest CrossSection intially active in diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2037
diff changeset
152 addStringData(DATA_IS_NEWEST, newString);
cd9bcdcf6597 Make only newest CrossSection intially active in diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2037
diff changeset
153 addStringData(DATA_IS_MASTER, newString);
cd9bcdcf6597 Make only newest CrossSection intially active in diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2037
diff changeset
154
1964
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
155 if (!fs.isEmpty()) {
4497
a2735a4bf75e Change facets member variable to private
Björn Ricks <bjoern.ricks@intevation.de>
parents: 3558
diff changeset
156 addFacets(getCurrentStateId(), fs);
1964
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
157 }
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
158 }
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
159
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
160
2036
c03aeb0cf46b Initialize km of cross-section artifact to a better value (not all cases covered, yet).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1985
diff changeset
161 /** Copy km where master-artifact "starts". */
1964
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
162 @Override
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
163 protected void initialize(
6574
4930ea445bdd Docs, cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6539
diff changeset
164 Artifact master,
1964
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
165 Object context,
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
166 CallMeta callMeta)
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
167 {
6574
4930ea445bdd Docs, cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6539
diff changeset
168 D4EArtifact masterArtifact = (D4EArtifact) master;
4857
c7133c1f8ede CrossSectionArtifact, Calculation4Access: Updated to use RangeAccess instead of FLYSUtils.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4497
diff changeset
169
6574
4930ea445bdd Docs, cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6539
diff changeset
170 RangeAccess rangeAccess = new RangeAccess(masterArtifact);
4857
c7133c1f8ede CrossSectionArtifact, Calculation4Access: Updated to use RangeAccess instead of FLYSUtils.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4497
diff changeset
171 double[] range = rangeAccess.getKmRange();
2037
986820795c3b Better initialize cross_section.km of cross-section-artifacts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2036
diff changeset
172 if (range != null && range.length > 0) {
6539
4c463ca9b36e issue1157: Make a better choice for master and active CrossSection.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6537
diff changeset
173 this.addStringData(DATA_KM, Double.toString(range[0]));
4c463ca9b36e issue1157: Make a better choice for master and active CrossSection.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6537
diff changeset
174 this.addStringData(PARENT_KM, Double.toString(range[0]));
2037
986820795c3b Better initialize cross_section.km of cross-section-artifacts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2036
diff changeset
175 }
1964
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
176 }
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
177
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
178
3284
d9af29a4bb85 Various cosmetic doc fixes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3272
diff changeset
179 /** Returns next possible km for a cross-section. */
3272
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
180 public Double getNextKm() {
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
181 return getDataAsDouble(DATA_NEXT_KM);
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
182 }
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
183
3284
d9af29a4bb85 Various cosmetic doc fixes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3272
diff changeset
184
d9af29a4bb85 Various cosmetic doc fixes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3272
diff changeset
185 /** Returns previous possible km for a cross-section. */
3272
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
186 public Double getPrevKm() {
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
187 return getDataAsDouble(DATA_PREV_KM);
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
188 }
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
189
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
190
1964
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
191 /**
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
192 * Create and return a new StaticState with charting output.
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
193 */
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
194 @Override
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
195 public State getCurrentState(Object cc) {
4497
a2735a4bf75e Change facets member variable to private
Björn Ricks <bjoern.ricks@intevation.de>
parents: 3558
diff changeset
196 final List<Facet> fs = getFacets(getCurrentStateId());
1964
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
197
1971
741d2067cfe1 Given CrossSections a name, let crosssection facets survive.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1967
diff changeset
198 StaticState state = new StaticState(STATIC_STATE_NAME) {
1982
8afd6a9bb244 Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1973
diff changeset
199 @Override
1971
741d2067cfe1 Given CrossSections a name, let crosssection facets survive.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1967
diff changeset
200 public Object staticCompute(List<Facet> facets) {
741d2067cfe1 Given CrossSections a name, let crosssection facets survive.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1967
diff changeset
201 if (facets != null) {
741d2067cfe1 Given CrossSections a name, let crosssection facets survive.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1967
diff changeset
202 facets.addAll(fs);
741d2067cfe1 Given CrossSections a name, let crosssection facets survive.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1967
diff changeset
203 }
741d2067cfe1 Given CrossSections a name, let crosssection facets survive.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1967
diff changeset
204 return null;
741d2067cfe1 Given CrossSections a name, let crosssection facets survive.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1967
diff changeset
205 }
741d2067cfe1 Given CrossSections a name, let crosssection facets survive.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1967
diff changeset
206 };
1964
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
207
1967
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
208 state.addDefaultChartOutput("cross_section", fs);
1964
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
209
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
210 return state;
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
211 }
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
212
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
213
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
214 /**
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
215 * Get a list containing the one and only State.
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
216 * @param context ignored.
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
217 * @return list with one and only state.
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
218 */
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
219 @Override
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
220 protected List<State> getStates(Object context) {
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
221 ArrayList<State> states = new ArrayList<State>();
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
222 states.add(getCurrentState(context));
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
223
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
224 return states;
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
225 }
1967
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
226
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
227 // TODO all data access needs proper caching.
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
228
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
229 /**
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
230 * Get a DataItem casted to int (0 if fails).
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
231 */
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
232 public int getDataAsIntNull(String dataName) {
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
233 String val = getDataAsString(dataName);
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
234 try {
3405
b0ba96bbf01d Use Integer.parseInt() instead of Integer.valueOf() + Autounboxing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3284
diff changeset
235 return Integer.parseInt(val);
1967
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
236 }
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
237 catch (NumberFormatException e) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7842
diff changeset
238 log.warn("Could not get data " + dataName + " as int", e);
1967
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
239 return 0;
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
240 }
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
241 }
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
242
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
243
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
244 /** Returns database-id of cross-section (from data). */
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
245 protected int getDBID() {
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
246 return getDataAsIntNull(DATA_DBID);
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
247 }
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
248
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
249
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
250 /**
6537
f2722602936c issue1157: Store parents initial km at CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6101
diff changeset
251 * Return position (km) from parent (initial km), 0 if not found.
f2722602936c issue1157: Store parents initial km at CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6101
diff changeset
252 */
f2722602936c issue1157: Store parents initial km at CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6101
diff changeset
253 private double getParentKm() {
f2722602936c issue1157: Store parents initial km at CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6101
diff changeset
254 String val = getDataAsString(PARENT_KM);
6936
332d2dfa783f issue1460: prevent NPEs when backstepping and changing Q values for WINFO
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6574
diff changeset
255 if (val == null) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7842
diff changeset
256 log.warn("Empty data: " + PARENT_KM);
6936
332d2dfa783f issue1460: prevent NPEs when backstepping and changing Q values for WINFO
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6574
diff changeset
257 return 0;
332d2dfa783f issue1460: prevent NPEs when backstepping and changing Q values for WINFO
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6574
diff changeset
258 }
6537
f2722602936c issue1157: Store parents initial km at CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6101
diff changeset
259 try {
f2722602936c issue1157: Store parents initial km at CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6101
diff changeset
260 return Double.valueOf(val);
f2722602936c issue1157: Store parents initial km at CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6101
diff changeset
261 }
f2722602936c issue1157: Store parents initial km at CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6101
diff changeset
262 catch (NumberFormatException e) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7842
diff changeset
263 log.warn("Could not get data " + PARENT_KM + " as double", e);
6537
f2722602936c issue1157: Store parents initial km at CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6101
diff changeset
264 return 0;
f2722602936c issue1157: Store parents initial km at CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6101
diff changeset
265 }
f2722602936c issue1157: Store parents initial km at CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6101
diff changeset
266 }
f2722602936c issue1157: Store parents initial km at CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6101
diff changeset
267
f2722602936c issue1157: Store parents initial km at CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 6101
diff changeset
268 /**
1967
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
269 * Return position (km) from data, 0 if not found.
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
270 */
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
271 protected double getKm() {
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
272 String val = getDataAsString(DATA_KM);
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
273 try {
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
274 return Double.valueOf(val);
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
275 }
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
276 catch (NumberFormatException e) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7842
diff changeset
277 log.warn("Could not get data " + DATA_KM + " as double", e);
1967
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
278 return 0;
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
279 }
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
280 }
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
281
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
282
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
283 /** Returns true if artifact is set to be a "master" (other facets will
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
284 * refer to this). */
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
285 public boolean isMaster() {
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
286 return !getDataAsString(DATA_IS_MASTER).equals("0");
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
287 }
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
288
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
289
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
290 /**
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
291 * Get points of Profile of cross section at given kilometer.
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
292 *
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
293 * @return an array holding coordinates of points of profile (
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
294 * in the form {{x1, x2} {y1, y2}} ).
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
295 */
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
296 public double [][] getCrossSectionData() {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7842
diff changeset
297 log.info("getCrossSectionData() for cross_section.km "
1967
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
298 + getDataAsString(DATA_KM));
2120
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
299 FastCrossSectionLine line = searchCrossSectionLine();
1967
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
300
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
301 return line != null
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
302 ? line.fetchCrossSectionProfile()
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
303 : null;
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
304 }
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
305
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
306
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
307 /**
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
308 * Get CrossSectionLine spatially closest to what is specified in the data
2678
d35e37b6a211 Fix issue620: synchron navigation at impossible km.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2153
diff changeset
309 * "cross_section.km", null if considered too far.
1967
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
310 *
3272
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
311 * It also adds DataItems to store the next and previous (numerically)
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
312 * values at which cross-section data was recorded.
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
313 *
2678
d35e37b6a211 Fix issue620: synchron navigation at impossible km.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2153
diff changeset
314 * @return CrossSectionLine closest to "cross_section.km", might be null
d35e37b6a211 Fix issue620: synchron navigation at impossible km.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2153
diff changeset
315 * if considered too far.
1967
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
316 */
2120
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
317 public FastCrossSectionLine searchCrossSectionLine() {
2678
d35e37b6a211 Fix issue620: synchron navigation at impossible km.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2153
diff changeset
318 double TOO_FAR = 1d;
2120
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
319 CrossSection crossSection = CrossSectionFactory
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
320 .getCrossSection(getDBID());
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
321
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7842
diff changeset
322 if (log.isDebugEnabled()) {
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7842
diff changeset
323 log.debug("dbid " + getDBID() + " : " + crossSection);
1967
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
324 }
2120
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
325
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
326 NavigableMap<Double, Integer> kms = CrossSectionKMService
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
327 .getKms(crossSection.getId());
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
328
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
329 Double wishKM = getKm();
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
330
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
331 Double floor = kms.floorKey(wishKM);
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
332 Double ceil = kms.ceilingKey(wishKM);
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
333
3272
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
334 Double nextKm;
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
335 Double prevKm;
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
336
2120
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
337 double floorD = floor != null
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
338 ? Math.abs(floor - wishKM)
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
339 : Double.MAX_VALUE;
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
340
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
341 double ceilD = ceil != null
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
342 ? Math.abs(ceil - wishKM)
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
343 : Double.MAX_VALUE;
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
344
3272
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
345 double km;
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
346 if (floorD < ceilD) {
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
347 km = floor;
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
348 }
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
349 else {
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
350 km = ceil;
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
351 }
2120
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
352
2678
d35e37b6a211 Fix issue620: synchron navigation at impossible km.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2153
diff changeset
353 // If we are too far from the wished km, return null.
d35e37b6a211 Fix issue620: synchron navigation at impossible km.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2153
diff changeset
354 if (Math.abs(km - wishKM) > TOO_FAR) {
d35e37b6a211 Fix issue620: synchron navigation at impossible km.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2153
diff changeset
355 return null;
d35e37b6a211 Fix issue620: synchron navigation at impossible km.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2153
diff changeset
356 }
d35e37b6a211 Fix issue620: synchron navigation at impossible km.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2153
diff changeset
357
3272
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
358 // Store next and previous km.
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
359 nextKm = kms.higherKey(km);
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
360 prevKm = kms.lowerKey(km);
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
361
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
362 if (prevKm == null) {
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
363 prevKm = -1d;
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
364 }
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
365 if (nextKm == null) {
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
366 nextKm = -1d;
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
367 }
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
368
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
369 addStringData(DATA_PREV_KM, prevKm.toString());
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
370 addStringData(DATA_NEXT_KM, nextKm.toString());
31168ac9c7e7 Partial fix for issue694 (heightmarks snap to nearest cross section).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2763
diff changeset
371
2120
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
372 return FastCrossSectionLineFactory
f021080cb409 Use improved caching for cross section lines data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2040
diff changeset
373 .getCrossSectionLine(crossSection, km);
1967
27bb2e24f7f8 Preparations for better CrossSection diagrams.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1964
diff changeset
374 }
1964
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
375 }
85e442933e6d New CrossSectionArtifact.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
376 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org