/* -*-c++-*- */
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
* Copyright 2008-2010 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/>
*/

#ifndef OSGEARTH_CACHE_SEED_H
#define OSGEARTH_CACHE_SEED_H 1

#include <osgEarth/Common>
#include <osgEarth/Map>
#include <osgEarth/TileKey>
#include <osgEarth/MapNode>

namespace osgEarth
{
    /**
    * Utility class for seeding a cache
    */
    class OSGEARTH_EXPORT CacheSeed
    {
    public:
        CacheSeed():
          _minLevel(0),
          _maxLevel(12),
          _bounds(-180, -90, 180, 90) { }

        /**
        * Sets the minimum level to seed to
        */
        void setMinLevel(const unsigned int& minLevel) {_minLevel = minLevel;}

        /**
        * Gets the minimum level to cache to.
        */
        const unsigned int getMinLevel() const {return _minLevel;}

        /**
        * Sets the maximum level to seed to
        */
        void setMaxLevel(const unsigned int& maxLevel) {_maxLevel = maxLevel;}

        /**
        * Gets the maximum level to cache to.
        */
        const unsigned int getMaxLevel() const {return _maxLevel;}

        /**
        * Gets the bounds to seed in
        */
        const Bounds& getBounds() const { return _bounds; }

        /**
        * Sets the bounds to seed in
        */
        void setBounds(const Bounds& bounds) { _bounds = bounds; }

        /**
        * Sets the bounds to seed in
        */
        void setBounds(const double& minLon, const double& minLat, const double& maxLon, const double& maxLat) { _bounds = Bounds(minLon, minLat, maxLon, maxLat); }

        /**
        * Performs the seed operation
        */
        void seed( Map* map );

    protected:
        unsigned int _minLevel;
        unsigned int _maxLevel;
        Bounds _bounds;

        void processKey( const MapFrame& mapf, const TileKey& key ) const;
        void cacheTile( const MapFrame& mapf, const TileKey& key ) const;
    };
}

#endif //OSGEARTH_CACHE_SEED_H
