From: Braden M. <br...@us...> - 2006-05-17 07:59:53
|
Update of /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv24525/src/libopenvrml/openvrml Modified Files: browser.cpp vrml97node.cpp Added Files: x3d_cad_geometry.cpp x3d_cad_geometry.h Log Message: Added support for creating scene graphs with CADGeomentry component nodes. From Andrew Grieve <sg...@us...> Index: browser.cpp =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml/browser.cpp,v retrieving revision 1.175 retrieving revision 1.176 diff -C2 -d -r1.175 -r1.176 *** browser.cpp 17 May 2006 03:57:08 -0000 1.175 --- browser.cpp 17 May 2006 07:59:50 -0000 1.176 *************** *** 62,65 **** --- 62,66 ---- # include "x3d_hanim.h" # include "x3d_nurbs.h" + # include "x3d_cad_geometry.h" namespace openvrml { *************** *** 3826,3829 **** --- 3827,3831 ---- } + class OPENVRML_LOCAL profile { typedef std::map<std::string, int> map_t; *************** *** 6017,6020 **** --- 6019,6023 ---- register_hanim_node_classes(b); register_nurbs_node_classes(b); + register_cad_geometry_node_classes(b); } } *************** *** 6805,6809 **** * @param[in] url an alternative URI list. * @param[in] node the node to which the nodes loaded from @p url should be ! * sent as an event. * @param[in] event the event of @p node to which the new nodes will be sent. * --- 6808,6812 ---- * @param[in] url an alternative URI list. * @param[in] node the node to which the nodes loaded from @p url should be ! * sent as an event. * @param[in] event the event of @p node to which the new nodes will be sent. * *************** *** 13521,13524 **** --- 13524,13770 ---- + class OPENVRML_LOCAL x3d_cad_geometry_component : public component { + public: + static const char * const id; + + virtual size_t support_level() const OPENVRML_NOTHROW; + + private: + virtual void do_add_to_scope(const openvrml::browser & b, + openvrml::scope & scope, + size_t level) const + OPENVRML_THROW1(std::bad_alloc); + }; + + const char * const x3d_cad_geometry_component::id = "CADGeometry"; + + size_t x3d_cad_geometry_component::support_level() const OPENVRML_NOTHROW + { + return 2; + } + + void x3d_cad_geometry_component::do_add_to_scope(const openvrml::browser & b, + openvrml::scope & scope, + const size_t level) const + OPENVRML_THROW1(std::bad_alloc) + { + using namespace openvrml; + + // CADAssembly node + if (level >= 2) + { + static const node_interface interfaces[] = { + node_interface(node_interface::eventin_id, + field_value::mfnode_id, + "addChildren"), + node_interface(node_interface::eventin_id, + field_value::mfnode_id, + "removeChildren"), + node_interface(node_interface::exposedfield_id, + field_value::mfnode_id, + "children"), + node_interface(node_interface::exposedfield_id, + field_value::sfnode_id, + "metadata"), + node_interface(node_interface::exposedfield_id, + field_value::sfstring_id, + "name"), + node_interface(node_interface::field_id, + field_value::sfvec3f_id, + "bboxCenter"), + node_interface(node_interface::field_id, + field_value::sfvec3f_id, + "bboxSize") + }; + + static const node_interface_set interface_set(interfaces, interfaces + 7); + add_scope_entry(b, "CADAssembly", interface_set, + "urn:X-openvrml:node:CADAssembly", scope); + } + // CADFace node + if (level >= 2) + { + static const node_interface interfaces[] = { + node_interface(node_interface::exposedfield_id, + field_value::sfnode_id, + "metadata"), + node_interface(node_interface::exposedfield_id, + field_value::sfstring_id, + "name"), + node_interface(node_interface::exposedfield_id, + field_value::sfnode_id, + "shape") + }; + + static const node_interface_set interface_set(interfaces, interfaces + 3); + add_scope_entry(b, "CADFace", interface_set, + "urn:X-openvrml:node:CADFace", scope); + } + // CADLayer node + if (level >= 2) + { + static const node_interface interfaces[] = { + node_interface(node_interface::eventin_id, + field_value::mfnode_id, + "addChildren"), + node_interface(node_interface::eventin_id, + field_value::mfnode_id, + "removeChildren"), + node_interface(node_interface::exposedfield_id, + field_value::mfnode_id, + "children"), + node_interface(node_interface::exposedfield_id, + field_value::sfnode_id, + "metadata"), + node_interface(node_interface::exposedfield_id, + field_value::sfstring_id, + "name"), + node_interface(node_interface::exposedfield_id, + field_value::mfbool_id, + "visible"), + node_interface(node_interface::field_id, + field_value::sfvec3f_id, + "bboxCenter"), + node_interface(node_interface::field_id, + field_value::sfvec3f_id, + "bboxSize") + }; + + static const node_interface_set interface_set(interfaces, interfaces + 8); + add_scope_entry(b, "CADLayer", interface_set, + "urn:X-openvrml:node:CADLayer", scope); + } + // CADPart node + if (level >= 2) + { + static const node_interface interfaces[] = { + node_interface(node_interface::eventin_id, + field_value::mfnode_id, + "addChildren"), + node_interface(node_interface::eventin_id, + field_value::mfnode_id, + "removeChildren"), + node_interface(node_interface::exposedfield_id, + field_value::mfnode_id, + "children"), + node_interface(node_interface::exposedfield_id, + field_value::sfvec3f_id, + "center"), + node_interface(node_interface::exposedfield_id, + field_value::sfnode_id, + "metadata"), + node_interface(node_interface::exposedfield_id, + field_value::sfstring_id, + "name"), + node_interface(node_interface::exposedfield_id, + field_value::sfrotation_id, + "rotation"), + node_interface(node_interface::exposedfield_id, + field_value::sfvec3f_id, + "scale"), + node_interface(node_interface::exposedfield_id, + field_value::sfrotation_id, + "scaleOrientation"), + node_interface(node_interface::exposedfield_id, + field_value::sfvec3f_id, + "translation"), + node_interface(node_interface::field_id, + field_value::sfvec3f_id, + "bboxCenter"), + node_interface(node_interface::field_id, + field_value::sfvec3f_id, + "bboxSize") + }; + + static const node_interface_set interface_set(interfaces, interfaces + 12); + add_scope_entry(b, "CADPart", interface_set, + "urn:X-openvrml:node:CADPart", scope); + } + // IndexedQuadSet node + if (level >= 1) + { + static const node_interface interfaces[] = { + node_interface(node_interface::eventin_id, + field_value::mfint32_id, + "set_index"), + node_interface(node_interface::exposedfield_id, + field_value::sfnode_id, + "color"), + node_interface(node_interface::exposedfield_id, + field_value::sfnode_id, + "coord"), + node_interface(node_interface::exposedfield_id, + field_value::sfnode_id, + "metadata"), + node_interface(node_interface::exposedfield_id, + field_value::sfnode_id, + "normal"), + node_interface(node_interface::exposedfield_id, + field_value::sfnode_id, + "texCoord"), + node_interface(node_interface::field_id, + field_value::sfbool_id, + "ccw"), + node_interface(node_interface::field_id, + field_value::sfbool_id, + "colorPerVertex"), + node_interface(node_interface::field_id, + field_value::sfbool_id, + "normalPerVertex"), + node_interface(node_interface::field_id, + field_value::sfbool_id, + "solid"), + node_interface(node_interface::field_id, + field_value::mfint32_id, + "index") + }; + + static const node_interface_set interface_set(interfaces, interfaces + 11); + add_scope_entry(b, "IndexedQuadSet", interface_set, + "urn:X-openvrml:node:IndexedQuadSet", scope); + } + // QuadSet node + if (level >= 1) { + static const node_interface interfaces[] = { + node_interface(node_interface::exposedfield_id, + field_value::sfnode_id, + "color"), + node_interface(node_interface::exposedfield_id, + field_value::sfnode_id, + "coord"), + node_interface(node_interface::exposedfield_id, + field_value::sfnode_id, + "metadata"), + node_interface(node_interface::exposedfield_id, + field_value::sfnode_id, + "normal"), + node_interface(node_interface::exposedfield_id, + field_value::sfnode_id, + "texCoord"), + node_interface(node_interface::field_id, + field_value::sfbool_id, + "ccw"), + node_interface(node_interface::field_id, + field_value::sfbool_id, + "colorPerVertex"), + node_interface(node_interface::field_id, + field_value::sfbool_id, + "normalPerVertex"), + node_interface(node_interface::field_id, + field_value::sfbool_id, + "solid") + }; + + static const node_interface_set interface_set(interfaces, + interfaces + 9); + add_scope_entry(b, + "QuadSet", + interface_set, + "urn:X-openvrml:node:QuadSet", + scope); + } + } + + class OPENVRML_LOCAL x3d_geospatial_component : public component { public: *************** *** 15873,15876 **** --- 16119,16126 ---- this->insert(key, new x3d_event_utilities_component).second; assert(succeeded); + + key = x3d_cad_geometry_component::id; + succeeded = this->insert(key, new x3d_cad_geometry_component).second; + assert(succeeded); } --- NEW FILE: x3d_cad_geometry.h --- // -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; -*- // // OpenVRML // // Copyright 2006 Braden McDaniel // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // 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 GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // # ifndef OPENVRML_X3D_CAD_GEOMETRY_H # define OPENVRML_X3D_CAD_GEOMETRY_H namespace openvrml { class browser; } extern "C" void register_cad_geometry_node_classes(openvrml::browser & b); # endif Index: vrml97node.cpp =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml/vrml97node.cpp,v retrieving revision 1.103 retrieving revision 1.104 diff -C2 -d -r1.103 -r1.104 *** vrml97node.cpp 16 Apr 2006 08:22:18 -0000 1.103 --- vrml97node.cpp 17 May 2006 07:59:50 -0000 1.104 *************** *** 1111,1114 **** --- 1111,1148 ---- OPENVRML_THROW2(unsupported_interface, std::bad_alloc); }; + + /** + * @brief Class object for CADLayer nodes. + */ + class OPENVRML_LOCAL cad_layer_class : public node_class { + public: + static const char * const id; + + explicit cad_layer_class(openvrml::browser & browser); + virtual ~cad_layer_class() throw (); + + private: + virtual const boost::shared_ptr<node_type> + do_create_type(const std::string & id, + const node_interface_set & interfaces) const + throw (unsupported_interface, std::bad_alloc); + }; + + /** + * @brief Class object for CADAssembly nodes. + */ + class OPENVRML_LOCAL cad_assembly_class : public node_class { + public: + static const char * const id; + + explicit cad_assembly_class(openvrml::browser & browser); + virtual ~cad_assembly_class() throw (); + + private: + virtual const boost::shared_ptr<node_type> + do_create_type(const std::string & id, + const node_interface_set & interfaces) const + throw (unsupported_interface, std::bad_alloc); + }; } *************** *** 1223,1226 **** --- 1257,1264 ---- b.add_node_class(world_info_class::id, shared_ptr<node_class>(new world_info_class(b))); + b.add_node_class(cad_layer_class::id, + shared_ptr<node_class>(new cad_layer_class(b))); + b.add_node_class(cad_assembly_class::id, + shared_ptr<node_class>(new cad_assembly_class(b))); } *************** *** 27130,27132 **** --- 27168,27842 ---- world_info_node::~world_info_node() OPENVRML_NOTHROW {} + + + class OPENVRML_LOCAL cad_layer_node : + public grouping_node_base<cad_layer_node> { + + friend class cad_layer_class; + + class visible_exposedfield : public exposedfield<mfbool> { + public: + explicit visible_exposedfield(cad_layer_node & node); + visible_exposedfield(const visible_exposedfield & obj) + throw (); + virtual ~visible_exposedfield() throw (); + + private: + virtual std::auto_ptr<field_value> do_clone() const + throw (std::bad_alloc); + virtual void event_side_effect(const mfbool & visible, + double timestamp) + throw (std::bad_alloc); + }; + friend class visible_exposedfield; + + exposedfield<sfstring> name_; + visible_exposedfield visible_; + + //holds all currently visible nodes + mfnode current_children_; + + public: + cad_layer_node(const node_type & type, + const boost::shared_ptr<openvrml::scope> & scope); + virtual ~cad_layer_node() throw (); + + virtual bool modified() const; + + private: + virtual void do_children_event_side_effect(const mfnode & choice, + double timestamp) + throw (std::bad_alloc); + + virtual void do_render_child(openvrml::viewer & viewer, + rendering_context context); + virtual const std::vector<boost::intrusive_ptr<node> > & + do_children() const throw (); + virtual void recalc_bsphere(); + }; + + + /** + * @brief @c node_class identifier. + */ + const char * const cad_layer_class::id = "urn:X-openvrml:node:CADLayer"; + + /** + * @brief Construct. + * + * @param browser the @c browser associated with this @c cad_layer_class. + */ + cad_layer_class::cad_layer_class(openvrml::browser & browser): + node_class(cad_layer_class::id, browser) + {} + + /** + * @brief Destroy. + */ + cad_layer_class::~cad_layer_class() throw () + {} + + /** + * @brief Create a node_type. + * + * @param id the name for the new node_type. + * @param interfaces the interfaces for the new node_type. + * + * @return a node_type_ptr to a node_type capable of creating CADLayer nodes. + * + * @exception unsupported_interface if @p interfaces includes an interface + * not supported by cad_layer_class. + * @exception std::bad_alloc if memory allocation fails. + */ + const boost::shared_ptr<openvrml::node_type> + cad_layer_class::do_create_type(const std::string & id, + const node_interface_set & interfaces) const + throw (unsupported_interface, std::bad_alloc) + { + typedef boost::array<node_interface, 8> supported_interfaces_t; + static const supported_interfaces_t supported_interfaces = { + node_interface(node_interface::eventin_id, + field_value::mfnode_id, + "addChildren"), + node_interface(node_interface::eventin_id, + field_value::mfnode_id, + "removeChildren"), + node_interface(node_interface::exposedfield_id, + field_value::mfnode_id, + "children"), + node_interface(node_interface::exposedfield_id, + field_value::sfnode_id, + "metadata"), + node_interface(node_interface::exposedfield_id, + field_value::sfstring_id, + "name"), + node_interface(node_interface::exposedfield_id, + field_value::mfbool_id, + "visible"), + node_interface(node_interface::field_id, + field_value::sfvec3f_id, + "bboxCenter"), + node_interface(node_interface::field_id, + field_value::sfvec3f_id, + "bboxSize") + }; + typedef node_type_impl<cad_layer_node> node_type_t; + + const boost::shared_ptr<node_type> type(new node_type_t(*this, id)); + node_type_t & the_node_type = static_cast<node_type_t &>(*type); + + for (node_interface_set::const_iterator interface(interfaces.begin()); + interface != interfaces.end(); + ++interface) { + supported_interfaces_t::const_iterator supported_interface = + supported_interfaces.begin() - 1; + if (*interface == *++supported_interface) { + the_node_type.add_eventin( + supported_interface->field_type, + supported_interface->id, + node_type_t::event_listener_ptr_ptr( + new node_type_t::event_listener_ptr< + cad_layer_node::add_children_listener>( + &cad_layer_node::add_children_listener_))); + } else if (*interface == *++supported_interface) { + the_node_type.add_eventin( + supported_interface->field_type, + supported_interface->id, + node_type_t::event_listener_ptr_ptr( + new node_type_t::event_listener_ptr< + cad_layer_node::remove_children_listener>( + &cad_layer_node::remove_children_listener_))); + } else if (*interface == *++supported_interface) { + the_node_type.add_exposedfield( + supported_interface->field_type, + supported_interface->id, + node_type_t::event_listener_ptr_ptr( + new node_type_t::event_listener_ptr< + cad_layer_node::children_exposedfield>( + &cad_layer_node::children_)), + node_type_t::field_ptr_ptr( + new node_type_t::field_ptr< + cad_layer_node::children_exposedfield>( + &cad_layer_node::children_)), + node_type_t::event_emitter_ptr_ptr( + new node_type_t::event_emitter_ptr< + cad_layer_node::children_exposedfield>( + &cad_layer_node::children_))); + } else if (*interface == *++supported_interface) { + the_node_type.add_exposedfield( + supported_interface->field_type, + supported_interface->id, + node_type_t::event_listener_ptr_ptr( + new node_type_t::event_listener_ptr< + abstract_node<cad_layer_node>::exposedfield<sfnode> >( + &cad_layer_node::metadata)), + node_type_t::field_ptr_ptr( + new node_type_t::field_ptr< + abstract_node<cad_layer_node>::exposedfield<sfnode> >( + &cad_layer_node::metadata)), + node_type_t::event_emitter_ptr_ptr( + new node_type_t::event_emitter_ptr< + abstract_node<cad_layer_node>::exposedfield<sfnode> >( + &cad_layer_node::metadata))); + } else if (*interface == *++supported_interface) { + the_node_type.add_exposedfield( + supported_interface->field_type, + supported_interface->id, + node_type_t::event_listener_ptr_ptr( + new node_type_t::event_listener_ptr< + abstract_node<cad_layer_node>::exposedfield<sfstring> >( + &cad_layer_node::name_)), + node_type_t::field_ptr_ptr( + new node_type_t::field_ptr< + abstract_node<cad_layer_node>::exposedfield<sfstring> >( + &cad_layer_node::name_)), + node_type_t::event_emitter_ptr_ptr( + new node_type_t::event_emitter_ptr< + abstract_node<cad_layer_node>::exposedfield<sfstring> >( + &cad_layer_node::name_))); + } else if (*interface == *++supported_interface) { + the_node_type.add_exposedfield( + supported_interface->field_type, + supported_interface->id, + node_type_t::event_listener_ptr_ptr( + new node_type_t::event_listener_ptr< + cad_layer_node::visible_exposedfield>( + &cad_layer_node::visible_)), + node_type_t::field_ptr_ptr( + new node_type_t::field_ptr< + cad_layer_node::visible_exposedfield>( + &cad_layer_node::visible_)), + node_type_t::event_emitter_ptr_ptr( + new node_type_t::event_emitter_ptr< + cad_layer_node::visible_exposedfield>( + &cad_layer_node::visible_))); + } else if (*interface == *++supported_interface) { + the_node_type.add_field( + supported_interface->field_type, + supported_interface->id, + node_type_t::field_ptr_ptr( + new node_type_t::field_ptr<sfvec3f>( + &cad_layer_node::bbox_center_))); + } else if (*interface == *++supported_interface) { + the_node_type.add_field( + supported_interface->field_type, + supported_interface->id, + node_type_t::field_ptr_ptr( + new node_type_t::field_ptr<sfvec3f>( + &cad_layer_node::bbox_size_))); + } + } + return type; + } + + + /** + * @var cad_layer_node::visible_exposedfield cad_layer_node::visible_ + * + * @brief visible exposedField. + */ + + /** + * @class cad_layer_node + * + * @brief Represents CADLayer node instances. + */ + + /** + * @var cad_layer_node::CADLayer_class + * + * @brief Class object for CADLayer nodes. + */ + + /** + * @var cad_layer_node::name_t cad_layer_node::name_ + * + * @brief name exposedField + */ + + /** + * @var cad_layer_node::visible_exposedfield cad_layer_node::visible_ + * + * @brief visible exposedField + */ + + /** + * @brief Process event. + * + * @param choice choice nodes. + * @param timestamp the current time. + * + * @exception std::bad_alloc if memory allocation fails. + */ + void cad_layer_node:: + do_children_event_side_effect(const mfnode &, double) throw (std::bad_alloc) + { + try { + const std::vector<bool> & visible = this->visible_.mfbool::value(); + const mfnode::value_type & all_children = + this->children_.mfnode::value(); + + mfnode::value_type children(visible.size()); + + //add only the visible children + for (size_t i = 0; i < visible.size() && i < all_children.size(); ++i) + { + if (visible[i]) + children.push_back(all_children[i]); + } + + this->current_children_.value(children); + } catch (std::bad_cast & ex) { + OPENVRML_PRINT_EXCEPTION_(ex); + } + } + + /** + * @internal + * + * @class cad_layer_node::visible_exposedfield + * + * @brief choice exposedField implementation. + */ + + /** + * @brief Construct. + * + * @param node cad_layer_node. + */ + cad_layer_node::visible_exposedfield:: + visible_exposedfield(cad_layer_node & node): + node_event_listener(node), + openvrml::event_emitter(static_cast<const field_value &>(*this)), + node_field_value_listener<mfbool>(node), + exposedfield<mfbool>(node) + {} + + /** + * @brief Construct a copy. + * + * @param obj instance to copy. + */ + cad_layer_node::visible_exposedfield:: + visible_exposedfield(const visible_exposedfield & obj) throw (): + openvrml::event_listener(), + node_event_listener(obj.node_event_listener::node()), + openvrml::event_emitter(static_cast<const field_value &>(*this)), + node_field_value_listener<mfbool>(obj.node_event_listener::node()), + exposedfield<openvrml::mfbool>(obj) + {} + + /** + * @brief Destroy. + */ + cad_layer_node::visible_exposedfield:: + ~visible_exposedfield() throw () + {} + + /** + * @brief Polymorphically construct a copy. + * + * @return a copy of the instance. + * + * @exception std::bad_alloc if memory allocation fails. + */ + std::auto_ptr<openvrml::field_value> + cad_layer_node::visible_exposedfield::do_clone() const + throw (std::bad_alloc) + { + return std::auto_ptr<openvrml::field_value>( + new visible_exposedfield(*this)); + } + + /** + * @brief Process event. + * + * @param visible choice nodes. + * @param timestamp the current time. + * + * @exception std::bad_alloc if memory allocation fails. + */ + void + cad_layer_node::visible_exposedfield:: + event_side_effect(const mfbool &, double time) + throw (std::bad_alloc) + { + try { + cad_layer_node & n = + dynamic_cast<cad_layer_node &>( + this->node_event_listener::node()); + n.do_children_event_side_effect(n.children_, time); + } catch (std::bad_cast & ex) { + OPENVRML_PRINT_EXCEPTION_(ex); + } + } + + + /** + * @brief Determine whether the node has been modified. + * + * @return @c true if the node or one of its children has been modified, + * @c false otherwise. + */ + bool cad_layer_node::modified() const + { + if (this->node::modified()) { return true; } + + mfnode::value_type::const_iterator iter = + current_children_.value().begin(); + for (; iter != current_children_.value().end(); ++iter) + { + if ((*iter)->modified()) + return true; + } + return false; + } + + /** + * @brief Render the node. + * + * The child corresponding to @a whichChoice is rendered. Nothing is + * rendered if @a whichChoice is -1. + * + * @param viewer a Viewer. + * @param context a rendering context. + */ + void + cad_layer_node:: + do_render_child(openvrml::viewer & viewer, const rendering_context context) + { + mfnode::value_type::const_iterator iter = + current_children_.value().begin(); + for (; iter != current_children_.value().end(); ++iter) + { + child_node * const child = node_cast<child_node *>(iter->get()); + if (child) { child->render_child(viewer, context); } + } + + this->node::modified(false); + } + + /** + * @brief Get the children in the scene graph. + * + * @return the child nodes in the scene graph. + */ + const std::vector<boost::intrusive_ptr<openvrml::node> > & + cad_layer_node::do_children() const throw () + { + return this->current_children_.value(); + } + + /** + * @brief Recalculate the bounding volume. + */ + void cad_layer_node::recalc_bsphere() + { + this->bsphere = bounding_sphere(); + + mfnode::value_type::const_iterator iter = + current_children_.value().begin(); + for (; iter != current_children_.value().end(); ++iter) + { + bounded_volume_node * bounded_volume = + node_cast<bounded_volume_node *>(iter->get()); + + if (bounded_volume) { + const openvrml::bounding_volume & ci_bv = + bounded_volume->bounding_volume(); + this->bsphere.extend(ci_bv); + } + } + this->bounding_volume_dirty(false); + } + + /** + * @brief Construct. + * + * @param type the node_type associated with this node. + * @param scope the scope to which the node belongs. + */ + cad_layer_node:: + cad_layer_node(const node_type & type, + const boost::shared_ptr<openvrml::scope> & scope): + node(type, scope), + bounded_volume_node(type, scope), + child_node(type, scope), + grouping_node(type, scope), + grouping_node_base<self_t>(type, scope), + name_(*this), + visible_(*this) + {} + + /** + * @brief Destroy. + */ + cad_layer_node::~cad_layer_node() throw () + {} + + + class OPENVRML_LOCAL cad_assembly_node : + public grouping_node_base<cad_assembly_node> { + friend class cad_assembly_class; + + //for CADAssembly node + exposedfield<sfstring> name_; + + public: + cad_assembly_node(const node_type & type, + const boost::shared_ptr<openvrml::scope> & scope); + virtual ~cad_assembly_node() throw (); + }; + + /** + * @brief @c node_class identifier. + */ + const char * const cad_assembly_class::id = + "urn:X-openvrml:node:CADAssembly"; + + /** + * @brief Construct. + * + * @param browser the @c browser associated with this @c node_class object. + */ + cad_assembly_class::cad_assembly_class(openvrml::browser & browser): + node_class(cad_layer_class::id, browser) + {} + + /** + * @brief Destroy. + */ + cad_assembly_class::~cad_assembly_class() throw () {} + + /** + * @brief Create a node_type. + * + * @param id the name for the new node_type. + * @param interfaces the interfaces for the new node_type. + * + * @return a boost::shared_ptr<node_type> to a node_type capable of + * creating Group nodes. + * + * @exception unsupported_interface if @p interfaces includes an interface + * not supported by cad_assembly_class. + * @exception std::bad_alloc if memory allocation fails. + */ + const boost::shared_ptr<openvrml::node_type> + cad_assembly_class:: + do_create_type(const std::string & id, + const node_interface_set & interfaces) const + throw (unsupported_interface, std::bad_alloc) + { + typedef boost::array<node_interface, 7> supported_interfaces_t; + static const supported_interfaces_t supported_interfaces = { + node_interface(node_interface::eventin_id, + field_value::mfnode_id, + "addChildren"), + node_interface(node_interface::eventin_id, + field_value::mfnode_id, + "removeChildren"), + node_interface(node_interface::exposedfield_id, + field_value::mfnode_id, + "children"), + node_interface(node_interface::field_id, + field_value::sfvec3f_id, + "bboxCenter"), + node_interface(node_interface::field_id, + field_value::sfvec3f_id, + "bboxSize"), + node_interface(node_interface::exposedfield_id, + field_value::sfnode_id, + "metadata"), + node_interface(node_interface::exposedfield_id, + field_value::sfstring_id, + "name") + }; + + typedef node_type_impl<cad_assembly_node> node_type_t; + + const boost::shared_ptr<node_type> type(new node_type_t(*this, id)); + node_type_t & theNodeType = static_cast<node_type_t &>(*type); + for (node_interface_set::const_iterator interface(interfaces.begin()); + interface != interfaces.end(); + ++interface) { + supported_interfaces_t::const_iterator supported_interface = + supported_interfaces.begin() - 1; + if (*interface == *++supported_interface) { + theNodeType.add_eventin( + supported_interface->field_type, + supported_interface->id, + node_type_t::event_listener_ptr_ptr( + new node_type_t::event_listener_ptr< + cad_assembly_node::add_children_listener>( + &cad_assembly_node::add_children_listener_))); + } else if (*interface == *++supported_interface) { + theNodeType.add_eventin( + supported_interface->field_type, + supported_interface->id, + node_type_t::event_listener_ptr_ptr( + new node_type_t::event_listener_ptr< + cad_assembly_node::remove_children_listener>( + &cad_assembly_node::remove_children_listener_))); + } else if (*interface == *++supported_interface) { + theNodeType.add_exposedfield( + supported_interface->field_type, + supported_interface->id, + node_type_t::event_listener_ptr_ptr( + new node_type_t::event_listener_ptr< + cad_assembly_node::children_exposedfield>( + &cad_assembly_node::children_)), + node_type_t::field_ptr_ptr( + new node_type_t::field_ptr< + cad_assembly_node::children_exposedfield>( + &cad_assembly_node::children_)), + node_type_t::event_emitter_ptr_ptr( + new node_type_t::event_emitter_ptr< + cad_assembly_node::children_exposedfield>( + &cad_assembly_node::children_))); + } else if (*interface == *++supported_interface) { + theNodeType.add_field( + supported_interface->field_type, + supported_interface->id, + node_type_t::field_ptr_ptr( + new node_type_t::field_ptr<sfvec3f>( + &cad_assembly_node::bbox_center_))); + } else if (*interface == *++supported_interface) { + theNodeType.add_field( + supported_interface->field_type, + supported_interface->id, + node_type_t::field_ptr_ptr( + new node_type_t::field_ptr<sfvec3f>( + &cad_assembly_node::bbox_size_))); + } else if (*interface == *++supported_interface) { + theNodeType.add_exposedfield( + supported_interface->field_type, + supported_interface->id, + node_type_t::event_listener_ptr_ptr( + new node_type_t::event_listener_ptr< + abstract_node<cad_assembly_node>::exposedfield<sfnode> >( + &cad_assembly_node::metadata)), + node_type_t::field_ptr_ptr( + new node_type_t::field_ptr< + abstract_node<cad_assembly_node>::exposedfield<sfnode> >( + &cad_assembly_node::metadata)), + node_type_t::event_emitter_ptr_ptr( + new node_type_t::event_emitter_ptr< + abstract_node<cad_assembly_node>::exposedfield<sfnode> >( + &cad_assembly_node::metadata))); + } else if (*interface == *++supported_interface) { + theNodeType.add_exposedfield( + supported_interface->field_type, + supported_interface->id, + node_type_t::event_listener_ptr_ptr( + new node_type_t::event_listener_ptr< + abstract_node<cad_assembly_node>::exposedfield<sfstring> > + (&cad_assembly_node::name_)), + node_type_t::field_ptr_ptr( + new node_type_t::field_ptr< + abstract_node<cad_assembly_node>::exposedfield<sfstring> > + (&cad_assembly_node::name_)), + node_type_t::event_emitter_ptr_ptr( + new node_type_t::event_emitter_ptr< + abstract_node<cad_assembly_node>::exposedfield<sfstring> > + (&cad_assembly_node::name_))); + } else { + throw unsupported_interface(*interface); + } + } + return type; + } + + /** + * @class cad_assembly_node + * + * @brief Represents Group node instances. + */ + + /** + * @var cad_assembly_node::cad_assembly_class + * + * @brief Class object for Group nodes. + */ + + /** + * @brief Construct. + */ + cad_assembly_node:: + cad_assembly_node(const node_type & type, + const boost::shared_ptr<openvrml::scope> & scope): + node(type, scope), + bounded_volume_node(type, scope), + child_node(type, scope), + grouping_node(type, scope), + grouping_node_base<cad_assembly_node>(type, scope), + name_(*this) + {} + + /** + * @brief Destroy. + */ + cad_assembly_node::~cad_assembly_node() throw () + {} + + } --- NEW FILE: x3d_cad_geometry.cpp --- // -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; -*- // // OpenVRML // // Copyright 2006 Braden McDaniel // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // 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 GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // # ifdef HAVE_CONFIG_H # include <config.h> # endif # include <boost/array.hpp> # include <private.h> # include "browser.h" # include "node_impl_util.h" # include "x3d_cad_geometry.h" using namespace openvrml; using namespace openvrml::node_impl_util; using namespace std; namespace { /** * @brief Class object for CADFace nodes. */ class OPENVRML_LOCAL cad_face_class : public node_class { public: static const char * const id; explicit cad_face_class(openvrml::browser & browser); virtual ~cad_face_class() OPENVRML_NOTHROW; private: virtual const boost::shared_ptr<node_type> do_create_type(const std::string & id, const node_interface_set & interfaces) const OPENVRML_THROW2(unsupported_interface, std::bad_alloc); }; /** * @brief Class object for IndexedQuadSet and QuadSet nodes. */ class OPENVRML_LOCAL quad_set_class : public node_class { public: static const char * const id; explicit quad_set_class(openvrml::browser & browser); virtual ~quad_set_class() OPENVRML_NOTHROW; private: virtual const boost::shared_ptr<node_type> do_create_type(const std::string & id, const node_interface_set & interfaces) const OPENVRML_THROW2(unsupported_interface, std::bad_alloc); }; } void register_cad_geometry_node_classes(openvrml::browser & b) { using openvrml::node_class; using boost::shared_ptr; b.add_node_class(cad_face_class::id, shared_ptr<node_class>(new cad_face_class(b))); //NOTE: This has been moved to vrml97node.cpp for the time being. //b.add_node_class("urn:X-openvrml:node:CADLayer", // shared_ptr<node_class>(new cad_layer_class(b))); b.add_node_class(quad_set_class::id, shared_ptr<node_class>(new quad_set_class(b))); } namespace { using namespace openvrml_; class OPENVRML_LOCAL cad_face_node : public abstract_node<cad_face_node>, public grouping_node { friend class cad_face_class; exposedfield<sfstring> name_; exposedfield<sfnode> shape_; //used by do_children to return the shape std::vector<boost::intrusive_ptr<node> > children_; public: cad_face_node(const node_type & type, const boost::shared_ptr<openvrml::scope> & scope); virtual ~cad_face_node() OPENVRML_NOTHROW; virtual bool modified() const; protected: virtual const openvrml::bounding_volume & do_bounding_volume() const; virtual const std::vector<boost::intrusive_ptr<node> > & do_children() const OPENVRML_NOTHROW; }; class OPENVRML_LOCAL quad_set_node : public abstract_node<quad_set_node>, public geometry_node { friend class quad_set_class; class set_index_listener : public event_listener_base<self_t>, public mfint32_listener { public: explicit set_index_listener(self_t & node); virtual ~set_index_listener() OPENVRML_NOTHROW; private: virtual void do_process_event(const mfint32 & fraction, double timestamp) OPENVRML_THROW1(std::bad_alloc); }; set_index_listener set_index_listener_; exposedfield<sfnode> color_; exposedfield<sfnode> coord_; exposedfield<sfnode> normal_; exposedfield<sfnode> tex_coord_; sfbool ccw_; sfbool color_per_vertex_; sfbool normal_per_vertex_; sfbool solid_; mfint32 index_; bounding_sphere bsphere; public: quad_set_node(const node_type & type, const boost::shared_ptr<openvrml::scope> & scope); virtual ~quad_set_node() OPENVRML_NOTHROW; virtual const color_node * color() const OPENVRML_NOTHROW; virtual bool modified() const; private: virtual const openvrml::bounding_volume & do_bounding_volume() const; virtual viewer::object_t do_render_geometry(openvrml::viewer & viewer, rendering_context context); void recalc_bsphere(); }; /** * @brief @c node_class identifier. */ const char * const cad_face_class::id = "urn:X-openvrml:node:CADFace"; /** * @brief Construct. * * @param browser the browser associated with this cad_face_class. */ cad_face_class::cad_face_class(openvrml::browser & browser): node_class(cad_face_class::id, browser) {} /** * @brief Destroy. */ cad_face_class::~cad_face_class() OPENVRML_NOTHROW {} /** * @brief Create a node_type. * * @param id the name for the new node_type. * @param interfaces the interfaces for the new node_type. * * @return a node_type_ptr to a node_type capable of creating CADFace nodes. * * @exception unsupported_interface if @p interfaces includes an interface * not supported by cad_face_class. * @exception std::bad_alloc if memory allocation fails. */ const boost::shared_ptr<openvrml::node_type> cad_face_class::do_create_type(const std::string & id, const node_interface_set & interfaces) const OPENVRML_THROW2(unsupported_interface, std::bad_alloc) { typedef boost::array<node_interface, 3> supported_interfaces_t; static const supported_interfaces_t supported_interfaces = { node_interface(node_interface::exposedfield_id, field_value::sfnode_id, "metadata"), node_interface(node_interface::exposedfield_id, field_value::sfstring_id, "name"), node_interface(node_interface::exposedfield_id, field_value::sfnode_id, "shape") }; typedef node_type_impl<cad_face_node> node_type_t; const boost::shared_ptr<node_type> type(new node_type_t(*this, id)); node_type_t & the_node_type = static_cast<node_type_t &>(*type); for (node_interface_set::const_iterator interface(interfaces.begin()); interface != interfaces.end(); ++interface) { supported_interfaces_t::const_iterator supported_interface = supported_interfaces.begin() - 1; if (*interface == *++supported_interface) { the_node_type.add_exposedfield( supported_interface->field_type, supported_interface->id, node_type_t::event_listener_ptr_ptr( new node_type_t::event_listener_ptr< abstract_node<cad_face_node>::exposedfield<sfnode> >( &cad_face_node::metadata)), node_type_t::field_ptr_ptr( new node_type_t::field_ptr< abstract_node<cad_face_node>::exposedfield<sfnode> >( &cad_face_node::metadata)), node_type_t::event_emitter_ptr_ptr( new node_type_t::event_emitter_ptr< abstract_node<cad_face_node>::exposedfield<sfnode> >( &cad_face_node::metadata))); } else if (*interface == *++supported_interface) { the_node_type.add_exposedfield( supported_interface->field_type, supported_interface->id, node_type_t::event_listener_ptr_ptr( new node_type_t::event_listener_ptr< abstract_node<cad_face_node>::exposedfield<sfstring> >( &cad_face_node::name_)), node_type_t::field_ptr_ptr( new node_type_t::field_ptr< abstract_node<cad_face_node>::exposedfield<sfstring> >( &cad_face_node::name_)), node_type_t::event_emitter_ptr_ptr( new node_type_t::event_emitter_ptr< abstract_node<cad_face_node>::exposedfield<sfstring> >( &cad_face_node::name_))); } else if (*interface == *++supported_interface) { the_node_type.add_exposedfield( supported_interface->field_type, supported_interface->id, node_type_t::event_listener_ptr_ptr( new node_type_t::event_listener_ptr< abstract_node<cad_face_node>::exposedfield<sfnode> >( &cad_face_node::shape_)), node_type_t::field_ptr_ptr( new node_type_t::field_ptr< abstract_node<cad_face_node>::exposedfield<sfnode> >( &cad_face_node::shape_)), node_type_t::event_emitter_ptr_ptr( new node_type_t::event_emitter_ptr< abstract_node<cad_face_node>::exposedfield<sfnode> >( &cad_face_node::shape_))); } else { throw unsupported_interface(*interface); } } return type; } /** * @brief @c node_class identifier. */ const char * const quad_set_class::id = "urn:X-openvrml:node:QuadSet"; /** * @brief Construct. * * @param browser the browser associated with this quad_set_class. */ quad_set_class::quad_set_class(openvrml::browser & browser): node_class(cad_face_class::id, browser) {} /** * @brief Destroy. */ quad_set_class::~quad_set_class() OPENVRML_NOTHROW {} /** * @brief Create a node_type. * * @param id the name for the new node_type. * @param interfaces the interfaces for the new node_type. * * @return a node_type_ptr to a node_type capable of creating IndexedQuadSet nodes. * * @exception unsupported_interface if @p interfaces includes an interface * not supported by quad_set_class. * @exception std::bad_alloc if memory allocation fails. */ const boost::shared_ptr<openvrml::node_type> quad_set_class::do_create_type(const std::string & id, const node_interface_set & interfaces) const OPENVRML_THROW2(unsupported_interface, std::bad_alloc) { typedef boost::array<node_interface, 11> supported_interfaces_t; static const supported_interfaces_t supported_interfaces = { node_interface(node_interface::eventin_id, field_value::mfint32_id, "set_index"), node_interface(node_interface::exposedfield_id, field_value::sfnode_id, "color"), node_interface(node_interface::exposedfield_id, field_value::sfnode_id, "coord"), node_interface(node_interface::exposedfield_id, field_value::sfnode_id, "metadata"), node_interface(node_interface::exposedfield_id, field_value::sfnode_id, "normal"), node_interface(node_interface::exposedfield_id, field_value::sfnode_id, "texCoord"), node_interface(node_interface::field_id, field_value::sfbool_id, "ccw"), node_interface(node_interface::field_id, field_value::sfbool_id, "colorPerVertex"), node_interface(node_interface::field_id, field_value::sfbool_id, "normalPerVertex"), node_interface(node_interface::field_id, field_value::sfbool_id, "solid"), node_interface(node_interface::field_id, field_value::mfint32_id, "index") }; typedef node_type_impl<quad_set_node> node_type_t; const boost::shared_ptr<node_type> type(new node_type_t(*this, id)); node_type_t & the_node_type = static_cast<node_type_t &>(*type); for (node_interface_set::const_iterator interface(interfaces.begin()); interface != interfaces.end(); ++interface) { supported_interfaces_t::const_iterator supported_interface = supported_interfaces.begin() - 1; if (*interface == *++supported_interface) { the_node_type.add_eventin( supported_interface->field_type, supported_interface->id, node_type_t::event_listener_ptr_ptr( new node_type_t::event_listener_ptr< quad_set_node::set_index_listener>( &quad_set_node::set_index_listener_))); } else if (*interface == *++supported_interface) { the_node_type.add_exposedfield( supported_interface->field_type, supported_interface->id, node_type_t::event_listener_ptr_ptr( new node_type_t::event_listener_ptr< abstract_node<quad_set_node>::exposedfield<sfnode> >( &quad_set_node::color_)), node_type_t::field_ptr_ptr( new node_type_t::field_ptr< abstract_node<quad_set_node>::exposedfield<sfnode> >( &quad_set_node::color_)), node_type_t::event_emitter_ptr_ptr( new node_type_t::event_emitter_ptr< abstract_node<quad_set_node>::exposedfield<sfnode> >( &quad_set_node::color_))); } else if (*interface == *++supported_interface) { the_node_type.add_exposedfield( supported_interface->field_type, supported_interface->id, node_type_t::event_listener_ptr_ptr( new node_type_t::event_listener_ptr< abstract_node<quad_set_node>::exposedfield<sfnode> >( &quad_set_node::coord_)), node_type_t::field_ptr_ptr( new node_type_t::field_ptr< abstract_node<quad_set_node>::exposedfield<sfnode> >( &quad_set_node::coord_)), node_type_t::event_emitter_ptr_ptr( new node_type_t::event_emitter_ptr< abstract_node<quad_set_node>::exposedfield<sfnode> >( &quad_set_node::coord_))); } else if (*interface == *++s... [truncated message content] |