Panda3D

switchNode.h

00001 // Filename: switchNode.h
00002 // Created by:  drose (31Jul02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef SWITCHNODE_H
00016 #define SWITCHNODE_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "selectiveChildNode.h"
00021 
00022 ////////////////////////////////////////////////////////////////////
00023 //       Class : SwitchNode
00024 // Description : A node that renders only one of its children,
00025 //               according to the user's indication.
00026 ////////////////////////////////////////////////////////////////////
00027 class EXPCL_PANDA_PGRAPHNODES SwitchNode : public SelectiveChildNode {
00028 PUBLISHED:
00029   INLINE SwitchNode(const string &name);
00030 
00031 public:
00032   SwitchNode(const SwitchNode &copy);
00033 
00034   virtual PandaNode *make_copy() const;
00035   virtual bool safe_to_combine() const;
00036   virtual bool safe_to_combine_children() const;
00037 
00038   virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
00039   virtual int get_first_visible_child() const;
00040   virtual bool has_single_child_visibility() const;
00041 
00042 PUBLISHED:
00043   INLINE void set_visible_child(int index);
00044   virtual int get_visible_child() const;
00045 
00046 private:
00047   class EXPCL_PANDA_PGRAPHNODES CData : public CycleData {
00048   public:
00049     INLINE CData();
00050     INLINE CData(const CData &copy);
00051     virtual CycleData *make_copy() const;
00052     virtual void write_datagram(BamWriter *manager, Datagram &dg) const;
00053     virtual void fillin(DatagramIterator &scan, BamReader *manager);
00054     virtual TypeHandle get_parent_type() const {
00055       return SwitchNode::get_class_type();
00056     }
00057 
00058     int _visible_child;
00059   };
00060 
00061   PipelineCycler<CData> _cycler;
00062   typedef CycleDataReader<CData> CDReader;
00063   typedef CycleDataWriter<CData> CDWriter;
00064 
00065 public:
00066   static void register_with_read_factory();
00067   virtual void write_datagram(BamWriter *manager, Datagram &dg);
00068 
00069 protected:
00070   static TypedWritable *make_from_bam(const FactoryParams &params);
00071   void fillin(DatagramIterator &scan, BamReader *manager);
00072 
00073 public:
00074   static TypeHandle get_class_type() {
00075     return _type_handle;
00076   }
00077   static void init_type() {
00078     SelectiveChildNode::init_type();
00079     register_type(_type_handle, "SwitchNode",
00080                   SelectiveChildNode::get_class_type());
00081   }
00082   virtual TypeHandle get_type() const {
00083     return get_class_type();
00084   }
00085   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00086 
00087 private:
00088   static TypeHandle _type_handle;
00089 };
00090 
00091 #include "switchNode.I"
00092 
00093 #endif
 All Classes Functions Variables Enumerations