Пример #1
0
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;
}
Пример #2
0
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;
}