From 42bb7215bcc504c7b744469b5042753e1b4aefaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20M=C3=B6bius?= Date: Mon, 11 Mar 2013 07:35:31 +0000 Subject: [PATCH] Added Vector 4 data type git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@16499 383ad7c9-94d9-4d36-a494-682f7c89f535 --- parser/context.cc | 4 +- types/vec4d.cc | 81 ++++++++++++++++++ types/vec4d.hh | 74 +++++++++++++++++ types/vec4dWidget.cc | 193 +++++++++++++++++++++++++++++++++++++++++++ types/vec4dWidget.hh | 93 +++++++++++++++++++++ 5 files changed, 444 insertions(+), 1 deletion(-) create mode 100644 types/vec4d.cc create mode 100644 types/vec4d.hh create mode 100644 types/vec4dWidget.cc create mode 100644 types/vec4dWidget.hh diff --git a/parser/context.cc b/parser/context.cc index 148a569..3125b88 100644 --- a/parser/context.cc +++ b/parser/context.cc @@ -61,6 +61,7 @@ #include "types/filename.hh" #include "types/selection.hh" #include "types/vec3d.hh" +#include "types/vec4d.hh" #include "types/matrix4x4.hh" #include "types/objectId/objectId.hh" #include "types/any.hh" @@ -124,6 +125,7 @@ Context::Context (QScriptEngine *_engine) : registerType (new TypeFilename ()); registerType (new TypeSelection ()); registerType (new TypeVec3D ()); + registerType (new TypeVec4D ()); registerType (new TypeMatrix4x4 ()); registerType (new TypeObjectId ()); registerType (new TypeAny ()); @@ -597,4 +599,4 @@ Type * Context::getType(QString _type) //------------------------------------------------------------------------------ -} \ No newline at end of file +} diff --git a/types/vec4d.cc b/types/vec4d.cc new file mode 100644 index 0000000..654a73e --- /dev/null +++ b/types/vec4d.cc @@ -0,0 +1,81 @@ +/*===========================================================================*\ +* * +* OpenFlipper * +* Copyright (C) 2001-2011 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: 10745 $ * +* $LastChangedBy: moebius $ * +* $Date: 2011-01-26 10:23:50 +0100 (Mi, 26. Jan 2011) $ * +* * +\*===========================================================================*/ + +//== INCLUDES ================================================================= +#include "vec4d.hh" +#include "vec4dWidget.hh" + +//== NAMESPACES =============================================================== +namespace VSI { + +//============================================================================= +// +// CLASS VSI::TypeVec3D - IMPLEMENTATION +// +//============================================================================= + +/// Constructor +TypeVec4D::TypeVec4D() +{ + types_ << "Vector4" << "Vec4D" << "Vec4d" << "vec4d"; + + hints_ << "default"; +} + +//------------------------------------------------------------------------------ + +/// Has configuration widget +bool TypeVec4D::hasWidget() +{ + return true; +} + +//------------------------------------------------------------------------------ + +/// Return configuration widget +TypeWidget * TypeVec4D::widget(QMap< QString, QString > _hints, QString _typeName, QWidget *_parent) +{ + return new Vec4DWidget (_hints, _typeName, _parent); +} + +//------------------------------------------------------------------------------ +} diff --git a/types/vec4d.hh b/types/vec4d.hh new file mode 100644 index 0000000..35ef53c --- /dev/null +++ b/types/vec4d.hh @@ -0,0 +1,74 @@ +/*===========================================================================*\ +* * +* OpenFlipper * +* Copyright (C) 2001-2011 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: 13386 $ * +* $LastChangedBy: moebius $ * +* $Date: 2012-01-13 12:21:45 +0100 (Fr, 13 Jan 2012) $ * +* * +\*===========================================================================*/ + +#ifndef VSI_VEC4D_HH +#define VSI_VEC4D_HH + +//== INCLUDES ================================================================= +#include "../parser/type.hh" + +//== NAMESPACES =============================================================== +namespace VSI { + +//== CLASS DEFINITION ========================================================= + +/** 4D Vector visual scripting type class + */ + +class TypeVec4D : public Type { + public: + + /// Constructor + TypeVec4D (); + + /// Has configuration widget + bool hasWidget (); + + /// Returns configuration widget + TypeWidget *widget (QMap _hints, QString _typeName, QWidget *_parent = NULL); +}; + +//============================================================================= +} +//============================================================================= + +#endif diff --git a/types/vec4dWidget.cc b/types/vec4dWidget.cc new file mode 100644 index 0000000..3fd546c --- /dev/null +++ b/types/vec4dWidget.cc @@ -0,0 +1,193 @@ +/*===========================================================================*\ +* * +* OpenFlipper * +* Copyright (C) 2001-2011 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: 10745 $ * +* $LastChangedBy: moebius $ * +* $Date: 2011-01-26 10:23:50 +0100 (Mi, 26. Jan 2011) $ * +* * +\*===========================================================================*/ + +//== INCLUDES ================================================================= +#include +#include +#include + +#include "vec4dWidget.hh" + +//== NAMESPACES =============================================================== +namespace VSI { + +//============================================================================= +// +// CLASS VSI::Vec3DWidget - IMPLEMENTATION +// +//============================================================================= + +/// Constructor +Vec4DWidget::Vec4DWidget(QMap< QString, QString > &_hints, QString _typeName, QWidget *_parent) : + TypeWidget (_hints, _typeName, _parent) +{ + bool ok; + + QHBoxLayout *hL = new QHBoxLayout; + + for (int i = 0; i < 4; i++) + default_[i] = 0.0; + + ok = true; + if (_hints.contains ("default")) + { + QStringList sl = _hints["default"].split (','); + + if (sl.length () == 4) + { + for (int i = 0; i < 4 && ok; i++) + default_[i] = sl[i].toFloat (&ok); + + if (!ok) + for (int i = 0; i < 4; i++) + default_[i] = 0.0; + } + } + + for (int i = 0; i < 4; i++) + fields_[i] = new QLineEdit; + + hL->addWidget (new QLabel ("(")); + hL->addWidget (fields_[0]); + hL->addWidget (new QLabel (",")); + hL->addWidget (fields_[1]); + hL->addWidget (new QLabel (",")); + hL->addWidget (fields_[2]); + hL->addWidget (new QLabel (")")); + hL->addWidget (fields_[3]); + hL->addWidget (new QLabel (")")); + + for (int i = 0; i < 4; i++) + { + fields_[i]->setText (QString::number (default_[i])); + connect (fields_[i], SIGNAL (editingFinished ()), this, SLOT (editingFinished ())); + } + + setLayout (hL); + + for (int i = 0; i < 4; i++) + current_[i] = default_[i]; +} + +/// Destructor +Vec4DWidget::~ Vec4DWidget() +{ +} + +//------------------------------------------------------------------------------ + +/// Convert current value to string +QString Vec4DWidget::toValue() +{ + QString rv = "Vector4 ("; + rv += QString::number (current_[0]) + ","; + rv += QString::number (current_[1]) + ","; + rv += QString::number (current_[2]) + ","; + rv += QString::number (current_[3]) + ")"; + return rv; +} + +//------------------------------------------------------------------------------ + +/// Read value from string +void Vec4DWidget::fromValue(QString _from) +{ + if (_from.startsWith ("Vector4 (")) + _from.remove (0, 8); + if (_from.endsWith (")")) + _from.remove (_from.length () - 1, 1); + + QStringList sl = _from.split (','); + + float v[4]; + bool ok = true; + + if (sl.length () == 4) + { + for (int i = 0; i < 4 && ok; i++) + v[i] = sl[i].toFloat (&ok); + + if (ok) + for (int i = 0; i < 4; i++) + { + current_[i] = v[i]; + fields_[i]->setText (QString::number (current_[i])); + } + } +} + +//------------------------------------------------------------------------------ + +// handle slider changes +void Vec4DWidget::editingFinished () +{ + bool ok; + float v; + + for (int i = 0; i < 4; i++) + { + v = fields_[i]->text ().toFloat (&ok); + + if (ok) + current_[i] = v; + else + fields_[i]->setText (QString::number (current_[i])); + } +} + + + +//------------------------------------------------------------------------------ + +/// Reset to default +void Vec4DWidget::toDefault() +{ + for (int i = 0; i < 4; i++) + { + current_[i] = default_[i]; + fields_[i]->setText (QString::number (current_[i])); + } +} + +//------------------------------------------------------------------------------ +} + diff --git a/types/vec4dWidget.hh b/types/vec4dWidget.hh new file mode 100644 index 0000000..c5356fd --- /dev/null +++ b/types/vec4dWidget.hh @@ -0,0 +1,93 @@ +/*===========================================================================*\ +* * +* OpenFlipper * +* Copyright (C) 2001-2011 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: 13386 $ * +* $LastChangedBy: moebius $ * +* $Date: 2012-01-13 12:21:45 +0100 (Fr, 13 Jan 2012) $ * +* * +\*===========================================================================*/ + +#ifndef VSI_VEC4DWIDGET_HH +#define VSI_VEC4DWIDGET_HH + +//== INCLUDES ================================================================= +#include "../parser/typeWidget.hh" + +//== FORWARDDECLARATIONS ====================================================== +class QLineEdit; + +//== NAMESPACES =============================================================== +namespace VSI { + +//== CLASS DEFINITION ========================================================= + +/** Widget to configure number inputs + */ + +class Vec4DWidget : public TypeWidget { + Q_OBJECT + + public: + /// Constructor + Vec4DWidget (QMap &_hints, QString _typeName, QWidget *_parent = NULL); + + /// Destructor + ~Vec4DWidget (); + + /// Convert current value to string + QString toValue (); + + /// Read value from string + void fromValue (QString _from); + + /// Reset to default + void toDefault (); + + private slots: + void editingFinished (); + + private: + + float current_[4]; + float default_[4]; + + QLineEdit *fields_[4]; +}; +//============================================================================= +} +//============================================================================= + +#endif -- GitLab