Panda3D
switchNode.h
1 // Filename: switchNode.h
2 // Created by: drose (31Jul02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef SWITCHNODE_H
16 #define SWITCHNODE_H
17 
18 #include "pandabase.h"
19 
20 #include "selectiveChildNode.h"
21 
22 ////////////////////////////////////////////////////////////////////
23 // Class : SwitchNode
24 // Description : A node that renders only one of its children,
25 // according to the user's indication.
26 ////////////////////////////////////////////////////////////////////
27 class EXPCL_PANDA_PGRAPHNODES SwitchNode : public SelectiveChildNode {
28 PUBLISHED:
29  INLINE SwitchNode(const string &name);
30 
31 public:
32  SwitchNode(const SwitchNode &copy);
33 
34  virtual PandaNode *make_copy() const;
35  virtual bool safe_to_combine() const;
36  virtual bool safe_to_combine_children() const;
37 
38  virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
39  virtual int get_first_visible_child() const;
40  virtual bool has_single_child_visibility() const;
41 
42 PUBLISHED:
43  INLINE void set_visible_child(int index);
44  virtual int get_visible_child() const;
45 
46 private:
47  class EXPCL_PANDA_PGRAPHNODES CData : public CycleData {
48  public:
49  INLINE CData();
50  INLINE CData(const CData &copy);
51  virtual CycleData *make_copy() const;
52  virtual void write_datagram(BamWriter *manager, Datagram &dg) const;
53  virtual void fillin(DatagramIterator &scan, BamReader *manager);
54  virtual TypeHandle get_parent_type() const {
55  return SwitchNode::get_class_type();
56  }
57 
58  int _visible_child;
59  };
60 
61  PipelineCycler<CData> _cycler;
64 
65 public:
66  static void register_with_read_factory();
67  virtual void write_datagram(BamWriter *manager, Datagram &dg);
68 
69 protected:
70  static TypedWritable *make_from_bam(const FactoryParams &params);
71  void fillin(DatagramIterator &scan, BamReader *manager);
72 
73 public:
74  static TypeHandle get_class_type() {
75  return _type_handle;
76  }
77  static void init_type() {
78  SelectiveChildNode::init_type();
79  register_type(_type_handle, "SwitchNode",
80  SelectiveChildNode::get_class_type());
81  }
82  virtual TypeHandle get_type() const {
83  return get_class_type();
84  }
85  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
86 
87 private:
88  static TypeHandle _type_handle;
89 };
90 
91 #include "switchNode.I"
92 
93 #endif
virtual int get_visible_child() const
Returns the index number of the currently visible child of this node.
Definition: pandaNode.cxx:563
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
A single page of data maintained by a PipelineCycler.
Definition: cycleData.h:50
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
virtual bool safe_to_combine_children() const
Returns true if it is generally safe to combine the children of this PandaNode with each other...
Definition: pandaNode.cxx:295
virtual TypeHandle get_parent_type() const
Returns the type of the container that owns the CycleData.
Definition: cycleData.cxx:91
This collects together the pieces of data that are accumulated for each node while walking the scene ...
A base class for nodes like LODNode and SequenceNode that select only one visible child at a time...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
virtual bool safe_to_combine() const
Returns true if it is generally safe to combine this particular kind of PandaNode with other kinds of...
Definition: pandaNode.cxx:281
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
virtual void write_datagram(BamWriter *, Datagram &) const
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: cycleData.cxx:34
virtual int get_first_visible_child() const
Returns the index number of the first visible child of this node, or a number >= get_num_children() i...
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
virtual PandaNode * make_copy() const
Returns a newly-allocated PandaNode that is a shallow copy of this one.
Definition: pandaNode.cxx:604
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class&#39;s make_from_bam() method to read in all...
Definition: cycleData.cxx:68
virtual bool has_single_child_visibility() const
Should be overridden by derived classes to return true if this kind of node has the special property ...
Definition: pandaNode.cxx:551
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
Definition: cullTraverser.h:48
A node that renders only one of its children, according to the user&#39;s indication. ...
Definition: switchNode.h:27