/* -*-c++-*- */
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
* Copyright 2008-2013 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_ENGINE_QUADTREE_CUSTOM_PAGED_LOD
#define OSGEARTH_ENGINE_QUADTREE_CUSTOM_PAGED_LOD 1

#include "Common"
#include "TileNode"
#include "TileNodeRegistry"
#include <osg/PagedLOD>

using namespace osgEarth;

namespace osgEarth_engine_quadtree
{
    /**
     * Customized PagedLOD node that automatically registers TileNodes
     * with a TileNodeRegistry when they are added to the scene graph.
     */
    class CustomPagedLOD : public osg::PagedLOD
    {
    public:
        /**
         * Constructs a PagedLOD node that will register TileNode's with the 
         * provided registry 
         */
        CustomPagedLOD(
            TileNodeRegistry* liveTiles,
            TileNodeRegistry* deadTiles );

        /**
         * Destructor 
         */
        virtual ~CustomPagedLOD();

    public: // osg::Group

        /**
         * Override Group methods so that a TileNode gets registered when the 
         * DatabasePager adds it to the scene graph. Of course this would happen
         * if you simply added the TileNode to any parent, but in this 
         * implmementation the DatabasePager is the only entity adding a TileNode
         * to a parent.
         *
         * DatabasePager only calls addChild or removeChild, but we will implement the
         * other methods (insert, replace, etc) later if necessary
         */
        bool addChild( osg::Node* child );
        bool removeChildren(unsigned pos, unsigned numChildrenToRemove );

    private:

        osg::ref_ptr<TileNodeRegistry> _live, _dead;
    };

} // namespace osgEarth_engine_quadtree

#endif // OSGEARTH_ENGINE_QUADTREE_CUSTOM_PAGED_LOD
