From 509bc2f5fa256cd713ff365417c97ddcff9f6167 Mon Sep 17 00:00:00 2001 From: vahrenkamp <vahrenkamp@042f3d55-54a8-47e9-b7fb-15903f145c44> Date: Mon, 10 Nov 2014 13:22:41 +0000 Subject: [PATCH] fixed relative path bug in export to XML git-svn-id: http://svn.code.sf.net/p/simox/code/trunk@728 042f3d55-54a8-47e9-b7fb-15903f145c44 --- VirtualRobot/Nodes/RobotNode.cpp | 24 ++++++++++++++++++------ VirtualRobot/Nodes/RobotNode.h | 2 +- VirtualRobot/Robot.cpp | 4 ++-- VirtualRobot/Robot.h | 2 +- VirtualRobot/XML/RobotIO.cpp | 2 +- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/VirtualRobot/Nodes/RobotNode.cpp b/VirtualRobot/Nodes/RobotNode.cpp index a7e567aaf..0718269f0 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 2654d27fb..4eceffdb2 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 c758af208..422ae3311 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 9a6bd36e0..d64479b7f 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 a9be99e57..9c625961e 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(); -- GitLab