31 #include <boost/filesystem.hpp>
49 bool make_convex_meshes,
50 std::unordered_map<std::string, tesseract_scene_graph::Material::Ptr>& available_materials)
52 std::string link_name;
54 std::throw_with_nested(std::runtime_error(
"Link: Missing or failed parsing attribute 'name'!"));
56 auto l = std::make_shared<tesseract_scene_graph::Link>(link_name);
59 const tinyxml2::XMLElement* inertial = xml_element->FirstChildElement(
"inertial");
60 if (inertial !=
nullptr)
68 std::throw_with_nested(
69 std::runtime_error(
"Link: Error parsing 'inertial' element for link '" + link_name +
"'!"));
74 for (
const tinyxml2::XMLElement* visual = xml_element->FirstChildElement(
"visual"); visual !=
nullptr;
75 visual = visual->NextSiblingElement(
"visual"))
80 temp_visual =
parseVisual(visual, locator, available_materials);
84 std::throw_with_nested(std::runtime_error(
"Link: Error parsing 'visual' element for link '" + link_name +
"'!"));
87 l->visual.push_back(temp_visual);
91 for (
const tinyxml2::XMLElement* collision = xml_element->FirstChildElement(
"collision"); collision !=
nullptr;
92 collision = collision->NextSiblingElement(
"collision"))
97 temp_collision =
parseCollision(collision, locator, make_convex_meshes);
101 std::throw_with_nested(
102 std::runtime_error(
"Link: Error parsing 'collision' element for link '" + link_name +
"'!"));
105 l->collision.push_back(temp_collision);
111 tinyxml2::XMLElement*
writeLink(
const std::shared_ptr<const tesseract_scene_graph::Link>& link,
112 tinyxml2::XMLDocument& doc,
113 const std::string& package_path)
116 std::throw_with_nested(std::runtime_error(
"Link is nullptr and cannot be converted to XML"));
120 xml_element->SetAttribute(
"name", link->getName().c_str());
123 if (link->inertial !=
nullptr)
125 tinyxml2::XMLElement* xml_inertial =
writeInertial(link->inertial, doc);
126 xml_element->InsertEndChild(xml_inertial);
131 if (link->visual.size() > 1)
137 std::filesystem::create_directory(std::filesystem::path(
trailingSlash(package_path) +
"visual/"));
138 tinyxml2::XMLElement* xml_visual =
writeVisual(vis, doc, package_path, link->getName(),
id++);
139 xml_element->InsertEndChild(xml_visual);
143 std::throw_with_nested(std::runtime_error(
"Could not write visual to XML for link `" + link->getName() +
"`!"));
149 if (link->collision.size() > 1)
155 std::filesystem::create_directory(std::filesystem::path(
trailingSlash(package_path) +
"collision/"));
156 tinyxml2::XMLElement* xml_collision =
writeCollision(col, doc, package_path, link->getName(),
id++);
157 xml_element->InsertEndChild(xml_collision);
161 std::throw_with_nested(
162 std::runtime_error(
"Could not write collision to XML for link `" + link->getName() +
"`!"));