fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / NodeCores / Groups / Base / OSGMultiCore.cpp
blob43e6dc5c7e298eec2263c34f46b3ec19944bbf7c
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2006 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 //---------------------------------------------------------------------------
40 // Includes
41 //---------------------------------------------------------------------------
43 #include <cstdlib>
44 #include <cstdio>
46 #include "OSGConfig.h"
48 #include "OSGMultiCore.h"
49 #include "OSGRenderAction.h"
51 OSG_BEGIN_NAMESPACE
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 /***************************************************************************\
59 * Class variables *
60 \***************************************************************************/
62 /***************************************************************************\
63 * Class methods *
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 /***************************************************************************\
84 * Instance methods *
85 \***************************************************************************/
87 /*-------------------------------------------------------------------------*\
88 - private -
89 \*-------------------------------------------------------------------------*/
91 /*----------------------- constructors & destructors ----------------------*/
93 MultiCore::MultiCore(void) :
94 Inherited()
98 MultiCore::MultiCore(const MultiCore &source) :
99 Inherited(source)
103 MultiCore::~MultiCore(void)
107 /*----------------------------- class specific ----------------------------*/
109 void MultiCore::changed(ConstFieldMaskArg whichField,
110 UInt32 origin,
111 BitVector details)
113 if(whichField & CoresFieldMask)
115 invalidateVolume();
118 Inherited::changed(whichField, origin, details);
121 /*-------------------------------------------------------------------------*/
122 /* Helper */
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);
133 ++coreIt;
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);
146 ++coreIt;
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)
174 returnValue = rc;
176 if(_sfExitOnSkip.getValue() == true)
177 break;
179 else if(rc == Action::Quit)
181 returnValue = rc;
183 break;
186 ++coreIt;
189 return returnValue;
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)
210 returnValue = rc;
212 if(_sfExitOnSkip.getValue() == true)
213 break;
215 else if(rc == Action::Quit)
217 returnValue = rc;
219 break;
222 ++coreIt;
225 return returnValue;
228 Action::ResultE MultiCore::actionEnterFrom(Action *action,
229 NodeCore *pFrom )
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)
243 if(bActive == true)
245 action->setActParent(this);
247 Action::ResultE rc = action->callEnter(*coreIt);
249 if(rc == Action::Skip)
251 returnValue = rc;
253 if(_sfExitOnSkip.getValue() == true)
254 break;
256 else if(rc == Action::Quit)
258 returnValue = rc;
260 break;
264 if(*coreIt == pFrom)
265 bActive = true;
267 ++coreIt;
270 return returnValue;
273 Action::ResultE MultiCore::actionLeaveFrom(Action *action,
274 NodeCore *pFrom )
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)
288 if(bActive == true)
290 action->setActParent(this);
292 Action::ResultE rc = action->callLeave(*coreIt);
294 if(rc == Action::Skip)
296 returnValue = rc;
298 if(_sfExitOnSkip.getValue() == true)
299 break;
301 else if(rc == Action::Quit)
303 returnValue = rc;
305 break;
309 if(*coreIt == pFrom)
310 bActive = true;
312 ++coreIt;
315 return returnValue;
318 void MultiCore::replaceCore(UInt32 uiIndex,
319 NodeCore * const value )
321 if(value == NULL)
322 return;
324 if(uiIndex >= _mfCores.size())
325 return;
327 editMField(CoresFieldMask, _mfCores);
329 _mfCores.replace(uiIndex, value);
332 void MultiCore::replaceCoreByObj(NodeCore * const pOldElem,
333 NodeCore * const pNewElem)
335 if(pNewElem == NULL)
336 return;
338 Int32 elemIdx = _mfCores.findIndex(pOldElem);
340 if(elemIdx != -1)
342 editMField(CoresFieldMask, _mfCores);
344 _mfCores.replace(elemIdx, pNewElem);
348 OSG_SYSTEM_DLLMAPPING
349 void addCoreToNode(Node *pNode,
350 NodeCore *pCore)
352 if(pNode == NULL || pCore == NULL)
353 return;
355 NodeCore *pCurrCore = pNode->getCore();
356 MultiCore *pMCore = dynamic_cast<MultiCore *>(pCurrCore);
358 if(pMCore != NULL)
360 Int32 iIdx = pMCore->findCore(pCore);
362 if(iIdx == -1)
364 pMCore->addCore(pCore);
367 else if(pCurrCore == NULL)
369 pNode->setCore(pCore);
371 else
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,
387 NodeCore *pCore,
388 bool bSimplify)
390 if(pNode == NULL || pCore == NULL)
391 return;
393 NodeCore *pCurrCore = pNode->getCore();
394 MultiCoreUnrecPtr pMCore = dynamic_cast<MultiCore *>(pCurrCore);
396 if(pMCore != NULL)
398 pMCore->subCoreByObj(pCore);
400 if(bSimplify == true)
402 if(pMCore->getNCores() == 1)
404 pNode->setCore(pMCore->getCores(0));
406 pMCore = NULL;
408 else if(pMCore->getNCores() == 0)
410 pNode->setCore(NULL);
414 else
416 if(pCore == pCurrCore)
418 pNode->setCore(NULL);
423 OSG_END_NAMESPACE