From 97fed783fa3dd9bbbf8451983d5ff1afabc02f2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20M=C3=B6bius?= Date: Wed, 10 Feb 2010 09:01:19 +0000 Subject: [PATCH] Made DataType available in scripting git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@8511 383ad7c9-94d9-4d36-a494-682f7c89f535 --- Core/Core.cc | 11 +- Core/Core.hh | 7 +- .../scriptPrototypes/prototypeDataType.cc | 63 +++++++++++ .../scriptPrototypes/prototypeDataType.hh | 65 +++++++++++ Scripting/scriptWrappers/DataTypeWrapper.cc | 106 ++++++++++++++++++ Scripting/scriptWrappers/DataTypeWrapper.hh | 70 ++++++++++++ common/DataTypes.hh | 1 + 7 files changed, 321 insertions(+), 2 deletions(-) create mode 100644 Scripting/scriptPrototypes/prototypeDataType.cc create mode 100644 Scripting/scriptPrototypes/prototypeDataType.hh create mode 100644 Scripting/scriptWrappers/DataTypeWrapper.cc create mode 100644 Scripting/scriptWrappers/DataTypeWrapper.hh diff --git a/Core/Core.cc b/Core/Core.cc index 7c83a270..2f4c8c66 100644 --- a/Core/Core.cc +++ b/Core/Core.cc @@ -436,9 +436,18 @@ Core::init() { // Register IdList Type to scripting Engine qScriptRegisterSequenceMetaType< IdList >(&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 ) qScriptRegisterMetaType(&scriptEngine_, diff --git a/Core/Core.hh b/Core/Core.hh index c763b355..7e95ce94 100644 --- a/Core/Core.hh +++ b/Core/Core.hh @@ -84,8 +84,10 @@ // Prototypes for scripting #include "OpenFlipper/Scripting/scriptPrototypes/prototypeVec3d.hh" #include "OpenFlipper/Scripting/scriptPrototypes/prototypeMatrix4x4.hh" +#include "OpenFlipper/Scripting/scriptPrototypes/prototypeDataType.hh" #include #include +#include // #include // Required Interface definition ( Some variables were defined there ) @@ -865,8 +867,11 @@ private slots: /// Prototype for the Vector type prototypeVec3d vec3dPrototype_; + + /// Prototype for the DataType + prototypeDataType DataTypePrototype_; - /// Prototype for the Vector type + /// Prototype for the Matrix type prototypeMatrix4x4 matrix4x4Prototype_; diff --git a/Scripting/scriptPrototypes/prototypeDataType.cc b/Scripting/scriptPrototypes/prototypeDataType.cc new file mode 100644 index 00000000..3004231c --- /dev/null +++ b/Scripting/scriptPrototypes/prototypeDataType.cc @@ -0,0 +1,63 @@ +/*===========================================================================*\ + * * + * 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 . * + * * +\*===========================================================================*/ + +/*===========================================================================*\ + * * + * $Revision: 6727 $ * + * $Author: moebius $ * + * $Date: 2009-08-05 08:03:50 +0200 (Mi, 05. Aug 2009) $ * + * * +\*===========================================================================*/ + + +#include "prototypeDataType.hh" +#include + +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); +} + + diff --git a/Scripting/scriptPrototypes/prototypeDataType.hh b/Scripting/scriptPrototypes/prototypeDataType.hh new file mode 100644 index 00000000..0b1dcdb9 --- /dev/null +++ b/Scripting/scriptPrototypes/prototypeDataType.hh @@ -0,0 +1,65 @@ +/*===========================================================================*\ + * * + * 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 . * + * * +\*===========================================================================*/ + +/*===========================================================================*\ + * * + * $Revision: 6727 $ * + * $Author: moebius $ * + * $Date: 2009-08-05 08:03:50 +0200 (Mi, 05. Aug 2009) $ * + * * +\*===========================================================================*/ + + + +#ifndef PROTOTYPEDATATYPE_HH +#define PROTOTYPEDATATYPE_HH + + +#include +#include + +class prototypeDataType : public QObject , public QScriptable +{ + Q_OBJECT + + public: + prototypeDataType(QObject *parent = 0); + + public Q_SLOTS: + QString toString() const; + +}; + + +#endif // PROTOTYPEDATATYPE_HH diff --git a/Scripting/scriptWrappers/DataTypeWrapper.cc b/Scripting/scriptWrappers/DataTypeWrapper.cc new file mode 100644 index 00000000..95c2bcd4 --- /dev/null +++ b/Scripting/scriptWrappers/DataTypeWrapper.cc @@ -0,0 +1,106 @@ +/*===========================================================================*\ + * * + * 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 . * + * * +\*===========================================================================*/ + +/*===========================================================================*\ + * * + * $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) ); +} + +//============================================================================= + diff --git a/Scripting/scriptWrappers/DataTypeWrapper.hh b/Scripting/scriptWrappers/DataTypeWrapper.hh new file mode 100644 index 00000000..5a920b5f --- /dev/null +++ b/Scripting/scriptWrappers/DataTypeWrapper.hh @@ -0,0 +1,70 @@ +/*===========================================================================*\ + * * + * 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 . * + * * +\*===========================================================================*/ + +/*===========================================================================*\ + * * + * $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 + +//=========================================================================== +/** @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 diff --git a/common/DataTypes.hh b/common/DataTypes.hh index ba4a8393..31c0dfca 100644 --- a/common/DataTypes.hh +++ b/common/DataTypes.hh @@ -99,6 +99,7 @@ typedef std::vector< int > IdList; typedef ACG::Matrix4x4d Matrix4x4; Q_DECLARE_METATYPE(IdList); +Q_DECLARE_METATYPE(DataType); Q_DECLARE_METATYPE(QVector< int >); Q_DECLARE_METATYPE(Vector); Q_DECLARE_METATYPE(Matrix4x4); -- GitLab