Commit 15b39b52 authored by Jan Möbius's avatar Jan Möbius
Browse files

Added Light Source widget

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@9110 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 49acacfd
......@@ -12,6 +12,7 @@
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/BasePlugin/PluginFunctionsCore.hh>
#include <ACG/QtWidgets/QtSceneGraphWidget.hh>
#include "LightWidget.hh"
#include "Light.hh"
//== DEFINES ==================================================================
......@@ -37,7 +38,7 @@ class LightWidgetGenerator : public ACG::QtWidgets::SceneGraphWidgetGenerator {
if ( widgetMap_.contains(_node) ) {
return widgetMap_[_node];
} else {
QWidget* widget = new QWidget();
QWidget* widget = new LightWidget(_node);
widgetMap_[_node] = widget;
return widget;
}
......@@ -188,6 +189,16 @@ LightNode* LightObject::lightNodeVis() {
return lightNodeVis_;
}
bool LightObject::hasNode(BaseNode* _node) {
if ( BaseObjectData::hasNode(_node) )
return true;
if ( _node == lightNode_ )
return true;
return false;
}
// ===============================================================================
// Object information
// ===============================================================================
......
......@@ -96,6 +96,8 @@ class DLLEXPORT LightObject : public BaseObjectData {
/// Get the scenegraph Node
LightNode* lightNodeVis();
virtual bool hasNode(BaseNode* _node);
private:
/// Light status node
LightNode* lightNode_;
......
/*===========================================================================*\
* *
* 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: 8520 $ *
* $Author: moebius $ *
* $Date: 2010-02-10 15:56:59 +0100 (Mi, 10. Feb 2010) $ *
* *
\*===========================================================================*/
#include "LightWidget.hh"
#include <QtGui>
#include <QMessageBox>
#include <iostream>
#include <OpenFlipper/common/GlobalOptions.hh>
LightWidget::LightWidget( ACG::SceneGraph::BaseNode* _node, QWidget *parent)
: QDialog(parent),
object_(0),
light_(0),
updatingWidgets_(false)
{
setupUi(this);
node_ = dynamic_cast< ACG::SceneGraph::LightNode* >(_node);
if ( ! node_ ) {
std::cerr << "LightWidget could not cast given node to LightNode!" << std::endl;
return;
}
connect(directional,SIGNAL(clicked()),this,SLOT(directionalToggled()));
connect(xpos,SIGNAL(editingFinished()),this,SLOT(directionalToggled()));
connect(ypos,SIGNAL(editingFinished()),this,SLOT(directionalToggled()));
connect(zpos,SIGNAL(editingFinished()),this,SLOT(directionalToggled()));
connect(xdir,SIGNAL(editingFinished()),this,SLOT(directionalToggled()));
connect(ydir,SIGNAL(editingFinished()),this,SLOT(directionalToggled()));
connect(zdir,SIGNAL(editingFinished()),this,SLOT(directionalToggled()));
connect(spotx,SIGNAL(editingFinished()),this,SLOT(spotChanged()));
connect(spoty,SIGNAL(editingFinished()),this,SLOT(spotChanged()));
connect(spotz,SIGNAL(editingFinished()),this,SLOT(spotChanged()));
connect(angle,SIGNAL(editingFinished()),this,SLOT(spotChanged()));
connect(exponent,SIGNAL(editingFinished()),this,SLOT(spotChanged()));
}
void LightWidget::showEvent ( QShowEvent * event )
{
if ( !getObject() )
return;
// Block updates
updatingWidgets_ = true;
directional->setChecked( light_->directional() );
// Switch to right tab
if ( directional->isChecked() )
stackedWidget->setCurrentIndex(1);
else
stackedWidget->setCurrentIndex(0);
xdir->setText(QString::number(light_->direction()[0]));
ydir->setText(QString::number(light_->direction()[1]));
zdir->setText(QString::number(light_->direction()[2]));
xpos->setText(QString::number(light_->position()[0]));
ypos->setText(QString::number(light_->position()[1]));
zpos->setText(QString::number(light_->position()[2]));
fixedPosition->setChecked( light_->fixedPosition() );
spotx->setText(QString::number(light_->spotDirection()[0]));
spoty->setText(QString::number(light_->spotDirection()[1]));
spotz->setText(QString::number(light_->spotDirection()[2]));
angle->setText(QString::number(light_->spotCutoff()));
exponent->setText(QString::number(light_->spotExponent()));
// Allow updates
updatingWidgets_ = false;
}
void LightWidget::directionalToggled() {
// Block if we currently update the widgets or if we dont get the object
if (updatingWidgets_ || !getObject() )
return;
// Switch to right tab
if ( directional->isChecked() )
stackedWidget->setCurrentIndex(1);
else
stackedWidget->setCurrentIndex(0);
if ( directional->isChecked() )
light_->direction( ACG::Vec3d( xdir->text().toDouble() ,ydir->text().toDouble() ,zdir->text().toDouble() ));
else
light_->position( ACG::Vec3d( xpos->text().toDouble() ,ypos->text().toDouble() ,zpos->text().toDouble() ));
updated();
}
void LightWidget::spotChanged() {
// Block if we currently update the widgets or if we dont get the object
if (updatingWidgets_ || !getObject() )
return;
light_->spotDirection( ACG::Vec3d( spotx->text().toDouble() ,spoty->text().toDouble() ,spotz->text().toDouble() ));
light_->spotCutoff(angle->text().toDouble());
light_->spotExponent(exponent->text().toDouble());
updated();
}
bool LightWidget::getObject() {
if ( !object_ ) {
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS,DATA_LIGHT) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
if ( o_it->hasNode(node_) ) {
object_ = PluginFunctions::lightObject(*o_it);
light_ = PluginFunctions::lightSource(object_);
return true;
}
}
std::cerr << " Object not found! " << std::endl;
// Not Found!
return false;
}
return true;
}
void LightWidget::updated() {
// Update the object
object_->update();
// Force a redraw
node_->setDirty();
}
/*===========================================================================*\
* *
* 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: 8520 $ *
* $Author: moebius $ *
* $Date: 2010-02-10 15:56:59 +0100 (Mi, 10. Feb 2010) $ *
* *
\*===========================================================================*/
#include <ui_lightWidget.hh>
#include <QtGui>
#include <ObjectTypes/Light/LightNode.hh>
#include <OpenFlipper/common/GlobalDefines.hh>
#include "Light.hh"
class DLLEXPORT LightWidget : public QDialog, public Ui::LightWidgetBase
{
Q_OBJECT
public:
LightWidget( ACG::SceneGraph::BaseNode* _node, QWidget *parent = 0);
private slots:
/// The directional checkbox changed -> update object
void directionalToggled();
/// Spot direction changed
void spotChanged();
protected:
/// Initialize contents of widget before showing it
virtual void showEvent ( QShowEvent * event );
private:
/// Initializes the internal object. Returns true if successfull
bool getObject();
/// Called when the object has been updated
void updated();
private:
ACG::SceneGraph::LightNode* node_;
LightObject* object_;
LightSource* light_;
bool updatingWidgets_;
};
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LightWidgetBase</class>
<widget class="QDialog" name="LightWidgetBase">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>226</width>
<height>582</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="directional">
<property name="toolTip">
<string>Directional Light source or lightsource with position</string>
</property>
<property name="text">
<string>Directional Light Source</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="fixedPosition">
<property name="toolTip">
<string>Light source fixed relatively to the viewer</string>
</property>
<property name="text">
<string>Fixed Position/Direction</string>
</property>
</widget>
</item>
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="page">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Position</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>X</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Z</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="xpos"/>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="ypos"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Y</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="zpos"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_2">
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Direction</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>X</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="xdir"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Y</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="ydir"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Z</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="zdir"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>Spot</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QGroupBox" name="groupBox_5">
<property name="title">
<string>Direction</string>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>X</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="spotx"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Y</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="spoty"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Z</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="spotz"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Parameters</string>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="1" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Angle</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="angle"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Exponent</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="exponent"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
Supports Markdown
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