/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield * * This software is open source and may be redistributed and/or modified under * the terms of the GNU General Public License (GPL) version 2.0. * The full license is in LICENSE.txt file included with this distribution,. * * This software 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 * include LICENSE.txt for more details. */ #include "ReadShowFile.h" #include "ShowEventHandler.h" #include #include #include #include #include #include #include #include #include #include #include class AddVolumeEditingCallbackVisitor : public osg::NodeVisitor { public: AddVolumeEditingCallbackVisitor(): osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {} void apply(osg::Group& group) { osgVolume::VolumeTile* volumeTile = dynamic_cast(&group); if (volumeTile) { volumeTile->addEventCallback(new osgVolume::PropertyAdjustmentCallback()); } else { traverse(group); } } }; bool p3d::getFileNames(osg::ArgumentParser& arguments, FileNameList& xmlFiles, FileNameList& normalFiles) { // note currently doesn't delete the loaded file entries from the command line yet... for(int pos=1;pos doc = new osgDB::XmlNode; osgDB::XmlNode* root = 0; osgDB::XmlNode::Input input; input.open(fileName); input.readAllDataIntoBuffer(); doc->read(input); if (doc == NULL ) { fprintf(stderr,"Document not parsed successfully. \n"); 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 (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; for(osgDB::XmlNode::Children::iterator itr = root->children.begin(); itr != root->children.end(); ++itr) { osgDB::XmlNode* cur = itr->get(); if (cur->name=="env") { char* str = strdup(cur->contents.c_str()); osg::notify(osg::INFO)<<"putenv("< local_options = options ? options->cloneOptions() : 0; if (!local_options) { local_options = osgDB::Registry::instance()->getOptions() ? osgDB::Registry::instance()->getOptions()->cloneOptions() : new osgDB::Options; } local_options->setPluginStringData("P3D_EVENTHANDLER","none"); return local_options.release(); } osg::Node* p3d::readHoldingSlide(const std::string& filename) { std::string ext = osgDB::getFileExtension(filename); if (!osgDB::equalCaseInsensitive(ext,"xml") && !osgDB::equalCaseInsensitive(ext,"p3d")) return 0; osg::ref_ptr options = createOptions(0); options->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_NONE); options->setOptionString("preview"); return osgDB::readNodeFile(filename, options.get()); } osg::Node* p3d::readPresentation(const std::string& filename,const osgDB::ReaderWriter::Options* options) { std::string ext = osgDB::getFileExtension(filename); if (!osgDB::equalCaseInsensitive(ext,"xml") && !osgDB::equalCaseInsensitive(ext,"p3d")) return 0; osg::ref_ptr local_options = createOptions(options); local_options->setOptionString("main"); return osgDB::readNodeFile(filename, local_options.get()); } osg::Node* p3d::readShowFiles(osg::ArgumentParser& arguments,const osgDB::ReaderWriter::Options* options) { osg::ref_ptr local_options = createOptions(options); local_options->setOptionString("main"); typedef std::vector< osg::ref_ptr > NodeList; NodeList nodeList; std::string filename; while (arguments.read("--image",filename)) { osg::ref_ptr image = readImageFile(filename.c_str(), local_options.get()); if (image.valid()) nodeList.push_back(osg::createGeodeForImage(image.get())); } while (arguments.read("--movie",filename)) { osg::ref_ptr image = readImageFile(filename.c_str(), local_options.get()); osg::ref_ptr imageStream = dynamic_cast(image.get()); if (image.valid()) { imageStream->play(); nodeList.push_back(osg::createGeodeForImage(imageStream.get())); } } while (arguments.read("--dem",filename)) { osg::HeightField* hf = readHeightFieldFile(filename.c_str(), local_options.get()); if (hf) { osg::Geode* geode = new osg::Geode; geode->addDrawable(new osg::ShapeDrawable(hf)); nodeList.push_back(geode); } } // note currently doesn't delete the loaded file entries from the command line yet... for(int pos=1;posgetName().empty()) node->setName( arguments[pos] ); nodeList.push_back(node); } } } if (nodeList.empty()) { return NULL; } osg::ref_ptr root; if (nodeList.size()==1) { root = nodeList.front().get(); } else // size >1 { osg::Switch* sw = new osg::Switch; for(NodeList::iterator itr=nodeList.begin(); itr!=nodeList.end(); ++itr) { sw->addChild((*itr).get()); } sw->setSingleChildOn(0); sw->setEventCallback(new p3d::ShowEventHandler()); root = sw; } if (root.valid()) { osg::notify(osg::INFO)<<"Got node now adding callback"<accept(avecv); } return root.release(); }