osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarth/MapNodeOptions.cpp

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 #include <osgEarth/MapNodeOptions>
00020 #include <osg/Notify>
00021 #include <OpenThreads/Thread>
00022 
00023 using namespace osgEarth;
00024 
00025 std::string MapNodeOptions::OPTIONS_TAG = "__osgEarth::MapNodeOptions";
00026 
00027 //----------------------------------------------------------------------------
00028 
00029 static TerrainOptions s_defaultTerrainOptions;
00030 
00031 //----------------------------------------------------------------------------
00032 
00033 MapNodeOptions::MapNodeOptions( const Config& conf ) :
00034 ConfigOptions        ( conf ),
00035 _proxySettings       ( ProxySettings() ),
00036 _cacheOnly           ( false ),
00037 _enableLighting      ( true ),
00038 _overlayVertexWarping( false ),
00039 _overlayBlending     ( true ),
00040 _overlayTextureSize  ( 4096 ),
00041 _terrainOptions      ( 0L )
00042 {
00043     mergeConfig( conf );
00044 }
00045 
00046 MapNodeOptions::MapNodeOptions( const TerrainOptions& to ) :
00047 _proxySettings       ( ProxySettings() ),
00048 _cacheOnly           ( false ),
00049 _enableLighting      ( true ),
00050 _overlayVertexWarping( false ),
00051 _overlayBlending     ( true ),
00052 _overlayTextureSize  ( 4096 ),
00053 _terrainOptions      ( 0L )
00054 {
00055     setTerrainOptions( to );
00056 }
00057 
00058 
00059 MapNodeOptions::~MapNodeOptions()
00060 {
00061     if ( _terrainOptions )
00062     {
00063         delete _terrainOptions;
00064         _terrainOptions = 0L;
00065     }
00066 }
00067 
00068 Config
00069 MapNodeOptions::getConfig() const
00070 {
00071     Config conf; // start with a fresh one since this is a FINAL object  // = ConfigOptions::getConfig();
00072     conf.key() = "options";
00073 
00074     conf.updateObjIfSet( "proxy",            _proxySettings );
00075     conf.updateIfSet   ( "cache_only",       _cacheOnly );
00076     conf.updateIfSet   ( "lighting",         _enableLighting );
00077     conf.updateIfSet   ( "terrain",          _terrainOptionsConf );
00078     conf.updateIfSet   ( "overlay_warping",  _overlayVertexWarping );
00079     conf.updateIfSet   ( "overlay_blending", _overlayBlending );
00080     conf.updateIfSet   ( "overlay_texture_size",     _overlayTextureSize );
00081 
00082     return conf;
00083 }
00084 
00085 void
00086 MapNodeOptions::mergeConfig( const Config& conf )
00087 {
00088     ConfigOptions::mergeConfig( conf );
00089 
00090     conf.getObjIfSet( "proxy",            _proxySettings );
00091     conf.getIfSet   ( "cache_only",       _cacheOnly );
00092     conf.getIfSet   ( "lighting",         _enableLighting );
00093     conf.getIfSet   ( "overlay_warping",  _overlayVertexWarping );
00094     conf.getIfSet   ( "overlay_blending", _overlayBlending );
00095     conf.getIfSet   ( "overlay_texture_size",     _overlayTextureSize );
00096 
00097     if ( conf.hasChild( "terrain" ) )
00098     {
00099         _terrainOptionsConf = conf.child( "terrain" );
00100         if ( _terrainOptions )
00101         {
00102             delete _terrainOptions;
00103             _terrainOptions = 0L;
00104         }
00105     }
00106 }
00107 
00108 void
00109 MapNodeOptions::setTerrainOptions( const TerrainOptions& options )
00110 {
00111     _terrainOptionsConf = options.getConfig();
00112     if ( _terrainOptions )
00113     {
00114         delete _terrainOptions;
00115         _terrainOptions = 0L;
00116     }
00117 }
00118 
00119 const TerrainOptions&
00120 MapNodeOptions::getTerrainOptions() const
00121 {
00122     if ( _terrainOptionsConf.isSet() )
00123     {
00124         if ( !_terrainOptions )
00125         {
00126             const_cast<MapNodeOptions*>(this)->_terrainOptions = new TerrainOptions( _terrainOptionsConf.value() );
00127         }
00128         return *_terrainOptions;
00129     }
00130     else
00131     {
00132         return s_defaultTerrainOptions;
00133     }
00134 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines