From 41768f68242f2b8ceece3cb27aba6d04463345ff Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 7 Oct 2002 20:17:57 +0000 Subject: [PATCH] Fixes to Switch so that it defaults to adding children switched on, and adds a flag to control whether children and added as true or false. --- include/osg/Switch | 9 ++++++++- src/osg/AnimationPath.cpp | 2 -- src/osg/Switch.cpp | 19 ++++++++++++------- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/include/osg/Switch b/include/osg/Switch index a958c5b40..51292c3da 100644 --- a/include/osg/Switch +++ b/include/osg/Switch @@ -28,8 +28,14 @@ class SG_EXPORT Switch : public Group virtual void traverse(NodeVisitor& nv); + void setNewChildDefaultValue(bool value) { _newChildDefaultValue = value; } + + bool getNewChildDefaultValue() const { return _newChildDefaultValue; } + virtual bool addChild( Node *child ); + virtual bool addChild( Node *child, bool value ); + virtual bool removeChild( Node *child ); void setValue(unsigned int pos,bool value); @@ -73,7 +79,8 @@ class SG_EXPORT Switch : public Group virtual ~Switch() {} // this is effectively a bit mask. - ValueList _values; + bool _newChildDefaultValue; + ValueList _values; }; } diff --git a/src/osg/AnimationPath.cpp b/src/osg/AnimationPath.cpp index f1521e557..da4d981c8 100644 --- a/src/osg/AnimationPath.cpp +++ b/src/osg/AnimationPath.cpp @@ -12,8 +12,6 @@ bool AnimationPath::getInterpolatedControlPoint(double time,ControlPoint& contro { if (_timeControlPointMap.empty()) return false; - - switch(_loopMode) { case(SWING): diff --git a/src/osg/Switch.cpp b/src/osg/Switch.cpp index f5cabe44c..21e970b1b 100644 --- a/src/osg/Switch.cpp +++ b/src/osg/Switch.cpp @@ -4,16 +4,14 @@ using namespace osg; -/** - * Switch constructor. The default setting of _value is - * ALL_CHILDREN_OFF. - */ -Switch::Switch() +Switch::Switch(): + _newChildDefaultValue(true) { } Switch::Switch(const Switch& sw,const CopyOp& copyop): Group(sw,copyop), + _newChildDefaultValue(sw._newChildDefaultValue), _values(sw._values) { } @@ -41,10 +39,15 @@ void Switch::traverse(NodeVisitor& nv) } bool Switch::addChild( Node *child ) +{ + return addChild(child,_newChildDefaultValue); +} + +bool Switch::addChild( Node *child, bool value ) { if (Group::addChild(child)) { - if (_children.size()>_values.size()) _values.resize(_children.size(),false); + if (_children.size()>_values.size()) _values.resize(_children.size(),value); return true; } return false; @@ -63,7 +66,7 @@ bool Switch::removeChild( Node *child ) void Switch::setValue(unsigned int pos,bool value) { - if (pos>=_values.size()) _values.resize(pos+1,false); + if (pos>=_values.size()) _values.resize(pos+1,_newChildDefaultValue); _values[pos]=value; } @@ -100,6 +103,7 @@ void Switch::setValue(int value) break; case(ALL_CHILDREN_OFF): { + _newChildDefaultValue = false; for(ValueList::iterator itr=_values.begin(); itr!=_values.end(); ++itr) @@ -110,6 +114,7 @@ void Switch::setValue(int value) } case(ALL_CHILDREN_ON): { + _newChildDefaultValue = true; for(ValueList::iterator itr=_values.begin(); itr!=_values.end(); ++itr)