From: Braden M. <br...@us...> - 2006-04-05 07:23:33
|
Update of /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3880/src/libopenvrml/openvrml Modified Files: browser.cpp browser.h vrml97node.cpp Log Message: Fixed resolution of relative URIs in Inline nodes to be resolved against the URI of the containing scene. Index: browser.cpp =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml/browser.cpp,v retrieving revision 1.159 retrieving revision 1.160 diff -C2 -d -r1.159 -r1.160 *** browser.cpp 5 Apr 2006 06:57:37 -0000 1.159 --- browser.cpp 5 Apr 2006 07:23:17 -0000 1.160 *************** *** 7430,7503 **** } - struct OPENVRML_LOCAL openvrml::scene::load_scene { - - load_scene(openvrml::scene & scene, - const std::vector<std::string> & url): - scene_(&scene), - url_(&url) - {} - - void operator()() const OPENVRML_NOTHROW - try { - using std::endl; - using std::string; - using std::vector; - - openvrml::scene & scene = *this->scene_; - const vector<string> & url = *this->url_; - - assert(scene.url_.empty()); - - vector<boost::intrusive_ptr<node> > nodes; - try { - std::auto_ptr<resource_istream> in = scene.get_resource(url); - if (!(*in)) { throw unreachable_url(); } - scene.load(*in); - } catch (antlr::ANTLRException & ex) { - scene.browser().err(ex.getMessage()); - } catch (std::exception & ex) { - scene.browser().err(ex.what()); - throw unreachable_url(); - } catch (...) { - throw unreachable_url(); - } - scene.nodes(nodes); - scene.scene_loaded(); - } catch (std::exception & ex) { - this->scene_->browser().err(ex.what()); - } - - private: - openvrml::scene * const scene_; - const std::vector<std::string> * const url_; - }; - - /** - * @brief Load a world. - * - * The world specified by @p url is loaded asynchronously. - * <code>scene::scene_loaded</code> is called when loading the world has - * completed (i.e., when <code>scene::nodes</code> will return the world's - * root <code>node</code>s). - * - * As this function executes asynchronously, note that it will not throw upon - * encountering a malformed or unreachable URI, or syntactically incorrect - * VRML. - * - * @param[in] url the URI for the world. Per VRML97 convention, this is a list - * of alternative URIs. The first one in the list to load - * successfully is used. - * - * @exception boost::thread_resource_error if a new thread of execution cannot - * be started. - * @exception std::bad_alloc if memory allocation fails. - */ - void openvrml::scene::load(const std::vector<std::string> & url) - OPENVRML_THROW2(boost::thread_resource_error, std::bad_alloc) - { - boost::function0<void> f = load_scene(*this, url); - boost::thread t(f); - } - /** * @brief Load the scene from a stream. --- 7430,7433 ---- *************** *** 7518,7521 **** --- 7448,7452 ---- this->url_ = in.url(); parse_vrml(in, in.url(), in.type(), *this, this->nodes_, this->meta_); + this->scene_loaded(); } *************** *** 7676,7680 **** boost::mutex::scoped_lock lock(this->url_mutex_); using std::string; ! const string result = this->parent_ ? string(uri(this->url_) .resolve_against(uri(this->parent_->url()))) --- 7607,7611 ---- boost::mutex::scoped_lock lock(this->url_mutex_); using std::string; ! const string result = (this->parent_ && !this->url_.empty()) ? string(uri(this->url_) .resolve_against(uri(this->parent_->url()))) Index: browser.h =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml/browser.h,v retrieving revision 1.52 retrieving revision 1.53 diff -C2 -d -r1.52 -r1.53 *** browser.h 12 Mar 2006 23:42:14 -0000 1.52 --- browser.h 5 Apr 2006 07:23:20 -0000 1.53 *************** *** 352,357 **** class OPENVRML_API scene : boost::noncopyable { - struct load_scene; - openvrml::browser * const browser_; scene * const parent_; --- 352,355 ---- *************** *** 373,378 **** openvrml::browser & browser() const OPENVRML_NOTHROW; scene * parent() const OPENVRML_NOTHROW; - void load(const std::vector<std::string> & url) - OPENVRML_THROW2(boost::thread_resource_error, std::bad_alloc); void load(resource_istream & in); void initialize(double timestamp) OPENVRML_THROW1(std::bad_alloc); --- 371,374 ---- Index: vrml97node.cpp =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml/vrml97node.cpp,v retrieving revision 1.101 retrieving revision 1.102 diff -C2 -d -r1.101 -r1.102 *** vrml97node.cpp 19 Mar 2006 00:05:29 -0000 1.101 --- vrml97node.cpp 5 Apr 2006 07:23:20 -0000 1.102 *************** *** 1,3 **** ! // -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; -*- // // OpenVRML --- 1,3 ---- ! // -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 78 -*- // // OpenVRML *************** *** 38,41 **** --- 38,42 ---- # include <boost/algorithm/string/predicate.hpp> # include <boost/array.hpp> + # include <boost/thread.hpp> # ifdef OPENVRML_ENABLE_RENDER_TEXT_NODE # include <ft2build.h> *************** *** 3048,3051 **** --- 3049,3054 ---- friend class inline_class; + struct load_inline_scene; + exposedfield<mfstring> url_; exposedfield<sfbool> load_; *************** *** 3053,3058 **** sfvec3f bbox_size_; ! openvrml::scene * inlineScene; ! bool hasLoaded; public: --- 3056,3062 ---- sfvec3f bbox_size_; ! openvrml::scene * inline_scene_; ! bool loaded_; ! boost::scoped_ptr<boost::thread> load_inline_scene_thread_; public: *************** *** 13760,13765 **** url_(*this), load_(*this, true), ! inlineScene(0), ! hasLoaded(false) { this->bounding_volume_dirty(true); --- 13764,13769 ---- url_(*this), load_(*this, true), ! inline_scene_(0), ! loaded_(false) { this->bounding_volume_dirty(true); *************** *** 13770,13774 **** */ inline_node::~inline_node() OPENVRML_NOTHROW ! {} /** --- 13774,13782 ---- */ inline_node::~inline_node() OPENVRML_NOTHROW ! { ! if (this->load_inline_scene_thread_) { ! this->load_inline_scene_thread_->join(); ! } ! } /** *************** *** 13786,13790 **** { this->load(); ! if (this->inlineScene) { this->inlineScene->render(viewer, context); } } --- 13794,13798 ---- { this->load(); ! if (this->inline_scene_) { this->inline_scene_->render(viewer, context); } } *************** *** 13798,13806 **** { static const std::vector<boost::intrusive_ptr<openvrml::node> > empty; ! return this->inlineScene ! ? this->inlineScene->nodes() : empty; } /** * @brief Load the children from the URL. --- 13806,13859 ---- { static const std::vector<boost::intrusive_ptr<openvrml::node> > empty; ! return this->inline_scene_ ! ? this->inline_scene_->nodes() : empty; } + struct OPENVRML_LOCAL inline_node::load_inline_scene { + + load_inline_scene(openvrml::scene & scene, + const std::vector<std::string> & url): + inline_scene_(&scene), + url_(&url) + {} + + void operator()() const OPENVRML_NOTHROW + try { + using std::endl; + using std::string; + using std::vector; + + openvrml::scene & inline_scene = *this->inline_scene_; + const vector<string> & url = *this->url_; + + assert(inline_scene.url().empty()); + + vector<boost::intrusive_ptr<node> > nodes; + try { + // + // Any relative URLs passed here will be relative to the + // *parent* scene; so we call get_resource on the parent. + // + assert(inline_scene.parent()); + std::auto_ptr<resource_istream> in = + inline_scene.parent()->get_resource(url); + if (!(*in)) { throw unreachable_url(); } + inline_scene.load(*in); + } catch (std::exception & ex) { + inline_scene.browser().err(ex.what()); + throw unreachable_url(); + } catch (...) { + throw unreachable_url(); + } + } catch (std::exception & ex) { + this->inline_scene_->browser().err(ex.what()); + } + + private: + openvrml::scene * const inline_scene_; + const std::vector<std::string> * const url_; + }; + /** * @brief Load the children from the URL. *************** *** 13812,13822 **** inline_scene(openvrml::browser & b, openvrml::scene * parent): openvrml::scene(b, parent) ! {} private: virtual void scene_loaded() ! { ! this->initialize(openvrml::browser::current_time()); ! } }; --- 13865,13875 ---- inline_scene(openvrml::browser & b, openvrml::scene * parent): openvrml::scene(b, parent) ! {} private: virtual void scene_loaded() ! { ! this->initialize(openvrml::browser::current_time()); ! } }; *************** *** 13824,13836 **** // XXX Need to check whether Url has been modified. // ! if (this->hasLoaded) { return; } ! this->hasLoaded = true; // although perhaps not successfully this->bounding_volume_dirty(true); assert(this->scene()); ! this->inlineScene = new inline_scene(this->scene()->browser(), ! this->scene()); ! this->inlineScene->load(this->url_.mfstring::value()); } --- 13877,13892 ---- // XXX Need to check whether Url has been modified. // ! if (this->loaded_) { return; } ! this->loaded_ = true; // although perhaps not successfully this->bounding_volume_dirty(true); assert(this->scene()); ! this->inline_scene_ = new inline_scene(this->scene()->browser(), ! this->scene()); ! boost::function0<void> f = ! load_inline_scene(*this->inline_scene_, ! this->url_.mfstring::value()); ! this->load_inline_scene_thread_.reset(new boost::thread(f)); } |