diff --git a/VirtualRobot/Nodes/RobotNode.cpp b/VirtualRobot/Nodes/RobotNode.cpp index a7e567aafee3dbc0216178d9ea995b76520d9bee..0718269f0b965a594f16f89fe0453f1b26b2ea63 100644 --- a/VirtualRobot/Nodes/RobotNode.cpp +++ b/VirtualRobot/Nodes/RobotNode.cpp @@ -15,6 +15,7 @@ #include <boost/math/special_functions/fpclassify.hpp> #include <boost/pointer_cast.hpp> +#include <boost/filesystem.hpp> #include <Eigen/Core> @@ -693,7 +694,7 @@ std::vector<SensorPtr> RobotNode::getSensors() const return sensors; } -std::string RobotNode::toXML( const std::string &modelPath /*= "models"*/, bool storeSensors ) +std::string RobotNode::toXML( const std::string &basePath, const std::string &modelPathRelative /*= "models"*/, bool storeSensors ) { std::stringstream ss; ss << "\t<RobotNode name='" << name << "'>" << endl; @@ -703,24 +704,35 @@ std::string RobotNode::toXML( const std::string &modelPath /*= "models"*/, bool ss << BaseIO::toXML(localTransformation,"\t\t\t"); ss << "\t\t</Transform>" << endl; } - ss << _toXML(modelPath); + ss << _toXML(modelPathRelative); if (physics.isSet()) ss << physics.toXML(2); - if (visualizationModel && visualizationModel->getTriMeshModel() && visualizationModel->getTriMeshModel()->faces.size()>0) + boost::filesystem::path pBase(basePath); + if (visualizationModel && visualizationModel->getTriMeshModel() && visualizationModel->getTriMeshModel()->faces.size()>0) { std::string visuFile = getFilenameReplacementVisuModel(); - ss << visualizationModel->toXML(modelPath,visuFile,2); + + boost::filesystem::path pModel(modelPathRelative); + boost::filesystem::path modelDirComplete = boost::filesystem::operator/(pBase,pModel); + boost::filesystem::path fn(visuFile); + boost::filesystem::path modelFileComplete = boost::filesystem::operator/(modelDirComplete,fn); + + ss << visualizationModel->toXML(pBase.string(),modelFileComplete.string(),2); } if (collisionModel && collisionModel->getTriMeshModel() && collisionModel->getTriMeshModel()->faces.size()>0) { std::string colFile = getFilenameReplacementColModel(); - ss << collisionModel->toXML(modelPath,colFile,2); + boost::filesystem::path pModel(modelPathRelative); + boost::filesystem::path modelDirComplete = boost::filesystem::operator/(pBase,pModel); + boost::filesystem::path fn(colFile); + boost::filesystem::path modelFileComplete = boost::filesystem::operator/(modelDirComplete,fn); + ss << collisionModel->toXML(pBase.string(),modelFileComplete.string(),2); } if (storeSensors) { for (size_t i=0;i<sensors.size();i++) { - ss << sensors[i]->toXML(modelPath,2); + ss << sensors[i]->toXML(modelPathRelative,2); } } diff --git a/VirtualRobot/Nodes/RobotNode.h b/VirtualRobot/Nodes/RobotNode.h index 2654d27fbe29b4ab97f24a39c0cad72421efc647..4eceffdb27d68a94b53db6c69a19311faef2cb45 100644 --- a/VirtualRobot/Nodes/RobotNode.h +++ b/VirtualRobot/Nodes/RobotNode.h @@ -291,7 +291,7 @@ public: Creates an XML string that defines the robotnode. Filenames of all visualization models are set to modelPath/RobotNodeName_visu and/or modelPath/RobotNodeName_colmodel. @see RobotIO::saveXML. */ - virtual std::string toXML(const std::string &modelPath = "models", bool storeSensors = true); + virtual std::string toXML( const std::string &basePath, const std::string &modelPathRelative = "models", bool storeSensors = true); protected: diff --git a/VirtualRobot/Robot.cpp b/VirtualRobot/Robot.cpp index c758af208eeb29a1db45ad6fbb18b79bf89e431e..422ae3311629354a9db2348c5f926cd5581ea11c 100644 --- a/VirtualRobot/Robot.cpp +++ b/VirtualRobot/Robot.cpp @@ -865,7 +865,7 @@ std::vector<SensorPtr> Robot::getSensors() return result; } -std::string Robot::toXML( const std::string &modelPath /*= "models"*/, bool storeEEF, bool storeRNS, bool storeSensors ) +std::string Robot::toXML(const std::string &basePath, const std::string &modelPath /*= "models"*/, bool storeEEF, bool storeRNS, bool storeSensors ) { std::stringstream ss; ss << "<?xml version='1.0' encoding='UTF-8'?>" << endl << endl; @@ -873,7 +873,7 @@ std::string Robot::toXML( const std::string &modelPath /*= "models"*/, bool stor std::vector<RobotNodePtr> nodes = getRobotNodes(); for (size_t i=0;i<nodes.size();i++) { - ss << nodes[i]->toXML(modelPath, storeSensors) << endl; + ss << nodes[i]->toXML(basePath, modelPath, storeSensors) << endl; } ss << endl; if (storeRNS) diff --git a/VirtualRobot/Robot.h b/VirtualRobot/Robot.h index 9a6bd36e0b4a9c0001d95270c4a65447e68f091e..d64479b7f4871aace0379635e05bed6c8658f49f 100644 --- a/VirtualRobot/Robot.h +++ b/VirtualRobot/Robot.h @@ -378,7 +378,7 @@ public: Creates an XML string that defines the complete robot. Filenames of all visualization models are set to modelPath/RobotNodeName_visu and/or modelPath/RobotNodeName_colmodel. @see RobotIO::saveXML. */ - virtual std::string toXML(const std::string &modelPath = "models", bool storeEEF = true, bool storeRNS = true, bool storeSensors = true); + virtual std::string toXML(const std::string &basePath = ".", const std::string &modelPath = "models", bool storeEEF = true, bool storeRNS = true, bool storeSensors = true); protected: Robot(); diff --git a/VirtualRobot/XML/RobotIO.cpp b/VirtualRobot/XML/RobotIO.cpp index a9be99e571767b99fd6e049cb3d2b44c6971598e..9c625961e9016529cf147531dac2d97e6d3cadfe 100644 --- a/VirtualRobot/XML/RobotIO.cpp +++ b/VirtualRobot/XML/RobotIO.cpp @@ -1212,7 +1212,7 @@ bool RobotIO::saveXML(RobotPtr robot, const std::string &filename, const std::st return false; } - std::string xmlRob = robot->toXML(modelDir, storeEEF, storeRNS, storeSensors); + std::string xmlRob = robot->toXML(basePath, modelDir, storeEEF, storeRNS, storeSensors); f << xmlRob; f.close();