1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2006 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 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
46 #include <boost/bind.hpp>
48 #include "OSGConfig.h"
50 #include "OSGConnectorAttachment.h"
51 #include "OSGAttachmentContainer.h"
55 // Documentation for this class is emitted in the
56 // OSGConnectorAttachmentBase.cpp file.
57 // To modify it, please change the .fcd file (OSGConnectorAttachment.fcd) and
58 // regenerate the base file.
60 /***************************************************************************\
62 \***************************************************************************/
64 /***************************************************************************\
66 \***************************************************************************/
68 void ConnectorAttachment::initMethod(InitPhase ePhase
)
70 Inherited::initMethod(ePhase
);
72 if(ePhase
== TypeObject::SystemPost
)
78 /***************************************************************************\
80 \***************************************************************************/
82 /*-------------------------------------------------------------------------*\
84 \*-------------------------------------------------------------------------*/
86 /*----------------------- constructors & destructors ----------------------*/
88 ConnectorAttachment::ConnectorAttachment(void) :
94 ConnectorAttachment::ConnectorAttachment(const ConnectorAttachment
&source
) :
100 ConnectorAttachment::~ConnectorAttachment(void)
104 /*----------------------------- class specific ----------------------------*/
106 void ConnectorAttachment::changed(ConstFieldMaskArg whichField
,
110 Inherited::changed(whichField
, origin
, details
);
113 void ConnectorAttachment::dump( UInt32
,
114 const BitVector
) const
116 SLOG
<< "Dump ConnectorAttachment NI" << std::endl
;
119 void ConnectorAttachment::addConnection (BasicFieldConnector
*pConnector
)
121 if(pConnector
!= NULL
)
123 _vConnections
.push_back(pConnector
);
127 void ConnectorAttachment::processChanged(FieldContainer
*pObj
,
128 BitVector whichField
,
131 ConnectionStore::const_iterator cIt
= _vConnections
.begin();
132 ConnectionStore::const_iterator cEnd
= _vConnections
.end ();
136 if((*cIt
)->match(whichField
) == true)
145 void ConnectorAttachment::targetDestroyed(FieldContainer
*pObj
,
146 BitVector whichField
,
149 if(whichField
== 0x0000)
151 this->removeConnectionTo(pObj
);
155 bool ConnectorAttachment::hasConnectionTo(const FieldContainer
*pDst
) const
157 bool returnValue
= false;
159 ConnectionStore::const_iterator cIt
= _vConnections
.begin();
160 ConnectionStore::const_iterator cEnd
= _vConnections
.end ();
164 if((*cIt
)->getDst() == pDst
)
176 void ConnectorAttachment::removeConnectionTo(const FieldContainer
*pDst
)
178 ConnectionStore::iterator cIt
= _vConnections
.begin();
179 ConnectionStore::const_iterator cEnd
= _vConnections
.end ();
183 if((*cIt
)->getDst() == pDst
)
187 cIt
= _vConnections
.erase(cIt
);
189 cEnd
= _vConnections
.end();
198 void ConnectorAttachment::removeConnections( BitVector bSrcMask
,
199 const FieldContainer
*pDst
,
202 ConnectionStore::iterator cIt
= _vConnections
.begin();
203 ConnectionStore::const_iterator cEnd
= _vConnections
.end ();
205 ConnectionCount mConnCount
;
207 this->countConnections(mConnCount
);
211 if((*cIt
)->match(bSrcMask
, pDst
, bDstMask
) == true)
213 --(mConnCount
[(*cIt
)->getDst()]);
217 cIt
= _vConnections
.erase(cIt
);
219 cEnd
= _vConnections
.end();
227 ConnectionCount::const_iterator ccIt
= mConnCount
.begin();
228 ConnectionCount::const_iterator ccEnd
= mConnCount
.end ();
232 if(ccIt
->second
== 0)
234 ccIt
->first
->subChangedFunctor(
235 boost::bind(&ConnectorAttachment::targetDestroyed
,
246 void ConnectorAttachment::countConnections(ConnectionCount
&mCount
)
248 ConnectionStore::const_iterator cIt
= _vConnections
.begin();
249 ConnectionStore::const_iterator cEnd
= _vConnections
.end ();
251 ConnectionCount::iterator ccIt
;
255 ccIt
= mCount
.find((*cIt
)->getDst());
257 if(ccIt
== mCount
.end())
259 mCount
[(*cIt
)->getDst()] = 1;
271 bool ConnectorAttachment::unlinkParent(FieldContainer
* const pParent
,
272 UInt16
const parentFieldId
)
274 pParent
->subChangedFunctor(
275 boost::bind(&ConnectorAttachment::processChanged
,
281 return Inherited::unlinkParent(pParent
, parentFieldId
);
284 void ConnectorAttachment::resolveLinks(void)
286 for(UInt32 i
= 0; i
< _vConnections
.size(); ++i
)
288 FieldContainer
*pDst
= _vConnections
[i
]->getDst();
290 pDst
->subChangedFunctor(
291 boost::bind(&ConnectorAttachment::targetDestroyed
,
297 delete _vConnections
[i
];
300 _vConnections
.clear();
303 /*---------------------------------------------------------------------*/
304 /*! \name Connector handling */
307 /*! \ingroup GrpBaseFieldContainerConnector
308 \relatesalso AttachmentContainer
311 void addConnector(OSG::AttachmentContainer
*pContainer
,
312 OSG::BasicFieldConnector
*pConn
)
314 if(pContainer
== NULL
)
316 FFATAL(("addConnector: no container?!?"));
322 FFATAL(("addConnector: no connector?!?"));
326 ConnectorAttachmentUnrecPtr pCA
= NULL
;
328 Attachment
*att
= pContainer
->findAttachment(
329 ConnectorAttachment::getClassType().getGroupId());
333 pCA
= ConnectorAttachment::createDependent(
334 pContainer
->getFieldFlags()->_bNamespaceMask
);
336 pContainer
->addChangedFunctor(
337 boost::bind(&ConnectorAttachment::processChanged
,
344 pContainer
->addAttachment(pCA
);
348 pCA
= dynamic_cast<ConnectorAttachment
*>(att
);
352 FFATAL(("setName: Attachment is not castable to Conn?!?"));
357 if(pCA
->hasConnectionTo(pConn
->getDst()) == false)
359 FieldContainer
*pDst
= pConn
->getDst();
361 pDst
->addChangedFunctor(
362 boost::bind(&ConnectorAttachment::targetDestroyed
,
370 pCA
->addConnection(pConn
);
373 /*! \ingroup GrpBaseFieldContainerConnector
374 \relatesalso AttachmentContainer
377 void subConnector(OSG::AttachmentContainer
*pSrcContainer
,
378 OSG::BitVector bSrcMask
,
379 OSG::FieldContainer
*pDstContainer
,
380 OSG::BitVector bDstMask
)
382 if(pSrcContainer
== NULL
)
384 FFATAL(("subConnector: no container?!?"));
388 ConnectorAttachmentUnrecPtr pCA
= NULL
;
390 Attachment
*att
= pSrcContainer
->findAttachment(
391 ConnectorAttachment::getClassType().getGroupId());
393 pCA
= dynamic_cast<ConnectorAttachment
*>(att
);
397 pCA
->removeConnections(bSrcMask
, pDstContainer
, bDstMask
);
402 /*---------------------------------------------------------------------*/