changed: gcc8 base update
[opensg.git] / Source / System / NodeCores / Groups / Misc / OSGProxyGroup.cpp
blobb09ca682282dd1406c921a3c35a16629b5dd1a64
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
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. *
18 * *
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. *
23 * *
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. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 #include <cstdlib>
40 #include <cstdio>
42 #include <sstream>
43 #include <fstream>
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"
55 OSG_USING_NAMESPACE
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 /*-------------------------------------------------------------------------*/
63 /* Sync */
65 void ProxyGroup::changed(ConstFieldMaskArg whichField,
66 UInt32 origin,
67 BitVector details)
69 if(whichField & (UrlFieldMask))
71 if(getAbsoluteUrl().empty())
73 PathHandler *ph = SceneFileHandler::the()->getPathHandler();
75 if(ph != NULL)
77 setAbsoluteUrl(ph->findFile(getUrl().c_str()));
80 if(getAbsoluteUrl().empty())
82 setAbsoluteUrl(getUrl());
85 setState(NOT_LOADED);
88 if(whichField & (StateFieldMask |
89 UrlFieldMask |
90 VolumeFieldMask))
92 for(UInt32 i = 0; i < _mfParents.size(); i++)
94 _mfParents[i]->invalidateVolume();
98 Inherited::changed(whichField, origin, details);
101 /*-------------------------------------------------------------------------*/
102 /* Dump */
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 /*-------------------------------------------------------------------------*/
111 /* Constructors */
113 ProxyGroup::ProxyGroup(void) :
114 Inherited ( ),
115 _loadedRoot(NULL)
119 ProxyGroup::ProxyGroup(const ProxyGroup &source) :
120 Inherited (source),
121 _loadedRoot(NULL )
125 /*-------------------------------------------------------------------------*/
126 /* Destructor */
128 ProxyGroup::~ProxyGroup(void)
132 void ProxyGroup::resolveLinks(void)
134 _loadedRoot = NULL;
137 /*!
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)
144 volume.setValid();
145 volume.setEmpty();
147 if(getEnabled() == false)
148 return;
150 if(getState() == LOADED && getRoot() != NULL)
152 volume.extendBy(getRoot()->getVolume());
154 else
156 volume.extendBy(getVolume());
160 /*-------------------------------------------------------------------------*/
161 /* Draw */
164 Draw loaded geometry. If nothing was loaded until now, start
165 loading. If loading is not finished, draw the children of
166 thid group.
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)
178 startLoading();
180 if(getState() == LOAD_THREAD_FINISHED)
182 if(_loadedRoot != NULL)
184 _loadThread = NULL;
186 setRoot(_loadedRoot);
188 getRoot()->invalidateVolume();
189 getRoot()->updateVolume();
192 setState(LOADED);
194 da->getActNode()->invalidateVolume();
195 da->getActNode()->updateVolume ();
197 else
199 SWARNING << "failed to load " << getAbsoluteUrl() << std::endl;
201 setState(LOAD_ERROR);
205 if(getState() == LOADED)
207 da->useNodeList();
209 if(da->isVisible(getCPtr(getRoot())))
210 da->addNode(getRoot());
212 else
214 if(da->getActNode()->getNChildren() == 0)
216 Color3f col;
217 col.setValuesRGB(.5,.3,0);
219 dropVolume(da, da->getActNode(), col);
223 // thread cleanup
224 if(_loadThread && _loadQueue.empty())
226 printf("join\n");
227 BaseThread::join(_loadThread);
228 _loadThread = NULL;
231 return Action::Continue;
233 #endif
235 Action::ResultE ProxyGroup::renderEnter(Action *action)
237 return Action::Continue;
240 /*-------------------------------------------------------------------------*/
241 /* loading */
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());
257 else
259 std::stringstream tmpStream(std::ios_base::in |
260 std::ios_base::out |
261 std::ios_base::binary);
263 tmpStream.write(
264 reinterpret_cast<const char*>(&getMFInline()->front()),
265 getMFInline()->size ());
267 _loadedRoot = SceneFileHandler::the()->read(tmpStream, "osb");
270 setState(LOAD_THREAD_FINISHED);
272 else
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();
289 if(noThread)
291 if(_loadThread)
292 BaseThread::join(_loadThread);
294 _loadThread = dynamic_cast<Thread *>(
295 ThreadManager::the()->getThread(NULL));
297 _loadThread->runFunction(loadProc,
298 Thread::getCurrentAspect(),
299 NULL );
302 #endif
305 /*-------------------------------------------------------------------------*/
306 /* Init */
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;
326 ProxyGroup *g;
328 _loadLock->acquire();
330 g = _loadQueue.front();
332 _loadLock->release();
334 while(!stopThread)
336 if(g->getMFInline()->size() == 0)
338 g->_loadedRoot=SceneFileHandler::the()->read(
339 g->getAbsoluteUrl().c_str());
341 else
343 std::stringstream tmpStream(std::ios_base::in |
344 std::ios_base::out |
345 std::ios_base::binary);
347 tmpStream.write(
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();
358 _loadQueue.pop();
360 if(_loadQueue.empty())
362 stopThread=true;
364 else
366 g=_loadQueue.front();
369 _loadLock->release();
371 #endif
374 Thread *ProxyGroup::_loadThread = NULL;
376 std::queue<ProxyGroupUnrecPtr> ProxyGroup::_loadQueue =
377 std::queue<ProxyGroupUnrecPtr>();
379 Lock *ProxyGroup::_loadLock = NULL;