/* -*-c++-*- */
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
 * Copyright 2015 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 OSGEARTHANNO_ANNOTATION_EDITING_H
#define OSGEARTHANNO_ANNOTATION_EDITING_H 1

#include <osgEarthAnnotation/Common>
#include <osgEarthAnnotation/LocalizedNode>
#include <osgEarthAnnotation/CircleNode>
#include <osgEarthAnnotation/EllipseNode>
#include <osgEarthAnnotation/RectangleNode>
#include <osgEarthAnnotation/Draggers>
#include <osgEarth/MapNode>

namespace osgEarth { namespace Annotation
{
    class OSGEARTHANNO_EXPORT AnnotationEditor : public osg::Group
    {
    protected:
        AnnotationEditor();

        virtual ~AnnotationEditor() { }
    };

     /**
     * An editor node that allows you to move the position of LocalizedNode annotations    
     */
    class OSGEARTHANNO_EXPORT LocalizedNodeEditor : public AnnotationEditor
    {
    public:
        /**
         * Create a new LocalizedAnnotationEditor
         * @param localizedNode
         *        The LocalizedNode to edit
         */
        LocalizedNodeEditor(LocalizedNode* localizedNode);    
        
        virtual ~LocalizedNodeEditor();    

        virtual void updateDraggers();

        Dragger* getPositionDragger() { return _dragger; }

        void setPosition( const GeoPoint& pos );

    protected:
        osg::ref_ptr< LocalizedNode > _node;
        Dragger* _dragger;
    };

    class OSGEARTHANNO_EXPORT CircleNodeEditor : public LocalizedNodeEditor
    {
    public:
        /**
         * Create a new CircleEditor
         * @param circleNode
         *        The CircleNode to edit
         */
        CircleNodeEditor(CircleNode* circleNode);    
        
        virtual ~CircleNodeEditor();    

        void computeBearing();

        void setBearing( const Angle& value );

        virtual void updateDraggers();

        Dragger* getRadiusDragger() { return _radiusDragger; }

        double _bearing;

        Dragger* _radiusDragger;
    };

    class OSGEARTHANNO_EXPORT EllipseNodeEditor : public LocalizedNodeEditor
    {
    public:
        /**
         * Create a new EllipseNodeEditor
         * @param ellipseNode
         *        The EllipseNodeEditor to edit
         */
        EllipseNodeEditor(EllipseNode* ellipseNode);    
        
        virtual ~EllipseNodeEditor();    

        virtual void updateDraggers();

        Dragger* _majorDragger;
        Dragger* _minorDragger;
    };

    class OSGEARTHANNO_EXPORT RectangleNodeEditor : public LocalizedNodeEditor
    {
    public:
        /**
         * Create a new RectangleNodeEditor
         * @param rectangleNode
         *        The RectangleNodeEditor to edit
         */
        RectangleNodeEditor(RectangleNode* rectangleNode);    
        
        virtual ~RectangleNodeEditor();    

        virtual void updateDraggers();

        Dragger* _llDragger;
        Dragger* _lrDragger;
        Dragger* _urDragger;
        Dragger* _ulDragger;
    };

} } // namespace osgEarth::Annotation

#endif // OSGEARTHANNO_FEATURE_EDITING_H
