diff --git a/VirtualRobot/examples/MjcfConverter/SimoxXMLDocument.cpp b/VirtualRobot/examples/MjcfConverter/SimoxXMLDocument.cpp index a7cf8671f6f7b083500d792a0284d3c534d9ce4b..00915d28cda30f3d1edd227bbf526d4b1b2f5a46 100644 --- a/VirtualRobot/examples/MjcfConverter/SimoxXMLDocument.cpp +++ b/VirtualRobot/examples/MjcfConverter/SimoxXMLDocument.cpp @@ -28,7 +28,6 @@ void SimoxXMLDocument::LoadFile(const fs::path& path) collisionModelFiles.clear(); visualizationFiles.clear(); - includedFiles.clear(); XMLNode* xmlRobot = FirstChildElement("Robot"); assert(xmlRobot); @@ -36,7 +35,7 @@ void SimoxXMLDocument::LoadFile(const fs::path& path) SimoxXMLVisitor visitor(*this); xmlRobot->Accept(&visitor); - for (fs::path file : includedFiles) + for (fs::path file : visitor.includedFiles) { VR_INFO << "Loading included XML: " << file << std::endl; @@ -140,7 +139,7 @@ bool SimoxXMLVisitor::VisitEnter(const tinyxml2::XMLElement& elem, const tinyxml assert(file); fs::path relPath = file->GetText(); - xml.includedFiles.push_back(xml.inputFilePath.parent_path() / relPath); + includedFiles.push_back(xml.inputFilePath.parent_path() / relPath); } return true; diff --git a/VirtualRobot/examples/MjcfConverter/SimoxXMLDocument.h b/VirtualRobot/examples/MjcfConverter/SimoxXMLDocument.h index 41fd4a0e14b6631a3e1038f1268278411562569e..b0b6c5c69cdcbc69579f02b184fe3c07f3cce64d 100644 --- a/VirtualRobot/examples/MjcfConverter/SimoxXMLDocument.h +++ b/VirtualRobot/examples/MjcfConverter/SimoxXMLDocument.h @@ -11,7 +11,11 @@ namespace VirtualRobot { - + +/** + * @brief A Simox XML document offering access to information not included + * in a VirtualRobot::Robot. + */ class SimoxXMLDocument : private tinyxml2::XMLDocument { using Base = tinyxml2::XMLDocument; @@ -20,48 +24,78 @@ class SimoxXMLDocument : private tinyxml2::XMLDocument public: + /// Constructor. SimoxXMLDocument(); + /** + * @brief Load a Simox XML file. + * Loads the given XML file and traverses it to collect the wanted + * information. If the file references any other XML files via a + * <ChildFromRobot> element, loads that as well and aggregates its + * information into this. + */ void LoadFile(const boost::filesystem::path& path); + /// @see LoadFile(const boost::filesyste::path&) void LoadFile(const std::string& path); - + /// Indicate whether a RobotNode has specified a collision model file. bool hasCollisionModelFile(RobotNodePtr robotNode) const; + /// Indicate whether a RobotNode has specified a visualization file. bool hasVisualizationFile(RobotNodePtr robotNode) const; + /// Get the collision model file of a RobotNode. If the node did not + /// specify a collision model file, an empty path is returned. boost::filesystem::path collisionModelFile(RobotNodePtr robotNode) const; + /// Get the visualization file of a RobotNode. If the node did not + /// specify a visualization model file, an empty path is returned. boost::filesystem::path visualizationFile(RobotNodePtr robotNode) const; private: + /// Map from (node) name to a path. using NamePathMap = std::map<std::string, boost::filesystem::path>; - + /// Return true when there is an entry for the robot node in the map. bool hasEntry(RobotNodePtr robotNode, const NamePathMap& map) const; + /// Return the value of the robot node in the map. If none is found, return an empty path. boost::filesystem::path getEntry(RobotNodePtr robotNode, const NamePathMap& map) const; - + /// The input file path. Necessary for resolving relative paths. boost::filesystem::path inputFilePath; + /// The collision model files of RobotNodes. NamePathMap collisionModelFiles; + /// The visualization files of RobotNodes. NamePathMap visualizationFiles; - std::vector<boost::filesystem::path> includedFiles; + }; +/** + * @brief The SimoxXMLVisitor class + */ class SimoxXMLVisitor : public tinyxml2::XMLVisitor { + friend class SimoxXMLDocument; + public: + SimoxXMLVisitor(SimoxXMLDocument& xml); + /// Stores mesh files of RobotNodes, and stores files included <ChildFromRobot> elements. virtual bool VisitEnter(const tinyxml2::XMLElement&, const tinyxml2::XMLAttribute*) override; + private: + SimoxXMLDocument& xml; + /// The files included by the input file. + std::vector<boost::filesystem::path> includedFiles; + };