felix@1122: package de.intevation.flys.artifacts.model;
felix@1122: 
felix@1122: import org.apache.log4j.Logger;
felix@1122: 
felix@1975: import java.util.List;
felix@1975: 
felix@1122: import de.intevation.artifacts.Artifact;
felix@1122: import de.intevation.artifacts.CallContext;
felix@2141: import de.intevation.artifacts.DataProvider;
felix@1122: 
felix@1122: import de.intevation.artifactdatabase.state.Facet;
felix@1122: 
felix@1981: import de.intevation.flys.artifacts.WaterLineArtifact;
felix@1122: 
sascha@2126: import de.intevation.flys.model.FastCrossSectionLine;
felix@1122: 
ingo@3227: import de.intevation.flys.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: 
felix@3272:     /** Private logger to use. */
felix@3272:     private static Logger logger =
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) {
felix@1122:         logger.debug("Get data for cross section water line");
felix@1122: 
felix@1975:         List<DataProvider> providers = context.
felix@1975:             getDataProvider(CrossSectionFacet.BLACKBOARD_CS_MASTER_DATA);
felix@1975:         if (providers.size() < 1) {
felix@1975:             logger.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@3272:         WaterLineArtifact lineArtifact = (WaterLineArtifact) artifact;
felix@1122: 
felix@2676:         if (crossSection != null) {
felix@3272:             return lineArtifact.getWaterLines(this.getIndex(),
felix@3272:                 (FastCrossSectionLine) crossSection, (Double) nextKm, (Double) prevKm);
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 :