1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2008 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
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. *
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. *
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. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 #include "OSGAttachmentContainer.h"
40 #include "OSGFieldConnector.h"
41 #include "OSGConnectorAttachment.h"
46 /*---------------------------------------------------------------------*/
47 /*! \name Connection handling */
50 /*! \ingroup GrpBaseFieldContainerConnector
51 \relatesalso AttachmentContainer
54 bool addConnection( OSG::AttachmentContainer
*pSrcContainer
,
55 const OSG::Char8
*szSrcName
,
56 OSG::FieldContainer
*pDstContainer
,
57 const OSG::Char8
*szDstName
)
59 if(pSrcContainer
== NULL
|| szSrcName
== NULL
||
60 pDstContainer
== NULL
|| szDstName
== NULL
)
65 const FieldDescriptionBase
*pSrcDesc
= NULL
;
66 const FieldDescriptionBase
*pDstDesc
= NULL
;
68 GetFieldHandlePtr pSrcHnd
= pSrcContainer
->getField(szSrcName
);
69 GetFieldHandlePtr pDstHnd
= pDstContainer
->getField(szDstName
);
71 if(pSrcHnd
!= NULL
&& pSrcHnd
->isValid() == true)
73 pSrcDesc
= pSrcHnd
->getDescription();
76 if(pDstHnd
!= NULL
&& pDstHnd
->isValid() == true)
78 pDstDesc
= pDstHnd
->getDescription();
81 // check core for node
84 Node
*pNode
= dynamic_cast<Node
*>(pSrcContainer
);
86 if(pNode
!= NULL
&& pNode
->getCore() != NULL
)
88 pSrcHnd
= pNode
->getCore()->getField(szSrcName
);
90 if(pSrcHnd
!= NULL
&& pSrcHnd
->isValid() == true)
92 pSrcDesc
= pSrcHnd
->getDescription();
100 Node
*pNode
= dynamic_cast<Node
*>(pDstContainer
);
102 if(pNode
!= NULL
&& pNode
->getCore() != NULL
)
104 pDstHnd
= pNode
->getCore()->getField(szDstName
);
106 if(pDstHnd
!= NULL
&& pDstHnd
->isValid() == true)
108 pDstDesc
= pDstHnd
->getDescription();
113 if(pSrcDesc
== NULL
|| pDstDesc
== NULL
)
115 FWARNING(("addConnection: Failed to obtain field descriptions for "
116 "source container [%p] field [%s] desc [%p] - "
117 "destination container [%p] field [%s] desc [%p]\n",
118 static_cast<void *>(pSrcContainer
),
120 static_cast<const void *>(pSrcDesc
),
121 static_cast<void *>(pDstContainer
),
123 static_cast<const void *>(pDstDesc
) ));
128 const Field
*pSrcField
= pSrcHnd
->getField();
129 Field
*pDstField
= const_cast<Field
*>(pDstHnd
->getField());
132 dynamic_cast<AttachmentContainer
*>(pSrcHnd
->getContainer());
135 dynamic_cast<FieldContainer
*>(pDstHnd
->getContainer());
137 if(pSrcContainer
== NULL
|| pDstContainer
== NULL
)
139 FWARNING(("addConnection: Failed to obtain field handles for "
140 "source container [%p] - destination container [%p]\n",
141 static_cast<void *>(pSrcContainer
),
142 static_cast<void *>(pDstContainer
)));
147 BasicFieldConnector
*pConn
= pSrcDesc
->createConnector(pSrcField
,
153 pConn
->setTargetContainer(pDstContainer
);
155 addConnector(pSrcContainer
, pConn
);
161 /*! \ingroup GrpBaseFieldContainerConnector
162 \relatesalso AttachmentContainer
165 bool subConnection( OSG::AttachmentContainer
*pSrcContainer
,
166 const OSG::Char8
*szSrcName
,
167 OSG::FieldContainer
*pDstContainer
,
168 const OSG::Char8
*szDstName
)
170 if(pSrcContainer
== NULL
)
176 const FieldDescriptionBase
*pSrcDesc
= NULL
;
178 GetFieldHandlePtr pSrcHnd
;
180 if(szSrcName
!= NULL
)
182 pSrcHnd
= pSrcContainer
->getField(szSrcName
);
184 if(pSrcHnd
!= NULL
&& pSrcHnd
->isValid() == true)
186 pSrcDesc
= pSrcHnd
->getDescription();
189 // check core for node
192 Node
*pNode
= dynamic_cast<Node
*>(pSrcContainer
);
194 if(pNode
!= NULL
&& pNode
->getCore() != NULL
)
196 pSrcHnd
= pNode
->getCore()->getField(szSrcName
);
198 if(pSrcHnd
!= NULL
&& pSrcHnd
->isValid() == true)
200 pSrcDesc
= pSrcHnd
->getDescription();
207 const FieldDescriptionBase
*pDstDesc
= NULL
;
209 GetFieldHandlePtr pDstHnd
;
211 if(pDstContainer
!= NULL
&& szDstName
!= NULL
)
213 pDstHnd
= pDstContainer
->getField(szDstName
);
215 if(pDstHnd
!= NULL
&& pDstHnd
->isValid() == true)
217 pDstDesc
= pDstHnd
->getDescription();
223 Node
*pNode
= dynamic_cast<Node
*>(pDstContainer
);
225 if(pNode
!= NULL
&& pNode
->getCore() != NULL
)
227 pDstHnd
= pNode
->getCore()->getField(szDstName
);
229 if(pDstHnd
!= NULL
&& pDstHnd
->isValid() == true)
231 pDstDesc
= pDstHnd
->getDescription();
241 FWARNING(("subConnection: Failed to obtain field description for: "
242 "source container [%p] field [%s]\n",
243 pSrcContainer
, szSrcName
));
249 BitVector bSrcMask
= TypeTraits
<BitVector
>::BitsClear
;
250 BitVector bDstMask
= TypeTraits
<BitVector
>::BitsClear
;
254 bSrcMask
= pSrcDesc
->getFieldMask();
257 dynamic_cast<AttachmentContainer
*>(pSrcHnd
->getContainer());
259 else if(szSrcName
== NULL
)
261 bSrcMask
= TypeTraits
<BitVector
>::BitsSet
;
266 bDstMask
= pDstDesc
->getFieldMask();
269 dynamic_cast<AttachmentContainer
*>(pDstHnd
->getContainer());
271 else if(szDstName
== NULL
)
273 bDstMask
= TypeTraits
<BitVector
>::BitsSet
;
276 subConnector(pSrcContainer
, bSrcMask
,
277 pDstContainer
, bDstMask
);
283 /*---------------------------------------------------------------------*/