FieldContainerTransitPtr deepClone(
          OSG::FieldContainer const                        *src,
    const std::vector<const OSG::ReflexiveContainerType *> &shareTypes,
    const std::vector<const OSG::ReflexiveContainerType *> &ignoreTypes,
    const std::vector<OSG::UInt16>                         &shareGroupIds,
    const std::vector<OSG::UInt16>                         &ignoreGroupIds)
{
    if(src == NULL)
        return FieldContainerTransitPtr(NULL);

    const FieldContainerType &fcType  = src->getType();
    FieldContainerTransitPtr  fcClone = fcType.createContainer();

    UInt32 fCount = osgMin(fcType            .getNumFieldDescs(),
                           fcClone->getType().getNumFieldDescs() );

    for(UInt32 i = 1; i <= fCount; ++i)
    {
        const FieldDescriptionBase *fDesc = fcType.getFieldDesc(i);

        if(fDesc->isInternal())
            continue;

        GetFieldHandlePtr  srcField = src    ->getField (i);
        EditFieldHandlePtr dstField = fcClone->editField(i);

        if(dstField == NULL || dstField->isValid() == false || 
           srcField == NULL || srcField->isValid() == false)
        {
            continue;
        }

        if(srcField->isPointerField() == false)
        {
            dstField->copyValues(srcField);
        }
        else
        {
            dstField->cloneValues(srcField, 
                                  shareTypes,    
                                  ignoreTypes,
                                  shareGroupIds, 
                                  ignoreGroupIds);
        }
    }

    return fcClone;
}
Beispiel #2
0
void OSGWriter::visitField(GetFieldHandlePtr hF)
{
    if(hF->isValid() == false)
    {
        return;
    }

//    const FieldType &fType       = hF->getType();

    GetMapFieldHandlePtr sfMap = 
        boost::dynamic_pointer_cast<
            GetMapFieldHandle>(hF);

    if(sfMap != NULL && sfMap->isValid() == true)
    {
        sfMap->traverse(boost::bind(&OSGWriter::visitContainer, this, _1));
    }
    else
    {
        FieldContainerPtrSFieldBase::GetHandlePtr sfFCPtr = 
            boost::dynamic_pointer_cast<
                FieldContainerPtrSFieldBase::GetHandle>(hF);

        FieldContainerPtrMFieldBase::GetHandlePtr mfFCPtr = 
            boost::dynamic_pointer_cast<
                FieldContainerPtrMFieldBase::GetHandle>(hF);

        if(sfFCPtr != NULL && sfFCPtr->isValid() == true)
        {
            visitContainer((*sfFCPtr)->getValue());
        }
        else if(mfFCPtr != NULL && mfFCPtr->isValid() == true)
        {
            SizeT mfSize = (*mfFCPtr)->size();

            for(SizeT i = 0; i < mfSize; i++)
            {
                visitContainer((**mfFCPtr)[i]);
            }
        }
    }
}
Beispiel #3
0
void CSMLogger::doLog(FieldContainer *pContainer, 
                      BitVector       bvFlags   ,
                      UInt32          origin    ,
                      UInt32          uiRefFieldId,
                      BitVector       uiRefFieldMask)
{
    if(0x0000 != (bvFlags & uiRefFieldMask) && _sfEnabled.getValue() == true)
    {
        GetFieldHandlePtr pFH = pContainer->getField(uiRefFieldId);

        if(pFH && pFH->isValid() == true)
        {
            static CErrOutStream cerrStream;

            const FieldDescriptionBase *pDesc = 
                pContainer->getFieldDescription(uiRefFieldId);

            AttachmentContainer *pAtt = 
                dynamic_cast<AttachmentContainer *>(pContainer);

            if(pAtt != NULL)
            {
                const Char8 *szName = getName(pAtt);

                if(szName != NULL)
                {
                    cerrStream << "[" << szName << "]:";
                }
            }

            cerrStream << pContainer->getType().getName() 
                       << "."
                       << pDesc->getName()
                       << " : ";
            
            pFH->pushValueToStream(cerrStream);

            cerrStream << std::endl;
        }
    }
}
OSG_BEGIN_NAMESPACE

/*---------------------------------------------------------------------*/
/*! \name Connection handling                                          */
/*! \{                                                                 */

/*! \ingroup GrpBaseFieldContainerConnector
    \relatesalso AttachmentContainer
 */

bool addConnection(      OSG::AttachmentContainer *pSrcContainer,
                         const OSG::Char8               *szSrcName,
                         OSG::FieldContainer      *pDstContainer,
                         const OSG::Char8               *szDstName    )
{
    if(pSrcContainer == NULL || szSrcName == NULL ||
            pDstContainer == NULL || szDstName == NULL  )
    {
        return false;
    }

    const FieldDescriptionBase *pSrcDesc = NULL;
    const FieldDescriptionBase *pDstDesc = NULL;

    GetFieldHandlePtr pSrcHnd = pSrcContainer->getField(szSrcName);
    GetFieldHandlePtr pDstHnd = pDstContainer->getField(szDstName);

    if(pSrcHnd != NULL && pSrcHnd->isValid() == true)
    {
        pSrcDesc = pSrcHnd->getDescription();
    }

    if(pDstHnd != NULL && pDstHnd->isValid() == true)
    {
        pDstDesc = pDstHnd->getDescription();
    }

    // check core for node
    if(pSrcDesc == NULL)
    {
        Node *pNode = dynamic_cast<Node *>(pSrcContainer);

        if(pNode != NULL && pNode->getCore() != NULL)
        {
            pSrcHnd = pNode->getCore()->getField(szSrcName);

            if(pSrcHnd != NULL && pSrcHnd->isValid() == true)
            {
                pSrcDesc = pSrcHnd->getDescription();
            }
        }
    }

    // same here
    if(pDstDesc == NULL)
    {
        Node *pNode = dynamic_cast<Node *>(pDstContainer);

        if(pNode != NULL && pNode->getCore() != NULL)
        {
            pDstHnd = pNode->getCore()->getField(szDstName);

            if(pDstHnd != NULL && pDstHnd->isValid() == true)
            {
                pDstDesc = pDstHnd->getDescription();
            }
        }
    }

    if(pSrcDesc == NULL || pDstDesc == NULL)
    {
        FWARNING(("addConnection: Failed to obtain field descriptions for "
                  "source container [%p] field [%s] desc [%p] - "
                  "destination container [%p] field [%s] desc [%p]\n",
                  static_cast<void *>(pSrcContainer),
                  szSrcName,
                  static_cast<const void *>(pSrcDesc),
                  static_cast<void *>(pDstContainer),
                  szDstName,
                  static_cast<const void *>(pDstDesc)                      ));

        return false;
    }

    const Field *pSrcField = pSrcHnd->getField();
    Field *pDstField = const_cast<Field *>(pDstHnd->getField());

    pSrcContainer =
        dynamic_cast<AttachmentContainer *>(pSrcHnd->getContainer());

    pDstContainer =
        dynamic_cast<FieldContainer      *>(pDstHnd->getContainer());

    if(pSrcContainer == NULL || pDstContainer == NULL)
    {
        FWARNING(("addConnection: Failed to obtain field handles for "
                  "source container [%p] - destination container [%p]\n",
                  static_cast<void *>(pSrcContainer),
                  static_cast<void *>(pDstContainer)));

        return false;
    }

    BasicFieldConnector *pConn = pSrcDesc->createConnector(pSrcField,
                                 pDstDesc,
                                 pDstField);

    if(pConn != NULL)
    {
        pConn->setTargetContainer(pDstContainer);

        addConnector(pSrcContainer, pConn);
    }

    return true;
}
bool subConnection(      OSG::AttachmentContainer *pSrcContainer,
                         const OSG::Char8               *szSrcName,
                         OSG::FieldContainer      *pDstContainer,
                         const OSG::Char8               *szDstName    )
{
    if(pSrcContainer == NULL)
    {
        return false;
    }


    const FieldDescriptionBase *pSrcDesc = NULL;

    GetFieldHandlePtr pSrcHnd;

    if(szSrcName != NULL)
    {
        pSrcHnd = pSrcContainer->getField(szSrcName);

        if(pSrcHnd != NULL && pSrcHnd->isValid() == true)
        {
            pSrcDesc = pSrcHnd->getDescription();
        }

        // check core for node
        if(pSrcDesc == NULL)
        {
            Node *pNode = dynamic_cast<Node *>(pSrcContainer);

            if(pNode != NULL && pNode->getCore() != NULL)
            {
                pSrcHnd = pNode->getCore()->getField(szSrcName);

                if(pSrcHnd != NULL && pSrcHnd->isValid() == true)
                {
                    pSrcDesc = pSrcHnd->getDescription();
                }
            }
        }
    }


    const FieldDescriptionBase *pDstDesc = NULL;

    GetFieldHandlePtr pDstHnd;

    if(pDstContainer != NULL && szDstName != NULL)
    {
        pDstHnd = pDstContainer->getField(szDstName);

        if(pDstHnd != NULL && pDstHnd->isValid() == true)
        {
            pDstDesc = pDstHnd->getDescription();
        }

        // same here
        if(pDstDesc == NULL)
        {
            Node *pNode = dynamic_cast<Node *>(pDstContainer);

            if(pNode != NULL && pNode->getCore() != NULL)
            {
                pDstHnd = pNode->getCore()->getField(szDstName);

                if(pDstHnd != NULL && pDstHnd->isValid() == true)
                {
                    pDstDesc = pDstHnd->getDescription();
                }
            }
        }
    }


#if 0
    if(pSrcDesc == NULL)
    {
        FWARNING(("subConnection: Failed to obtain field description for: "
                  "source container [%p] field [%s]\n",
                  pSrcContainer, szSrcName));

        return false;
    }
#endif

    BitVector bSrcMask = TypeTraits<BitVector>::BitsClear;
    BitVector bDstMask = TypeTraits<BitVector>::BitsClear;

    if(pSrcDesc != NULL)
    {
        bSrcMask = pSrcDesc->getFieldMask();

        pSrcContainer =
            dynamic_cast<AttachmentContainer *>(pSrcHnd->getContainer());
    }
    else if(szSrcName == NULL)
    {
        bSrcMask = TypeTraits<BitVector>::BitsSet;
    }

    if(pDstDesc != NULL)
    {
        bDstMask = pDstDesc->getFieldMask();

        pDstContainer =
            dynamic_cast<AttachmentContainer *>(pDstHnd->getContainer());
    }
    else if(szDstName == NULL)
    {
        bDstMask = TypeTraits<BitVector>::BitsSet;
    }

    subConnector(pSrcContainer, bSrcMask,
                 pDstContainer, bDstMask);

    return false;
}
void SetFieldValueCommand::execute(void)
{
    //Check for a valid Field Container
    if(_FC == NULL)
    {
        SWARNING << "FieldContainer is NULL." << std::endl;
        return;
    }

    //Check for valid Field
    GetFieldHandlePtr TheFieldHandle = _FC->getField(_FieldId);
    if(!TheFieldHandle->isValid())
    {
        SWARNING << "No Field with Id: " << _FieldId << " in FieldContainers of type " << _FC->getType().getName() << std::endl;
        return;
    }

    //Check for valid indexing
    if(TheFieldHandle->getCardinality() == FieldType::SingleField && _Index != 0)
    {
        SWARNING << "Cannot reference index " << _Index << ", on field " << TheFieldHandle->getDescription()->getName() 
                 << ", on FieldContianer of type " << _FC->getType().getName()
                 << " because that field is a SingleField." << std::endl;
        return;
    }
    else if(TheFieldHandle->getCardinality() == FieldType::MultiField && _Index >= TheFieldHandle->size())
    {
        SWARNING << "Cannot set the value of index " << _Index << ", on field " << TheFieldHandle->getDescription()->getName() 
                 << ", on FieldContianer of type " << _FC->getType().getName()
                 << " because that field has size " << TheFieldHandle->size() << std::endl;
        return;
    }


    //Get the previous value
    if(_PrevValue.empty())
    {
        std::ostringstream StrStream;
        OutStream TheOutStream(StrStream);
        if(TheFieldHandle->getCardinality() == FieldType::SingleField)
        {
            if(TheFieldHandle->isPointerField())
            {
                _PrevPtrValue = dynamic_cast<GetSFieldHandle<FieldContainerPtrSFieldBase>*>(TheFieldHandle.get())->get();
                if(dynamic_cast<GetSFieldHandle<FieldContainerPtrSFieldBase>*>(TheFieldHandle.get())->get())
                {
                    _PrevValue = boost::lexical_cast<std::string>(dynamic_cast<GetSFieldHandle<FieldContainerPtrSFieldBase>*>(TheFieldHandle.get())->get()->getId());
                }
                else
                {
                    _PrevValue = "0";
                }
            }
            else
            {
                TheFieldHandle->pushValueToStream(TheOutStream);
                _PrevValue = StrStream.str();
            }
        }
        else
        {
            if(TheFieldHandle->isPointerField())
            {
                _PrevPtrValue = dynamic_cast<GetMFieldHandle<FieldContainerPtrMFieldBase>*>(TheFieldHandle.get())->get(_Index);
                if(_PrevPtrValue)
                {
                    _PrevValue = boost::lexical_cast<std::string>(dynamic_cast<GetMFieldHandle<FieldContainerPtrMFieldBase>*>(TheFieldHandle.get())->get(_Index)->getId());
                }
                else
                {
                    _PrevValue = "0";
                }
            }
            else
            {
                TheFieldHandle->pushIndexedValueToStream(TheOutStream, _Index);
                _PrevValue = StrStream.str();
            }
        }

        //Remove quotes from strings
        if(TheFieldHandle->getType().getContentType() == FieldTraits<std::string>::getType())
        {
            _PrevValue = _PrevValue.substr(1,StrStream.str().size()-2);
        }
    }

    //Set the value
    if(TheFieldHandle->getCardinality() == FieldType::SingleField)
    {
        if(TheFieldHandle->isPointerField())
        {
            _PtrValue = FieldContainerFactory::the()->getContainer(boost::lexical_cast<UInt32>(_Value));
            
            //Check the pointer types match
            if(_PtrValue != NULL &&
                !isFieldContentDerivedFrom(TheFieldHandle->getType(),&_PtrValue->getType()))
            {
                SWARNING << "Cannot set the value of field " << TheFieldHandle->getDescription()->getName() 
                         << ", on FieldContianer of type " << _FC->getType().getName()
                         << " because the value attemting to be set is not derived from the type the field stores." << std::endl;
                return;
            }
            if(_PtrValue != _PrevPtrValue)
            {
                dynamic_cast<EditSFieldHandle<FieldContainerPtrSFieldBase>*>(_FC->editField(_FieldId).get())->set(_PtrValue);
            }
        }
        else
        {
            _FC->editField(_FieldId)->pushValueFromCString(_Value.c_str());
        }
    }
    else
    {
        if(TheFieldHandle->isPointerField())
        {
            _PtrValue = FieldContainerFactory::the()->getContainer(boost::lexical_cast<UInt32>(_Value));
            
            //Check the pointer types match
            if(_PtrValue != NULL && !isFieldContentDerivedFrom(TheFieldHandle->getType(),&_PtrValue->getType()))
            {
                SWARNING << "Cannot set the value of field " << TheFieldHandle->getDescription()->getName() 
                         << ", on FieldContianer of type " << _FC->getType().getName()
                         << " because the value attemting to be set is not derived from the type the field stores." << std::endl;
                return;
            }
            if(_PtrValue != _PrevPtrValue)
            {
                dynamic_cast<EditMFieldHandle<FieldContainerPtrMFieldBase>*>(_FC->editField(_FieldId).get())->replace(_Index, _PtrValue);
            }
        }
        else
        {
            _FC->editField(_FieldId)->pushIndexedValueFromCString(_Value.c_str(), _Index);
        }
    }

    Inherited::execute();
	_HasBeenDone = true;
}
void OSGLoader::beginFieldDecl(const Char8  *szFieldType,
                               const UInt32  uiFieldTypeId,
                               const Char8  *szFieldName  )
{
    UInt32 uiOSGFieldTypeId = mapIntExtFieldType(szFieldName, uiFieldTypeId);
    
    DynFieldContainerInterface *pIf = 
        dynamic_cast<DynFieldContainerInterface *>(_pCurrentFC.get());

    if(pIf != NULL)
    {
        GetFieldHandlePtr pField = _pCurrentFC->getField(szFieldName);

        if(pField == NULL || pField->isValid() == false)
        {
            if(uiFieldTypeId == 0)
            {
                pIf->addField(szFieldType, szFieldName);
            }
            else
            {
                pIf->addField(uiOSGFieldTypeId, szFieldName);
            }
        }

        _pCurrentField     = _pCurrentFC->editField(szFieldName);
        _pCurrentFieldDesc =
            _pCurrentFC->getType().getFieldDesc(szFieldName);
    }
    else
    {
        AttachmentContainer *pAttCnt = 
            dynamic_cast<AttachmentContainer *>(_pCurrentFC.get());

        if(pAttCnt != NULL)
        {
            OSGGenericAttUnrecPtr pGenAtt = 
                dynamic_cast<OSGGenericAtt *>(
                    pAttCnt->findAttachment(OSGGenericAtt::getClassGroupId()));

            if(pGenAtt == NULL)
            {
                pGenAtt = OSGGenericAtt::create();
                
                pAttCnt->addAttachment(pGenAtt);
            }
            
            GetFieldHandlePtr pField = pGenAtt->getField(szFieldName);

            if(pField == NULL || pField->isValid() == false)
            {
                if(uiFieldTypeId == 0)
                {
//                    pGenAtt->addField(szFieldType, szFieldName);
                }
                else
                {
                    pGenAtt->addField(uiOSGFieldTypeId, szFieldName);
                }
            }
            
            _pCurrentField     = pGenAtt->editField(szFieldName);
            _pCurrentFieldDesc =
                pGenAtt->getType().getFieldDesc(szFieldName);

        }
    }

    _fStack.push (_pCurrentField);
    _fdStack.push(_pCurrentFieldDesc);
}
Beispiel #8
0
void OSGWriter::writeField(GetFieldHandlePtr hF)
{
    if(hF->isValid() == false)
    {
        return;
    }

//    const FieldType& fType = hF->getType();

    GetMapFieldHandlePtr sfMap = 
        boost::dynamic_pointer_cast<
            GetMapFieldHandle>(hF);

    FieldContainerPtrSFieldBase::GetHandlePtr sfFCPtr = 
        boost::dynamic_pointer_cast<FieldContainerPtrSFieldBase::GetHandle>(hF);
    
    FieldContainerPtrMFieldBase::GetHandlePtr mfFCPtr = 
        boost::dynamic_pointer_cast<FieldContainerPtrMFieldBase::GetHandle>(hF);

    if(sfMap != NULL && sfMap->isValid() == true)
    {
        _outStream << BeginElem 
                   << hF->getName();

        //if the Attachment Map is empty write [] as its content
        if(sfMap->empty() == true)
        {
            _outStream << " [ ] " << EndElemNL;
        }
        else
        {
            _outStream << EndElemNL
                       << BeginElem
                       << "["
                       << EndElemNL;

            _outStream << IncIndent;
        
            EditMapFieldHandle::MapList fcList;

            sfMap->flatten(fcList);

            EditMapFieldHandle::MapList::iterator iter = fcList.begin();
            EditMapFieldHandle::MapList::iterator end  = fcList.end  ();

            for(; iter!=end; ++iter)
            {
                _outStream << BeginElem
                           << "MapHelper"
                           << EndElemNL
                           << BeginElem
                           << "{"
                           << EndElemNL;

                _outStream << IncIndent;

                _outStream << BeginElem
                           << "keys"
                           << EndElemNL
                           << BeginElem
                           << "["
                           << EndElemNL;

                _outStream << IncIndent;

                std::vector<std::string>::const_iterator kIt  = 
                    iter->first.begin();

                std::vector<std::string>::const_iterator kEnd = 
                    iter->first.end();

                for(; kIt != kEnd; ++kIt)
                {
                    _outStream << BeginElem
                               << "\""
                               << *kIt
                               << "\""
                               << EndElemNL;
                }

                _outStream << DecIndent;

                _outStream << BeginElem
                           << "]"
                           << EndElemNL;

                _outStream << BeginElem
                           << "container ";
                    
                if(iter->second == NULL)
                {
                    _outStream << "NULL"
                               << EndElemNL;
                }
                else
                {
                    writeContainer(iter->second, false);
                    _outStream << EndElemNL;
                }

                _outStream << DecIndent;
                                    
                _outStream << BeginElem
                           << "}"
                           << EndElemNL;
            }

            _outStream << DecIndent; 
            
            _outStream << BeginElem
                       << "]"
                       << EndElemNL;
        }
    }
    else if(sfFCPtr != NULL || mfFCPtr != NULL)
    {
        //this Field points to FC

        if(hF->getDescription()->isDynamic() == true)
        {
            _outStream << BeginElem 
                       << "field "
                       << hF->getType().getCName()
                       << " "
                       << hF->getName();
        }
        else
        {
            _outStream << BeginElem 
                       << hF->getName();
        }

        if(sfFCPtr != NULL && sfFCPtr->isValid() == true)
        {
            if((*sfFCPtr)->getValue() == NULL)
            {
                _outStream << " NULL" << EndElemNL;
            }
            else
            {
                _outStream << " ";
                writeContainer((*sfFCPtr)->getValue(), false);
            }
        }
        else if(mfFCPtr != NULL && mfFCPtr->isValid() == true)
        {
            _outStream << EndElemNL
                       << BeginElem
                       << "[" 
                       << EndElemNL;

            _outStream << IncIndent;

            SizeT mfSize = (*mfFCPtr)->size();

            for(SizeT i = 0; i < mfSize; i++)
            {
                if((*(*mfFCPtr))[i] == NULL)
                {
                    _outStream << BeginElem
                               << "NULL" 
                               << EndElemNL;
                }
                else
                {
                    writeContainer((*(*mfFCPtr))[i], true);
                }
            }

            _outStream << DecIndent;

            _outStream << BeginElem
                       << "]" 
                       << EndElemNL;
        }
    }
    else
    {
        //this Field contains data -> write it out

        if(hF->getDescription()->isDynamic() == true)
        {
            _outStream << BeginElem 
                       << "field "
                       << hF->getType().getCName()
                       << " "
                       << hF->getName();
        }
        else
        {
            _outStream << BeginElem << hF->getName();
        }

        //to access the content of a field via a Field*
        //one must know the cardinality
        if(hF->getCardinality() == FieldType::SingleField)
        {
            _outStream << " ";

            hF->pushValueToStream(_outStream);

            _outStream << EndElemNL;
        }
        else if(hF->getCardinality() == FieldType::MultiField)
        {
            _outStream << " #";

            hF->pushSizeToStream(_outStream);

            _outStream << EndElemNL
                       << BeginElem
                       << "[" 
                       << EndElemNL;

            _outStream << IncIndent;

#ifdef WFC
            hF->pushValueToStream(_outStream);

            _outStream << EndElemNL;
#endif


            _outStream << DecIndent;
            
            _outStream << BeginElem
                       << "]" 
                       << EndElemNL;
        }
    }
}