changed: auto add updateData callback to stages so that stagedata can be updated...
[opensg.git] / Source / System / FieldContainer / Mixins / OSGStageHandlerMixin.inl
blob5916ec598527b3d9923dd551c29a359172bdf03b
1 /*---------------------------------------------------------------------------*\
2  *                                OpenSG                                     *
3  *                                                                           *
4  *                                                                           *
5  *           Copyright (C) 2003 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 OSG_BEGIN_NAMESPACE
41 template <class ParentT> inline
42 void StageHandlerMixin<ParentT>::changed(ConstFieldMaskArg whichField, 
43                                          UInt32            origin,
44                                          BitVector         details)
46     Inherited::changed(whichField, origin, details);
49 template <class ParentT> inline
50 typename StageHandlerMixin<ParentT>::ValidationStatus 
51     StageHandlerMixin<ParentT>::validateOnEnter(
52         RenderActionBase *pAction)
54     TraversalValidator::ValidationStatus returnValue = Self::validate(pAction);
56     StageDataUnrecPtr pData = 
57         pAction->template getData<StageData *>(this->_iDataSlotId);
59     if(pData == NULL)
60     {
61         pData = StageData::createLocal();
63         pAction->setData(pData, this->_iDataSlotId);
64     }
66     if(returnValue == TraversalValidator::Finished)
67     {
68         if(pData != NULL)
69         {           
70             Int32 iPartBegin = pData->getPartitionRangeBegin();
71             Int32 iPartEnd   = pData->getPartitionRangeEnd  ();
72             
73             while(iPartBegin <= iPartEnd)
74             {
75                 pAction->readdPartitionByIndex(iPartBegin);
76                 
77                 ++iPartBegin;
78             }
79         }
80     }
82     return returnValue;
85 template <class ParentT> inline
86 typename StageHandlerMixin<ParentT>::ValidationStatus 
87     StageHandlerMixin<ParentT>::validateOnLeave(
88         RenderActionBase *pAction)
90     return Self::validate(pAction);
93 template <class ParentT> inline
94 void StageHandlerMixin<ParentT>::pushPartition(
95     RenderActionBase          *pAction,
96     UInt32                     uiCopyOnPush, 
97     RenderPartitionBase::Mode  eMode)
99     StageData *pData = 
100         pAction->template getData<StageData *>(this->_iDataSlotId);
102     pAction->pushPartition(uiCopyOnPush, eMode);
104     if(pData != NULL)
105     {
106         if(pData->getGroupMode() == NoPartitionGroup)
107         {
108             pData->setPartitionRangeBegin(pAction->getActivePartitionIdx());
109         }
111     }
114 template <class ParentT> inline
115 void StageHandlerMixin<ParentT>::popPartition(
116     RenderActionBase *pAction)
118     StageData *pData = 
119         pAction->template getData<StageData *>(this->_iDataSlotId);
121     pAction->popPartition();
123     if(pData != NULL)
124     {
125         if(pData->getGroupMode() == NoPartitionGroup)
126         {
127             pData->setPartitionRangeEnd(pAction->getLastPartitionIdx());
128         }
129     }
132 template <class ParentT> inline
133 void StageHandlerMixin<ParentT>::beginPartitionGroup(
134     RenderActionBase *pAction)
136     StageData *pData = 
137         pAction->template getData<StageData *>(this->_iDataSlotId);
139     if(pData != NULL)
140     {
141         pData->setGroupMode(InPartitionGroup);
142     }
144     pAction->beginPartitionGroup();
146     if(pData != NULL)
147     {
148         pData->setPartitionRangeBegin(pAction->getActivePartitionIdx());
149     }
152 template <class ParentT> inline
153 void StageHandlerMixin<ParentT>::endPartitionGroup(
154     RenderActionBase *pAction)
156     StageData *pData = 
157         pAction->template getData<StageData *>(this->_iDataSlotId);
159     if(pData != NULL)
160     {
161         pData->setGroupMode(NoPartitionGroup);
162     }
164     pAction->endPartitionGroup();
166     if(pData != NULL)
167     {
168         pData->setPartitionRangeEnd(pAction->getLastPartitionIdx());
169     }
172 template <class ParentT> inline
173 void StageHandlerMixin<ParentT>::beginPartitions(
174     RenderActionBase *pAction)
176     StageData *pData = 
177         pAction->template getData<StageData *>(this->_iDataSlotId);
179     if(pData != NULL)
180     {
181         pData->setGroupMode          (InPartitionList                   );
182         pData->setPartitionRangeBegin(pAction->getLastPartitionIdx() + 1);
183     }
186 template <class ParentT> inline
187 void StageHandlerMixin<ParentT>::endPartitions(
188     RenderActionBase *pAction)
190     StageData *pData = 
191         pAction->template getData<StageData *>(this->_iDataSlotId);
193     if(pData != NULL)
194     {
195         pData->setGroupMode        (NoPartitionGroup              );
196         pData->setPartitionRangeEnd(pAction->getLastPartitionIdx());
197     }
200 template <class ParentT> inline
201 void StageHandlerMixin<ParentT>::setData(
202     StageData        *pData, 
203     Int32             iDataSlotId,
204     RenderActionBase *pAction)
206     StageData *pStoredData = 
207         pAction->template getData<StageData *>(this->_iDataSlotId);
209     bool bCheckCallback = false;
211     OSG_ASSERT(iDataSlotId == this->_iDataSlotId);
213     if(pStoredData == NULL)
214     {
215         pAction->setData(pData, this->_iDataSlotId);
216         bCheckCallback = true;
217     }
218     else if(pStoredData != pData)
219     {
220         pData->copyFrom(pStoredData);
222         pAction->setData(pData, this->_iDataSlotId);
223         bCheckCallback = true;
224     }
226     if(bCheckCallback == true)
227     {
228         if(this->hasDestroyedFunctor(
229                boost::bind(&DataSlotHandler::clearData,
230                            pAction,
231                            _1,
232                            _2,
233                            this->_iDataSlotId)) == false)
234         {
235             this->addDestroyedFunctor(
236                 boost::bind(&DataSlotHandler::clearData,
237                             static_cast<DataSlotHandler *>(pAction),
238                             _1,
239                             _2,
240                             this->_iDataSlotId), "");
242             pAction->addDestroyedFunctorFor(
243                 boost::bind(&Self::clearDestroyedFunctorFor,
244                             this,
245                             _1),
246                 this);
247         }
249         if(pData != NULL)
250         {
251             this->addChangedFunctor(
252                 boost::bind(&StageData::updateData, 
253                             pData, 
254                             _1, 
255                             _2,
256                             _3),
257                 "");
258             
259             pData->addChangedFunctor(
260                 boost::bind(&Self::dataDestroyed, 
261                             this, 
262                             _1, 
263                             _2,
264                             _3),
265                 "");
266         }
267         if(pStoredData != NULL)
268         {
269             this->subChangedFunctor(
270                 boost::bind(&StageData::updateData, 
271                             pStoredData, 
272                             _1, 
273                             _2,
274                             _3));
275             
276             pStoredData->subChangedFunctor(
277                 boost::bind(&Self::dataDestroyed, 
278                             this, 
279                             _1, 
280                             _2,
281                             _3));
282          }
283     }
286 /*-------------------------------------------------------------------------*/
287 /*                                Set                                      */
289 /*-------------------------------------------------------------------------*/
290 /* Binary access                                                           */
292 /*-------------------------------------------------------------------------*/
293 /*                             Assignment                                  */
296 /*-------------------------------------------------------------------------*/
297 /*                            Constructors                                 */
299 template <class ParentT> inline
300 StageHandlerMixin<ParentT>::StageHandlerMixin(void) :
301     Inherited()
303     _tmpStatus = TraversalValidator::Finished;
306 template <class ParentT> inline
307 StageHandlerMixin<ParentT>::StageHandlerMixin(
308     const StageHandlerMixin &source) :
310     Inherited(source)
312     _tmpStatus = TraversalValidator::Finished;
315 template <class ParentT> inline
316 StageHandlerMixin<ParentT>::~StageHandlerMixin(void)
320 template <class ParentT> inline
321 void StageHandlerMixin<ParentT>::dataDestroyed(FieldContainer *pCore,
322                                                BitVector       whichField,
323                                                UInt32          origin    )
325     if(whichField == 0x0000)
326     {
327         this->subChangedFunctor(
328             boost::bind(&StageData::updateData, 
329                         pCore, 
330                         _1, 
331                         _2,
332                         _3));
333     }
336 template <class ParentT> inline
337 void StageHandlerMixin<ParentT>::dump(      UInt32    uiIndent,
338                                       const BitVector bvFlags ) const
342 /*-------------------------------------------------------------------------*/
343 /*                             Destructor                                  */
345 /*-------------------------------------------------------------------------*/
346 /*                             Assignment                                  */
348 template <class ParentT> inline
349 Action::ResultE StageHandlerMixin<ParentT>::recurseFromThis(Action *action)
351     Action::ResultE  returnValue = Action::Continue;
353     Node            *pActNode    = action->getActNode  ();
354     FieldContainer  *pActParent  = action->getActParent();
356     if(pActNode != pActParent)
357     {
358         OSG_ASSERT(pActParent == pActNode->getCore());
360         MultiCore *pCore = dynamic_cast<MultiCore *>(pActParent);
362         if(pCore != NULL)
363         {
364             returnValue = action->recurseMultiCoreFrom(pActNode, 
365                                                        pCore,
366                                                        this);
367         }
368         else
369         {
370             returnValue = action->recurseNoCallback(pActNode);
371         }
372     }
373     else
374     {
375         returnValue = action->recurseNoCallback(pActNode);
376     }
378     action->setActNode  (pActNode  );
379     action->setActParent(pActParent);
381     return returnValue;
384 template <class ParentT> inline
385 Action::ResultE StageHandlerMixin<ParentT>::recurseFrom(Action   *action,
386                                                         NodeCore *pFrom )
388     Action::ResultE  returnValue = Action::Continue;
390     Node            *pActNode    = action->getActNode  ();
391     FieldContainer  *pActParent  = action->getActParent();
393     if(pActNode != pActParent)
394     {
395         OSG_ASSERT(pActParent == pActNode->getCore());
397         MultiCore *pCore = dynamic_cast<MultiCore *>(pActParent);
399         if(pCore != NULL)
400         {
401             returnValue = action->recurseMultiCoreFrom(pActNode, 
402                                                        pCore,
403                                                        pFrom);
404         }
405         else
406         {
407             returnValue = action->recurseNoCallback(pActNode);
408         }
409     }
410     else
411     {
412         returnValue = action->recurseNoCallback(pActNode);
413     }
415     action->setActNode  (pActNode  );
416     action->setActParent(pActParent);
418     return returnValue;
421 template <class ParentT> inline
422 Action::ResultE StageHandlerMixin<ParentT>::recurse(Action *action,
423                                                         Node   *node  )
425     Node            *pActNode    = action->getActNode  ();
426     FieldContainer  *pActParent  = action->getActParent();
428     Action::ResultE  returnValue = action->recurse(node);    
430     action->setActNode  (pActNode  );
431     action->setActParent(pActParent);
433     return returnValue;
436 /*-------------------------------------------------------------------------*/
437 /*                             Comparison                                  */
439 OSG_END_NAMESPACE