more member functions to plugin manager

This commit is contained in:
alemuntoni 2021-01-27 11:16:37 +01:00
parent 5403f0a497
commit f8a2d88d94
4 changed files with 90 additions and 31 deletions

View File

@ -233,6 +233,45 @@ QAction* PluginManager::filterAction(const QString& name)
return nullptr;
}
IOMeshPluginInterface* PluginManager::inputMeshPlugin(const QString& inputFormat)
{
auto it = allKnowInputMeshFormats.find(inputFormat.toLower());
if (it != allKnowInputMeshFormats.end())
return *it;
return nullptr;
}
IOMeshPluginInterface* PluginManager::outputMeshPlugin(const QString& outputFormat)
{
auto it = allKnowOutputFormats.find(outputFormat.toLower());
if (it != allKnowOutputFormats.end())
return *it;
return nullptr;
}
IORasterPluginInterface* PluginManager::inputRasterPlugin(const QString inputFormat)
{
auto it = allKnownInputRasterFormats.find(inputFormat.toLower());
if (it != allKnownInputRasterFormats.end())
return *it;
return nullptr;
}
const QStringList& PluginManager::inputMeshFormatList() const
{
return inpMeshFilters;
}
const QStringList& PluginManager::outputMeshFormatList() const
{
return outFilters;
}
const QStringList& PluginManager::inputRasterFormatList() const
{
return inpRasterFilters;
}
PluginManager::PluginRangeIterator PluginManager::pluginIterator()
{
return PluginRangeIterator(this);

View File

@ -54,8 +54,14 @@ public:
unsigned int size() const;
DecoratePluginInterface* getDecoratePlugin(const QString& name);
QAction* filterAction(const QString& name);
IOMeshPluginInterface* inputMeshPlugin(const QString& inputFormat);
IOMeshPluginInterface* outputMeshPlugin(const QString& outputFormat);
IORasterPluginInterface* inputRasterPlugin(const QString inputFormat);
const QStringList& inputMeshFormatList() const;
const QStringList& outputMeshFormatList() const;
const QStringList& inputRasterFormatList() const;
class PluginRangeIterator
{
@ -67,7 +73,7 @@ public:
PluginRangeIterator(PluginManager* pm) : pm(pm) {}
PluginManager* pm;
};
class FilterPluginRangeIterator
{
friend class PluginManager;
@ -78,7 +84,7 @@ public:
FilterPluginRangeIterator(PluginManager* pm) : pm(pm) {}
PluginManager* pm;
};
class RenderPluginRangeIterator
{
friend class PluginManager;
@ -89,7 +95,7 @@ public:
RenderPluginRangeIterator(PluginManager* pm) : pm(pm) {}
PluginManager* pm;
};
class DecoratePluginRangeIterator
{
friend class PluginManager;
@ -100,7 +106,7 @@ public:
DecoratePluginRangeIterator(PluginManager* pm) : pm(pm) {}
PluginManager* pm;
};
class EditPluginFactoryRangeIterator
{
friend class PluginManager;
@ -122,13 +128,6 @@ public:
/** Old declarations, to be deleted or moved to private */
QMap<QString,IOMeshPluginInterface*> allKnowInputMeshFormats;
QMap<QString,IOMeshPluginInterface*> allKnowOutputFormats;
QMap<QString, IORasterPluginInterface*> allKnownInputRasterFormats;
QStringList inpMeshFilters;
QStringList inpRasterFilters;
QStringList outFilters;
QVector<QAction *> editActionList;
QVector<QAction *> decoratorActionList;
// Used for unique destruction - this "owns" all IO, Filter, Render, and Decorate plugins
@ -136,16 +135,37 @@ public:
QStringList pluginsLoaded;
private:
std::map<QString, PluginInterface*> ownerPlug;
QVector<IOMeshPluginInterface*> ioMeshPlugins;
QVector<IORasterPluginInterface*> ioRasterPlugins;
QVector<FilterPluginInterface*> filterPlugins;
QVector<RenderPluginInterface*> renderPlugins;
QVector<DecoratePluginInterface*> decoratePlugins;
QVector<EditPluginInterfaceFactory*> editPlugins;
QDir pluginsDir;
//all plugins
std::map<QString, PluginInterface*> ownerPlug;
//IOMeshPlugins
QVector<IOMeshPluginInterface*> ioMeshPlugins;
QMap<QString,IOMeshPluginInterface*> allKnowInputMeshFormats;
QMap<QString,IOMeshPluginInterface*> allKnowOutputFormats;
QStringList inpMeshFilters;
QStringList outFilters;
//IORasterPlugins
QVector<IORasterPluginInterface*> ioRasterPlugins;
QMap<QString, IORasterPluginInterface*> allKnownInputRasterFormats;
QStringList inpRasterFilters;
//Filter Plugins
QVector<FilterPluginInterface*> filterPlugins;
QMap<QString, QAction*> actionFilterMap;
//Render Plugins
QVector<RenderPluginInterface*> renderPlugins;
//Decorate Plugins
QVector<DecoratePluginInterface*> decoratePlugins;
//Edit Plugins
QVector<EditPluginInterfaceFactory*> editPlugins;
//Private member functions
void fillKnownIOFormats();
static QString addPluginRasterFormats(

View File

@ -1998,7 +1998,7 @@ bool MainWindow::importRaster(const QString& fileImg)
QStringList fileNameList;
if (fileImg.isEmpty())
fileNameList = QFileDialog::getOpenFileNames(this,tr("Import Mesh"), lastUsedDirectory.path(), PM.inpRasterFilters.join(";;"));
fileNameList = QFileDialog::getOpenFileNames(this,tr("Import Mesh"), lastUsedDirectory.path(), PM.inputRasterFormatList().join(";;"));
else
fileNameList.push_back(fileImg);
@ -2017,7 +2017,7 @@ bool MainWindow::importRaster(const QString& fileImg)
for(const QString& fileName : fileNameList) {
QFileInfo fi(fileName);
QString extension = fi.suffix();
IORasterPluginInterface *pCurrentIOPlugin = PM.allKnownInputRasterFormats[extension.toLower()];
IORasterPluginInterface *pCurrentIOPlugin = PM.inputRasterPlugin(extension);
//pCurrentIOPlugin->setLog(gla->log);
if (pCurrentIOPlugin == NULL)
{
@ -2253,7 +2253,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.inpMeshFilters.join(";;"));
fileNameList = QFileDialog::getOpenFileNames(this,tr("Import Mesh"), lastUsedDirectory.path(), PM.inputMeshFormatList().join(";;"));
else
fileNameList.push_back(fileName);
@ -2272,9 +2272,9 @@ bool MainWindow::importMesh(QString fileName,bool isareload)
{
QFileInfo fi(fileName);
QString extension = fi.suffix();
IOMeshPluginInterface *pCurrentIOPlugin = PM.allKnowInputMeshFormats[extension.toLower()];
IOMeshPluginInterface *pCurrentIOPlugin = PM.inputMeshPlugin(extension);
//pCurrentIOPlugin->setLog(gla->log);
if (pCurrentIOPlugin == NULL)
if (pCurrentIOPlugin == nullptr)
{
QString errorMsgFormat("Unable to open file:\n\"%1\"\n\nError details: file format " + extension + " not supported.");
QMessageBox::critical(this, tr("Meshlab Opening Error"), errorMsgFormat.arg(fileName));
@ -2368,7 +2368,7 @@ bool MainWindow::loadMeshWithStandardParams(QString& fullPath, MeshModel* mm, co
mm->Clear();
QFileInfo fi(fullPath);
QString extension = fi.suffix();
IOMeshPluginInterface *pCurrentIOPlugin = PM.allKnowInputMeshFormats[extension.toLower()];
IOMeshPluginInterface *pCurrentIOPlugin = PM.inputMeshPlugin(extension);
if(pCurrentIOPlugin != NULL)
{
@ -2441,7 +2441,7 @@ void MainWindow::reload()
bool MainWindow::exportMesh(QString fileName,MeshModel* mod,const bool saveAllPossibleAttributes)
{
QStringList& suffixList = PM.outFilters;
const QStringList& suffixList = PM.outputMeshFormatList();
//QHash<QString, MeshIOInterface*> allKnownFormats;
QFileInfo fi(fileName);
@ -2507,7 +2507,7 @@ bool MainWindow::exportMesh(QString fileName,MeshModel* mod,const bool saveAllPo
QStringListIterator itFilter(suffixList);
IOMeshPluginInterface *pCurrentIOPlugin = PM.allKnowOutputFormats[extension.toLower()];
IOMeshPluginInterface *pCurrentIOPlugin = PM.outputMeshPlugin(extension);
if (pCurrentIOPlugin == 0)
{
QMessageBox::warning(this, "Unknown type", "File extension not supported!");

View File

@ -173,7 +173,7 @@ public:
QString extension = fi.suffix();
qDebug("Opening a file with extension %s", qUtf8Printable(extension));
// retrieving corresponding IO plugin
IOMeshPluginInterface* pCurrentIOPlugin = PM.allKnowInputMeshFormats[extension.toLower()];
IOMeshPluginInterface* pCurrentIOPlugin = PM.inputMeshPlugin(extension);
if (pCurrentIOPlugin == 0)
{
fprintf(fp,"Error encountered while opening file: ");
@ -238,8 +238,8 @@ public:
QString extension = fi.suffix();
// retrieving corresponding IO plugin
IOMeshPluginInterface* pCurrentIOPlugin = PM.allKnowOutputFormats[extension.toLower()];
if (pCurrentIOPlugin == 0)
IOMeshPluginInterface* pCurrentIOPlugin = PM.outputMeshPlugin(extension);
if (pCurrentIOPlugin == nullptr)
{
fprintf(fp,"Error encountered while opening file: ");
//QString errorMsgFormat = "Error encountered while opening file:\n\"%1\"\n\nError details: The \"%2\" file extension does not correspond to any supported format.";
@ -403,7 +403,7 @@ public:
mm->Clear();
QFileInfo fi(fullPath);
QString extension = fi.suffix();
IOMeshPluginInterface *pCurrentIOPlugin = PM.allKnowInputMeshFormats[extension.toLower()];
IOMeshPluginInterface *pCurrentIOPlugin = PM.inputMeshPlugin(extension);
if(pCurrentIOPlugin != NULL)
{