/* -*-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 OSGEARTHFEATURES_FEATURE_H
#define OSGEARTHFEATURES_FEATURE_H 1

#include <osgEarthFeatures/Common>
#include <osgEarthSymbology/Geometry>
#include <osgEarthSymbology/Style>
#include <osgEarth/SpatialReference>
#include <osg/Array>
#include <map>
#include <list>

namespace osgEarth { namespace Features
{
    /**
     * Metadata and schema information for feature data.
     */
    class OSGEARTHFEATURES_EXPORT FeatureProfile : public osg::Referenced
    {
    public:        
        FeatureProfile( const GeoExtent& extent );

        /** Gets the spatial extents of the features in this profile. */
        const GeoExtent& getExtent() const {
            return _extent; }

        /** Gets the spatial reference system of feature shapes in this class. */
        const SpatialReference* getSRS() const {
            return _extent.getSRS(); }

    protected:
        GeoExtent _extent;
    };

    typedef std::map<std::string, std::string> AttributeTable;

    /**
     * Basic building block of vector feature data.
     */
    class OSGEARTHFEATURES_EXPORT Feature : public osg::Object
    {
    public:
        Feature( long fid =0L );

        /** Copy contructor */
        Feature( const Feature& rhs, const osg::CopyOp& copyop =osg::CopyOp::DEEP_COPY_ALL );

        META_Object( osgEarthFeatures, Feature );

    public:

        long getFID() const;

        void setGeometry( Symbology::Geometry* geom ) {
            _geom = geom; }

        Symbology::Geometry* getGeometry() {
            return _geom; }

        const Symbology::Geometry* getGeometry() const {
            return _geom; }

        const AttributeTable& getAttrs() const {
            return _attrs; }

        void setAttr( const std::string& name, const std::string& value );

        const std::string& getAttr( const std::string& name ) const;

        /** Embedded style. */
        optional<osg::ref_ptr<Symbology::Style> >& style() { return _style; }
        const optional<osg::ref_ptr<Symbology::Style> >& style() const { return _style; }

    protected:
        long _fid;
        osg::ref_ptr<Symbology::Geometry> _geom;
        AttributeTable _attrs;
        optional<osg::ref_ptr<Symbology::Style> > _style;
    };

    typedef std::list< osg::ref_ptr<Feature> > FeatureList;

} } // namespace osgEarth::Features

#endif // OSGEARTHFEATURES_FEATURE_H
