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