00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include <cstdlib>
00044 #include <cstdio>
00045
00046 #include "OSGConfig.h"
00047
00048 #include "OSGAttachmentContainer.h"
00049 #include "OSGFieldContainerAttachment.h"
00050 #include "OSGTypeBasePredicates.h"
00051 #include "OSGReflexiveContainerTypePredicates.h"
00052
00053 OSG_BEGIN_NAMESPACE
00054
00055 void AttachmentContainer::classDescInserter(TypeObject &oType)
00056 {
00057 FieldDescriptionBase *pDesc;
00058
00059 typedef SFAttachmentObjPtrMap::Description SFDesc;
00060
00061 pDesc = new SFDesc(
00062 SFAttachmentObjPtrMap::getClassType(),
00063 "attachments",
00064 "List of attachments connected.",
00065 OSG_RC_FIELD_DESC(Attachments),
00066 false,
00067 Field::SFDefaultFlags,
00068 static_cast<FieldEditMethodSig>(&Self::editHandleAttachments),
00069 static_cast<FieldGetMethodSig >(&Self::getHandleAttachments ),
00070 NULL);
00071
00072 oType.addInitialDesc(pDesc);
00073 }
00074
00075 AttachmentContainer::TypeObject AttachmentContainer::_type(
00076 AttachmentContainer::getClassname(),
00077 Inherited ::getClassname(),
00078 NULL,
00079 0,
00080 NULL,
00081 NULL,
00082 (InitalInsertDescFunc) &AttachmentContainer::classDescInserter,
00083 false,
00084 0);
00085
00086
00087
00088
00089 AttachmentContainer::AttachmentContainer(void) :
00090 Inherited (),
00091 _sfAttachments()
00092 {
00093 }
00094
00095 AttachmentContainer::AttachmentContainer(const AttachmentContainer &source) :
00096 Inherited (source ),
00097 _sfAttachments(source._sfAttachments)
00098 {
00099 }
00100
00101
00102
00103 AttachmentContainer::~AttachmentContainer(void)
00104 {
00105 }
00106
00107
00108
00109
00110 OSG_ABSTR_FIELD_CONTAINER_DEF(AttachmentContainer)
00111
00112 #if 0
00113 void AttachmentContainer::pushToField(
00114 FieldContainerPtrConstArg pNewElement,
00115 const UInt32 uiFieldId )
00116 {
00117 Inherited::pushToField(pNewElement, uiFieldId);
00118
00119 if(uiFieldId == AttachmentsFieldId)
00120 {
00121 addAttachment(dynamic_cast<AttachmentObjPtr>(pNewElement));
00122 }
00123 }
00124
00125 void AttachmentContainer::insertIntoMField(
00126 const UInt32 uiIndex,
00127 FieldContainerPtrConstArg pNewElement,
00128 const UInt32 uiFieldId )
00129 {
00130 Inherited::insertIntoMField(uiIndex, pNewElement, uiFieldId);
00131
00132 FWARNING(("AttachmentContainerMixin::insertIntoMField: NIY\n"));
00133 }
00134
00135 void AttachmentContainer::replaceInMField (
00136 const UInt32 uiIndex,
00137 FieldContainerPtrConstArg pNewElement,
00138 const UInt32 uiFieldId )
00139 {
00140 Inherited::replaceInMField(uiIndex, pNewElement, uiFieldId);
00141
00142 FWARNING(("AttachmentContainerMixin::replaceInMField: NIY\n"));
00143 }
00144
00145 void AttachmentContainer::replaceInMField (
00146 FieldContainerPtrConstArg pOldElement,
00147 FieldContainerPtrConstArg pNewElement,
00148 const UInt32 uiFieldId )
00149 {
00150 Inherited::replaceInMField(pOldElement, pNewElement, uiFieldId);
00151
00152 FWARNING(("AttachmentContainerMixin::replaceInMField: NIY\n"));
00153 }
00154
00155 void AttachmentContainer::removeFromMField(
00156 const UInt32 uiIndex,
00157 const UInt32 uiFieldId )
00158 {
00159 Inherited::removeFromMField(uiIndex, uiFieldId);
00160
00161 FWARNING(("AttachmentContainerMixin::removeFromMField: NIY\n"));
00162 }
00163
00164 void AttachmentContainer::removeFromMField(
00165 FieldContainerPtrConstArg pElement,
00166 const UInt32 uiFieldId )
00167 {
00168 Inherited::removeFromMField(pElement, uiFieldId);
00169
00170 FWARNING(("AttachmentContainerMixin::removeFromMField: NIY\n"));
00171 }
00172
00173 void AttachmentContainer::clearField(const UInt32 uiFieldId)
00174 {
00175 Inherited::clearField(uiFieldId);
00176
00177 FWARNING(("AttachmentContainerMixin::clearField: NIY\n"));
00178 }
00179 #endif
00180
00181
00182
00183
00184 UInt32 AttachmentContainer::getBinSize(ConstFieldMaskArg whichField)
00185 {
00186 UInt32 returnValue = Inherited::getBinSize(whichField);
00187
00188 if(FieldBits::NoField != (AttachmentsFieldMask & whichField))
00189 {
00190 returnValue += _sfAttachments.getBinSize();
00191 }
00192
00193 return returnValue;
00194 }
00195
00196 void AttachmentContainer::copyToBin(BinaryDataHandler &pMem,
00197 ConstFieldMaskArg whichField)
00198 {
00199 Inherited::copyToBin(pMem, whichField);
00200
00201 if(FieldBits::NoField != (AttachmentsFieldMask & whichField))
00202 {
00203 _sfAttachments.copyToBin(pMem);
00204 }
00205 }
00206
00207 void AttachmentContainer::copyFromBin(BinaryDataHandler &pMem,
00208 ConstFieldMaskArg whichField)
00209 {
00210 Inherited::copyFromBin(pMem, whichField);
00211
00212 if(FieldBits::NoField != (AttachmentsFieldMask & whichField))
00213 {
00214 _sfAttachments.copyFromBin(pMem);
00215 }
00216 }
00217
00218
00219
00220
00232 void AttachmentContainer::addAttachment(
00233 const AttachmentObjPtr pAttachment,
00234 UInt16 binding)
00235 {
00236 UInt32 key;
00237
00238 if(pAttachment == NullFC)
00239 return;
00240
00241 key = (UInt32 (pAttachment->getGroupId()) << 16) | binding;
00242
00243 addRef(pAttachment);
00244
00245 pAttachment->addParent(this);
00246
00247 Self::editSField(AttachmentsFieldMask);
00248
00249 AttachmentObjPtrMapIt fcI = _sfAttachments.getValue().find(key);
00250
00251 if(fcI != _sfAttachments.getValue().end())
00252 {
00253 (*fcI).second->subParent(this);
00254
00255 subRef((*fcI).second);
00256
00257 (*fcI).second = pAttachment;
00258 }
00259 else
00260 {
00261 _sfAttachments.getValue()[key] = pAttachment;
00262 }
00263 }
00264
00276 void AttachmentContainer::subAttachment(
00277 const AttachmentObjPtr pAttachment,
00278 UInt16 binding)
00279 {
00280 UInt32 key;
00281
00282 AttachmentObjPtrMapIt fcI;
00283
00284 if(pAttachment == NullFC)
00285 return;
00286
00287 key = (UInt32(pAttachment->getGroupId()) << 16) | binding;
00288
00289 Self::editSField(AttachmentsFieldMask);
00290
00291 fcI = _sfAttachments.getValue().find(key);
00292
00293 if(fcI != _sfAttachments.getValue().end())
00294 {
00295 (*fcI).second->subParent(this);
00296
00297 subRef((*fcI).second);
00298
00299 _sfAttachments.getValue().erase(fcI);
00300 }
00301 }
00302
00303
00304 const AttachmentContainer::SFAttachmentObjPtrMap *
00305 AttachmentContainer::getSFAttachments(void) const
00306 {
00307 return &_sfAttachments;
00308 }
00309
00310
00311 void AttachmentContainer::dump( UInt32 uiIndent,
00312 const BitVector bvFlags ) const
00313 {
00314 indentLog(uiIndent, PLOG);
00315 PLOG << "attachments " << std::endl;
00316
00317 indentLog(uiIndent, PLOG);
00318 PLOG << "{" << std::endl;
00319
00320 indentLog(uiIndent, PLOG);
00321 PLOG << "}" << std::endl;
00322 }
00323
00324
00325
00326
00327
00328 #ifdef OSG_MT_CPTR_ASPECT
00329 void AttachmentContainer::execSync(
00330 AttachmentContainer *pFrom,
00331 ConstFieldMaskArg whichField,
00332 AspectOffsetStore &oOffsets,
00333 ConstFieldMaskArg syncMode ,
00334 const UInt32 uiSyncInfo)
00335 {
00336 Inherited::execSync(pFrom, whichField, oOffsets, syncMode, uiSyncInfo);
00337
00338 if(FieldBits::NoField != (AttachmentsFieldMask & whichField))
00339 {
00340 _sfAttachments.syncWith(pFrom->_sfAttachments);
00341 }
00342 }
00343 #endif
00344
00345 void AttachmentContainer::resolveLinks(void)
00346 {
00347 Inherited::resolveLinks();
00348
00349 AttachmentObjPtrMapIt fcI = _sfAttachments.getValue().begin();
00350 AttachmentObjPtrMapIt fcE = _sfAttachments.getValue().end ();
00351
00352 while(fcI != fcE)
00353 {
00354 (*fcI).second->subParent(this);
00355
00356 subRef((*fcI).second);
00357
00358 ++fcI;
00359 }
00360 }
00361
00362 EditFieldHandlePtr AttachmentContainer::editHandleAttachments(void)
00363 {
00364 SFAttachmentObjPtrMap::EditHandlePtr returnValue(
00365 new SFAttachmentObjPtrMap::EditHandle(
00366 &_sfAttachments,
00367 this->getType().getFieldDesc(AttachmentsFieldId)));
00368
00369 editSField(AttachmentsFieldMask);
00370
00371 return returnValue;
00372 }
00373
00374 GetFieldHandlePtr AttachmentContainer::getHandleAttachments(void) const
00375 {
00376 SFAttachmentObjPtrMap::GetHandlePtr returnValue(
00377 new SFAttachmentObjPtrMap::GetHandle(
00378 &_sfAttachments,
00379 this->getType().getFieldDesc(AttachmentsFieldId)));
00380
00381 return returnValue;
00382 }
00383
00384
00385
00386
00387
00388
00389
00405 void cloneAttachments(
00406 AttachmentContainerPtrConstArg src,
00407 AttachmentContainerPtrArg dst,
00408 const std::vector<std::string> &cloneTypeNames,
00409 const std::vector<std::string> &ignoreTypeNames,
00410 const std::vector<std::string> &cloneGroupNames,
00411 const std::vector<std::string> &ignoreGroupNames)
00412 {
00413 std::vector<const ReflexiveContainerType *> cloneTypes;
00414 std::vector<const ReflexiveContainerType *> ignoreTypes;
00415 std::vector<UInt16> cloneGroupIds;
00416 std::vector<UInt16> ignoreGroupIds;
00417
00418 appendTypesVector (cloneTypeNames, cloneTypes );
00419 appendTypesVector (ignoreTypeNames, ignoreTypes );
00420 appendGroupsVector(cloneGroupNames, cloneGroupIds );
00421 appendGroupsVector(ignoreGroupNames, ignoreGroupIds);
00422
00423 cloneAttachments(src, dst, cloneTypes, ignoreTypes,
00424 cloneGroupIds, ignoreGroupIds);
00425 }
00426
00438 void cloneAttachments(
00439 AttachmentContainerPtrConstArg src,
00440 AttachmentContainerPtrArg dst,
00441 const std::vector<UInt16> &cloneGroupIds,
00442 const std::vector<UInt16> &ignoreGroupIds)
00443 {
00444 std::vector<const ReflexiveContainerType *> cloneTypes;
00445 std::vector<const ReflexiveContainerType *> ignoreTypes;
00446
00447 cloneAttachments(src, dst, cloneTypes, ignoreTypes,
00448 cloneGroupIds, ignoreGroupIds);
00449 }
00450
00466 void cloneAttachments(
00467 AttachmentContainerPtrConstArg src,
00468 AttachmentContainerPtrArg dst,
00469 const std::string &cloneTypesString,
00470 const std::string &ignoreTypesString)
00471 {
00472 std::vector<const ReflexiveContainerType *> cloneTypes;
00473 std::vector<const ReflexiveContainerType *> ignoreTypes;
00474 std::vector<UInt16> cloneGroupIds;
00475 std::vector<UInt16> ignoreGroupIds;
00476
00477 appendTypesString(cloneTypesString, cloneTypes);
00478 appendTypesString(ignoreTypesString, ignoreTypes);
00479
00480 cloneAttachments(src, dst, cloneTypes, ignoreTypes,
00481 cloneGroupIds, ignoreGroupIds);
00482 }
00483
00498 void cloneAttachments(
00499 AttachmentContainerPtrConstArg src,
00500 AttachmentContainerPtrArg dst,
00501 const std::vector<const ReflexiveContainerType *> &cloneTypes,
00502 const std::vector<const ReflexiveContainerType *> &ignoreTypes,
00503 const std::vector<UInt16> &cloneGroupIds,
00504 const std::vector<UInt16> &ignoreGroupIds)
00505 {
00506 #if 0
00507 const FieldContainerType &type = dst->getType();
00508 const FieldDescriptionBase *fDesc = type.getFieldDesc("attachments");
00509 const UInt32 fieldId = fDesc->getFieldId();
00510 const Field *srcField = src->getField("attachments");
00511
00512 fDesc->shareValuesV(srcField, fieldId, dst, cloneTypes, ignoreTypes,
00513 cloneGroupIds, ignoreGroupIds);
00514 #else
00515 const SFFieldContainerAttachmentPtrMap *pAttMap =
00516 src->getSFAttachments();
00517
00518 FieldContainerAttachmentMap::const_iterator mapIt =
00519 pAttMap->getValue().begin();
00520
00521 FieldContainerAttachmentMap::const_iterator mapEnd =
00522 pAttMap->getValue().end();
00523
00524 for(; mapIt != mapEnd; ++mapIt)
00525 {
00526 FieldContainerAttachmentPtr att = mapIt->second;
00527 UInt16 uiBinding = UInt16(mapIt->first &
00528 0x0000FFFF );
00529
00530 if(att != NullFC)
00531 {
00532 const FieldContainerType &attType = att->getType();
00533
00534
00535 if(!TypePredicates::typeInGroupIds (ignoreGroupIds.begin(),
00536 ignoreGroupIds.end(),
00537 attType ) &&
00538 !TypePredicates::typeDerivedFrom(ignoreTypes.begin(),
00539 ignoreTypes.end(),
00540 attType ) )
00541 {
00542
00543 if(TypePredicates::typeInGroupIds (cloneGroupIds.begin(),
00544 cloneGroupIds.end(),
00545 attType ) ||
00546 TypePredicates::typeDerivedFrom(cloneTypes.begin(),
00547 cloneTypes.end(),
00548 attType ) )
00549 {
00550 att = dynamic_cast<FieldContainerAttachmentPtr>(
00551 OSG::deepClone(att, cloneTypes, ignoreTypes,
00552 cloneGroupIds, ignoreGroupIds));
00553 }
00554 }
00555 }
00556
00557 dst->addAttachment(att, uiBinding);
00558 }
00559 #endif
00560 }
00561
00577 void deepCloneAttachments(
00578 AttachmentContainerPtrConstArg src,
00579 AttachmentContainerPtrArg dst,
00580 const std::vector<std::string> &shareTypeNames,
00581 const std::vector<std::string> &ignoreTypeNames,
00582 const std::vector<std::string> &shareGroupNames,
00583 const std::vector<std::string> &ignoreGroupNames)
00584 {
00585 std::vector<const ReflexiveContainerType *> shareTypes;
00586 std::vector<const ReflexiveContainerType *> ignoreTypes;
00587 std::vector<UInt16> shareGroupIds;
00588 std::vector<UInt16> ignoreGroupIds;
00589
00590 appendTypesVector (shareTypeNames, shareTypes );
00591 appendTypesVector (ignoreTypeNames, ignoreTypes );
00592 appendGroupsVector(shareGroupNames, shareGroupIds );
00593 appendGroupsVector(ignoreGroupNames, ignoreGroupIds);
00594
00595 deepCloneAttachments(src, dst, shareTypes, ignoreTypes,
00596 shareGroupIds, ignoreGroupIds);
00597 }
00598
00610 void deepCloneAttachments(
00611 AttachmentContainerPtrConstArg src,
00612 AttachmentContainerPtrArg dst,
00613 const std::vector<UInt16> &shareGroupIds,
00614 const std::vector<UInt16> &ignoreGroupIds)
00615 {
00616 std::vector<const ReflexiveContainerType *> shareTypes;
00617 std::vector<const ReflexiveContainerType *> ignoreTypes;
00618
00619 deepCloneAttachments(src, dst, shareTypes, ignoreTypes,
00620 shareGroupIds, ignoreGroupIds);
00621 }
00622
00638 void deepCloneAttachments(
00639 AttachmentContainerPtrConstArg src,
00640 AttachmentContainerPtrArg dst,
00641 const std::string &shareTypesString,
00642 const std::string &ignoreTypesString)
00643 {
00644 std::vector<const ReflexiveContainerType *> shareTypes;
00645 std::vector<const ReflexiveContainerType *> ignoreTypes;
00646 std::vector<UInt16> shareGroupIds;
00647 std::vector<UInt16> ignoreGroupIds;
00648
00649 appendTypesString(shareTypesString, shareTypes);
00650 appendTypesString(ignoreTypesString, ignoreTypes);
00651
00652 deepCloneAttachments(src, dst, shareTypes, ignoreTypes,
00653 shareGroupIds, ignoreGroupIds);
00654 }
00655
00670 void deepCloneAttachments(
00671 AttachmentContainerPtrConstArg src,
00672 AttachmentContainerPtrArg dst,
00673 const std::vector<const ReflexiveContainerType *> &shareTypes,
00674 const std::vector<const ReflexiveContainerType *> &ignoreTypes,
00675 const std::vector<UInt16> &shareGroupIds,
00676 const std::vector<UInt16> &ignoreGroupIds)
00677 {
00678 #if 0
00679 const FieldContainerType &type = dst->getType();
00680 const FieldDescriptionBase *fDesc = type.getFieldDesc("attachments");
00681 const UInt32 fieldId = fDesc->getFieldId();
00682 const Field *srcField = src->getField("attachments");
00683
00684 fDesc->cloneValuesV(srcField, fieldId, dst, shareTypes, ignoreTypes,
00685 shareGroupIds, ignoreGroupIds);
00686 #else
00687 const SFFieldContainerAttachmentPtrMap *pAttMap =
00688 src->getSFAttachments();
00689
00690 FieldContainerAttachmentMap::const_iterator mapIt =
00691 pAttMap->getValue().begin();
00692
00693 FieldContainerAttachmentMap::const_iterator mapEnd =
00694 pAttMap->getValue().end();
00695
00696 for(; mapIt != mapEnd; ++mapIt)
00697 {
00698 FieldContainerAttachmentPtr att = mapIt->second;
00699 UInt16 uiBinding = UInt16(mapIt->first &
00700 0x0000FFFF );
00701
00702 if(att != NullFC)
00703 {
00704 const FieldContainerType &attType = att->getType();
00705
00706
00707 if(!TypePredicates::typeInGroupIds (ignoreGroupIds.begin(),
00708 ignoreGroupIds.end(),
00709 attType ) &&
00710 !TypePredicates::typeDerivedFrom(ignoreTypes.begin(),
00711 ignoreTypes.end(),
00712 attType ) )
00713 {
00714
00715 if(!TypePredicates::typeInGroupIds (shareGroupIds.begin(),
00716 shareGroupIds.end(),
00717 attType ) &&
00718 !TypePredicates::typeDerivedFrom(shareTypes.begin(),
00719 shareTypes.end(),
00720 attType ) )
00721 {
00722 att = dynamic_cast<FieldContainerAttachmentPtr>(
00723 OSG::deepClone(att, shareTypes, ignoreTypes,
00724 shareGroupIds, ignoreGroupIds));
00725 }
00726 }
00727 }
00728
00729 dst->addAttachment(att, uiBinding);
00730 }
00731 #endif
00732 }
00733
00734 OSG_END_NAMESPACE