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