first code sketch to support scripting engine

This commit is contained in:
Guido Ranzuglia granzuglia 2010-08-20 08:52:50 +00:00
parent 766c3faccf
commit e4c25bb0bb
6 changed files with 114 additions and 22 deletions

View File

@ -24,6 +24,7 @@
#include <QFileDialog>
#include "ui_filterScriptDialog.h"
#include "ui_scriptEditor.h"
#include "filterScriptDialog.h"
#include "mainwindow.h"
@ -235,3 +236,41 @@ FilterScriptDialog::~FilterScriptDialog()
}
EditorScriptDialog::EditorScriptDialog( QWidget *parent /*= 0*/ )
:code()
{
ui = new Ui::scriptEditor();
EditorScriptDialog::ui->setupUi(this);
connect(ui->okButton, SIGNAL(clicked()), this, SLOT(applyScript()));
connect(ui->saveScriptButton, SIGNAL(clicked()), this, SLOT(saveScript()));
connect(ui->openScriptButton, SIGNAL(clicked()), this, SLOT(openScript()));
}
EditorScriptDialog::~EditorScriptDialog()
{
delete ui;
}
void EditorScriptDialog::applyScript()
{
code.clear();
code = ui->textEditor->toPlainText();
accept();
}
void EditorScriptDialog::saveScript()
{
}
void EditorScriptDialog::openScript()
{
}
const QString& EditorScriptDialog::scriptCode() const
{
return code;
}

View File

@ -26,6 +26,7 @@
namespace Ui
{
class scriptDialog;
class scriptEditor;
}
class FilterScriptDialog : public QDialog
@ -62,3 +63,20 @@ private:
FilterScript *scriptPtr;
};
class EditorScriptDialog : public QDialog
{
Q_OBJECT
public:
EditorScriptDialog(QWidget *parent = 0);
~EditorScriptDialog();
private slots:
void applyScript();
void saveScript();
void openScript();
public:
const QString& scriptCode() const;
private:
Ui::scriptEditor* ui;
QString code;
};

View File

@ -27,6 +27,7 @@
//None of this should happen if we are compiling c, not c++
#ifdef __cplusplus
#include <GL/glew.h>
#include <QtScript\QtScript>
#include <QDir>
#include <QMainWindow>
@ -93,6 +94,7 @@ private slots:
void applyLastFilter();
void runFilterScript();
void showFilterScript();
void showScriptEditor();
void showTooltip(QAction*);
/////////// Slot Menu Render /////////////////////
void renderBbox();
@ -185,6 +187,13 @@ private:
LayerDialog *layerDialog;
QSignalMapper *windowMapper;
/******************************************************************REMOVE IT!!!!************************************************/
QScriptEngine eng;
/******************************************************************REMOVE IT!!!!************************************************/
PluginManager PM;
/*
@ -304,6 +313,7 @@ private:
QAction *lastFilterAct;
QAction *runFilterScriptAct;
QAction *showFilterScriptAct;
QAction* showScriptEditAct;
QAction *recentFileActs[MAXRECENTFILES];
QAction *separatorAct;
QAction *exitAct;

View File

@ -64,7 +64,7 @@ MainWindow::MainWindow()
icon.addPixmap(QPixmap(":images/eye48.png"));
setWindowIcon(icon);
PM.loadPlugins(defaultGlobalParams);
PM.loadPlugins(defaultGlobalParams,&eng);
// Now load from the registry the settings and merge the hardwired values got from the PM.loadPlugins with the ones found in the registry.
loadMeshLabSettings();
createActions();
@ -318,6 +318,10 @@ void MainWindow::createActions()
showFilterScriptAct->setEnabled(true);
connect(showFilterScriptAct, SIGNAL(triggered()), this, SLOT(showFilterScript()));
showScriptEditAct = new QAction(tr("Script Editor"),this);
showScriptEditAct->setEnabled(true);
connect(showScriptEditAct, SIGNAL(triggered()), this, SLOT(showScriptEditor()));
//////////////Action Menu Preferences /////////////////////////////////////////////////////////////////////
setCustomizeAct = new QAction(tr("&Options..."),this);
connect(setCustomizeAct, SIGNAL(triggered()), this, SLOT(setCustomize()));
@ -430,6 +434,7 @@ void MainWindow::createMenus()
filterMenu = menuBar()->addMenu(tr("Fi&lters"));
filterMenu->addAction(lastFilterAct);
filterMenu->addAction(showFilterScriptAct);
filterMenu->addAction(showScriptEditAct);
filterMenu->addSeparator();
filterMenuSelect = filterMenu->addMenu(tr("Selection"));
filterMenuClean = filterMenu->addMenu(tr("Cleaning and Repairing"));

View File

@ -587,6 +587,24 @@ void MainWindow::showFilterScript()
}
void MainWindow::showScriptEditor()
{
EditorScriptDialog dialog(this);
if (dialog.exec()==QDialog::Accepted)
{
QScriptValue val = eng.newQObject(meshDoc());
eng.globalObject().setProperty("md",val);
QScriptValue result = eng.evaluate(dialog.scriptCode());
if (result.isError())
{
meshDoc()->Log.Logf(GLLogStream::SYSTEM,"Interpreter Error: line %i: %s",result.property("lineNumber").toInt32(),qPrintable(result.toString()));
layerDialog->updateLog(meshDoc()->Log);
}
else
this->updateGL();
}
}
void MainWindow::runFilterScript()
{
FilterScript::iterator ii;
@ -940,24 +958,6 @@ void MainWindow::applyDecorateMode()
}
bool MainWindow::QCallBack(const int pos, const char * str)
{
int static lastPos=-1;
if(pos==lastPos) return true;
lastPos=pos;
static QTime currTime;
if(currTime.elapsed()< 100) return true;
currTime.start();
MainWindow::globalStatusBar()->showMessage(str,5000);
qb->show();
qb->setEnabled(true);
qb->setValue(pos);
MainWindow::globalStatusBar()->update();
qApp->processEvents();
return true;
}
void MainWindow::setLight()
{
GLA()->setLight(!GLA()->getCurrentRenderMode().lighting);
@ -1087,11 +1087,10 @@ bool MainWindow::open(QString fileName, GLArea *gla)
{
// Opening files in a transparent form (IO plugins contribution is hidden to user)
QStringList filters;
// HashTable storing all supported formats together with
// the (1-based) index of first plugin which is able to open it
QHash<QString, MeshIOInterface*> allKnownFormats;
PM.LoadFormats(filters, allKnownFormats,PluginManager::IMPORT);
filters.push_back("ALN project ( *.aln)");
filters.front().chop(1);
@ -1496,3 +1495,21 @@ void MainWindow::keyPressEvent(QKeyEvent *e)
}
else e->ignore();
}
bool MainWindow::QCallBack(const int pos, const char * str)
{
int static lastPos=-1;
if(pos==lastPos) return true;
lastPos=pos;
static QTime currTime;
if(currTime.elapsed()< 100) return true;
currTime.start();
MainWindow::globalStatusBar()->showMessage(str,5000);
qb->show();
qb->setEnabled(true);
qb->setValue(pos);
MainWindow::globalStatusBar()->update();
qApp->processEvents();
return true;
}

View File

@ -52,7 +52,8 @@ FORMS = ui/layerDialog.ui \
ui/aboutDialog.ui \
ui/renametexture.ui \
ui/savemaskexporter.ui \
ui/congratsDialog.ui
ui/congratsDialog.ui \
ui/scriptEditor.ui
RESOURCES = meshlab.qrc
# to add windows icon
@ -71,6 +72,8 @@ ICON = images/meshlab.icns
QT += opengl
QT += xml
QT += network
QT += script
# the following line is needed to avoid mismatch between
# the awful min/max macros of windows and the limits max