/* -*-c++-*- */
/* osgEarth - Geospatial SDK for OpenSceneGraph
 * Copyright 2020 Pelican Mapping
 * http://osgearth.org
 *
 * osgEarth is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 */
#pragma once
#include <osgEarth/Common>
#include <osgEarth/TileKey>
#include <osgEarth/VisibleLayer>
#include <osg/Node>

namespace osgEarth
{
    class ProgressCallback;

    /**
     * Layer that creates a scene graph from a tiled data source.
     * This class is abstract; subclasses must implement createTileImplementation().
     */
    class OSGEARTH_EXPORT TiledModelLayer : public VisibleLayer
    {
    public:
        // options serialization
        struct OSGEARTH_EXPORT Options : public VisibleLayer::Options
        {
            META_LayerOptions(osgEarth, Options, VisibleLayer::Options);
            virtual Config getConfig() const;
            void fromConfig(const Config& conf);
        };

    public:
        META_Layer_Abstract(osgEarth, TiledModelLayer, Options, VisibleLayer);

        //! Create an OSG node from a tile key.
        //! @param key The tile key.
        //! @param  progress A progress callback
        osg::ref_ptr<osg::Node> createTile(const TileKey& key, ProgressCallback* progress) const;

        //! Profile of the underlying tiled data source.
        virtual const Profile* getProfile() const = 0;

        //! Minimum available LOD of the underlying tiled data source.
        virtual unsigned getMinLevel() const = 0;

        //! Maximum available LOD of the underlying tiled data source.
        virtual unsigned getMaxLevel() const = 0;

    protected:
        //! Subclasses must implement this to create a tile.
        //! @param key The tile key, in the underlying tiled data source's profile.
        //! @param progress A progress callback that can be checked for user cancellation.
        virtual osg::ref_ptr<osg::Node> createTileImplementation(const TileKey& key, ProgressCallback* progress) const = 0;
    };
}
