osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarth/ModelLayer

Go to the documentation of this file.
00001 /* -*-c++-*- */
00002 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
00003  * Copyright 2008-2010 Pelican Mapping
00004  * http://osgearth.org
00005  *
00006  * osgEarth is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU Lesser General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public License
00017  * along with this program.  If not, see <http://www.gnu.org/licenses/>
00018  */
00019 
00020 #ifndef OSGEARTH_MODEL_LAYER_H
00021 #define OSGEARTH_MODEL_LAYER_H 1
00022 
00023 #include <osgEarth/Common>
00024 #include <osgEarth/Layer>
00025 #include <osgEarth/Config>
00026 #include <osgEarth/ModelSource>
00027 #include <osg/Node>
00028 #include <vector>
00029 
00030 namespace osgEarth
00031 {
00032     class Map;
00033 
00037     class OSGEARTH_EXPORT ModelLayerOptions : public ConfigOptions
00038     {
00039     public:        
00040         ModelLayerOptions( const ConfigOptions& options =ConfigOptions() );
00041 
00042         ModelLayerOptions( const std::string& name, const ModelSourceOptions& driverOptions =ModelSourceOptions() );
00043 
00047         optional<std::string>& name() { return _name; }
00048         const optional<std::string>& name() const { return _name; }
00049 
00053         optional<ModelSourceOptions>& driver() { return _driver; }
00054         const optional<ModelSourceOptions>& driver() const { return _driver; }
00055 
00059         optional<bool>& lightingEnabled() { return _lighting; }
00060         const optional<bool>& lightingEnabled() const { return _lighting; }
00061 
00065         optional<bool>& enabled() { return _enabled; }
00066         const optional<bool>& enabled() const { return _enabled; }
00067 
00072         optional<bool>& overlay() { return _overlay; }
00073         const optional<bool>& overlay() const { return _overlay; }
00074 
00075     public:
00076         virtual Config getConfig() const;
00077         virtual void mergeConfig( const Config& conf );
00078 
00079     private:
00080         void fromConfig( const Config& conf );
00081         void setDefaults();
00082 
00083         optional<std::string> _name;
00084         optional<bool> _overlay;
00085         optional<ModelSourceOptions> _driver;
00086         optional<bool> _enabled;
00087         optional<bool> _lighting;
00088     };
00089 
00093     struct ModelLayerCallback : public osg::Referenced
00094     {
00095         virtual void onOverlayChanged( class ModelLayer* layer ) { }
00096     };
00097 
00098     typedef void (ModelLayerCallback::*ModelLayerCallbackMethodPtr)(ModelLayer* layer);
00099 
00100     typedef std::list< osg::ref_ptr<ModelLayerCallback> > ModelLayerCallbackList;
00101 
00102 
00103     class OSGEARTH_EXPORT ModelLayer : public Layer
00104     {
00105     public:
00109         ModelLayer( const ModelLayerOptions& options );
00110 
00114         ModelLayer( const std::string& name, const ModelSourceOptions& options );
00115         
00119         ModelLayer(const ModelLayerOptions& options, ModelSource* source );
00120 
00124         ModelLayer(const std::string& name, osg::Node* node);
00125 
00126     public:
00130         const std::string& getName() const { return *_runtimeOptions.name(); }
00131 
00135         const ModelLayerOptions& getModelLayerOptions() const { return _initOptions; }
00136 
00140         const std::string& getReferenceURI() const { return _referenceURI; }
00141 
00145         ModelSource* getModelSource() const { return _modelSource.get(); }
00146 
00147     public:
00148 
00149         osg::Node* getOrCreateNode( ProgressCallback* progress =0L );
00150 
00151     public: // properties
00152 
00154         bool getEnabled() const;
00155         void setEnabled(bool enabled);
00156 
00158         bool getOverlay() const;
00159         void setOverlay( bool overlay );
00160 
00162         void setLightingEnabled( bool value );
00163         bool isLightingEnabled() const;
00164 
00165     public:
00166 
00168         void addCallback( ModelLayerCallback* cb );
00169 
00171         void removeCallback( ModelLayerCallback* cb );
00172 
00173     public:
00174 
00175         // internal function
00176         void initialize( const std::string& referenceURI, const Map* map );
00177 
00178     private:
00179         std::string _referenceURI;
00180         osg::ref_ptr<ModelSource> _modelSource;
00181 
00182         const ModelLayerOptions _initOptions;
00183         ModelLayerOptions       _runtimeOptions;
00184 
00185         osg::ref_ptr< osg::Node > _node;
00186 
00187         //optional<bool> _enabled;
00188         //optional<bool> _lighting;
00189         //optional<bool> _overlay;
00190 
00191         Revision _modelSourceRev;
00192 
00193         ModelLayerCallbackList _callbacks;
00194         virtual void fireCallback( ModelLayerCallbackMethodPtr method );
00195 
00196         void copyOptions();
00197 
00198     };
00199 
00200     typedef std::vector< osg::ref_ptr<ModelLayer> > ModelLayerVector;
00201 }
00202 
00203 #endif // OSGEARTH_MODEL_LAYER_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines