示例#1
0
void Env::insertExpressionBinding( const QString& nm,const QString& exp )
{
	QString decl("var " + nm + " = " + exp + ";");
	QScriptValue res = evaluate(decl);
	if	(res.isError())
		throw JavaScriptException(res.toString());
}
示例#2
0
void FilterThread::run()
{
    try
    {
        Env env;
        QScriptValue val = env.loadMLScriptEnv(_md,_pm);
        if (val.isError())
            throw JavaScriptException("A Plugin-bridge-code generated a JavaScript Error: " + val.toString() + "\n");

        QMap<QString,MeshLabXMLFilterContainer>::iterator it =_pm.stringXMLFilterMap.find(_fname);
        if ((it == _pm.stringXMLFilterMap.end()) || (it->xmlInfo == NULL))
            throw MeshLabException("Filter " + _fname + " has not been found.\n");
        if (it->filterInterface != NULL)
        {

            it->filterInterface->glContext = new QGLContext(QGLFormat::defaultFormat(),_glwid->context()->device());
            it->filterInterface->glContext->create(_glwid->context());
            for (QMap<QString,QString>::const_iterator itp = _parexpval.constBegin();itp != _parexpval.constEnd();++itp)
                env.insertExpressionBinding(itp.key(),itp.value());
            EnvWrap envwrap(env);
            _cur = this;
            _success = it->filterInterface->applyFilter(_fname, _md, envwrap, &localCallBack);
            _cur = NULL;

            delete it->filterInterface->glContext;
        }
        else
            throw MeshLabException("There is not yet support for not-C++ filters.");
    }
    catch (MeshLabException& e)
    {
        _md.Log.Log(GLLogStream::SYSTEM,e.what());
    }
}
void PluginGeneratorGUI::executeCurrentCode()
{
	Env env;
	if (doc != NULL)
	{
		QScriptValue res = env.loadMLScriptEnv(*doc,PM);
		if (res.isError())
			throw JavaScriptException("A Plugin-bridge-code generated a JavaScript Error: " + res.toString() + "\n");
		FilterGeneratorTab* ftab = tab(tabs->currentIndex());
		if (ftab != NULL)
		{
			QTime t;
			t.start();
			QScriptValue result = env.evaluate(ftab->getCode());
			int time = t.elapsed();
			emit scriptCodeExecuted(result,time,env.output());
		}
		else
			throw MeshLabException("System Error: A FilterGeneratorTab object has been expected.");
	}
	else
		throw MeshLabException("System Error: A valid MeshLabDocument has not correctly been associated with PluginGeneratorGUI. Code cannot be executed.");
}