BaseNode.hh

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: 8548 $                                                       *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2010-02-12 14:40:13 +0100 (Fr, 12. Feb 2010) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 //=============================================================================
00046 //
00047 //  CLASS BaseNode
00048 //
00049 //=============================================================================
00050 
00051 
00052 #ifndef ACG_BASE_NODE_HH
00053 #define ACG_BASE_NODE_HH
00054 
00055 
00056 //== INCLUDES =================================================================
00057 
00058 // ACG
00059 #include "../Math/VectorT.hh"
00060 #include "../GL/GLState.hh"
00061 #include "../Config/ACGDefines.hh"
00062 
00063 // Qt
00064 //#include <qgl.h>
00065 #include <QMouseEvent>
00066 
00067 // stdc++
00068 #include <list>
00069 #include <string>
00070 #include <algorithm>
00071 #include <iostream>
00072 #include <ACG/Scenegraph/DrawModes.hh>
00073 
00074 
00075 //== NAMESPACES ===============================================================
00076 
00077 
00078 namespace ACG {
00079 namespace SceneGraph {
00080 
00081 
00082 //== CLASS DEFINITION =========================================================
00083 
00084 
00086 enum PickTarget 
00087 {
00089   PICK_CELL,
00091   PICK_FACE,
00093   PICK_EDGE,
00095   PICK_VERTEX,
00097   PICK_ANYTHING,
00098 
00100   PICK_FRONT_EDGE,
00102   PICK_FRONT_VERTEX
00103 };
00104 
00105 
00107 #define ACG_CLASSNAME(_className) \
00108  virtual const std::string& className() const { \
00109   static std::string cname( #_className ); return cname; \
00110 }
00111 
00112 
00119 class ACGDLLEXPORT BaseNode 
00120 {
00121 public:
00122 
00123 
00125   BaseNode(BaseNode* _parent=0, std::string _name="<unknown>");
00126 
00128   BaseNode(BaseNode* _parent, BaseNode* _child, std::string _name="<unknown>");
00129  
00131   virtual ~BaseNode();
00132 
00141   void delete_subtree();
00142 
00143 
00144   // --- basic interface ---
00145 
00147   virtual const std::string& className() const = 0;
00148 
00151   virtual DrawModes::DrawMode availableDrawModes() const { return DrawModes::NONE; }
00152 
00158   virtual void boundingBox(Vec3d& /* _bbMin */, Vec3d& /*_bbMax*/ ) {}
00159 
00166   virtual void enter(GLState& /*_state */, DrawModes::DrawMode /*_drawMode*/ ) {}
00167 
00169   virtual void draw(GLState& /* _state */, DrawModes::DrawMode /* _drawMode */)  {}
00170 
00174   virtual void leave(GLState& /* _state */, DrawModes::DrawMode /* _drawMode */) {}
00175 
00181   virtual void enterPick(GLState& _state , PickTarget _target,
00182                          DrawModes::DrawMode _drawMode );
00183   
00188   virtual void pick(GLState& /* _state */, PickTarget /* _target */ ) {}
00189 
00194   virtual void leavePick(GLState& _state, PickTarget _target,
00195                          DrawModes::DrawMode _drawMode );
00196   
00200   void enablePicking(bool _enable) { pickingEnabled_ = _enable; };
00201   
00204   bool pickingEnabled() { return pickingEnabled_; };
00205   
00207   virtual void mouseEvent(GLState& /* _state */, QMouseEvent* /* _event */ ) {}
00208 
00209 
00211   GLenum depthFunc() const { return depth_func_; }
00212 
00214   void depthFunc(GLenum _func) { depth_func_ = _func; }
00215 
00217   void setDirty (bool _dirty = true) { dirty_ = _dirty; }
00218 
00220   bool isDirty () const { return dirty_; }
00221 
00222 
00223   // --- iterators ---
00224 
00226   typedef std::list<BaseNode*>::const_iterator ConstChildIter;
00228   typedef std::list<BaseNode*>::iterator ChildIter;
00229 
00231   typedef std::list<BaseNode*>::const_reverse_iterator ConstChildRIter;
00233   typedef std::list<BaseNode*>::reverse_iterator ChildRIter;
00234 
00236   ChildIter childrenBegin() { return children_.begin(); }
00238   ConstChildIter childrenBegin() const { return children_.begin(); }
00240   ChildIter childrenEnd() { return children_.end(); }
00242   ConstChildIter childrenEnd() const { return children_.end(); }
00243   
00245   ChildRIter childrenRBegin() { return children_.rbegin(); }
00247   ConstChildRIter childrenRBegin() const { return children_.rbegin(); }
00249   ChildRIter childrenREnd() { return children_.rend(); }
00251   ConstChildRIter childrenREnd() const { return children_.rend(); }
00252 
00253 
00254 
00255 
00256   
00257   // --- insert / remove ---
00258 
00260   void push_back(BaseNode* _node) 
00261   {
00262     if (_node)
00263     {
00264       children_.push_back(_node);
00265       _node->parent_=this;
00266     }
00267   }
00268 
00272   void remove(ChildIter _pos) 
00273   {
00274     if (_pos == childrenEnd()) return;
00275     //(*_pos)->parent_=0;
00276     children_.erase(_pos); 
00277   }
00278 
00280   unsigned int nChildren() const { return children_.size(); }
00281 
00288   ChildIter find(BaseNode* _node) 
00289   {
00290     ChildIter i=std::find(children_.begin(),children_.end(),_node);
00291     return i;
00292   } 
00293 
00294 
00297   BaseNode * find( const std::string & _name )
00298   {
00299     if ( name() == _name )
00300       return this;
00301 
00302     for ( BaseNode::ChildIter cIt = childrenBegin();
00303           cIt != childrenEnd(); ++cIt )
00304     {
00305       BaseNode * n = (*cIt)->find( _name );
00306       if ( n ) return n;
00307     }
00308 
00309     return 0;
00310   } 
00311   
00312 
00314   BaseNode* parent() { return parent_; }
00315   
00321   void set_parent(BaseNode* _parent);
00322 
00323 
00324   // --- status info ---
00325 
00326   
00328   enum StatusMode
00329   {
00331     Active = 0x1,
00333     HideNode  = 0x2,
00335     HideChildren = 0x4,
00337     HideSubtree  = 0x8
00338   };
00340   StatusMode status() const { return status_; }
00342   void set_status(StatusMode _s) { status_ = _s; }
00344   void hide() { set_status(HideNode); }
00346   void show() { set_status(Active); }
00348   bool visible() { return status_ == Active; }
00350   bool hidden() { return status_ != Active; }
00351 
00352 
00354   std::string name() const { return name_; }
00356   void name(const std::string& _name) { name_ = _name; }
00357 
00358   
00362   unsigned int id() const { return id_; }
00363   
00364 
00365 
00366   //--- draw mode ---
00367 
00369   DrawModes::DrawMode drawMode() const { return drawMode_; }
00372   void drawMode(DrawModes::DrawMode _drawMode) { drawMode_ = _drawMode; }
00373 
00374   //--- traverse type ---
00375 
00377   enum TraverseMode
00378   {
00380     NodeFirst = 0x1,
00382     ChildrenFirst = 0x2,
00384     SecondPass = 0x4
00385   };
00386 
00388   unsigned int traverseMode () const { return traverseMode_; }
00389 
00391   void setTraverseMode(unsigned int _mode) { traverseMode_ = _mode; }
00392 
00393   //===========================================================================
00403   //===========================================================================
00404 
00405 public:
00406   
00408   typedef unsigned int MultipassBitMask;
00409   
00410 
00412   enum PASSES {
00413     NOPASS = 0,
00414     ALLPASSES = 1 << 0,
00415     PASS_1    = 1 << 1,
00416     PASS_2    = 1 << 2,
00417     PASS_3    = 1 << 3,
00418     PASS_4    = 1 << 4,
00419     PASS_5    = 1 << 5,
00420     PASS_6    = 1 << 6,
00421     PASS_7    = 1 << 7,
00422     PASS_8    = 1 << 8
00423   };
00424   
00432   MultipassBitMask multipassStatus() const {return multipassStatus_;};
00433   
00434   
00444   void setMultipassStatus(const MultipassBitMask _passStatus) { multipassStatus_ = _passStatus; };
00445   
00455   void multipassStatusSetActive(const unsigned int _i, bool _active);
00456  
00465   bool multipassStatusActive(const unsigned int _i) const;  
00466   
00467   
00468   
00476   MultipassBitMask multipassNode() const {return multipassNode_;};  
00477   
00478   
00479   
00488   void setMultipassNode(const MultipassBitMask _passNode) { multipassNode_ = _passNode; };  
00489   
00499   void multipassNodeSetActive(const unsigned int _i , bool _active);
00500   
00509   bool multipassNodeActive(const unsigned int _i) const;  
00510 
00511 private:
00512 
00517   MultipassBitMask multipassStatus_;
00518   
00523   MultipassBitMask multipassNode_;
00524 
00527 private:
00528 
00530   BaseNode(const BaseNode&);
00532   void operator=(const BaseNode&);
00533 
00534   
00536   BaseNode* parent_;
00537 
00539   std::string name_;
00540 
00542   StatusMode status_;
00543   
00545   std::list<BaseNode*> children_; 
00546 
00548   static unsigned int last_id_used__;
00549 
00551   unsigned int id_;
00552 
00554   DrawModes::DrawMode drawMode_;
00555 
00557   GLenum depth_func_;
00558   
00562   bool pickingEnabled_;
00563 
00565   bool dirty_;
00566 
00568   unsigned int traverseMode_;
00569 };
00570 
00571 
00572 //=============================================================================
00573 } // namespace SceneGraph
00574 } // namespace ACG
00575 //=============================================================================
00576 #endif // ACG_BASE_NODE_HH defined
00577 //=============================================================================

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