1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
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.
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.
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.
26class OSG_EXPORT Switch : public Group
33 /** Copy constructor using CopyOp to manage deep vs shallow copy. */
34 Switch(const Switch&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
36 virtual Switch* asSwitch() { return this; }
37 virtual const Switch* asSwitch() const { return this; }
40 META_Node(osg, Switch);
42 virtual void traverse(NodeVisitor& nv);
44 void setNewChildDefaultValue(bool value) { _newChildDefaultValue = value; }
46 bool getNewChildDefaultValue() const { return _newChildDefaultValue; }
48 using osg::Group::addChild;
49 using osg::Group::insertChild;
51 virtual bool addChild( Node *child );
53 virtual bool addChild( Node *child, bool value );
55 virtual bool insertChild( unsigned int index, Node *child );
57 virtual bool insertChild( unsigned int index, Node *child, bool value );
59 virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove);
62 void setValue(unsigned int pos,bool value);
64 bool getValue(unsigned int pos) const;
66 void setChildValue(const Node* child,bool value);
68 bool getChildValue(const Node* child) const;
70 /** Set all the children off (false), and set the new default child
71 * value to off (false). */
72 bool setAllChildrenOff();
74 /** Set all the children on (true), and set the new default child
75 * value to on (true). */
76 bool setAllChildrenOn();
78 /** Set a single child on, switch off all other children. */
79 bool setSingleChildOn(unsigned int pos);
82 typedef std::vector<bool> ValueList;
84 void setValueList(const ValueList& values) { _values=values; }
86 const ValueList& getValueList() const { return _values; }
88 virtual BoundingSphere computeBound() const;
94 // This is effectively a bit mask.
95 bool _newChildDefaultValue;