Commit 97fed783 authored by Jan Möbius's avatar Jan Möbius

Made DataType available in scripting

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@8511 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 36afa0b2
...@@ -436,9 +436,18 @@ Core::init() { ...@@ -436,9 +436,18 @@ Core::init() {
// Register IdList Type to scripting Engine // Register IdList Type to scripting Engine
qScriptRegisterSequenceMetaType< IdList >(&scriptEngine_); qScriptRegisterSequenceMetaType< IdList >(&scriptEngine_);
qScriptRegisterSequenceMetaType< QVector< int > >(&scriptEngine_); qScriptRegisterSequenceMetaType< QVector< int > >(&scriptEngine_);
// Register DataType in QScriptEngine
qScriptRegisterMetaType(&scriptEngine_,
toScriptValueDataType,
fromScriptValueDataType,
scriptEngine_.newQObject(&DataTypePrototype_));
// set a constructor to allow creation via DataType(uint)
QScriptValue dataType = scriptEngine_.newFunction(createDataType);
scriptEngine_.globalObject().setProperty("DataType", dataType);
// Register Matrix Type to scripting Engine ( is ACG::Matrix4x4d ) // Register Matrix Type to scripting Engine ( is ACG::Matrix4x4d )
qScriptRegisterMetaType(&scriptEngine_, qScriptRegisterMetaType(&scriptEngine_,
......
...@@ -84,8 +84,10 @@ ...@@ -84,8 +84,10 @@
// Prototypes for scripting // Prototypes for scripting
#include "OpenFlipper/Scripting/scriptPrototypes/prototypeVec3d.hh" #include "OpenFlipper/Scripting/scriptPrototypes/prototypeVec3d.hh"
#include "OpenFlipper/Scripting/scriptPrototypes/prototypeMatrix4x4.hh" #include "OpenFlipper/Scripting/scriptPrototypes/prototypeMatrix4x4.hh"
#include "OpenFlipper/Scripting/scriptPrototypes/prototypeDataType.hh"
#include <OpenFlipper/Scripting/scriptWrappers/vec3dWrapper.hh> #include <OpenFlipper/Scripting/scriptWrappers/vec3dWrapper.hh>
#include <OpenFlipper/Scripting/scriptWrappers/matrix4x4Wrapper.hh> #include <OpenFlipper/Scripting/scriptWrappers/matrix4x4Wrapper.hh>
#include <OpenFlipper/Scripting/scriptWrappers/DataTypeWrapper.hh>
// #include <OpenFlipper/Scripting/scriptWrappers/ObjectIdWrapper.hh> // #include <OpenFlipper/Scripting/scriptWrappers/ObjectIdWrapper.hh>
// Required Interface definition ( Some variables were defined there ) // Required Interface definition ( Some variables were defined there )
...@@ -865,8 +867,11 @@ private slots: ...@@ -865,8 +867,11 @@ private slots:
/// Prototype for the Vector type /// Prototype for the Vector type
prototypeVec3d vec3dPrototype_; prototypeVec3d vec3dPrototype_;
/// Prototype for the DataType
prototypeDataType DataTypePrototype_;
/// Prototype for the Vector type /// Prototype for the Matrix type
prototypeMatrix4x4 matrix4x4Prototype_; prototypeMatrix4x4 matrix4x4Prototype_;
......
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision: 6727 $ *
* $Author: moebius $ *
* $Date: 2009-08-05 08:03:50 +0200 (Mi, 05. Aug 2009) $ *
* *
\*===========================================================================*/
#include "prototypeDataType.hh"
#include <OpenFlipper/common/Types.hh>
prototypeDataType::prototypeDataType(QObject *parent ) :
QObject(parent)
{
std::cerr << "Prototype cnstructor" << std::endl;
}
QString prototypeDataType::toString() const {
DataType s = thisObject().property("type").toNumber();
std::cerr << "Prototype to String " << s << std::endl;
std::cerr << "String is : " << typeName(s).toStdString() << std::endl;
return typeName(s);
}
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision: 6727 $ *
* $Author: moebius $ *
* $Date: 2009-08-05 08:03:50 +0200 (Mi, 05. Aug 2009) $ *
* *
\*===========================================================================*/
#ifndef PROTOTYPEDATATYPE_HH
#define PROTOTYPEDATATYPE_HH
#include <QtCore/QObject>
#include <QtScript/QtScript>
class prototypeDataType : public QObject , public QScriptable
{
Q_OBJECT
public:
prototypeDataType(QObject *parent = 0);
public Q_SLOTS:
QString toString() const;
};
#endif // PROTOTYPEDATATYPE_HH
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision: 7874 $ *
* $Author: moebius $ *
* $Date: 2009-12-14 16:08:50 +0100 (Mo, 14. Dez 2009) $ *
* *
\*===========================================================================*/
//=============================================================================
//
// Wrapper for IdList ( std::vector< int > ) - IMPLEMENTATION
//
//=============================================================================
//== INCLUDES =================================================================
#include "DataTypeWrapper.hh"
//== IMPLEMENTATION ==========================================================
QScriptValue toScriptValueDataType(QScriptEngine *engine, const DataType &s)
{
QScriptValue obj = engine->newObject();
obj.setProperty("type", QScriptValue(engine, s ));
std::cerr << "toScriptValueDataType " << s << std::endl;
return obj;
}
void fromScriptValueDataType(const QScriptValue &obj, DataType &s)
{
s = obj.property("type").toNumber();
std::cerr << "fromScriptValueDataType " << s << std::endl;
}
QScriptValue createDataType(QScriptContext *context, QScriptEngine *engine)
{
std::cerr << "createDataType " << std::endl;
DataType s;
QScriptValue callee = context->callee();
// If arguments are given, use them for initialization otherwise
// initialize with 0
if (context->argumentCount() == 1) {
s = context->argument(0).toNumber();
} else {
s = DATA_UNKNOWN;
}
std::cerr << "s set to " << s << std::endl;
return engine->toScriptValue( s );
}
QScriptValue DataTypeToString(QScriptContext *context, QScriptEngine *engine)
{
DataType s = context->thisObject().property("type").toNumber();
std::cerr << "DataTypeToString " << s << std::endl;
std::cerr << "DataTypeToString " << typeName(s).toStdString() << std::endl;
return QScriptValue(engine, typeName(s) );
}
//=============================================================================
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision: 7874 $ *
* $Author: moebius $ *
* $Date: 2009-12-14 16:08:50 +0100 (Mo, 14. Dez 2009) $ *
* *
\*===========================================================================*/
#ifndef WRAPPERDATATTYPE_HH
#define WRAPPERDATATTYPE_HH
#include "OpenFlipper/common/Types.hh"
#include <QtScript/QtScript>
//===========================================================================
/** @name Script Wrappers for DataType Type
* @{ */
//===========================================================================
/// Convert IdList to scriptvalue
QScriptValue toScriptValueDataType(QScriptEngine *engine, const DataType &s);
/// Convert scriptvalue to IdList
void fromScriptValueDataType(const QScriptValue &obj, DataType &s);
/// Create an empty IdList in Scripting environment
QScriptValue createDataType(QScriptContext *, QScriptEngine *engine);
QScriptValue DataTypeToString(QScriptContext *context, QScriptEngine *engine);
/** @} */
#endif // WRAPPERDATATTYPE_HH
...@@ -99,6 +99,7 @@ typedef std::vector< int > IdList; ...@@ -99,6 +99,7 @@ typedef std::vector< int > IdList;
typedef ACG::Matrix4x4d Matrix4x4; typedef ACG::Matrix4x4d Matrix4x4;
Q_DECLARE_METATYPE(IdList); Q_DECLARE_METATYPE(IdList);
Q_DECLARE_METATYPE(DataType);
Q_DECLARE_METATYPE(QVector< int >); Q_DECLARE_METATYPE(QVector< int >);
Q_DECLARE_METATYPE(Vector); Q_DECLARE_METATYPE(Vector);
Q_DECLARE_METATYPE(Matrix4x4); Q_DECLARE_METATYPE(Matrix4x4);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment