MultiSwitch 3.9 KB

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