Switch 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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_SWITCH
  14. #define OSG_SWITCH 1
  15. #include <osg/Group>
  16. namespace osg {
  17. /** Switch is a Group node that allows switching between children.
  18. * Typical uses would be for objects which might need to be rendered
  19. * differently at different times, for instance a switch could be used
  20. * to represent the different states of a traffic light.
  21. */
  22. class OSG_EXPORT Switch : public Group
  23. {
  24. public :
  25. Switch();
  26. /** Copy constructor using CopyOp to manage deep vs shallow copy. */
  27. Switch(const Switch&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
  28. virtual Switch* asSwitch() { return this; }
  29. virtual const Switch* asSwitch() const { return this; }
  30. META_Node(osg, Switch);
  31. virtual void traverse(NodeVisitor& nv);
  32. void setNewChildDefaultValue(bool value) { _newChildDefaultValue = value; }
  33. bool getNewChildDefaultValue() const { return _newChildDefaultValue; }
  34. using osg::Group::addChild;
  35. using osg::Group::insertChild;
  36. virtual bool addChild( Node *child );
  37. virtual bool addChild( Node *child, bool value );
  38. virtual bool insertChild( unsigned int index, Node *child );
  39. virtual bool insertChild( unsigned int index, Node *child, bool value );
  40. virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove);
  41. void setValue(unsigned int pos,bool value);
  42. bool getValue(unsigned int pos) const;
  43. void setChildValue(const Node* child,bool value);
  44. bool getChildValue(const Node* child) const;
  45. /** Set all the children off (false), and set the new default child
  46. * value to off (false). */
  47. bool setAllChildrenOff();
  48. /** Set all the children on (true), and set the new default child
  49. * value to on (true). */
  50. bool setAllChildrenOn();
  51. /** Set a single child on, switch off all other children. */
  52. bool setSingleChildOn(unsigned int pos);
  53. typedef std::vector<bool> ValueList;
  54. void setValueList(const ValueList& values) { _values=values; }
  55. const ValueList& getValueList() const { return _values; }
  56. virtual BoundingSphere computeBound() const;
  57. protected :
  58. virtual ~Switch() {}
  59. // This is effectively a bit mask.
  60. bool _newChildDefaultValue;
  61. ValueList _values;
  62. };
  63. }
  64. #endif