/* osgEarth - Geospatial SDK for OpenSceneGraph
* Copyright 2020 Pelican Mapping
* MIT License
*/
#ifndef OSGEARTH_PROCEDURAL_GROUNDCOVER_FEATURESOURCE
#define OSGEARTH_PROCEDURAL_GROUNDCOVER_FEATURESOURCE 1

#include "Export"
#include "GroundCoverLayer"
#include "GroundCoverFeatureGenerator"
#include <osgEarth/FeatureSource>

using namespace osgEarth;

namespace osgEarth { namespace Procedural
{
    /**
     * Creates features representing the location and configuration
     * of GroundCover instances.
     */
    class OSGEARTHPROCEDURAL_EXPORT GroundCoverFeatureSource :
        public FeatureSource
    {
    public: // serialization
        class OSGEARTHPROCEDURAL_EXPORT Options : public FeatureSource::Options
        {
        public:
            META_LayerOptions(osgEarth, Options, FeatureSource::Options);
            OE_OPTION_LAYER(GroundCoverLayer, groundCoverLayer);
            virtual Config getConfig() const;
        private:
            void fromConfig(const Config& conf);
        };

    public:
        META_Layer(osgEarth, GroundCoverFeatureSource, Options, FeatureSource, GroundCoverFeatures);

        //! GroundCoverLayer from which to generate feature data
        void setGroundCoverLayer(GroundCoverLayer* layer);
        GroundCoverLayer* getGroundCoverLayer() const;

    public: // FeatureSource

        virtual FeatureCursor* createFeatureCursorImplementation(const Query& query, ProgressCallback* progress);

    protected: // Layer

        virtual void init();

        virtual Status openImplementation();

        virtual Status closeImplementation();

        virtual void addedToMap(const Map*);

        virtual void removedFromMap(const Map*);
        
    private:
        GroundCoverFeatureGenerator _gen;
    };

} } // namespace osgEarth::Procedural

#endif // OSGEARTH_PROCEDURAL_GROUNDCOVER_FEATURESOURCE
