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;
}
Пример #2
0
void LookAndFeel::initUndefinedPrototypes(void)
{
    //Find all of the types that inherit off of the defined prototypes
    UInt32 NumFCTypes(FieldContainerFactory::the()->getNumTypes());
    const FieldContainerType* UndefinedPrototypeType(NULL);
    const FieldContainerType* ClosestAncestorType(NULL);
    FieldContainerRefPtr UndefinedPrototype(NULL);
    FieldContainerRefPtr ClosestAncestorPrototype(NULL);

    const FieldDescriptionBase* UndefinedPrototypeDesc(NULL);
    const FieldDescriptionBase* ClosestAncestorDesc(NULL);
    UInt32 NumTypesFound(0);
    for (UInt32 i(0); NumTypesFound < NumFCTypes ; ++i)
    {
        UndefinedPrototypeType = FieldContainerFactory::the()->findType(i);
        if(UndefinedPrototypeType == NULL)
        {
            continue;
        }
        else
        {
            ++NumTypesFound;
        }

        ClosestAncestorType = getClosestAncestor(UndefinedPrototypeType,
                                                 getMFPrototypes()->begin(),
                                                 getMFPrototypes()->end());
        if(ClosestAncestorType != NULL &&
           *ClosestAncestorType != *UndefinedPrototypeType &&
           !UndefinedPrototypeType->isAbstract())
        {
            SNOTICE << "UserInterface: LookAndFeel: Initializing undefined prototype for a derived user interface type" << std::endl
                    << "    Undefined Prototype Type: "   << UndefinedPrototypeType->getCName() << std::endl
                    << "    Closest Ancestor: "         << ClosestAncestorType->getCName() << std::endl;
            //For all of these types set the prototype values of all of the 
            //inherited fields to the same as the closest ancestor
            UndefinedPrototype = UndefinedPrototypeType->getPrototype();
            ClosestAncestorPrototype = ClosestAncestorType->getPrototype();
            for(UInt32 j(1); j<=ClosestAncestorType->getNumFieldDescs() ; ++j)
            {
                ClosestAncestorDesc = ClosestAncestorType->getFieldDesc(j);
                UndefinedPrototypeDesc = ClosestAncestorType->getFieldDesc(ClosestAncestorDesc->getCName());

                //Set the field to the same as this closest ancestor
                //Get the Undefined Field
                EditFieldHandlePtr UndefinedField =
                    UndefinedPrototype->editField(UndefinedPrototypeDesc->getFieldId());
                GetFieldHandlePtr ClosestAncestorField =
                    ClosestAncestorPrototype->getField(ClosestAncestorDesc->getFieldId());
                //Get the Closest Ancestor Field
                if(UndefinedField != NULL && 
                   ClosestAncestorField != NULL &&
                   !UndefinedPrototypeDesc->isInternal())
                {
                    if(UndefinedField->isPointerField())
                    {
                        UndefinedField->cloneValues(ClosestAncestorField);
                    }
                    else
                    {
                        UndefinedField->copyValues(ClosestAncestorField);
                    }
                }
            }
        }
    }
}