comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java @ 1981:bf62cc7052d4

Implement and use WaterLineArtifact interface. flys-artifacts/trunk@3411 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 14 Dec 2011 10:44:00 +0000
parents a7e030efd50e
children 701658081f4f
comparison
equal deleted inserted replaced
1980:d377b89d2827 1981:bf62cc7052d4
4 import java.util.List; 4 import java.util.List;
5 5
6 import org.apache.log4j.Logger; 6 import org.apache.log4j.Logger;
7 7
8 import org.w3c.dom.Document; 8 import org.w3c.dom.Document;
9
10 import java.awt.geom.Point2D;
9 11
10 import de.intevation.artifactdatabase.state.Facet; 12 import de.intevation.artifactdatabase.state.Facet;
11 import de.intevation.artifactdatabase.state.DefaultOutput; 13 import de.intevation.artifactdatabase.state.DefaultOutput;
12 import de.intevation.artifactdatabase.state.State; 14 import de.intevation.artifactdatabase.state.State;
13 15
14 import de.intevation.artifacts.Artifact; 16 import de.intevation.artifacts.Artifact;
15 import de.intevation.artifacts.ArtifactFactory; 17 import de.intevation.artifacts.ArtifactFactory;
16 import de.intevation.artifacts.ArtifactNamespaceContext; 18 import de.intevation.artifacts.ArtifactNamespaceContext;
17 import de.intevation.artifacts.CallMeta; 19 import de.intevation.artifacts.CallMeta;
18 20
21 import de.intevation.flys.artifacts.model.CrossSectionWaterLineFacet;
19 import de.intevation.flys.artifacts.model.FacetTypes; 22 import de.intevation.flys.artifacts.model.FacetTypes;
20 import de.intevation.flys.artifacts.model.WKms; 23 import de.intevation.flys.artifacts.model.WKms;
21 import de.intevation.flys.artifacts.model.WKmsFacet; 24 import de.intevation.flys.artifacts.model.WKmsFacet;
22 import de.intevation.flys.artifacts.model.WKmsFactory; 25 import de.intevation.flys.artifacts.model.WKmsFactory;
23 26
24 import de.intevation.flys.artifacts.states.StaticState; 27 import de.intevation.flys.artifacts.states.StaticState;
25 import de.intevation.flys.artifacts.resources.Resources; 28 import de.intevation.flys.artifacts.resources.Resources;
26 29
27 import de.intevation.artifacts.common.utils.XMLUtils; 30 import de.intevation.artifacts.common.utils.XMLUtils;
31
32 import de.intevation.flys.geom.Lines;
33 import de.intevation.flys.model.CrossSectionLine;
28 34
29 /** 35 /**
30 * Artifact to access additional "waterlevel"-type of data, like the height 36 * Artifact to access additional "waterlevel"-type of data, like the height
31 * of protective measures (dikes). 37 * of protective measures (dikes).
32 * 38 *
33 * This artifact neglects (Static)FLYSArtifacts capabilities of interaction 39 * This artifact neglects (Static)FLYSArtifacts capabilities of interaction
34 * with the StateEngine by overriding the getState*-methods. 40 * with the StateEngine by overriding the getState*-methods.
35 */ 41 */
36 public class StaticWKmsArtifact 42 public class StaticWKmsArtifact
37 extends StaticFLYSArtifact 43 extends StaticFLYSArtifact
38 implements FacetTypes 44 implements FacetTypes, WaterLineArtifact
39 { 45 {
40 /** The logger for this class. */ 46 /** The logger for this class. */
41 private static Logger logger = 47 private static Logger logger =
42 Logger.getLogger(StaticWKmsArtifact.class); 48 Logger.getLogger(StaticWKmsArtifact.class);
43 49
84 //ex.: flood_protection-wstv-114-12 90 //ex.: flood_protection-wstv-114-12
85 if (code != null) { 91 if (code != null) {
86 String [] parts = code.split("-"); 92 String [] parts = code.split("-");
87 93
88 if (parts.length >= 4) { 94 if (parts.length >= 4) {
89 int col = Integer.valueOf(parts[2]); 95 int col = -1;
90 int wst = Integer.valueOf(parts[3]); 96 int wst = Integer.valueOf(parts[3]);
97
98 if (!parts[2].equals("A")) {
99 col = Integer.valueOf(parts[2]);
100 }
91 101
92 addStringData("col_pos", parts[2]); 102 addStringData("col_pos", parts[2]);
93 addStringData("wst_id", parts[3]); 103 addStringData("wst_id", parts[3]);
94 104
95 String wkmsName = WKmsFactory.getWKmsName(col, wst); 105 String wkmsName;
106 if (col > 0) {
107 wkmsName = WKmsFactory.getWKmsName(col, wst);
108 }
109 else {
110 wkmsName = WKmsFactory.getWKmsName(wst);
111 }
96 112
97 String name; 113 String name;
98 if (parts[0].equals(HEIGHTMARKS_POINTS)) { 114 if (parts[0].equals(HEIGHTMARKS_POINTS)) {
99 name = HEIGHTMARKS_POINTS; 115 name = HEIGHTMARKS_POINTS;
100 } 116 }
101 else { 117 else {
102 name = STATIC_WKMS; 118 name = STATIC_WKMS;
103 } 119 }
104 120
105 Facet facet = new WKmsFacet( 121 String facetDescription = Resources.getMsg(
122 callMeta, wkmsName, wkmsName);
123 Facet wKmsFacet = new WKmsFacet(
106 name, 124 name,
107 Resources.getMsg( 125 facetDescription);
108 callMeta, 126 Facet csFacet = new CrossSectionWaterLineFacet(0,
109 wkmsName, 127 facetDescription);
110 wkmsName)); 128 fs.add(wKmsFacet);
111 fs.add(facet); 129 fs.add(csFacet);
112 facets.put(state.getID(), fs); 130 facets.put(state.getID(), fs);
113 } 131 }
114 } 132 }
115 133
116 spawnState(); 134 spawnState();
214 Integer.valueOf(getDataAsString("wst_id"))); 232 Integer.valueOf(getDataAsString("wst_id")));
215 } 233 }
216 234
217 235
218 /** 236 /**
237 * Returns W at Km of WKms, searching linearly.
238 * Returns -1 if not found.
239 */
240 public double getWAtKm(WKms wkms, double km) {
241 // Uninformed search.
242 int size = wkms.size();
243 for (int i = 0; i < size; i++) {
244 if (wkms.getKm(i) == km) {
245 return wkms.getW(i);
246 }
247 }
248
249 return -1;
250 }
251
252
253 /**
254 * Get points of line describing the surface of water at cross section.
255 *
256 * @return an array holding coordinates of points of surface of water (
257 * in the form {{x1, x2} {y1, y2}} ).
258 */
259 public double [][] getWaterLines(int idx, CrossSectionLine csl) {
260 logger.debug("getWaterLines(" + idx + ")");
261
262 List<Point2D> points = csl.fetchCrossSectionLinesPoints();
263
264 WKms wkms = getWKms(0);
265
266 double km = csl.getKm().doubleValue();
267
268 // Find W at km.
269 double wAtKm = getWAtKm(wkms, km);
270 if (wAtKm == -1) {
271 logger.warn("Waterlevel at km " + km + " unknown.");
272 return new double[][] {{}};
273 }
274
275 return Lines.createWaterLines(points, wAtKm);
276 }
277
278
279 /**
219 * Determines Facets initial disposition regarding activity (think of 280 * Determines Facets initial disposition regarding activity (think of
220 * selection in Client ThemeList GUI). This will be checked one time 281 * selection in Client ThemeList GUI). This will be checked one time
221 * when the facet enters a collections describe document. 282 * when the facet enters a collections describe document.
222 * 283 *
223 * @param facetName name of the facet. 284 * @param facetName name of the facet.

http://dive4elements.wald.intevation.org