updated scriptinterface to avoid crash

This commit is contained in:
Guido Ranzuglia granzuglia 2011-02-01 08:06:09 +00:00
parent f11022c1a0
commit 8d47fd12ba
3 changed files with 21 additions and 6 deletions

View File

@ -1,6 +1,8 @@
#ifndef ML_EXCEPTION
#define ML_EXCEPTION
#include <exception>
class MeshLabException : public std::exception
{
public:

View File

@ -46,12 +46,12 @@ QScriptValue PluginInterfaceInit(QScriptContext *context, QScriptEngine *engine,
return false;
}
MeshDocument* md = qscriptvalue_cast<MeshDocument*>(engine->globalObject().property("md"));
MeshDocumentScriptInterface* md = qscriptvalue_cast<MeshDocumentScriptInterface*>(engine->globalObject().property(PluginManager::meshDocVarName()));
RichParameterSet* rps = qscriptvalue_cast<RichParameterSet*>(context->argument(1));
MeshFilterInterface * mi = it.value();
QAction act(filterName, NULL);
mi->initParameterSet(&act, *(md->mm()), *rps);
mi->initParameterSet(&act, (md->current()->mm), *rps);
return true;
}
@ -66,12 +66,12 @@ QScriptValue PluginInterfaceApply(QScriptContext *context, QScriptEngine *engine
return false;
}
MeshDocument* md = qscriptvalue_cast<MeshDocument*>(engine->globalObject().property("md"));
MeshDocumentScriptInterface* md = qscriptvalue_cast<MeshDocumentScriptInterface*>(engine->globalObject().property(PluginManager::meshDocVarName()));
RichParameterSet* rps = qscriptvalue_cast<RichParameterSet*>(context->argument(1));
MeshFilterInterface * mi = it.value();
QAction act(filterName, NULL);
const bool res = mi->applyFilter(&act, *md, *rps, TestCallback);
const bool res = mi->applyFilter(&act, *(md->md), *rps, TestCallback);
return res;
}
@ -171,6 +171,16 @@ void MeshModelScriptInterfaceFromScriptValue(const QScriptValue& val,MeshModelSc
out = qobject_cast<MeshModelScriptInterface*>(val.toQObject());
}
QScriptValue MeshDocumentScriptInterfaceToScriptValue( QScriptEngine* eng,MeshDocumentScriptInterface* const& in )
{
return eng->newQObject(in);
}
void MeshDocumentScriptInterfaceFromScriptValue( const QScriptValue& val,MeshDocumentScriptInterface*& out )
{
out = qobject_cast<MeshDocumentScriptInterface*>(val.toQObject());
}
MeshDocumentScriptInterface::MeshDocumentScriptInterface( MeshDocument* doc )
:QObject(doc),md(doc)
{

View File

@ -63,7 +63,6 @@ public:
Q_INVOKABLE MeshModelScriptInterface* getMesh(const int meshId);
Q_INVOKABLE MeshModelScriptInterface* current();
private:
MeshDocument* md;
};
@ -76,10 +75,14 @@ public:
Q_INVOKABLE float bboxDiag() const;
private:
MeshModel& mm;
};
Q_DECLARE_METATYPE(MeshDocumentScriptInterface*)
QScriptValue MeshDocumentScriptInterfaceToScriptValue(QScriptEngine* eng,MeshDocumentScriptInterface* const& in);
void MeshDocumentScriptInterfaceFromScriptValue(const QScriptValue& val,MeshDocumentScriptInterface*& out);
Q_DECLARE_METATYPE(MeshModelScriptInterface*)
QScriptValue MeshModelScriptInterfaceToScriptValue(QScriptEngine* eng,MeshModelScriptInterface* const& in);