From 0e5d261b4013448ea51e2bc3e500b3b6bfd39a8e Mon Sep 17 00:00:00 2001 From: alemuntoni Date: Wed, 27 Jan 2021 16:18:15 +0100 Subject: [PATCH] list of supported formats from plugin manager --- src/common/plugin_manager.cpp | 57 +++++++++++++++++++++--------- src/common/plugin_manager.h | 20 +++++++---- src/meshlab/mainwindow_RunTime.cpp | 6 ++-- 3 files changed, 57 insertions(+), 26 deletions(-) diff --git a/src/common/plugin_manager.cpp b/src/common/plugin_manager.cpp index 39ce461d7..632fb3e4b 100644 --- a/src/common/plugin_manager.cpp +++ b/src/common/plugin_manager.cpp @@ -205,11 +205,6 @@ void PluginManager::loadPlugins(RichParameterList& defaultGlobal, const QDir& pl fillKnownIOFormats(); } -int PluginManager::numberIOPlugins() const -{ - return ioMeshPlugins.size(); -} - unsigned int PluginManager::size() const { return allPlugins.size(); @@ -259,19 +254,49 @@ IORasterPluginInterface* PluginManager::inputRasterPlugin(const QString inputFor return nullptr; } -const QStringList& PluginManager::inputMeshFormatList() const +bool PluginManager::isInputMeshFormatSupported(const QString inputFormat) const { - return allInputMeshFormats; + return inputMeshFormatToPluginMap.find(inputFormat.toLower()) != inputMeshFormatToPluginMap.end(); } -const QStringList& PluginManager::outputMeshFormatList() const +bool PluginManager::isOutputMeshFormatSupported(const QString outputFormat) const { - return allOutputMeshFormats; + return outputMeshFormatToPluginMap.find(outputFormat.toLower()) != outputMeshFormatToPluginMap.end(); } -const QStringList& PluginManager::inputRasterFormatList() const +bool PluginManager::isInputRasterFormatSupported(const QString inputFormat) const { - return allInputRasterFormats; + return inputRasterFormatToPluginMap.find(inputFormat.toLower()) != inputRasterFormatToPluginMap.end(); +} + +QStringList PluginManager::inputMeshFormatList() const +{ + return inputMeshFormatToPluginMap.keys(); +} + +QStringList PluginManager::outputMeshFormatList() const +{ + return outputMeshFormatToPluginMap.keys(); +} + +QStringList PluginManager::inputRasterFormatList() const +{ + return inputRasterFormatToPluginMap.keys(); +} + +const QStringList& PluginManager::inputMeshFormatListDialog() const +{ + return inputMeshFormatsDialogStringList; +} + +const QStringList& PluginManager::outputMeshFormatListDialog() const +{ + return outputMeshFormatsDialogStringList; +} + +const QStringList& PluginManager::inputRasterFormatListDialog() const +{ + return inputRasterFormatsDialogStringList; } PluginManager::NamePluginPairRangeIterator PluginManager::namePluginPairIterator() const @@ -313,23 +338,23 @@ void PluginManager::fillKnownIOFormats() { QString allKnownFormatsFilter = QObject::tr("All known formats ("); for (IOMeshPluginInterface* pMeshIOPlugin: ioMeshPlugins) { - allKnownFormatsFilter += addPluginMeshFormats(inputMeshFormatToPluginMap, allInputMeshFormats, pMeshIOPlugin, pMeshIOPlugin->importFormats()); + allKnownFormatsFilter += addPluginMeshFormats(inputMeshFormatToPluginMap, inputMeshFormatsDialogStringList, pMeshIOPlugin, pMeshIOPlugin->importFormats()); } allKnownFormatsFilter.append(')'); - allInputMeshFormats.push_front(allKnownFormatsFilter); + inputMeshFormatsDialogStringList.push_front(allKnownFormatsFilter); for (IOMeshPluginInterface* pMeshIOPlugin: ioMeshPlugins) { - addPluginMeshFormats(outputMeshFormatToPluginMap, allOutputMeshFormats, pMeshIOPlugin, pMeshIOPlugin->exportFormats()); + addPluginMeshFormats(outputMeshFormatToPluginMap, outputMeshFormatsDialogStringList, pMeshIOPlugin, pMeshIOPlugin->exportFormats()); } allKnownFormatsFilter = QObject::tr("All known formats ("); for (IORasterPluginInterface* pRasterIOPlugin : ioRasterPlugins){ - allKnownFormatsFilter += addPluginRasterFormats(inputRasterFormatToPluginMap, allInputRasterFormats, pRasterIOPlugin, pRasterIOPlugin->importFormats()); + allKnownFormatsFilter += addPluginRasterFormats(inputRasterFormatToPluginMap, inputRasterFormatsDialogStringList, pRasterIOPlugin, pRasterIOPlugin->importFormats()); } allKnownFormatsFilter.append(')'); - allInputRasterFormats.push_front(allKnownFormatsFilter); + inputRasterFormatsDialogStringList.push_front(allKnownFormatsFilter); } QString PluginManager::addPluginRasterFormats( diff --git a/src/common/plugin_manager.h b/src/common/plugin_manager.h index f850314f9..1fae5a576 100644 --- a/src/common/plugin_manager.h +++ b/src/common/plugin_manager.h @@ -50,18 +50,24 @@ public: void loadPlugins(RichParameterList& defaultGlobal, const QDir& pluginsDirectory, bool verbose = false); QString pluginsCode() const; - int numberIOPlugins() const; unsigned int size() const; DecoratePluginInterface* getDecoratePlugin(const QString& name); QAction* filterAction(const QString& name); + IOMeshPluginInterface* inputMeshPlugin(const QString& inputFormat) const; IOMeshPluginInterface* outputMeshPlugin(const QString& outputFormat) const; IORasterPluginInterface* inputRasterPlugin(const QString inputFormat) const; - const QStringList& inputMeshFormatList() const; - const QStringList& outputMeshFormatList() const; - const QStringList& inputRasterFormatList() const; + bool isInputMeshFormatSupported(const QString inputFormat) const; + bool isOutputMeshFormatSupported(const QString outputFormat) const; + bool isInputRasterFormatSupported(const QString inputFormat) const; + QStringList inputMeshFormatList() const; + QStringList outputMeshFormatList() const; + QStringList inputRasterFormatList() const; + const QStringList& inputMeshFormatListDialog() const; + const QStringList& outputMeshFormatListDialog() const; + const QStringList& inputRasterFormatListDialog() const; class NamePluginPairRangeIterator { @@ -164,13 +170,13 @@ private: QVector ioMeshPlugins; QMap inputMeshFormatToPluginMap; QMap outputMeshFormatToPluginMap; - QStringList allInputMeshFormats; - QStringList allOutputMeshFormats; + QStringList inputMeshFormatsDialogStringList; //todo: remove this + QStringList outputMeshFormatsDialogStringList; //todo: remove this //IORasterPlugins QVector ioRasterPlugins; QMap inputRasterFormatToPluginMap; - QStringList allInputRasterFormats; + QStringList inputRasterFormatsDialogStringList; //Filter Plugins QVector filterPlugins; diff --git a/src/meshlab/mainwindow_RunTime.cpp b/src/meshlab/mainwindow_RunTime.cpp index 967b9fbb8..eddd5f3e8 100644 --- a/src/meshlab/mainwindow_RunTime.cpp +++ b/src/meshlab/mainwindow_RunTime.cpp @@ -2003,7 +2003,7 @@ bool MainWindow::importRaster(const QString& fileImg) QStringList fileNameList; if (fileImg.isEmpty()) - fileNameList = QFileDialog::getOpenFileNames(this,tr("Import Mesh"), lastUsedDirectory.path(), PM.inputRasterFormatList().join(";;")); + fileNameList = QFileDialog::getOpenFileNames(this,tr("Import Mesh"), lastUsedDirectory.path(), PM.inputRasterFormatListDialog().join(";;")); else fileNameList.push_back(fileImg); @@ -2258,7 +2258,7 @@ bool MainWindow::importMesh(QString fileName,bool isareload) //PM.LoadFormats(suffixList, allKnownFormats,PluginManager::IMPORT); QStringList fileNameList; if (fileName.isEmpty()) - fileNameList = QFileDialog::getOpenFileNames(this,tr("Import Mesh"), lastUsedDirectory.path(), PM.inputMeshFormatList().join(";;")); + fileNameList = QFileDialog::getOpenFileNames(this,tr("Import Mesh"), lastUsedDirectory.path(), PM.inputMeshFormatListDialog().join(";;")); else fileNameList.push_back(fileName); @@ -2446,7 +2446,7 @@ void MainWindow::reload() bool MainWindow::exportMesh(QString fileName,MeshModel* mod,const bool saveAllPossibleAttributes) { - const QStringList& suffixList = PM.outputMeshFormatList(); + const QStringList& suffixList = PM.outputMeshFormatListDialog(); //QHash allKnownFormats; QFileInfo fi(fileName);