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.
14#ifndef OSG_MULTISWITCH
15#define OSG_MULTISWITCH 1
18#include <osgSim/Export>
22/** MultiSwitch is a Group node which allows switching between sets of selected children.
23 MultiSwitch is based on the OpenFlight switch behaviour.
25class OSGSIM_EXPORT MultiSwitch : public osg::Group
32 /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
33 MultiSwitch(const MultiSwitch&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
35 META_Node(osgSim, MultiSwitch);
37 virtual void traverse(osg::NodeVisitor& nv);
39 void setNewChildDefaultValue(bool value) { _newChildDefaultValue = value; }
41 bool getNewChildDefaultValue() const { return _newChildDefaultValue; }
43 virtual bool addChild( osg::Node *child );
45 virtual bool insertChild( unsigned int index, osg::Node *child );
47 virtual bool removeChild( osg::Node *child );
49 void setValue(unsigned int switchSet, unsigned int pos,bool value);
51 bool getValue(unsigned int switchSet, unsigned int pos) const;
53 void setChildValue(const osg::Node* child,unsigned int switchSet, bool value);
55 bool getChildValue(const osg::Node* child,unsigned int switchSet) const;
57 /** Set all the children off (false), and set the new default child value to off (false).*/
58 bool setAllChildrenOff(unsigned int switchSet);
60 /** Set all the children on (true), and set the new default child value to on (true).*/
61 bool setAllChildrenOn(unsigned int switchSet);
63 /** Set a single child to be on, MultiSwitch off all other children.*/
64 bool setSingleChildOn(unsigned int switchSet, unsigned int pos);
66 /** Set which of the available switch set lists to use.*/
67 void setActiveSwitchSet(unsigned int switchSet) { _activeSwitchSet = switchSet; }
69 /** Get which of the available switch set lists to use.*/
70 unsigned int getActiveSwitchSet() const { return _activeSwitchSet; }
72 typedef std::vector<bool> ValueList;
73 typedef std::vector<ValueList> SwitchSetList;
74 typedef std::vector<std::string> SwitchSetNameList;
76 /** Set the compile set of different values.*/
77 void setSwitchSetList(const SwitchSetList& switchSetList);
79 /** Get the compile set of different values.*/
80 const SwitchSetList& getSwitchSetList() const { return _values; }
82 /** Set the a single set of different values for a particular switch set.*/
83 void setValueList(unsigned int switchSet, const ValueList& values);
85 /** Get the a single set of different values for a particular switch set.*/
86 const ValueList& getValueList(unsigned int switchSet) const { return _values[switchSet]; }
88 void setValueName(unsigned int switchSet, const std::string& name);
90 const std::string& getValueName(unsigned int switchSet) const { return _valueNames[switchSet]; }
94 virtual ~MultiSwitch() {}
96 void expandToEncompassSwitchSet(unsigned int switchSet);
98 // this is effectively a list of bit mask.
99 bool _newChildDefaultValue;
100 unsigned int _activeSwitchSet;
101 SwitchSetList _values;
102 SwitchSetNameList _valueNames;