felix@1825: package de.intevation.flys.artifacts; felix@1825: felix@5798: import java.awt.geom.Point2D; felix@5798: felix@1825: import java.util.ArrayList; felix@1825: import java.util.List; felix@1825: felix@1825: import org.apache.log4j.Logger; felix@1825: felix@1825: import org.w3c.dom.Document; felix@1825: felix@1825: import de.intevation.artifactdatabase.state.Facet; sascha@3556: import de.intevation.artifactdatabase.state.FacetActivity; felix@1825: felix@1825: import de.intevation.artifacts.Artifact; felix@1825: import de.intevation.artifacts.ArtifactFactory; felix@5798: import de.intevation.artifacts.CallContext; felix@1825: import de.intevation.artifacts.CallMeta; felix@1825: felix@2124: import de.intevation.artifacts.common.utils.XMLUtils; felix@2124: felix@5798: import de.intevation.flys.artifacts.geom.Lines; felix@5798: felix@1825: import de.intevation.flys.artifacts.model.FacetTypes; felix@5798: import de.intevation.flys.model.FastCrossSectionLine; felix@5798: import de.intevation.flys.artifacts.model.WKms; felix@1825: import de.intevation.flys.artifacts.model.WQKms; felix@1825: import de.intevation.flys.artifacts.model.WKmsFactory; felix@5798: import de.intevation.flys.artifacts.model.WQKmsFacet; felix@1825: import de.intevation.flys.artifacts.model.WQKmsFactory; felix@1825: felix@2124: import de.intevation.flys.artifacts.states.DefaultState; felix@1825: felix@1825: felix@1825: /** felix@1825: * Artifact to access additional "waterlevel/discharge"-type of data, like felix@1825: * fixation measurements. felix@1825: * felix@1825: * This artifact neglects (Static)FLYSArtifacts capabilities of interaction felix@1825: * with the StateEngine by overriding the getState*-methods. felix@1825: */ felix@1825: public class StaticWQKmsArtifact felix@1825: extends StaticFLYSArtifact felix@5798: implements FacetTypes, WaterLineArtifact felix@1825: { felix@1825: /** The logger for this class. */ felix@1825: private static Logger logger = felix@1825: Logger.getLogger(StaticWQKmsArtifact.class); felix@1825: felix@1825: public static final String STATIC_STATE_NAME = felix@1825: "state.additional_wqkms.static"; felix@1825: sascha@3556: private static final String NAME = "staticwqkms"; sascha@3556: sascha@3556: static { sascha@3556: // TODO: Move to configuration. sascha@3556: FacetActivity.Registry.getInstance() sascha@3556: .register(NAME, FacetActivity.INACTIVE); sascha@3556: } felix@1825: felix@1825: /** felix@1825: * Trivial Constructor. felix@1825: */ felix@1825: public StaticWQKmsArtifact() { felix@1825: logger.debug("StaticWQKmsArtifact.StaticWQKmsArtifact"); felix@1825: } felix@1825: felix@1825: felix@1825: /** felix@1825: * Gets called from factory, to set things up. felix@1825: */ felix@1825: @Override felix@1825: public void setup( felix@1825: String identifier, felix@1825: ArtifactFactory factory, felix@1825: Object context, felix@1825: CallMeta callMeta, felix@1825: Document data) felix@1825: { felix@1825: logger.debug("StaticWQKmsArtifact.setup"); felix@1825: felix@2124: // Store the 'ids' (from datacage). sascha@3405: if (logger.isDebugEnabled()) { sascha@3405: logger.debug("StaticWQKmsArtiact.setup" + XMLUtils.toString(data)); sascha@3405: } felix@1825: felix@2741: String code = getDatacageIDValue(data); felix@2124: addStringData("ids", code); felix@1825: if (code != null) { felix@1825: String [] parts = code.split("-"); felix@1825: felix@1825: if (parts.length >= 4) { sascha@3405: int col = Integer.parseInt(parts[2]); sascha@3405: int wst = Integer.parseInt(parts[3]); felix@1825: felix@1900: addStringData("col_pos", parts[2]); felix@1900: addStringData("wst_id", parts[3]); felix@1825: } felix@1825: } felix@1825: felix@2124: // Do this AFTER we have set the col_pos etc. felix@1825: super.setup(identifier, factory, context, callMeta, data); felix@1825: } felix@1825: felix@1825: felix@1825: /** felix@1825: * Called via setup. felix@1825: * felix@1825: * @param artifact The master-artifact. felix@1825: */ felix@1825: @Override felix@1825: protected void initialize( felix@1825: Artifact artifact, felix@1825: Object context, felix@1825: CallMeta meta) felix@1825: { felix@1825: logger.debug("StaticWQKmsArtifact.initialize"); felix@5798: FLYSArtifact flys = (FLYSArtifact) artifact; felix@2124: // TODO: The river is of no interest, so far., also use importData felix@5798: importData(flys, "river"); felix@1825: felix@2124: List fs = new ArrayList(); felix@1825: felix@2124: DefaultState state = (DefaultState) getCurrentState(context); felix@2124: state.computeInit(this, hash(), context, meta, fs); sascha@3076: if (!fs.isEmpty()) { sascha@3076: logger.debug("Facets to add in StaticWQKmsArtifact.initialize ."); bjoern@4497: addFacets(getCurrentStateId(), fs); sascha@3076: } sascha@3076: else { felix@2124: logger.debug("No facets to add in StaticWQKmsArtifact.initialize (" felix@2124: + state.getID() + ")."); felix@2124: } felix@1825: } felix@1825: felix@1825: felix@1825: /** felix@1825: * Get WQKms from factory. felix@1825: * @return WQKms according to parameterization (can be null); felix@1825: */ felix@2124: public WQKms getWQKms() { felix@1825: logger.debug("StaticWQKmsArtifact.getWQKms"); felix@1825: sascha@3405: int col = Integer.parseInt(getDataAsString("col_pos")); sascha@3405: int wst = Integer.parseInt(getDataAsString("wst_id")); felix@2124: felix@2124: /** TODO do not run twice against db to do this. */ felix@2124: String wkmsName = WKmsFactory.getWKmsName(col, wst); felix@2124: sascha@3405: WQKms res = WQKmsFactory.getWQKms(col, wst); felix@2124: res.setName(wkmsName); felix@2124: return res; felix@1825: } felix@1825: sascha@3556: /** Return specific name. */ felix@1825: @Override felix@2124: public String getName() { sascha@3556: return NAME; felix@2124: } felix@2124: felix@5798: felix@5798: /** felix@5798: * Get points of line describing the surface of water at cross section. felix@5798: * felix@5798: * @param idx Index of facet and in wkms array. felix@5798: * @param csl FastCrossSectionLine to compute water surface agains. felix@5798: * @param next The km of the next crosssectionline. felix@5798: * @param prev The km of the previous crosssectionline. felix@5798: * @param context Ignored in this implementation. felix@5798: * felix@5798: * @return an array holding coordinates of points of surface of water ( felix@5798: * in the form {{x1, x2}, {y1, y2}} ). felix@5798: */ felix@5798: @Override felix@5798: public Lines.LineData getWaterLines(int idx, FastCrossSectionLine csl, felix@5798: double next, double prev, CallContext context felix@5798: ) { felix@5798: logger.debug("getWaterLines(" + idx + ")/" + identifier()); felix@5798: felix@5798: List points = csl.getPoints(); felix@5798: felix@5798: WKms wkms = getWQKms(); felix@5798: felix@5798: double km = csl.getKm(); felix@5798: felix@5798: // Find W at km. felix@5798: double wAtKm; felix@5798: felix@5798: // If heightmarks, only deliver if data snaps. felix@5798: /* felix@5798: if (getDataAsString(DATA_HEIGHT_TYPE) != null && felix@5798: getDataAsString(DATA_HEIGHT_TYPE).equals("true")) { felix@5798: wAtKm = getWAtCloseKm(wkms, km, next, prev); felix@5798: } felix@5798: else { felix@5798: */ felix@5798: wAtKm = StaticWKmsArtifact.getWAtKm(wkms, km); felix@5798: //} felix@5798: felix@5798: if (wAtKm == -1 || Double.isNaN(wAtKm)) { felix@5798: logger.warn("Waterlevel at km " + km + " unknown."); felix@5798: return new Lines.LineData(new double[][] {{}}, 0d, 0d); felix@5798: } felix@5798: felix@5798: return Lines.createWaterLines(points, wAtKm); felix@5798: } felix@2124: // TODO implement deepCopy. felix@1825: } felix@1825: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :