fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / NodeCores / Groups / Misc / OSGInline.cpp
blob91b9b3cf414afa4a98650d82ce6735116bdcb1fa
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 <boost/bind.hpp>
44 #include "OSGConfig.h"
46 #include "OSGInline.h"
47 #include "OSGSceneFileHandler.h"
48 #include "OSGOSGSceneFileType.h"
49 #include "OSGRenderAction.h"
50 #include "OSGGraphOpSeq.h"
52 OSG_USING_NAMESPACE
54 // Documentation for this class is emited in the
55 // OSGInlineBase.cpp file.
56 // To modify it, please change the .fcd file (OSGInline.fcd) and
57 // regenerate the base file.
59 /*-------------------------------------------------------------------------*/
60 /* Sync */
62 void Inline::changed(ConstFieldMaskArg whichField,
63 UInt32 origin,
64 BitVector details)
66 Inherited::changed(whichField, origin, details);
69 /*-------------------------------------------------------------------------*/
70 /* Dump */
72 void Inline::dump( UInt32 OSG_CHECK_ARG(uiIndent),
73 const BitVector OSG_CHECK_ARG(bvFlags )) const
75 SLOG << "Dump Inline NI" << std::endl;
78 /*-------------------------------------------------------------------------*/
79 /* Constructors */
81 Inline::Inline(void) :
82 Inherited()
86 Inline::Inline(const Inline &source) :
87 Inherited(source)
91 /*-------------------------------------------------------------------------*/
92 /* Destructor */
94 Inline::~Inline(void)
99 /*-------------------------------------------------------------------------*/
100 /* Init */
102 void Inline::initMethod(InitPhase ePhase)
104 Inherited::initMethod(ePhase);
106 if(ePhase == TypeObject::SystemPost)
108 RenderAction::registerEnterDefault(
109 Inline::getClassType(),
110 reinterpret_cast<Action::Callback>(&Inline::renderEnter));
114 void Inline::postOSGLoading(FileContextAttachment * const pContext)
116 Inherited::postOSGLoading(pContext);
118 UInt32 i = 0;
120 for(; i < _mfUrl.size(); ++i)
122 std::string szFilenameResolved =
123 SceneFileHandler::the()->getPathHandler()->findFile(
124 _mfUrl[i].c_str());
127 SceneFileHandler::the()->getPathHandler()->pushState();
129 // could be a real url with a relative inline path.
130 if(szFilenameResolved.empty() == true)
132 szFilenameResolved = _mfUrl[i];
135 SceneFileHandler::the()->getPathHandler()->setBaseFile(
136 szFilenameResolved.c_str());
138 std::string szFName =
139 SceneFileHandler::the()->getPathHandler()->extractFilename(
140 _mfUrl[i].c_str());
142 GraphOpSeqRefPtr pGraphOp = NULL;
144 if(_sfGraphOp.getValue().compare("none") == 0)
146 // leave it NULL
148 else if(_sfGraphOp.getValue().compare("default") == 0)
150 pGraphOp = SceneFileHandler::the()->getDefaultGraphOp();
152 else
154 pGraphOp = GraphOpSeq::create(_sfGraphOp.getValue());
157 std::string urlExt;
159 if(_mfOptions.size() != 0)
161 boost::filesystem::path urlPath(_mfUrl[i]);
162 urlExt = OSGBP2STR(urlPath.extension());
164 if(urlExt.empty() == false)
166 SceneFileHandler::the()->pushOptions(urlExt);
168 for(UInt32 j = 0; j < _mfOptions.size(); ++j)
170 SizeT uiSplit = _mfOptions[j].find('=');
172 if(uiSplit != std::string::npos)
174 std::string name = _mfOptions[j].substr(0,
175 uiSplit );
176 std::string value = _mfOptions[j].substr(uiSplit + 1);
178 SceneFileHandler::the()->setOption(urlExt,
179 name,
180 value );
186 NodeUnrecPtr pFile = SceneFileHandler::the()->read(
187 szFName.c_str(),
188 pGraphOp,
189 NULL,
190 false);
192 if(pFile == NULL)
194 pFile = SceneFileHandler::the()->read(
195 szFilenameResolved.c_str(),
196 pGraphOp,
197 NULL,
198 false);
200 if(pFile == NULL)
202 pFile = SceneFileHandler::the()->read(
203 _mfUrl[i].c_str(),
204 pGraphOp,
205 NULL,
206 false);
210 if(_mfOptions.size() != 0 && urlExt.empty() == false)
211 SceneFileHandler::the()->popOptions(urlExt);
213 if(pFile != NULL)
215 pFile->addChangedFunctor(
216 boost::bind(&Inline::rootChanged, this, _1, _2, _3),
217 "");
219 setRoot(pFile);
221 SceneFileHandler::the()->getPathHandler()->popState();
223 break;
225 else
227 SWARNING << "could not read "
228 << _mfUrl[i]
229 << std::endl;
232 SceneFileHandler::the()->getPathHandler()->popState();
235 if(i == _mfUrl.size() && _sfRoot.getValue() != NULL)
237 _sfRoot.getValue()->subChangedFunctor(
238 boost::bind(&Inline::rootChanged, this, _1, _2, _3));
240 setRoot(NULL);
244 void Inline::moveRootTo(Node *pTarget)
246 if(pTarget == NULL)
247 return;
249 NodeUnrecPtr pInlineRoot = this->getRoot();
251 this->setRoot(NULL);
253 pTarget->addChild(pInlineRoot);
257 Node *Inline::getRoot(void) const
259 return Inherited::getRoot();
262 Action::ResultE Inline::renderEnter(Action *action)
264 RenderAction *a = dynamic_cast<RenderAction *>(action);
266 a->useNodeList();
268 if(a->isVisible(this->getRoot()))
269 a->addNode(this->getRoot());
271 return Action::Continue;
274 void Inline::adjustVolume(Volume &volume)
276 if(getRoot() != NULL)
278 getRoot()->updateVolume();
280 volume.extendBy(getRoot()->getVolume());
284 void Inline::rootChanged(FieldContainer *pFC,
285 ConstFieldMaskArg whichField,
286 UInt32 origin )
288 if(0x0000 != (whichField & Node::VolumeFieldMask))
290 this->invalidateVolume();
294 void Inline::resolveLinks(void)
296 if(_sfRoot.getValue() != NULL)
298 _sfRoot.getValue()->subChangedFunctor(
299 boost::bind(&Inline::rootChanged, this, _1, _2, _3));
302 Inherited::resolveLinks();