osgEarth 2.1.1
|
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 <osgEarthFeatures/BuildTextFilter> 00020 #include <osgEarthFeatures/BuildTextOperator> // this should be in symbology -gw 00021 #include <osgEarthFeatures/LabelSource> 00022 #include <osgEarthSymbology/TextSymbol> 00023 #include <osgText/Text> 00024 00025 #define LC "[BuildTextFilter] " 00026 00027 using namespace osgEarth; 00028 using namespace osgEarth::Features; 00029 using namespace osgEarth::Symbology; 00030 00031 BuildTextFilter::BuildTextFilter( const Style& style ) : 00032 _style( style ) 00033 { 00034 //nop 00035 } 00036 00037 osg::Node* 00038 BuildTextFilter::push( FeatureList& input, FilterContext& context ) 00039 { 00040 osg::Node* result = 0L; 00041 00042 const TextSymbol* text = _style.get<TextSymbol>(); 00043 if ( !text ) 00044 { 00045 OE_WARN << LC << "Insufficient symbology (no TextSymbol)" << std::endl; 00046 return 0L; 00047 } 00048 00049 // if a provider is set, load the plugin and create the node. 00050 if ( !text->provider()->empty() && !text->provider().isSetTo("legacy") ) 00051 { 00052 LabelSourceOptions options; 00053 options.setDriver( *text->provider() ); 00054 osg::ref_ptr<LabelSource> source = LabelSourceFactory::create( options ); 00055 if ( source.valid() ) 00056 { 00057 result = source->createNode( input, text, context ); 00058 } 00059 else 00060 { 00061 OE_WARN << LC << "FAIL, unable to load label provider \"" << (*text->provider()) << "\"" << std::endl; 00062 return 0L; 00063 } 00064 } 00065 00066 else // legacy behavior... will be deprecated. 00067 { 00068 BuildTextOperator op; 00069 result = op( input, text, context ); 00070 } 00071 00072 return result; 00073 }