/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield * * This library is open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * (at your option) any later version. The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. */ #ifndef OSG_MULTISWITCH #define OSG_MULTISWITCH 1 #include namespace osgSim { /** MultiSwitch is a Group node which allows switching between sets of selected children. MultiSwtich is based on the OpenFlight switch behaviour. */ class SG_EXPORT MultiSwitch : public osg::Group { public : MultiSwitch(); /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ MultiSwitch(const MultiSwitch&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); META_Node(osgSim, MultiSwitch); virtual void traverse(osg::NodeVisitor& nv); void setNewChildDefaultValue(bool value) { _newChildDefaultValue = value; } bool getNewChildDefaultValue() const { return _newChildDefaultValue; } virtual bool addChild( Node *child ); virtual bool insertChild( unsigned int index, Node *child ); virtual bool removeChild( Node *child ); void setValue(unsigned int switchSet, unsigned int pos,bool value); bool getValue(unsigned int switchSet, unsigned int pos) const; void setChildValue(const Node* child,unsigned int switchSet, bool value); bool getChildValue(const Node* child,unsigned int switchSet) const; /** Set all the children off (false), and set the new default child value to off (false).*/ bool setAllChildrenOff(unsigned int switchSet); /** Set all the children on (true), and set the new default child value to on (true).*/ bool setAllChildrenOn(unsigned int switchSet); /** Set a single child to be on, MultiSwitch off all other children.*/ bool setSingleChildOn(unsigned int switchSet, unsigned int pos); /** Set which of the available switch set lists to use.*/ void setActiveSwitchSet(unsigned int switchSet) { _activeSwitchSet = switchSet; } /** Get which of the available switch set lists to use.*/ unsigned int getActiveSwitchSet(unsigned int switchSet) { return _activeSwitchSet; } typedef std::vector ValueList; typedef std::vector SwitchSetList; const SwitchSetList& getSwitchSetList() const { return _values; } const ValueList& getValueList(unsigned int switchSet) const { return _values[switchSet]; } protected : virtual ~MultiSwitch() {} void expandToEncompassSwitchSet(unsigned int switchSet); // this is effectively a list of bit mask. bool _newChildDefaultValue; unsigned int _activeSwitchSet; SwitchSetList _values; }; } #endif