1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 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 \*---------------------------------------------------------------------------*/
45 #include "OSGConfig.h"
47 #include "OSGAction.h"
48 #include "OSGCamera.h"
49 #include "OSGRenderAction.h"
50 #include "OSGSceneFileHandler.h"
51 #include "OSGVolumeDraw.h"
53 #include "OSGProxyGroup.h"
57 // Documentation for this class is emited in the
58 // OSGProxyGroupBase.cpp file.
59 // To modify it, please change the .fcd file (OSGProxyGroup.fcd) and
60 // regenerate the base file.
62 /*-------------------------------------------------------------------------*/
65 void ProxyGroup::changed(ConstFieldMaskArg whichField
,
69 if(whichField
& (UrlFieldMask
))
71 if(getAbsoluteUrl().empty())
73 PathHandler
*ph
= SceneFileHandler::the()->getPathHandler();
77 setAbsoluteUrl(ph
->findFile(getUrl().c_str()));
80 if(getAbsoluteUrl().empty())
82 setAbsoluteUrl(getUrl());
88 if(whichField
& (StateFieldMask
|
92 for(UInt32 i
= 0; i
< _mfParents
.size(); i
++)
94 _mfParents
[i
]->invalidateVolume();
98 Inherited::changed(whichField
, origin
, details
);
101 /*-------------------------------------------------------------------------*/
104 void ProxyGroup::dump( UInt32
OSG_CHECK_ARG(uiIndent
),
105 const BitVector
OSG_CHECK_ARG(bvFlags
)) const
107 SLOG
<< "Dump ProxyGroup NI" << std::endl
;
110 /*-------------------------------------------------------------------------*/
113 ProxyGroup::ProxyGroup(void) :
119 ProxyGroup::ProxyGroup(const ProxyGroup
&source
) :
125 /*-------------------------------------------------------------------------*/
128 ProxyGroup::~ProxyGroup(void)
132 void ProxyGroup::resolveLinks(void)
138 If url was loaded, extend volume by loaded geometry. Otherwise
139 extend volume by the volume given in the proxy object
142 void ProxyGroup::adjustVolume(Volume
&volume
)
147 if(getEnabled() == false)
150 if(getState() == LOADED
&& getRoot() != NULL
)
152 volume
.extendBy(getRoot()->getVolume());
156 volume
.extendBy(getVolume());
160 /*-------------------------------------------------------------------------*/
164 Draw loaded geometry. If nothing was loaded until now, start
165 loading. If loading is not finished, draw the children of
169 #ifdef OSG_OLD_RENDER_ACTION
170 Action::ResultE
ProxyGroup::render(Action
*action
)
172 DrawActionBase
*da
= dynamic_cast<DrawActionBase
*>(action
);
174 if(getEnabled() == false)
175 return Action::Continue
;
177 if(getState() == NOT_LOADED
)
180 if(getState() == LOAD_THREAD_FINISHED
)
182 if(_loadedRoot
!= NULL
)
186 setRoot(_loadedRoot
);
188 getRoot()->invalidateVolume();
189 getRoot()->updateVolume();
194 da
->getActNode()->invalidateVolume();
195 da
->getActNode()->updateVolume ();
199 SWARNING
<< "failed to load " << getAbsoluteUrl() << std::endl
;
201 setState(LOAD_ERROR
);
205 if(getState() == LOADED
)
209 if(da
->isVisible(getCPtr(getRoot())))
210 da
->addNode(getRoot());
214 if(da
->getActNode()->getNChildren() == 0)
217 col
.setValuesRGB(.5,.3,0);
219 dropVolume(da
, da
->getActNode(), col
);
224 if(_loadThread
&& _loadQueue
.empty())
227 BaseThread::join(_loadThread
);
231 return Action::Continue
;
235 Action::ResultE
ProxyGroup::renderEnter(Action
*action
)
237 return Action::Continue
;
240 /*-------------------------------------------------------------------------*/
244 Load the given URL, currently the URL is treated as a filename.
247 void ProxyGroup::startLoading(void)
249 #ifdef OSG_OLD_RENDER_ACTION
250 if(getConcurrentLoad() == false)
252 if(getMFInline()->size() == 0)
254 _loadedRoot
= SceneFileHandler::the()->read(
255 getAbsoluteUrl().c_str());
259 std::stringstream
tmpStream(std::ios_base::in
|
261 std::ios_base::binary
);
264 reinterpret_cast<const char*>(&getMFInline()->front()),
265 getMFInline()->size ());
267 _loadedRoot
= SceneFileHandler::the()->read(tmpStream
, "osb");
270 setState(LOAD_THREAD_FINISHED
);
274 if(_loadLock
== NULL
)
276 _loadLock
= Lock::get("ProxyGroupLoadLock");
279 _loadLock
->acquire();
281 bool noThread
= _loadQueue
.empty();
283 _loadQueue
.push(this);
285 setState(LOAD_THREAD_RUNNING
);
287 _loadLock
->release();
292 BaseThread::join(_loadThread
);
294 _loadThread
= dynamic_cast<Thread
*>(
295 ThreadManager::the()->getThread(NULL
));
297 _loadThread
->runFunction(loadProc
,
298 Thread::getCurrentAspect(),
305 /*-------------------------------------------------------------------------*/
308 void ProxyGroup::initMethod(InitPhase ePhase
)
310 Inherited::initMethod(ePhase
);
312 if(ePhase
== TypeObject::SystemPost
)
314 RenderAction::registerEnterDefault(
315 ProxyGroup::getClassType(),
316 reinterpret_cast<Action::Callback
>(&ProxyGroup::renderEnter
));
321 void ProxyGroup::loadProc(void *)
323 #ifdef OSG_OLD_RENDER_ACTION
324 bool stopThread
= false;
328 _loadLock
->acquire();
330 g
= _loadQueue
.front();
332 _loadLock
->release();
336 if(g
->getMFInline()->size() == 0)
338 g
->_loadedRoot
=SceneFileHandler::the()->read(
339 g
->getAbsoluteUrl().c_str());
343 std::stringstream
tmpStream(std::ios_base::in
|
345 std::ios_base::binary
);
348 reinterpret_cast<const char *>(&g
->getMFInline()->front()),
349 g
->getMFInline()->size());
351 g
->_loadedRoot
= SceneFileHandler::the()->read(tmpStream
, "osb");
354 g
->setState(LOAD_THREAD_FINISHED
);
356 _loadLock
->acquire();
360 if(_loadQueue
.empty())
366 g
=_loadQueue
.front();
369 _loadLock
->release();
374 Thread
*ProxyGroup::_loadThread
= NULL
;
376 std::queue
<ProxyGroupUnrecPtr
> ProxyGroup::_loadQueue
=
377 std::queue
<ProxyGroupUnrecPtr
>();
379 Lock
*ProxyGroup::_loadLock
= NULL
;