collada_urdf: ColladaWriterException -> ColladaUrdfException

This commit is contained in:
tfield 2010-04-26 19:00:40 +00:00
parent 3ab12d3c7f
commit de6ad90cf1
4 changed files with 25 additions and 13 deletions

View File

@ -47,6 +47,12 @@
namespace collada_urdf { namespace collada_urdf {
class ColladaUrdfException : public std::runtime_error
{
public:
ColladaUrdfException(std::string const& what);
};
/** Construct a COLLADA DOM from an URDF file /** Construct a COLLADA DOM from an URDF file
* \param file The filename from where to read the URDF * \param file The filename from where to read the URDF
* \param dom The resulting COLLADA DOM * \param dom The resulting COLLADA DOM

View File

@ -37,6 +37,8 @@
#ifndef COLLADA_URDF_COLLADA_WRITER_H #ifndef COLLADA_URDF_COLLADA_WRITER_H
#define COLLADA_URDF_COLLADA_WRITER_H #define COLLADA_URDF_COLLADA_WRITER_H
#include "collada_urdf/collada_urdf.h"
#include <map> #include <map>
#include <dae.h> #include <dae.h>
@ -55,14 +57,13 @@
namespace collada_urdf { namespace collada_urdf {
class ColladaWriterException : public std::runtime_error
{
public:
ColladaWriterException(std::string const& what) : std::runtime_error(what) { }
};
class Mesh; 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 class ColladaWriter : public daeErrorHandler
{ {
private: private:

View File

@ -42,6 +42,11 @@ using boost::shared_ptr;
namespace collada_urdf { namespace collada_urdf {
ColladaUrdfException::ColladaUrdfException(std::string const& what)
: std::runtime_error(what)
{
}
bool colladaFromUrdfFile(string const& file, shared_ptr<DAE>& dom) { bool colladaFromUrdfFile(string const& file, shared_ptr<DAE>& dom) {
TiXmlDocument urdf_xml; TiXmlDocument urdf_xml;
if (!urdf_xml.LoadFile(file)) { if (!urdf_xml.LoadFile(file)) {

View File

@ -79,7 +79,7 @@ shared_ptr<DAE> ColladaWriter::convert() {
return collada_; return collada_;
} }
catch (ColladaWriterException ex) { catch (ColladaUrdfException ex) {
ROS_ERROR("Error converting: %s", ex.what()); ROS_ERROR("Error converting: %s", ex.what());
return shared_ptr<DAE>(); return shared_ptr<DAE>();
} }
@ -88,7 +88,7 @@ shared_ptr<DAE> ColladaWriter::convert() {
// Implementation // Implementation
void ColladaWriter::handleError(daeString msg) { void ColladaWriter::handleError(daeString msg) {
throw ColladaWriterException(msg); throw ColladaUrdfException(msg);
} }
void ColladaWriter::handleWarning(daeString msg) { void ColladaWriter::handleWarning(daeString msg) {
@ -100,7 +100,7 @@ void ColladaWriter::initDocument(string const& documentName) {
daeDocument* doc = NULL; daeDocument* doc = NULL;
daeInt error = collada_->getDatabase()->insertDocument(documentName.c_str(), &doc); // also creates a collada root daeInt error = collada_->getDatabase()->insertDocument(documentName.c_str(), &doc); // also creates a collada root
if (error != DAE_OK || doc == NULL) if (error != DAE_OK || doc == NULL)
throw ColladaWriterException("Failed to create document"); throw ColladaUrdfException("Failed to create document");
dom_ = daeSafeCast<domCOLLADA>(doc->getDomRoot()); dom_ = daeSafeCast<domCOLLADA>(doc->getDomRoot());
dom_->setAttribute("xmlns:math", "http://www.w3.org/1998/Math/MathML"); 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 { try {
loadMeshWithSTLLoader(resource, geometry, geometry_id); loadMeshWithSTLLoader(resource, geometry, geometry_id);
} }
catch (ColladaWriterException e) { catch (ColladaUrdfException e) {
std::cerr << "Unable to load mesh file " << filename << ": " << e.what() << std::endl; 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"; char tmp_filename[] = "/tmp/collada_urdf_XXXXXX";
int fd = mkstemp(tmp_filename); int fd = mkstemp(tmp_filename);
if (fd == -1) 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) { if ((uint32_t) write(fd, resource.data.get(), resource.size) != resource.size) {
close(fd); close(fd);
unlink(tmp_filename); unlink(tmp_filename);
throw ColladaWriterException("Couldn't write resource to file"); throw ColladaUrdfException("Couldn't write resource to file");
} }
close(fd); close(fd);
@ -282,7 +282,7 @@ bool ColladaWriter::loadMeshWithSTLLoader(resource_retriever::MemoryResource con
shared_ptr<Mesh> stl_mesh = loader.load(string(tmp_filename)); shared_ptr<Mesh> stl_mesh = loader.load(string(tmp_filename));
if (stl_mesh == shared_ptr<Mesh>()) { if (stl_mesh == shared_ptr<Mesh>()) {
unlink(tmp_filename); unlink(tmp_filename);
throw ColladaWriterException("Couldn't import mesh with STLLoader"); throw ColladaUrdfException("Couldn't import STL mesh");
} }
// Build the COLLADA mesh // Build the COLLADA mesh