1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
42 #include "OSGConfig.h"
44 #include "OSGSwitch.h"
46 #include "OSGRenderAction.h"
47 #include "OSGIntersectAction.h"
51 // Documentation for this class is emited in the
52 // OSGSwitchBase.cpp file.
53 // To modify it, please change the .fcd file (OSGSwitch.fcd) and
54 // regenerate the base file.
56 /*-------------------------------------------------------------------------*/
59 void Switch::changed(ConstFieldMaskArg whichField
,
63 Inherited::changed(whichField
, origin
, details
);
66 /*-------------------------------------------------------------------------*/
69 void Switch::dump( UInt32
OSG_CHECK_ARG(uiIndent
),
70 const BitVector
OSG_CHECK_ARG(bvFlags
)) const
72 SLOG
<< "Dump Switch NI" << std::endl
;
75 /*-------------------------------------------------------------------------*/
78 Switch::Switch(void) :
83 Switch::Switch(const Switch
&source
) :
88 /*-------------------------------------------------------------------------*/
95 /*-------------------------------------------------------------------------*/
98 Action::ResultE
Switch::renderEnter(Action
*action
)
100 Action::ResultE returnValue
= Action::Continue
;
101 RenderAction
*ra
= dynamic_cast<RenderAction
*>(action
);
103 if(ra
->pushVisibility() == true)
105 if((this->getChoice() >= 0 ) &&
106 (static_cast<UInt32
>(this->getChoice()) < ra
->getNNodes()) )
110 if(ra
->isVisible(ra
->getNode(this->getChoice())))
112 ra
->addNode(ra
->getNode(this->getChoice()));
117 returnValue
= Action::Skip
;
120 else if(this->getChoice() == Switch::ALL
)
122 if(ra
->selectVisibles() == 0)
125 returnValue
= Action::Skip
;
131 returnValue
= Action::Skip
;
138 Action::ResultE
Switch::renderLeave(Action
*action
)
140 RenderAction
*ra
= dynamic_cast<RenderAction
*>(action
);
144 return Action::Continue
;
147 Action::ResultE
Switch::intersectEnter(Action
*action
)
149 Action::ResultE returnValue
= Action::Continue
;
150 IntersectAction
*ia
= dynamic_cast<IntersectAction
*>(action
);
152 if((getChoice() >= 0 ) &&
153 (UInt32(getChoice()) < ia
->getNNodes()) )
156 ia
->addNode (ia
->getNode(getChoice()));
158 else if(getChoice() == ALL
)
160 returnValue
= Action::Continue
;
164 returnValue
= Action::Skip
;
170 /*-------------------------------------------------------------------------*/
173 void Switch::initMethod(InitPhase ePhase
)
175 Inherited::initMethod(ePhase
);
177 if(ePhase
== TypeObject::SystemPost
)
179 RenderAction::registerEnterDefault(
180 Switch::getClassType(),
181 reinterpret_cast<Action::Callback
>(&Switch::renderEnter
));
183 RenderAction::registerLeaveDefault(
184 Switch::getClassType(),
185 reinterpret_cast<Action::Callback
>(&Switch::renderLeave
));
187 IntersectAction::registerEnterDefault(
189 reinterpret_cast<Action::Callback
>(&Switch::intersectEnter
));