From 590ac02859dcbd37dc395d213280dec1e700d636 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 29 Apr 2009 20:30:21 +0000 Subject: [PATCH] Created a simple XmlNode parser class for reading of basic xml files, such as used by present3D. Converted Present3D across from using libxml2 to using the new osgDB::XmlNode/XmlNode::Input classes from Xml Parsing. This changes removes the dependency on libxml2, and allows the present3D application and p3d to work on all platforms. --- CMakeLists.txt | 1 - applications/CMakeLists.txt | 4 +- applications/present3D/CMakeLists.txt | 32 +- applications/present3D/ReadShowFile.cpp | 74 +- ...eaderWriterXML.cpp => ReaderWriterP3D.cpp} | 995 +++++++--------- include/osgDB/XmlParser | 135 +++ src/osgDB/CMakeLists.txt | 2 + src/osgDB/DynamicLibrary.cpp | 2 +- src/osgDB/XmlParser.cpp | 415 +++++++ src/osgPlugins/CMakeLists.txt | 4 +- src/osgPlugins/p3d/CMakeLists.txt | 3 - src/osgPlugins/p3d/PickEventHandler.cpp | 26 +- src/osgPlugins/p3d/PickEventHandler.h | 25 +- src/osgPlugins/p3d/ReaderWriterP3D.cpp | 1040 +++++++---------- src/osgPlugins/p3d/SlideEventHandler.cpp | 91 +- src/osgPlugins/p3d/SlideEventHandler.h | 125 +- src/osgPlugins/p3d/SlideShowConstructor.cpp | 83 +- src/osgPlugins/p3d/SlideShowConstructor.h | 114 +- src/osgWrappers/osgDB/XmlParser.cpp | 179 +++ 19 files changed, 1895 insertions(+), 1455 deletions(-) rename applications/present3D/{ReaderWriterXML.cpp => ReaderWriterP3D.cpp} (54%) create mode 100644 include/osgDB/XmlParser create mode 100644 src/osgDB/XmlParser.cpp create mode 100644 src/osgWrappers/osgDB/XmlParser.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index ceccc8c0e..19a6922f3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -325,7 +325,6 @@ FIND_PACKAGE(OurDCMTK) FIND_PACKAGE(OpenAL) FIND_PACKAGE(XUL) FIND_PACKAGE(FFmpeg) -FIND_PACKAGE(LibXml2) #use pkg-config to find various modues INCLUDE(FindPkgConfig OPTIONAL) diff --git a/applications/CMakeLists.txt b/applications/CMakeLists.txt index a1744a6eb..3cb567509 100644 --- a/applications/CMakeLists.txt +++ b/applications/CMakeLists.txt @@ -32,9 +32,7 @@ IF(DYNAMIC_OPENSCENEGRAPH) ADD_SUBDIRECTORY(osgconv) ADD_SUBDIRECTORY(osgfilecache) ADD_SUBDIRECTORY(osgversion) - IF(LIBXML2_FOUND) - ADD_SUBDIRECTORY(present3D) - ENDIF() + ADD_SUBDIRECTORY(present3D) ELSE() # need to define this on win32 or linker cries about _declspecs ADD_DEFINITIONS(-DOSG_LIBRARY_STATIC) diff --git a/applications/present3D/CMakeLists.txt b/applications/present3D/CMakeLists.txt index b3a606ec2..318116d79 100644 --- a/applications/present3D/CMakeLists.txt +++ b/applications/present3D/CMakeLists.txt @@ -2,6 +2,21 @@ INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE_DIR} ) SET(TARGET_EXTERNAL_LIBRARIES ${LIBXML2_LIBRARIES}) SET(TARGET_SRC + AnimationMaterial.cpp + Cluster.cpp + CompileSlideCallback.cpp + ExportHTML.cpp + PickEventHandler.cpp + PointsEventHandler.cpp + present3D.cpp + ReaderWriterP3D.cpp + ReadShowFile.cpp + ShowEventHandler.cpp + SlideEventHandler.cpp + SlideShowConstructor.cpp +) + +SET(TARGET_H AnimationMaterial.h Cluster.h CompileSlideCallback.h @@ -14,21 +29,6 @@ SET(TARGET_SRC SlideShowConstructor.h ) -SET(TARGET_H - AnimationMaterial.cpp - Cluster.cpp - CompileSlideCallback.cpp - ExportHTML.cpp - PickEventHandler.cpp - PointsEventHandler.cpp - present3D.cpp - ReaderWriterXML.cpp - ReadShowFile.cpp - ShowEventHandler.cpp - SlideEventHandler.cpp - SlideShowConstructor.cpp -) - IF (SDL_FOUND) OPTION(BUILD_WITH_SDL "Set to ON to build with SDL for joystick support." OFF) @@ -56,4 +56,4 @@ ENDIF(SDL_FOUND) SET(TARGET_ADDED_LIBRARIES osgVolume osgFX) -SETUP_APPLICATION(present3D) +SETUP_APPLICATION(present3D-osg) diff --git a/applications/present3D/ReadShowFile.cpp b/applications/present3D/ReadShowFile.cpp index d51cdcf35..286f13ded 100644 --- a/applications/present3D/ReadShowFile.cpp +++ b/applications/present3D/ReadShowFile.cpp @@ -24,8 +24,7 @@ #include -#include -#include +#include #include @@ -107,10 +106,14 @@ bool p3d::readEnvVars(const std::string& fileName) !osgDB::equalCaseInsensitive(ext,"p3d")) return false; - xmlDocPtr doc; - xmlNodePtr cur; + osg::ref_ptr doc = new osgDB::XmlNode; + osgDB::XmlNode* root = 0; - doc = xmlParseFile(fileName.c_str()); + osgDB::XmlNode::Input input; + input.open(fileName); + input.readAllDataIntoBuffer(); + + doc->read(input); if (doc == NULL ) { @@ -118,50 +121,43 @@ bool p3d::readEnvVars(const std::string& fileName) return false; } - cur = xmlDocGetRootElement(doc); - - if (cur == NULL) - { - fprintf(stderr,"empty document\n"); - xmlFreeDoc(doc); - return false; + for(osgDB::XmlNode::Children::iterator itr = doc->children.begin(); + itr != doc->children.end() && !root; + ++itr) + { + if ((*itr)->name=="presentation") root = itr->get(); } - if (xmlStrcmp(cur->name, (const xmlChar *) "presentation")) - { - fprintf(stderr,"document of the wrong type, root node != presentation"); - xmlFreeDoc(doc); - return false; + if (root == NULL) + { + fprintf(stderr,"empty document\n"); + return false; } - + + if (root->name!="presentation") + { + fprintf(stderr,"document of the wrong type, root node != presentation"); + return false; + } + bool readVars = false; - xmlChar *key; - cur = cur->xmlChildrenNode; - while (cur != NULL) { + for(osgDB::XmlNode::Children::iterator itr = root->children.begin(); + itr != root->children.end(); + ++itr) + { + osgDB::XmlNode* cur = itr->get(); - if ((!xmlStrcmp(cur->name, (const xmlChar *)"env"))) + if (cur->name=="env") { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) - { - char* str = strdup((char*)key); - osg::notify(osg::INFO)<<"putenv("<contents.c_str()); + osg::notify(osg::INFO)<<"putenv("<next; } - #ifndef __APPLE__ - - xmlFreeDoc(doc); - - #endif - - return readVars; + return readVars; } osg::Node* p3d::readHoldingSlide(const std::string& filename) diff --git a/applications/present3D/ReaderWriterXML.cpp b/applications/present3D/ReaderWriterP3D.cpp similarity index 54% rename from applications/present3D/ReaderWriterXML.cpp rename to applications/present3D/ReaderWriterP3D.cpp index d6c7cbaf7..b0fe3a5db 100644 --- a/applications/present3D/ReaderWriterXML.cpp +++ b/applications/present3D/ReaderWriterP3D.cpp @@ -25,14 +25,13 @@ #include #include #include -#include -#include + +#include #include #include - /** * OpenSceneGraph plugin wrapper/converter. */ @@ -112,22 +111,22 @@ public: virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const; - void parseModel(osgPresentation::SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur) const; + void parseModel(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const; - void parseVolume(osgPresentation::SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur) const; + void parseVolume(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const; - void parseStereoPair(osgPresentation::SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur) const; + void parseStereoPair(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const; - void parseLayer(osgPresentation::SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur) const; + void parseLayer(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const; - void parseBullets(osgPresentation::SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur, bool inheritPreviousLayers, bool defineAsBaseLayer) const; - void parseText(osgPresentation::SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur, bool inheritPreviousLayers, bool defineAsBaseLayer) const; + void parseBullets(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur, bool inheritPreviousLayers, bool defineAsBaseLayer) const; + void parseText(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur, bool inheritPreviousLayers, bool defineAsBaseLayer) const; - void parsePage (osgPresentation::SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur) const; + void parsePage (osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const; - void parseSlide (osgPresentation::SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur, bool parseTitles=true, bool parseLayers=true) const; + void parseSlide (osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur, bool parseTitles=true, bool parseLayers=true) const; - void parsePdfDocument (osgPresentation::SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur) const; + void parsePdfDocument (osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const; osg::Vec4 mapStringToColor(const std::string& str) const { @@ -164,25 +163,25 @@ public: inline bool read(const std::string& str, osg::Vec3& value) const; inline bool read(const std::string& str, osg::Vec4& value) const; - bool getProperty(xmlNodePtr cur, const char* token) const; - bool getProperty(xmlNodePtr cur, const char* token, int& value) const; - bool getProperty(xmlNodePtr cur, const char* token, float& value) const; - bool getProperty(xmlNodePtr cur, const char* token, double& value) const; - bool getProperty(xmlNodePtr cur, const char* token, osg::Vec2& value) const; - bool getProperty(xmlNodePtr cur, const char* token, osg::Vec3& value) const; - bool getProperty(xmlNodePtr cur, const char* token, osg::Vec4& value) const; - bool getProperty(xmlNodePtr cur, const char* token, std::string& value) const; - bool getProperty(xmlNodePtr cur, const char* token, osgText::Text::Layout& value) const; - bool getProperty(xmlNodePtr cur, const char* token, osgText::Text::AlignmentType& value) const; + bool getProperty(osgDB::XmlNode*cur, const char* token) const; + bool getProperty(osgDB::XmlNode*cur, const char* token, int& value) const; + bool getProperty(osgDB::XmlNode*cur, const char* token, float& value) const; + bool getProperty(osgDB::XmlNode*cur, const char* token, double& value) const; + bool getProperty(osgDB::XmlNode*cur, const char* token, osg::Vec2& value) const; + bool getProperty(osgDB::XmlNode*cur, const char* token, osg::Vec3& value) const; + bool getProperty(osgDB::XmlNode*cur, const char* token, osg::Vec4& value) const; + bool getProperty(osgDB::XmlNode*cur, const char* token, std::string& value) const; + bool getProperty(osgDB::XmlNode*cur, const char* token, osgText::Text::Layout& value) const; + bool getProperty(osgDB::XmlNode*cur, const char* token, osgText::Text::AlignmentType& value) const; - bool getProperties(xmlNodePtr cur, osgPresentation::SlideShowConstructor::PositionData& value) const; - bool getProperties(xmlNodePtr cur, osgPresentation::SlideShowConstructor::FontData& value) const; - bool getProperties(xmlNodePtr cur, osgPresentation::SlideShowConstructor::ModelData& value) const; - bool getProperties(xmlNodePtr cur, osgPresentation::SlideShowConstructor::ImageData& value) const; - bool getJumpProperties(xmlNodePtr cur, bool& relativeJump, int& slideNum, int& layerNum) const; + bool getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::PositionData& value) const; + bool getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::FontData& value) const; + bool getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::ModelData& value) const; + bool getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::ImageData& value) const; + bool getJumpProperties(osgDB::XmlNode*cur, bool& relativeJump, int& slideNum, int& layerNum) const; - bool getKeyPositionInner(xmlDocPtr doc, xmlNodePtr cur, osgPresentation::KeyPosition& keyPosition) const; - bool getKeyPosition(xmlDocPtr doc, xmlNodePtr cur, osgPresentation::KeyPosition& keyPosition) const; + bool getKeyPositionInner(osgDB::XmlNode*cur, osgPresentation::KeyPosition& keyPosition) const; + bool getKeyPosition(osgDB::XmlNode*cur, osgPresentation::KeyPosition& keyPosition) const; typedef std::map ColorMap; typedef std::map LayoutMap; @@ -197,9 +196,7 @@ public: AlignmentMap _alignmentMap; StringKeyMap _stringKeyMap; - typedef std::pair DocNodePair; - typedef std::map TemplateMap; - + typedef std::map > TemplateMap; mutable TemplateMap _templateMap; osg::NotifySeverity _notifyLevel; @@ -328,123 +325,90 @@ bool ReaderWriterP3DXML::read(const std::string& str, osg::Vec4& value) const return !iss.fail(); } -bool ReaderWriterP3DXML::getProperty(xmlNodePtr cur, const char* token) const +bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode* cur, const char* token) const { - bool success = false; - xmlChar *key; - key = xmlGetProp (cur, (const xmlChar *)token); - if (key) success=true; - xmlFree(key); - return success; + return cur->properties.count(token)!=0; } -bool ReaderWriterP3DXML::getProperty(xmlNodePtr cur, const char* token, int& value) const +bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, int& value) const { - xmlChar *key; - key = xmlGetProp (cur, (const xmlChar *)token); - bool success = read((const char*)key,value); - xmlFree(key); - return success; + osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token); + if (itr==cur->properties.end()) return false; + return read(itr->second,value); } -bool ReaderWriterP3DXML::getProperty(xmlNodePtr cur, const char* token, float& value) const +bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, float& value) const { - xmlChar *key; - key = xmlGetProp (cur, (const xmlChar *)token); - bool success = read((const char*)key,value); - xmlFree(key); - return success; + osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token); + if (itr==cur->properties.end()) return false; + return read(itr->second,value); } -bool ReaderWriterP3DXML::getProperty(xmlNodePtr cur, const char* token, double& value) const +bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, double& value) const { - xmlChar *key; - key = xmlGetProp (cur, (const xmlChar *)token); - bool success = read((const char*)key,value); - xmlFree(key); - return success; + osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token); + if (itr==cur->properties.end()) return false; + return read(itr->second,value); } -bool ReaderWriterP3DXML::getProperty(xmlNodePtr cur, const char* token, osg::Vec2& value) const +bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, osg::Vec2& value) const { - xmlChar *key; - key = xmlGetProp (cur, (const xmlChar *)token); - bool success = read((const char*)key,value); - xmlFree(key); - return success; + osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token); + if (itr==cur->properties.end()) return false; + return read(itr->second,value); } -bool ReaderWriterP3DXML::getProperty(xmlNodePtr cur, const char* token, osg::Vec3& value) const +bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, osg::Vec3& value) const { - xmlChar *key; - key = xmlGetProp (cur, (const xmlChar *)token); - bool success = read((const char*)key,value); - xmlFree(key); - return success; + osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token); + if (itr==cur->properties.end()) return false; + return read(itr->second,value); } -bool ReaderWriterP3DXML::getProperty(xmlNodePtr cur, const char* token, osg::Vec4& value) const +bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, osg::Vec4& value) const { - xmlChar *key; - key = xmlGetProp (cur, (const xmlChar *)token); - bool success = read((const char*)key,value); - xmlFree(key); - return success; + osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token); + if (itr==cur->properties.end()) return false; + return read(itr->second,value); } -bool ReaderWriterP3DXML::getProperty(xmlNodePtr cur, const char* token, std::string& value) const +bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, std::string& value) const { - bool success = false; - xmlChar *key; - key = xmlGetProp (cur, (const xmlChar *)token); - if (key) + osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token); + if (itr==cur->properties.end()) return false; + value = itr->second; + return true; +} + +bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, osgText::Text::Layout& value) const +{ + osgDB::XmlNode::Properties::iterator pitr = cur->properties.find(token); + if (pitr==cur->properties.end()) return false; + + const std::string& str = pitr->second; + LayoutMap::const_iterator itr = _layoutMap.find(str); + if (itr!=_layoutMap.end()) { - success = true; - value = (const char*)key; + value = itr->second; } - xmlFree(key); - return success; + return true; } -bool ReaderWriterP3DXML::getProperty(xmlNodePtr cur, const char* token, osgText::Text::Layout& value) const +bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, osgText::Text::AlignmentType& value) const { - bool success = false; - xmlChar *key; - key = xmlGetProp (cur, (const xmlChar *)token); - if (key) + osgDB::XmlNode::Properties::iterator pitr = cur->properties.find(token); + if (pitr==cur->properties.end()) return false; + + const std::string& str = pitr->second; + AlignmentMap::const_iterator itr = _alignmentMap.find(str); + if (itr!=_alignmentMap.end()) { - success = true; - std::string str = (const char*)key; - LayoutMap::const_iterator itr = _layoutMap.find(str); - if (itr!=_layoutMap.end()) - { - value = itr->second; - } + value = itr->second; } - xmlFree(key); - return success; + return true; } -bool ReaderWriterP3DXML::getProperty(xmlNodePtr cur, const char* token, osgText::Text::AlignmentType& value) const -{ - bool success = false; - xmlChar *key; - key = xmlGetProp (cur, (const xmlChar *)token); - if (key) - { - success = true; - std::string str = (const char*)key; - AlignmentMap::const_iterator itr = _alignmentMap.find(str); - if (itr!=_alignmentMap.end()) - { - value = itr->second; - } - } - xmlFree(key); - return success; -} - -bool ReaderWriterP3DXML::getProperties(xmlNodePtr cur, osgPresentation::SlideShowConstructor::PositionData& value) const +bool ReaderWriterP3DXML::getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::PositionData& value) const { bool propertiesRead=false; @@ -686,7 +650,7 @@ bool ReaderWriterP3DXML::getProperties(xmlNodePtr cur, osgPresentation::SlideSho return propertiesRead; } -bool ReaderWriterP3DXML::getProperties(xmlNodePtr cur, osgPresentation::SlideShowConstructor::FontData& value) const +bool ReaderWriterP3DXML::getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::FontData& value) const { bool propertiesRead=false; @@ -721,7 +685,7 @@ bool ReaderWriterP3DXML::getProperties(xmlNodePtr cur, osgPresentation::SlideSho return propertiesRead; } -bool ReaderWriterP3DXML::getProperties(xmlNodePtr cur, osgPresentation::SlideShowConstructor::ModelData& value) const +bool ReaderWriterP3DXML::getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::ModelData& value) const { bool propertiesRead=false; @@ -736,7 +700,7 @@ bool ReaderWriterP3DXML::getProperties(xmlNodePtr cur, osgPresentation::SlideSho return propertiesRead; } -bool ReaderWriterP3DXML::getProperties(xmlNodePtr cur, osgPresentation::SlideShowConstructor::ImageData& value) const +bool ReaderWriterP3DXML::getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::ImageData& value) const { bool propertiesRead=false; @@ -812,7 +776,7 @@ bool ReaderWriterP3DXML::getProperties(xmlNodePtr cur, osgPresentation::SlideSho return propertiesRead; } -bool ReaderWriterP3DXML::getJumpProperties(xmlNodePtr cur, bool& relativeJump, int& slideNum, int& layerNum) const +bool ReaderWriterP3DXML::getJumpProperties(osgDB::XmlNode*cur, bool& relativeJump, int& slideNum, int& layerNum) const { bool propertyRead = false; @@ -839,7 +803,7 @@ bool ReaderWriterP3DXML::getJumpProperties(xmlNodePtr cur, bool& relativeJump, i return propertyRead; } -void ReaderWriterP3DXML::parseModel(osgPresentation::SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur) const +void ReaderWriterP3DXML::parseModel(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const { osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getModelPositionData(); @@ -848,31 +812,24 @@ void ReaderWriterP3DXML::parseModel(osgPresentation::SlideShowConstructor& const osgPresentation::SlideShowConstructor::ModelData modelData;// = constructor.getModelData(); getProperties(cur,modelData); - std::string filename; - xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) filename = (const char*)key; - xmlFree(key); - - if (!filename.empty()) + std::string filename = cur->contents; + + if (!filename.empty()) { constructor.addModel(filename, positionRead ? positionData : constructor.getModelPositionData(), modelData); } - } -void ReaderWriterP3DXML::parseVolume(osgPresentation::SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur) const +void ReaderWriterP3DXML::parseVolume(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const { osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getModelPositionData(); bool positionRead = getProperties(cur,positionData); - std::string filename; - xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) filename = (const char*)key; - xmlFree(key); - + std::string filename = cur->contents; + if (!filename.empty()) { constructor.addVolume(filename, @@ -880,7 +837,7 @@ void ReaderWriterP3DXML::parseVolume(osgPresentation::SlideShowConstructor& cons } } -void ReaderWriterP3DXML::parseStereoPair(osgPresentation::SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur) const +void ReaderWriterP3DXML::parseStereoPair(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const { std::string filenameLeft; std::string filenameRight; @@ -891,31 +848,23 @@ void ReaderWriterP3DXML::parseStereoPair(osgPresentation::SlideShowConstructor& osgPresentation::SlideShowConstructor::ImageData imageDataLeft;// = constructor.getImageData(); osgPresentation::SlideShowConstructor::ImageData imageDataRight;// = constructor.getImageData(); - xmlChar *key; - cur = cur->xmlChildrenNode; - - while (cur != NULL) + for(osgDB::XmlNode::Children::iterator itr = cur->children.begin(); + itr != cur->children.end(); + ++itr) { - if ((!xmlStrcmp(cur->name, (const xmlChar *)"image_left"))) + osgDB::XmlNode* child = itr->get(); + + if (child->name == "image_left") { - getProperties(cur,imageDataLeft); - - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) filenameLeft = (const char*)key; - xmlFree(key); - - + getProperties(child,imageDataLeft); + filenameLeft = child->name; } - if ((!xmlStrcmp(cur->name, (const xmlChar *)"image_right"))) + if (cur->name == "image_right") { + getProperties(child,imageDataRight); + filenameRight = child->name; getProperties(cur,imageDataRight); - - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) filenameRight = (const char*)key; - xmlFree(key); - } - cur = cur->next; } if (!filenameLeft.empty() && !filenameRight.empty()) @@ -925,15 +874,15 @@ void ReaderWriterP3DXML::parseStereoPair(osgPresentation::SlideShowConstructor& } -bool ReaderWriterP3DXML::getKeyPosition(xmlDocPtr doc, xmlNodePtr cur, osgPresentation::KeyPosition& keyPosition) const +bool ReaderWriterP3DXML::getKeyPosition(osgDB::XmlNode*cur, osgPresentation::KeyPosition& keyPosition) const { - if ((!xmlStrcmp(cur->name, (const xmlChar *)"key"))) + if (cur->name == "key") { - return getKeyPositionInner(doc, cur, keyPosition); + return getKeyPositionInner(cur, keyPosition); } - if ((!xmlStrcmp(cur->name, (const xmlChar *)"escape")) || - (!xmlStrcmp(cur->name, (const xmlChar *)"esc")) || - (!xmlStrcmp(cur->name, (const xmlChar *)"exit"))) + if (cur->name == "escape" || + cur->name == "esc" || + cur->name == "exit") { keyPosition.set(osgGA::GUIEventAdapter::KEY_Escape, 0.0f, 0.0f); return true; @@ -941,7 +890,7 @@ bool ReaderWriterP3DXML::getKeyPosition(xmlDocPtr doc, xmlNodePtr cur, osgPresen return false; } -bool ReaderWriterP3DXML::getKeyPositionInner(xmlDocPtr doc, xmlNodePtr cur, osgPresentation::KeyPosition& keyPosition) const +bool ReaderWriterP3DXML::getKeyPositionInner(osgDB::XmlNode*cur, osgPresentation::KeyPosition& keyPosition) const { // x in range -1 to 1, from left to right float x = FLT_MAX; @@ -965,37 +914,32 @@ bool ReaderWriterP3DXML::getKeyPositionInner(xmlDocPtr doc, xmlNodePtr cur, osgP y = v*2.0f-1.0f; } - xmlChar* key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) + + std::string key = cur->contents; + unsigned int keyValue = 0; + + StringKeyMap::const_iterator itr=_stringKeyMap.find(key); + if (itr != _stringKeyMap.end()) { - - unsigned int keyValue = 0; - - StringKeyMap::const_iterator itr=_stringKeyMap.find((const char*)key); - if (itr != _stringKeyMap.end()) - { - keyValue = itr->second; - } - else if (strlen((const char*)key)==1) - { - keyValue = key[0]; - } - else - { - osg::notify(osg::NOTICE)<<"Warning: unreconginized key sequence '"<<(const char*) key<<"'"<second; + } + else if (key.length()==1) + { + keyValue = key[0]; + } + else + { + osg::notify(osg::NOTICE)<<"Warning: unreconginized key sequence '"<xmlChildrenNode; - while (cur != NULL) + for(osgDB::XmlNode::Children::iterator itr = root->children.begin(); + itr != root->children.end(); + ++itr) { - if ((!xmlStrcmp(cur->name, (const xmlChar *)"run"))) + osgDB::XmlNode* cur = itr->get(); + if (cur->name == "run") { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) - { - osg::notify(osg::INFO)<<"run ["<<(const char*)key<<"]"<contents<<"]"<contents); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"jump"))) + else if (cur->name == "jump") { osg::notify(osg::NOTICE)<<"Parsed Jump "<name, (const xmlChar *)"click_to_run"))) + else if (cur->name == "click_to_run") { bool relativeJump = true; int slideNum = 0; int layerNum = 0; getJumpProperties(cur, relativeJump, slideNum, layerNum); - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) - { - osg::notify(osg::INFO)<<"click_to_run ["<<(const char*)key<<"]"<contents<<"]"<contents,osgPresentation::RUN, relativeJump, slideNum, layerNum); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"click_to_load"))) + else if (cur->name == "click_to_load") { bool relativeJump = true; int slideNum = 0; int layerNum = 0; getJumpProperties(cur, relativeJump, slideNum, layerNum); - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) - { - osg::notify(osg::INFO)<<"click_to_load ["<<(const char*)key<<"]"<contents<<"]"<contents,osgPresentation::LOAD, relativeJump, slideNum, layerNum); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"click_to_event"))) + else if (cur->name == "click_to_event") { bool relativeJump = true; int slideNum = 0; int layerNum = 0; getJumpProperties(cur, relativeJump, slideNum, layerNum); - if (getKeyPositionInner(doc, cur, keyPosition)) + if (getKeyPositionInner( cur, keyPosition)) { osg::notify(osg::INFO)<<"click_to_event ["<name, (const xmlChar *)"click_to_jump"))) + else if (cur->name == "click_to_jump") { bool relativeJump = true; int slideNum = 0; @@ -1087,148 +1017,115 @@ void ReaderWriterP3DXML::parseLayer(osgPresentation::SlideShowConstructor& const constructor.layerClickEventOperation(osgPresentation::JUMP, relativeJump, slideNum, layerNum); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"newline"))) + else if (cur->name == "newline") { constructor.translateTextCursor(osg::Vec3(0.0f,-0.05f,0.0f)); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"indent"))) + else if (cur->name == "indent") { float localIndent = 0.05f; constructor.translateTextCursor(osg::Vec3(localIndent,0.0f,0.0f)); totalIndent += localIndent; } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"unindent"))) + else if (cur->name == "unindent") { float localIndent = -0.05f; constructor.translateTextCursor(osg::Vec3(localIndent,0.0f,0.0f)); totalIndent += localIndent; } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"bullet"))) + else if (cur->name == "bullet") { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) - { - osg::notify(osg::INFO)<<"bullet ["<<(const char*)key<<"]"<contents<<"]"<contents, + positionRead ? positionData : constructor.getTextPositionData(), + fontRead ? fontData : constructor.getTextFontData()); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"paragraph"))) + else if (cur->name == "paragraph") { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) - { - osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getTextPositionData(); - bool positionRead = getProperties(cur,positionData); + osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getTextPositionData(); + bool positionRead = getProperties(cur,positionData); - osgPresentation::SlideShowConstructor::FontData fontData = constructor.getTextFontData(); - bool fontRead = getProperties(cur,fontData); + osgPresentation::SlideShowConstructor::FontData fontData = constructor.getTextFontData(); + bool fontRead = getProperties(cur,fontData); - constructor.addParagraph((const char*)key, - positionRead ? positionData : constructor.getTextPositionData(), - fontRead ? fontData : constructor.getTextFontData()); - } - xmlFree(key); + constructor.addParagraph(cur->contents, + positionRead ? positionData : constructor.getTextPositionData(), + fontRead ? fontData : constructor.getTextFontData()); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"image"))) + else if (cur->name == "image") { - std::string filename; - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) - { - osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); - bool positionRead = getProperties(cur,positionData); + osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); + bool positionRead = getProperties(cur,positionData); - osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData(); - getProperties(cur,imageData); + osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData(); + getProperties(cur,imageData); - constructor.addImage((const char*)key, - positionRead ? positionData : constructor.getImagePositionData(), - imageData); - } + constructor.addImage(cur->contents, + positionRead ? positionData : constructor.getImagePositionData(), + imageData); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"vnc"))) + else if (cur->name == "vnc") { - std::string filename; - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) - { - osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); - bool positionRead = getProperties(cur,positionData); + osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); + bool positionRead = getProperties(cur,positionData); - osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData(); - getProperties(cur,imageData); + osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData(); + getProperties(cur,imageData); - constructor.addVNC((const char*)key, - positionRead ? positionData : constructor.getImagePositionData(), - imageData); - } + constructor.addVNC(cur->contents, + positionRead ? positionData : constructor.getImagePositionData(), + imageData); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"browser"))) + else if (cur->name == "browser") { - std::string filename; - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) - { - osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); - bool positionRead = getProperties(cur,positionData); + osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); + bool positionRead = getProperties(cur,positionData); - osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData(); - getProperties(cur,imageData); + osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData(); + getProperties(cur,imageData); - constructor.addBrowser((const char*)key, - positionRead ? positionData : constructor.getImagePositionData(), - imageData); - } + constructor.addBrowser(cur->contents, + positionRead ? positionData : constructor.getImagePositionData(), + imageData); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"pdf"))) + else if (cur->name == "pdf") { - std::string filename; - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) - { - osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); - bool positionRead = getProperties(cur,positionData); + osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); + bool positionRead = getProperties(cur,positionData); - osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData(); - getProperties(cur,imageData); + osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData(); + getProperties(cur,imageData); - constructor.addPDF((const char*)key, - positionRead ? positionData : constructor.getImagePositionData(), - imageData); - } + constructor.addPDF(cur->contents, + positionRead ? positionData : constructor.getImagePositionData(), + imageData); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"stereo_pair"))) + else if (cur->name == "stereo_pair") { - parseStereoPair(constructor, doc,cur); + parseStereoPair(constructor, cur); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"model"))) + else if (cur->name == "model") { - parseModel(constructor, doc,cur); + parseModel(constructor, cur); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"volume"))) + else if (cur->name == "volume") { - parseVolume(constructor, doc,cur); + parseVolume(constructor, cur); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"duration"))) + else if (cur->name == "duration") { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) constructor.setLayerDuration(atof((const char*)key)); - xmlFree(key); + constructor.setLayerDuration(atof(cur->contents.c_str())); } - else if (getKeyPosition(doc, cur, keyPosition)) + else if (getKeyPosition(cur, keyPosition)) { constructor.addLayerKey(keyPosition); } - cur = cur->next; } if (totalIndent != 0.0f) @@ -1238,179 +1135,157 @@ void ReaderWriterP3DXML::parseLayer(osgPresentation::SlideShowConstructor& const } -void ReaderWriterP3DXML::parseBullets(osgPresentation::SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur, bool inheritPreviousLayers, bool defineAsBaseLayer) const +void ReaderWriterP3DXML::parseBullets(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur, bool inheritPreviousLayers, bool defineAsBaseLayer) const { - xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) - { - constructor.addLayer(inheritPreviousLayers, defineAsBaseLayer); + constructor.addLayer(inheritPreviousLayers, defineAsBaseLayer); - osg::notify(osg::INFO)<<"bullets ["<<(const char*)key<<"]"<contents<<"]"<contents, + positionRead ? positionData : constructor.getTextPositionData(), + fontRead ? fontData : constructor.getTextFontData()); } -void ReaderWriterP3DXML::parseText(osgPresentation::SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur, bool inheritPreviousLayers, bool defineAsBaseLayer) const +void ReaderWriterP3DXML::parseText(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur, bool inheritPreviousLayers, bool defineAsBaseLayer) const { - xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) - { - constructor.addLayer(inheritPreviousLayers, defineAsBaseLayer); + constructor.addLayer(inheritPreviousLayers, defineAsBaseLayer); - osg::notify(osg::INFO)<<"text ["<<(const char*)key<<"]"<contents<<"]"<contents, + positionRead ? positionData : constructor.getTextPositionData(), + fontRead ? fontData : constructor.getTextFontData()); } -void ReaderWriterP3DXML::parsePage(osgPresentation::SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur) const +void ReaderWriterP3DXML::parsePage(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const { - xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) + constructor.addSlide(); + + std::string title; + getProperty(cur, "title", title); + + std::string inherit; + getProperty(cur, "inherit", inherit); + + if (!inherit.empty() && _templateMap.count(inherit)!=0) { - constructor.addSlide(); - - std::string title; - getProperty(cur, "title", title); - - std::string inherit; - getProperty(cur, "inherit", inherit); - - if (!inherit.empty() && _templateMap.count(inherit)!=0) - { - parseSlide(constructor, _templateMap[inherit].first, _templateMap[inherit].second, true, false); - } - - if (!title.empty()) - { - constructor.setSlideTitle(title, - constructor.getTitlePositionData(), - constructor.getTitleFontData()); - } - - if (!inherit.empty() && _templateMap.count(inherit)!=0) - { - parseSlide(constructor, _templateMap[inherit].first, _templateMap[inherit].second, false, true); - } - - constructor.addLayer(true,false); - - osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getTextPositionData(); - bool positionRead = getProperties(cur,positionData); - - osgPresentation::SlideShowConstructor::FontData fontData = constructor.getTextFontData(); - bool fontRead = getProperties(cur,fontData); - - constructor.addParagraph((const char*)key, - positionRead ? positionData : constructor.getTextPositionData(), - fontRead ? fontData : constructor.getTextFontData()); + parseSlide(constructor, _templateMap[inherit].get(), true, false); } - xmlFree(key); + + if (!title.empty()) + { + constructor.setSlideTitle(title, + constructor.getTitlePositionData(), + constructor.getTitleFontData()); + } + + if (!inherit.empty() && _templateMap.count(inherit)!=0) + { + parseSlide(constructor, _templateMap[inherit].get(), false, true); + } + + constructor.addLayer(true,false); + + osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getTextPositionData(); + bool positionRead = getProperties(cur,positionData); + + osgPresentation::SlideShowConstructor::FontData fontData = constructor.getTextFontData(); + bool fontRead = getProperties(cur,fontData); + + constructor.addParagraph(cur->contents, + positionRead ? positionData : constructor.getTextPositionData(), + fontRead ? fontData : constructor.getTextFontData()); } -void ReaderWriterP3DXML::parsePdfDocument(osgPresentation::SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur) const +void ReaderWriterP3DXML::parsePdfDocument(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const { - xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) + std::string title; + getProperty(cur, "title", title); + + std::string inherit; + getProperty(cur, "inherit", inherit); + + constructor.addSlide(); + + if (!inherit.empty() && _templateMap.count(inherit)!=0) { + parseSlide(constructor, _templateMap[inherit].get(), true, false); + } - std::string title; - getProperty(cur, "title", title); + if (!title.empty()) + { + constructor.setSlideTitle(title, + constructor.getTitlePositionData(), + constructor.getTitleFontData()); + } - std::string inherit; - getProperty(cur, "inherit", inherit); - - constructor.addSlide(); - - if (!inherit.empty() && _templateMap.count(inherit)!=0) + if (!inherit.empty() && _templateMap.count(inherit)!=0) + { + parseSlide(constructor, _templateMap[inherit].get(), false, true); + } + + constructor.addLayer(true,false); + + osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); + getProperties(cur,positionData); + + osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData(); + imageData.page = 0; + getProperties(cur,imageData); + + osg::Image* image = constructor.addInteractiveImage(cur->contents, positionData, imageData); + osgWidget::PdfImage* pdfImage = dynamic_cast(image); + if (pdfImage) + { + int numPages = pdfImage->getNumOfPages(); + osg::notify(osg::NOTICE)<<"NumOfPages = "<1) { - parseSlide(constructor, _templateMap[inherit].first, _templateMap[inherit].second, true, false); - } - - if (!title.empty()) - { - constructor.setSlideTitle(title, - constructor.getTitlePositionData(), - constructor.getTitleFontData()); - } - - if (!inherit.empty() && _templateMap.count(inherit)!=0) - { - parseSlide(constructor, _templateMap[inherit].first, _templateMap[inherit].second, false, true); - } - - constructor.addLayer(true,false); - - osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); - getProperties(cur,positionData); - - osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData(); - imageData.page = 0; - getProperties(cur,imageData); - - osg::Image* image = constructor.addInteractiveImage((const char*)key, positionData, imageData); - osgWidget::PdfImage* pdfImage = dynamic_cast(image); - if (pdfImage) - { - int numPages = pdfImage->getNumOfPages(); - osg::notify(osg::NOTICE)<<"NumOfPages = "<1) + for(int pageNum=1; pageNumcontents, positionData, imageData); + } - } } - xmlFree(key); } -void ReaderWriterP3DXML::parseSlide (osgPresentation::SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur, bool parseTitles, bool parseLayers) const +void ReaderWriterP3DXML::parseSlide (osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode* root, bool parseTitles, bool parseLayers) const { osg::Vec4 previous_bgcolor = constructor.getBackgroundColor(); @@ -1419,70 +1294,57 @@ void ReaderWriterP3DXML::parseSlide (osgPresentation::SlideShowConstructor& cons // create a keyPosition just in case we need it. osgPresentation::KeyPosition keyPosition; - xmlChar *key; - cur = cur->xmlChildrenNode; - while (cur != NULL) + for(osgDB::XmlNode::Children::iterator itr = root->children.begin(); + itr != root->children.end(); + ++itr) { + osgDB::XmlNode* cur = itr->get(); + if (parseTitles) { - if ((!xmlStrcmp(cur->name, (const xmlChar *)"title"))) + if (cur->name == "title") { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getTitlePositionData(); + bool positionRead = getProperties(cur,positionData); - if (key) - { - osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getTitlePositionData(); - bool positionRead = getProperties(cur,positionData); + osgPresentation::SlideShowConstructor::FontData fontData = constructor.getTitleFontData(); + bool fontRead = getProperties(cur,fontData); - osgPresentation::SlideShowConstructor::FontData fontData = constructor.getTitleFontData(); - bool fontRead = getProperties(cur,fontData); - - constructor.setSlideTitle((const char*)key, - positionRead ? positionData : constructor.getTitlePositionData(), - fontRead ? fontData : constructor.getTitleFontData()); - - xmlFree(key); - } - else constructor.setSlideTitle("", constructor.getTitlePositionData(), constructor.getTitleFontData()); + constructor.setSlideTitle(cur->contents, + positionRead ? positionData : constructor.getTitlePositionData(), + fontRead ? fontData : constructor.getTitleFontData()); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"background"))) + else if (cur->name == "background") { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) constructor.setSlideBackground((const char*)key); - else constructor.setSlideBackground(""); - xmlFree(key); + constructor.setSlideBackground(cur->contents); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"bgcolor"))) + else if (cur->name == "bgcolor") { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) constructor.setBackgroundColor(mapStringToColor((const char*)key),true); - xmlFree(key); + constructor.setBackgroundColor(mapStringToColor(cur->contents),true); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"textcolor"))) + else if (cur->name == "textcolor") { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) constructor.setTextColor(mapStringToColor((const char*)key)); - xmlFree(key); + constructor.setTextColor(mapStringToColor(cur->contents)); } } if (parseLayers) { - if ((!xmlStrcmp(cur->name, (const xmlChar *)"base"))) + if (cur->name == "base") { constructor.addLayer(true, true); - parseLayer (constructor, doc, cur); + parseLayer (constructor, cur); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"layer"))) + else if (cur->name == "layer") { constructor.addLayer(true, false); - parseLayer (constructor, doc, cur); + parseLayer (constructor, cur); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"clean_layer"))) + else if (cur->name == "clean_layer") { constructor.addLayer(false, false); - parseLayer (constructor, doc, cur); + parseLayer (constructor, cur); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"modify_layer"))) + else if (cur->name == "modify_layer") { int layerNum; if (getProperty(cur, "layer", layerNum)) @@ -1494,24 +1356,21 @@ void ReaderWriterP3DXML::parseSlide (osgPresentation::SlideShowConstructor& cons constructor.addLayer(true, false); } - parseLayer (constructor, doc, cur); + parseLayer (constructor, cur); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"bullets"))) + else if (cur->name == "bullets") { - parseBullets (constructor, doc, cur,true, false); + parseBullets (constructor, cur,true, false); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"duration"))) + else if (cur->name == "duration") { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) constructor.setSlideDuration(atof((const char*)key)); - xmlFree(key); + constructor.setSlideDuration(atof(cur->contents.c_str())); } - else if (getKeyPosition(doc, cur, keyPosition)) + else if (getKeyPosition(cur, keyPosition)) { constructor.addSlideKey(keyPosition); } } - cur = cur->next; } constructor.setBackgroundColor(previous_bgcolor,false); @@ -1520,6 +1379,8 @@ void ReaderWriterP3DXML::parseSlide (osgPresentation::SlideShowConstructor& cons return; } +#include + osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const { @@ -1535,58 +1396,67 @@ osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(const std::string& // create a keyPosition just in case we need it. osgPresentation::KeyPosition keyPosition; - xmlDocPtr doc; - xmlNodePtr cur; + osg::ref_ptr doc = new osgDB::XmlNode; + osgDB::XmlNode* root = 0; - doc = xmlParseFile(fileName.c_str()); + osgDB::XmlNode::Input input; + input.open(fileName); + input.readAllDataIntoBuffer(); - if (doc == NULL ) { + doc->read(input); + + // doc->write(std::cout); + + if (doc == NULL ) + { fprintf(stderr,"Document not parsed successfully. \n"); return ReadResult::FILE_NOT_HANDLED; } - cur = xmlDocGetRootElement(doc); + for(osgDB::XmlNode::Children::iterator itr = doc->children.begin(); + itr != doc->children.end() && !root; + ++itr) + { + if ((*itr)->name=="presentation") root = itr->get(); + } - if (cur == NULL) { + if (root == NULL) + { fprintf(stderr,"empty document\n"); - xmlFreeDoc(doc); return ReadResult::FILE_NOT_HANDLED; } - if (xmlStrcmp(cur->name, (const xmlChar *) "presentation")) { + if (root->name!="presentation") + { fprintf(stderr,"document of the wrong type, root node != presentation"); - xmlFreeDoc(doc); return ReadResult::FILE_NOT_HANDLED; } osgPresentation::SlideShowConstructor constructor; - + osgDB::FilePathList previousPaths = osgDB::getDataFilePathList(); - + bool readSlide = false; - - - xmlChar *key; - cur = cur->xmlChildrenNode; - while (cur != NULL) { + for(osgDB::XmlNode::Children::iterator itr = root->children.begin(); + itr != root->children.end(); + ++itr) + { + osgDB::XmlNode* cur = itr->get(); - if ((!xmlStrcmp(cur->name, (const xmlChar *)"name"))) + if (cur->name == "name") { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) constructor.setPresentationName((const char*)key); - else constructor.setPresentationName(""); - xmlFree(key); + constructor.setPresentationName(cur->contents); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"loop"))) + else if (cur->name == "loop") { constructor.setLoopPresentation(true); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"auto"))) + else if (cur->name == "auto") { constructor.setAutoSteppingActive(true); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"title-settings"))) + else if (cur->name == "title-settings") { bool fontRead = getProperties(cur,constructor.getTitleFontDataDefault()); if (fontRead) @@ -1594,7 +1464,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(const std::string& osg::notify(osg::INFO)<<"Title font details read"<name, (const xmlChar *)"text-settings"))) + else if (cur->name == "text-settings") { bool fontRead = getProperties(cur,constructor.getTextFontDataDefault()); if (fontRead) @@ -1602,51 +1472,40 @@ osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(const std::string& osg::notify(osg::INFO)<<"Text font details read"<name, (const xmlChar *)"ratio"))) + /*else if (cur->name == "ratio") { key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) constructor.setPresentationAspectRatio((const char*)key); + if (key) constructor.setPresentationAspectRatio(cur->contents); xmlFree(key); }*/ - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"path"))) + else if (cur->name == "path") { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) - { - osg::notify(osg::INFO)<<"Appending search path "<<(char*)key<contents<contents)); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"bgcolor"))) + else if (cur->name == "bgcolor") { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) constructor.setBackgroundColor(mapStringToColor((const char*)key),false); - xmlFree(key); + constructor.setBackgroundColor(mapStringToColor(cur->contents),false); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"textcolor"))) + else if (cur->name == "textcolor") { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) constructor.setTextColor(mapStringToColor((const char*)key)); - xmlFree(key); + constructor.setTextColor(mapStringToColor(cur->contents)); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"duration"))) + else if (cur->name == "duration") { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) constructor.setPresentationDuration(atof((const char*)key)); - xmlFree(key); + constructor.setPresentationDuration(atof(cur->contents.c_str())); } - else if (getKeyPosition(doc, cur, keyPosition)) + else if (getKeyPosition(cur, keyPosition)) { constructor.addPresentationKey(keyPosition); } - else if (readOnlyHoldingPage && (!xmlStrcmp(cur->name, (const xmlChar *)"holding_slide"))) + else if (readOnlyHoldingPage && cur->name == "holding_slide") { readSlide = true; constructor.addSlide(); - parseSlide (constructor, doc, cur); + parseSlide (constructor, cur); } - else if (!readOnlyHoldingPage && (!xmlStrcmp(cur->name, (const xmlChar *)"slide"))) + else if (!readOnlyHoldingPage && cur->name == "slide") { readSlide = true; constructor.addSlide(); @@ -1654,58 +1513,54 @@ osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(const std::string& std::string inherit; if (getProperty(cur, "inherit", inherit) && !inherit.empty() && _templateMap.count(inherit)!=0) { - parseSlide(constructor, _templateMap[inherit].first, _templateMap[inherit].second, true, false); - parseSlide (constructor, doc, cur, true, false); - parseSlide(constructor, _templateMap[inherit].first, _templateMap[inherit].second, false, true); - parseSlide (constructor, doc, cur, false, true); + parseSlide(constructor, _templateMap[inherit].get(), true, false); + parseSlide (constructor, cur, true, false); + parseSlide(constructor, _templateMap[inherit].get(), false, true); + parseSlide (constructor, cur, false, true); } else { - parseSlide (constructor, doc, cur); + parseSlide (constructor, cur); } } - else if (!readOnlyHoldingPage && (!xmlStrcmp(cur->name, (const xmlChar *)"modify_slide"))) + else if (!readOnlyHoldingPage && cur->name == "modify_slide") { readSlide = true; int slideNum; if (getProperty(cur, "slide", slideNum)) { constructor.selectSlide(slideNum); - parseSlide (constructor, doc, cur); + parseSlide (constructor, cur); } else { constructor.addSlide(); } } - else if (!readOnlyHoldingPage && (!xmlStrcmp(cur->name, (const xmlChar *)"page"))) + else if (!readOnlyHoldingPage && cur->name == "page") { readSlide = true; - parsePage (constructor, doc, cur); + parsePage (constructor, cur); } - else if (!readOnlyHoldingPage && (!xmlStrcmp(cur->name, (const xmlChar *)"pdf_document"))) + else if (!readOnlyHoldingPage && cur->name == "pdf_document") { readSlide = true; - parsePdfDocument(constructor, doc, cur); + parsePdfDocument(constructor, cur); } - else if (!readOnlyHoldingPage && (!xmlStrcmp(cur->name, (const xmlChar *)"template_slide"))) + else if (!readOnlyHoldingPage && cur->name == "template_slide") { readSlide = true; std::string name; if (getProperty(cur, "name", name)) { - _templateMap[name] = DocNodePair(doc,cur); + _templateMap[name] = cur; std::cout<<"Defining template slide "<next; } - xmlFreeDoc(doc); - + osgDB::getDataFilePathList() = previousPaths; - return constructor.takePresentation(); /* diff --git a/include/osgDB/XmlParser b/include/osgDB/XmlParser new file mode 100644 index 000000000..97d43ec05 --- /dev/null +++ b/include/osgDB/XmlParser @@ -0,0 +1,135 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#ifndef OSGDB_XML_PARSER +#define OSGDB_XML_PARSER 1 + +#include + +namespace osgDB { + +// forward declare +class XmlNode; + +/** read an Xml file, find the file in ReaderWriter::Options DataFilePathList.*/ +extern OSGDB_EXPORT XmlNode* readXmlFile(const std::string& filename,const ReaderWriter::Options* options); + +/** read an Xml file, find the file in osgDB::Registry's eaderWriter::Options DataFilePathList.*/ +inline XmlNode* readXmlFile(const std::string& filename) +{ + return readXmlFile(filename, osgDB::Registry::instance()->getOptions()); +} + +/** read an Xml from from an istream.*/ +extern OSGDB_EXPORT XmlNode* readXmlStream(std::istream& fin); + +/** XmlNode class for very basic reading and writing of xml files.*/ +class XmlNode : public osg::Referenced +{ + public: + + XmlNode(); + + enum NodeType + { + UNASSIGNED, + ATOM, + NODE, + GROUP, + ROOT, + COMMENT, + INFORMATION + }; + + typedef std::map< std::string, std::string > Properties; + typedef std::vector< osg::ref_ptr > Children; + + NodeType type; + std::string name; + std::string contents; + Properties properties; + Children children; + + public: + + class Input + { + public: + + Input(); + Input(const Input&); + + ~Input(); + + typedef std::string::size_type size_type; + + void open(const std::string& filename); + void attach(std::istream& istream); + + void readAllDataIntoBuffer(); + + operator bool () const { return _currentPos<_buffer.size(); } + + int get() { if (_currentPos<_buffer.size()) return _buffer[_currentPos++]; else return -1; } + + int operator [] (size_type i) const { if ((_currentPos+i)<_buffer.size()) return _buffer[_currentPos+i]; else return -1; } + + void operator ++ () { if (_currentPos<_buffer.size()) ++_currentPos; } + + void operator += (size_type n) { if ((_currentPos+n)<_buffer.size()) _currentPos+=n; else _currentPos = _buffer.size(); } + + void skipWhiteSpace(); + + std::string substr(size_type pos, size_type n=std::string::npos) { return (_currentPos<_buffer.size()) ? _buffer.substr(_currentPos+pos,n) : std::string(); } + + size_type find(const std::string& str) + { + if (_currentPos<_buffer.size()) + { + size_type pos = _buffer.find(str, _currentPos); + if (pos==std::string::npos) return std::string::npos; + else return pos-_currentPos; + } else return std::string::npos; + } + + bool match(const std::string& str) { return (_currentPos<_buffer.size()) ? _buffer.compare(_currentPos, str.size(), str)==0 : false; } + + + typedef std::map< std::string, int > ControlToCharacterMap; + typedef std::map< int, std::string> CharacterToControlMap; + + void addControlToCharacter(const std::string& control, int c); + + ControlToCharacterMap _controlToCharacterMap; + CharacterToControlMap _characterToControlMap; + + private: + + void setUpControlMappings(); + + size_type _currentPos; + + std::ifstream _fin; + std::string _buffer; + + }; + + bool read(Input& input); + + bool write(std::ostream& fout) const; + bool writeString(std::ostream& fout, const std::string& str) const; + +}; + +} +#endif \ No newline at end of file diff --git a/src/osgDB/CMakeLists.txt b/src/osgDB/CMakeLists.txt index 52ba60091..88e24c2bf 100644 --- a/src/osgDB/CMakeLists.txt +++ b/src/osgDB/CMakeLists.txt @@ -46,6 +46,7 @@ SET(LIB_PUBLIC_HEADERS ${HEADER_PATH}/SharedStateManager ${HEADER_PATH}/Version ${HEADER_PATH}/WriteFile + ${HEADER_PATH}/XmlParser ) # FIXME: For OS X, need flag for Framework or dylib @@ -77,6 +78,7 @@ ADD_LIBRARY(${LIB_NAME} SharedStateManager.cpp Version.cpp WriteFile.cpp + XmlParser.cpp ${OPENSCENEGRAPH_VERSIONINFO_RC} ) diff --git a/src/osgDB/DynamicLibrary.cpp b/src/osgDB/DynamicLibrary.cpp index e71d74ee2..7f00259f6 100644 --- a/src/osgDB/DynamicLibrary.cpp +++ b/src/osgDB/DynamicLibrary.cpp @@ -139,7 +139,7 @@ DynamicLibrary::PROC_ADDRESS DynamicLibrary::getProcAddress(const std::string& p if (_handle==NULL) return NULL; #if defined(WIN32) && !defined(__CYGWIN__) return (DynamicLibrary::PROC_ADDRESS)GetProcAddress( (HMODULE)_handle, - procName.c_str() ); + procName.c_str() ); /* FIX WARNING */ #elif defined(__APPLE__) && defined(APPLE_PRE_10_3) std::string temp("_"); NSSymbol symbol; diff --git a/src/osgDB/XmlParser.cpp b/src/osgDB/XmlParser.cpp new file mode 100644 index 000000000..7b0f8766d --- /dev/null +++ b/src/osgDB/XmlParser.cpp @@ -0,0 +1,415 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#include +#include + +#include + +using namespace osgDB; + +XmlNode* osgDB::readXmlFile(const std::string& filename,const ReaderWriter::Options* options) +{ + std::string foundFile = osgDB::findDataFile(filename, options); + if (!foundFile.empty()) + { + XmlNode::Input input; + input.open(foundFile); + if (!input) + { + osg::notify(osg::NOTICE)<<"Could not open XML file: "< root = new XmlNode; + root->read(input); + + return root.release(); + } + else + { + osg::notify(osg::NOTICE)<<"Could not find XML file: "< root = new XmlNode; + root->read(input); + + return root.release(); +} + + +XmlNode::Input::Input(): + _currentPos(0) +{ + setUpControlMappings(); +} + +XmlNode::Input::Input(const Input&): + _currentPos(0) +{ + setUpControlMappings(); +} + +XmlNode::Input::~Input() +{ +} + +void XmlNode::Input::setUpControlMappings() +{ + addControlToCharacter("&",'&'); + addControlToCharacter("<",'<'); + addControlToCharacter(">",'>'); + addControlToCharacter(""",'"'); + addControlToCharacter("'",'\''); +} + +void XmlNode::Input::addControlToCharacter(const std::string& control, int c) +{ + _controlToCharacterMap[control] = c; + _characterToControlMap[c] = control; +} + +void XmlNode::Input::open(const std::string& filename) +{ + _fin.open(filename.c_str()); +} + +void XmlNode::Input::attach(std::istream& fin) +{ + std::ios &fios = _fin; + fios.rdbuf(fin.rdbuf()); +} + +void XmlNode::Input::readAllDataIntoBuffer() +{ + while(_fin) + { + int c = _fin.get(); + if (c>=0 && c<=255) + { + _buffer.push_back(c); + } + } +} + +void XmlNode::Input::skipWhiteSpace() +{ + while(_currentPos<_buffer.size() && _buffer[_currentPos]==' ') ++_currentPos; +} + +XmlNode::XmlNode() +{ + type = UNASSIGNED; +} + +bool XmlNode::read(Input& input) +{ + if (type == UNASSIGNED) type = ROOT; + + while(input) + { + //input.skipWhiteSpace(); + if (input.match(""); + commentNode->contents = input.substr(0, end); + if (end!=std::string::npos) + { + osg::notify(osg::INFO)<<"Valid Comment record ["<contents<<"]"<contents<<"]"<"); + std::string comment = input.substr(0, end); + if (end!=std::string::npos) + { + osg::notify(osg::INFO)<<"Valid end tag ["<type = XmlNode::INFORMATION; + children.push_back(commentNode); + + input += 2; + XmlNode::Input::size_type end = input.find("?>"); + commentNode->contents = input.substr(0, end); + if (end!=std::string::npos) + { + osg::notify(osg::INFO)<<"Valid infomation record ["<contents<<"]"<contents<<"]"<type = XmlNode::NODE; + children.push_back(childNode); + + input += 1; + + input.skipWhiteSpace(); + + int c = 0; + while ((c=input[0])>=0 && c!=' ' && c!='>' ) + { + childNode->name.push_back(c); + ++input; + } + + while ((c=input[0])>=0 && c!='>') + { + input.skipWhiteSpace(); + std::string option; + std::string value; + while((c=input[0])>=0 && c!='>' && c!='"' && c!='\'' && c!='=') + { + option.push_back(c); + ++input; + } + input.skipWhiteSpace(); + if (input[0]=='=') + { + ++input; + if (input[0]=='"') + { + ++input; + while((c=input[0])>=0 && c!='"') + { + value.push_back(c); + ++input; + } + ++input; + } + else if (input[0]=='\'') + { + ++input; + while((c=input[0])>=0 && c!='\'') + { + value.push_back(c); + ++input; + } + ++input; + } + else + { + ++input; + while((c=input[0])>=0 && c!=' ' && c!='"' && c!='\'' && c!='>') + { + value.push_back(c); + ++input; + } + } + } + + if (!option.empty()) + { + osg::notify(osg::INFO)<<"Assigning option "<properties[option] = value; + } + } + + if ((c=input[0])>=0 && c=='>' ) + { + ++input; + + osg::notify(osg::INFO)<<"Valid tag ["<name<<"]"<read(input); + if (!result) return false; + + if (type==NODE && !children.empty()) type = GROUP; + } + else + { + osg::notify(osg::NOTICE)<<"Unclosed tag ["<name<<"]"<first<<"\""; + writeString(fout,oitr->second); + fout<<"\""<write(fout); + } + return true; + } + case(NODE): + { + fout<<"<"<first<<"=\""; + writeString(fout,oitr->second); + fout<<"\""; + } + fout<<">"; + + for(Children::const_iterator citr = children.begin(); + citr != children.end(); + ++citr) + { + (*citr)->write(fout); + } + + if (!contents.empty()) writeString(fout,contents); + + fout<<""<first<<"=\""; + writeString(fout,oitr->second); + fout<<"\""; + } + fout<<">"<write(fout); + } + + fout<<""<"<"< #include -PickEventHandler::PickEventHandler(SlideShowConstructor::Operation operation,bool relativeJump, int slideNum, int layerNum): +using namespace osgPresentation; + +PickEventHandler::PickEventHandler(osgPresentation::Operation operation,bool relativeJump, int slideNum, int layerNum): _operation(operation), _relativeJump(relativeJump), _slideNum(slideNum), @@ -25,7 +27,7 @@ PickEventHandler::PickEventHandler(SlideShowConstructor::Operation operation,boo { } -PickEventHandler::PickEventHandler(const std::string& str, SlideShowConstructor::Operation operation,bool relativeJump, int slideNum, int layerNum): +PickEventHandler::PickEventHandler(const std::string& str, osgPresentation::Operation operation,bool relativeJump, int slideNum, int layerNum): _command(str), _operation(operation), _relativeJump(relativeJump), @@ -34,9 +36,9 @@ PickEventHandler::PickEventHandler(const std::string& str, SlideShowConstructor: { } -PickEventHandler::PickEventHandler(const SlideShowConstructor::KeyPosition& keyPos,bool relativeJump, int slideNum, int layerNum): +PickEventHandler::PickEventHandler(const osgPresentation::KeyPosition& keyPos,bool relativeJump, int slideNum, int layerNum): _keyPos(keyPos), - _operation(SlideShowConstructor::EVENT), + _operation(osgPresentation::EVENT), _relativeJump(relativeJump), _slideNum(slideNum), _layerNum(layerNum) @@ -114,13 +116,12 @@ void PickEventHandler::doOperation() { switch(_operation) { - case(SlideShowConstructor::RUN): + case(osgPresentation::RUN): { osg::notify(osg::NOTICE)<<"Run "<<_command<dispatchEvent(_keyPos); break; } + case(osgPresentation::JUMP): + { + osg::notify(osg::NOTICE)<<"Requires jump "< -#include "SlideShowConstructor.h" +#include "SlideEventHandler.h" + +namespace osgPresentation +{ class PickEventHandler : public osgGA::GUIEventHandler { public: - PickEventHandler(SlideShowConstructor::Operation operation, bool relativeJump=true, int slideNum=0, int layerNum=0); - PickEventHandler(const std::string& str, SlideShowConstructor::Operation operation, bool relativeJump=true, int slideNum=0, int layerNum=0); - PickEventHandler(const SlideShowConstructor::KeyPosition& keyPos, bool relativeJump=true, int slideNum=0, int layerNum=0); + PickEventHandler(osgPresentation::Operation operation, bool relativeJump=true, int slideNum=0, int layerNum=0); + PickEventHandler(const std::string& str, osgPresentation::Operation operation, bool relativeJump=true, int slideNum=0, int layerNum=0); + PickEventHandler(const osgPresentation::KeyPosition& keyPos, bool relativeJump=true, int slideNum=0, int layerNum=0); - void setOperation(SlideShowConstructor::Operation operation) { _operation = operation; } - SlideShowConstructor::Operation getOperation() const { return _operation; } + void setOperation(osgPresentation::Operation operation) { _operation = operation; } + osgPresentation::Operation getOperation() const { return _operation; } void setCommand(const std::string& str) { _command = str; } const std::string& getCommand() const { return _command; } - void setKeyPosition(const SlideShowConstructor::KeyPosition& keyPos) { _keyPos = keyPos; } - const SlideShowConstructor::KeyPosition& getKeyPosition() const { return _keyPos; } + void setKeyPosition(const osgPresentation::KeyPosition& keyPos) { _keyPos = keyPos; } + const osgPresentation::KeyPosition& getKeyPosition() const { return _keyPos; } void setRelativeJump(int slideDelta, int layerDelta); void setAbsoluteJump(int slideNum, int layerNum); @@ -55,12 +58,14 @@ class PickEventHandler : public osgGA::GUIEventHandler void doOperation(); std::string _command; - SlideShowConstructor::KeyPosition _keyPos; - SlideShowConstructor::Operation _operation; + osgPresentation::KeyPosition _keyPos; + osgPresentation::Operation _operation; bool _relativeJump; int _slideNum; int _layerNum; }; +} + #endif diff --git a/src/osgPlugins/p3d/ReaderWriterP3D.cpp b/src/osgPlugins/p3d/ReaderWriterP3D.cpp index caffa9e8a..b0fe3a5db 100644 --- a/src/osgPlugins/p3d/ReaderWriterP3D.cpp +++ b/src/osgPlugins/p3d/ReaderWriterP3D.cpp @@ -21,19 +21,17 @@ #include #include "SlideShowConstructor.h" -#include "SlideEventHandler.h" #include #include #include -#include -#include + +#include #include #include - /** * OpenSceneGraph plugin wrapper/converter. */ @@ -113,22 +111,22 @@ public: virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const; - void parseModel(SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur) const; + void parseModel(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const; - void parseVolume(SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur) const; + void parseVolume(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const; - void parseStereoPair(SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur) const; + void parseStereoPair(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const; - void parseLayer(SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur) const; + void parseLayer(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const; - void parseBullets(SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur, bool inheritPreviousLayers, bool defineAsBaseLayer) const; - void parseText(SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur, bool inheritPreviousLayers, bool defineAsBaseLayer) const; + void parseBullets(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur, bool inheritPreviousLayers, bool defineAsBaseLayer) const; + void parseText(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur, bool inheritPreviousLayers, bool defineAsBaseLayer) const; - void parsePage (SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur) const; + void parsePage (osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const; - void parseSlide (SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur, bool parseTitles=true, bool parseLayers=true) const; + void parseSlide (osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur, bool parseTitles=true, bool parseLayers=true) const; - void parsePdfDocument (SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur) const; + void parsePdfDocument (osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const; osg::Vec4 mapStringToColor(const std::string& str) const { @@ -165,25 +163,25 @@ public: inline bool read(const std::string& str, osg::Vec3& value) const; inline bool read(const std::string& str, osg::Vec4& value) const; - bool getProperty(xmlNodePtr cur, const char* token) const; - bool getProperty(xmlNodePtr cur, const char* token, int& value) const; - bool getProperty(xmlNodePtr cur, const char* token, float& value) const; - bool getProperty(xmlNodePtr cur, const char* token, double& value) const; - bool getProperty(xmlNodePtr cur, const char* token, osg::Vec2& value) const; - bool getProperty(xmlNodePtr cur, const char* token, osg::Vec3& value) const; - bool getProperty(xmlNodePtr cur, const char* token, osg::Vec4& value) const; - bool getProperty(xmlNodePtr cur, const char* token, std::string& value) const; - bool getProperty(xmlNodePtr cur, const char* token, osgText::Text::Layout& value) const; - bool getProperty(xmlNodePtr cur, const char* token, osgText::Text::AlignmentType& value) const; + bool getProperty(osgDB::XmlNode*cur, const char* token) const; + bool getProperty(osgDB::XmlNode*cur, const char* token, int& value) const; + bool getProperty(osgDB::XmlNode*cur, const char* token, float& value) const; + bool getProperty(osgDB::XmlNode*cur, const char* token, double& value) const; + bool getProperty(osgDB::XmlNode*cur, const char* token, osg::Vec2& value) const; + bool getProperty(osgDB::XmlNode*cur, const char* token, osg::Vec3& value) const; + bool getProperty(osgDB::XmlNode*cur, const char* token, osg::Vec4& value) const; + bool getProperty(osgDB::XmlNode*cur, const char* token, std::string& value) const; + bool getProperty(osgDB::XmlNode*cur, const char* token, osgText::Text::Layout& value) const; + bool getProperty(osgDB::XmlNode*cur, const char* token, osgText::Text::AlignmentType& value) const; - bool getProperties(xmlNodePtr cur, SlideShowConstructor::PositionData& value) const; - bool getProperties(xmlNodePtr cur, SlideShowConstructor::FontData& value) const; - bool getProperties(xmlNodePtr cur, SlideShowConstructor::ModelData& value) const; - bool getProperties(xmlNodePtr cur, SlideShowConstructor::ImageData& value) const; - bool getJumpProperties(xmlNodePtr cur, bool& relativeJump, int& slideNum, int& layerNum) const; + bool getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::PositionData& value) const; + bool getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::FontData& value) const; + bool getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::ModelData& value) const; + bool getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::ImageData& value) const; + bool getJumpProperties(osgDB::XmlNode*cur, bool& relativeJump, int& slideNum, int& layerNum) const; - bool getKeyPositionInner(xmlDocPtr doc, xmlNodePtr cur, SlideShowConstructor::KeyPosition& keyPosition) const; - bool getKeyPosition(xmlDocPtr doc, xmlNodePtr cur, SlideShowConstructor::KeyPosition& keyPosition) const; + bool getKeyPositionInner(osgDB::XmlNode*cur, osgPresentation::KeyPosition& keyPosition) const; + bool getKeyPosition(osgDB::XmlNode*cur, osgPresentation::KeyPosition& keyPosition) const; typedef std::map ColorMap; typedef std::map LayoutMap; @@ -198,9 +196,7 @@ public: AlignmentMap _alignmentMap; StringKeyMap _stringKeyMap; - typedef std::pair DocNodePair; - typedef std::map TemplateMap; - + typedef std::map > TemplateMap; mutable TemplateMap _templateMap; osg::NotifySeverity _notifyLevel; @@ -329,123 +325,90 @@ bool ReaderWriterP3DXML::read(const std::string& str, osg::Vec4& value) const return !iss.fail(); } -bool ReaderWriterP3DXML::getProperty(xmlNodePtr cur, const char* token) const +bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode* cur, const char* token) const { - bool success = false; - xmlChar *key; - key = xmlGetProp (cur, (const xmlChar *)token); - if (key) success=true; - xmlFree(key); - return success; + return cur->properties.count(token)!=0; } -bool ReaderWriterP3DXML::getProperty(xmlNodePtr cur, const char* token, int& value) const +bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, int& value) const { - xmlChar *key; - key = xmlGetProp (cur, (const xmlChar *)token); - bool success = read((const char*)key,value); - xmlFree(key); - return success; + osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token); + if (itr==cur->properties.end()) return false; + return read(itr->second,value); } -bool ReaderWriterP3DXML::getProperty(xmlNodePtr cur, const char* token, float& value) const +bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, float& value) const { - xmlChar *key; - key = xmlGetProp (cur, (const xmlChar *)token); - bool success = read((const char*)key,value); - xmlFree(key); - return success; + osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token); + if (itr==cur->properties.end()) return false; + return read(itr->second,value); } -bool ReaderWriterP3DXML::getProperty(xmlNodePtr cur, const char* token, double& value) const +bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, double& value) const { - xmlChar *key; - key = xmlGetProp (cur, (const xmlChar *)token); - bool success = read((const char*)key,value); - xmlFree(key); - return success; + osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token); + if (itr==cur->properties.end()) return false; + return read(itr->second,value); } -bool ReaderWriterP3DXML::getProperty(xmlNodePtr cur, const char* token, osg::Vec2& value) const +bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, osg::Vec2& value) const { - xmlChar *key; - key = xmlGetProp (cur, (const xmlChar *)token); - bool success = read((const char*)key,value); - xmlFree(key); - return success; + osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token); + if (itr==cur->properties.end()) return false; + return read(itr->second,value); } -bool ReaderWriterP3DXML::getProperty(xmlNodePtr cur, const char* token, osg::Vec3& value) const +bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, osg::Vec3& value) const { - xmlChar *key; - key = xmlGetProp (cur, (const xmlChar *)token); - bool success = read((const char*)key,value); - xmlFree(key); - return success; + osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token); + if (itr==cur->properties.end()) return false; + return read(itr->second,value); } -bool ReaderWriterP3DXML::getProperty(xmlNodePtr cur, const char* token, osg::Vec4& value) const +bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, osg::Vec4& value) const { - xmlChar *key; - key = xmlGetProp (cur, (const xmlChar *)token); - bool success = read((const char*)key,value); - xmlFree(key); - return success; + osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token); + if (itr==cur->properties.end()) return false; + return read(itr->second,value); } -bool ReaderWriterP3DXML::getProperty(xmlNodePtr cur, const char* token, std::string& value) const +bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, std::string& value) const { - bool success = false; - xmlChar *key; - key = xmlGetProp (cur, (const xmlChar *)token); - if (key) + osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token); + if (itr==cur->properties.end()) return false; + value = itr->second; + return true; +} + +bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, osgText::Text::Layout& value) const +{ + osgDB::XmlNode::Properties::iterator pitr = cur->properties.find(token); + if (pitr==cur->properties.end()) return false; + + const std::string& str = pitr->second; + LayoutMap::const_iterator itr = _layoutMap.find(str); + if (itr!=_layoutMap.end()) { - success = true; - value = (const char*)key; + value = itr->second; } - xmlFree(key); - return success; + return true; } -bool ReaderWriterP3DXML::getProperty(xmlNodePtr cur, const char* token, osgText::Text::Layout& value) const +bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, osgText::Text::AlignmentType& value) const { - bool success = false; - xmlChar *key; - key = xmlGetProp (cur, (const xmlChar *)token); - if (key) + osgDB::XmlNode::Properties::iterator pitr = cur->properties.find(token); + if (pitr==cur->properties.end()) return false; + + const std::string& str = pitr->second; + AlignmentMap::const_iterator itr = _alignmentMap.find(str); + if (itr!=_alignmentMap.end()) { - success = true; - std::string str = (const char*)key; - LayoutMap::const_iterator itr = _layoutMap.find(str); - if (itr!=_layoutMap.end()) - { - value = itr->second; - } + value = itr->second; } - xmlFree(key); - return success; + return true; } -bool ReaderWriterP3DXML::getProperty(xmlNodePtr cur, const char* token, osgText::Text::AlignmentType& value) const -{ - bool success = false; - xmlChar *key; - key = xmlGetProp (cur, (const xmlChar *)token); - if (key) - { - success = true; - std::string str = (const char*)key; - AlignmentMap::const_iterator itr = _alignmentMap.find(str); - if (itr!=_alignmentMap.end()) - { - value = itr->second; - } - } - xmlFree(key); - return success; -} - -bool ReaderWriterP3DXML::getProperties(xmlNodePtr cur, SlideShowConstructor::PositionData& value) const +bool ReaderWriterP3DXML::getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::PositionData& value) const { bool propertiesRead=false; @@ -462,14 +425,14 @@ bool ReaderWriterP3DXML::getProperties(xmlNodePtr cur, SlideShowConstructor::Pos { propertiesRead = true; - if (str=="model") value.frame = SlideShowConstructor::MODEL; - else if (str=="slide") value.frame = SlideShowConstructor::SLIDE; + if (str=="model") value.frame = osgPresentation::SlideShowConstructor::MODEL; + else if (str=="slide") value.frame = osgPresentation::SlideShowConstructor::SLIDE; else osg::notify(_notifyLevel)<<"Parser error - coordinate_frame=\""<xmlChildrenNode, 1); - if (key) filename = (const char*)key; - xmlFree(key); - - if (!filename.empty()) + std::string filename = cur->contents; + + if (!filename.empty()) { constructor.addModel(filename, positionRead ? positionData : constructor.getModelPositionData(), modelData); } - } -void ReaderWriterP3DXML::parseVolume(SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur) const +void ReaderWriterP3DXML::parseVolume(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const { - SlideShowConstructor::PositionData positionData = constructor.getModelPositionData(); + osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getModelPositionData(); bool positionRead = getProperties(cur,positionData); - std::string filename; - xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) filename = (const char*)key; - xmlFree(key); - + std::string filename = cur->contents; + if (!filename.empty()) { constructor.addVolume(filename, @@ -881,42 +837,34 @@ void ReaderWriterP3DXML::parseVolume(SlideShowConstructor& constructor, xmlDocPt } } -void ReaderWriterP3DXML::parseStereoPair(SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur) const +void ReaderWriterP3DXML::parseStereoPair(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const { std::string filenameLeft; std::string filenameRight; - SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); + osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); bool positionRead = getProperties(cur,positionData); - SlideShowConstructor::ImageData imageDataLeft;// = constructor.getImageData(); - SlideShowConstructor::ImageData imageDataRight;// = constructor.getImageData(); + osgPresentation::SlideShowConstructor::ImageData imageDataLeft;// = constructor.getImageData(); + osgPresentation::SlideShowConstructor::ImageData imageDataRight;// = constructor.getImageData(); - xmlChar *key; - cur = cur->xmlChildrenNode; - - while (cur != NULL) + for(osgDB::XmlNode::Children::iterator itr = cur->children.begin(); + itr != cur->children.end(); + ++itr) { - if ((!xmlStrcmp(cur->name, (const xmlChar *)"image_left"))) + osgDB::XmlNode* child = itr->get(); + + if (child->name == "image_left") { - getProperties(cur,imageDataLeft); - - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) filenameLeft = (const char*)key; - xmlFree(key); - - + getProperties(child,imageDataLeft); + filenameLeft = child->name; } - if ((!xmlStrcmp(cur->name, (const xmlChar *)"image_right"))) + if (cur->name == "image_right") { + getProperties(child,imageDataRight); + filenameRight = child->name; getProperties(cur,imageDataRight); - - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) filenameRight = (const char*)key; - xmlFree(key); - } - cur = cur->next; } if (!filenameLeft.empty() && !filenameRight.empty()) @@ -926,15 +874,15 @@ void ReaderWriterP3DXML::parseStereoPair(SlideShowConstructor& constructor, xmlD } -bool ReaderWriterP3DXML::getKeyPosition(xmlDocPtr doc, xmlNodePtr cur, SlideShowConstructor::KeyPosition& keyPosition) const +bool ReaderWriterP3DXML::getKeyPosition(osgDB::XmlNode*cur, osgPresentation::KeyPosition& keyPosition) const { - if ((!xmlStrcmp(cur->name, (const xmlChar *)"key"))) + if (cur->name == "key") { - return getKeyPositionInner(doc, cur, keyPosition); + return getKeyPositionInner(cur, keyPosition); } - if ((!xmlStrcmp(cur->name, (const xmlChar *)"escape")) || - (!xmlStrcmp(cur->name, (const xmlChar *)"esc")) || - (!xmlStrcmp(cur->name, (const xmlChar *)"exit"))) + if (cur->name == "escape" || + cur->name == "esc" || + cur->name == "exit") { keyPosition.set(osgGA::GUIEventAdapter::KEY_Escape, 0.0f, 0.0f); return true; @@ -942,7 +890,7 @@ bool ReaderWriterP3DXML::getKeyPosition(xmlDocPtr doc, xmlNodePtr cur, SlideShow return false; } -bool ReaderWriterP3DXML::getKeyPositionInner(xmlDocPtr doc, xmlNodePtr cur, SlideShowConstructor::KeyPosition& keyPosition) const +bool ReaderWriterP3DXML::getKeyPositionInner(osgDB::XmlNode*cur, osgPresentation::KeyPosition& keyPosition) const { // x in range -1 to 1, from left to right float x = FLT_MAX; @@ -966,60 +914,51 @@ bool ReaderWriterP3DXML::getKeyPositionInner(xmlDocPtr doc, xmlNodePtr cur, Slid y = v*2.0f-1.0f; } - xmlChar* key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) + + std::string key = cur->contents; + unsigned int keyValue = 0; + + StringKeyMap::const_iterator itr=_stringKeyMap.find(key); + if (itr != _stringKeyMap.end()) { - - unsigned int keyValue = 0; - - StringKeyMap::const_iterator itr=_stringKeyMap.find((const char*)key); - if (itr != _stringKeyMap.end()) - { - keyValue = itr->second; - } - else if (strlen((const char*)key)==1) - { - keyValue = key[0]; - } - else - { - osg::notify(osg::NOTICE)<<"Warning: unreconginized key sequence '"<<(const char*) key<<"'"<second; + } + else if (key.length()==1) + { + keyValue = key[0]; + } + else + { + osg::notify(osg::NOTICE)<<"Warning: unreconginized key sequence '"<xmlChildrenNode; - while (cur != NULL) + for(osgDB::XmlNode::Children::iterator itr = root->children.begin(); + itr != root->children.end(); + ++itr) { - if ((!xmlStrcmp(cur->name, (const xmlChar *)"run"))) + osgDB::XmlNode* cur = itr->get(); + if (cur->name == "run") { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) - { - osg::notify(osg::INFO)<<"run ["<<(const char*)key<<"]"<contents<<"]"<contents); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"jump"))) + else if (cur->name == "jump") { osg::notify(osg::NOTICE)<<"Parsed Jump "<name, (const xmlChar *)"click_to_run"))) + else if (cur->name == "click_to_run") { bool relativeJump = true; int slideNum = 0; int layerNum = 0; getJumpProperties(cur, relativeJump, slideNum, layerNum); - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) - { - osg::notify(osg::INFO)<<"click_to_run ["<<(const char*)key<<"]"<contents<<"]"<contents,osgPresentation::RUN, relativeJump, slideNum, layerNum); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"click_to_load"))) + else if (cur->name == "click_to_load") { bool relativeJump = true; int slideNum = 0; int layerNum = 0; getJumpProperties(cur, relativeJump, slideNum, layerNum); - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) - { - osg::notify(osg::INFO)<<"click_to_load ["<<(const char*)key<<"]"<contents<<"]"<contents,osgPresentation::LOAD, relativeJump, slideNum, layerNum); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"click_to_event"))) + else if (cur->name == "click_to_event") { bool relativeJump = true; int slideNum = 0; int layerNum = 0; getJumpProperties(cur, relativeJump, slideNum, layerNum); - if (getKeyPositionInner(doc, cur, keyPosition)) + if (getKeyPositionInner( cur, keyPosition)) { osg::notify(osg::INFO)<<"click_to_event ["<name, (const xmlChar *)"click_to_jump"))) + else if (cur->name == "click_to_jump") { bool relativeJump = true; int slideNum = 0; int layerNum = 0; getJumpProperties(cur, relativeJump, slideNum, layerNum); - constructor.layerClickEventOperation(SlideShowConstructor::JUMP, relativeJump, slideNum, layerNum); + constructor.layerClickEventOperation(osgPresentation::JUMP, relativeJump, slideNum, layerNum); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"newline"))) + else if (cur->name == "newline") { constructor.translateTextCursor(osg::Vec3(0.0f,-0.05f,0.0f)); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"indent"))) + else if (cur->name == "indent") { float localIndent = 0.05f; constructor.translateTextCursor(osg::Vec3(localIndent,0.0f,0.0f)); totalIndent += localIndent; } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"unindent"))) + else if (cur->name == "unindent") { float localIndent = -0.05f; constructor.translateTextCursor(osg::Vec3(localIndent,0.0f,0.0f)); totalIndent += localIndent; } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"bullet"))) + else if (cur->name == "bullet") { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) - { - osg::notify(osg::INFO)<<"bullet ["<<(const char*)key<<"]"<contents<<"]"<contents, + positionRead ? positionData : constructor.getTextPositionData(), + fontRead ? fontData : constructor.getTextFontData()); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"paragraph"))) + else if (cur->name == "paragraph") { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) - { - SlideShowConstructor::PositionData positionData = constructor.getTextPositionData(); - bool positionRead = getProperties(cur,positionData); + osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getTextPositionData(); + bool positionRead = getProperties(cur,positionData); - SlideShowConstructor::FontData fontData = constructor.getTextFontData(); - bool fontRead = getProperties(cur,fontData); + osgPresentation::SlideShowConstructor::FontData fontData = constructor.getTextFontData(); + bool fontRead = getProperties(cur,fontData); - constructor.addParagraph((const char*)key, - positionRead ? positionData : constructor.getTextPositionData(), - fontRead ? fontData : constructor.getTextFontData()); - } - xmlFree(key); + constructor.addParagraph(cur->contents, + positionRead ? positionData : constructor.getTextPositionData(), + fontRead ? fontData : constructor.getTextFontData()); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"image"))) + else if (cur->name == "image") { - std::string filename; - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) - { - SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); - bool positionRead = getProperties(cur,positionData); + osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); + bool positionRead = getProperties(cur,positionData); - SlideShowConstructor::ImageData imageData;// = constructor.getImageData(); - getProperties(cur,imageData); + osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData(); + getProperties(cur,imageData); - constructor.addImage((const char*)key, - positionRead ? positionData : constructor.getImagePositionData(), - imageData); - } + constructor.addImage(cur->contents, + positionRead ? positionData : constructor.getImagePositionData(), + imageData); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"vnc"))) + else if (cur->name == "vnc") { - std::string filename; - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) - { - SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); - bool positionRead = getProperties(cur,positionData); + osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); + bool positionRead = getProperties(cur,positionData); - SlideShowConstructor::ImageData imageData;// = constructor.getImageData(); - getProperties(cur,imageData); + osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData(); + getProperties(cur,imageData); - constructor.addVNC((const char*)key, - positionRead ? positionData : constructor.getImagePositionData(), - imageData); - } + constructor.addVNC(cur->contents, + positionRead ? positionData : constructor.getImagePositionData(), + imageData); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"browser"))) + else if (cur->name == "browser") { - std::string filename; - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) - { - SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); - bool positionRead = getProperties(cur,positionData); + osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); + bool positionRead = getProperties(cur,positionData); - SlideShowConstructor::ImageData imageData;// = constructor.getImageData(); - getProperties(cur,imageData); + osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData(); + getProperties(cur,imageData); - constructor.addBrowser((const char*)key, - positionRead ? positionData : constructor.getImagePositionData(), - imageData); - } + constructor.addBrowser(cur->contents, + positionRead ? positionData : constructor.getImagePositionData(), + imageData); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"pdf"))) + else if (cur->name == "pdf") { - std::string filename; - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) - { - SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); - bool positionRead = getProperties(cur,positionData); + osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); + bool positionRead = getProperties(cur,positionData); - SlideShowConstructor::ImageData imageData;// = constructor.getImageData(); - getProperties(cur,imageData); + osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData(); + getProperties(cur,imageData); - constructor.addPDF((const char*)key, - positionRead ? positionData : constructor.getImagePositionData(), - imageData); - } + constructor.addPDF(cur->contents, + positionRead ? positionData : constructor.getImagePositionData(), + imageData); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"stereo_pair"))) + else if (cur->name == "stereo_pair") { - parseStereoPair(constructor, doc,cur); + parseStereoPair(constructor, cur); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"model"))) + else if (cur->name == "model") { - parseModel(constructor, doc,cur); + parseModel(constructor, cur); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"volume"))) + else if (cur->name == "volume") { - parseVolume(constructor, doc,cur); + parseVolume(constructor, cur); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"duration"))) + else if (cur->name == "duration") { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) constructor.setLayerDuration(atof((const char*)key)); - xmlFree(key); + constructor.setLayerDuration(atof(cur->contents.c_str())); } - else if (getKeyPosition(doc, cur, keyPosition)) + else if (getKeyPosition(cur, keyPosition)) { constructor.addLayerKey(keyPosition); } - cur = cur->next; } if (totalIndent != 0.0f) @@ -1239,251 +1135,216 @@ void ReaderWriterP3DXML::parseLayer(SlideShowConstructor& constructor, xmlDocPtr } -void ReaderWriterP3DXML::parseBullets(SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur, bool inheritPreviousLayers, bool defineAsBaseLayer) const +void ReaderWriterP3DXML::parseBullets(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur, bool inheritPreviousLayers, bool defineAsBaseLayer) const { - xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) - { - constructor.addLayer(inheritPreviousLayers, defineAsBaseLayer); + constructor.addLayer(inheritPreviousLayers, defineAsBaseLayer); - osg::notify(osg::INFO)<<"bullets ["<<(const char*)key<<"]"<contents<<"]"<contents, + positionRead ? positionData : constructor.getTextPositionData(), + fontRead ? fontData : constructor.getTextFontData()); } -void ReaderWriterP3DXML::parseText(SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur, bool inheritPreviousLayers, bool defineAsBaseLayer) const +void ReaderWriterP3DXML::parseText(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur, bool inheritPreviousLayers, bool defineAsBaseLayer) const { - xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) - { - constructor.addLayer(inheritPreviousLayers, defineAsBaseLayer); + constructor.addLayer(inheritPreviousLayers, defineAsBaseLayer); - osg::notify(osg::INFO)<<"text ["<<(const char*)key<<"]"<contents<<"]"<contents, + positionRead ? positionData : constructor.getTextPositionData(), + fontRead ? fontData : constructor.getTextFontData()); } -void ReaderWriterP3DXML::parsePage(SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur) const +void ReaderWriterP3DXML::parsePage(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const { - xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) + constructor.addSlide(); + + std::string title; + getProperty(cur, "title", title); + + std::string inherit; + getProperty(cur, "inherit", inherit); + + if (!inherit.empty() && _templateMap.count(inherit)!=0) { - constructor.addSlide(); - - std::string title; - getProperty(cur, "title", title); - - std::string inherit; - getProperty(cur, "inherit", inherit); - - if (!inherit.empty() && _templateMap.count(inherit)!=0) - { - parseSlide(constructor, _templateMap[inherit].first, _templateMap[inherit].second, true, false); - } - - if (!title.empty()) - { - constructor.setSlideTitle(title, - constructor.getTitlePositionData(), - constructor.getTitleFontData()); - } - - if (!inherit.empty() && _templateMap.count(inherit)!=0) - { - parseSlide(constructor, _templateMap[inherit].first, _templateMap[inherit].second, false, true); - } - - constructor.addLayer(true,false); - - SlideShowConstructor::PositionData positionData = constructor.getTextPositionData(); - bool positionRead = getProperties(cur,positionData); - - SlideShowConstructor::FontData fontData = constructor.getTextFontData(); - bool fontRead = getProperties(cur,fontData); - - constructor.addParagraph((const char*)key, - positionRead ? positionData : constructor.getTextPositionData(), - fontRead ? fontData : constructor.getTextFontData()); + parseSlide(constructor, _templateMap[inherit].get(), true, false); } - xmlFree(key); + + if (!title.empty()) + { + constructor.setSlideTitle(title, + constructor.getTitlePositionData(), + constructor.getTitleFontData()); + } + + if (!inherit.empty() && _templateMap.count(inherit)!=0) + { + parseSlide(constructor, _templateMap[inherit].get(), false, true); + } + + constructor.addLayer(true,false); + + osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getTextPositionData(); + bool positionRead = getProperties(cur,positionData); + + osgPresentation::SlideShowConstructor::FontData fontData = constructor.getTextFontData(); + bool fontRead = getProperties(cur,fontData); + + constructor.addParagraph(cur->contents, + positionRead ? positionData : constructor.getTextPositionData(), + fontRead ? fontData : constructor.getTextFontData()); } -void ReaderWriterP3DXML::parsePdfDocument(SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur) const +void ReaderWriterP3DXML::parsePdfDocument(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const { - xmlChar *key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) + std::string title; + getProperty(cur, "title", title); + + std::string inherit; + getProperty(cur, "inherit", inherit); + + constructor.addSlide(); + + if (!inherit.empty() && _templateMap.count(inherit)!=0) { + parseSlide(constructor, _templateMap[inherit].get(), true, false); + } - std::string title; - getProperty(cur, "title", title); + if (!title.empty()) + { + constructor.setSlideTitle(title, + constructor.getTitlePositionData(), + constructor.getTitleFontData()); + } - std::string inherit; - getProperty(cur, "inherit", inherit); - - constructor.addSlide(); - - if (!inherit.empty() && _templateMap.count(inherit)!=0) + if (!inherit.empty() && _templateMap.count(inherit)!=0) + { + parseSlide(constructor, _templateMap[inherit].get(), false, true); + } + + constructor.addLayer(true,false); + + osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); + getProperties(cur,positionData); + + osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData(); + imageData.page = 0; + getProperties(cur,imageData); + + osg::Image* image = constructor.addInteractiveImage(cur->contents, positionData, imageData); + osgWidget::PdfImage* pdfImage = dynamic_cast(image); + if (pdfImage) + { + int numPages = pdfImage->getNumOfPages(); + osg::notify(osg::NOTICE)<<"NumOfPages = "<1) { - parseSlide(constructor, _templateMap[inherit].first, _templateMap[inherit].second, true, false); - } - - if (!title.empty()) - { - constructor.setSlideTitle(title, - constructor.getTitlePositionData(), - constructor.getTitleFontData()); - } - - if (!inherit.empty() && _templateMap.count(inherit)!=0) - { - parseSlide(constructor, _templateMap[inherit].first, _templateMap[inherit].second, false, true); - } - - constructor.addLayer(true,false); - - SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); - getProperties(cur,positionData); - - SlideShowConstructor::ImageData imageData;// = constructor.getImageData(); - imageData.page = 0; - getProperties(cur,imageData); - - osg::Image* image = constructor.addInteractiveImage((const char*)key, positionData, imageData); - osgWidget::PdfImage* pdfImage = dynamic_cast(image); - if (pdfImage) - { - int numPages = pdfImage->getNumOfPages(); - osg::notify(osg::NOTICE)<<"NumOfPages = "<1) + for(int pageNum=1; pageNumcontents, positionData, imageData); + } - } } - xmlFree(key); } -void ReaderWriterP3DXML::parseSlide (SlideShowConstructor& constructor, xmlDocPtr doc, xmlNodePtr cur, bool parseTitles, bool parseLayers) const +void ReaderWriterP3DXML::parseSlide (osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode* root, bool parseTitles, bool parseLayers) const { osg::Vec4 previous_bgcolor = constructor.getBackgroundColor(); osg::Vec4 previous_textcolor = constructor.getTextColor(); // create a keyPosition just in case we need it. - SlideShowConstructor::KeyPosition keyPosition; + osgPresentation::KeyPosition keyPosition; - xmlChar *key; - cur = cur->xmlChildrenNode; - while (cur != NULL) + for(osgDB::XmlNode::Children::iterator itr = root->children.begin(); + itr != root->children.end(); + ++itr) { + osgDB::XmlNode* cur = itr->get(); + if (parseTitles) { - if ((!xmlStrcmp(cur->name, (const xmlChar *)"title"))) + if (cur->name == "title") { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getTitlePositionData(); + bool positionRead = getProperties(cur,positionData); - if (key) - { - SlideShowConstructor::PositionData positionData = constructor.getTitlePositionData(); - bool positionRead = getProperties(cur,positionData); + osgPresentation::SlideShowConstructor::FontData fontData = constructor.getTitleFontData(); + bool fontRead = getProperties(cur,fontData); - SlideShowConstructor::FontData fontData = constructor.getTitleFontData(); - bool fontRead = getProperties(cur,fontData); - - constructor.setSlideTitle((const char*)key, - positionRead ? positionData : constructor.getTitlePositionData(), - fontRead ? fontData : constructor.getTitleFontData()); - - xmlFree(key); - } - else constructor.setSlideTitle("", constructor.getTitlePositionData(), constructor.getTitleFontData()); + constructor.setSlideTitle(cur->contents, + positionRead ? positionData : constructor.getTitlePositionData(), + fontRead ? fontData : constructor.getTitleFontData()); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"background"))) + else if (cur->name == "background") { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) constructor.setSlideBackground((const char*)key); - else constructor.setSlideBackground(""); - xmlFree(key); + constructor.setSlideBackground(cur->contents); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"bgcolor"))) + else if (cur->name == "bgcolor") { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) constructor.setBackgroundColor(mapStringToColor((const char*)key),true); - xmlFree(key); + constructor.setBackgroundColor(mapStringToColor(cur->contents),true); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"textcolor"))) + else if (cur->name == "textcolor") { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) constructor.setTextColor(mapStringToColor((const char*)key)); - xmlFree(key); + constructor.setTextColor(mapStringToColor(cur->contents)); } } if (parseLayers) { - if ((!xmlStrcmp(cur->name, (const xmlChar *)"base"))) + if (cur->name == "base") { constructor.addLayer(true, true); - parseLayer (constructor, doc, cur); + parseLayer (constructor, cur); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"layer"))) + else if (cur->name == "layer") { constructor.addLayer(true, false); - parseLayer (constructor, doc, cur); + parseLayer (constructor, cur); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"clean_layer"))) + else if (cur->name == "clean_layer") { constructor.addLayer(false, false); - parseLayer (constructor, doc, cur); + parseLayer (constructor, cur); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"modify_layer"))) + else if (cur->name == "modify_layer") { int layerNum; if (getProperty(cur, "layer", layerNum)) @@ -1495,24 +1356,21 @@ void ReaderWriterP3DXML::parseSlide (SlideShowConstructor& constructor, xmlDocPt constructor.addLayer(true, false); } - parseLayer (constructor, doc, cur); + parseLayer (constructor, cur); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"bullets"))) + else if (cur->name == "bullets") { - parseBullets (constructor, doc, cur,true, false); + parseBullets (constructor, cur,true, false); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"duration"))) + else if (cur->name == "duration") { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) constructor.setSlideDuration(atof((const char*)key)); - xmlFree(key); + constructor.setSlideDuration(atof(cur->contents.c_str())); } - else if (getKeyPosition(doc, cur, keyPosition)) + else if (getKeyPosition(cur, keyPosition)) { constructor.addSlideKey(keyPosition); } } - cur = cur->next; } constructor.setBackgroundColor(previous_bgcolor,false); @@ -1521,6 +1379,8 @@ void ReaderWriterP3DXML::parseSlide (SlideShowConstructor& constructor, xmlDocPt return; } +#include + osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const { @@ -1534,60 +1394,69 @@ osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(const std::string& if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; // create a keyPosition just in case we need it. - SlideShowConstructor::KeyPosition keyPosition; + osgPresentation::KeyPosition keyPosition; - xmlDocPtr doc; - xmlNodePtr cur; + osg::ref_ptr doc = new osgDB::XmlNode; + osgDB::XmlNode* root = 0; - doc = xmlParseFile(fileName.c_str()); + osgDB::XmlNode::Input input; + input.open(fileName); + input.readAllDataIntoBuffer(); - if (doc == NULL ) { + doc->read(input); + + // doc->write(std::cout); + + if (doc == NULL ) + { fprintf(stderr,"Document not parsed successfully. \n"); return ReadResult::FILE_NOT_HANDLED; } - cur = xmlDocGetRootElement(doc); + for(osgDB::XmlNode::Children::iterator itr = doc->children.begin(); + itr != doc->children.end() && !root; + ++itr) + { + if ((*itr)->name=="presentation") root = itr->get(); + } - if (cur == NULL) { + if (root == NULL) + { fprintf(stderr,"empty document\n"); - xmlFreeDoc(doc); return ReadResult::FILE_NOT_HANDLED; } - if (xmlStrcmp(cur->name, (const xmlChar *) "presentation")) { + if (root->name!="presentation") + { fprintf(stderr,"document of the wrong type, root node != presentation"); - xmlFreeDoc(doc); return ReadResult::FILE_NOT_HANDLED; } - SlideShowConstructor constructor; - + osgPresentation::SlideShowConstructor constructor; + osgDB::FilePathList previousPaths = osgDB::getDataFilePathList(); - + bool readSlide = false; - - - xmlChar *key; - cur = cur->xmlChildrenNode; - while (cur != NULL) { + for(osgDB::XmlNode::Children::iterator itr = root->children.begin(); + itr != root->children.end(); + ++itr) + { + osgDB::XmlNode* cur = itr->get(); - if ((!xmlStrcmp(cur->name, (const xmlChar *)"name"))) + if (cur->name == "name") { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) constructor.setPresentationName((const char*)key); - else constructor.setPresentationName(""); - xmlFree(key); + constructor.setPresentationName(cur->contents); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"loop"))) + else if (cur->name == "loop") { constructor.setLoopPresentation(true); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"auto"))) + else if (cur->name == "auto") { constructor.setAutoSteppingActive(true); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"title-settings"))) + else if (cur->name == "title-settings") { bool fontRead = getProperties(cur,constructor.getTitleFontDataDefault()); if (fontRead) @@ -1595,7 +1464,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(const std::string& osg::notify(osg::INFO)<<"Title font details read"<name, (const xmlChar *)"text-settings"))) + else if (cur->name == "text-settings") { bool fontRead = getProperties(cur,constructor.getTextFontDataDefault()); if (fontRead) @@ -1603,51 +1472,40 @@ osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(const std::string& osg::notify(osg::INFO)<<"Text font details read"<name, (const xmlChar *)"ratio"))) + /*else if (cur->name == "ratio") { key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) constructor.setPresentationAspectRatio((const char*)key); + if (key) constructor.setPresentationAspectRatio(cur->contents); xmlFree(key); }*/ - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"path"))) + else if (cur->name == "path") { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) - { - osg::notify(osg::INFO)<<"Appending search path "<<(char*)key<contents<contents)); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"bgcolor"))) + else if (cur->name == "bgcolor") { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) constructor.setBackgroundColor(mapStringToColor((const char*)key),false); - xmlFree(key); + constructor.setBackgroundColor(mapStringToColor(cur->contents),false); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"textcolor"))) + else if (cur->name == "textcolor") { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) constructor.setTextColor(mapStringToColor((const char*)key)); - xmlFree(key); + constructor.setTextColor(mapStringToColor(cur->contents)); } - else if ((!xmlStrcmp(cur->name, (const xmlChar *)"duration"))) + else if (cur->name == "duration") { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key) constructor.setPresentationDuration(atof((const char*)key)); - xmlFree(key); + constructor.setPresentationDuration(atof(cur->contents.c_str())); } - else if (getKeyPosition(doc, cur, keyPosition)) + else if (getKeyPosition(cur, keyPosition)) { constructor.addPresentationKey(keyPosition); } - else if (readOnlyHoldingPage && (!xmlStrcmp(cur->name, (const xmlChar *)"holding_slide"))) + else if (readOnlyHoldingPage && cur->name == "holding_slide") { readSlide = true; constructor.addSlide(); - parseSlide (constructor, doc, cur); + parseSlide (constructor, cur); } - else if (!readOnlyHoldingPage && (!xmlStrcmp(cur->name, (const xmlChar *)"slide"))) + else if (!readOnlyHoldingPage && cur->name == "slide") { readSlide = true; constructor.addSlide(); @@ -1655,65 +1513,59 @@ osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(const std::string& std::string inherit; if (getProperty(cur, "inherit", inherit) && !inherit.empty() && _templateMap.count(inherit)!=0) { - parseSlide(constructor, _templateMap[inherit].first, _templateMap[inherit].second, true, false); - parseSlide (constructor, doc, cur, true, false); - parseSlide(constructor, _templateMap[inherit].first, _templateMap[inherit].second, false, true); - parseSlide (constructor, doc, cur, false, true); + parseSlide(constructor, _templateMap[inherit].get(), true, false); + parseSlide (constructor, cur, true, false); + parseSlide(constructor, _templateMap[inherit].get(), false, true); + parseSlide (constructor, cur, false, true); } else { - parseSlide (constructor, doc, cur); + parseSlide (constructor, cur); } } - else if (!readOnlyHoldingPage && (!xmlStrcmp(cur->name, (const xmlChar *)"modify_slide"))) + else if (!readOnlyHoldingPage && cur->name == "modify_slide") { readSlide = true; int slideNum; if (getProperty(cur, "slide", slideNum)) { constructor.selectSlide(slideNum); - parseSlide (constructor, doc, cur); + parseSlide (constructor, cur); } else { constructor.addSlide(); } } - else if (!readOnlyHoldingPage && (!xmlStrcmp(cur->name, (const xmlChar *)"page"))) + else if (!readOnlyHoldingPage && cur->name == "page") { readSlide = true; - parsePage (constructor, doc, cur); + parsePage (constructor, cur); } - else if (!readOnlyHoldingPage && (!xmlStrcmp(cur->name, (const xmlChar *)"pdf_document"))) + else if (!readOnlyHoldingPage && cur->name == "pdf_document") { readSlide = true; - parsePdfDocument(constructor, doc, cur); + parsePdfDocument(constructor, cur); } - else if (!readOnlyHoldingPage && (!xmlStrcmp(cur->name, (const xmlChar *)"template_slide"))) + else if (!readOnlyHoldingPage && cur->name == "template_slide") { readSlide = true; std::string name; if (getProperty(cur, "name", name)) { - _templateMap[name] = DocNodePair(doc,cur); + _templateMap[name] = cur; std::cout<<"Defining template slide "<next; } - xmlFreeDoc(doc); - + osgDB::getDataFilePathList() = previousPaths; - - osg::ref_ptr root = constructor.takePresentation(); - - SlideEventHandler* seh = new SlideEventHandler; - seh->set(root.get()); - root->setEventCallback(seh); - - return root.release(); + return constructor.takePresentation(); + /* + std::cout<<"readSlide="<_keys.begin(); + for(LayerAttributes::Keys::iterator itr = _layerAttribute->_keys.begin(); itr != _layerAttribute->_keys.end(); ++itr) { @@ -186,7 +210,7 @@ struct LayerAttributesOperator : public ObjectOperator } if (!_layerAttribute->_runStrings.empty()) { - for(SlideShowConstructor::LayerAttributes::RunStrings::iterator itr = _layerAttribute->_runStrings.begin(); + for(LayerAttributes::RunStrings::iterator itr = _layerAttribute->_runStrings.begin(); itr != _layerAttribute->_runStrings.end(); ++itr) { @@ -232,7 +256,7 @@ struct LayerAttributesOperator : public ObjectOperator osg::ref_ptr _node; - osg::ref_ptr _layerAttribute; + osg::ref_ptr _layerAttribute; }; @@ -252,7 +276,7 @@ public: _operatorList.insert(new CallbackOperator(&node, node.getUpdateCallback())); } - SlideShowConstructor::LayerAttributes* la = dynamic_cast(node.getUserData()); + LayerAttributes* la = dynamic_cast(node.getUserData()); if (la) { _operatorList.insert(new LayerAttributesOperator(&node, la)); @@ -409,7 +433,7 @@ public: void apply(osg::Node& node) { - SlideShowConstructor::HomePosition* homePosition = dynamic_cast(node.getUserData()); + HomePosition* homePosition = dynamic_cast(node.getUserData()); if (homePosition) { _homePosition = homePosition; @@ -418,7 +442,7 @@ public: traverse(node); } - osg::ref_ptr _homePosition; + osg::ref_ptr _homePosition; }; @@ -457,7 +481,7 @@ public: void apply(osg::Node& node) { - SlideShowConstructor::FilePathData* fdd = dynamic_cast(node.getUserData()); + FilePathData* fdd = dynamic_cast(node.getUserData()); if (fdd) { osg::notify(osg::INFO)<<"Recorded FilePathData"<(node->getUserData()); + const LayerAttributes* la = dynamic_cast(node->getUserData()); return la ? la->_duration : -1.0; } @@ -677,7 +701,7 @@ void SlideEventHandler::set(osg::Node* model) _timePerSlide = duration; } - //selectSlide(0); + selectSlide(0); } else { @@ -694,7 +718,7 @@ void SlideEventHandler::set(osg::Node* model) osg::notify(osg::INFO)<<"Found presentation slide"<getName()<(nv); - if (ev) - { - if (node->getNumChildrenRequiringEventTraversal()>0) traverse(node,nv); - - if (ev->getActionAdapter() && !ev->getEvents().empty()) - { - for(osgGA::EventQueue::Events::iterator itr = ev->getEvents().begin(); - itr != ev->getEvents().end(); - ++itr) - { - handleWithCheckAgainstIgnoreHandledEventsMask(*(*itr), *(ev->getActionAdapter()), node, nv); - } - } - } -} - bool SlideEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa) { - - if (!_viewer) - { - _viewer = dynamic_cast(&aa); - selectSlide(0); - home(); - osg::notify(osg::NOTICE)<<"Assigned viewer. to SlideEventHandler"<(_slideSwitch->getUserData()) : 0; + LayerAttributes* la = _slideSwitch.valid() ? dynamic_cast(_slideSwitch->getUserData()) : 0; if (la && la->requiresJump()) { if (la->getRelativeJump()) @@ -1165,7 +1159,7 @@ bool SlideEventHandler::previousSlide() bool SlideEventHandler::nextLayer() { - SlideShowConstructor::LayerAttributes* la = (_slideSwitch.valid() && _activeLayer>=0) ? dynamic_cast(_slideSwitch->getChild(_activeLayer)->getUserData()) : 0; + LayerAttributes* la = (_slideSwitch.valid() && _activeLayer>=0) ? dynamic_cast(_slideSwitch->getChild(_activeLayer)->getUserData()) : 0; if (la) { la->callLeaveCallbacks(_slideSwitch->getChild(_activeLayer)); @@ -1207,11 +1201,8 @@ void SlideEventHandler::updateOperators() _activeOperators.collect(_slideSwitch.get()); _activeOperators.process(); - if (_viewer.valid()) - { - UpdateLightVisitor uav(_viewer->getCamera()->getViewMatrix(),0.0f,0.0f); - _viewer->getSceneData()->accept(uav); - } + UpdateLightVisitor uav(_viewer->getCamera()->getViewMatrix(),0.0f,0.0f); + _viewer->getSceneData()->accept(uav); } bool SlideEventHandler::home(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa) @@ -1298,7 +1289,7 @@ void SlideEventHandler::releaseSlide(unsigned int slideNum) _presentationSwitch->getChild(slideNum)->accept(globjVisitor); } -void SlideEventHandler::dispatchEvent(const SlideShowConstructor::KeyPosition& keyPosition) +void SlideEventHandler::dispatchEvent(const KeyPosition& keyPosition) { osg::notify(osg::INFO)<<" keyPosition._key "< #include "CompileSlideCallback.h" -#include "SlideShowConstructor.h" + +namespace osgPresentation +{ + +/// Operations related to click to run/load/key events. +enum Operation +{ + RUN, + LOAD, + EVENT, + JUMP +}; + +struct HomePosition : public virtual osg::Referenced +{ + HomePosition() {} + + HomePosition(const osg::Vec3& in_eye, const osg::Vec3& in_center, const osg::Vec3& in_up): + eye(in_eye), + center(in_center), + up(in_up) {} + + osg::Vec3 eye; + osg::Vec3 center; + osg::Vec3 up; +}; + +struct KeyPosition +{ + KeyPosition(unsigned int key=0, float x=FLT_MAX, float y=FLT_MAX): + _key((osgGA::GUIEventAdapter::KeySymbol)key), + _x(x), + _y(y) {} + + + void set(unsigned int key=0, float x=FLT_MAX, float y=FLT_MAX) + { + _key = (osgGA::GUIEventAdapter::KeySymbol)key; + _x = x; + _y = y; + } + + osgGA::GUIEventAdapter::KeySymbol _key; + float _x; + float _y; +}; + +struct LayerCallback : public virtual osg::Referenced +{ + virtual void operator() (osg::Node* node) const = 0; +}; + +struct LayerAttributes : public virtual osg::Referenced +{ + LayerAttributes():_duration(0),_relativeJump(true),_slideNum(0),_layerNum(0) {} + LayerAttributes(double in_duration):_duration(in_duration),_relativeJump(true),_slideNum(0),_layerNum(0) {} + + void setDuration(double duration) { _duration = duration; } + double getDuration() const { return _duration; } + + typedef std::vector Keys; + typedef std::vector RunStrings; + + void setKeys(const Keys& keys) { _keys = keys; } + const Keys& getKeys() const { return _keys; } + + void addKey(const KeyPosition& kp) { _keys.push_back(kp); } + + void setRunStrings(const RunStrings& runStrings) { _runStrings = runStrings; } + const RunStrings& getRunStrings() const { return _runStrings; } + + void addRunString(const std::string& runString) { _runStrings.push_back(runString); } + + void setJump(bool relativeJump, int slideNum, int layerNum) + { + _relativeJump = relativeJump; + _slideNum = slideNum; + _layerNum = layerNum; + } + + bool getRelativeJump() const { return _relativeJump; } + int getSlideNum() const { return _slideNum; } + int getLayerNum() const { return _layerNum; } + + bool requiresJump() const { return _relativeJump ? (_slideNum!=0 || _layerNum!=0) : true; } + + double _duration; + Keys _keys; + RunStrings _runStrings; + + bool _relativeJump; + int _slideNum; + int _layerNum; + + void addEnterCallback(LayerCallback* lc) { _enterLayerCallbacks.push_back(lc); } + void addLeaveCallback(LayerCallback* lc) { _leaveLayerCallbacks.push_back(lc); } + + void callEnterCallbacks(osg::Node* node); + void callLeaveCallbacks(osg::Node* node); + + typedef std::list< osg::ref_ptr > LayerCallbacks; + LayerCallbacks _enterLayerCallbacks; + LayerCallbacks _leaveLayerCallbacks; +}; + +struct FilePathData : public virtual osg::Referenced +{ + FilePathData(const osgDB::FilePathList& fpl):filePathList(fpl) {} + + osgDB::FilePathList filePathList; +}; struct dereference_less @@ -95,9 +205,6 @@ public: virtual void accept(osgGA::GUIEventHandlerVisitor& v) { v.visit(*this); } - /** Event traversal node callback method.*/ - virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); - virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&); virtual void getUsage(osg::ApplicationUsage& usage) const; @@ -151,7 +258,7 @@ public: void setLoopPresentation(bool loop) { _loopPresentation = loop; } bool getLoopPresentation() const { return _loopPresentation; } - void dispatchEvent(const SlideShowConstructor::KeyPosition& keyPosition); + void dispatchEvent(const KeyPosition& keyPosition); enum ObjectMask { @@ -173,13 +280,13 @@ protected: osg::observer_ptr _viewer; - osg::observer_ptr _showSwitch; + osg::ref_ptr _showSwitch; unsigned int _activePresentation; - osg::observer_ptr _presentationSwitch; + osg::ref_ptr _presentationSwitch; unsigned int _activeSlide; - osg::observer_ptr _slideSwitch; + osg::ref_ptr _slideSwitch; unsigned int _activeLayer; bool _firstTraversal; @@ -215,4 +322,6 @@ protected: }; +} + #endif diff --git a/src/osgPlugins/p3d/SlideShowConstructor.cpp b/src/osgPlugins/p3d/SlideShowConstructor.cpp index 0ce3efe81..ef8e571dd 100644 --- a/src/osgPlugins/p3d/SlideShowConstructor.cpp +++ b/src/osgPlugins/p3d/SlideShowConstructor.cpp @@ -50,6 +50,8 @@ #include "AnimationMaterial.h" #include "PickEventHandler.h" +using namespace osgPresentation; + class SetToTransparentBin : public osg::NodeVisitor { public: @@ -84,28 +86,6 @@ public: } }; -void SlideShowConstructor::LayerAttributes::callEnterCallbacks(osg::Node* node) -{ - osg::notify(osg::INFO)<<"SlideShowConstructor::LayerAttributes::callEnterCallbacks("<getScreenDistance(); @@ -208,7 +188,7 @@ void SlideShowConstructor::createPresentation() if (_autoSteppingActive) _root->addDescription("auto"); } -SlideShowConstructor::LayerAttributes* SlideShowConstructor::getOrCreateLayerAttributes(osg::Node* node) +LayerAttributes* SlideShowConstructor::getOrCreateLayerAttributes(osg::Node* node) { LayerAttributes* la = dynamic_cast(node->getUserData()); if (!la) @@ -294,7 +274,7 @@ void SlideShowConstructor::selectSlide(int slideNum) { addSlide(); } - else if (slideNum>=_presentationSwitch->getNumChildren()) + else if (slideNum>=static_cast(_presentationSwitch->getNumChildren())) { addSlide(); } @@ -329,6 +309,8 @@ void SlideShowConstructor::addLayer(bool inheritPreviousLayers, bool defineAsBas if (!_slide) addSlide(); _currentLayer = new osg::Group; + + // osg::notify(osg::NOTICE)<<"addLayer"<setTextureAttributeAndModes(0, + texture, + osg::StateAttribute::ON); + } + else + { + osg::Texture2D* texture = new osg::Texture2D(image.get()); + texture->setResizeNonPowerOfTwoHint(false); + backgroundStateSet->setTextureAttributeAndModes(0, + texture, + osg::StateAttribute::ON); + } background->addDrawable(backgroundQuad); @@ -412,7 +415,7 @@ void SlideShowConstructor::selectLayer(int layerNum) addSlide(); addLayer(); } - else if (layerNum>=0 && layerNum<_slide->getNumChildren() && _slide->getChild(layerNum)->asGroup()) + else if (layerNum>=0 && layerNum(_slide->getNumChildren()) && _slide->getChild(layerNum)->asGroup()) { _currentLayer = _slide->getChild(layerNum)->asGroup(); _previousLayer = _currentLayer; @@ -493,7 +496,7 @@ void SlideShowConstructor::layerClickToDoOperation(const std::string& command, O } -void SlideShowConstructor::layerClickEventOperation(const SlideShowConstructor::KeyPosition& keyPos, bool relativeJump, int slideNum, int layerNum) +void SlideShowConstructor::layerClickEventOperation(const KeyPosition& keyPos, bool relativeJump, int slideNum, int layerNum) { if (!_currentLayer) addLayer(); @@ -1052,7 +1055,7 @@ void SlideShowConstructor::addPDF(const std::string& filename, const PositionDat addInteractiveImage(filename, positionData, imageData); } -class SetPageCallback: public SlideShowConstructor::LayerCallback +class SetPageCallback: public LayerCallback { public: SetPageCallback(osgWidget::PdfImage* pdfImage, int pageNum): @@ -1421,7 +1424,7 @@ void SlideShowConstructor::addModel(osg::Node* subgraph, const PositionData& pos void SlideShowConstructor::addVolume(const std::string& filename, const PositionData& positionData) { - osg::Object::DataVariance defaultMatrixDataVariance = osg::Object::DYNAMIC; // STATIC + // osg::Object::DataVariance defaultMatrixDataVariance = osg::Object::DYNAMIC; // STATIC std::string foundFile = filename; diff --git a/src/osgPlugins/p3d/SlideShowConstructor.h b/src/osgPlugins/p3d/SlideShowConstructor.h index 4bf82b744..4f60b4545 100644 --- a/src/osgPlugins/p3d/SlideShowConstructor.h +++ b/src/osgPlugins/p3d/SlideShowConstructor.h @@ -26,6 +26,10 @@ #include #include "AnimationMaterial.h" +#include "SlideEventHandler.h" + +namespace osgPresentation +{ class SlideShowConstructor { @@ -34,98 +38,6 @@ public: enum CoordinateFrame { SLIDE, MODEL }; - struct HomePosition : public virtual osg::Referenced - { - HomePosition() {} - - HomePosition(const osg::Vec3& in_eye, const osg::Vec3& in_center, const osg::Vec3& in_up): - eye(in_eye), - center(in_center), - up(in_up) {} - - osg::Vec3 eye; - osg::Vec3 center; - osg::Vec3 up; - }; - - struct KeyPosition - { - KeyPosition(unsigned int key=0, float x=FLT_MAX, float y=FLT_MAX): - _key((osgGA::GUIEventAdapter::KeySymbol)key), - _x(x), - _y(y) {} - - - void set(unsigned int key=0, float x=FLT_MAX, float y=FLT_MAX) - { - _key = (osgGA::GUIEventAdapter::KeySymbol)key; - _x = x; - _y = y; - } - - osgGA::GUIEventAdapter::KeySymbol _key; - float _x; - float _y; - }; - - struct LayerCallback : public virtual osg::Referenced - { - virtual void operator() (osg::Node* node) const = 0; - }; - - struct LayerAttributes : public virtual osg::Referenced - { - LayerAttributes():_duration(0),_relativeJump(true),_slideNum(0),_layerNum(0) {} - LayerAttributes(double in_duration):_duration(in_duration),_relativeJump(true),_slideNum(0),_layerNum(0) {} - - void setDuration(double duration) { _duration = duration; } - double getDuration() const { return _duration; } - - typedef std::vector Keys; - typedef std::vector RunStrings; - - void setKeys(const Keys& keys) { _keys = keys; } - const Keys& getKeys() const { return _keys; } - - void addKey(const KeyPosition& kp) { _keys.push_back(kp); } - - void setRunStrings(const RunStrings& runStrings) { _runStrings = runStrings; } - const RunStrings& getRunStrings() const { return _runStrings; } - - void addRunString(const std::string& runString) { _runStrings.push_back(runString); } - - void setJump(bool relativeJump, int slideNum, int layerNum) - { - _relativeJump = relativeJump; - _slideNum = slideNum; - _layerNum = layerNum; - } - - bool getRelativeJump() const { return _relativeJump; } - int getSlideNum() const { return _slideNum; } - int getLayerNum() const { return _layerNum; } - - bool requiresJump() const { return _relativeJump ? (_slideNum!=0 || _layerNum!=0) : true; } - - double _duration; - Keys _keys; - RunStrings _runStrings; - - bool _relativeJump; - int _slideNum; - int _layerNum; - - void addEnterCallback(LayerCallback* lc) { _enterLayerCallbacks.push_back(lc); } - void addLeaveCallback(LayerCallback* lc) { _leaveLayerCallbacks.push_back(lc); } - - void callEnterCallbacks(osg::Node* node); - void callLeaveCallbacks(osg::Node* node); - - typedef std::list< osg::ref_ptr > LayerCallbacks; - LayerCallbacks _enterLayerCallbacks; - LayerCallbacks _leaveLayerCallbacks; - }; - LayerAttributes* getOrCreateLayerAttributes(osg::Node* node); @@ -198,12 +110,6 @@ public: if (_currentLayer.valid()) setJump(_currentLayer.get(),relativeJump, switchNum, layerNum); } - struct FilePathData : public virtual osg::Referenced - { - FilePathData(const osgDB::FilePathList& fpl):filePathList(fpl) {} - - osgDB::FilePathList filePathList; - }; struct PositionData @@ -320,14 +226,6 @@ public: osg::Vec4 color; }; - /// Operations related to click to run/load/key events. - enum Operation - { - RUN, - LOAD, - EVENT, - JUMP - }; SlideShowConstructor(); @@ -399,7 +297,7 @@ public: void layerClickToDoOperation(Operation operation, bool relativeJump=true, int slideNum=0, int layerNum=0); void layerClickToDoOperation(const std::string& command, Operation operation, bool relativeJump=true, int slideNum=0, int layerNum=0); - void layerClickEventOperation(const SlideShowConstructor::KeyPosition& keyPos, bool relativeJump=true, int slideNum=0, int layerNum=0); + void layerClickEventOperation(const KeyPosition& keyPos, bool relativeJump=true, int slideNum=0, int layerNum=0); void addBullet(const std::string& bullet, PositionData& positionData, FontData& fontData); @@ -515,4 +413,6 @@ protected: }; +} + #endif diff --git a/src/osgWrappers/osgDB/XmlParser.cpp b/src/osgWrappers/osgDB/XmlParser.cpp new file mode 100644 index 000000000..44444d3e7 --- /dev/null +++ b/src/osgWrappers/osgDB/XmlParser.cpp @@ -0,0 +1,179 @@ +// *************************************************************************** +// +// Generated automatically by genwrapper. +// Please DO NOT EDIT this file! +// +// *************************************************************************** + +#include +#include +#include +#include + +#include + +// Must undefine IN and OUT macros defined in Windows headers +#ifdef IN +#undef IN +#endif +#ifdef OUT +#undef OUT +#endif + +BEGIN_ENUM_REFLECTOR(osgDB::XmlNode::NodeType) + I_DeclaringFile("osgDB/XmlParser"); + I_EnumLabel(osgDB::XmlNode::UNASSIGNED); + I_EnumLabel(osgDB::XmlNode::ATOM); + I_EnumLabel(osgDB::XmlNode::NODE); + I_EnumLabel(osgDB::XmlNode::GROUP); + I_EnumLabel(osgDB::XmlNode::ROOT); + I_EnumLabel(osgDB::XmlNode::COMMENT); + I_EnumLabel(osgDB::XmlNode::INFORMATION); +END_REFLECTOR + +TYPE_NAME_ALIAS(std::map< std::string COMMA std::string >, osgDB::XmlNode::Properties) + +TYPE_NAME_ALIAS(std::vector< osg::ref_ptr< osgDB::XmlNode > >, osgDB::XmlNode::Children) + +BEGIN_OBJECT_REFLECTOR(osgDB::XmlNode) + I_DeclaringFile("osgDB/XmlParser"); + I_BaseType(osg::Referenced); + I_Constructor0(____XmlNode, + "", + ""); + I_Method1(bool, read, IN, osgDB::XmlNode::Input &, input, + Properties::NON_VIRTUAL, + __bool__read__Input_R1, + "", + ""); + I_Method1(bool, write, IN, std::ostream &, fout, + Properties::NON_VIRTUAL, + __bool__write__std_ostream_R1, + "", + ""); + I_Method2(bool, writeString, IN, std::ostream &, fout, IN, const std::string &, str, + Properties::NON_VIRTUAL, + __bool__writeString__std_ostream_R1__C5_std_string_R1, + "", + ""); + I_PublicMemberProperty(osgDB::XmlNode::NodeType, type); + I_PublicMemberProperty(std::string, name); + I_PublicMemberProperty(std::string, contents); + I_PublicMemberProperty(osgDB::XmlNode::Properties, properties); + I_PublicMemberProperty(osgDB::XmlNode::Children, children); +END_REFLECTOR + +TYPE_NAME_ALIAS(std::string::size_type, osgDB::XmlNode::Input::size_type) + +TYPE_NAME_ALIAS(std::map< std::string COMMA int >, osgDB::XmlNode::Input::ControlToCharacterMap) + +TYPE_NAME_ALIAS(std::map< int COMMA std::string >, osgDB::XmlNode::Input::CharacterToControlMap) + +BEGIN_VALUE_REFLECTOR(osgDB::XmlNode::Input) + I_DeclaringFile("osgDB/XmlParser"); + I_Constructor0(____Input, + "", + ""); + I_Constructor1(IN, const osgDB::XmlNode::Input &, x, + Properties::NON_EXPLICIT, + ____Input__C5_Input_R1, + "", + ""); + I_Method1(void, open, IN, const std::string &, filename, + Properties::NON_VIRTUAL, + __void__open__C5_std_string_R1, + "", + ""); + I_Method1(void, attach, IN, std::istream &, istream, + Properties::NON_VIRTUAL, + __void__attach__std_istream_R1, + "", + ""); + I_Method0(void, readAllDataIntoBuffer, + Properties::NON_VIRTUAL, + __void__readAllDataIntoBuffer, + "", + ""); + I_Method0(int, get, + Properties::NON_VIRTUAL, + __int__get, + "", + ""); + I_Method0(void, skipWhiteSpace, + Properties::NON_VIRTUAL, + __void__skipWhiteSpace, + "", + ""); + I_MethodWithDefaults2(std::string, substr, IN, osgDB::XmlNode::Input::size_type, pos, , IN, osgDB::XmlNode::Input::size_type, n, std::string::npos, + Properties::NON_VIRTUAL, + __std_string__substr__size_type__size_type, + "", + ""); + I_Method1(osgDB::XmlNode::Input::size_type, find, IN, const std::string &, str, + Properties::NON_VIRTUAL, + __size_type__find__C5_std_string_R1, + "", + ""); + I_Method1(bool, match, IN, const std::string &, str, + Properties::NON_VIRTUAL, + __bool__match__C5_std_string_R1, + "", + ""); + I_Method2(void, addControlToCharacter, IN, const std::string &, control, IN, int, c, + Properties::NON_VIRTUAL, + __void__addControlToCharacter__C5_std_string_R1__int, + "", + ""); + I_SimpleProperty(int, , + __int__get, + 0); + I_PublicMemberProperty(osgDB::XmlNode::Input::ControlToCharacterMap, _controlToCharacterMap); + I_PublicMemberProperty(osgDB::XmlNode::Input::CharacterToControlMap, _characterToControlMap); +END_REFLECTOR + +BEGIN_VALUE_REFLECTOR(osg::ref_ptr< osgDB::XmlNode >) + I_DeclaringFile("osg/ref_ptr"); + I_Constructor0(____ref_ptr, + "", + ""); + I_Constructor1(IN, osgDB::XmlNode *, ptr, + Properties::NON_EXPLICIT, + ____ref_ptr__T_P1, + "", + ""); + I_Constructor1(IN, const osg::ref_ptr< osgDB::XmlNode > &, rp, + Properties::NON_EXPLICIT, + ____ref_ptr__C5_ref_ptr_R1, + "", + ""); + I_Method0(osgDB::XmlNode *, get, + Properties::NON_VIRTUAL, + __T_P1__get, + "", + ""); + I_Method0(bool, valid, + Properties::NON_VIRTUAL, + __bool__valid, + "", + ""); + I_Method0(osgDB::XmlNode *, release, + Properties::NON_VIRTUAL, + __T_P1__release, + "", + ""); + I_Method1(void, swap, IN, osg::ref_ptr< osgDB::XmlNode > &, rp, + Properties::NON_VIRTUAL, + __void__swap__ref_ptr_R1, + "", + ""); + I_SimpleProperty(osgDB::XmlNode *, , + __T_P1__get, + 0); +END_REFLECTOR + +STD_MAP_REFLECTOR(std::map< int COMMA std::string >) + +STD_MAP_REFLECTOR(std::map< std::string COMMA int >) + +STD_VECTOR_REFLECTOR(std::vector< osg::ref_ptr< osgDB::XmlNode > >) +