teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5863: * Software engineering by Intevation GmbH teichmann@5863: * teichmann@5994: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5994: * documentation coming with Dive4Elements River for details. teichmann@5863: */ teichmann@5863: teichmann@5831: package org.dive4elements.river.artifacts.model; felix@1122: felix@1122: import org.apache.log4j.Logger; felix@1122: felix@1975: import java.util.List; felix@1975: teichmann@5831: import org.dive4elements.artifacts.Artifact; teichmann@5831: import org.dive4elements.artifacts.CallContext; teichmann@5831: import org.dive4elements.artifacts.DataProvider; felix@1122: teichmann@5831: import org.dive4elements.artifactdatabase.state.Facet; felix@1122: teichmann@5831: import org.dive4elements.river.artifacts.WaterLineArtifact; felix@1122: teichmann@5831: import org.dive4elements.river.model.FastCrossSectionLine; felix@1122: teichmann@5831: import org.dive4elements.river.artifacts.geom.Lines; felix@2652: felix@3225: felix@1122: /** felix@1122: * Facet for Waterlines in Cross Sections. felix@1122: */ felix@1122: public class CrossSectionWaterLineFacet felix@2028: extends BlackboardDataFacet felix@1122: implements FacetTypes { felix@1122: teichmann@8202: /** Private log to use. */ teichmann@8202: private static Logger log = felix@3272: Logger.getLogger(CrossSectionWaterLineFacet.class); felix@1122: felix@1122: felix@1122: /** Trivial constructor, set (maybe localized) description. */ felix@1802: public CrossSectionWaterLineFacet(int idx, String description) { felix@1802: super(idx, CROSS_SECTION_WATER_LINE, description); felix@1122: } felix@1122: felix@1122: felix@3272: /** felix@3272: * Trivial constructor, set (maybe localized) description. felix@3272: * @param idx Index of this facet. felix@3272: * @param name 'type' of this facet. felix@3272: * @param description (maybe) localized user-visible description. felix@3272: */ felix@3198: public CrossSectionWaterLineFacet(int idx, String name, String description) { felix@3198: super(idx, name, description); felix@3198: } felix@3198: felix@3198: felix@1122: /** felix@1975: * Gets waterline (crossed with cross section) of waterlevel. felix@1122: */ felix@1122: public Object getData(Artifact artifact, CallContext context) { teichmann@8202: log.debug("Get data for cross section water line"); felix@1122: felix@1975: List providers = context. felix@1975: getDataProvider(CrossSectionFacet.BLACKBOARD_CS_MASTER_DATA); felix@1975: if (providers.size() < 1) { teichmann@8202: log.warn("Could not find Cross-Section data provider."); felix@2673: return new Lines.LineData(new double[][] {}, 0d, 0d); felix@1975: } sascha@3076: felix@1975: Object crossSection = providers.get(0) felix@3272: .provideData(CrossSectionFacet.BLACKBOARD_CS_MASTER_DATA, felix@3272: null, context); felix@3272: Object nextKm = providers.get(0). felix@3272: provideData(CrossSectionFacet.BLACKBOARD_CS_NEXT_KM, null, context); felix@3272: Object prevKm = providers.get(0). felix@3272: provideData(CrossSectionFacet.BLACKBOARD_CS_PREV_KM, null, context); felix@3272: if (prevKm == null) felix@3272: prevKm = new Double(-1d); felix@3272: if (nextKm == null) felix@3272: nextKm = new Double(-1d); felix@1975: felix@4506: if (!(artifact instanceof WaterLineArtifact)) { teichmann@8202: log.error("CrossSectionWaterLineFacet needs WaterLineArtifact"); felix@4506: return new Lines.LineData(new double[][] {}, 0d,0d); felix@4506: } felix@3272: WaterLineArtifact lineArtifact = (WaterLineArtifact) artifact; felix@1122: felix@2676: if (crossSection != null) { felix@3272: return lineArtifact.getWaterLines(this.getIndex(), felix@4478: (FastCrossSectionLine) crossSection, (Double) nextKm, felix@4478: (Double) prevKm, context); felix@2676: } felix@2676: else { felix@2676: return new Lines.LineData(new double[][] {}, 0d,0d); felix@2676: } felix@1122: } felix@1122: felix@1136: felix@1136: /** Do a deep copy. */ sascha@3076: @Override felix@1122: public Facet deepCopy() { felix@1975: CrossSectionWaterLineFacet copy = new CrossSectionWaterLineFacet( felix@1975: this.getIndex(), felix@1975: this.description); felix@1122: copy.set(this); felix@1122: return copy; felix@1122: } felix@1122: } felix@1122: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :