mirror of
https://github.com/lucaspalomodevelop/meshlab.git
synced 2026-03-15 00:54:38 +00:00
updated version of XML-oriented MeshLab
This commit is contained in:
parent
5242c72692
commit
bbe2bfb7be
@ -17,7 +17,7 @@ const QString& Expression::expression() const
|
||||
|
||||
QScriptValue Expression::evaluate(Env* env ) const
|
||||
{
|
||||
QScriptValue val = env->eng->evaluate(expression());
|
||||
QScriptValue val = env->evaluate(expression());
|
||||
if(val.isError())
|
||||
throw ParsingException(QString(val.toString()));
|
||||
return val;
|
||||
@ -59,6 +59,23 @@ Value* FloatExpression::eval(const QString& floatExp,Env* env )
|
||||
return new FloatValue(evaluate(env).toNumber());
|
||||
}
|
||||
|
||||
IntExpression::IntExpression() : Expression() {}
|
||||
IntExpression::IntExpression(const QString& ex) : Expression(ex) {}
|
||||
|
||||
IntExpression::~IntExpression() {}
|
||||
|
||||
Value* IntExpression::eval( Env* env ) const
|
||||
{
|
||||
return new IntValue(evaluate(env).toInt32());
|
||||
}
|
||||
|
||||
Value* IntExpression::eval(const QString& intExp,Env* env )
|
||||
{
|
||||
expression() = intExp;
|
||||
return new IntValue(evaluate(env).toInt32());
|
||||
}
|
||||
|
||||
|
||||
//FilterEnv::FilterEnv(const QMap<QString,Value*>& evalExpress)
|
||||
//:evaluatedExpressions(evalExpress)
|
||||
//{
|
||||
@ -76,9 +93,15 @@ Value* FloatExpression::eval(const QString& floatExp,Env* env )
|
||||
// return evaluatedExpressions->find(nm)->getFloat();
|
||||
//}
|
||||
//
|
||||
Env::Env( QScriptEngine* scriptEng )
|
||||
Env::Env()
|
||||
:QScriptEngine()
|
||||
{
|
||||
eng = scriptEng;
|
||||
}
|
||||
|
||||
Value* Env::insertNewFieldToVariable(const QString& var,const QString& field,Expression* exp)
|
||||
{
|
||||
QString decl(var + "." + field + " = " + exp->expression() + ";");
|
||||
return exp->eval(decl,this);
|
||||
}
|
||||
|
||||
Value* Env::insertLocalExpressionBinding( const QString& nm,Expression* exp )
|
||||
|
||||
@ -44,6 +44,16 @@ public:
|
||||
Value* eval(const QString& floatExp,Env* env);
|
||||
};
|
||||
|
||||
class IntExpression : public Expression
|
||||
{
|
||||
public:
|
||||
IntExpression();
|
||||
IntExpression(const QString& ex);
|
||||
~IntExpression();
|
||||
Value* eval(Env* env) const;
|
||||
Value* eval(const QString& intExp,Env* env);
|
||||
};
|
||||
|
||||
class FilterEnv
|
||||
{
|
||||
private:
|
||||
@ -92,21 +102,18 @@ public:
|
||||
|
||||
|
||||
|
||||
class Env
|
||||
class Env : public QScriptEngine
|
||||
{
|
||||
public:
|
||||
Env(QScriptEngine* scriptEng);
|
||||
Env();
|
||||
|
||||
//could throw a ParsingException: you should catch it in the calling code
|
||||
Value* insertLocalExpressionBinding(const QString& nm,Expression* val);
|
||||
Value* insertNewFieldToVariable(const QString& var,const QString& field,Expression* exp);
|
||||
|
||||
//Value* removeLocalValueBinding(const QString& nm);
|
||||
//Value* insertGlobalValueBinding(const QString& nm,Value* val);
|
||||
//Value* removeGlobalValueBinding(const QString& nm);
|
||||
inline void pushFrame() {eng->pushContext();};
|
||||
inline void popFrame() {eng->popContext();};
|
||||
|
||||
|
||||
QScriptEngine* eng;
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -7,7 +7,7 @@
|
||||
|
||||
|
||||
PluginManager::PluginManager()
|
||||
:eng(),env(&eng)
|
||||
:env()
|
||||
{
|
||||
//pluginsDir=QDir(getPluginDirPath());
|
||||
// without adding the correct library path in the mac the loading of jpg (done via qt plugins) fails
|
||||
@ -137,13 +137,13 @@ void PluginManager::loadPlugins(RichParameterSet& defaultGlobal)
|
||||
}
|
||||
}
|
||||
|
||||
QScriptValue initFun = eng.newFunction(PluginInterfaceInit, this);
|
||||
eng.globalObject().setProperty("_initParameterSet", initFun);
|
||||
QScriptValue initFun = env.newFunction(PluginInterfaceInit, this);
|
||||
env.globalObject().setProperty("_initParameterSet", initFun);
|
||||
|
||||
QScriptValue applyFun = eng.newFunction(PluginInterfaceApply, this);
|
||||
eng.globalObject().setProperty("_applyFilter", applyFun);
|
||||
QScriptValue applyFun = env.newFunction(PluginInterfaceApply, this);
|
||||
env.globalObject().setProperty("_applyFilter", applyFun);
|
||||
|
||||
eng.evaluate(code);
|
||||
env.evaluate(code);
|
||||
qDebug("Code:\n %s",qPrintable(code));
|
||||
}
|
||||
/*
|
||||
@ -250,3 +250,26 @@ void PluginManager::LoadFormats(QStringList &filters, QHash<QString, MeshIOInter
|
||||
allKnownFormatsFilter.append(')');
|
||||
filters.push_front(allKnownFormatsFilter);
|
||||
}
|
||||
|
||||
void PluginManager::updateDocumentScriptBindings(MeshDocument& doc )
|
||||
{
|
||||
QScriptValue val = env.newQObject(&doc);
|
||||
env.globalObject().setProperty(meshDocVarName(),val);
|
||||
if (doc.mm() != NULL)
|
||||
updateMeshScriptBindings(doc,doc.mm()->id());
|
||||
|
||||
}
|
||||
|
||||
void PluginManager::updateMeshScriptBindings(MeshDocument& doc,const int id)
|
||||
{
|
||||
IntExpression meshInd(QString::number(id));
|
||||
env.insertNewFieldToVariable(meshDocVarName(),currentMeshVarName(),&meshInd);
|
||||
FloatExpression bboxDiag(QString::number(0.0f));
|
||||
MeshModel* model = doc.getMesh(id);
|
||||
if (model != NULL)
|
||||
bboxDiag.expression() = QString::number(model->cm.bbox.Diag());
|
||||
|
||||
Value* val = env.insertNewFieldToVariable(meshDocVarName() + "." + currentMeshVarName(),QString("bboxDiag"),&bboxDiag);
|
||||
QString st(meshDocVarName() + "." + currentMeshVarName() + ".bboxDiag");
|
||||
env.evaluate("print(" + st + ");");
|
||||
}
|
||||
@ -73,8 +73,13 @@ public:
|
||||
|
||||
QStringList pluginsLoaded;
|
||||
|
||||
QScriptEngine eng;
|
||||
Env env;
|
||||
|
||||
inline static const QString meshDocVarName() {return QString("meshDocument");}
|
||||
inline static const QString currentMeshVarName() {return QString("current");}
|
||||
|
||||
void updateDocumentScriptBindings(MeshDocument& doc);
|
||||
void updateMeshScriptBindings(MeshDocument& doc,const int id);
|
||||
};
|
||||
|
||||
#endif // PLUGINMANAGER_H
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user