diff --git a/collada_urdf/include/collada_urdf/collada_urdf.h b/collada_urdf/include/collada_urdf/collada_urdf.h index 7030f82..44f5837 100644 --- a/collada_urdf/include/collada_urdf/collada_urdf.h +++ b/collada_urdf/include/collada_urdf/collada_urdf.h @@ -47,6 +47,12 @@ namespace collada_urdf { +class ColladaUrdfException : public std::runtime_error +{ +public: + ColladaUrdfException(std::string const& what); +}; + /** Construct a COLLADA DOM from an URDF file * \param file The filename from where to read the URDF * \param dom The resulting COLLADA DOM diff --git a/collada_urdf/include/collada_urdf/collada_writer.h b/collada_urdf/include/collada_urdf/collada_writer.h index 3bf0c30..6aada98 100644 --- a/collada_urdf/include/collada_urdf/collada_writer.h +++ b/collada_urdf/include/collada_urdf/collada_writer.h @@ -37,6 +37,8 @@ #ifndef COLLADA_URDF_COLLADA_WRITER_H #define COLLADA_URDF_COLLADA_WRITER_H +#include "collada_urdf/collada_urdf.h" + #include #include @@ -55,14 +57,13 @@ namespace collada_urdf { -class ColladaWriterException : public std::runtime_error -{ -public: - ColladaWriterException(std::string const& what) : std::runtime_error(what) { } -}; - class Mesh; +/** + * Implements writing urdf::Model objects to a COLLADA DOM. + * + * The API for this class is unstable. The public API for collada_urdf is declared in collada_urdf.h. + */ class ColladaWriter : public daeErrorHandler { private: diff --git a/collada_urdf/src/collada_urdf.cpp b/collada_urdf/src/collada_urdf.cpp index 69fbd3f..63ea86e 100644 --- a/collada_urdf/src/collada_urdf.cpp +++ b/collada_urdf/src/collada_urdf.cpp @@ -42,6 +42,11 @@ using boost::shared_ptr; namespace collada_urdf { +ColladaUrdfException::ColladaUrdfException(std::string const& what) + : std::runtime_error(what) +{ +} + bool colladaFromUrdfFile(string const& file, shared_ptr& dom) { TiXmlDocument urdf_xml; if (!urdf_xml.LoadFile(file)) { diff --git a/collada_urdf/src/collada_writer.cpp b/collada_urdf/src/collada_writer.cpp index 7265365..8fe3dea 100644 --- a/collada_urdf/src/collada_writer.cpp +++ b/collada_urdf/src/collada_writer.cpp @@ -79,7 +79,7 @@ shared_ptr ColladaWriter::convert() { return collada_; } - catch (ColladaWriterException ex) { + catch (ColladaUrdfException ex) { ROS_ERROR("Error converting: %s", ex.what()); return shared_ptr(); } @@ -88,7 +88,7 @@ shared_ptr ColladaWriter::convert() { // Implementation void ColladaWriter::handleError(daeString msg) { - throw ColladaWriterException(msg); + throw ColladaUrdfException(msg); } void ColladaWriter::handleWarning(daeString msg) { @@ -100,7 +100,7 @@ void ColladaWriter::initDocument(string const& documentName) { daeDocument* doc = NULL; daeInt error = collada_->getDatabase()->insertDocument(documentName.c_str(), &doc); // also creates a collada root if (error != DAE_OK || doc == NULL) - throw ColladaWriterException("Failed to create document"); + throw ColladaUrdfException("Failed to create document"); dom_ = daeSafeCast(doc->getDomRoot()); dom_->setAttribute("xmlns:math", "http://www.w3.org/1998/Math/MathML"); @@ -258,7 +258,7 @@ void ColladaWriter::loadMesh(string const& filename, domGeometryRef geometry, st try { loadMeshWithSTLLoader(resource, geometry, geometry_id); } - catch (ColladaWriterException e) { + catch (ColladaUrdfException e) { std::cerr << "Unable to load mesh file " << filename << ": " << e.what() << std::endl; } } @@ -268,12 +268,12 @@ bool ColladaWriter::loadMeshWithSTLLoader(resource_retriever::MemoryResource con char tmp_filename[] = "/tmp/collada_urdf_XXXXXX"; int fd = mkstemp(tmp_filename); if (fd == -1) - throw ColladaWriterException("Couldn't create temporary file"); + throw ColladaUrdfException("Couldn't create temporary file"); if ((uint32_t) write(fd, resource.data.get(), resource.size) != resource.size) { close(fd); unlink(tmp_filename); - throw ColladaWriterException("Couldn't write resource to file"); + throw ColladaUrdfException("Couldn't write resource to file"); } close(fd); @@ -282,7 +282,7 @@ bool ColladaWriter::loadMeshWithSTLLoader(resource_retriever::MemoryResource con shared_ptr stl_mesh = loader.load(string(tmp_filename)); if (stl_mesh == shared_ptr()) { unlink(tmp_filename); - throw ColladaWriterException("Couldn't import mesh with STLLoader"); + throw ColladaUrdfException("Couldn't import STL mesh"); } // Build the COLLADA mesh