changed: gcc8 base update
[opensg.git] / Source / System / Material / Base / OSGSwitchMaterialBase.cpp
blob6de6fd7180f3793074cf221e0bb438d8e5aecefd
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2013 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, carsten_neumann@gmx.net *
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 *****************************************************************************
41 ** **
42 ** This file is automatically generated. **
43 ** **
44 ** Any changes made to this file WILL be lost when it is **
45 ** regenerated, which can become necessary at any time. **
46 ** **
47 ** Do not change this file, changes should be done in the derived **
48 ** class SwitchMaterial!
49 ** **
50 *****************************************************************************
51 \*****************************************************************************/
53 #include <cstdlib>
54 #include <cstdio>
56 #ifdef WIN32
57 #pragma warning(disable: 4355) // turn off 'this' : used in base member initializer list warning
58 #pragma warning(disable: 4290) // disable exception specification warning
59 #endif
61 #include "OSGConfig.h"
65 #include "OSGMaterial.h" // Materials Class
67 #include "OSGSwitchMaterialBase.h"
68 #include "OSGSwitchMaterial.h"
70 #include <boost/bind.hpp>
72 OSG_BEGIN_NAMESPACE
74 /***************************************************************************\
75 * Description *
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(
102 "SwitchMaterialPtr",
103 "CompositeMaterialPtr",
104 SwitchMaterial::getClassType(),
105 nsOSG);
106 #endif
108 OSG_FIELDTRAITS_GETTYPE_NS(SwitchMaterial *, nsOSG)
110 OSG_EXPORT_PTR_SFIELD_FULL(PointerSField,
111 SwitchMaterial *,
112 nsOSG)
114 OSG_EXPORT_PTR_MFIELD_FULL(PointerMField,
115 SwitchMaterial *,
116 nsOSG)
118 /***************************************************************************\
119 * Field Description *
120 \***************************************************************************/
122 void SwitchMaterialBase::classDescInserter(TypeObject &oType)
124 FieldDescriptionBase *pDesc = NULL;
127 pDesc = new MFUnrecMaterialPtr::Description(
128 MFUnrecMaterialPtr::getClassType(),
129 "materials",
130 "Materials to choose from.\n",
131 MaterialsFieldId, MaterialsFieldMask,
132 false,
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(),
141 "choice",
142 "The material to actually use for drawing.\n",
143 ChoiceFieldId, ChoiceFieldMask,
144 false,
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(),
156 "NULL",
157 nsOSG, //Namespace
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)),
163 false,
165 "<?xml version=\"1.0\"?>\n"
166 "\n"
167 "<FieldContainer\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"
178 " >\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"
181 " <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"
187 "\t >\n"
188 "\tMaterials to choose from.\n"
189 " </Field>\n"
190 " <Field\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"
196 "\t >\n"
197 "\tThe material to actually use for drawing.\n"
198 " </Field>\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)
208 return _type;
211 const FieldContainerType &SwitchMaterialBase::getType(void) const
213 return _type;
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);
245 return &_sfChoice;
248 const SFUInt32 *SwitchMaterialBase::getSFChoice(void) const
250 return &_sfChoice;
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 =
266 value.begin();
267 MFUnrecMaterialPtr::const_iterator elemEnd =
268 value.end ();
270 static_cast<SwitchMaterial *>(this)->clearMaterials();
272 while(elemIt != elemEnd)
274 this->pushToMaterials(*elemIt);
276 ++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);
294 if(iElemIdx != -1)
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();
326 return returnValue;
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);
374 return fc;
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);
390 return fc;
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);
406 return fc;
409 SwitchMaterial *SwitchMaterialBase::createEmptyLocal(BitVector bFlags)
411 SwitchMaterial *returnValue;
413 newPtr<SwitchMaterial>(returnValue, bFlags);
415 returnValue->_pFieldFlags->_bNamespaceMask &= ~bFlags;
417 return returnValue;
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();
430 return returnValue;
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;
445 return returnValue;
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;
459 return returnValue;
462 FieldContainerTransitPtr SwitchMaterialBase::shallowCopy(void) const
464 SwitchMaterial *tmpPtr;
466 newPtr(tmpPtr,
467 dynamic_cast<const SwitchMaterial *>(this),
468 Thread::getCurrentLocalFlags());
470 tmpPtr->_pFieldFlags->_bNamespaceMask &= ~Thread::getCurrentLocalFlags();
472 FieldContainerTransitPtr returnValue(tmpPtr);
474 return returnValue;
480 /*------------------------- constructors ----------------------------------*/
482 SwitchMaterialBase::SwitchMaterialBase(void) :
483 Inherited(),
484 _mfMaterials (),
485 _sfChoice ()
489 SwitchMaterialBase::SwitchMaterialBase(const SwitchMaterialBase &source) :
490 Inherited(source),
491 _mfMaterials (),
492 _sfChoice (source._sfChoice )
497 /*-------------------------- destructors ----------------------------------*/
499 SwitchMaterialBase::~SwitchMaterialBase(void)
503 void SwitchMaterialBase::onCreate(const SwitchMaterial *source)
505 Inherited::onCreate(source);
507 if(source != NULL)
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);
520 ++MaterialsIt;
525 GetFieldHandlePtr SwitchMaterialBase::getHandleMaterials (void) const
527 MFUnrecMaterialPtr::GetHandlePtr returnValue(
528 new MFUnrecMaterialPtr::GetHandle(
529 &_mfMaterials,
530 this->getType().getFieldDesc(MaterialsFieldId),
531 const_cast<SwitchMaterialBase *>(this)));
533 return returnValue;
536 EditFieldHandlePtr SwitchMaterialBase::editHandleMaterials (void)
538 MFUnrecMaterialPtr::EditHandlePtr returnValue(
539 new MFUnrecMaterialPtr::EditHandle(
540 &_mfMaterials,
541 this->getType().getFieldDesc(MaterialsFieldId),
542 this));
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);
559 return returnValue;
562 GetFieldHandlePtr SwitchMaterialBase::getHandleChoice (void) const
564 SFUInt32::GetHandlePtr returnValue(
565 new SFUInt32::GetHandle(
566 &_sfChoice,
567 this->getType().getFieldDesc(ChoiceFieldId),
568 const_cast<SwitchMaterialBase *>(this)));
570 return returnValue;
573 EditFieldHandlePtr SwitchMaterialBase::editHandleChoice (void)
575 SFUInt32::EditHandlePtr returnValue(
576 new SFUInt32::EditHandle(
577 &_sfChoice,
578 this->getType().getFieldDesc(ChoiceFieldId),
579 this));
582 editSField(ChoiceFieldMask);
584 return returnValue;
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),
598 whichField,
599 oOffsets,
600 syncMode,
601 uiSyncInfo);
603 #endif
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));
616 return returnValue;
618 #endif
620 void SwitchMaterialBase::resolveLinks(void)
622 Inherited::resolveLinks();
624 static_cast<SwitchMaterial *>(this)->clearMaterials();
630 OSG_END_NAMESPACE