BaseNode.cc 7.87 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1
2
3
/*===========================================================================*\
 *                                                                           *
 *                              OpenFlipper                                  *
Jan Möbius's avatar
Jan Möbius committed
4
 *      Copyright (C) 2001-2010 by Computer Graphics Group, RWTH Aachen      *
Jan Möbius's avatar
Jan Möbius committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 *                           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/>.                                      *
 *                                                                           *
\*===========================================================================*/

/*===========================================================================*\
 *                                                                           *
Jan Möbius's avatar
Jan Möbius committed
37
 *   $Revision$                                                       *
Jan Möbius's avatar
Jan Möbius committed
38
39
40
41
 *   $Author$                                                      *
 *   $Date$                   *
 *                                                                           *
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64




//=============================================================================
//
//  CLASS BaseNode - IMPLEMENTATION
//
//=============================================================================


//== INCLUDES =================================================================

#include "BaseNode.hh"
#include "DrawModes.hh"


//== NAMESPACES ===============================================================

namespace ACG {
namespace SceneGraph {


Jan Möbius's avatar
Nothing    
Jan Möbius committed
65
//== IMPLEMENTATION ==========================================================
Jan Möbius's avatar
 
Jan Möbius committed
66
67


Jan Möbius's avatar
Nothing    
Jan Möbius committed
68
unsigned int BaseNode::last_id_used__ = 0;
Jan Möbius's avatar
 
Jan Möbius committed
69
70
71
72
73
74
75


//----------------------------------------------------------------------------


BaseNode::
BaseNode(BaseNode* _parent, std::string _name)
Jan Möbius's avatar
Jan Möbius committed
76
77
  : multipassStatus_(ALLPASSES),
    multipassNode_(PASS_1),
78
    parent_(_parent),
Jan Möbius's avatar
Nothing    
Jan Möbius committed
79
    name_(_name),
Jan Möbius's avatar
 
Jan Möbius committed
80
81
82
83
84
    status_(Active),
    drawMode_(DrawModes::DEFAULT),
    pickingEnabled_(true),
    dirty_ (false),
    traverseMode_ (BaseNode::NodeFirst)
Jan Möbius's avatar
Nothing    
Jan Möbius committed
85
{
Jan Möbius's avatar
 
Jan Möbius committed
86
87
88
89
90
  id_ = ++last_id_used__;
  if (_parent!=0) _parent->push_back(this);

  DrawModes::initializeDefaultDrawModes();
}
Jan Möbius's avatar
Nothing    
Jan Möbius committed
91

Jan Möbius's avatar
 
Jan Möbius committed
92
93
94
95
96
97

//----------------------------------------------------------------------------


BaseNode::
BaseNode(BaseNode* _parent, BaseNode* _child, std::string _name)
Jan Möbius's avatar
Jan Möbius committed
98
99
  : multipassStatus_(ALLPASSES),
    multipassNode_(PASS_1),
100
    parent_(_parent),
Jan Möbius's avatar
Nothing    
Jan Möbius committed
101
    name_(_name),
Jan Möbius's avatar
 
Jan Möbius committed
102
103
    status_(Active),
    drawMode_(DrawModes::DEFAULT)
Jan Möbius's avatar
Nothing    
Jan Möbius committed
104
{
Jan Möbius's avatar
 
Jan Möbius committed
105
106
107
108
109
110
111
112
113
  assert(_parent != 0 && _child != 0);

  id_ = ++last_id_used__;

  _parent->push_back(this);
  _child->set_parent(this);

  DrawModes::initializeDefaultDrawModes();
}
Jan Möbius's avatar
Nothing    
Jan Möbius committed
114

Jan Möbius's avatar
 
Jan Möbius committed
115
116
117
118

//----------------------------------------------------------------------------


Jan Möbius's avatar
Nothing    
Jan Möbius committed
119
BaseNode::~BaseNode()
Jan Möbius's avatar
 
Jan Möbius committed
120
121
{
  // remove myself from parent's children
Jan Möbius's avatar
Nothing    
Jan Möbius committed
122
  if (parent_!=0)
Jan Möbius's avatar
 
Jan Möbius committed
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
  {
    ChildIter me(parent_->find(this));
    assert(me != parent_->childrenEnd());
    parent_->remove(me);
  }


  // remove me (as parent) from my children
  for (BaseNode::ChildIter cIt=childrenBegin(); cIt!=childrenEnd(); ++cIt)
    (*cIt)->parent_ = 0;
}


//----------------------------------------------------------------------------


void
BaseNode::
set_parent(BaseNode* _parent)
Jan Möbius's avatar
Nothing    
Jan Möbius committed
142
{
Jan Möbius's avatar
 
Jan Möbius committed
143
144
145
146
147
148
  if (parent_)
  {
    ChildIter me(parent_->find(this));
    if (me != parent_->childrenEnd())
      parent_->remove(me);
  }
Jan Möbius's avatar
Nothing    
Jan Möbius committed
149

Jan Möbius's avatar
 
Jan Möbius committed
150
  parent_ = _parent;
Jan Möbius's avatar
Nothing    
Jan Möbius committed
151

Jan Möbius's avatar
 
Jan Möbius committed
152
153
154
155
156
157
158
159
160
161
162
163
  if (parent_)
  {
    ChildIter me(parent_->find(this));
    if (me == parent_->childrenEnd())
      parent_->push_back(this);
  }
}


//----------------------------------------------------------------------------


Jan Möbius's avatar
Nothing    
Jan Möbius committed
164
void
Jan Möbius's avatar
 
Jan Möbius committed
165
166
167
168
169
170
171
BaseNode::delete_subtree()
{
  while (!children_.empty())
    children_.front()->delete_subtree();
  delete this;
}

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
172
173
174
//----------------------------------------------------------------------------

void
Jan Möbius's avatar
Jan Möbius committed
175
BaseNode::enterPick(GLState& _state, PickTarget /*_target*/, DrawModes::DrawMode _drawMode)
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
176
177
178
179
180
181
182
{
  enter (_state, _drawMode);
}

//----------------------------------------------------------------------------

void
Jan Möbius's avatar
Jan Möbius committed
183
BaseNode::leavePick(GLState& _state, PickTarget /*_target*/, DrawModes::DrawMode _drawMode)
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
184
185
186
{
  leave (_state, _drawMode);
}
Jan Möbius's avatar
 
Jan Möbius committed
187

188
189
//----------------------------------------------------------------------------

190
void BaseNode::multipassStatusSetActive(const unsigned int _i, bool _active) {
Jan Möbius's avatar
Jan Möbius committed
191
192
193
194
195
196
197
198
199
200
201
202
203
204

  if ( _i == NOPASS ) {
    multipassStatus_ = NOPASS;
  } else if ( _i == ALLPASSES ) {
    if ( _active )
      multipassStatus_ = ALLPASSES;
    else
      multipassStatus_ = NOPASS;  
  } else {
    if ( _active ) 
      multipassStatus_ |=  (1 << (_i == 0 ? 0 : _i - 1));
    else
      multipassStatus_ &=  ~(1 << (_i == 0 ? 0 : _i - 1));
  }
205
  
206
207
208
209
}

//----------------------------------------------------------------------------

210
bool BaseNode::multipassStatusActive(const unsigned int _i) const {
Jan Möbius's avatar
Jan Möbius committed
211
212
213
214

  if ( multipassStatus_ == NOPASS )
    return false;
  else if ( multipassStatus_ & ALLPASSES )
215
216
217
    return true;
  else  
    return ((1 << (_i == 0 ? 0 : _i - 1)) & multipassStatus_) != 0;
Jan Möbius's avatar
Jan Möbius committed
218
  
219
220
221
222
}

//----------------------------------------------------------------------------

223
224
void BaseNode::multipassNodeSetActive(const unsigned int _i , bool _active) {
  
Jan Möbius's avatar
Jan Möbius committed
225
226
227
228
229
230
231
232
233
234
235
236
237
  if ( _i == NOPASS ) {
    multipassNode_ = NOPASS;
  } else if ( _i == ALLPASSES ) {
    if ( _active )
      multipassNode_ = ALLPASSES;
    else
      multipassNode_ = NOPASS;  
  } else {
    if ( _active ) 
      multipassNode_ |=  (1 << (_i == 0 ? 0 : _i - 1));
    else
      multipassNode_ &=  ~(1 << (_i == 0 ? 0 : _i - 1));
  }
238
  
239
240
241
242
}

//----------------------------------------------------------------------------

243
244
bool BaseNode::multipassNodeActive(const unsigned int _i) const {
  
Jan Möbius's avatar
Jan Möbius committed
245
246
247
  if ( multipassNode_ == NOPASS )
    return false;
  else if ( multipassNode_ & ALLPASSES )
248
249
250
    return true;
  else  
    return ((1 << (_i == 0 ? 0 : _i - 1)) & multipassNode_) != 0;
Jan Möbius's avatar
Jan Möbius committed
251
  
252
}
253

Jan Möbius's avatar
 
Jan Möbius committed
254
255
256
257
//=============================================================================
} // namespace SceneGraph
} // namespace ACG
//=============================================================================