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 \*---------------------------------------------------------------------------*/
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"
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 /*-------------------------------------------------------------------------*/
62 void Inline::changed(ConstFieldMaskArg whichField
,
66 Inherited::changed(whichField
, origin
, details
);
69 /*-------------------------------------------------------------------------*/
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 /*-------------------------------------------------------------------------*/
81 Inline::Inline(void) :
86 Inline::Inline(const Inline
&source
) :
91 /*-------------------------------------------------------------------------*/
99 /*-------------------------------------------------------------------------*/
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
);
120 for(; i
< _mfUrl
.size(); ++i
)
122 std::string szFilenameResolved
=
123 SceneFileHandler::the()->getPathHandler()->findFile(
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(
142 GraphOpSeqRefPtr pGraphOp
= NULL
;
144 if(_sfGraphOp
.getValue().compare("none") == 0)
148 else if(_sfGraphOp
.getValue().compare("default") == 0)
150 pGraphOp
= SceneFileHandler::the()->getDefaultGraphOp();
154 pGraphOp
= GraphOpSeq::create(_sfGraphOp
.getValue());
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,
176 std::string value
= _mfOptions
[j
].substr(uiSplit
+ 1);
178 SceneFileHandler::the()->setOption(urlExt
,
186 NodeUnrecPtr pFile
= SceneFileHandler::the()->read(
194 pFile
= SceneFileHandler::the()->read(
195 szFilenameResolved
.c_str(),
202 pFile
= SceneFileHandler::the()->read(
210 if(_mfOptions
.size() != 0 && urlExt
.empty() == false)
211 SceneFileHandler::the()->popOptions(urlExt
);
215 pFile
->addChangedFunctor(
216 boost::bind(&Inline::rootChanged
, this, _1
, _2
, _3
),
221 SceneFileHandler::the()->getPathHandler()->popState();
227 SWARNING
<< "could not read "
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
));
244 void Inline::moveRootTo(Node
*pTarget
)
249 NodeUnrecPtr pInlineRoot
= this->getRoot();
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
);
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
,
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();