From: Markus R. <rol...@us...> - 2006-02-19 13:19:28
|
Update of /cvsroot/simspark/simspark/spark/plugin/rosimporter In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25404 Modified Files: roselements.cpp rosimporter.cpp rosimporter.h Log Message: - ignore comments and other unknown XML elements - treat unknown RoSimML tags like <elements> tag - implemented a macro registry that stores XML subtrees indexed by string - implemented RoSim macro definition and instsncing Index: roselements.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/plugin/rosimporter/roselements.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** roselements.cpp 18 Feb 2006 19:52:14 -0000 1.1 --- roselements.cpp 19 Feb 2006 13:19:18 -0000 1.2 *************** *** 62,65 **** --- 62,72 ---- ROS_DEFINE_ELEMENT(RE_CAPPEDCYLINDER,"CappedCylinder"); + ROS_DEFINE_ELEMENT(RE_MACRO, "Macro"); + ROS_DEFINE_ELEMENT(RE_USE, "Use"); + + ROS_DEFINE_ELEMENT(RE_HINGE,"Hinge"); + ROS_DEFINE_ELEMENT(RE_ANCHORPOINT,"AnchorPoint"); + ROS_DEFINE_ELEMENT(RE_AXIS,"Axis"); + ROS_DEFINE_ELEMENT(RE_GLOBALPHYSICALPARAMETERS,"GlobalPhysicalParameters"); ROS_DEFINE_ELEMENT(RE_PHYSICALATTRIBUTES,"PhysicalAttributes"); Index: rosimporter.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/plugin/rosimporter/rosimporter.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** rosimporter.cpp 19 Feb 2006 11:11:58 -0000 1.4 --- rosimporter.cpp 19 Feb 2006 13:19:18 -0000 1.5 *************** *** 52,55 **** --- 52,58 ---- static const string S_GEOM("geometry_"); static const string S_VISUAL("visual_"); + static const string S_MACRO("macro_"); + + RosImporter::TMacroMap RosImporter::mMacroMap; RosImporter::RosImporter() : SceneImporter() *************** *** 151,160 **** ) { ! TiXmlElement* element = static_cast<TiXmlElement*>(node); ! if (element == 0) { continue; } bool ok = true; --- 154,175 ---- ) { ! if (node == 0) ! { ! continue; ! } ! ! switch(node->Type()) { + case TiXmlNode::ELEMENT: + break; + + default: + /** ignore declarations, comments and other + unknown node types + */ continue; } + TiXmlElement* element = static_cast<TiXmlElement*>(node); bool ok = true; *************** *** 173,176 **** --- 188,196 ---- case RosElements::RE_SCENE: ok = ReadScene(parent, element); + break; + + case RosElements::RE_MACRO: + ok = ReadMacro(parent, element); + break; } *************** *** 376,379 **** --- 396,416 ---- ) { + if (node == 0) + { + continue; + } + + switch(node->Type()) + { + case TiXmlNode::ELEMENT: + break; + + default: + /** ignore declarations, comments and other + unknown node types + */ + continue; + } + TiXmlElement* childElement = static_cast<TiXmlElement*>(node); if (! ReadElements(parent, childElement, context)) *************** *** 408,413 **** --- 445,452 ---- { default: + // treat unknown tags like a <element> tag GetLog()->Error() << "(RosImporter::ReadElements) ERROR: skipping unknown element " << GetXMLPath(element) << "\n"; + ok = ReadElements(parent, element, context); break; *************** *** 439,442 **** --- 478,485 ---- ok = ReadHinge(parent,element,context); break; + + case RosElements::RE_USE: + ok = ReadUse(parent,element,context); + break; } *************** *** 921,925 **** shared_ptr<Body> body1 = GetJointParentBody(parent); ! if (! ReadChildElements(parent, element, context)) { return false; --- 964,970 ---- shared_ptr<Body> body1 = GetJointParentBody(parent); ! //! Todo: figure out if all objects below a joint node are ! //implicitly movable, i.e. are created with a Body node ! if (! ReadChildElements(parent, element, NC_MOVABLE)) { return false; *************** *** 934,938 **** { GetLog()->Error() << "(RosImporter::ReadHinge) found no bodies to attach hinge to in " ! << GetXMLPath(element) << "\n"; return false; } --- 979,983 ---- { GetLog()->Error() << "(RosImporter::ReadHinge) found no bodies to attach hinge to in " ! << GetXMLPath(element) << " named " << name << "\n"; return false; } *************** *** 950,951 **** --- 995,1054 ---- GetLog()->Debug() << "(RosImporter) created hinge joint " << name << "\n"; } + + bool RosImporter::ReadMacro(shared_ptr<BaseNode> parent, TiXmlElement* element) + { + string name; + if (! ReadAttribute(element, RA_NAME, name)) + { + return false; + } + + shared_ptr<TiXmlElement> macro(new TiXmlElement(*element)); + mMacroMap[name] = macro; + + GetLog()->Debug() << "(RosImporter) defined macro " << name << "\n"; + } + + bool RosImporter::ReadUse(shared_ptr<BaseNode> parent, TiXmlElement* element, ENodeContext context) + { + string name; + string instance; + Trans trans; + + if ( + (! ReadAttribute(element, RA_MACRONAME, name)) || + (! ReadAttribute(element, RA_INSTANCENAME, instance, true)) || + (! ReadTrans(element, trans)) + ) + { + return false; + } + + TMacroMap::const_iterator iter = mMacroMap.find(name); + if (iter == mMacroMap.end()) + { + GetLog()->Error() << "(RosImporter) use of undefined macro " << name << " in " + << GetXMLPath(element) << "\n"; + return false; + } + + // todo: <SubstituteSurfaces> + // todo: <SubstituteAllSurfaces> + + if (instance.empty()) + { + instance = name; + } + + shared_ptr<Transform> transform = CreateTransform(parent, trans); + transform->SetName(S_MACRO+instance); + + GetLog()->Debug() << "(RosImporter) START instancing macro " << name << "\n"; + + shared_ptr<TiXmlElement> tree = (*iter).second; + bool ok = ReadElements(transform, tree.get(), context); + + GetLog()->Debug() << "(RosImporter) END instancing macro " << name << "\n"; + + return ok; + } Index: rosimporter.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/plugin/rosimporter/rosimporter.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** rosimporter.h 19 Feb 2006 10:44:28 -0000 1.3 --- rosimporter.h 19 Feb 2006 13:19:18 -0000 1.4 *************** *** 23,27 **** #define ROSIMPORTER_H ! #include <list> #include <oxygen/sceneserver/sceneimporter.h> #include <tinyxml/tinyxml.h> --- 23,27 ---- #define ROSIMPORTER_H ! #include <map> #include <oxygen/sceneserver/sceneimporter.h> #include <tinyxml/tinyxml.h> *************** *** 86,89 **** --- 86,94 ---- }; + /** define a registry of macros; a macro is a XML subtree with the + <Macro> node a the root element + */ + typedef std::map<std::string, boost::shared_ptr<TiXmlElement> > TMacroMap; + public: RosImporter(); *************** *** 126,129 **** --- 131,137 ---- bool ReadScene(boost::shared_ptr<oxygen::BaseNode> parent, TiXmlElement* element); + bool ReadMacro(boost::shared_ptr<oxygen::BaseNode> parent, TiXmlElement* element); + bool ReadUse(boost::shared_ptr<oxygen::BaseNode> parent, TiXmlElement* element, ENodeContext context); + bool ReadChildElements(boost::shared_ptr<oxygen::BaseNode> parent, TiXmlElement* element, ENodeContext context); *************** *** 146,150 **** bool ReadAxis(TiXmlElement* element, salt::Vector3f& axis); - boost::shared_ptr<oxygen::Body> RosImporter::GetJointParentBody(boost::shared_ptr<oxygen::BaseNode> parent); boost::shared_ptr<oxygen::Body> RosImporter::GetJointChildBody(boost::shared_ptr<oxygen::BaseNode> parent); --- 154,157 ---- *************** *** 165,168 **** --- 172,179 ---- double mGlobalCFM; + /** the static macro registry is shared across RosImporter + instances + */ + static TMacroMap mMacroMap; }; |