1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2013 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, carsten_neumann@gmx.net *
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 /*****************************************************************************\
40 *****************************************************************************
42 ** This file is automatically generated. **
44 ** Any changes made to this file WILL be lost when it is **
45 ** regenerated, which can become necessary at any time. **
47 ** Do not change this file, changes should be done in the derived **
48 ** class SwitchMaterial!
50 *****************************************************************************
51 \*****************************************************************************/
57 #pragma warning(disable: 4355) // turn off 'this' : used in base member initializer list warning
58 #pragma warning(disable: 4290) // disable exception specification warning
61 #include "OSGConfig.h"
65 #include "OSGMaterial.h" // Materials Class
67 #include "OSGSwitchMaterialBase.h"
68 #include "OSGSwitchMaterial.h"
70 #include <boost/bind.hpp>
74 /***************************************************************************\
76 \***************************************************************************/
78 /*! \class OSG::SwitchMaterial
79 Material that allows selection of one of the materials in the _mfMaterials
80 field based on the value of the _sfChoice field.
83 /***************************************************************************\
84 * Field Documentation *
85 \***************************************************************************/
87 /*! \var Material * SwitchMaterialBase::_mfMaterials
88 Materials to choose from.
91 /*! \var UInt32 SwitchMaterialBase::_sfChoice
92 The material to actually use for drawing.
96 /***************************************************************************\
97 * FieldType/FieldTrait Instantiation *
98 \***************************************************************************/
100 #if !defined(OSG_DO_DOC) || defined(OSG_DOC_DEV)
101 PointerType FieldTraits
<SwitchMaterial
*, nsOSG
>::_type(
103 "CompositeMaterialPtr",
104 SwitchMaterial::getClassType(),
108 OSG_FIELDTRAITS_GETTYPE_NS(SwitchMaterial
*, nsOSG
)
110 OSG_EXPORT_PTR_SFIELD_FULL(PointerSField
,
114 OSG_EXPORT_PTR_MFIELD_FULL(PointerMField
,
118 /***************************************************************************\
119 * Field Description *
120 \***************************************************************************/
122 void SwitchMaterialBase::classDescInserter(TypeObject
&oType
)
124 FieldDescriptionBase
*pDesc
= NULL
;
127 pDesc
= new MFUnrecMaterialPtr::Description(
128 MFUnrecMaterialPtr::getClassType(),
130 "Materials to choose from.\n",
131 MaterialsFieldId
, MaterialsFieldMask
,
133 (Field::MFDefaultFlags
| Field::FStdAccess
),
134 static_cast<FieldEditMethodSig
>(&SwitchMaterial::editHandleMaterials
),
135 static_cast<FieldGetMethodSig
>(&SwitchMaterial::getHandleMaterials
));
137 oType
.addInitialDesc(pDesc
);
139 pDesc
= new SFUInt32::Description(
140 SFUInt32::getClassType(),
142 "The material to actually use for drawing.\n",
143 ChoiceFieldId
, ChoiceFieldMask
,
145 (Field::SFDefaultFlags
| Field::FStdAccess
),
146 static_cast<FieldEditMethodSig
>(&SwitchMaterial::editHandleChoice
),
147 static_cast<FieldGetMethodSig
>(&SwitchMaterial::getHandleChoice
));
149 oType
.addInitialDesc(pDesc
);
153 SwitchMaterialBase::TypeObject
SwitchMaterialBase::_type(
154 SwitchMaterialBase::getClassname(),
155 Inherited::getClassname(),
158 reinterpret_cast<PrototypeCreateF
>(&SwitchMaterialBase::createEmptyLocal
),
159 reinterpret_cast<InitContainerF
>(&SwitchMaterial::initMethod
),
160 reinterpret_cast<ExitContainerF
>(&SwitchMaterial::exitMethod
),
161 reinterpret_cast<InitalInsertDescFunc
>(
162 reinterpret_cast<void *>(&SwitchMaterial::classDescInserter
)),
165 "<?xml version=\"1.0\"?>\n"
168 " name=\"SwitchMaterial\"\n"
169 " parent=\"CompositeMaterial\"\n"
170 " library=\"System\"\n"
171 " pointerfieldtypes=\"both\"\n"
172 " structure=\"concrete\"\n"
173 " systemcomponent=\"true\"\n"
174 " parentsystemcomponent=\"true\"\n"
175 " decoratable=\"false\"\n"
176 " useLocalIncludes=\"false\"\n"
177 " docGroupBase=\"GrpSystemMaterial\"\n"
179 " Material that allows selection of one of the materials in the _mfMaterials\n"
180 " field based on the value of the _sfChoice field.\n"
182 "\t name=\"materials\"\n"
183 "\t type=\"MaterialPtr\"\n"
184 "\t cardinality=\"multi\"\n"
185 "\t visibility=\"external\"\n"
186 "\t access=\"public\"\n"
188 "\tMaterials to choose from.\n"
191 "\t name=\"choice\"\n"
192 "\t type=\"UInt32\"\n"
193 "\t cardinality=\"single\"\n"
194 "\t visibility=\"external\"\n"
195 "\t access=\"public\"\n"
197 "\tThe material to actually use for drawing.\n"
199 "</FieldContainer>\n",
200 "Material that allows selection of one of the materials in the _mfMaterials\n"
201 "field based on the value of the _sfChoice field.\n"
204 /*------------------------------ get -----------------------------------*/
206 FieldContainerType
&SwitchMaterialBase::getType(void)
211 const FieldContainerType
&SwitchMaterialBase::getType(void) const
216 UInt32
SwitchMaterialBase::getContainerSize(void) const
218 return sizeof(SwitchMaterial
);
221 /*------------------------- decorator get ------------------------------*/
224 //! Get the SwitchMaterial::_mfMaterials field.
225 const MFUnrecMaterialPtr
*SwitchMaterialBase::getMFMaterials(void) const
227 return &_mfMaterials
;
230 MFUnrecMaterialPtr
*SwitchMaterialBase::editMFMaterials (void)
232 editMField(MaterialsFieldMask
, _mfMaterials
);
234 return &_mfMaterials
;
236 Material
* SwitchMaterialBase::getMaterials(const UInt32 index
) const
238 return _mfMaterials
[index
];
241 SFUInt32
*SwitchMaterialBase::editSFChoice(void)
243 editSField(ChoiceFieldMask
);
248 const SFUInt32
*SwitchMaterialBase::getSFChoice(void) const
256 void SwitchMaterialBase::pushToMaterials(Material
* const value
)
258 editMField(MaterialsFieldMask
, _mfMaterials
);
260 _mfMaterials
.push_back(value
);
263 void SwitchMaterialBase::assignMaterials(const MFUnrecMaterialPtr
&value
)
265 MFUnrecMaterialPtr::const_iterator elemIt
=
267 MFUnrecMaterialPtr::const_iterator elemEnd
=
270 static_cast<SwitchMaterial
*>(this)->clearMaterials();
272 while(elemIt
!= elemEnd
)
274 this->pushToMaterials(*elemIt
);
280 void SwitchMaterialBase::removeFromMaterials(UInt32 uiIndex
)
282 if(uiIndex
< _mfMaterials
.size())
284 editMField(MaterialsFieldMask
, _mfMaterials
);
286 _mfMaterials
.erase(uiIndex
);
290 void SwitchMaterialBase::removeObjFromMaterials(Material
* const value
)
292 Int32 iElemIdx
= _mfMaterials
.findIndex(value
);
296 editMField(MaterialsFieldMask
, _mfMaterials
);
298 _mfMaterials
.erase(iElemIdx
);
301 void SwitchMaterialBase::clearMaterials(void)
303 editMField(MaterialsFieldMask
, _mfMaterials
);
306 _mfMaterials
.clear();
311 /*------------------------------ access -----------------------------------*/
313 SizeT
SwitchMaterialBase::getBinSize(ConstFieldMaskArg whichField
)
315 SizeT returnValue
= Inherited::getBinSize(whichField
);
317 if(FieldBits::NoField
!= (MaterialsFieldMask
& whichField
))
319 returnValue
+= _mfMaterials
.getBinSize();
321 if(FieldBits::NoField
!= (ChoiceFieldMask
& whichField
))
323 returnValue
+= _sfChoice
.getBinSize();
329 void SwitchMaterialBase::copyToBin(BinaryDataHandler
&pMem
,
330 ConstFieldMaskArg whichField
)
332 Inherited::copyToBin(pMem
, whichField
);
334 if(FieldBits::NoField
!= (MaterialsFieldMask
& whichField
))
336 _mfMaterials
.copyToBin(pMem
);
338 if(FieldBits::NoField
!= (ChoiceFieldMask
& whichField
))
340 _sfChoice
.copyToBin(pMem
);
344 void SwitchMaterialBase::copyFromBin(BinaryDataHandler
&pMem
,
345 ConstFieldMaskArg whichField
)
347 Inherited::copyFromBin(pMem
, whichField
);
349 if(FieldBits::NoField
!= (MaterialsFieldMask
& whichField
))
351 editMField(MaterialsFieldMask
, _mfMaterials
);
352 _mfMaterials
.copyFromBin(pMem
);
354 if(FieldBits::NoField
!= (ChoiceFieldMask
& whichField
))
356 editSField(ChoiceFieldMask
);
357 _sfChoice
.copyFromBin(pMem
);
361 //! create a new instance of the class
362 SwitchMaterialTransitPtr
SwitchMaterialBase::createLocal(BitVector bFlags
)
364 SwitchMaterialTransitPtr fc
;
366 if(getClassType().getPrototype() != NULL
)
368 FieldContainerTransitPtr tmpPtr
=
369 getClassType().getPrototype()-> shallowCopyLocal(bFlags
);
371 fc
= dynamic_pointer_cast
<SwitchMaterial
>(tmpPtr
);
377 //! create a new instance of the class, copy the container flags
378 SwitchMaterialTransitPtr
SwitchMaterialBase::createDependent(BitVector bFlags
)
380 SwitchMaterialTransitPtr fc
;
382 if(getClassType().getPrototype() != NULL
)
384 FieldContainerTransitPtr tmpPtr
=
385 getClassType().getPrototype()-> shallowCopyDependent(bFlags
);
387 fc
= dynamic_pointer_cast
<SwitchMaterial
>(tmpPtr
);
393 //! create a new instance of the class
394 SwitchMaterialTransitPtr
SwitchMaterialBase::create(void)
396 SwitchMaterialTransitPtr fc
;
398 if(getClassType().getPrototype() != NULL
)
400 FieldContainerTransitPtr tmpPtr
=
401 getClassType().getPrototype()-> shallowCopy();
403 fc
= dynamic_pointer_cast
<SwitchMaterial
>(tmpPtr
);
409 SwitchMaterial
*SwitchMaterialBase::createEmptyLocal(BitVector bFlags
)
411 SwitchMaterial
*returnValue
;
413 newPtr
<SwitchMaterial
>(returnValue
, bFlags
);
415 returnValue
->_pFieldFlags
->_bNamespaceMask
&= ~bFlags
;
420 //! create an empty new instance of the class, do not copy the prototype
421 SwitchMaterial
*SwitchMaterialBase::createEmpty(void)
423 SwitchMaterial
*returnValue
;
425 newPtr
<SwitchMaterial
>(returnValue
, Thread::getCurrentLocalFlags());
427 returnValue
->_pFieldFlags
->_bNamespaceMask
&=
428 ~Thread::getCurrentLocalFlags();
434 FieldContainerTransitPtr
SwitchMaterialBase::shallowCopyLocal(
435 BitVector bFlags
) const
437 SwitchMaterial
*tmpPtr
;
439 newPtr(tmpPtr
, dynamic_cast<const SwitchMaterial
*>(this), bFlags
);
441 FieldContainerTransitPtr
returnValue(tmpPtr
);
443 tmpPtr
->_pFieldFlags
->_bNamespaceMask
&= ~bFlags
;
448 FieldContainerTransitPtr
SwitchMaterialBase::shallowCopyDependent(
449 BitVector bFlags
) const
451 SwitchMaterial
*tmpPtr
;
453 newPtr(tmpPtr
, dynamic_cast<const SwitchMaterial
*>(this), ~bFlags
);
455 FieldContainerTransitPtr
returnValue(tmpPtr
);
457 tmpPtr
->_pFieldFlags
->_bNamespaceMask
= bFlags
;
462 FieldContainerTransitPtr
SwitchMaterialBase::shallowCopy(void) const
464 SwitchMaterial
*tmpPtr
;
467 dynamic_cast<const SwitchMaterial
*>(this),
468 Thread::getCurrentLocalFlags());
470 tmpPtr
->_pFieldFlags
->_bNamespaceMask
&= ~Thread::getCurrentLocalFlags();
472 FieldContainerTransitPtr
returnValue(tmpPtr
);
480 /*------------------------- constructors ----------------------------------*/
482 SwitchMaterialBase::SwitchMaterialBase(void) :
489 SwitchMaterialBase::SwitchMaterialBase(const SwitchMaterialBase
&source
) :
492 _sfChoice (source
._sfChoice
)
497 /*-------------------------- destructors ----------------------------------*/
499 SwitchMaterialBase::~SwitchMaterialBase(void)
503 void SwitchMaterialBase::onCreate(const SwitchMaterial
*source
)
505 Inherited::onCreate(source
);
509 SwitchMaterial
*pThis
= static_cast<SwitchMaterial
*>(this);
511 MFUnrecMaterialPtr::const_iterator MaterialsIt
=
512 source
->_mfMaterials
.begin();
513 MFUnrecMaterialPtr::const_iterator MaterialsEnd
=
514 source
->_mfMaterials
.end ();
516 while(MaterialsIt
!= MaterialsEnd
)
518 pThis
->pushToMaterials(*MaterialsIt
);
525 GetFieldHandlePtr
SwitchMaterialBase::getHandleMaterials (void) const
527 MFUnrecMaterialPtr::GetHandlePtr
returnValue(
528 new MFUnrecMaterialPtr::GetHandle(
530 this->getType().getFieldDesc(MaterialsFieldId
),
531 const_cast<SwitchMaterialBase
*>(this)));
536 EditFieldHandlePtr
SwitchMaterialBase::editHandleMaterials (void)
538 MFUnrecMaterialPtr::EditHandlePtr
returnValue(
539 new MFUnrecMaterialPtr::EditHandle(
541 this->getType().getFieldDesc(MaterialsFieldId
),
544 returnValue
->setAddMethod(
545 boost::bind(&SwitchMaterial::pushToMaterials
,
546 static_cast<SwitchMaterial
*>(this), _1
));
547 returnValue
->setRemoveMethod(
548 boost::bind(&SwitchMaterial::removeFromMaterials
,
549 static_cast<SwitchMaterial
*>(this), _1
));
550 returnValue
->setRemoveObjMethod(
551 boost::bind(&SwitchMaterial::removeObjFromMaterials
,
552 static_cast<SwitchMaterial
*>(this), _1
));
553 returnValue
->setClearMethod(
554 boost::bind(&SwitchMaterial::clearMaterials
,
555 static_cast<SwitchMaterial
*>(this)));
557 editMField(MaterialsFieldMask
, _mfMaterials
);
562 GetFieldHandlePtr
SwitchMaterialBase::getHandleChoice (void) const
564 SFUInt32::GetHandlePtr
returnValue(
565 new SFUInt32::GetHandle(
567 this->getType().getFieldDesc(ChoiceFieldId
),
568 const_cast<SwitchMaterialBase
*>(this)));
573 EditFieldHandlePtr
SwitchMaterialBase::editHandleChoice (void)
575 SFUInt32::EditHandlePtr
returnValue(
576 new SFUInt32::EditHandle(
578 this->getType().getFieldDesc(ChoiceFieldId
),
582 editSField(ChoiceFieldMask
);
588 #ifdef OSG_MT_CPTR_ASPECT
589 void SwitchMaterialBase::execSyncV( FieldContainer
&oFrom
,
590 ConstFieldMaskArg whichField
,
591 AspectOffsetStore
&oOffsets
,
592 ConstFieldMaskArg syncMode
,
593 const UInt32 uiSyncInfo
)
595 SwitchMaterial
*pThis
= static_cast<SwitchMaterial
*>(this);
597 pThis
->execSync(static_cast<SwitchMaterial
*>(&oFrom
),
606 #ifdef OSG_MT_CPTR_ASPECT
607 FieldContainer
*SwitchMaterialBase::createAspectCopy(
608 const FieldContainer
*pRefAspect
) const
610 SwitchMaterial
*returnValue
;
612 newAspectCopy(returnValue
,
613 dynamic_cast<const SwitchMaterial
*>(pRefAspect
),
614 dynamic_cast<const SwitchMaterial
*>(this));
620 void SwitchMaterialBase::resolveLinks(void)
622 Inherited::resolveLinks();
624 static_cast<SwitchMaterial
*>(this)->clearMaterials();