diff --git a/src/common/plugins/interfaces/iomesh_plugin.h b/src/common/plugins/interfaces/iomesh_plugin.h index a950f6883..c5c9ba9c3 100644 --- a/src/common/plugins/interfaces/iomesh_plugin.h +++ b/src/common/plugins/interfaces/iomesh_plugin.h @@ -126,7 +126,7 @@ public: int& defaultBits) const = 0; /// callback used to actually load a mesh from a file - virtual bool open( + virtual void open( const QString &format, /// the extension of the format e.g. "PLY" const QString &fileName, /// The name of the file to be opened MeshModel &m, /// The mesh that is filled with the file content @@ -144,6 +144,16 @@ public: vcg::CallBackPos *cb = 0, QWidget *parent = 0) = 0; + void wrongOpenFormat(const QString& format) + { + throw MLException("Internal error: unknown open format " + format + " to " + pluginName() + " plugin."); + }; + + void wrongSaveFormat(const QString& format) + { + throw MLException("Internal error: unknown save format " + format + " to " + pluginName() + " plugin."); + }; + /// This function is invoked by the framework when the import/export plugin fails to give some info to the user about the failure /// io plugins should avoid using QMessageBox for reporting errors. /// Failure should put some meaningful information inside the errorMessage string. diff --git a/src/meshlab/mainwindow_RunTime.cpp b/src/meshlab/mainwindow_RunTime.cpp index e36068dac..f320223c3 100644 --- a/src/meshlab/mainwindow_RunTime.cpp +++ b/src/meshlab/mainwindow_RunTime.cpp @@ -2216,9 +2216,14 @@ bool MainWindow::loadMesh(const QString& fileName, IOMeshPlugin *pCurrentIOPlugi meshDoc()->setBusy(true); pCurrentIOPlugin->setLog(&meshDoc()->Log); - if (!pCurrentIOPlugin->open(extension, fileNameSansDir, *mm ,mask,*prePar,QCallBack,this /*gla*/)) - { - QMessageBox::warning(this, tr("Opening Failure"), QString("While opening: '%1'\n\n").arg(fileName)+pCurrentIOPlugin->errorMsg()); // text+ + try { + pCurrentIOPlugin->open(extension, fileNameSansDir, *mm ,mask,*prePar,QCallBack,this /*gla*/); + } + catch(const MLException& e) { + QMessageBox::warning( + this, + tr("Opening Failure"), + "While opening: " + fileName + "\n\n" + e.what()); pCurrentIOPlugin->clearErrorString(); meshDoc()->setBusy(false); QDir::setCurrent(origDir); // undo the change of directory before leaving diff --git a/src/meshlabplugins/filter_ssynth/filter_ssynth.cpp b/src/meshlabplugins/filter_ssynth/filter_ssynth.cpp index 7b0dd9a30..1f3625445 100644 --- a/src/meshlabplugins/filter_ssynth/filter_ssynth.cpp +++ b/src/meshlabplugins/filter_ssynth/filter_ssynth.cpp @@ -177,35 +177,44 @@ std::list FilterSSynth::exportFormats() const return formats ; } -bool FilterSSynth::open(const QString &/*formatName*/, const QString &fileName, MeshModel &m, int& mask, const RichParameterList & par, CallBackPos *cb, QWidget *parent) +void FilterSSynth::open( + const QString& formatName, + const QString& fileName, + MeshModel &m, + int& mask, + const RichParameterList & par, + CallBackPos *cb, + QWidget *parent) { - this->seed=par.getInt("seed"); - int maxrec=par.getInt("maxrec"); - int sphereres=par.getInt("sphereres"); - int maxobj=par.getInt("maxobj"); - this->renderTemplate=GetTemplate(sphereres); - if(this->renderTemplate!= ""){ - QFile grammar(fileName); - grammar.open(QFile::ReadOnly|QFile::Text); - QString gcontent(grammar.readAll()); - grammar.close(); - if(maxrec>0)ParseGram(&gcontent,maxrec,tr("set maxdepth")); - if(maxobj>0)ParseGram(&gcontent,maxobj,tr("set maxobjects")); - QString x3dfile(FilterSSynth::ssynth(gcontent,maxrec,this->seed,cb)); - if(QFile::exists(x3dfile)){ - openX3D(x3dfile,m,mask,cb); - QFile x3df(x3dfile); - x3df.remove(); - return true; - } - else{ - errorMessage = "Error: " + QString("An error occurred during the mesh generation: ").append(x3dfile); - return false; - } - } - else{ - errorMessage = "Error: Sphere resolution must be between 1 and 4"; - return false; + if (formatName.toUpper() == tr("ES")){ + this->seed=par.getInt("seed"); + int maxrec=par.getInt("maxrec"); + int sphereres=par.getInt("sphereres"); + int maxobj=par.getInt("maxobj"); + this->renderTemplate=GetTemplate(sphereres); + if(this->renderTemplate!= ""){ + QFile grammar(fileName); + grammar.open(QFile::ReadOnly|QFile::Text); + QString gcontent(grammar.readAll()); + grammar.close(); + if(maxrec>0)ParseGram(&gcontent,maxrec,tr("set maxdepth")); + if(maxobj>0)ParseGram(&gcontent,maxobj,tr("set maxobjects")); + QString x3dfile(FilterSSynth::ssynth(gcontent,maxrec,this->seed,cb)); + if(!QFile::exists(x3dfile)){ + throw MLException("An error occurred during the mesh generation: " + x3dfile); + } + else{ + openX3D(x3dfile,m,mask,cb); + QFile x3df(x3dfile); + x3df.remove(); + } + } + else{ + throw MLException("Error: Sphere resolution must be between 1 and 4"); + } + } + else { + wrongOpenFormat(formatName); } } diff --git a/src/meshlabplugins/filter_ssynth/filter_ssynth.h b/src/meshlabplugins/filter_ssynth/filter_ssynth.h index b31cda936..1df949128 100644 --- a/src/meshlabplugins/filter_ssynth/filter_ssynth.h +++ b/src/meshlabplugins/filter_ssynth/filter_ssynth.h @@ -60,7 +60,7 @@ class FilterSSynth : public QObject, public IOMeshPlugin, public FilterPlugin{ virtual void exportMaskCapability(const QString &format, int &capability, int &defaultBits) const; void initPreOpenParameter(const QString &formatName, RichParameterList &parlst); - bool open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, const RichParameterList & par, vcg::CallBackPos *cb=0, QWidget *parent=0); + void open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, const RichParameterList & par, vcg::CallBackPos *cb=0, QWidget *parent=0); bool save(const QString &formatName, const QString &fileName, MeshModel &m, const int mask, const RichParameterList &, vcg::CallBackPos *cb, QWidget *parent); FilterPlugin::FilterArity filterArity(const QAction *) const {return NONE;} private: diff --git a/src/meshlabplugins/io_3ds/meshio.cpp b/src/meshlabplugins/io_3ds/meshio.cpp index 8f7e7d225..23e720de1 100644 --- a/src/meshlabplugins/io_3ds/meshio.cpp +++ b/src/meshlabplugins/io_3ds/meshio.cpp @@ -84,10 +84,11 @@ void ExtraMeshIOPlugin::initPreOpenParameter( } } -bool ExtraMeshIOPlugin::open( +void ExtraMeshIOPlugin::open( const QString &formatName, const QString &fileName, - MeshModel &m, int& mask, + MeshModel &m, + int& mask, const RichParameterList& params, CallBackPos *cb, QWidget*) @@ -104,19 +105,16 @@ bool ExtraMeshIOPlugin::open( string filename = QFile::encodeName(fileName).constData (); //string filename = fileName.toUtf8().data(); - if (formatName.toUpper() == tr("3DS")) - { + if (formatName.toUpper() == tr("3DS")) { vcg::tri::io::_3dsInfo info; info.cb = cb; Lib3dsFile *file = NULL; file = lib3ds_file_load(filename.c_str()); - if (!file) - { + if (!file) { int result = vcg::tri::io::Importer3DS::E_CANTOPEN; - errorMessage = errorMsgFormat.arg(fileName, vcg::tri::io::Importer3DS::ErrorMsg(result)); - return false; + throw MLException(errorMsgFormat.arg(fileName, vcg::tri::io::Importer3DS::ErrorMsg(result))); } // No nodes? Fabricate nodes to display all the meshes. @@ -134,8 +132,9 @@ bool ExtraMeshIOPlugin::open( } } - if( !file->nodes) - return false; + if( !file->nodes) { + throw MLException("Malformed file."); + } lib3ds_file_eval(file, 0); @@ -202,9 +201,8 @@ bool ExtraMeshIOPlugin::open( int result = vcg::tri::io::Importer3DS::Load(m.cm, file, 0, info); if (result != vcg::tri::io::Importer3DS::E_NOERROR) { - errorMessage = "3DS Opening Error: " + errorMsgFormat.arg(fileName, vcg::tri::io::Importer3DS::ErrorMsg(result)); lib3ds_file_free(file); - return false; + throw MLException("3DS Opening Error: " + errorMsgFormat.arg(fileName, vcg::tri::io::Importer3DS::ErrorMsg(result))); } if(info.mask & vcg::tri::io::Mask::IOM_WEDGNORMAL) @@ -240,10 +238,10 @@ bool ExtraMeshIOPlugin::open( // freeing memory lib3ds_file_free(file); - - return true; } - return false; + else { + wrongOpenFormat(formatName); + } } bool ExtraMeshIOPlugin::save( diff --git a/src/meshlabplugins/io_3ds/meshio.h b/src/meshlabplugins/io_3ds/meshio.h index ba068da2b..22ce87c7e 100644 --- a/src/meshlabplugins/io_3ds/meshio.h +++ b/src/meshlabplugins/io_3ds/meshio.h @@ -48,7 +48,7 @@ public: const QString& format, RichParameterList& parameters); - bool open(const QString &formatName, + void open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, diff --git a/src/meshlabplugins/io_base/baseio.cpp b/src/meshlabplugins/io_base/baseio.cpp index 9b33de9cd..84d34c47a 100644 --- a/src/meshlabplugins/io_base/baseio.cpp +++ b/src/meshlabplugins/io_base/baseio.cpp @@ -85,21 +85,20 @@ void BaseMeshIOPlugin::initPreOpenParameter(const QString &formatName, RichParam } } -bool BaseMeshIOPlugin::open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, const RichParameterList &parlst, CallBackPos *cb, QWidget * /*parent*/) +void BaseMeshIOPlugin::open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, const RichParameterList &parlst, CallBackPos *cb, QWidget * /*parent*/) { - //bool normalsUpdated = false; - QString errorMsgFormat = "Error encountered while loading file:\n\"%1\"\n\nError details: %2"; + //bool normalsUpdated = false; + QString errorMsgFormat = "Error encountered while loading file:\n\"%1\"\n\nError details: %2"; - if(!QFile::exists(fileName)) - { - errorMessage = errorMsgFormat.arg(fileName, "File does not exist"); - return false; - } + if(!QFile::exists(fileName)) { + throw MLException(errorMsgFormat.arg(fileName, "File does not exist")); + } // initializing mask mask = 0; // initializing progress bar status - if (cb != NULL) (*cb)(0, "Loading..."); + if (cb != NULL) + (*cb)(0, "Loading..."); //string filename = fileName.toUtf8().data(); @@ -118,8 +117,7 @@ bool BaseMeshIOPlugin::open(const QString &formatName, const QString &fileName, { if (tri::io::ImporterPLY::ErrorCritical(result)) { - errorMessage = errorMsgFormat.arg(fileName, tri::io::ImporterPLY::ErrorMsg(result)); - return false; + throw MLException(errorMsgFormat.arg(fileName, tri::io::ImporterPLY::ErrorMsg(result))); } } } @@ -127,15 +125,13 @@ bool BaseMeshIOPlugin::open(const QString &formatName, const QString &fileName, { if (!tri::io::ImporterSTL::LoadMask(filename.c_str(), mask)) { - errorMessage = errorMsgFormat.arg(fileName, tri::io::ImporterSTL::ErrorMsg(tri::io::ImporterSTL::E_MALFORMED)); - return false; + throw MLException(errorMsgFormat.arg(fileName, tri::io::ImporterSTL::ErrorMsg(tri::io::ImporterSTL::E_MALFORMED))); } m.Enable(mask); int result = tri::io::ImporterSTL::Open(m.cm, filename.c_str(), mask, cb); if (result != 0) // all the importers return 0 on success { - errorMessage = errorMsgFormat.arg(fileName, tri::io::ImporterSTL::ErrorMsg(result)); - return false; + throw MLException(errorMsgFormat.arg(fileName, tri::io::ImporterSTL::ErrorMsg(result))); } bool stluinf = parlst.getBool(stlUnifyParName()); @@ -150,19 +146,19 @@ bool BaseMeshIOPlugin::open(const QString &formatName, const QString &fileName, { tri::io::ImporterOBJ::Info oi; oi.cb = cb; - if (!tri::io::ImporterOBJ::LoadMask(filename.c_str(), oi)) - return false; + if (!tri::io::ImporterOBJ::LoadMask(filename.c_str(), oi)){ + throw MLException("Error while loading OBJ mask."); + } m.Enable(oi.mask); int result = tri::io::ImporterOBJ::Open(m.cm, filename.c_str(), oi); if (result != tri::io::ImporterOBJ::E_NOERROR) { - if (result & tri::io::ImporterOBJ::E_NON_CRITICAL_ERROR) + if (result & tri::io::ImporterOBJ::E_NON_CRITICAL_ERROR) { errorMessage = errorMsgFormat.arg(fileName, tri::io::ImporterOBJ::ErrorMsg(result)); - else - { - errorMessage = errorMsgFormat.arg(fileName, tri::io::ImporterOBJ::ErrorMsg(result)); - return false; + } + else { + throw MLException(errorMsgFormat.arg(fileName, tri::io::ImporterOBJ::ErrorMsg(result))); } } @@ -198,8 +194,7 @@ bool BaseMeshIOPlugin::open(const QString &formatName, const QString &fileName, int result = tri::io::ImporterPTX::Open(m.cm, filename.c_str(), importparams, cb); if (result == 1) { - errorMessage = errorMsgFormat.arg(fileName, tri::io::ImporterPTX::ErrorMsg(result)); - return false; + throw MLException(errorMsgFormat.arg(fileName, tri::io::ImporterPTX::ErrorMsg(result))); } // update mask @@ -210,37 +205,36 @@ bool BaseMeshIOPlugin::open(const QString &formatName, const QString &fileName, int loadMask; if (!tri::io::ImporterOFF::LoadMask(filename.c_str(), loadMask)) { - errorMessage = errorMsgFormat.arg(fileName, tri::io::ImporterOFF::ErrorMsg(tri::io::ImporterOFF::InvalidFile)); - return false; + throw MLException(errorMsgFormat.arg(fileName, tri::io::ImporterOFF::ErrorMsg(tri::io::ImporterOFF::InvalidFile))); } m.Enable(loadMask); int result = tri::io::ImporterOFF::Open(m.cm, filename.c_str(), mask, cb); if (result != 0) // OFFCodes enum is protected { - errorMessage = errorMsgFormat.arg(fileName, tri::io::ImporterOFF::ErrorMsg(result)); - return false; + throw MLException(errorMsgFormat.arg(fileName, tri::io::ImporterOFF::ErrorMsg(result))); } } else if (formatName.toUpper() == tr("VMI")) { int loadMask; - if (!tri::io::ImporterVMI::LoadMask(filename.c_str(), loadMask)) - return false; + if (!tri::io::ImporterVMI::LoadMask(filename.c_str(), loadMask)) { + throw MLException("Error while loading VMI mask."); + } m.Enable(loadMask); int result = tri::io::ImporterVMI::Open(m.cm, filename.c_str(), mask, cb); if (result != 0) { - errorMessage = errorMsgFormat.arg(fileName, tri::io::ImporterOFF::ErrorMsg(result)); - return false; + throw MLException(errorMsgFormat.arg(fileName, tri::io::ImporterOFF::ErrorMsg(result))); } } else if (formatName.toUpper() == tr("GTS")) { int loadMask; - if (!tri::io::ImporterGTS::LoadMask(filename.c_str(), loadMask)) - return false; + if (!tri::io::ImporterGTS::LoadMask(filename.c_str(), loadMask)){ + throw MLException("Error while loading GTS mask."); + } m.Enable(loadMask); tri::io::ImporterGTS::Options opt; @@ -249,34 +243,31 @@ bool BaseMeshIOPlugin::open(const QString &formatName, const QString &fileName, int result = tri::io::ImporterGTS::Open(m.cm, filename.c_str(), mask, opt, cb); if (result != 0) { - errorMessage = errorMsgFormat.arg(fileName, vcg::tri::io::ImporterGTS::ErrorMsg(result)); - return false; + throw MLException(errorMsgFormat.arg(fileName, vcg::tri::io::ImporterGTS::ErrorMsg(result))); } } - else if (formatName.toUpper() == tr("FBX")) - { - m.Enable(tri::io::Mask::IOM_WEDGTEXCOORD); - - int result = tri::io::ImporterFBX::Open(m.cm, filename.c_str(),cb); - if(m.cm.textures.empty()) - m.clearDataMask(tri::io::Mask::IOM_WEDGTEXCOORD); - - if (result != 0) - { - errorMessage = errorMsgFormat.arg(fileName, vcg::tri::io::ImporterFBX::ErrorMsg(result)); - return false; - } - }else - { - assert(0); // Unknown File type - return false; + else if (formatName.toUpper() == tr("FBX")) + { + m.Enable(tri::io::Mask::IOM_WEDGTEXCOORD); + + int result = tri::io::ImporterFBX::Open(m.cm, filename.c_str(),cb); + if(m.cm.textures.empty()) + m.clearDataMask(tri::io::Mask::IOM_WEDGTEXCOORD); + + if (result != 0) + { + throw MLException(errorMsgFormat.arg(fileName, vcg::tri::io::ImporterFBX::ErrorMsg(result))); + } + } + else { + wrongOpenFormat(formatName); } - // Add a small pass to convert backslash into forward slash - for(auto i = m.cm.textures.begin();i!=m.cm.textures.end();++i) - { - std::replace(i->begin(), i->end(), '\\', '/'); - } + // Add a small pass to convert backslash into forward slash + for(auto i = m.cm.textures.begin();i!=m.cm.textures.end();++i) + { + std::replace(i->begin(), i->end(), '\\', '/'); + } // verify if texture files are present QString missingTextureFilesMsg = "The following texture files were not found:\n"; bool someTextureNotFound = false; @@ -293,8 +284,6 @@ bool BaseMeshIOPlugin::open(const QString &formatName, const QString &fileName, log("Missing texture files: %s", qUtf8Printable(missingTextureFilesMsg)); if (cb != NULL) (*cb)(99, "Done"); - - return true; } bool BaseMeshIOPlugin::save(const QString &formatName, const QString &fileName, MeshModel &m, const int mask, const RichParameterList & par, CallBackPos *cb, QWidget * /*parent*/) diff --git a/src/meshlabplugins/io_base/baseio.h b/src/meshlabplugins/io_base/baseio.h index aae7da9f5..dac3b1a40 100644 --- a/src/meshlabplugins/io_base/baseio.h +++ b/src/meshlabplugins/io_base/baseio.h @@ -43,7 +43,7 @@ public: void exportMaskCapability(const QString& format, int &capability, int &defaultBits) const; - bool open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, const RichParameterList & par, vcg::CallBackPos *cb = 0, QWidget *parent = 0); + void open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, const RichParameterList & par, vcg::CallBackPos *cb = 0, QWidget *parent = 0); bool save(const QString &formatName, const QString &fileName, MeshModel &m, const int mask, const RichParameterList & par, vcg::CallBackPos *cb = 0, QWidget *parent = 0); //void initOpenParameter(const QString &format, MeshModel &/*m*/, RichParameterSet & par); //void applyOpenParameter(const QString &format, MeshModel &m, const RichParameterSet &par); diff --git a/src/meshlabplugins/io_bre/io_bre.cpp b/src/meshlabplugins/io_bre/io_bre.cpp index 9f9d46940..47baf57aa 100644 --- a/src/meshlabplugins/io_bre/io_bre.cpp +++ b/src/meshlabplugins/io_bre/io_bre.cpp @@ -131,20 +131,19 @@ void BreMeshIOPlugin::initPreOpenParameter(const QString &formatName, RichParame } -bool BreMeshIOPlugin::open(const QString &/*formatName*/, const QString &fileName, MeshModel &m, int& mask, const RichParameterList &parlst, CallBackPos *cb, QWidget * /*parent*/) +void BreMeshIOPlugin::open(const QString &/*formatName*/, const QString &fileName, MeshModel &m, int& mask, const RichParameterList &parlst, CallBackPos *cb, QWidget * /*parent*/) { - // initializing progress bar status - if (cb != NULL) (*cb)(0, "Loading..."); - mask = 0; - QString errorMsgFormat = "Error encountered while loading file:\n\"%1\"\n\nError details: %2"; - bool points = parlst.getBool("pointsonly"); - int result = vcg::tri::io::ImporterBRE::Open(m, m.cm, mask, fileName,points, cb); - if (result != 0) // all the importers return 0 on success + // initializing progress bar status + if (cb != NULL) + (*cb)(0, "Loading..."); + mask = 0; + QString errorMsgFormat = "Error encountered while loading file:\n\"%1\"\n\nError details: %2"; + bool points = parlst.getBool("pointsonly"); + int result = vcg::tri::io::ImporterBRE::Open(m, m.cm, mask, fileName,points, cb); + if (result != 0) // all the importers return 0 on success { - errorMessage = errorMsgFormat.arg(fileName, ErrorMsg(result)); - return false; + throw MLException(errorMsgFormat.arg(fileName, ErrorMsg(result))); } - return true; } bool BreMeshIOPlugin::save(const QString & /*formatName*/,const QString & /*fileName*/, MeshModel &, const int /*mask*/, const RichParameterList & /*par*/, CallBackPos *, QWidget * /*parent*/) diff --git a/src/meshlabplugins/io_bre/io_bre.h b/src/meshlabplugins/io_bre/io_bre.h index 7a037c14b..2de164501 100644 --- a/src/meshlabplugins/io_bre/io_bre.h +++ b/src/meshlabplugins/io_bre/io_bre.h @@ -166,7 +166,7 @@ public: void exportMaskCapability(const QString &format, int &capability, int &defaultBits) const; - bool open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask,const RichParameterList & par, vcg::CallBackPos *cb=0, QWidget *parent=0); + void open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask,const RichParameterList & par, vcg::CallBackPos *cb=0, QWidget *parent=0); bool save(const QString &formatName, const QString &fileName, MeshModel &m, const int mask, const RichParameterList & par, vcg::CallBackPos *cb=0, QWidget *parent= 0); virtual void initOpenParameter(const QString &format, MeshModel &/*m*/, RichParameterList & par); virtual void applyOpenParameter(const QString &format, MeshModel &m, const RichParameterList &par); diff --git a/src/meshlabplugins/io_collada/io_collada.cpp b/src/meshlabplugins/io_collada/io_collada.cpp index 32b9b965a..f9f2eb340 100644 --- a/src/meshlabplugins/io_collada/io_collada.cpp +++ b/src/meshlabplugins/io_collada/io_collada.cpp @@ -101,52 +101,53 @@ using namespace std; using namespace vcg; -bool ColladaIOPlugin::open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, const RichParameterList &, CallBackPos *cb, QWidget * /*parent*/) +void ColladaIOPlugin::open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, const RichParameterList &, CallBackPos *cb, QWidget * /*parent*/) { // initializing mask - mask = 0; + mask = 0; // initializing progress bar status if (cb != NULL) (*cb)(0, "Loading..."); QString errorMsgFormat = "Error encountered while loading file:\n\"%1\"\n\nError details: %2"; string filename = QFile::encodeName(fileName).constData (); - //std::string filename = fileName.toUtf8().data(); + //std::string filename = fileName.toUtf8().data(); bool normalsUpdated = false; if(formatName.toUpper() == tr("DAE")) { //m.addinfo = NULL; - tri::io::InfoDAE info; - if (!tri::io::ImporterDAE::LoadMask(filename.c_str(), info)) - return false; + tri::io::InfoDAE info; + if (!tri::io::ImporterDAE::LoadMask(filename.c_str(), info)){ + throw MLException("Error while loading DAE mask."); + } - m.Enable(info.mask); - // for(unsigned int tx = 0; tx < info->texturefile.size();++tx) - // m.cm.textures.push_back(info->texturefile[tx].toStdString()); + m.Enable(info.mask); + // for(unsigned int tx = 0; tx < info->texturefile.size();++tx) + // m.cm.textures.push_back(info->texturefile[tx].toStdString()); int result = vcg::tri::io::ImporterDAE::Open(m.cm, filename.c_str(),info); if (result != vcg::tri::io::ImporterDAE::E_NOERROR) { - errorMessage = "DAE Opening Error" + QString(vcg::tri::io::ImporterDAE::ErrorMsg(result)); - return false; + throw MLException("DAE Opening Error" + QString(vcg::tri::io::ImporterDAE::ErrorMsg(result))); } else _mp.push_back(&m); - if(info.mask & vcg::tri::io::Mask::IOM_WEDGNORMAL) + if(info.mask & vcg::tri::io::Mask::IOM_WEDGNORMAL) normalsUpdated = true; - mask = info.mask; + mask = info.mask; + + vcg::tri::UpdateBounding::Box(m.cm); // updates bounding box + if (!normalsUpdated) + vcg::tri::UpdateNormal::PerVertex(m.cm); // updates normals + + if (cb != NULL) (*cb)(99, "Done"); + } + else { + wrongOpenFormat(formatName); } - - vcg::tri::UpdateBounding::Box(m.cm); // updates bounding box - if (!normalsUpdated) - vcg::tri::UpdateNormal::PerVertex(m.cm); // updates normals - - if (cb != NULL) (*cb)(99, "Done"); - - return true; } bool ColladaIOPlugin::save(const QString &formatName, const QString &fileName, MeshModel &m, const int mask, const RichParameterList &, vcg::CallBackPos * /*cb*/, QWidget * /*parent*/) diff --git a/src/meshlabplugins/io_collada/io_collada.h b/src/meshlabplugins/io_collada/io_collada.h index b3f9cecc1..2c3a92137 100644 --- a/src/meshlabplugins/io_collada/io_collada.h +++ b/src/meshlabplugins/io_collada/io_collada.h @@ -62,7 +62,7 @@ class ColladaIOPlugin : public QObject, public IOMeshPlugin std::list exportFormats() const; void exportMaskCapability(const QString &format, int &capability, int &defaultBits) const; - bool open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, const RichParameterList &par, vcg::CallBackPos *cb=0, QWidget *parent=0); + void open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, const RichParameterList &par, vcg::CallBackPos *cb=0, QWidget *parent=0); bool save(const QString &formatName, const QString &fileName, MeshModel &m, const int mask, const RichParameterList &, vcg::CallBackPos *cb=0, QWidget *parent= 0); }; diff --git a/src/meshlabplugins/io_ctm/io_ctm.cpp b/src/meshlabplugins/io_ctm/io_ctm.cpp index 549826a64..e9610836e 100644 --- a/src/meshlabplugins/io_ctm/io_ctm.cpp +++ b/src/meshlabplugins/io_ctm/io_ctm.cpp @@ -36,16 +36,14 @@ using namespace vcg; -bool IOMPlugin::open(const QString & /*formatName*/, const QString &fileName, MeshModel &m, int& mask,const RichParameterList & /*par*/, CallBackPos *cb, QWidget * /*parent*/) +void IOMPlugin::open(const QString & /*formatName*/, const QString &fileName, MeshModel &m, int& mask,const RichParameterList & /*par*/, CallBackPos *cb, QWidget * /*parent*/) { - QString errorMsgFormat = "Error encountered while loading file:\n\"%1\"\n\nError details: %2"; - int result = tri::io::ImporterCTM::Open(m.cm, qUtf8Printable(fileName), mask, cb); - if (result != 0) // all the importers return 0 on success - { - errorMessage = errorMsgFormat.arg(fileName, tri::io::ImporterCTM::ErrorMsg(result)); - return false; - } - return true; + QString errorMsgFormat = "Error encountered while loading file:\n\"%1\"\n\nError details: %2"; + int result = tri::io::ImporterCTM::Open(m.cm, qUtf8Printable(fileName), mask, cb); + if (result != 0) // all the importers return 0 on success + { + throw MLException(errorMsgFormat.arg(fileName, tri::io::ImporterCTM::ErrorMsg(result))); + } } bool IOMPlugin::save(const QString & /*formatName*/, const QString &fileName, MeshModel &m, const int mask,const RichParameterList & par, vcg::CallBackPos * /*cb*/, QWidget *parent) diff --git a/src/meshlabplugins/io_ctm/io_ctm.h b/src/meshlabplugins/io_ctm/io_ctm.h index 11a541218..d57d3e8d2 100644 --- a/src/meshlabplugins/io_ctm/io_ctm.h +++ b/src/meshlabplugins/io_ctm/io_ctm.h @@ -49,7 +49,7 @@ public: virtual void exportMaskCapability(const QString &format, int &capability, int &defaultBits) const; void initSaveParameter(const QString &/*format*/, MeshModel &/*m*/, RichParameterList & /*par*/); - bool open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask,const RichParameterList & par, vcg::CallBackPos *cb=0, QWidget *parent=0); + void open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask,const RichParameterList & par, vcg::CallBackPos *cb=0, QWidget *parent=0); bool save(const QString &formatName, const QString &fileName, MeshModel &m, const int mask,const RichParameterList & par, vcg::CallBackPos *cb, QWidget *parent); }; diff --git a/src/meshlabplugins/io_expe/io_expe.cpp b/src/meshlabplugins/io_expe/io_expe.cpp index e72484cf7..de5e673dc 100644 --- a/src/meshlabplugins/io_expe/io_expe.cpp +++ b/src/meshlabplugins/io_expe/io_expe.cpp @@ -38,7 +38,7 @@ using namespace vcg; -bool ExpeIOPlugin::open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, const RichParameterList & /*parlst*/, CallBackPos *cb, QWidget*/*parent*/) +void ExpeIOPlugin::open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, const RichParameterList & /*parlst*/, CallBackPos *cb, QWidget*/*parent*/) { // initializing mask mask = 0; @@ -57,26 +57,25 @@ bool ExpeIOPlugin::open(const QString &formatName, const QString &fileName, Mesh if (!vcg::tri::io::ImporterExpePTS::LoadMask(filename.c_str(),loadMask)) { useXYZ=true; - if (!vcg::tri::io::ImporterXYZ::LoadMask(filename.c_str(),loadMask)) - return false; - } + if (!vcg::tri::io::ImporterXYZ::LoadMask(filename.c_str(),loadMask)){ + throw MLException("Error while loading [A]PTS mask."); + } + } m.Enable(loadMask); int result; if(useXYZ) { - result = vcg::tri::io::ImporterXYZ::Open(m.cm, filename.c_str(), mask, cb); + result = vcg::tri::io::ImporterXYZ::Open(m.cm, filename.c_str(), mask, cb); if (result != 0) { - errorMessage = errorMsgFormat.arg(fileName, vcg::tri::io::ImporterXYZ::ErrorMsg(result)); - return false; + throw MLException(errorMsgFormat.arg(fileName, vcg::tri::io::ImporterXYZ::ErrorMsg(result))); } } else { - result = vcg::tri::io::ImporterExpePTS::Open(m.cm, filename.c_str(), mask, cb); + result = vcg::tri::io::ImporterExpePTS::Open(m.cm, filename.c_str(), mask, cb); if (result != 0) { - errorMessage = errorMsgFormat.arg(fileName, vcg::tri::io::ImporterExpePTS::ErrorMsg(result)); - return false; + throw MLException(errorMsgFormat.arg(fileName, vcg::tri::io::ImporterExpePTS::ErrorMsg(result))); } } @@ -84,16 +83,16 @@ bool ExpeIOPlugin::open(const QString &formatName, const QString &fileName, Mesh else if (formatName.toLower() == tr("xyz")) { int loadMask; - if (!vcg::tri::io::ImporterXYZ::LoadMask(filename.c_str(),loadMask)) - return false; + if (!vcg::tri::io::ImporterXYZ::LoadMask(filename.c_str(),loadMask)) { + throw MLException("Error while loading XYZ mask."); + } m.Enable(loadMask); int result = vcg::tri::io::ImporterXYZ::Open(m.cm, filename.c_str(), mask, cb); if (result != 0) { - errorMessage = errorMsgFormat.arg(fileName, vcg::tri::io::ImporterXYZ::ErrorMsg(result)); - return false; + throw MLException(errorMsgFormat.arg(fileName, vcg::tri::io::ImporterXYZ::ErrorMsg(result))); } } @@ -101,8 +100,6 @@ bool ExpeIOPlugin::open(const QString &formatName, const QString &fileName, Mesh if (cb != NULL) (*cb)(99, "Done"); - - return true; } bool ExpeIOPlugin::save(const QString &formatName, const QString &fileName, MeshModel &m, const int mask, const RichParameterList &, vcg::CallBackPos * /*cb*/, QWidget *parent) diff --git a/src/meshlabplugins/io_expe/io_expe.h b/src/meshlabplugins/io_expe/io_expe.h index 4d8bd6904..f193f41ee 100644 --- a/src/meshlabplugins/io_expe/io_expe.h +++ b/src/meshlabplugins/io_expe/io_expe.h @@ -44,7 +44,7 @@ public: virtual void exportMaskCapability(const QString &format, int &capability, int &defaultBits) const; // void initPreOpenParameter(const QString &/*format*/, const QString &/*fileName*/, RichParameterSet & /*par*/); - bool open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, const RichParameterList &, vcg::CallBackPos *cb=0, QWidget *parent=0); + void open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, const RichParameterList &, vcg::CallBackPos *cb=0, QWidget *parent=0); bool save(const QString &formatName, const QString &fileName, MeshModel &m, const int mask, const RichParameterList &, vcg::CallBackPos *cb, QWidget *parent); }; diff --git a/src/meshlabplugins/io_json/io_json.cpp b/src/meshlabplugins/io_json/io_json.cpp index 25cc069d9..d34857159 100644 --- a/src/meshlabplugins/io_json/io_json.cpp +++ b/src/meshlabplugins/io_json/io_json.cpp @@ -45,16 +45,9 @@ QString JSONIOPlugin::pluginName() const return "IOJson"; } -bool JSONIOPlugin::open(const QString & formatName, const QString & fileName, MeshModel & m, int & mask, const RichParameterList & parlst, vcg::CallBackPos * cb, QWidget * /*parent*/) +void JSONIOPlugin::open(const QString & formatName, const QString &, MeshModel &, int &, const RichParameterList &, vcg::CallBackPos *, QWidget * /*parent*/) { - (void)formatName; - (void)fileName; - (void)m; - (void)mask; - (void)parlst; - (void)cb; - - return false; + wrongOpenFormat(formatName); } bool JSONIOPlugin::save(const QString & formatName,const QString & fileName, MeshModel & m, const int mask, const RichParameterList & par, vcg::CallBackPos * cb, QWidget * parent) diff --git a/src/meshlabplugins/io_json/io_json.h b/src/meshlabplugins/io_json/io_json.h index 409a7f8e6..12085dfc9 100644 --- a/src/meshlabplugins/io_json/io_json.h +++ b/src/meshlabplugins/io_json/io_json.h @@ -44,7 +44,7 @@ public: void exportMaskCapability(const QString & format, int & capability, int & defaultBits) const; - bool open(const QString & formatName, const QString & fileName, MeshModel & m, int & mask, const RichParameterList & par, vcg::CallBackPos * cb = 0, QWidget * parent = 0); + void open(const QString & formatName, const QString & fileName, MeshModel & m, int & mask, const RichParameterList & par, vcg::CallBackPos * cb = 0, QWidget * parent = 0); bool save(const QString & formatName, const QString & fileName, MeshModel & m, const int mask, const RichParameterList & par, vcg::CallBackPos * cb = 0, QWidget * parent = 0); }; diff --git a/src/meshlabplugins/io_pdb/io_pdb.cpp b/src/meshlabplugins/io_pdb/io_pdb.cpp index 693085c14..823e06550 100644 --- a/src/meshlabplugins/io_pdb/io_pdb.cpp +++ b/src/meshlabplugins/io_pdb/io_pdb.cpp @@ -64,7 +64,7 @@ void PDBIOPlugin::initPreOpenParameter(const QString &formatName, RichParameterL } } -bool PDBIOPlugin::open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, const RichParameterList &parlst, CallBackPos *cb, QWidget * /*parent*/) +void PDBIOPlugin::open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, const RichParameterList &parlst, CallBackPos *cb, QWidget * /*parent*/) { //bool normalsUpdated = false; @@ -72,63 +72,25 @@ bool PDBIOPlugin::open(const QString &formatName, const QString &fileName, MeshM mask = 0; // initializing progress bar status - if (cb != NULL) (*cb)(0, "Loading..."); + if (cb != NULL) + (*cb)(0, "Loading..."); - QString errorMsgFormat = "Error encountered while loading file:\n\"%1\"\n\nError details: %2"; - - //string filename = fileName.toUtf8().data(); string filename = QFile::encodeName(fileName).constData (); - - if (formatName.toUpper() == tr("PDB")) + + if (formatName.toUpper() == tr("PDB")) { mask |= vcg::tri::io::Mask::IOM_VERTCOLOR; m.Enable(mask); - return parsePDB(qUtf8Printable(fileName), m.cm, parlst, cb); - - - /* - tri::io::ImporterPTX::Info importparams; - - importparams.meshnum = parlst.getInt("meshindex"); - importparams.anglecull =parlst.getBool("anglecull"); - importparams.angle = parlst.getFloat("angle"); - importparams.savecolor = parlst.getBool("usecolor"); - importparams.pointcull = parlst.getBool("pointcull"); - importparams.pointsonly = parlst.getBool("pointsonly"); - importparams.switchside = parlst.getBool("switchside"); - importparams.flipfaces = parlst.getBool("flipfaces"); - - // if color, add to mesh - if(importparams.savecolor) - importparams.mask |= tri::io::Mask::IOM_VERTCOLOR; - - // reflectance is stored in quality - importparams.mask |= tri::io::Mask::IOM_VERTQUALITY; - - m.Enable(importparams.mask); - - int result = tri::io::ImporterPTX::Open(m.cm, filename.c_str(), importparams, cb); - if (result == 1) - { - errorMessage = errorMsgFormat.arg(fileName, tri::io::ImporterPTX::ErrorMsg(result)); - return false; - } - - // update mask - mask = importparams.mask; - */ + if (!parsePDB(qUtf8Printable(fileName), m.cm, parlst, cb)) + throw MLException("Error while opening PDB file"); + if (cb != NULL) + (*cb)(99, "Done"); } - else - { - assert(0); // Unknown File type - return false; + else { + wrongOpenFormat(formatName); } - - if (cb != NULL) (*cb)(99, "Done"); - - return true; } bool PDBIOPlugin::save(const QString & /*formatName*/,const QString & /*fileName*/, MeshModel & /*m*/, const int /*mask*/, const RichParameterList & /*par*/, CallBackPos * /*cb*/, QWidget * /*parent*/) diff --git a/src/meshlabplugins/io_pdb/io_pdb.h b/src/meshlabplugins/io_pdb/io_pdb.h index ed99df4f9..712b97398 100644 --- a/src/meshlabplugins/io_pdb/io_pdb.h +++ b/src/meshlabplugins/io_pdb/io_pdb.h @@ -42,9 +42,9 @@ public: void exportMaskCapability(const QString &format, int &capability, int &defaultBits) const; - bool open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask,const RichParameterList & par, vcg::CallBackPos *cb=0, QWidget *parent=0); + void open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask,const RichParameterList & par, vcg::CallBackPos *cb=0, QWidget *parent=0); bool save(const QString &formatName, const QString &fileName, MeshModel &m, const int mask, const RichParameterList & par, vcg::CallBackPos *cb=0, QWidget *parent= 0); - virtual void initOpenParameter(const QString &format, MeshModel &/*m*/, RichParameterList & par); + virtual void initOpenParameter(const QString &format, MeshModel &/*m*/, RichParameterList & par); virtual void applyOpenParameter(const QString &format, MeshModel &m, const RichParameterList &par); void initPreOpenParameter(const QString &formatName, RichParameterList &parlst); diff --git a/src/meshlabplugins/io_tri/io_tri.cpp b/src/meshlabplugins/io_tri/io_tri.cpp index 16dc9afcb..e395abea5 100755 --- a/src/meshlabplugins/io_tri/io_tri.cpp +++ b/src/meshlabplugins/io_tri/io_tri.cpp @@ -44,30 +44,30 @@ void TriIOPlugin::initPreOpenParameter(const QString &format, RichParameterList } } -bool TriIOPlugin::open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, const RichParameterList &parlst, CallBackPos *cb, QWidget *) +void TriIOPlugin::open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, const RichParameterList &parlst, CallBackPos *cb, QWidget *) { if(formatName.toUpper() == tr("TRI")) + { + mask |= vcg::tri::io::Mask::IOM_WEDGTEXCOORD; + m.Enable(mask); + if (!parseTRI(qUtf8Printable(fileName), m.cm)) + throw MLException("Error while opening TRI file"); + } + else if(formatName.toUpper() == tr("ASC")) + { + mask |= vcg::tri::io::Mask::IOM_VERTQUALITY; + m.Enable(mask); + bool triangulate = parlst.getBool("triangulate"); + int rowToSkip = parlst.getInt("rowToSkip"); + int result = tri::io::ImporterASC::Open(m.cm, qUtf8Printable(fileName),cb,triangulate,rowToSkip); + if (result != 0) // all the importers return 0 on success { - mask |= vcg::tri::io::Mask::IOM_WEDGTEXCOORD; - m.Enable(mask); - return parseTRI(qUtf8Printable(fileName), m.cm); + throw MLException("Error while opening ASC file"); } - if(formatName.toUpper() == tr("ASC")) - { - mask |= vcg::tri::io::Mask::IOM_VERTQUALITY; - m.Enable(mask); - bool triangulate = parlst.getBool("triangulate"); - int rowToSkip = parlst.getInt("rowToSkip"); - int result = tri::io::ImporterASC::Open(m.cm, qUtf8Printable(fileName),cb,triangulate,rowToSkip); - if (result != 0) // all the importers return 0 on success - { - errorMessage = QString("Failed to open:")+fileName; - return false; - } - - return true; - } - return false; + } + else { + wrongOpenFormat(formatName); + } } bool TriIOPlugin::save(const QString &, const QString &, MeshModel &, const int, const RichParameterList &, vcg::CallBackPos *, QWidget *) diff --git a/src/meshlabplugins/io_tri/io_tri.h b/src/meshlabplugins/io_tri/io_tri.h index d90e501e7..d14b993c2 100755 --- a/src/meshlabplugins/io_tri/io_tri.h +++ b/src/meshlabplugins/io_tri/io_tri.h @@ -48,7 +48,7 @@ public: virtual void exportMaskCapability(const QString &format, int &capability, int &defaultBits) const; virtual void initPreOpenParameter(const QString &/*format*/, RichParameterList & /*par*/); - bool open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, const RichParameterList &, vcg::CallBackPos *cb=0, QWidget *parent=0); + void open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, const RichParameterList &, vcg::CallBackPos *cb=0, QWidget *parent=0); bool save(const QString &formatName, const QString &fileName, MeshModel &m, const int mask, const RichParameterList &, vcg::CallBackPos *cb, QWidget *parent); }; diff --git a/src/meshlabplugins/io_txt/io_txt.cpp b/src/meshlabplugins/io_txt/io_txt.cpp index 87daf1105..f5116772e 100755 --- a/src/meshlabplugins/io_txt/io_txt.cpp +++ b/src/meshlabplugins/io_txt/io_txt.cpp @@ -59,31 +59,30 @@ void TxtIOPlugin::initPreOpenParameter(const QString &format, RichParameterList } } -bool TxtIOPlugin::open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, const RichParameterList &parlst, CallBackPos * /*cb*/, QWidget * /*parent*/) +void TxtIOPlugin::open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, const RichParameterList &parlst, CallBackPos * /*cb*/, QWidget * /*parent*/) { - bool result=false; + if(formatName.toUpper() == tr("TXT")) { + int rowToSkip = parlst.getInt("rowToSkip"); + int dataSeparator = parlst.getEnum("separator"); + int dataFormat = parlst.getEnum("strformat"); + int rgbMode = parlst.getEnum("rgbmode"); + int onError = parlst.getEnum("onerror"); - if(formatName.toUpper() == tr("TXT")) - { - int rowToSkip = parlst.getInt("rowToSkip"); - int dataSeparator = parlst.getEnum("separator"); - int dataFormat = parlst.getEnum("strformat"); - int rgbMode = parlst.getEnum("rgbmode"); - int onError = parlst.getEnum("onerror"); + if(!(dataFormat==0) && !(dataFormat==6) && !(dataFormat==10)) + mask |= vcg::tri::io::Mask::IOM_VERTQUALITY; + if(!(dataFormat==0) && !(dataFormat==10)) + mask |= vcg::tri::io::Mask::IOM_VERTCOLOR; + if((dataFormat==3) || (dataFormat==4) || (dataFormat==5) || (dataFormat>=8)) + mask |= vcg::tri::io::Mask::IOM_VERTNORMAL; - if(!(dataFormat==0) && !(dataFormat==6) && !(dataFormat==10)) - mask |= vcg::tri::io::Mask::IOM_VERTQUALITY; - if(!(dataFormat==0) && !(dataFormat==10)) - mask |= vcg::tri::io::Mask::IOM_VERTCOLOR; - if((dataFormat==3) || (dataFormat==4) || (dataFormat==5) || (dataFormat>=8)) - mask |= vcg::tri::io::Mask::IOM_VERTNORMAL; + m.Enable(mask); - m.Enable(mask); - - return parseTXT(fileName, m.cm, rowToSkip, dataSeparator, dataFormat, rgbMode, onError); - } - - return result; + if (!parseTXT(fileName, m.cm, rowToSkip, dataSeparator, dataFormat, rgbMode, onError)) + throw MLException("Error while opening TXT file."); + } + else { + wrongOpenFormat(formatName); + } } bool TxtIOPlugin::save(const QString & /*formatName*/, const QString & /*fileName*/, MeshModel & /*m*/, const int /*mask*/, const RichParameterList &, vcg::CallBackPos * /*cb*/, QWidget * /*parent*/) diff --git a/src/meshlabplugins/io_txt/io_txt.h b/src/meshlabplugins/io_txt/io_txt.h index 68c864e7f..336129191 100755 --- a/src/meshlabplugins/io_txt/io_txt.h +++ b/src/meshlabplugins/io_txt/io_txt.h @@ -42,7 +42,7 @@ public: virtual void exportMaskCapability(const QString &format, int &capability, int &defaultBits) const; virtual void initPreOpenParameter(const QString &/*format*/, RichParameterList & /*par*/); - bool open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, const RichParameterList &, vcg::CallBackPos *cb=0, QWidget *parent=0); + void open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, const RichParameterList &, vcg::CallBackPos *cb=0, QWidget *parent=0); bool save(const QString &formatName, const QString &fileName, MeshModel &m, const int mask, const RichParameterList &, vcg::CallBackPos *cb, QWidget *parent); }; diff --git a/src/meshlabplugins/io_u3d/io_u3d.cpp b/src/meshlabplugins/io_u3d/io_u3d.cpp index 503d23cac..88c50d091 100644 --- a/src/meshlabplugins/io_u3d/io_u3d.cpp +++ b/src/meshlabplugins/io_u3d/io_u3d.cpp @@ -44,8 +44,8 @@ U3DIOPlugin::U3DIOPlugin() : { } -bool U3DIOPlugin::open( - const QString &, +void U3DIOPlugin::open( + const QString& format, const QString &, MeshModel &, int&, @@ -53,7 +53,7 @@ bool U3DIOPlugin::open( CallBackPos *, QWidget *) { - return false; + wrongOpenFormat(format); } bool U3DIOPlugin::save( const QString &formatName, diff --git a/src/meshlabplugins/io_u3d/io_u3d.h b/src/meshlabplugins/io_u3d/io_u3d.h index 5a82f7212..ede92779a 100644 --- a/src/meshlabplugins/io_u3d/io_u3d.h +++ b/src/meshlabplugins/io_u3d/io_u3d.h @@ -48,7 +48,7 @@ public: virtual void exportMaskCapability(const QString &format, int &capability, int &defaultBits) const; - bool open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, const RichParameterList &, vcg::CallBackPos *cb=0, QWidget *parent=0); + void open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, const RichParameterList &, vcg::CallBackPos *cb=0, QWidget *parent=0); bool save(const QString &formatName, const QString &fileName, MeshModel &m, const int mask, const RichParameterList &, vcg::CallBackPos *cb=0, QWidget *parent= 0); void initSaveParameter(const QString &format, MeshModel &/*m*/, RichParameterList &par); diff --git a/src/meshlabplugins/io_x3d/io_x3d.cpp b/src/meshlabplugins/io_x3d/io_x3d.cpp index c326ffbfd..e5903ee0b 100644 --- a/src/meshlabplugins/io_x3d/io_x3d.cpp +++ b/src/meshlabplugins/io_x3d/io_x3d.cpp @@ -31,7 +31,7 @@ using namespace std; using namespace vcg; -bool IoX3DPlugin::open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, const RichParameterList &, CallBackPos *cb, QWidget */*parent*/) +void IoX3DPlugin::open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, const RichParameterList &, CallBackPos *cb, QWidget */*parent*/) { // initializing mask mask = 0; @@ -52,9 +52,7 @@ bool IoX3DPlugin::open(const QString &formatName, const QString &fileName, MeshM result = vcg::tri::io::ImporterX3D::LoadMaskVrml(filename.c_str(), info); if ( result != vcg::tri::io::ImporterX3D::E_NOERROR) { - errorMessage = errorMsgFormat.arg(fileName, info->filenameStack[info->filenameStack.size()-1], vcg::tri::io::ImporterX3D::ErrorMsg(result)); - delete info; - return false; + throw MLException(errorMsgFormat.arg(fileName, info->filenameStack[info->filenameStack.size()-1], vcg::tri::io::ImporterX3D::ErrorMsg(result))); } if (info->mask & vcg::tri::io::Mask::IOM_VERTTEXCOORD) { @@ -74,16 +72,14 @@ bool IoX3DPlugin::open(const QString &formatName, const QString &fileName, MeshM QString fileError = info->filenameStack[info->filenameStack.size()-1]; QString lineError; lineError.setNum(info->lineNumberError); - errorMessage = errorMsgFormat.arg(fileName, fileError, lineError, vcg::tri::io::ImporterX3D::ErrorMsg(result)); delete info; - return false; + throw MLException(errorMsgFormat.arg(fileName, fileError, lineError, vcg::tri::io::ImporterX3D::ErrorMsg(result))); } if (m.cm.vert.size() == 0) { errorMsgFormat = "Error encountered while loading file:\n\"%1\"\n\nError details: File without a geometry"; - errorMessage = errorMsgFormat.arg(fileName); delete info; - return false; + throw MLException(errorMsgFormat.arg(fileName)); } if(info->mask & vcg::tri::io::Mask::IOM_WEDGNORMAL) normalsUpdated = true; @@ -116,11 +112,11 @@ bool IoX3DPlugin::open(const QString &formatName, const QString &fileName, MeshM vcg::tri::UpdateNormal::PerVertexPerFace(m.cm); // updates normals delete info; + if (cb != NULL) (*cb)(99, "Done"); + } + else { + wrongOpenFormat(formatName); } - // verify if texture files are present - - if (cb != NULL) (*cb)(99, "Done"); - return true; } diff --git a/src/meshlabplugins/io_x3d/io_x3d.h b/src/meshlabplugins/io_x3d/io_x3d.h index d1fc00b0d..d5dad58bd 100644 --- a/src/meshlabplugins/io_x3d/io_x3d.h +++ b/src/meshlabplugins/io_x3d/io_x3d.h @@ -51,7 +51,7 @@ public: virtual void exportMaskCapability(const QString &format, int &capability, int &defaultBits) const; - bool open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, const RichParameterList &, vcg::CallBackPos *cb=0, QWidget *parent=0); + void open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, const RichParameterList &, vcg::CallBackPos *cb=0, QWidget *parent=0); bool save(const QString &formatName, const QString &fileName, MeshModel &m, const int mask, const RichParameterList &, vcg::CallBackPos *cb, QWidget *parent); }; diff --git a/src/meshlabserver/mainserver.cpp b/src/meshlabserver/mainserver.cpp index a5d587dc6..971294d0d 100644 --- a/src/meshlabserver/mainserver.cpp +++ b/src/meshlabserver/mainserver.cpp @@ -188,13 +188,14 @@ public: pCurrentIOPlugin->initPreOpenParameter(extension,prePar); prePar.join(meshlab::defaultGlobalParameterList()); - if (!pCurrentIOPlugin->open(extension, fileName, mm ,mask,prePar)) - { + try { + pCurrentIOPlugin->open(extension, fileName, mm ,mask,prePar); + } + catch(const MLException& e){ fprintf(fp,"MeshLabServer: Failed loading of %s from dir %s\n", qUtf8Printable(fileName), qUtf8Printable(QDir::currentPath())); QDir::setCurrent(curDir.absolutePath()); return false; } - // In case of polygonal meshes the normal should be updated accordingly if( mask & vcg::tri::io::Mask::IOM_BITPOLYGONAL) { @@ -310,9 +311,11 @@ public: md->setBusy(true); pCurrentIOPlugin->setLog(&md->Log); - if (!pCurrentIOPlugin->open(extension, fileNameSansDir, *mm ,mask,*prePar)) - { - fprintf(fp, "Opening Failure: %s", (QString("While opening: '%1'\n\n").arg(fileName)+pCurrentIOPlugin->errorMsg()).toStdString().c_str()); // text+ + try { + pCurrentIOPlugin->open(extension, fileNameSansDir, *mm ,mask,*prePar); + } + catch (const MLException& e) { + fprintf(fp, "Opening Failure: %s", (QString("While opening: '%1'\n\n").arg(fileName)+e.what()).toStdString().c_str()); // text+ pCurrentIOPlugin->clearErrorString(); md->setBusy(false); QDir::setCurrent(origDir); // undo the change of directory before leaving