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.minfo; raimund@3614: rrenkert@7984: import gnu.trove.TDoubleArrayList; rrenkert@7984: rrenkert@7984: import java.util.List; rrenkert@7984: rrenkert@7984: import org.apache.log4j.Logger; teichmann@5831: import org.dive4elements.artifacts.Artifact; teichmann@5831: import org.dive4elements.artifacts.CallContext; teichmann@5867: import org.dive4elements.river.artifacts.D4EArtifact; teichmann@5831: import org.dive4elements.river.artifacts.access.BedHeightAccess; teichmann@5831: import org.dive4elements.river.artifacts.model.BlackboardDataFacet; teichmann@5831: import org.dive4elements.river.artifacts.model.FacetTypes; tom@8559: import org.dive4elements.river.model.BedHeight; tom@8559: import org.dive4elements.river.model.BedHeightValue; raimund@3614: raimund@3614: public class BedHeightFacet raimund@3614: extends BlackboardDataFacet raimund@3614: implements FacetTypes { raimund@3614: teichmann@8202: private static final Logger log = Logger.getLogger(BedHeightFacet.class); rrenkert@7984: bjoern@4534: private String type; sascha@3633: bjoern@4534: public BedHeightFacet(String name, String description, String type) { raimund@3614: this.name = name; raimund@3614: this.description = description; bjoern@4534: this.type = type; raimund@3614: this.index = 0; rrenkert@7894: this.metaData.put("X", "chart.longitudinal.section.xaxis.label"); tom@8267: this.metaData.put("Y", "chart.bedheight_middle.section.yaxis.label"); raimund@3614: } raimund@3614: raimund@3614: /** raimund@3614: * Returns the data this facet requires. raimund@3614: * raimund@3614: * @param artifact the owner artifact. raimund@3614: * @param context the CallContext (ignored). raimund@3614: * raimund@3614: * @return the data. raimund@3614: */ raimund@3614: @Override raimund@3614: public Object getData(Artifact artifact, CallContext context) { teichmann@6101: BedHeightAccess access = new BedHeightAccess((D4EArtifact)artifact); bjoern@4534: if (type.equals("singlevalues")) { felix@7357: /* Former doc (from BedHeightAccess): tom@8559: * Return a {@link List} of {@link BedHeightValue}s felix@7357: * at the range of the artifact tom@8559: * @return List of {@link BedHeightValue}s */ tom@8559: BedHeight single = BedHeight.getBedHeightById( felix@7357: access.getHeightId()); tom@8559: List bedheightValues = tom@8559: BedHeightValue.getBedHeightValues( rrenkert@7984: single, andre@8648: access.getFrom(true), andre@8648: access.getTo(true)); rrenkert@7984: double[][] values = new double[2][bedheightValues.size()]; rrenkert@7984: int i = 0; tom@8559: for (BedHeightValue bedheightValue : bedheightValues) { rrenkert@7984: values[0][i] = bedheightValue.getStation(); rrenkert@7984: values[1][i] = bedheightValue.getHeight(); rrenkert@7984: i++; rrenkert@7984: } rrenkert@7984: return values; bjoern@4534: } felix@7357: else { felix@7357: /* Former doc (from BedHeightAccess): felix@7357: * Return the {@link BedHeight} at the height_id and time of the artifact felix@7391: * @return {@link BedHeight} */ rrenkert@7984: BedHeightData data = BedHeightFactory.getHeight( felix@7357: access.getType(), tom@8151: access.getHeightId()); rrenkert@7984: //data.removeNaNs(); rrenkert@7984: TDoubleArrayList stations= data.getStations(); rrenkert@7984: double[][] values = new double[2][stations.size()]; rrenkert@7984: for (int i = 0; i < stations.size(); i++) { rrenkert@7984: values[0][i] = stations.get(i); rrenkert@7984: values[1][i] = data.getHeight(i); rrenkert@7984: } rrenkert@7984: return values; felix@7357: } raimund@3614: } felix@7357: raimund@3614: /** raimund@3614: * Create a deep copy of this Facet. raimund@3614: * @return a deep copy. raimund@3614: */ raimund@3614: @Override raimund@3614: public BedHeightFacet deepCopy() { bjoern@4534: BedHeightFacet copy = new BedHeightFacet(name, description, type); raimund@3614: copy.set(this); raimund@3614: return copy; raimund@3614: } raimund@3614: } raimund@3614: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :