openscenegraph
MultiSwitch
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_MULTISWITCH
15#define OSG_MULTISWITCH 1
16
17#include <osg/Group>
18#include <osgSim/Export>
19
20namespace osgSim {
21
22/** MultiSwitch is a Group node which allows switching between sets of selected children.
23 MultiSwitch is based on the OpenFlight switch behaviour.
24*/
25class OSGSIM_EXPORT MultiSwitch : public osg::Group
26{
27 public :
28
29
30 MultiSwitch();
31
32 /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
33 MultiSwitch(const MultiSwitch&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
34
35 META_Node(osgSim, MultiSwitch);
36
37 virtual void traverse(osg::NodeVisitor& nv);
38
39 void setNewChildDefaultValue(bool value) { _newChildDefaultValue = value; }
40
41 bool getNewChildDefaultValue() const { return _newChildDefaultValue; }
42
43 virtual bool addChild( osg::Node *child );
44
45 virtual bool insertChild( unsigned int index, osg::Node *child );
46
47 virtual bool removeChild( osg::Node *child );
48
49 void setValue(unsigned int switchSet, unsigned int pos,bool value);
50
51 bool getValue(unsigned int switchSet, unsigned int pos) const;
52
53 void setChildValue(const osg::Node* child,unsigned int switchSet, bool value);
54
55 bool getChildValue(const osg::Node* child,unsigned int switchSet) const;
56
57 /** Set all the children off (false), and set the new default child value to off (false).*/
58 bool setAllChildrenOff(unsigned int switchSet);
59
60 /** Set all the children on (true), and set the new default child value to on (true).*/
61 bool setAllChildrenOn(unsigned int switchSet);
62
63 /** Set a single child to be on, MultiSwitch off all other children.*/
64 bool setSingleChildOn(unsigned int switchSet, unsigned int pos);
65
66 /** Set which of the available switch set lists to use.*/
67 void setActiveSwitchSet(unsigned int switchSet) { _activeSwitchSet = switchSet; }
68
69 /** Get which of the available switch set lists to use.*/
70 unsigned int getActiveSwitchSet() const { return _activeSwitchSet; }
71
72 typedef std::vector<bool> ValueList;
73 typedef std::vector<ValueList> SwitchSetList;
74 typedef std::vector<std::string> SwitchSetNameList;
75
76 /** Set the compile set of different values.*/
77 void setSwitchSetList(const SwitchSetList& switchSetList);
78
79 /** Get the compile set of different values.*/
80 const SwitchSetList& getSwitchSetList() const { return _values; }
81
82 /** Set the a single set of different values for a particular switch set.*/
83 void setValueList(unsigned int switchSet, const ValueList& values);
84
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]; }
87
88 void setValueName(unsigned int switchSet, const std::string& name);
89
90 const std::string& getValueName(unsigned int switchSet) const { return _valueNames[switchSet]; }
91
92 protected :
93
94 virtual ~MultiSwitch() {}
95
96 void expandToEncompassSwitchSet(unsigned int switchSet);
97
98 // this is effectively a list of bit mask.
99 bool _newChildDefaultValue;
100 unsigned int _activeSwitchSet;
101 SwitchSetList _values;
102 SwitchSetNameList _valueNames;
103};
104
105}
106
107#endif