Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/org/dive4elements/river/artifacts/StaticWQKmsArtifact.java @ 5831:bd047b71ab37
Repaired internal references
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:06:39 +0200 |
parents | flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWQKmsArtifact.java@948be49754c5 |
children |
comparison
equal
deleted
inserted
replaced
5830:160f53ee0870 | 5831:bd047b71ab37 |
---|---|
1 package org.dive4elements.river.artifacts; | |
2 | |
3 import java.awt.geom.Point2D; | |
4 | |
5 import java.util.ArrayList; | |
6 import java.util.List; | |
7 | |
8 import org.apache.log4j.Logger; | |
9 | |
10 import org.w3c.dom.Document; | |
11 | |
12 import org.dive4elements.artifactdatabase.state.Facet; | |
13 import org.dive4elements.artifactdatabase.state.FacetActivity; | |
14 | |
15 import org.dive4elements.artifacts.Artifact; | |
16 import org.dive4elements.artifacts.ArtifactFactory; | |
17 import org.dive4elements.artifacts.CallContext; | |
18 import org.dive4elements.artifacts.CallMeta; | |
19 | |
20 import org.dive4elements.artifacts.common.utils.XMLUtils; | |
21 | |
22 import org.dive4elements.river.artifacts.geom.Lines; | |
23 | |
24 import org.dive4elements.river.artifacts.model.FacetTypes; | |
25 import org.dive4elements.river.model.FastCrossSectionLine; | |
26 import org.dive4elements.river.artifacts.model.WKms; | |
27 import org.dive4elements.river.artifacts.model.WQKms; | |
28 import org.dive4elements.river.artifacts.model.WKmsFactory; | |
29 import org.dive4elements.river.artifacts.model.WQKmsFacet; | |
30 import org.dive4elements.river.artifacts.model.WQKmsFactory; | |
31 | |
32 import org.dive4elements.river.artifacts.states.DefaultState; | |
33 | |
34 | |
35 /** | |
36 * Artifact to access additional "waterlevel/discharge"-type of data, like | |
37 * fixation measurements. | |
38 * | |
39 * This artifact neglects (Static)FLYSArtifacts capabilities of interaction | |
40 * with the StateEngine by overriding the getState*-methods. | |
41 */ | |
42 public class StaticWQKmsArtifact | |
43 extends StaticFLYSArtifact | |
44 implements FacetTypes, WaterLineArtifact | |
45 { | |
46 /** The logger for this class. */ | |
47 private static Logger logger = | |
48 Logger.getLogger(StaticWQKmsArtifact.class); | |
49 | |
50 public static final String STATIC_STATE_NAME = | |
51 "state.additional_wqkms.static"; | |
52 | |
53 private static final String NAME = "staticwqkms"; | |
54 | |
55 static { | |
56 // TODO: Move to configuration. | |
57 FacetActivity.Registry.getInstance() | |
58 .register(NAME, FacetActivity.INACTIVE); | |
59 } | |
60 | |
61 /** | |
62 * Trivial Constructor. | |
63 */ | |
64 public StaticWQKmsArtifact() { | |
65 logger.debug("StaticWQKmsArtifact.StaticWQKmsArtifact"); | |
66 } | |
67 | |
68 | |
69 /** | |
70 * Gets called from factory, to set things up. | |
71 */ | |
72 @Override | |
73 public void setup( | |
74 String identifier, | |
75 ArtifactFactory factory, | |
76 Object context, | |
77 CallMeta callMeta, | |
78 Document data) | |
79 { | |
80 logger.debug("StaticWQKmsArtifact.setup"); | |
81 | |
82 // Store the 'ids' (from datacage). | |
83 if (logger.isDebugEnabled()) { | |
84 logger.debug("StaticWQKmsArtiact.setup" + XMLUtils.toString(data)); | |
85 } | |
86 | |
87 String code = getDatacageIDValue(data); | |
88 addStringData("ids", code); | |
89 if (code != null) { | |
90 String [] parts = code.split("-"); | |
91 | |
92 if (parts.length >= 4) { | |
93 int col = Integer.parseInt(parts[2]); | |
94 int wst = Integer.parseInt(parts[3]); | |
95 | |
96 addStringData("col_pos", parts[2]); | |
97 addStringData("wst_id", parts[3]); | |
98 } | |
99 } | |
100 | |
101 // Do this AFTER we have set the col_pos etc. | |
102 super.setup(identifier, factory, context, callMeta, data); | |
103 } | |
104 | |
105 | |
106 /** | |
107 * Called via setup. | |
108 * | |
109 * @param artifact The master-artifact. | |
110 */ | |
111 @Override | |
112 protected void initialize( | |
113 Artifact artifact, | |
114 Object context, | |
115 CallMeta meta) | |
116 { | |
117 logger.debug("StaticWQKmsArtifact.initialize"); | |
118 FLYSArtifact flys = (FLYSArtifact) artifact; | |
119 // TODO: The river is of no interest, so far., also use importData | |
120 importData(flys, "river"); | |
121 | |
122 List<Facet> fs = new ArrayList<Facet>(); | |
123 | |
124 DefaultState state = (DefaultState) getCurrentState(context); | |
125 state.computeInit(this, hash(), context, meta, fs); | |
126 if (!fs.isEmpty()) { | |
127 logger.debug("Facets to add in StaticWQKmsArtifact.initialize ."); | |
128 addFacets(getCurrentStateId(), fs); | |
129 } | |
130 else { | |
131 logger.debug("No facets to add in StaticWQKmsArtifact.initialize (" | |
132 + state.getID() + ")."); | |
133 } | |
134 } | |
135 | |
136 | |
137 /** | |
138 * Get WQKms from factory. | |
139 * @return WQKms according to parameterization (can be null); | |
140 */ | |
141 public WQKms getWQKms() { | |
142 logger.debug("StaticWQKmsArtifact.getWQKms"); | |
143 | |
144 int col = Integer.parseInt(getDataAsString("col_pos")); | |
145 int wst = Integer.parseInt(getDataAsString("wst_id")); | |
146 | |
147 /** TODO do not run twice against db to do this. */ | |
148 String wkmsName = WKmsFactory.getWKmsName(col, wst); | |
149 | |
150 WQKms res = WQKmsFactory.getWQKms(col, wst); | |
151 res.setName(wkmsName); | |
152 return res; | |
153 } | |
154 | |
155 /** Return specific name. */ | |
156 @Override | |
157 public String getName() { | |
158 return NAME; | |
159 } | |
160 | |
161 | |
162 /** | |
163 * Get points of line describing the surface of water at cross section. | |
164 * | |
165 * @param idx Index of facet and in wkms array. | |
166 * @param csl FastCrossSectionLine to compute water surface agains. | |
167 * @param next The km of the next crosssectionline. | |
168 * @param prev The km of the previous crosssectionline. | |
169 * @param context Ignored in this implementation. | |
170 * | |
171 * @return an array holding coordinates of points of surface of water ( | |
172 * in the form {{x1, x2}, {y1, y2}} ). | |
173 */ | |
174 @Override | |
175 public Lines.LineData getWaterLines(int idx, FastCrossSectionLine csl, | |
176 double next, double prev, CallContext context | |
177 ) { | |
178 logger.debug("getWaterLines(" + idx + ")/" + identifier()); | |
179 | |
180 List<Point2D> points = csl.getPoints(); | |
181 | |
182 WKms wkms = getWQKms(); | |
183 | |
184 double km = csl.getKm(); | |
185 | |
186 // Find W at km. | |
187 double wAtKm; | |
188 | |
189 // If heightmarks, only deliver if data snaps. | |
190 /* | |
191 if (getDataAsString(DATA_HEIGHT_TYPE) != null && | |
192 getDataAsString(DATA_HEIGHT_TYPE).equals("true")) { | |
193 wAtKm = getWAtCloseKm(wkms, km, next, prev); | |
194 } | |
195 else { | |
196 */ | |
197 wAtKm = StaticWKmsArtifact.getWAtKm(wkms, km); | |
198 //} | |
199 | |
200 if (wAtKm == -1 || Double.isNaN(wAtKm)) { | |
201 logger.warn("Waterlevel at km " + km + " unknown."); | |
202 return new Lines.LineData(new double[][] {{}}, 0d, 0d); | |
203 } | |
204 | |
205 return Lines.createWaterLines(points, wAtKm); | |
206 } | |
207 // TODO implement deepCopy. | |
208 } | |
209 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |