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@2001:
felix@2001: import java.util.List;
felix@2001:
felix@2001: import org.apache.log4j.Logger;
felix@2001:
teichmann@5831: import org.dive4elements.artifacts.Artifact;
teichmann@5831: import org.dive4elements.artifacts.CallContext;
felix@2001:
teichmann@5831: import org.dive4elements.artifactdatabase.state.DefaultFacet;
teichmann@5831: import org.dive4elements.artifactdatabase.state.Facet;
felix@2001:
teichmann@5831: import org.dive4elements.artifacts.DataProvider;
felix@2001:
teichmann@5831: import org.dive4elements.river.artifacts.AreaArtifact;
felix@2001:
felix@2001:
felix@2001: /**
felix@2001: * Trival Facet for areas.
felix@2018: * Note that this Facet comes in two "types" (names):
felix@2018: *
felix@2018: * - CROSS_SECTION_AREA (cross_section.area) and
felix@2018: * - LONGITUDINAL_SECTION_AREA (longitudinal.area
felix@2018: *
felix@2018: * This is to support different diagram types without being painted in both
felix@2018: * at the same time. The name has to be given when constructing.
felix@2001: */
felix@2001: public class AreaFacet
felix@2001: extends DefaultFacet
sascha@3774: {
felix@2001: private static Logger logger = Logger.getLogger(AreaFacet.class);
felix@2001:
felix@2018: /**
felix@2018: * Constructor, set (maybe localized) description and name.
felix@2018: * @param idx Index given when querying artifact for data.
felix@2018: * @param name important to discern areas in different diagram types.
felix@2018: */
felix@2018: public AreaFacet(int idx, String name, String description) {
felix@2018: super(idx, name, description);
felix@2001: }
felix@2001:
felix@2001:
felix@2001: /**
felix@2001: * Gets Cross Section (profile).
felix@2001: * @param art artifact to get data from.
felix@2001: * @param context ignored
felix@2001: */
felix@2001: public Object getData(Artifact art, CallContext context) {
felix@2010: logger.debug("Get data for area.");
felix@2001:
felix@2001: // Get information from artifact about which
felix@2001: // info to grab from blackboard.
felix@2001: //
felix@2001: // All compatible facets should provide their data
felix@2001: // under the key (Artifact-UUID + Facet-Index).
felix@2001: AreaArtifact artifact = (AreaArtifact) art;
felix@2001: Object lowerData = null;
felix@2001: Object upperData = null;
aheinecke@7714: String lowerFacetName = null;
aheinecke@7714: String upperFacetName = null;
felix@2001:
felix@2001: List providers = context.
felix@2001: getDataProvider(artifact.getLowerDPKey());
felix@2001: if (providers.size() < 1) {
sascha@3076: logger.warn("No 'lower' provider given for area [" +
felix@2018: artifact.getLowerDPKey() + "]");
felix@2001: }
felix@2001: else {
felix@2001: lowerData = providers.get(0).provideData(
felix@2001: artifact.getLowerDPKey(), null, context);
sascha@3076: logger.debug("'Lower' data provider key for area [" +
felix@2104: artifact.getLowerDPKey() + "]");
aheinecke@7714: lowerFacetName = artifact.getLowerDPKey().split(":")[1];
felix@2001: }
felix@2001:
felix@2001: providers = context.getDataProvider(artifact.getUpperDPKey());
felix@2001: if (providers.size() < 1) {
felix@2018: logger.warn("No 'upper' provider given for area [" +
felix@2018: artifact.getUpperDPKey() + "]");
felix@2001: }
felix@2001: else {
felix@2001: upperData = providers.get(0).provideData(
felix@2001: artifact.getUpperDPKey(), null, context);
felix@2104: logger.debug("'Upper' data provider key for area [" +
felix@2104: artifact.getUpperDPKey() + "]");
aheinecke@7714: upperFacetName = artifact.getUpperDPKey().split(":")[1];
felix@2001: }
felix@2001:
felix@2001: if (upperData == null && lowerData == null) {
felix@2010: logger.warn("Not given 'upper' and 'lower' for area");
felix@2001: }
felix@2001:
aheinecke@7714: return new Data(upperFacetName, lowerFacetName, lowerData, upperData,
felix@2104: Boolean.valueOf(artifact.getPaintBetween()));
felix@2001: }
felix@2001:
felix@2001:
felix@2001: /** Do a deep copy. */
sascha@3076: @Override
felix@2001: public Facet deepCopy() {
felix@2018: AreaFacet copy = new AreaFacet(this.index, this.name, this.description);
felix@2001: copy.set(this);
felix@2001: return copy;
felix@2001: }
felix@2104:
felix@2104: /** Result data bundle. */
aheinecke@7714: public static class Data {
aheinecke@7714: protected String upperFacetName;
aheinecke@7714: protected String lowerFacetName;
felix@2104: protected Object upperData;
felix@2104: protected Object lowerData;
felix@2104: protected boolean doPaintBetween;
felix@2104:
felix@2104: /** Create a new result data bundle. */
aheinecke@7714: public Data(String upperFacetName, String lowerFacetName, Object low, Object up, boolean between) {
felix@2104: this.lowerData = low;
felix@2104: this.upperData = up;
felix@2104: this.doPaintBetween = between;
aheinecke@7714: this.lowerFacetName = lowerFacetName;
aheinecke@7714: this.upperFacetName = upperFacetName;
felix@2104: }
felix@2104:
aheinecke@7714: public String getLowerFacetName() {
aheinecke@7714: return this.lowerFacetName;
aheinecke@7714: }
aheinecke@7714:
aheinecke@7714: public String getUpperFacetName() {
aheinecke@7714: return this.upperFacetName;
felix@2104: }
felix@2104:
felix@2104: /** Get data for 'upper' curve of area. */
felix@2104: public Object getUpperData() {
felix@2104: return this.upperData;
felix@2104: }
felix@2104:
felix@2104: /** Get data for 'lower' curve of area. */
felix@2104: public Object getLowerData() {
felix@2104: return this.lowerData;
felix@2104: }
felix@2104:
felix@2104: /** Whether to fill whole area between (in contrast to 'under'
felix@2104: * or 'over'). */
felix@2104: public boolean doPaintBetween() {
felix@2104: return this.doPaintBetween;
felix@2104: }
felix@2104: }
felix@2001: }
felix@2001: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :