osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarthDrivers/kml/KMLReader.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 "KMLReader"
00020 #include "KML_Root"
00021 #include <osgEarth/XmlUtils>
00022 #include <stack>
00023 #include <iterator>
00024 
00025 using namespace osgEarth;
00026 
00027 KMLReader::KMLReader( MapNode* mapNode, const KMLOptions* options ) :
00028 _mapNode( mapNode ),
00029 _options( options )
00030 {
00031     //nop
00032 }
00033 
00034 osg::Node*
00035 KMLReader::read( std::istream& in, const URIContext& context )
00036 {
00037     // read the KML from an XML stream:
00038     osg::ref_ptr<XmlDocument> xml = XmlDocument::load( in, context );
00039     if ( !xml.valid() )
00040         return 0L;
00041 
00042     // convert to a config:
00043     Config config = xml->getConfig();
00044 
00045     osg::Node* node = read( config );
00046     node->setName( context.referrer() );
00047 
00048     return node;
00049 }
00050 
00051 osg::Node*
00052 KMLReader::read( const Config& conf )
00053 {
00054     osg::Group* root = new osg::Group();
00055     root->ref();
00056 
00057     root->setName( conf.uriContext().referrer() );
00058 
00059     KMLContext cx;
00060     cx._mapNode = _mapNode;
00061     cx._sheet = new StyleSheet();
00062     cx._groupStack.push( root );
00063     cx._options = _options;
00064 
00065     const Config& kml = conf.child("kml");
00066     if ( !kml.empty() )
00067     {
00068         KML_Root kmlRoot;
00069         kmlRoot.scan( kml, cx );    // first pass
00070         kmlRoot.scan2( kml, cx );   // second pass
00071         kmlRoot.build( kml, cx );   // third pass.
00072     }
00073 
00074     return root;
00075 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines