From d5e715b917df25c8de256cd80cfca8a18529443f Mon Sep 17 00:00:00 2001 From: alemuntoni Date: Thu, 18 Mar 2021 16:06:50 +0100 Subject: [PATCH] management of the warning string - IOMesh documentation --- src/common/plugins/interfaces/iomesh_plugin.h | 92 +++++++++++++------ src/meshlab/mainwindow_RunTime.cpp | 6 +- src/meshlabplugins/io_3ds/meshio.cpp | 6 +- src/meshlabplugins/io_base/baseio.cpp | 2 +- src/meshlabplugins/io_x3d/io_x3d.cpp | 5 +- src/meshlabserver/mainserver.cpp | 6 +- 6 files changed, 76 insertions(+), 41 deletions(-) diff --git a/src/common/plugins/interfaces/iomesh_plugin.h b/src/common/plugins/interfaces/iomesh_plugin.h index 49c17214b..1e2fa5354 100644 --- a/src/common/plugins/interfaces/iomesh_plugin.h +++ b/src/common/plugins/interfaces/iomesh_plugin.h @@ -40,14 +40,14 @@ public: virtual ~IOMeshPlugin() {} /** - * @brief The importFormats functions return a list of all the supported + * @brief The importFormats function returns a list of all the * input file formats supported by the plugin. * This function must be implemented on any IOMesh plugin. */ virtual std::list importFormats() const = 0; /** - * @brief The exportFormats functions return a list of all the supported + * @brief The exportFormats function returns a list of all the * output file formats supported by the plugin. * This function must be implemented on any IOMesh plugin. */ @@ -125,49 +125,87 @@ public: int& capability, int& defaultBits) const = 0; - /// callback used to actually load a mesh from a file + /** + * @brief The open function is called by the framework everytime a mesh is loaded. + * @param format: the extension of the format e.g. "PLY" + * @param fileName: the name of the file to be opened (including its path) + * @param m: the mesh that is filled with the file content + * @param mask: a bit mask that will be filled reporting what kind of data we have found in the file (per vertex color, texture coords etc) + * @param par: the parameters that have been set up in the initPreOpenParameter() + * @param cb: standard callback for reporting progress in the loading + */ 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 - int &mask, /// a bit mask that will be filled reporting what kind of data we have found in the file (per vertex color, texture coords etc) - const RichParameterList & par, /// The parameters that have been set up in the initPreOpenParameter() - vcg::CallBackPos *cb = nullptr) = 0; /// standard callback for reporting progress in the loading - - virtual void save( - const QString &format, // the extension of the format e.g. "PLY" + const QString &format, const QString &fileName, MeshModel &m, - const int mask,// a bit mask indicating what kind of the data present in the mesh should be saved (e.g. you could not want to save normals in ply files) + int &mask, + const RichParameterList & par, + vcg::CallBackPos *cb = nullptr) = 0; + + /** + * @brief The save function is called by the framework everytime a mesh is saved. + * @param format: the extension of the format e.g. "PLY" + * @param fileName: the name of the file on which save the mesh m (including its path) + * @param m: the mesh to be saved in the file + * @param mask: a bit mask indicating what kind of the data present in the mesh should be saved (e.g. you could not want to save normals in ply files) + * @param par: the parameters that have been set up in the initSaveParameter() + * @param cb: standard callback for reporting progress in the saving + */ + virtual void save( + const QString &format, + const QString &fileName, + MeshModel &m, + const int mask, const RichParameterList & par, vcg::CallBackPos *cb) = 0; + /** + * @brief The reportWarning function should be used everytime that a non-critical + * error while loading or saving a file happens. This function appends the + * warning message passed as parameter to a string that will be shown + * by the framework at the end of the execution of the load/save function + * @param warningMessage + */ + void reportWarning(const QString& warningMessage) const + { + MeshLabPluginLogger::log(GLLogStream::WARNING, warningMessage.toStdString()); + warnString += "\n" + warningMessage; + } + + /** + * @brief call this function in any of the import functions + * (initPreOpenParameters, load...) whenever you receive as parameter a + * format that is not supported by your plugin + */ void wrongOpenFormat(const QString& format) { throw MLException("Internal error: unknown open format " + format + " to " + pluginName() + " plugin."); }; + /** + * @brief call this function in any of the export functions + * (exportMaskCapability, save...) whenever you receive as parameter a + * format that is not supported by your 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. - const QString& errorMsg() const + /** + * @brief The warningMessageString is invoked by the framework after the execution + * of load/save function. It returns the warning string containing all the + * warinings produced by the function, and it clears the string. + */ + QString warningMessageString() const { - return this->errorMessage; - } - void clearErrorString() - { - errorMessage.clear(); - } + QString tmp = warnString; + warnString.clear(); + return tmp; + }; -protected: - // this string is used to pass back to the framework error messages in case of failure of a filter apply. - // NEVER EVER use a msgbox to say something to the user. - QString errorMessage; +private: + mutable QString warnString; }; diff --git a/src/meshlab/mainwindow_RunTime.cpp b/src/meshlab/mainwindow_RunTime.cpp index e30338fec..1a7dd7ee4 100644 --- a/src/meshlab/mainwindow_RunTime.cpp +++ b/src/meshlab/mainwindow_RunTime.cpp @@ -2224,7 +2224,6 @@ bool MainWindow::loadMesh(const QString& fileName, IOMeshPlugin *pCurrentIOPlugi 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 return false; @@ -2240,11 +2239,10 @@ bool MainWindow::loadMesh(const QString& fileName, IOMeshPlugin *pCurrentIOPlugi //pCurrentIOPlugin->initOpenParameter(extension, *mm, par); //pCurrentIOPlugin->applyOpenParameter(extension, *mm, par); - QString err = pCurrentIOPlugin->errorMsg(); + QString err = pCurrentIOPlugin->warningMessageString(); if (!err.isEmpty()) { - QMessageBox::warning(this, tr("Opening Problems"), QString("While opening: '%1'\n\n").arg(fileName)+pCurrentIOPlugin->errorMsg()); - pCurrentIOPlugin->clearErrorString(); + QMessageBox::warning(this, tr("Opening Problems"), QString("While opening: '%1'\n\n").arg(fileName)+ err); } saveRecentFileList(fileName); diff --git a/src/meshlabplugins/io_3ds/meshio.cpp b/src/meshlabplugins/io_3ds/meshio.cpp index 76fe3d597..6bbeda306 100644 --- a/src/meshlabplugins/io_3ds/meshio.cpp +++ b/src/meshlabplugins/io_3ds/meshio.cpp @@ -159,7 +159,7 @@ void ExtraMeshIOPlugin::open( int result = vcg::tri::io::Importer3DS::Load(mm.cm, file, p, info); if (result != vcg::tri::io::Importer3DS::E_NOERROR) { - errorMessage = "3DS Opening Error" + errorMsgFormat.arg(fileName, vcg::tri::io::Importer3DS::ErrorMsg(result)); + reportWarning("3DS Opening Error: " + errorMsgFormat.arg(fileName, vcg::tri::io::Importer3DS::ErrorMsg(result))); continue; } @@ -182,7 +182,7 @@ void ExtraMeshIOPlugin::open( fclose (pFile); } if (someTextureNotFound){ - errorMessage = "Missing texture files: " + missingTextureFilesMsg; + reportWarning("Missing texture files: " + missingTextureFilesMsg); } vcg::tri::UpdateBounding::Box(mm.cm); // updates bounding box @@ -225,7 +225,7 @@ void ExtraMeshIOPlugin::open( fclose (pFile); } if (someTextureNotFound){ - errorMessage = "Missing texture files: " + missingTextureFilesMsg; + reportWarning("Missing texture files: " + missingTextureFilesMsg); } vcg::tri::UpdateBounding::Box(m.cm); // updates bounding box diff --git a/src/meshlabplugins/io_base/baseio.cpp b/src/meshlabplugins/io_base/baseio.cpp index 5e305e10e..35613946f 100644 --- a/src/meshlabplugins/io_base/baseio.cpp +++ b/src/meshlabplugins/io_base/baseio.cpp @@ -155,7 +155,7 @@ void BaseMeshIOPlugin::open(const QString &formatName, const QString &fileName, if (result != tri::io::ImporterOBJ::E_NOERROR) { if (result & tri::io::ImporterOBJ::E_NON_CRITICAL_ERROR) { - errorMessage = errorMsgFormat.arg(fileName, tri::io::ImporterOBJ::ErrorMsg(result)); + reportWarning(errorMsgFormat.arg(fileName, tri::io::ImporterOBJ::ErrorMsg(result))); } else { throw MLException(errorMsgFormat.arg(fileName, tri::io::ImporterOBJ::ErrorMsg(result))); diff --git a/src/meshlabplugins/io_x3d/io_x3d.cpp b/src/meshlabplugins/io_x3d/io_x3d.cpp index 139bb8f80..eb54836d2 100644 --- a/src/meshlabplugins/io_x3d/io_x3d.cpp +++ b/src/meshlabplugins/io_x3d/io_x3d.cpp @@ -104,8 +104,9 @@ void IoX3DPlugin::open(const QString &formatName, const QString &fileName, MeshM } - if (someTextureNotFound) - errorMessage = missingTextureFilesMsg; + if (someTextureNotFound){ + reportWarning(missingTextureFilesMsg); + } vcg::tri::UpdateBounding::Box(m.cm); // updates bounding box if (!normalsUpdated) diff --git a/src/meshlabserver/mainserver.cpp b/src/meshlabserver/mainserver.cpp index 785de26fb..219645bd3 100644 --- a/src/meshlabserver/mainserver.cpp +++ b/src/meshlabserver/mainserver.cpp @@ -319,7 +319,6 @@ public: } 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 return false; @@ -335,11 +334,10 @@ public: //pCurrentIOPlugin->initOpenParameter(extension, *mm, par); //pCurrentIOPlugin->applyOpenParameter(extension, *mm, par); - QString err = pCurrentIOPlugin->errorMsg(); + QString err = pCurrentIOPlugin->warningMessageString(); if (!err.isEmpty()) { - fprintf(fp, "Opening Problems: %s", (QString("While opening: '%1'\n\n").arg(fileName)+pCurrentIOPlugin->errorMsg()).toStdString().c_str()); - pCurrentIOPlugin->clearErrorString(); + fprintf(fp, "Opening Problems: %s", (QString("While opening: '%1'\n\n").arg(fileName)+err).toStdString().c_str()); } //saveRecentFileList(fileName);