added check for save errors
This commit is contained in:
parent
21d49e900e
commit
eaff614cb9
|
@ -86,22 +86,26 @@ public:
|
||||||
fprintf(o,"ENDSEC\n");
|
fprintf(o,"ENDSEC\n");
|
||||||
fprintf(o,"0\n");
|
fprintf(o,"0\n");
|
||||||
fprintf(o,"EOF\n");
|
fprintf(o,"EOF\n");
|
||||||
fclose(o);
|
|
||||||
return 0;
|
int result = 0;
|
||||||
|
if (ferror(o)) result = 2;
|
||||||
|
fclose(o);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
/// Standard call for knowing the meaning of an error code
|
/// Standard call for knowing the meaning of an error code
|
||||||
static const char *ErrorMsg(int error)
|
static const char *ErrorMsg(int error)
|
||||||
{
|
{
|
||||||
static std::vector<std::string> dxf_error_msg;
|
static std::vector<std::string> dxf_error_msg;
|
||||||
if(dxf_error_msg.empty())
|
if (dxf_error_msg.empty())
|
||||||
{
|
{
|
||||||
dxf_error_msg.resize(2 );
|
dxf_error_msg.resize(3);
|
||||||
dxf_error_msg[0]="No errors";
|
dxf_error_msg[0] = "No errors";
|
||||||
dxf_error_msg[1]="Can't open file";
|
dxf_error_msg[1] = "Can't open file";
|
||||||
}
|
dxf_error_msg[2] = "Output Stream Error";
|
||||||
|
}
|
||||||
|
|
||||||
if(error>1 || error<0) return "Unknown error";
|
if (error>2 || error<0) return "Unknown error";
|
||||||
else return dxf_error_msg[error].c_str();
|
else return dxf_error_msg[error].c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -173,22 +173,27 @@ namespace vcg {
|
||||||
for(j=0,vi=m.vert.begin();vi!=m.vert.end();++vi)
|
for(j=0,vi=m.vert.begin();vi!=m.vert.end();++vi)
|
||||||
(*vi).Flags()=FlagV[j++];
|
(*vi).Flags()=FlagV[j++];
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
int result = 0;
|
||||||
|
if (stream.status() != QTextStream::Ok) result = 3;
|
||||||
|
stream.flush();
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *ErrorMsg(int error)
|
static const char *ErrorMsg(int error)
|
||||||
{
|
{
|
||||||
static std::vector<std::string> off_error_msg;
|
static std::vector<std::string> off_error_msg;
|
||||||
if(off_error_msg.empty())
|
if (off_error_msg.empty())
|
||||||
{
|
{
|
||||||
off_error_msg.resize(2 );
|
off_error_msg.resize(4);
|
||||||
off_error_msg[0]="No errors";
|
off_error_msg[0] = "No errors";
|
||||||
off_error_msg[1]="Can't open file";
|
off_error_msg[1] = "Can't open file";
|
||||||
off_error_msg[2]="Internal error";
|
off_error_msg[2] = "Internal error";
|
||||||
}
|
off_error_msg[3] = "Otput Stream Error";
|
||||||
|
}
|
||||||
|
|
||||||
if(error>2 || error<0) return "Unknown error";
|
if (error>3 || error<0) return "Unknown error";
|
||||||
else return off_error_msg[error].c_str();
|
else return off_error_msg[error].c_str();
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
returns mask of capability one define with what are the saveable information of the format.
|
returns mask of capability one define with what are the saveable information of the format.
|
||||||
|
|
|
@ -54,15 +54,16 @@ public:
|
||||||
*/
|
*/
|
||||||
enum SaveError
|
enum SaveError
|
||||||
{
|
{
|
||||||
E_NOERROR, // 0
|
E_NOERROR, // 0
|
||||||
E_CANTOPENFILE, // 1
|
E_CANTOPENFILE, // 1
|
||||||
E_CANTCLOSEFILE, // 2
|
E_CANTCLOSEFILE, // 2
|
||||||
E_UNESPECTEDEOF, // 3
|
E_UNESPECTEDEOF, // 3
|
||||||
E_ABORTED, // 4
|
E_ABORTED, // 4
|
||||||
E_NOTDEFINITION, // 5
|
E_NOTDEFINITION, // 5
|
||||||
E_NO_VERTICES, // 6
|
E_NO_VERTICES, // 6
|
||||||
E_NOTFACESVALID, // 7
|
E_NOTFACESVALID, // 7
|
||||||
E_NO_VALID_MATERIAL
|
E_NO_VALID_MATERIAL, // 8
|
||||||
|
E_STREAMERROR // 9
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -72,18 +73,19 @@ public:
|
||||||
{
|
{
|
||||||
static const char* obj_error_msg[] =
|
static const char* obj_error_msg[] =
|
||||||
{
|
{
|
||||||
"No errors", // 0
|
"No errors", // 0
|
||||||
"Can't open file", // 1
|
"Can't open file", // 1
|
||||||
"can't close file", // 2
|
"can't close file", // 2
|
||||||
"Premature End of file", // 3
|
"Premature End of file", // 3
|
||||||
"File saving aborted", // 4
|
"File saving aborted", // 4
|
||||||
"Function not defined", // 5
|
"Function not defined", // 5
|
||||||
"Vertices not valid", // 6
|
"Vertices not valid", // 6
|
||||||
"Faces not valid", // 7
|
"Faces not valid", // 7
|
||||||
"The mesh has not a attribute containing the vector of materials" // 8
|
"The mesh has not a attribute containing the vector of materials", // 8
|
||||||
|
"Output Stream Error" //9
|
||||||
};
|
};
|
||||||
|
|
||||||
if(error>7 || error<0) return "Unknown error";
|
if(error>9 || error<0) return "Unknown error";
|
||||||
else return obj_error_msg[error];
|
else return obj_error_msg[error];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -277,7 +279,6 @@ public:
|
||||||
fprintf(fp,"# %d faces, %d coords texture\n\n",m.fn,int(CoordIndexTexture.size()));
|
fprintf(fp,"# %d faces, %d coords texture\n\n",m.fn,int(CoordIndexTexture.size()));
|
||||||
|
|
||||||
fprintf(fp,"# End of File\n");
|
fprintf(fp,"# End of File\n");
|
||||||
fclose(fp);
|
|
||||||
|
|
||||||
int errCode = E_NOERROR;
|
int errCode = E_NOERROR;
|
||||||
if((mask & Mask::IOM_WEDGTEXCOORD) || (mask & Mask::IOM_FACECOLOR) || (mask & Mask::IOM_VERTTEXCOORD) )
|
if((mask & Mask::IOM_WEDGTEXCOORD) || (mask & Mask::IOM_FACECOLOR) || (mask & Mask::IOM_VERTTEXCOORD) )
|
||||||
|
@ -286,9 +287,13 @@ public:
|
||||||
else errCode = WriteMaterials(materialVec, filename,cb);
|
else errCode = WriteMaterials(materialVec, filename,cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(errCode!= E_NOERROR)
|
int result = E_NOERROR;
|
||||||
return errCode;
|
if (errCode != E_NOERROR)
|
||||||
return E_NOERROR;
|
result = errCode;
|
||||||
|
else if (ferror(fp))
|
||||||
|
result = E_STREAMERROR;
|
||||||
|
fclose(fp);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -139,28 +139,30 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fclose(fpout);
|
|
||||||
// Recupera i flag originali
|
// Recupera i flag originali
|
||||||
j=0;
|
j=0;
|
||||||
for(vi=m.vert.begin();vi!=m.vert.end();++vi)
|
for(vi=m.vert.begin();vi!=m.vert.end();++vi)
|
||||||
(*vi).Flags()=FlagV[j++];
|
(*vi).Flags()=FlagV[j++];
|
||||||
|
|
||||||
return 0;
|
int result = 0;
|
||||||
|
if (ferror(fpout)) result = 2;
|
||||||
|
fclose(fpout);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *ErrorMsg(int error)
|
static const char *ErrorMsg(int error)
|
||||||
{
|
{
|
||||||
static std::vector<std::string> off_error_msg;
|
static std::vector<std::string> off_error_msg;
|
||||||
if(off_error_msg.empty())
|
if (off_error_msg.empty())
|
||||||
{
|
{
|
||||||
off_error_msg.resize(2 );
|
off_error_msg.resize(3);
|
||||||
off_error_msg[0]="No errors";
|
off_error_msg[0] = "No errors";
|
||||||
off_error_msg[1]="Can't open file";
|
off_error_msg[1] = "Can't open file";
|
||||||
}
|
off_error_msg[1] = "Output Stream error";
|
||||||
|
}
|
||||||
|
|
||||||
if(error>1 || error<0) return "Unknown error";
|
if (error>2 || error<0) return "Unknown error";
|
||||||
else return off_error_msg[error].c_str();
|
else return off_error_msg[error].c_str();
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
returns mask of capability one define with what are the saveable information of the format.
|
returns mask of capability one define with what are the saveable information of the format.
|
||||||
|
|
|
@ -756,8 +756,10 @@ namespace vcg {
|
||||||
}
|
}
|
||||||
assert(ecnt==m.en);
|
assert(ecnt==m.en);
|
||||||
}
|
}
|
||||||
|
int result = 0;
|
||||||
|
if (ferror(fpout)) result = ply::E_STREAMERROR;
|
||||||
fclose(fpout);
|
fclose(fpout);
|
||||||
return 0;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *ErrorMsg(int error)
|
static const char *ErrorMsg(int error)
|
||||||
|
@ -766,19 +768,21 @@ namespace vcg {
|
||||||
if(ply_error_msg.empty())
|
if(ply_error_msg.empty())
|
||||||
{
|
{
|
||||||
ply_error_msg.resize(PlyInfo::E_MAXPLYINFOERRORS );
|
ply_error_msg.resize(PlyInfo::E_MAXPLYINFOERRORS );
|
||||||
ply_error_msg[ply::E_NOERROR ]="No errors";
|
ply_error_msg[ply::E_NOERROR ]="No errors";
|
||||||
ply_error_msg[ply::E_CANTOPEN ]="Can't open file";
|
ply_error_msg[ply::E_CANTOPEN ]="Can't open file";
|
||||||
ply_error_msg[ply::E_NOTHEADER ]="Header not found";
|
ply_error_msg[ply::E_NOTHEADER ]="Header not found";
|
||||||
ply_error_msg[ply::E_UNESPECTEDEOF ]="Eof in header";
|
ply_error_msg[ply::E_UNESPECTEDEOF ]="Eof in header";
|
||||||
ply_error_msg[ply::E_NOFORMAT ]="Format not found";
|
ply_error_msg[ply::E_NOFORMAT ]="Format not found";
|
||||||
ply_error_msg[ply::E_SYNTAX ]="Syntax error on header";
|
ply_error_msg[ply::E_SYNTAX ]="Syntax error on header";
|
||||||
ply_error_msg[ply::E_PROPOUTOFELEMENT]="Property without element";
|
ply_error_msg[ply::E_PROPOUTOFELEMENT ]="Property without element";
|
||||||
ply_error_msg[ply::E_BADTYPENAME ]="Bad type name";
|
ply_error_msg[ply::E_BADTYPENAME ]="Bad type name";
|
||||||
ply_error_msg[ply::E_ELEMNOTFOUND ]="Element not found";
|
ply_error_msg[ply::E_ELEMNOTFOUND ]="Element not found";
|
||||||
ply_error_msg[ply::E_PROPNOTFOUND ]="Property 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_BADTYPE ]="Bad type on addtoread";
|
||||||
ply_error_msg[ply::E_INCOMPATIBLETYPE]="Incompatible type";
|
ply_error_msg[ply::E_INCOMPATIBLETYPE ]="Incompatible type";
|
||||||
ply_error_msg[ply::E_BADCAST ]="Bad cast";
|
ply_error_msg[ply::E_BADCAST ]="Bad cast";
|
||||||
|
|
||||||
|
ply_error_msg[ply::E_STREAMERROR ] = "Output Stream Error";
|
||||||
|
|
||||||
ply_error_msg[PlyInfo::E_NO_VERTEX ]="No vertex field found";
|
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_NO_FACE ]="No face field found";
|
||||||
|
|
|
@ -150,21 +150,24 @@ static int Save(SaveMeshType &m, const char * filename , bool binary =true, int
|
||||||
}
|
}
|
||||||
fprintf(fp,"endsolid vcg\n");
|
fprintf(fp,"endsolid vcg\n");
|
||||||
}
|
}
|
||||||
|
int result = 0;
|
||||||
|
if (ferror(fp)) result = 2;
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return 0;
|
return result;
|
||||||
}
|
}
|
||||||
static const char *ErrorMsg(int error)
|
static const char *ErrorMsg(int error)
|
||||||
{
|
{
|
||||||
static std::vector<std::string> stl_error_msg;
|
static std::vector<std::string> stl_error_msg;
|
||||||
if(stl_error_msg.empty())
|
if (stl_error_msg.empty())
|
||||||
{
|
{
|
||||||
stl_error_msg.resize(2 );
|
stl_error_msg.resize(3);
|
||||||
stl_error_msg[0]="No errors";
|
stl_error_msg[0] = "No errors";
|
||||||
stl_error_msg[1]="Can't open file";
|
stl_error_msg[1] = "Can't open file";
|
||||||
}
|
stl_error_msg[2] = "Output Stream error";
|
||||||
|
}
|
||||||
|
|
||||||
if(error>1 || error<0) return "Unknown error";
|
if (error>2 || error<0) return "Unknown error";
|
||||||
else return stl_error_msg[error].c_str();
|
else return stl_error_msg[error].c_str();
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -281,8 +281,10 @@ namespace vcg {
|
||||||
" ]\n"
|
" ]\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
);
|
);
|
||||||
|
int result = 0;
|
||||||
|
if (ferror(fp)) result = 2;
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return 0;
|
return result;
|
||||||
}
|
}
|
||||||
///Returns mask of capability one define with what are the saveable information of the format.
|
///Returns mask of capability one define with what are the saveable information of the format.
|
||||||
static int GetExportMaskCapability()
|
static int GetExportMaskCapability()
|
||||||
|
@ -305,11 +307,12 @@ namespace vcg {
|
||||||
static std::vector<std::string> wrl_error_msg;
|
static std::vector<std::string> wrl_error_msg;
|
||||||
if(wrl_error_msg.empty())
|
if(wrl_error_msg.empty())
|
||||||
{
|
{
|
||||||
wrl_error_msg.resize(2 );
|
wrl_error_msg.resize(3);
|
||||||
wrl_error_msg[0]="No errors";
|
wrl_error_msg[0] = "No errors";
|
||||||
wrl_error_msg[1]="Can't open file";
|
wrl_error_msg[1] = "Can't open file";
|
||||||
|
wrl_error_msg[1] = "Output Stream error";
|
||||||
}
|
}
|
||||||
if(error>1 || error<0) return "Unknown error";
|
if(error>2 || error<0) return "Unknown error";
|
||||||
else return wrl_error_msg[error].c_str();
|
else return wrl_error_msg[error].c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -152,15 +152,15 @@ public:
|
||||||
enum Error
|
enum Error
|
||||||
{
|
{
|
||||||
// Funzioni superiori
|
// Funzioni superiori
|
||||||
E_NO_VERTEX = ply::E_MAXPLYERRORS+1, // 14
|
E_NO_VERTEX = ply::E_MAXPLYERRORS+1, // 15
|
||||||
E_NO_FACE = ply::E_MAXPLYERRORS+2, // 15
|
E_NO_FACE = ply::E_MAXPLYERRORS+2, // 16
|
||||||
E_SHORTFILE = ply::E_MAXPLYERRORS+3, // 16
|
E_SHORTFILE = ply::E_MAXPLYERRORS+3, // 17
|
||||||
E_NO_3VERTINFACE = ply::E_MAXPLYERRORS+4, // 17
|
E_NO_3VERTINFACE = ply::E_MAXPLYERRORS+4, // 18
|
||||||
E_BAD_VERT_INDEX = ply::E_MAXPLYERRORS+5, // 18
|
E_BAD_VERT_INDEX = ply::E_MAXPLYERRORS+5, // 19
|
||||||
E_NO_6TCOORD = ply::E_MAXPLYERRORS+6, // 19
|
E_NO_6TCOORD = ply::E_MAXPLYERRORS+6, // 20
|
||||||
E_DIFFER_COLORS = ply::E_MAXPLYERRORS+7,
|
E_DIFFER_COLORS = ply::E_MAXPLYERRORS+7, // 21
|
||||||
E_BAD_VERT_INDEX_EDGE = ply::E_MAXPLYERRORS+8, // 18
|
E_BAD_VERT_INDEX_EDGE = ply::E_MAXPLYERRORS+8, // 22
|
||||||
E_MAXPLYINFOERRORS= ply::E_MAXPLYERRORS+9// 20
|
E_MAXPLYINFOERRORS= ply::E_MAXPLYERRORS+9 // 23
|
||||||
};
|
};
|
||||||
|
|
||||||
}; // end class
|
}; // end class
|
||||||
|
|
|
@ -91,6 +91,8 @@ enum PlyError {
|
||||||
E_BADTYPE, // 10
|
E_BADTYPE, // 10
|
||||||
E_INCOMPATIBLETYPE, // 11
|
E_INCOMPATIBLETYPE, // 11
|
||||||
E_BADCAST, // 12
|
E_BADCAST, // 12
|
||||||
|
//saving error
|
||||||
|
E_STREAMERROR, // 13
|
||||||
E_MAXPLYERRORS
|
E_MAXPLYERRORS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue