openscenegraph
Switch
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSG_SWITCH
15#define OSG_SWITCH 1
16
17#include <osg/Group>
18
19namespace osg {
20
21/** Switch is a Group node that allows switching between children.
22 * Typical uses would be for objects which might need to be rendered
23 * differently at different times, for instance a switch could be used
24 * to represent the different states of a traffic light.
25*/
26class OSG_EXPORT Switch : public Group
27{
28 public :
29
30
31 Switch();
32
33 /** Copy constructor using CopyOp to manage deep vs shallow copy. */
34 Switch(const Switch&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
35
36 virtual Switch* asSwitch() { return this; }
37 virtual const Switch* asSwitch() const { return this; }
38
39
40 META_Node(osg, Switch);
41
42 virtual void traverse(NodeVisitor& nv);
43
44 void setNewChildDefaultValue(bool value) { _newChildDefaultValue = value; }
45
46 bool getNewChildDefaultValue() const { return _newChildDefaultValue; }
47
48 using osg::Group::addChild;
49 using osg::Group::insertChild;
50
51 virtual bool addChild( Node *child );
52
53 virtual bool addChild( Node *child, bool value );
54
55 virtual bool insertChild( unsigned int index, Node *child );
56
57 virtual bool insertChild( unsigned int index, Node *child, bool value );
58
59 virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove);
60
61
62 void setValue(unsigned int pos,bool value);
63
64 bool getValue(unsigned int pos) const;
65
66 void setChildValue(const Node* child,bool value);
67
68 bool getChildValue(const Node* child) const;
69
70 /** Set all the children off (false), and set the new default child
71 * value to off (false). */
72 bool setAllChildrenOff();
73
74 /** Set all the children on (true), and set the new default child
75 * value to on (true). */
76 bool setAllChildrenOn();
77
78 /** Set a single child on, switch off all other children. */
79 bool setSingleChildOn(unsigned int pos);
80
81
82 typedef std::vector<bool> ValueList;
83
84 void setValueList(const ValueList& values) { _values=values; }
85
86 const ValueList& getValueList() const { return _values; }
87
88 virtual BoundingSphere computeBound() const;
89
90 protected :
91
92 virtual ~Switch() {}
93
94 // This is effectively a bit mask.
95 bool _newChildDefaultValue;
96 ValueList _values;
97};
98
99}
100
101#endif