Developer Documentation
LightObject.cc
1/*===========================================================================*\
2* *
3* OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39* *
40\*===========================================================================*/
41
42
43
44//=============================================================================
45//
46// Light Object
47//
48//=============================================================================
49
50#define LIGHTOBJECT_C
51
52//== INCLUDES =================================================================
53
57#include <ACG/QtWidgets/QtSceneGraphWidget.hh>
58#include "LightWidget.hh"
59
60#include <ACG/Scenegraph/MaterialNode.hh>
61
62
63//== DEFINES ==================================================================
64
65//== TYPEDEFS =================================================================
66
67//== CLASS DEFINITION =========================================================
68
70 public:
71 // constructor
73 }
74
75
76 virtual QWidget* getWidget(ACG::SceneGraph::BaseNode* _node ) {
77
78 // Check if we can handle this type
79 if ( ! canHandle( _node->className() ) )
80 return 0;
81
82 // Check if we already have a widget, otherwise generate a new one.
83 if ( widgetMap_.contains(_node) ) {
84 return widgetMap_[_node];
85 } else {
86 QWidget* widget = new LightWidget(_node);
87 widgetMap_[_node] = widget;
88 return widget;
89 }
90
91 }
92
93 virtual bool canHandle(std::string _className) {
94 return ( _className == std::string("LightNode") );
95 }
96
97 virtual std::string handles() {
98 return std::string("LightNode");
99 }
100
101 virtual QString contextMenuName() {
102 return QString("Edit Light");
103 }
104};
105
106static LightWidgetGenerator lightWidgetGenerator_;
107
113 lightNode_(0),
114 lightNodeVis_(0)
115{
117 setTypeIcon(DATA_LIGHT,"LightType.png");
118 init();
119
120 // Make sure, the generator is added to the widget
121 PluginFunctions::addSceneGraphGenerator( &lightWidgetGenerator_ );
122}
123
124//=============================================================================
125
126
131 BaseObjectData(_object),
132 defaultLightSource_(false)
133{
134
135 init(_object.lightNode_);
136
137 setName( name() );
138}
139
144{
145 // Delete the data attached to this object ( this will remove all perObject data)
146 // Not the best way to do it but it will work.
147 // This is only necessary if people use references to the light below and
148 // they do something with the light in the destructor of their
149 // perObjectData.
150 deleteData();
151
152 // Move children to parent
154
155 // First, collect all children as the iterator will get invalid if we delete while iterating!
156 std::vector< BaseNode*> children;
158 children.push_back( (*cIt) );
159
160 // Move the children
161 for (unsigned int i = 0 ; i < children.size(); ++i )
162 children[i]->set_parent(parent);
163
164 // Delete the scenegraph node
165 delete lightNode_;
166}
167
172
174
175 lightNode_ = NULL;
176
178 setTypeIcon(DATA_LIGHT,"LightType.png");
179
180 init();
181
182}
183
188 LightObject* object = new LightObject(*this);
189 return dynamic_cast< BaseObject* >(object);
190}
191
194void LightObject::init(LightNode* _light, LightNode* _lightVis) {
195
196 // Light nodes have to be on top of all other nodes.
197 lightNode_ = new LightNode( 0 , "LightNode");
198 lightNode_->visualize(false);
200
201 lightNodeVis_ = new LightNode( materialNode() , "LightNode Visualization");
204}
205
206// ===============================================================================
207// Name/Path Handling
208// ===============================================================================
209
213void LightObject::setName( QString _name ) {
215
216 std::string nodename = std::string("LightNode for Light " + _name.toUtf8() );
217 lightNode_->name( nodename );
218
219 std::string nodenameVis = std::string("LightNode Visualization for Light " + _name.toUtf8() );
220 lightNodeVis_->name( nodenameVis );
221}
222
223// ===============================================================================
224// Visualization
225// ===============================================================================
226
228 return lightNode_;
229}
230
232 return lightNodeVis_;
233}
234
236 if ( BaseObjectData::hasNode(_node) )
237 return true;
238
239 if ( _node == lightNode_ )
240 return true;
241
242 return false;
243}
244
245// ===============================================================================
246// Object information
247// ===============================================================================
248
255 QString output;
256
257 output += "========================================================================\n";
259
260 if ( dataType( DATA_LIGHT ) )
261 output += "Object Contains Light : ";
262
264// ACG::Vec3f nor = lightNode_->normal();
265
266 output += " Position ( " + QString::number(pos[0]) + ", " + QString::number(pos[1]) + ", " + QString::number(pos[2]) + ")";
267// output += " Normal ( " + QString::number(nor[0]) + ", " + QString::number(nor[1]) + ", " + QString::number(nor[2]) + ")";
268
269 output += "========================================================================\n";
270 return output;
271}
272
273// ===============================================================================
274// Picking
275// ===============================================================================
276
283bool LightObject::picked( uint _node_idx ) {
284 return ( _node_idx == lightNode_->id() || _node_idx == lightNodeVis_->id() );
285}
286
287void LightObject::enablePicking( bool _enable ) {
288 lightNode_->enablePicking( _enable );
289}
290
292 return lightNode_->pickingEnabled();
293}
294
296 if ( !visible_ ) {
298 visible_ = true;
299
301
302 emit visibilityChanged( id() );
303 }
304}
305
307 if ( visible_ ) {
309 visible_ = false;
310
311 emit visibilityChanged( id() );
312 }
313}
314
315void LightObject::visible(bool _visible) {
316 if ( _visible )
317 show();
318 else
319 hide();
320}
321
323 return visible_;
324}
325
327 return &lightSource_;
328}
329
331
332 if(lightSource_.enabled()) {
333 lightNode_->setMultipassStatus(ACG::SceneGraph::BaseNode::ALLPASSES);
335 } else {
336 lightNode_->setMultipassStatus(ACG::SceneGraph::BaseNode::NOPASS);
338 }
339
342}
343
344//=============================================================================
345
DLLEXPORT void setTypeIcon(DataType _id, const QString &_icon)
Set an Icon for a given DataType.
Definition: Types.cc:223
ACG::SceneGraph::LightNode LightNode
Simple Name for PlaneNode.
Definition: LightTypes.hh:69
#define DATA_LIGHT
Definition: Light.hh:58
ChildIter childrenBegin()
Returns: begin-iterator of children.
Definition: BaseNode.hh:294
ChildIter childrenEnd()
Returns: end-iterator of children.
Definition: BaseNode.hh:298
void enablePicking(bool _enable)
Definition: BaseNode.hh:265
void setMultipassStatus(const MultipassBitMask _passStatus)
Set multipass settings for the nodes status functions.
Definition: BaseNode.hh:505
@ HideNode
Hide this node, but draw children.
Definition: BaseNode.hh:394
@ Active
Draw node & children.
Definition: BaseNode.hh:392
BaseNode * parent()
Get the nodes parent node.
Definition: BaseNode.hh:372
std::vector< BaseNode * >::iterator ChildIter
allows to iterate over children
Definition: BaseNode.hh:286
void set_status(StatusMode _s)
Set the status of this node.
Definition: BaseNode.hh:403
virtual const std::string & className() const =0
Return class name (implemented by the ACG_CLASSNAME macro)
unsigned int id() const
Definition: BaseNode.hh:423
std::string name() const
Returns: name of node (needs not be unique)
Definition: BaseNode.hh:415
void push_back(BaseNode *_node)
Insert _node at the end of the list of children.
Definition: BaseNode.hh:318
void show()
Show node: set status to Active.
Definition: BaseNode.hh:407
bool visualize()
Should node be visualized?
Definition: LightNode.hh:290
void setLightSource(LightSource _light)
Set the light source parameters.
Definition: LightNode.hh:262
Structure to hold options for one LightSource.
Definition: LightNode.hh:86
void position(Vec3d _pos)
Set position for LightSource.
Definition: LightNode.cc:108
bool enabled() const
Get light source status.
Definition: LightNode.cc:137
virtual void show()
Sets the whole Scenegraph subtree of this node to visible.
virtual void hide()
Sets the whole Scenegraph subtree of this node to invisible.
virtual void setName(QString _name) override
path to the file from which the object is loaded ( defaults to "." )
MaterialNode * materialNode()
get a pointer to the materialnode
virtual void cleanup() override
virtual bool hasNode(BaseNode *_node)
Check if the given node is owned by this object.
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:242
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:728
BaseObject * parent()
Get the parent item ( 0 if rootitem )
Definition: BaseObject.cc:464
void setDataType(DataType _type)
Definition: BaseObject.cc:231
void visibilityChanged(int _objectId)
void deleteData()
Delete all data attached to this object ( calls delete on each object )
Definition: BaseObject.cc:810
DataType dataType() const
Definition: BaseObject.cc:227
bool visible_
Definition: BaseObject.hh:274
virtual void show()
Show Light Node.
Definition: LightObject.cc:295
BaseObject * copy()
Definition: LightObject.cc:187
virtual void hide()
Hide Light Node.
Definition: LightObject.cc:306
LightNode * lightNodeVis_
Light rendering node (only for rendering purposes)
Definition: LightObject.hh:175
LightSource * lightSource()
Definition: LightObject.cc:326
virtual void cleanup()
Reset current object, including all related nodes.
Definition: LightObject.cc:171
LightObject()
constructor
Definition: LightObject.cc:111
virtual void update(UpdateType _type=UPDATE_ALL)
Update the Light Object.
Definition: LightObject.cc:330
bool picked(uint _node_idx)
detect if the node has been picked
Definition: LightObject.cc:283
LightNode * lightNodeVis()
Get the scenegraph Node.
Definition: LightObject.cc:231
void setName(QString _name)
Set the name of the Object.
Definition: LightObject.cc:213
LightNode * lightNode_
Light status node.
Definition: LightObject.hh:172
bool pickingEnabled()
Check if picking is enabled for this Object.
Definition: LightObject.cc:291
QString getObjectinfo()
Get all Info for the Object as a string.
Definition: LightObject.cc:254
LightNode * lightNode()
Get the scenegraph Node.
Definition: LightObject.cc:227
virtual bool hasNode(BaseNode *_node)
Light status node.
Definition: LightObject.cc:235
void enablePicking(bool _enable)
Enable or disable picking for this Object.
Definition: LightObject.cc:287
LightSource lightSource_
Definition: LightObject.hh:130
virtual void init(LightNode *_light=0, LightNode *_lightVis=0)
Initialize current object, including all related nodes.
Definition: LightObject.cc:194
virtual bool visible()
Show Light Node.
Definition: LightObject.cc:322
virtual ~LightObject()
destructor
Definition: LightObject.cc:143
virtual QString contextMenuName()
Return a name for your widget in the context menu.
Definition: LightObject.cc:101
virtual std::string handles()
return the type this generator handles
Definition: LightObject.cc:97
virtual bool canHandle(std::string _className)
returns if the widgets can handle the given class
Definition: LightObject.cc:93
virtual QWidget * getWidget(ACG::SceneGraph::BaseNode *_node)
Get a widget for this Node.
Definition: LightObject.cc:76
Update type class.
Definition: UpdateType.hh:59
void addSceneGraphGenerator(ACG::QtWidgets::SceneGraphWidgetGenerator *_generator)
Add a scenegraph generator ( the handled type will be extracted from the generator)
void addGlobalStatusNode(ACG::SceneGraph::BaseNode *_node)
Adds a global status node.