osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarthSymbology/Style

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 #ifndef OSGEARTHSYMBOLOGY_STYLE_H
00020 #define OSGEARTHSYMBOLOGY_STYLE_H 1
00021 
00022 #include <osgEarthSymbology/Common>
00023 #include <osgEarthSymbology/Color>
00024 #include <osgEarthSymbology/Query>
00025 #include <osgEarthSymbology/PointSymbol>
00026 #include <osgEarthSymbology/LineSymbol>
00027 #include <osgEarthSymbology/PolygonSymbol>
00028 #include <osgEarthSymbology/MarkerSymbol>
00029 #include <osgEarthSymbology/ExtrusionSymbol>
00030 #include <osgEarthSymbology/AltitudeSymbol>
00031 #include <osgEarthSymbology/TextSymbol>
00032 #include <osgEarthSymbology/Skins>
00033 #include <osgEarthSymbology/ResourceLibrary>
00034 
00035 #include <osgEarth/Config>
00036 #include <osgEarth/Revisioning>
00037 #include <osg/Object>
00038 #include <vector>
00039 
00040 namespace osgEarth { namespace Symbology 
00041 {
00046     class OSGEARTHSYMBOLOGY_EXPORT Style
00047     {
00048     public:
00050         Style( const std::string& name = "" );
00051 
00053         Style(const Config& conf);
00054 
00056         Style(const Style& rhs); 
00057 
00059         const std::string& getName() const { return _name; }
00060 
00062         void setName( const std::string& value ) { _name = value; }
00063 
00066         Style combineWith( const Style& rhs ) const;
00067 
00069         bool empty() const { return _symbols.empty(); }
00070 
00072         void addSymbol(Symbol* symbol);
00073 
00075                 bool removeSymbol (Symbol* symbol);
00076                 
00078         template<typename T>
00079         T* getSymbol()
00080         {
00081             for (SymbolList::const_iterator it = _symbols.begin(); it != _symbols.end(); ++it)
00082             {
00083                 Symbol* symbol = (*it).get();
00084                 T* s = dynamic_cast<T*>(symbol);
00085                 if (s)
00086                     return s;
00087             }
00088             return 0L;
00089         }
00090         template<typename T> T* get() { return getSymbol<T>(); } // alias
00091 
00093         template<typename T>
00094         const T* getSymbol() const
00095         {
00096             for (SymbolList::const_iterator it = _symbols.begin(); it != _symbols.end(); ++it)
00097             {
00098                 Symbol* symbol = (*it).get();
00099                 const T* s = dynamic_cast<const T*>(symbol);
00100                 if (s)
00101                     return s;
00102             }
00103             return 0L;
00104         }
00105         template<typename T> const T* get() const { return getSymbol<T>(); } // alias
00106 
00109         template<typename T>
00110         T* getOrCreateSymbol()
00111         {
00112             T* sym = getSymbol<T>();
00113             if ( !sym )
00114             {
00115                 sym = new T();
00116                 addSymbol( sym );
00117             }
00118             return sym;
00119         }
00120         template<typename T> T* getOrCreate() { return getOrCreateSymbol<T>(); } // alias        
00121 
00123         virtual Config getConfig( bool keepOrigType =true ) const;
00124 
00125         void mergeConfig( const Config& conf );
00126         void fromCSS( const std::string& css );
00127 
00128     protected:
00129         std::string                 _name;
00130         SymbolList                  _symbols;
00131         std::string                 _origType;
00132         std::string                 _origData;
00133         optional<URI>               _uri;
00134     };
00135 
00136     typedef std::vector<Style>           StyleList;
00137     typedef std::map<std::string, Style> StyleMap;
00138 
00145     class OSGEARTHSYMBOLOGY_EXPORT StyleSelector
00146     {
00147     public:
00148         StyleSelector( const Config& conf =Config() );
00149 
00150     public: // properties
00151 
00153         std::string& name() { return _name; }
00154         const std::string& name() const { return _name; }
00155 
00157         optional<std::string>& styleName() { return _styleName; }
00158         const optional<std::string>& styleName() const { return _styleName; }
00159 
00161         optional<Query>& query() { return _query; }
00162         const optional<Query>& query() const { return _query; }
00163 
00165         std::string getSelectedStyleName() const;
00166 
00167         //Configurable
00168         virtual void mergeConfig( const Config& conf );
00169         virtual Config getConfig() const;
00170 
00171     protected:
00172         std::string           _name;
00173         optional<std::string> _styleName;
00174         optional<Query>       _query;
00175     };
00176 
00177     typedef std::list<StyleSelector>   StyleSelectorList;
00178     typedef std::vector<StyleSelector> StyleSelectorVector;
00179 
00180 
00184     class OSGEARTHSYMBOLOGY_EXPORT StyleSheet : public osg::Referenced
00185     {
00186     public:
00188         StyleSheet( const Config& conf =Config() );
00189 
00191         const URIContext& uriContext() const { return _uriContext; }
00192 
00194         void addStyle( const Style& style );
00195 
00197         void removeStyle( const std::string& name );
00198         
00202         Style* getStyle( const std::string& name, bool fallBackOnDefault =true );
00203         const Style* getStyle( const std::string& name, bool fallBackOnDefault =true ) const;
00204 
00206         Style* getDefaultStyle();
00207         const Style* getDefaultStyle() const;
00208 
00210         StyleSelectorList& selectors() { return _selectors; }
00211         const StyleSelectorList& selectors() const { return _selectors; }
00212 
00214         void addResourceLibrary( const std::string& name, ResourceLibrary* library );
00215 
00217         ResourceLibrary* getResourceLibrary( const std::string& name ) const;
00218 
00220         const ResourceLibraryMap& resourceLibraries() const { return _libraries; }
00221 
00222     public: // serialization functions
00223 
00224         virtual Config getConfig() const;
00225         virtual void mergeConfig( const Config& conf );
00226 
00227     protected:
00228         URIContext         _uriContext;
00229         ResourceLibraryMap _libraries;
00230         StyleSelectorList  _selectors;
00231         StyleMap           _styles;
00232         Style              _emptyStyle;
00233     };
00234 
00235 } } // namespace osgEarth::Symbology
00236 
00237 
00238 #endif // OSGEARTHSYMBOLOGY_STYLE_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines