Uniformed return type to the style of Open. Now every export function returns 0 in case of success.

This commit is contained in:
Paolo Cignoni 2006-01-13 15:47:43 +00:00
parent 1cb45963f9
commit 390a724ff7
5 changed files with 105 additions and 16 deletions

View File

@ -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<OpenMeshType>::Save(m,filename);
err = ExporterPLY<OpenMeshType>::Save(m,filename,mask);
LastType()=KT_PLY;
}
else if(FileExtension(filename,"stl"))

View File

@ -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<std::string> 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

View File

@ -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<FaceType> he;
vcg::face::Pos<FaceType> hei;
@ -167,6 +167,21 @@ namespace vcg {
return 0;
}
static const char *ErrorMsg(int error)
{
static std::vector<std::string> 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

View File

@ -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;i<textures.size();++i)
// fprintf(fpout,"comment %s %s\n", TFILE, (const char *)(textures[i]) );
for(i=0;i<m.textures.size();++i)
fprintf(fpout,"comment %s %s\n", TFILE, (const char *)(m.textures[i].c_str()) );
//if(textures.size()>1 && (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<int> FlagV;
return 0;
}
static const char *ErrorMsg(int error)
{
static std::vector<std::string> 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();
};

View File

@ -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 SaveMeshType>
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<std::string> 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