mirror of
https://github.com/lucaspalomodevelop/meshlab.git
synced 2026-03-19 19:14:42 +00:00
- updated enum system
- fixed bugs on script enum - added MeshLabApplication in order to avoid crash when an handle raise up an uncaught exception.
This commit is contained in:
parent
ca3c7e1962
commit
fd25643a25
@ -74,6 +74,7 @@ HEADERS += filterparameter.h \
|
||||
scriptinterface.h \
|
||||
xmlfilterinfo.h \
|
||||
mlexception.h \
|
||||
mlapplication.h \
|
||||
../../../vcglib/wrap/gl/trimesh.h \
|
||||
meshlabdocumentxml.h
|
||||
SOURCES += filterparameter.cpp \
|
||||
@ -84,6 +85,7 @@ SOURCES += filterparameter.cpp \
|
||||
pluginmanager.cpp \
|
||||
scriptinterface.cpp \
|
||||
xmlfilterinfo.cpp \
|
||||
mlapplication.cpp \
|
||||
$$GLEWCODE \
|
||||
meshlabdocumentxml.cpp
|
||||
|
||||
|
||||
@ -638,10 +638,14 @@ void MeshModel::clearDataMask(int unneededDataMask)
|
||||
|
||||
void MeshModel::Enable(int openingFileMask)
|
||||
{
|
||||
if( openingFileMask & tri::io::Mask::IOM_VERTTEXCOORD ) updateDataMask(MM_VERTTEXCOORD);
|
||||
if( openingFileMask & tri::io::Mask::IOM_WEDGTEXCOORD ) updateDataMask(MM_WEDGTEXCOORD);
|
||||
if( openingFileMask & tri::io::Mask::IOM_VERTCOLOR ) updateDataMask(MM_VERTCOLOR);
|
||||
if( openingFileMask & tri::io::Mask::IOM_FACECOLOR ) updateDataMask(MM_FACECOLOR);
|
||||
if( openingFileMask & tri::io::Mask::IOM_VERTTEXCOORD )
|
||||
updateDataMask(MM_VERTTEXCOORD);
|
||||
if( openingFileMask & tri::io::Mask::IOM_WEDGTEXCOORD )
|
||||
updateDataMask(MM_WEDGTEXCOORD);
|
||||
if( openingFileMask & tri::io::Mask::IOM_VERTCOLOR )
|
||||
updateDataMask(MM_VERTCOLOR);
|
||||
if( openingFileMask & tri::io::Mask::IOM_FACECOLOR )
|
||||
updateDataMask(MM_FACECOLOR);
|
||||
if( openingFileMask & tri::io::Mask::IOM_VERTRADIUS ) updateDataMask(MM_VERTRADIUS);
|
||||
if( openingFileMask & tri::io::Mask::IOM_CAMERA ) updateDataMask(MM_CAMERA);
|
||||
if( openingFileMask & tri::io::Mask::IOM_VERTQUALITY ) updateDataMask(MM_VERTQUALITY);
|
||||
|
||||
25
src/common/mlapplication.cpp
Normal file
25
src/common/mlapplication.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#include "mlapplication.h"
|
||||
#include "mlexception.h"
|
||||
|
||||
MeshLabApplication::MeshLabApplication( int argc, char *argv[] )
|
||||
:QApplication(argc,argv)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
MeshLabApplication::~MeshLabApplication()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool MeshLabApplication::notify( QObject * rec, QEvent * ev )
|
||||
{
|
||||
try
|
||||
{
|
||||
return QApplication::notify(rec,ev);
|
||||
}
|
||||
catch (MeshLabException& e)
|
||||
{
|
||||
qCritical(e.what());
|
||||
}
|
||||
}
|
||||
14
src/common/mlapplication.h
Normal file
14
src/common/mlapplication.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef ML_APPLICATION_H
|
||||
#define ML_APPLICATION_H
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
class MeshLabApplication : public QApplication
|
||||
{
|
||||
public:
|
||||
MeshLabApplication(int argc, char *argv[]);
|
||||
~MeshLabApplication();
|
||||
bool notify(QObject * rec, QEvent * ev);
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -1,5 +1,5 @@
|
||||
#ifndef ML_EXCEPTION
|
||||
#define ML_EXCEPTION
|
||||
#ifndef ML_EXCEPTION_H
|
||||
#define ML_EXCEPTION_H
|
||||
|
||||
#include <exception>
|
||||
|
||||
|
||||
@ -9,18 +9,18 @@
|
||||
PluginManager::PluginManager()
|
||||
:currentDocInterface(NULL),env()
|
||||
{
|
||||
//pluginsDir=QDir(getPluginDirPath());
|
||||
//pluginsDir=QDir(getPluginDirPath());
|
||||
// without adding the correct library path in the mac the loading of jpg (done via qt plugins) fails
|
||||
//qApp->addLibraryPath(getPluginDirPath());
|
||||
//qApp->addLibraryPath(getBaseDirPath());
|
||||
//qApp->addLibraryPath(getPluginDirPath());
|
||||
//qApp->addLibraryPath(getBaseDirPath());
|
||||
}
|
||||
|
||||
void PluginManager::loadPlugins(RichParameterSet& defaultGlobal)
|
||||
{
|
||||
pluginsDir=QDir(getPluginDirPath());
|
||||
// without adding the correct library path in the mac the loading of jpg (done via qt plugins) fails
|
||||
qApp->addLibraryPath(getPluginDirPath());
|
||||
qApp->addLibraryPath(getBaseDirPath());
|
||||
pluginsDir=QDir(getPluginDirPath());
|
||||
// without adding the correct library path in the mac the loading of jpg (done via qt plugins) fails
|
||||
qApp->addLibraryPath(getPluginDirPath());
|
||||
qApp->addLibraryPath(getBaseDirPath());
|
||||
QStringList pluginfilters;
|
||||
#if defined(Q_OS_WIN)
|
||||
pluginfilters << "*.dll";
|
||||
@ -30,23 +30,23 @@ void PluginManager::loadPlugins(RichParameterSet& defaultGlobal)
|
||||
#endif
|
||||
//only the file with extension pluginfilters will be listed by function entryList()
|
||||
pluginsDir.setNameFilters(pluginfilters);
|
||||
|
||||
qDebug( "Current Plugins Dir is: %s ",qPrintable(pluginsDir.absolutePath()));
|
||||
|
||||
qDebug( "Current Plugins Dir is: %s ",qPrintable(pluginsDir.absolutePath()));
|
||||
foreach (QString fileName, pluginsDir.entryList(QDir::Files))
|
||||
{
|
||||
QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
|
||||
QObject *plugin = loader.instance();
|
||||
if (plugin)
|
||||
{
|
||||
pluginsLoaded.push_back(fileName);
|
||||
MeshFilterInterface *iFilter = qobject_cast<MeshFilterInterface *>(plugin);
|
||||
pluginsLoaded.push_back(fileName);
|
||||
MeshFilterInterface *iFilter = qobject_cast<MeshFilterInterface *>(plugin);
|
||||
if (iFilter)
|
||||
{
|
||||
meshFilterPlug.push_back(iFilter);
|
||||
foreach(QAction *filterAction, iFilter->actions())
|
||||
meshFilterPlug.push_back(iFilter);
|
||||
foreach(QAction *filterAction, iFilter->actions())
|
||||
{
|
||||
actionFilterMap.insert(filterAction->text(),filterAction);
|
||||
stringFilterMap.insert(filterAction->text(),iFilter);
|
||||
stringFilterMap.insert(filterAction->text(),iFilter);
|
||||
iFilter->initGlobalParameterSet(filterAction,defaultGlobal);
|
||||
}
|
||||
}
|
||||
@ -60,32 +60,32 @@ void PluginManager::loadPlugins(RichParameterSet& defaultGlobal)
|
||||
QString withoutext = fileName.left(res);
|
||||
QString xmlFile = getPluginDirPath() + "/" + withoutext + QObject::tr(".xml");
|
||||
qDebug("Loading XMLFile: %s",qPrintable(xmlFile));
|
||||
if(!QFileInfo(xmlFile).exists())
|
||||
{
|
||||
qDebug("Error XMLFile: %s does not exist",qPrintable(xmlFile));
|
||||
}
|
||||
else
|
||||
{
|
||||
XMLMessageHandler xmlErr;
|
||||
fc.xmlInfo = XMLFilterInfo::createXMLFileInfo(xmlFile,ScriptAdapterGenerator::xmlSchemaFile(),xmlErr);
|
||||
if (fc.xmlInfo != NULL)
|
||||
{
|
||||
QStringList fn = fc.xmlInfo->filterNames();
|
||||
foreach(QString filtName,fn)
|
||||
{
|
||||
fc.act = new QAction(filtName,plugin);
|
||||
stringXMLFilterMap.insert(filtName,fc);
|
||||
if(!QFileInfo(xmlFile).exists())
|
||||
{
|
||||
qDebug("Error XMLFile: %s does not exist",qPrintable(xmlFile));
|
||||
}
|
||||
else
|
||||
{
|
||||
XMLMessageHandler xmlErr;
|
||||
fc.xmlInfo = XMLFilterInfo::createXMLFileInfo(xmlFile,ScriptAdapterGenerator::xmlSchemaFile(),xmlErr);
|
||||
if (fc.xmlInfo != NULL)
|
||||
{
|
||||
QStringList fn = fc.xmlInfo->filterNames();
|
||||
foreach(QString filtName,fn)
|
||||
{
|
||||
fc.act = new QAction(filtName,plugin);
|
||||
stringXMLFilterMap.insert(filtName,fc);
|
||||
|
||||
//SHOULD INITIALIZE GLOBALS FOR FILTERS
|
||||
//SHOULD INITIALIZE GLOBALS FOR FILTERS
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QString err = xmlErr.statusMessage();
|
||||
qDebug("Error in XMLFile: %s - line: %d, column: %d - %s",qPrintable(xmlFile),xmlErr.line(),xmlErr.column(),qPrintable(err));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QString err = xmlErr.statusMessage();
|
||||
qDebug("Error in XMLFile: %s - line: %d, column: %d - %s",qPrintable(xmlFile),xmlErr.line(),xmlErr.column(),qPrintable(err));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MeshIOInterface *iIO = qobject_cast<MeshIOInterface *>(plugin);
|
||||
@ -96,7 +96,7 @@ void PluginManager::loadPlugins(RichParameterSet& defaultGlobal)
|
||||
if (iDecorator)
|
||||
{
|
||||
meshDecoratePlug.push_back(iDecorator);
|
||||
foreach(QAction *decoratorAction, iDecorator->actions())
|
||||
foreach(QAction *decoratorAction, iDecorator->actions())
|
||||
{
|
||||
editActionList.push_back(decoratorAction);
|
||||
iDecorator->initGlobalParameterSet(decoratorAction,defaultGlobal);
|
||||
@ -106,7 +106,7 @@ void PluginManager::loadPlugins(RichParameterSet& defaultGlobal)
|
||||
MeshRenderInterface *iRender = qobject_cast<MeshRenderInterface *>(plugin);
|
||||
if (iRender)
|
||||
meshRenderPlug.push_back(iRender);
|
||||
|
||||
|
||||
MeshEditInterfaceFactory *iEditFactory = qobject_cast<MeshEditInterfaceFactory *>(plugin);
|
||||
if(iEditFactory)
|
||||
{
|
||||
@ -117,7 +117,7 @@ void PluginManager::loadPlugins(RichParameterSet& defaultGlobal)
|
||||
}
|
||||
}
|
||||
knownIOFormats();
|
||||
|
||||
|
||||
/*******************************************/
|
||||
|
||||
/*QString code = "";
|
||||
@ -125,22 +125,22 @@ void PluginManager::loadPlugins(RichParameterSet& defaultGlobal)
|
||||
QMap<QString,RichParameterSet> FPM = generateFilterParameterMap();
|
||||
foreach(MeshFilterInterface* mi,this->meshFilterPlug)
|
||||
{
|
||||
QString pname = mi->pluginName();
|
||||
if (pname != "")
|
||||
{
|
||||
code += "Plugins." + pname + " = { };\n";
|
||||
foreach(MeshFilterInterface::FilterIDType tt,mi->types())
|
||||
{
|
||||
QString filterName = mi->filterName(tt);
|
||||
QString filterFunction = mi->filterScriptFunctionName(tt);
|
||||
if (filterFunction != "")
|
||||
{
|
||||
ScriptAdapterGenerator gen;
|
||||
QString gencode = gen.funCodeGenerator(filterName,FPM[filterName]);
|
||||
code += "Plugins." + pname + "." + filterFunction + " = " + gencode + "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
QString pname = mi->pluginName();
|
||||
if (pname != "")
|
||||
{
|
||||
code += "Plugins." + pname + " = { };\n";
|
||||
foreach(MeshFilterInterface::FilterIDType tt,mi->types())
|
||||
{
|
||||
QString filterName = mi->filterName(tt);
|
||||
QString filterFunction = mi->filterScriptFunctionName(tt);
|
||||
if (filterFunction != "")
|
||||
{
|
||||
ScriptAdapterGenerator gen;
|
||||
QString gencode = gen.funCodeGenerator(filterName,FPM[filterName]);
|
||||
code += "Plugins." + pname + "." + filterFunction + " = " + gencode + "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QScriptValue initFun = env.newFunction(PluginInterfaceInit, this);
|
||||
@ -150,7 +150,7 @@ void PluginManager::loadPlugins(RichParameterSet& defaultGlobal)
|
||||
env.globalObject().setProperty("_applyFilter", applyFun);
|
||||
|
||||
env.evaluate(code);
|
||||
*/
|
||||
*/
|
||||
QString code = "";
|
||||
QStringList liblist = ScriptAdapterGenerator::javaScriptLibraryFiles();
|
||||
int ii = 0;
|
||||
@ -180,7 +180,7 @@ void PluginManager::loadPlugins(RichParameterSet& defaultGlobal)
|
||||
QString filterFunction = mi.xmlInfo->filterAttribute(filterName,MLXMLElNames::filterScriptFunctName);
|
||||
if (filterFunction != "")
|
||||
{
|
||||
|
||||
|
||||
QString gencode = gen.funCodeGenerator(filterName,*mi.xmlInfo);
|
||||
code += "Plugins." + pname + "." + filterFunction + " = " + gencode + "\n";
|
||||
}
|
||||
@ -198,29 +198,29 @@ void PluginManager::loadPlugins(RichParameterSet& defaultGlobal)
|
||||
qDebug("Code:\n %s",qPrintable(code));
|
||||
if (env.hasUncaughtException())
|
||||
qDebug() << "JavaScript Interpreter Error: " << res.toString() << "\n";
|
||||
|
||||
|
||||
}
|
||||
/*
|
||||
This function create a map from filtername to dummy RichParameterSet.
|
||||
containing for each filtername the set of parameter that it uses.
|
||||
*/
|
||||
This function create a map from filtername to dummy RichParameterSet.
|
||||
containing for each filtername the set of parameter that it uses.
|
||||
*/
|
||||
QMap<QString, RichParameterSet> PluginManager::generateFilterParameterMap()
|
||||
{
|
||||
QMap<QString,RichParameterSet> FPM;
|
||||
MeshDocument md;
|
||||
MeshModel* mm = md.addNewMesh("","dummy",true);
|
||||
vcg::tri::Tetrahedron<CMeshO>(mm->cm);
|
||||
mm->updateDataMask(MeshModel::MM_ALL);
|
||||
QMap<QString, QAction*>::iterator ai;
|
||||
for(ai=this->actionFilterMap.begin(); ai !=this->actionFilterMap.end();++ai)
|
||||
{
|
||||
QString filterName = ai.key();// ->filterName();
|
||||
//QAction act(filterName,NULL);
|
||||
RichParameterSet rp;
|
||||
stringFilterMap[filterName]->initParameterSet(ai.value(),md,rp);
|
||||
FPM[filterName]=rp;
|
||||
}
|
||||
return FPM;
|
||||
QMap<QString,RichParameterSet> FPM;
|
||||
MeshDocument md;
|
||||
MeshModel* mm = md.addNewMesh("","dummy",true);
|
||||
vcg::tri::Tetrahedron<CMeshO>(mm->cm);
|
||||
mm->updateDataMask(MeshModel::MM_ALL);
|
||||
QMap<QString, QAction*>::iterator ai;
|
||||
for(ai=this->actionFilterMap.begin(); ai !=this->actionFilterMap.end();++ai)
|
||||
{
|
||||
QString filterName = ai.key();// ->filterName();
|
||||
//QAction act(filterName,NULL);
|
||||
RichParameterSet rp;
|
||||
stringFilterMap[filterName]->initParameterSet(ai.value(),md,rp);
|
||||
FPM[filterName]=rp;
|
||||
}
|
||||
return FPM;
|
||||
}
|
||||
|
||||
QString PluginManager::getBaseDirPath()
|
||||
@ -240,7 +240,7 @@ QString PluginManager::getBaseDirPath()
|
||||
if(baseDir.exists("plugins")) break;
|
||||
baseDir.cdUp();
|
||||
}
|
||||
qDebug("The base dir is %s",qPrintable(baseDir.absolutePath()));
|
||||
qDebug("The base dir is %s",qPrintable(baseDir.absolutePath()));
|
||||
#endif
|
||||
return baseDir.absolutePath();
|
||||
}
|
||||
|
||||
@ -115,8 +115,8 @@ QString ScriptAdapterGenerator::funCodeGenerator( const QString& filterName,cons
|
||||
QString argument = "arguments[" + QString::number(arg) + "]";
|
||||
if (isenum)
|
||||
{
|
||||
code += "\tvar argm = enumtype_" + num + "[" + argument + "];\n";
|
||||
code += "\tenviron.insertExpressionBinding(\"" + mp[MLXMLElNames::paramName] + "\",argm);\n";
|
||||
code += "\tvar argenum_" + num + " = enumtype_" + num + "[" + argument + "];\n";
|
||||
code += "\tenviron.insertExpressionBinding(\"" + mp[MLXMLElNames::paramName] + "\",argenum_" + num + ");\n";
|
||||
}
|
||||
else
|
||||
//code += "\tprint(" + argument + ");\n";
|
||||
@ -127,6 +127,7 @@ QString ScriptAdapterGenerator::funCodeGenerator( const QString& filterName,cons
|
||||
{
|
||||
if (isenum)
|
||||
{
|
||||
//code += "\tvar argenum_" + num + " = enumtype_" + num + "[" + argument + "];\n";
|
||||
code += "\tvar " + mp[MLXMLElNames::paramName] + " = " + optName() + "." + /*mp[MLXMLElNames::paramType] + "_" +*/ mp[MLXMLElNames::paramName] + ";\n";
|
||||
code += "\tenviron.insertExpressionBinding(\"" + mp[MLXMLElNames::paramName] + "\", " + mp[MLXMLElNames::paramName] + ");\n";
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ QString XMLFilterInfo::defaultGuiInfo(const QString& guiType,const QString& xmlv
|
||||
|
||||
QString XMLFilterInfo::floatGuiInfo(const QString& guiType,const QString& xmlvariable)
|
||||
{
|
||||
return defaultGuiInfo(guiType,xmlvariable) + externalSep() + MLXMLElNames::guiMinExpr + "={data(" + xmlvariable + "/@" + MLXMLElNames::guiMinExpr + ")}externalSep()" + MLXMLElNames::guiMaxExpr + "={data(" + xmlvariable + "/@" + MLXMLElNames::guiMaxExpr + ")}";
|
||||
return defaultGuiInfo(guiType,xmlvariable) + externalSep() + MLXMLElNames::guiMinExpr + "={data(" + xmlvariable + "/@" + MLXMLElNames::guiMinExpr + ")}" + externalSep() + MLXMLElNames::guiMaxExpr + "={data(" + xmlvariable + "/@" + MLXMLElNames::guiMaxExpr + ")}";
|
||||
}
|
||||
|
||||
QString XMLFilterInfo::enumGuiInfo( const QString& guiType,const QString& xmlvariable )
|
||||
@ -357,3 +357,24 @@ QString XMLFilterInfo::pluginName() const
|
||||
return QString();
|
||||
}
|
||||
|
||||
|
||||
bool MLXMLUtilityFunctions::getEnumNamesValuesFromString( const QString& st,QMap<int,QString>& mp )
|
||||
{
|
||||
QString cp(st);
|
||||
cp = cp.trimmed();
|
||||
QRegExp valid("Enum\\s*\\{(\\s*\\S+\\s*\\:\\s*\\d+\\s*\\|?)+\\}");
|
||||
bool res = valid.exactMatch(cp);
|
||||
QRegExp enumexp("Enum\\s*\\{");
|
||||
QRegExp spaces("\\s*");
|
||||
cp = cp.remove(enumexp).remove('}').remove(spaces);
|
||||
QRegExp extsp("\\|");
|
||||
QRegExp intsp("\\:");
|
||||
XMLFilterInfo::XMLMap xmlmp = XMLFilterInfo::mapFromString(cp,extsp,intsp);
|
||||
bool conv = true;
|
||||
for(XMLFilterInfo::XMLMap::iterator it = xmlmp.begin();it != xmlmp.end();++it)
|
||||
{
|
||||
mp.insert(it.value().toInt(&conv),it.key());
|
||||
res = conv && res;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -162,6 +162,12 @@ public:
|
||||
QStringList query(const QString& qry) const;
|
||||
};
|
||||
|
||||
class MLXMLUtilityFunctions
|
||||
{
|
||||
public:
|
||||
static bool getEnumNamesValuesFromString(const QString& st,QMap<int,QString>& mp);
|
||||
};
|
||||
|
||||
class MeshLabFilterInterface;
|
||||
|
||||
struct MeshLabXMLFilterContainer
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user