osgEarth 2.1.1
Public Member Functions | Protected Attributes

osgEarth::Symbology::Style Class Reference

Collaboration diagram for osgEarth::Symbology::Style:

List of all members.

Public Member Functions

 Style (const std::string &name="")
 Style (const Config &conf)
 Style (const Style &rhs)
const std::string & getName () const
void setName (const std::string &value)
Style combineWith (const Style &rhs) const
bool empty () const
void addSymbol (Symbol *symbol)
bool removeSymbol (Symbol *symbol)
template<typename T >
T * getSymbol ()
template<typename T >
T * get ()
template<typename T >
const T * getSymbol () const
template<typename T >
const T * get () const
template<typename T >
T * getOrCreateSymbol ()
template<typename T >
T * getOrCreate ()
virtual Config getConfig (bool keepOrigType=true) const
void mergeConfig (const Config &conf)
void fromCSS (const std::string &css)

Protected Attributes

std::string _name
SymbolList _symbols
std::string _origType
std::string _origData
optional< URI_uri

Detailed Description

Style is an unordered collection of Symbols that describes how to render geometry and other objects.

Definition at line 46 of file Style.


Constructor & Destructor Documentation

osgEarth::Symbology::Style::Style ( const std::string &  name = "")

Constructs a new, empty style.

Style::Style ( const Config conf)

Constructs a style by deserializing it from a Config.

Definition at line 65 of file Style.cpp.

{
    mergeConfig( conf );
}
Style::Style ( const Style rhs)

Copy constructor.

Definition at line 39 of file Style.cpp.

                             :
_name    ( rhs._name ),
_symbols ( rhs._symbols ),
_origType( rhs._origType ),
_origData( rhs._origData ),
_uri     ( rhs._uri )
{
    //nop
}

Member Function Documentation

void Style::addSymbol ( Symbol symbol)

Adds a symbol to the collection.

Definition at line 49 of file Style.cpp.

{
    _symbols.push_back(symbol);
}
Style Style::combineWith ( const Style rhs) const

Starts with this style, merges in all the symbols from the other style, and returns a new style

Definition at line 71 of file Style.cpp.

{
    // start by deep-cloning this style.
    Config conf = getConfig( false );
    Style newStyle( conf );

    // next, merge in the symbology from the other style.
    newStyle.mergeConfig( rhs.getConfig(false) );

    if ( !this->empty() && !rhs.empty() )
        newStyle.setName( _name + ":" + rhs.getName() );
    else if ( !this->empty() && rhs.empty() )
        newStyle.setName( _name );
    else if ( this->empty() && !rhs.empty() )
        newStyle.setName( rhs.getName() );
    else
        newStyle.setName( _name );

    return newStyle;
}

Here is the call graph for this function:

bool osgEarth::Symbology::Style::empty ( ) const [inline]

Test whether the style is empty

Definition at line 69 of file Style.

{ return _symbols.empty(); }
void osgEarth::Symbology::Style::fromCSS ( const std::string &  css)
template<typename T >
T* osgEarth::Symbology::Style::get ( ) [inline]

Definition at line 90 of file Style.

{ return getSymbol<T>(); } // alias
template<typename T >
const T* osgEarth::Symbology::Style::get ( ) const [inline]

Definition at line 105 of file Style.

{ return getSymbol<T>(); } // alias
virtual Config osgEarth::Symbology::Style::getConfig ( bool  keepOrigType = true) const [virtual]

Serializes this object into a Config.

const std::string& osgEarth::Symbology::Style::getName ( ) const [inline]

Gets the name of this style

Definition at line 59 of file Style.

{ return _name; }
template<typename T >
T* osgEarth::Symbology::Style::getOrCreate ( ) [inline]

Definition at line 120 of file Style.

{ return getOrCreateSymbol<T>(); } // alias        
template<typename T >
T* osgEarth::Symbology::Style::getOrCreateSymbol ( ) [inline]

Gets a typed symbol from the style (first one found), or creates/adds/returns one of that type if it doesn't already exist.

Definition at line 110 of file Style.

        {
            T* sym = getSymbol<T>();
            if ( !sym )
            {
                sym = new T();
                addSymbol( sym );
            }
            return sym;
        }
template<typename T >
const T* osgEarth::Symbology::Style::getSymbol ( ) const [inline]

Gets a typed symbol from the style (the first one found)

Definition at line 94 of file Style.

        {
            for (SymbolList::const_iterator it = _symbols.begin(); it != _symbols.end(); ++it)
            {
                Symbol* symbol = (*it).get();
                const T* s = dynamic_cast<const T*>(symbol);
                if (s)
                    return s;
            }
            return 0L;
        }
template<typename T >
T* osgEarth::Symbology::Style::getSymbol ( ) [inline]

Gets a typed symbol from the style (the first one found).

Definition at line 79 of file Style.

        {
            for (SymbolList::const_iterator it = _symbols.begin(); it != _symbols.end(); ++it)
            {
                Symbol* symbol = (*it).get();
                T* s = dynamic_cast<T*>(symbol);
                if (s)
                    return s;
            }
            return 0L;
        }
void osgEarth::Symbology::Style::mergeConfig ( const Config conf)
bool Style::removeSymbol ( Symbol symbol)

Remove a symbol from the collection

Definition at line 54 of file Style.cpp.

{
        SymbolList::iterator it = find(_symbols.begin(), _symbols.end(), symbol);
        if (it == _symbols.end())
                return false;
                
        _symbols.erase(it);
        
        return true;
}
void osgEarth::Symbology::Style::setName ( const std::string &  value) [inline]

Sets the name of this style

Definition at line 62 of file Style.

{ _name = value; }

Member Data Documentation

std::string osgEarth::Symbology::Style::_name [protected]

Definition at line 129 of file Style.

std::string osgEarth::Symbology::Style::_origData [protected]

Definition at line 132 of file Style.

std::string osgEarth::Symbology::Style::_origType [protected]

Definition at line 131 of file Style.

SymbolList osgEarth::Symbology::Style::_symbols [protected]

Definition at line 130 of file Style.

optional<URI> osgEarth::Symbology::Style::_uri [protected]

Definition at line 133 of file Style.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines