fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / NodeCores / Groups / Misc / OSGSwitch.cpp
blobe09436b5a9def322e01a16ddfaed52f6f1a5f0de
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
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. *
18 * *
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. *
23 * *
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. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 #include <cstdlib>
40 #include <cstdio>
42 #include "OSGConfig.h"
44 #include "OSGSwitch.h"
46 #include "OSGRenderAction.h"
47 #include "OSGIntersectAction.h"
49 OSG_USING_NAMESPACE
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 /*-------------------------------------------------------------------------*/
57 /* Sync */
59 void Switch::changed(ConstFieldMaskArg whichField,
60 UInt32 origin,
61 BitVector details)
63 Inherited::changed(whichField, origin, details);
66 /*-------------------------------------------------------------------------*/
67 /* Dump */
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 /*-------------------------------------------------------------------------*/
76 /* Constructors */
78 Switch::Switch(void) :
79 Inherited()
83 Switch::Switch(const Switch &source) :
84 Inherited(source)
88 /*-------------------------------------------------------------------------*/
89 /* Destructor */
91 Switch::~Switch(void)
95 /*-------------------------------------------------------------------------*/
96 /* Draw */
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()) )
108 ra->useNodeList();
110 if(ra->isVisible(ra->getNode(this->getChoice())))
112 ra->addNode(ra->getNode(this->getChoice()));
114 else
116 ra->popVisibility();
117 returnValue = Action::Skip;
120 else if(this->getChoice() == Switch::ALL)
122 if(ra->selectVisibles() == 0)
124 ra->popVisibility();
125 returnValue = Action::Skip;
128 else
130 ra->popVisibility();
131 returnValue = Action::Skip;
135 return returnValue;
138 Action::ResultE Switch::renderLeave(Action *action)
140 RenderAction *ra = dynamic_cast<RenderAction *>(action);
142 ra->popVisibility();
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()) )
155 ia->useNodeList( );
156 ia->addNode (ia->getNode(getChoice()));
158 else if(getChoice() == ALL)
160 returnValue = Action::Continue;
162 else
164 returnValue = Action::Skip;
167 return returnValue;
170 /*-------------------------------------------------------------------------*/
171 /* Init */
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(
188 getClassType(),
189 reinterpret_cast<Action::Callback>(&Switch::intersectEnter));