From 390a724ff795d451df18e193037b85c64ec2d7fb Mon Sep 17 00:00:00 2001 From: cignoni Date: Fri, 13 Jan 2006 15:47:43 +0000 Subject: [PATCH] Uniformed return type to the style of Open. Now every export function returns 0 in case of success. --- wrap/io_trimesh/export.h | 12 +++++++-- wrap/io_trimesh/export_dxf.h | 19 ++++++++++--- wrap/io_trimesh/export_off.h | 17 +++++++++++- wrap/io_trimesh/export_ply.h | 52 ++++++++++++++++++++++++++++++------ wrap/io_trimesh/export_stl.h | 21 +++++++++++++-- 5 files changed, 105 insertions(+), 16 deletions(-) diff --git a/wrap/io_trimesh/export.h b/wrap/io_trimesh/export.h index c283e2e8..544354ad 100644 --- a/wrap/io_trimesh/export.h +++ b/wrap/io_trimesh/export.h @@ -25,6 +25,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.1 2005/11/12 18:34:17 cignoni +Initial Commit + ****************************************************************************/ @@ -68,14 +71,19 @@ static bool FileExtension(std::string filename, std::string extension) std::string end=filename.substr(filename.length()-extension.length(),extension.length()); return end==extension; } - // Open Mesh static int Save(OpenMeshType &m, const char *filename, CallBackPos *cb=0) +{ + return Save(m,filename,0,cb); +} + +// Open Mesh +static int Save(OpenMeshType &m, const char *filename, const int mask, CallBackPos *cb=0) { int err; if(FileExtension(filename,"ply")) { - err = ExporterPLY::Save(m,filename); + err = ExporterPLY::Save(m,filename,mask); LastType()=KT_PLY; } else if(FileExtension(filename,"stl")) diff --git a/wrap/io_trimesh/export_dxf.h b/wrap/io_trimesh/export_dxf.h index c41f1dd9..0cb5f2c5 100644 --- a/wrap/io_trimesh/export_dxf.h +++ b/wrap/io_trimesh/export_dxf.h @@ -41,7 +41,7 @@ public: /* Prima versione da rivedere e ottimizzare, ma compatibile con Autocad. */ - static bool Save(SaveMeshType &m, const char * filename) + static int Save(SaveMeshType &m, const char * filename) { FILE * o = fopen(filename,"w"); if(o==NULL) return false; @@ -82,11 +82,24 @@ public: fprintf(o,"0\n"); fprintf(o,"EOF\n"); fclose(o); - return true; + return 0; } - + static const char *ErrorMsg(int error) + { + static std::vector dxf_error_msg; + if(dxf_error_msg.empty()) + { + dxf_error_msg.resize(2 ); + dxf_error_msg[0]="No errors"; + dxf_error_msg[1]="Can't open file"; + } + + if(error>1 || error<0) return "Unknown error"; + else return dxf_error_msg[error].c_str(); + } + }; // end class diff --git a/wrap/io_trimesh/export_off.h b/wrap/io_trimesh/export_off.h index 31a99218..2607d242 100644 --- a/wrap/io_trimesh/export_off.h +++ b/wrap/io_trimesh/export_off.h @@ -49,7 +49,7 @@ namespace vcg { typedef typename SaveMeshType::VertexIterator VertexIterator; typedef typename SaveMeshType::FaceIterator FaceIterator; - static bool Save(SaveMeshType &m, const char * filename ) + static int Save(SaveMeshType &m, const char * filename ) { vcg::face::Pos he; vcg::face::Pos hei; @@ -167,6 +167,21 @@ namespace vcg { return 0; } + + static const char *ErrorMsg(int error) + { + static std::vector off_error_msg; + if(off_error_msg.empty()) + { + off_error_msg.resize(2 ); + off_error_msg[0]="No errors"; + off_error_msg[1]="Can't open file"; + } + + if(error>1 || error<0) return "Unknown error"; + else return off_error_msg[error].c_str(); + } + }; // end class } // end namespace tri } // end namespace io diff --git a/wrap/io_trimesh/export_ply.h b/wrap/io_trimesh/export_ply.h index 528ff66c..5303b7a8 100644 --- a/wrap/io_trimesh/export_ply.h +++ b/wrap/io_trimesh/export_ply.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.12 2006/01/10 13:20:42 cignoni +Changed ply::PlyMask to io::Mask + Revision 1.11 2005/11/23 15:48:25 pietroni changed shot::similarity to shot::Similarity() and shot::camera to shot::Camera() @@ -114,20 +117,20 @@ typedef typename SaveMeshType::FacePointer FacePointer; typedef typename SaveMeshType::VertexIterator VertexIterator; typedef typename SaveMeshType::FaceIterator FaceIterator; -static bool Save(SaveMeshType &m, const char * filename, bool binary=true) +static int Save(SaveMeshType &m, const char * filename, bool binary=true) { PlyInfo pi; return Save(m,filename,binary,pi); } -static bool Save(SaveMeshType &m, const char * filename, int savemask ) +static int Save(SaveMeshType &m, const char * filename, int savemask ) { PlyInfo pi; pi.mask=savemask; return Save(m,filename,true,pi); } -static bool Save(SaveMeshType &m, const char * filename, bool binary, PlyInfo &pi ) // V1.0 +static int Save(SaveMeshType &m, const char * filename, bool binary, PlyInfo &pi ) // V1.0 { FILE * fpout; int i; @@ -155,12 +158,12 @@ static bool Save(SaveMeshType &m, const char * filename, bool binary, PlyInfo & if( pi.mask & Mask::IOM_WEDGTEXCOORD ) { - //const char * TFILE = "TextureFile"; + const char * TFILE = "TextureFile"; - //for(i=0;i1 && (HasPerWedgeTexture() || HasPerVertexTexture())) multit = true; + if(m.textures.size()>1 && (m.HasPerWedgeTexture() || m.HasPerVertexTexture())) multit = true; } if( (pi.mask & Mask::IOM_CAMERA) && m.shot.IsValid()) @@ -242,7 +245,8 @@ static bool Save(SaveMeshType &m, const char * filename, bool binary, PlyInfo & ); } - if( m.HasPerVertexTexture() || m.HasPerWedgeTexture() ) + if( ( m.HasPerVertexTexture() && pi.mask & Mask::IOM_VERTTEXCOORD ) || + ( m.HasPerWedgeTexture() && pi.mask & Mask::IOM_WEDGTEXCOORD ) ) { fprintf(fpout, "property list uchar float texcoord\n" @@ -603,6 +607,38 @@ std::vector FlagV; return 0; } +static const char *ErrorMsg(int error) +{ + static std::vector ply_error_msg; + if(ply_error_msg.empty()) + { + ply_error_msg.resize(PlyInfo::E_MAXPLYINFOERRORS ); + ply_error_msg[ply::E_NOERROR ]="No errors"; + ply_error_msg[ply::E_CANTOPEN ]="Can't open file"; + ply_error_msg[ply::E_NOTHEADER ]="Header not found"; + ply_error_msg[ply::E_UNESPECTEDEOF ]="Eof in header"; + ply_error_msg[ply::E_NOFORMAT ]="Format not found"; + ply_error_msg[ply::E_SYNTAX ]="Syntax error on header"; + ply_error_msg[ply::E_PROPOUTOFELEMENT]="Property without element"; + ply_error_msg[ply::E_BADTYPENAME ]="Bad type name"; + ply_error_msg[ply::E_ELEMNOTFOUND ]="Element not found"; + ply_error_msg[ply::E_PROPNOTFOUND ]="Property not found"; + ply_error_msg[ply::E_BADTYPE ]="Bad type on addtoread"; + ply_error_msg[ply::E_INCOMPATIBLETYPE]="Incompatible type"; + ply_error_msg[ply::E_BADCAST ]="Bad cast"; + + ply_error_msg[PlyInfo::E_NO_VERTEX ]="No vertex field found"; + ply_error_msg[PlyInfo::E_NO_FACE ]="No face field found"; + ply_error_msg[PlyInfo::E_SHORTFILE ]="Unespected eof"; + ply_error_msg[PlyInfo::E_NO_3VERTINFACE ]="Face with more than 3 vertices"; + ply_error_msg[PlyInfo::E_BAD_VERT_INDEX ]="Bad vertex index in face"; + ply_error_msg[PlyInfo::E_NO_6TCOORD ]="Face with no 6 texture coordinates"; + ply_error_msg[PlyInfo::E_DIFFER_COLORS ]="Number of color differ from vertices"; + } + + if(error>PlyInfo::E_MAXPLYINFOERRORS || error<0) return "Unknown error"; + else return ply_error_msg[error].c_str(); +}; diff --git a/wrap/io_trimesh/export_stl.h b/wrap/io_trimesh/export_stl.h index dc0d6503..acb92ecc 100644 --- a/wrap/io_trimesh/export_stl.h +++ b/wrap/io_trimesh/export_stl.h @@ -25,6 +25,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.5 2005/12/01 00:58:56 cignoni +Added and removed typenames for gcc compiling... + Revision 1.4 2004/10/28 00:52:45 cignoni Better Doxygen documentation @@ -60,14 +63,14 @@ template class ExporterSTL { public: -static bool Save(SaveMeshType &m, const char * filename , bool binary =true, const char *objectname=0) +static int Save(SaveMeshType &m, const char * filename , bool binary =true, const char *objectname=0) { typedef typename SaveMeshType::FaceIterator FaceIterator; FILE *fp; fp = fopen(filename,"wb"); if(fp==0) - return false; + return 1; if(binary) { @@ -119,6 +122,20 @@ static bool Save(SaveMeshType &m, const char * filename , bool binary =true, con fclose(fp); return true; } +static const char *ErrorMsg(int error) +{ + static std::vector stl_error_msg; + if(stl_error_msg.empty()) + { + stl_error_msg.resize(2 ); + stl_error_msg[0]="No errors"; + stl_error_msg[1]="Can't open file"; + } + + if(error>1 || error<0) return "Unknown error"; + else return stl_error_msg[error].c_str(); +}; + }; // end class } // end Namespace tri