1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2006 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 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
46 #include "OSGConfig.h"
48 #include "OSGMultiCore.h"
49 #include "OSGRenderAction.h"
53 // Documentation for this class is emitted in the
54 // OSGMultiCoreBase.cpp file.
55 // To modify it, please change the .fcd file (OSGMultiCore.fcd) and
56 // regenerate the base file.
58 /***************************************************************************\
60 \***************************************************************************/
62 /***************************************************************************\
64 \***************************************************************************/
66 void MultiCore::initMethod(InitPhase ePhase
)
68 Inherited::initMethod(ePhase
);
70 if(ePhase
== TypeObject::SystemPost
)
72 RenderAction::registerEnterDefault(
73 MultiCore::getClassType(),
74 reinterpret_cast<Action::Callback
>(&MultiCore::renderEnter
));
76 RenderAction::registerLeaveDefault(
77 MultiCore::getClassType(),
78 reinterpret_cast<Action::Callback
>(&MultiCore::renderLeave
));
83 /***************************************************************************\
85 \***************************************************************************/
87 /*-------------------------------------------------------------------------*\
89 \*-------------------------------------------------------------------------*/
91 /*----------------------- constructors & destructors ----------------------*/
93 MultiCore::MultiCore(void) :
98 MultiCore::MultiCore(const MultiCore
&source
) :
103 MultiCore::~MultiCore(void)
107 /*----------------------------- class specific ----------------------------*/
109 void MultiCore::changed(ConstFieldMaskArg whichField
,
113 if(whichField
& CoresFieldMask
)
118 Inherited::changed(whichField
, origin
, details
);
121 /*-------------------------------------------------------------------------*/
124 void MultiCore::accumulateMatrix(Matrix
&result
)
126 MFUnrecChildNodeCorePtr::const_iterator coreIt
= getMFCores()->begin();
127 MFUnrecChildNodeCorePtr::const_iterator coreEnd
= getMFCores()->end ();
129 while(coreIt
!= coreEnd
)
131 (*coreIt
)->accumulateMatrix(result
);
137 void MultiCore::adjustVolume(Volume
&volume
)
139 MFUnrecChildNodeCorePtr::const_iterator coreIt
= getMFCores()->begin();
140 MFUnrecChildNodeCorePtr::const_iterator coreEnd
= getMFCores()->end ();
142 while(coreIt
!= coreEnd
)
144 (*coreIt
)->adjustVolume(volume
);
150 void MultiCore::dump( UInt32
,
151 const BitVector
) const
153 SLOG
<< "Dump MultiCore NI" << std::endl
;
156 Action::ResultE
MultiCore::renderEnter(Action
*action
)
158 MFUnrecChildNodeCorePtr::const_iterator coreIt
=
159 this->getMFCores()->begin();
161 MFUnrecChildNodeCorePtr::const_iterator coreEnd
=
162 this->getMFCores()->end ();
164 Action::ResultE returnValue
= Action::Continue
;
166 while(coreIt
!= coreEnd
)
168 action
->setActParent(this);
170 Action::ResultE rc
= action
->callEnter(*coreIt
);
172 if(rc
== Action::Skip
)
176 if(_sfExitOnSkip
.getValue() == true)
179 else if(rc
== Action::Quit
)
192 Action::ResultE
MultiCore::renderLeave(Action
*action
)
194 MFUnrecChildNodeCorePtr::const_iterator coreIt
=
195 this->getMFCores()->begin();
197 MFUnrecChildNodeCorePtr::const_iterator coreEnd
=
198 this->getMFCores()->end ();
200 Action::ResultE returnValue
= Action::Continue
;
202 while(coreIt
!= coreEnd
)
204 action
->setActParent(this);
206 Action::ResultE rc
= action
->callLeave(*coreIt
);
208 if(rc
== Action::Skip
)
212 if(_sfExitOnSkip
.getValue() == true)
215 else if(rc
== Action::Quit
)
228 Action::ResultE
MultiCore::actionEnterFrom(Action
*action
,
231 MFUnrecChildNodeCorePtr::const_iterator coreIt
=
232 this->getMFCores()->begin();
234 MFUnrecChildNodeCorePtr::const_iterator coreEnd
=
235 this->getMFCores()->end ();
237 Action::ResultE returnValue
= Action::Continue
;
239 bool bActive
= false;
241 while(coreIt
!= coreEnd
)
245 action
->setActParent(this);
247 Action::ResultE rc
= action
->callEnter(*coreIt
);
249 if(rc
== Action::Skip
)
253 if(_sfExitOnSkip
.getValue() == true)
256 else if(rc
== Action::Quit
)
273 Action::ResultE
MultiCore::actionLeaveFrom(Action
*action
,
276 MFUnrecChildNodeCorePtr::const_iterator coreIt
=
277 this->getMFCores()->begin();
279 MFUnrecChildNodeCorePtr::const_iterator coreEnd
=
280 this->getMFCores()->end ();
282 Action::ResultE returnValue
= Action::Continue
;
284 bool bActive
= false;
286 while(coreIt
!= coreEnd
)
290 action
->setActParent(this);
292 Action::ResultE rc
= action
->callLeave(*coreIt
);
294 if(rc
== Action::Skip
)
298 if(_sfExitOnSkip
.getValue() == true)
301 else if(rc
== Action::Quit
)
318 void MultiCore::replaceCore(UInt32 uiIndex
,
319 NodeCore
* const value
)
324 if(uiIndex
>= _mfCores
.size())
327 editMField(CoresFieldMask
, _mfCores
);
329 _mfCores
.replace(uiIndex
, value
);
332 void MultiCore::replaceCoreByObj(NodeCore
* const pOldElem
,
333 NodeCore
* const pNewElem
)
338 Int32 elemIdx
= _mfCores
.findIndex(pOldElem
);
342 editMField(CoresFieldMask
, _mfCores
);
344 _mfCores
.replace(elemIdx
, pNewElem
);
348 OSG_SYSTEM_DLLMAPPING
349 void addCoreToNode(Node
*pNode
,
352 if(pNode
== NULL
|| pCore
== NULL
)
355 NodeCore
*pCurrCore
= pNode
->getCore();
356 MultiCore
*pMCore
= dynamic_cast<MultiCore
*>(pCurrCore
);
360 Int32 iIdx
= pMCore
->findCore(pCore
);
364 pMCore
->addCore(pCore
);
367 else if(pCurrCore
== NULL
)
369 pNode
->setCore(pCore
);
373 if(pCore
!= pCurrCore
)
375 MultiCoreUnrecPtr pNewMCore
= MultiCore::create();
377 pNewMCore
->addCore(pCurrCore
);
378 pNewMCore
->addCore(pCore
);
380 pNode
->setCore(pNewMCore
);
385 OSG_SYSTEM_DLLMAPPING
386 void subCoreFromNode(Node
*pNode
,
390 if(pNode
== NULL
|| pCore
== NULL
)
393 NodeCore
*pCurrCore
= pNode
->getCore();
394 MultiCoreUnrecPtr pMCore
= dynamic_cast<MultiCore
*>(pCurrCore
);
398 pMCore
->subCoreByObj(pCore
);
400 if(bSimplify
== true)
402 if(pMCore
->getNCores() == 1)
404 pNode
->setCore(pMCore
->getCores(0));
408 else if(pMCore
->getNCores() == 0)
410 pNode
->setCore(NULL
);
416 if(pCore
== pCurrCore
)
418 pNode
->setCore(NULL
);