felix@2172: package de.intevation.flys.artifacts; felix@2172: felix@2172: import java.util.ArrayList; felix@2172: import java.util.List; felix@2172: felix@3198: import java.awt.geom.Point2D; felix@3198: felix@2172: import org.apache.log4j.Logger; felix@2172: felix@2172: import org.w3c.dom.Document; felix@2172: felix@3198: import org.json.JSONArray; felix@3198: import org.json.JSONException; felix@3198: felix@2172: import de.intevation.artifactdatabase.state.Facet; felix@2172: felix@2172: import de.intevation.artifacts.Artifact; felix@2172: import de.intevation.artifacts.ArtifactFactory; felix@2172: import de.intevation.artifacts.CallMeta; felix@2172: felix@2172: import de.intevation.flys.artifacts.model.FacetTypes; felix@2172: felix@2172: import de.intevation.flys.artifacts.states.DefaultState; felix@2172: felix@3198: import de.intevation.flys.model.FastCrossSectionLine; felix@3198: ingo@3227: import de.intevation.flys.artifacts.geom.Lines; felix@2172: felix@2172: felix@2172: /** felix@3225: * Artifact to store user-added points and water lines. felix@2172: */ felix@2172: public class ManualPointsArtifact felix@2172: extends StaticFLYSArtifact felix@3198: implements FacetTypes, WaterLineArtifact felix@2172: { felix@2172: /** The logger for this class. */ felix@2172: private static Logger logger = Logger.getLogger(ManualPointsArtifact.class); felix@2172: felix@2172: /** The name of the artifact. */ felix@2172: public static final String ARTIFACT_NAME = "manualpoints"; felix@2172: felix@2172: felix@2172: /** felix@2172: * Trivial Constructor. felix@2172: */ felix@2172: public ManualPointsArtifact() { felix@2206: logger.debug("ManualPointsArtifact.ManualPointsArtifact()"); felix@2172: } felix@2172: felix@2172: felix@2172: /** felix@2172: * Gets called from factory, to set things up. felix@2172: */ felix@2172: @Override felix@2172: public void setup( felix@2172: String identifier, felix@2172: ArtifactFactory factory, felix@2172: Object context, felix@2172: CallMeta callMeta, felix@2172: Document data) felix@2172: { felix@2172: logger.debug("ManualPointsArtifact.setup"); felix@2172: super.setup(identifier, factory, context, callMeta, data); felix@2172: initialize(null, context, callMeta); felix@2172: } felix@2172: felix@2172: felix@2172: /** Return the name of this artifact. */ felix@2172: public String getName() { felix@2172: return ARTIFACT_NAME; felix@2172: } felix@2172: felix@2172: felix@2172: /** Access state data storing the jsonstring with points. */ felix@2206: public String getPointsData(String facetName) { felix@2206: return getDataAsString(facetName + ".data"); felix@2172: } felix@2172: felix@2172: felix@3198: /** felix@3198: * Access state data storing the jsonstring with lines. felix@3198: * @param facetName Name of facet or null if the so far felix@3198: * only known case should be picked. felix@3198: * @return (String) value of data element (expect json). felix@3198: */ felix@3198: public String getLinesData(String facetName) { felix@3198: if (facetName == null) felix@3198: return getDataAsString("cross_section.manualpoints.lines"); felix@3198: // TODO .lineS? felix@3198: return getDataAsString(facetName + ".line"); felix@3198: } felix@3198: felix@3198: felix@2172: /** Setup state and facet. */ felix@2172: @Override felix@2172: protected void initialize(Artifact artifact, Object context, CallMeta meta) { felix@2172: logger.debug("ManualPointsArtifact.initialize"); felix@2172: List fs = new ArrayList(); felix@2172: felix@2172: DefaultState state = (DefaultState) getCurrentState(context); felix@2172: state.computeInit(this, hash(), context, meta, fs); sascha@3076: if (!fs.isEmpty()) { sascha@3076: logger.debug("Facets to add in ManualPointsArtifact.initialize ."); sascha@3076: facets.put(getCurrentStateId(), fs); sascha@3076: } sascha@3076: else { felix@2172: logger.debug("No facets to add in ManualPointsArtifact.initialize (" felix@2172: + state.getID() + ")."); felix@2172: } felix@2172: } felix@2172: felix@2172: felix@2172: /** felix@3198: * Get value of line at index. felix@3198: * @param index index in json array defining lines. felix@3198: * @return water height of line at given index. felix@3198: */ felix@3198: protected double getLine(int index) { felix@3198: try { felix@3198: JSONArray lines = new JSONArray((String) getLinesData(null)); felix@3198: JSONArray array = lines.getJSONArray(index); felix@3198: felix@3198: return array.getDouble(0); felix@3198: } felix@3198: catch(JSONException e){ felix@3198: logger.error("Could not decode json for line."); felix@3198: return 0d; felix@3198: } felix@3198: } felix@3198: felix@3198: felix@3198: /** felix@3198: * Get the water line "surface". felix@3198: */ felix@3198: @Override felix@3198: public Lines.LineData getWaterLines(int index, FastCrossSectionLine csl) { felix@3198: List points = csl.getPoints(); felix@3198: return Lines.createWaterLines(points, getLine(index)); felix@3198: } felix@3198: felix@3198: /** felix@2172: * Determines Facets initial disposition regarding activity (think of felix@2172: * selection in Client ThemeList GUI). This will be checked one time felix@2172: * when the facet enters a collections describe document. felix@2172: * felix@2172: * @param facetName name of the facet. felix@2172: * @param index index of the facet. felix@2172: * @return 0 if not active felix@2172: */ felix@2172: @Override felix@2172: public int getInitialFacetActivity( felix@2172: String outputName, felix@2172: String facetName, felix@2172: int index) felix@2172: { felix@2172: return 1; felix@2172: } felix@2172: } felix@2172: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :