BaseNode.cc

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 6743 $                                                       *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2009-08-05 11:03:10 +0200 (Mi, 05. Aug 2009) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 
00046 //=============================================================================
00047 //
00048 //  CLASS BaseNode - IMPLEMENTATION
00049 //
00050 //=============================================================================
00051 
00052 
00053 //== INCLUDES =================================================================
00054 
00055 #include "BaseNode.hh"
00056 #include "DrawModes.hh"
00057 
00058 
00059 //== NAMESPACES ===============================================================
00060 
00061 namespace ACG {
00062 namespace SceneGraph {
00063 
00064 
00065 //== IMPLEMENTATION ==========================================================
00066 
00067 
00068 unsigned int BaseNode::last_id_used__ = 0;
00069 
00070 
00071 //----------------------------------------------------------------------------
00072 
00073 
00074 BaseNode::
00075 BaseNode(BaseNode* _parent, std::string _name)
00076   : parent_(_parent),
00077     name_(_name),
00078     status_(Active),
00079     drawMode_(DrawModes::DEFAULT),
00080     depth_func_(GL_LESS),
00081     pickingEnabled_(true),
00082     dirty_ (false),
00083     traverseMode_ (BaseNode::NodeFirst)
00084 {
00085   id_ = ++last_id_used__;
00086   if (_parent!=0) _parent->push_back(this);
00087 
00088   DrawModes::initializeDefaultDrawModes();
00089 }
00090 
00091 
00092 //----------------------------------------------------------------------------
00093 
00094 
00095 BaseNode::
00096 BaseNode(BaseNode* _parent, BaseNode* _child, std::string _name)
00097   : parent_(_parent),
00098     name_(_name),
00099     status_(Active),
00100     drawMode_(DrawModes::DEFAULT)
00101 {
00102   assert(_parent != 0 && _child != 0);
00103 
00104   id_ = ++last_id_used__;
00105 
00106   _parent->push_back(this);
00107   _child->set_parent(this);
00108 
00109   DrawModes::initializeDefaultDrawModes();
00110 }
00111 
00112 
00113 //----------------------------------------------------------------------------
00114 
00115 
00116 BaseNode::~BaseNode()
00117 {
00118   // remove myself from parent's children
00119   if (parent_!=0)
00120   {
00121     ChildIter me(parent_->find(this));
00122     assert(me != parent_->childrenEnd());
00123     parent_->remove(me);
00124   }
00125 
00126 
00127   // remove me (as parent) from my children
00128   for (BaseNode::ChildIter cIt=childrenBegin(); cIt!=childrenEnd(); ++cIt)
00129     (*cIt)->parent_ = 0;
00130 }
00131 
00132 
00133 //----------------------------------------------------------------------------
00134 
00135 
00136 void
00137 BaseNode::
00138 set_parent(BaseNode* _parent)
00139 {
00140   if (parent_)
00141   {
00142     ChildIter me(parent_->find(this));
00143     if (me != parent_->childrenEnd())
00144       parent_->remove(me);
00145   }
00146 
00147   parent_ = _parent;
00148 
00149   if (parent_)
00150   {
00151     ChildIter me(parent_->find(this));
00152     if (me == parent_->childrenEnd())
00153       parent_->push_back(this);
00154   }
00155 }
00156 
00157 
00158 //----------------------------------------------------------------------------
00159 
00160 
00161 void
00162 BaseNode::delete_subtree()
00163 {
00164   while (!children_.empty())
00165     children_.front()->delete_subtree();
00166   delete this;
00167 }
00168 
00169 //----------------------------------------------------------------------------
00170 
00171 void
00172 BaseNode::enterPick(GLState& _state, PickTarget /*_target*/, unsigned int _drawMode)
00173 {
00174   enter (_state, _drawMode);
00175 }
00176 
00177 //----------------------------------------------------------------------------
00178 
00179 void
00180 BaseNode::leavePick(GLState& _state, PickTarget /*_target*/, unsigned int _drawMode)
00181 {
00182   leave (_state, _drawMode);
00183 }
00184 
00185 //=============================================================================
00186 } // namespace SceneGraph
00187 } // namespace ACG
00188 //=============================================================================

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .