Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/ManualPointsArtifact.java @ 3318:dbe2f85bf160
merged flys-artifacts/2.8
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:35 +0200 |
parents | d9af29a4bb85 |
children | afc7bfb4800b |
comparison
equal
deleted
inserted
replaced
2987:98c7a46ec5ae | 3318:dbe2f85bf160 |
---|---|
1 package de.intevation.flys.artifacts; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.List; | |
5 | |
6 import java.awt.geom.Point2D; | |
7 | |
8 import org.apache.log4j.Logger; | |
9 | |
10 import org.w3c.dom.Document; | |
11 | |
12 import org.json.JSONArray; | |
13 import org.json.JSONException; | |
14 | |
15 import de.intevation.artifactdatabase.state.Facet; | |
16 | |
17 import de.intevation.artifacts.Artifact; | |
18 import de.intevation.artifacts.ArtifactFactory; | |
19 import de.intevation.artifacts.CallMeta; | |
20 | |
21 import de.intevation.flys.artifacts.model.FacetTypes; | |
22 | |
23 import de.intevation.flys.artifacts.states.DefaultState; | |
24 | |
25 import de.intevation.flys.model.FastCrossSectionLine; | |
26 | |
27 import de.intevation.flys.artifacts.geom.Lines; | |
28 | |
29 | |
30 /** | |
31 * Artifact to store user-added points and water lines. | |
32 */ | |
33 public class ManualPointsArtifact | |
34 extends StaticFLYSArtifact | |
35 implements FacetTypes, WaterLineArtifact | |
36 { | |
37 /** The logger for this class. */ | |
38 private static Logger logger = Logger.getLogger(ManualPointsArtifact.class); | |
39 | |
40 /** The name of the artifact. */ | |
41 public static final String ARTIFACT_NAME = "manualpoints"; | |
42 | |
43 | |
44 /** | |
45 * Trivial Constructor. | |
46 */ | |
47 public ManualPointsArtifact() { | |
48 logger.debug("ManualPointsArtifact.ManualPointsArtifact()"); | |
49 } | |
50 | |
51 | |
52 /** | |
53 * Gets called from factory, to set things up. | |
54 */ | |
55 @Override | |
56 public void setup( | |
57 String identifier, | |
58 ArtifactFactory factory, | |
59 Object context, | |
60 CallMeta callMeta, | |
61 Document data) | |
62 { | |
63 logger.debug("ManualPointsArtifact.setup"); | |
64 super.setup(identifier, factory, context, callMeta, data); | |
65 initialize(null, context, callMeta); | |
66 } | |
67 | |
68 | |
69 /** Return the name of this artifact. */ | |
70 public String getName() { | |
71 return ARTIFACT_NAME; | |
72 } | |
73 | |
74 | |
75 /** Access state data storing the jsonstring with points. */ | |
76 public String getPointsData(String facetName) { | |
77 return getDataAsString(facetName + ".data"); | |
78 } | |
79 | |
80 | |
81 /** | |
82 * Access state data storing the jsonstring with lines. | |
83 * @param facetName Name of facet or null if the so far | |
84 * only known case should be picked. | |
85 * @return (String) value of data element (expect json). | |
86 */ | |
87 public String getLinesData(String facetName) { | |
88 if (facetName == null) | |
89 return getDataAsString("cross_section.manualpoints.lines"); | |
90 // TODO .lineS? | |
91 return getDataAsString(facetName + ".line"); | |
92 } | |
93 | |
94 | |
95 /** Setup state and facet. */ | |
96 @Override | |
97 protected void initialize(Artifact artifact, Object context, CallMeta meta) { | |
98 logger.debug("ManualPointsArtifact.initialize"); | |
99 List<Facet> fs = new ArrayList<Facet>(); | |
100 | |
101 DefaultState state = (DefaultState) getCurrentState(context); | |
102 state.computeInit(this, hash(), context, meta, fs); | |
103 if (!fs.isEmpty()) { | |
104 logger.debug("Facets to add in ManualPointsArtifact.initialize ."); | |
105 facets.put(getCurrentStateId(), fs); | |
106 } | |
107 else { | |
108 logger.debug("No facets to add in ManualPointsArtifact.initialize (" | |
109 + state.getID() + ")."); | |
110 } | |
111 } | |
112 | |
113 | |
114 /** | |
115 * Get value of line at index. | |
116 * @param index index in json array defining lines. | |
117 * @return water height of line at given index. | |
118 */ | |
119 protected double getLine(int index) { | |
120 try { | |
121 JSONArray lines = new JSONArray((String) getLinesData(null)); | |
122 JSONArray array = lines.getJSONArray(index); | |
123 | |
124 return array.getDouble(0); | |
125 } | |
126 catch(JSONException e){ | |
127 logger.error("Could not decode json for line."); | |
128 return 0d; | |
129 } | |
130 } | |
131 | |
132 | |
133 /** | |
134 * Get the water line "surface". | |
135 * @param index index of facets data. | |
136 * @param csl 'ground' against which to determine water surface. | |
137 * @param a (ignored in this implementation). | |
138 * @param b (ignored in this implementation). | |
139 */ | |
140 @Override | |
141 public Lines.LineData getWaterLines( | |
142 int index, | |
143 FastCrossSectionLine csl, | |
144 double a, double b | |
145 ) { | |
146 List<Point2D> points = csl.getPoints(); | |
147 return Lines.createWaterLines(points, getLine(index)); | |
148 } | |
149 | |
150 /** | |
151 * Determines Facets initial disposition regarding activity (think of | |
152 * selection in Client ThemeList GUI). This will be checked one time | |
153 * when the facet enters a collections describe document. | |
154 * | |
155 * @param facetName name of the facet. | |
156 * @param index index of the facet. | |
157 * @return 0 if not active | |
158 */ | |
159 @Override | |
160 public int getInitialFacetActivity( | |
161 String outputName, | |
162 String facetName, | |
163 int index) | |
164 { | |
165 return 1; | |
166 } | |
167 } | |
168 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |