1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2003 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 \*---------------------------------------------------------------------------*/
41 template <class ParentT> inline
42 void TraversalValidationHandlerMixin<ParentT>::classDescInserter(
45 FieldDescriptionBase *pDesc;
47 typedef typename SFUInt32::Description SFDesc;
50 SFUInt32::getClassType(),
52 "how the element is updated.",
53 OSG_RC_FIELD_DESC(Self::UpdateMode),
55 Field::SFDefaultFlags,
56 static_cast<FieldEditMethodSig>(&Self::editHandleUpdateMode),
57 static_cast<FieldGetMethodSig >(&Self::getHandleUpdateMode ));
59 oType.addInitialDesc(pDesc);
62 SFOSGAny::getClassType(),
65 OSG_RC_FIELD_DESC(Self::RequestRun),
67 Field::SFDefaultFlags,
68 static_cast<FieldEditMethodSig>(&Self::invalidEditField ),
69 static_cast<FieldGetMethodSig >(&Self::getHandleRequestRun));
71 oType.addInitialDesc(pDesc);
73 pDesc = new MFChangedFunctorCallback::Description(
74 MFChangedFunctorCallback::getClassType(),
77 OSG_RC_FIELD_DESC(Self::DestroyedFunctors),
79 (Field::MFDefaultFlags | Field::FStdAccess),
80 static_cast <FieldEditMethodSig>(&Self::invalidEditField),
81 static_cast <FieldGetMethodSig >(&Self::invalidGetField));
83 oType.addInitialDesc(pDesc);
86 template <class ParentT> inline
87 bool TraversalValidationHandlerMixin<ParentT>::requestRun(void)
89 Self::editSField(RequestRunFieldMask);
94 template <class ParentT> inline
95 void TraversalValidationHandlerMixin<ParentT>::changed(
96 ConstFieldMaskArg whichField,
100 if(0x0000 != (whichField & RequestRunFieldMask))
102 Window::requestStageRun(this->_iElementId);
105 Inherited::changed(whichField, origin, details);
108 template <class ParentT> inline
109 typename TraversalValidationHandlerMixin<ParentT>::ValidationStatus
110 TraversalValidationHandlerMixin<ParentT>::validate(
111 RenderActionBase *pAction)
114 TraversalValidator *pVal = NULL;
116 if(_sfUpdateMode.getValue() == Self::PerWindow)
118 Window *pWin = pAction->getWindow();
120 pVal = pWin->getTravValidator();
122 else if(_sfUpdateMode.getValue() == Self::PerViewport)
124 Viewarea *pVP = pAction->getViewarea();
126 pVal = pVP->getTravValidator();
128 else if(_sfUpdateMode.getValue() == Self::PerTraversal)
130 pVal = pAction->getTravValidator();
132 else if(_sfUpdateMode.getValue() == Self::OnRequest)
134 Window *pWin = pAction->getWindow();
136 pVal = pWin->getTravValidator();
138 return pVal->checkRunRequest(this->_iElementId);
142 return TraversalValidator::Run;
145 return pVal->validate(this->_iElementId, pAction->getFrameTravCount());
148 template <class ParentT> inline
149 void TraversalValidationHandlerMixin<ParentT>::addDestroyedFunctor(
151 std::string createSymbol)
153 ChangedFunctorCallback oTmp;
156 oTmp._createSymbol = createSymbol;
158 _mfDestroyedFunctors.push_back(oTmp);
161 template <class ParentT>
162 template<class FunctorT> inline
163 void TraversalValidationHandlerMixin<ParentT>::subDestroyedFunctor(
166 MFChangedFunctorCallback::iterator cfIt =
167 _mfDestroyedFunctors.begin();
169 MFChangedFunctorCallback::const_iterator cfEnd=
170 _mfDestroyedFunctors.end();
172 for(; cfIt != cfEnd; ++cfIt)
174 if(cfIt->_func == func)
179 _mfDestroyedFunctors.erase(cfIt);
182 template <class ParentT>
183 template<class FunctorT> inline
184 bool TraversalValidationHandlerMixin<ParentT>::hasDestroyedFunctor(
187 bool returnValue = false;
189 MFChangedFunctorCallback::iterator cfIt =
190 _mfDestroyedFunctors.begin();
192 MFChangedFunctorCallback::const_iterator cfEnd=
193 _mfDestroyedFunctors.end();
196 for(; cfIt != cfEnd; ++cfIt)
198 if(cfIt->_func == func)
207 template <class ParentT> inline
208 void TraversalValidationHandlerMixin<ParentT>::clearDestroyedFunctors(void)
210 _mfDestroyedFunctors.clear();
213 template <class ParentT>
214 template<class DataSlotHandlerT> inline
215 void TraversalValidationHandlerMixin<ParentT>::clearDestroyedFunctorFor(
216 DataSlotHandlerT *pHandler)
218 this->subDestroyedFunctor(boost::bind(&DataSlotHandlerT::clearData,
225 /*-------------------------------------------------------------------------*/
228 template <class ParentT> inline
229 void TraversalValidationHandlerMixin<ParentT>::setUpdateMode(UpdateMode eMode)
231 Inherited::editSField(UpdateModeFieldMask);
233 _sfUpdateMode.setValue(eMode);
236 template <class ParentT> inline
237 UInt32 TraversalValidationHandlerMixin<ParentT>::getUpdateMode(void) const
239 return _sfUpdateMode.getValue();
242 template <class ParentT> inline
243 SFUInt32 *TraversalValidationHandlerMixin<ParentT>::editSFUpdateMode(void)
245 Inherited::editSField(UpdateModeFieldMask);
247 return &_sfUpdateMode;
250 template <class ParentT> inline
252 TraversalValidationHandlerMixin<ParentT>::getSFUpdateMode(void) const
254 return &_sfUpdateMode;
257 /*-------------------------------------------------------------------------*/
260 template <class ParentT> inline
261 SizeT TraversalValidationHandlerMixin<ParentT>::getBinSize(
262 ConstFieldMaskArg whichField)
264 SizeT returnValue = Inherited::getBinSize(whichField);
266 if(FieldBits::NoField != (UpdateModeFieldMask & whichField))
268 returnValue += _sfUpdateMode.getBinSize();
270 if(FieldBits::NoField != (RequestRunFieldMask & whichField))
272 returnValue += _sfRequestRun.getBinSize();
274 if(FieldBits::NoField != (DestroyedFunctorsFieldMask & whichField))
276 returnValue += _mfDestroyedFunctors.getBinSize();
282 template <class ParentT> inline
283 void TraversalValidationHandlerMixin<ParentT>::copyToBin(
284 BinaryDataHandler &pMem, ConstFieldMaskArg whichField)
286 Inherited::copyToBin(pMem, whichField);
288 if(FieldBits::NoField != (UpdateModeFieldMask & whichField))
290 _sfUpdateMode.copyToBin(pMem);
292 if(FieldBits::NoField != (RequestRunFieldMask & whichField))
294 _sfRequestRun.copyToBin(pMem);
296 if(FieldBits::NoField != (DestroyedFunctorsFieldMask & whichField))
298 _mfDestroyedFunctors.copyToBin(pMem);
302 template <class ParentT> inline
303 void TraversalValidationHandlerMixin<ParentT>::copyFromBin(
304 BinaryDataHandler &pMem, ConstFieldMaskArg whichField)
306 Inherited::copyFromBin(pMem, whichField);
308 if(FieldBits::NoField != (UpdateModeFieldMask & whichField))
310 Self::editSField(UpdateModeFieldMask);
312 _sfUpdateMode.copyFromBin(pMem);
314 if(FieldBits::NoField != (RequestRunFieldMask & whichField))
316 _sfRequestRun.copyFromBin(pMem);
318 if(FieldBits::NoField != (DestroyedFunctorsFieldMask & whichField))
320 Self::editMField(DestroyedFunctorsFieldMask, _mfDestroyedFunctors);
322 _mfDestroyedFunctors.copyFromBin(pMem);
326 /*-------------------------------------------------------------------------*/
330 /*-------------------------------------------------------------------------*/
333 template <class ParentT> inline
334 TraversalValidationHandlerMixin<ParentT>::TraversalValidationHandlerMixin(void):
338 _sfUpdateMode (PerTraversal),
340 _mfDestroyedFunctors( )
343 _tmpStatus = StageValidator::Finished;
347 template <class ParentT> inline
348 TraversalValidationHandlerMixin<ParentT>::TraversalValidationHandlerMixin(
349 const Self &source) :
354 _sfUpdateMode (source._sfUpdateMode ),
355 _sfRequestRun (source._sfRequestRun ),
356 _mfDestroyedFunctors(source._mfDestroyedFunctors)
359 _tmpStatus = StageValidator::Finished;
363 template <class ParentT> inline
364 TraversalValidationHandlerMixin<ParentT>::~TraversalValidationHandlerMixin(void)
368 template <class ParentT> inline
369 void TraversalValidationHandlerMixin<ParentT>::dump(
371 const BitVector bvFlags ) const
375 template <class ParentT> inline
377 TraversalValidationHandlerMixin<ParentT>::editHandleUpdateMode(void)
379 SFUInt32::EditHandlePtr returnValue(
380 new SFUInt32::EditHandle(
382 this->getType().getFieldDesc(UpdateModeFieldId),
385 Self::editSField(UpdateModeFieldMask);
390 template <class ParentT> inline
392 TraversalValidationHandlerMixin<ParentT>::getHandleUpdateMode(void) const
394 SFUInt32::GetHandlePtr returnValue(
395 new SFUInt32::GetHandle(
397 this->getType().getFieldDesc(UpdateModeFieldId),
398 const_cast<Self *>(this)));
403 template <class ParentT> inline
405 TraversalValidationHandlerMixin<ParentT>::getHandleRequestRun(void) const
407 SFOSGAny::GetHandlePtr returnValue(
408 new SFOSGAny::GetHandle(
410 this->getType().getFieldDesc(RequestRunFieldId),
411 const_cast<Self *>(this)));
416 template <class ParentT> inline
418 TraversalValidationHandlerMixin<ParentT>::getHandleDestroyedFunctors(
421 MFChangedFunctorCallback::GetHandlePtr returnValue(
422 new MFChangedFunctorCallback::GetHandle(
423 &_mfDestroyedFunctors,
424 this->getType().getFieldDesc(DestroyedFunctorsFieldId),
425 const_cast<Self *>(this)));
430 template <class ParentT> inline
432 TraversalValidationHandlerMixin<ParentT>::editHandleDestroyedFunctors(void)
434 MFChangedFunctorCallback::EditHandlePtr returnValue(
435 new MFChangedFunctorCallback::EditHandle(
436 &_mfDestroyedFunctors,
437 this->getType().getFieldDesc(DestroyedFunctorsFieldId),
440 Self::editMField(DestroyedFunctorsFieldMask, _mfDestroyedFunctors);
445 /*-------------------------------------------------------------------------*/
449 #ifdef OSG_MT_CPTR_ASPECT
450 template <class ParentT> inline
451 void TraversalValidationHandlerMixin<ParentT>::execSync(
453 ConstFieldMaskArg whichField,
454 AspectOffsetStore &oOffsets,
455 ConstFieldMaskArg syncMode ,
456 const UInt32 uiSyncInfo)
458 Inherited::execSync(pFrom, whichField, oOffsets, syncMode, uiSyncInfo);
460 if(FieldBits::NoField != (UpdateModeFieldMask & whichField))
462 _sfUpdateMode.syncWith(pFrom->_sfUpdateMode);
464 if(FieldBits::NoField != (RequestRunFieldMask & whichField))
466 _sfRequestRun.syncWith(pFrom->_sfRequestRun);
471 template <class ParentT> inline
472 void TraversalValidationHandlerMixin<ParentT>::onCreateAspect(
473 const Self *createAspect,
476 Inherited::onCreateAspect(createAspect, source);
479 if(GlobalSystemState == OSG::Running)
481 _iDataSlotId = createAspect->_iDataSlotId;
482 _iElementId = createAspect->_iElementId;
486 template <class ParentT> inline
487 void TraversalValidationHandlerMixin<ParentT>::onCreate(const Self *source)
489 Inherited::onCreate(source);
492 if(GlobalSystemState == OSG::Running)
494 _iDataSlotId = DataSlotIdPool::the()->create();
495 _iElementId = ElementIdPool ::the()->create();
499 template <class ParentT> inline
500 void TraversalValidationHandlerMixin<ParentT>::onDestroy(UInt32 uiContainerId)
502 Inherited::onDestroy(uiContainerId);
505 if(GlobalSystemState == OSG::Running)
507 DataSlotIdPool::the()->release(_iDataSlotId);
508 ElementIdPool ::the()->release(_iElementId );
512 template <class ParentT> inline
513 void TraversalValidationHandlerMixin<ParentT>::onDestroyAspect(
514 UInt32 uiContainerId,
517 Inherited::onDestroy(uiContainerId);
520 if(GlobalSystemState == OSG::Running)
522 MFChangedFunctorCallback::iterator cfIt =
523 _mfDestroyedFunctors.begin();
525 MFChangedFunctorCallback::const_iterator cfEnd=
526 _mfDestroyedFunctors.end();
528 for(; cfIt != cfEnd; ++cfIt)
531 (cfIt->_func)(this, 0x0000, ChangedOrigin::External);
536 /*-------------------------------------------------------------------------*/
539 /*-------------------------------------------------------------------------*/