vsg  1.1.0
VulkanSceneGraph library
Switch.h
1 #pragma once
2 
3 /* <editor-fold desc="MIT License">
4 
5 Copyright(c) 2018 Robert Osfield
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8 
9 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10 
11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 
13 </editor-fold> */
14 
15 #include <vsg/core/ref_ptr.h>
16 #include <vsg/nodes/Node.h>
17 
18 #include <vector>
19 
20 namespace vsg
21 {
22 
24  class VSG_DECLSPEC Switch : public Inherit<Node, Switch>
25  {
26  public:
27  explicit Switch();
28 
29  template<class N, class V>
30  static void t_traverse(N& node, V& visitor)
31  {
32  for (auto& child : node.children)
33  {
34  if ((visitor.traversalMask & (visitor.overrideMask | child.mask)) != MASK_OFF) child.node->accept(visitor);
35  }
36  }
37 
38  void traverse(Visitor& visitor) override { t_traverse(*this, visitor); }
39  void traverse(ConstVisitor& visitor) const override { t_traverse(*this, visitor); }
40  void traverse(RecordTraversal& visitor) const override { t_traverse(*this, visitor); }
41 
42  int compare(const Object& rhs) const override;
43 
44  void read(Input& input) override;
45  void write(Output& output) const override;
46 
47  struct Child
48  {
49  Mask mask = MASK_ALL;
50  ref_ptr<Node> node;
51  };
52 
53  using Children = std::vector<Child>;
54  Children children;
55 
57  void addChild(Mask mask, ref_ptr<Node> child);
58 
60  void addChild(bool enabled, ref_ptr<Node> child);
61 
63  void setAllChildren(bool enabled);
64 
66  void setSingleChildOn(size_t index);
67 
68  protected:
69  virtual ~Switch();
70  };
71  VSG_type_name(vsg::Switch);
72 
73  inline Mask boolToMask(bool enabled) { return enabled ? MASK_ALL : MASK_OFF; }
74 
75 } // namespace vsg
Definition: ConstVisitor.h:147
Definition: Inherit.h:28
Definition: Input.h:44
Definition: Object.h:42
Definition: Output.h:41
RecordTraversal traverses a scene graph doing view frustum culling and invoking state/commands to rec...
Definition: RecordTraversal.h:61
Switch node for toggling on/off recording of children.
Definition: Switch.h:25
void addChild(bool enabled, ref_ptr< Node > child)
add a child to the back of the children list.
void setSingleChildOn(size_t index)
set specified child to be on and all other children off.
void addChild(Mask mask, ref_ptr< Node > child)
add a child to the back of the children list.
void setAllChildren(bool enabled)
set all children to specified state.
int compare(const Object &rhs) const override
compare two objects, return -1 if this object is less than rhs, return 0 if it's equal,...
Definition: Visitor.h:147
Definition: ref_ptr.h:22
Definition: Switch.h:48