From 8d47fd12baee8be6958d59dffca545ad1ff6a52a Mon Sep 17 00:00:00 2001 From: Guido Ranzuglia granzuglia Date: Tue, 1 Feb 2011 08:06:09 +0000 Subject: [PATCH] updated scriptinterface to avoid crash --- src/common/mlexception.h | 2 ++ src/common/scriptinterface.cpp | 18 ++++++++++++++---- src/common/scriptinterface.h | 7 +++++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/common/mlexception.h b/src/common/mlexception.h index 2c452f4d2..a4362a02b 100644 --- a/src/common/mlexception.h +++ b/src/common/mlexception.h @@ -1,6 +1,8 @@ #ifndef ML_EXCEPTION #define ML_EXCEPTION +#include + class MeshLabException : public std::exception { public: diff --git a/src/common/scriptinterface.cpp b/src/common/scriptinterface.cpp index c4c55251f..e45af11d3 100644 --- a/src/common/scriptinterface.cpp +++ b/src/common/scriptinterface.cpp @@ -46,12 +46,12 @@ QScriptValue PluginInterfaceInit(QScriptContext *context, QScriptEngine *engine, return false; } - MeshDocument* md = qscriptvalue_cast(engine->globalObject().property("md")); + MeshDocumentScriptInterface* md = qscriptvalue_cast(engine->globalObject().property(PluginManager::meshDocVarName())); RichParameterSet* rps = qscriptvalue_cast(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(engine->globalObject().property("md")); + MeshDocumentScriptInterface* md = qscriptvalue_cast(engine->globalObject().property(PluginManager::meshDocVarName())); RichParameterSet* rps = qscriptvalue_cast(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(val.toQObject()); } +QScriptValue MeshDocumentScriptInterfaceToScriptValue( QScriptEngine* eng,MeshDocumentScriptInterface* const& in ) +{ + return eng->newQObject(in); +} + +void MeshDocumentScriptInterfaceFromScriptValue( const QScriptValue& val,MeshDocumentScriptInterface*& out ) +{ + out = qobject_cast(val.toQObject()); +} + MeshDocumentScriptInterface::MeshDocumentScriptInterface( MeshDocument* doc ) :QObject(doc),md(doc) { diff --git a/src/common/scriptinterface.h b/src/common/scriptinterface.h index 3c10b8ee0..f27a38a09 100644 --- a/src/common/scriptinterface.h +++ b/src/common/scriptinterface.h @@ -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);