1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2008 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 #include "OSGSceneGraphUtils.h"
40 #include "OSGFieldContainerSFields.h"
41 #include "OSGFieldContainerMFields.h"
42 #include "OSGAttachment.h"
43 #include "OSGAttachmentMapSFields.h"
44 #include "OSGNameAttachment.h"
46 #include <boost/bind.hpp>
47 #include <boost/format.hpp>
54 //---------------------------------------------------------------------------
56 //---------------------------------------------------------------------------
58 SceneGraphPrinter::SceneGraphPrinter(Node
*root
)
68 void SceneGraphPrinter::printDownTree(std::ostream
&os
)
74 boost::bind(&Self::traverseEnter
, this, _1
),
75 boost::bind(&Self::traverseLeave
, this, _1
, _2
) );
80 void SceneGraphPrinter::printUpTree(std::ostream
&os
)
89 NodeCore
*core
= node
->getCore();
93 << "] [" << node
->getId()
94 << "] [" << (getName(node
) ? getName(node
) : "<unnamed>")
96 << "] [" << core
->getId()
97 << "] [" << core
->getType().getCName()
100 node
= node
->getParent();
107 SceneGraphPrinter::addPrintFunc(const FieldContainerType
&fcType
,
108 const CorePrintFunction
&printFunc
)
110 _printFuncMap
[fcType
.getId()] = printFunc
;
114 SceneGraphPrinter::subPrintFunc(const FieldContainerType
&fcType
)
116 PrintFuncMapIt pfIt
= _printFuncMap
.find(fcType
.getId());
118 if(pfIt
!= _printFuncMap
.end())
119 _printFuncMap
.erase(pfIt
);
123 SceneGraphPrinter::incIndent(void)
129 SceneGraphPrinter::decIndent(void)
135 SceneGraphPrinter::indentStream(void)
137 for(UInt32 i
= 0; i
< _indent
; ++i
)
144 SceneGraphPrinter::getStream(void)
150 SceneGraphPrinter::getCurrNode(void)
155 Action::ResultE
SceneGraphPrinter::traverseEnter(Node
*node
)
158 return Action::Continue
;
162 std::ostream
&os
= getStream();
167 << "] [" << node
->getId()
168 << "] [" << (getName(node
) ? getName(node
) : "<unnamed>")
171 NodeCore
*core
= node
->getCore();
175 os
<< " -- !! MISSING CORE !!\n";
176 return Action::Continue
;
179 os
<< " -- [" << core
180 << "] [" << core
->getId()
181 << "] [" << core
->getType().getCName()
184 os
<< " [" << (getName(core
) ? getName(core
) : "<unnamed>")
187 NodeCore::MFParentsType::const_iterator pIt
= core
->getMFParents()->begin();
188 NodeCore::MFParentsType::const_iterator pEnd
= core
->getMFParents()->end ();
190 if(core
->getMFParents()->size() > 1)
192 os
<< " # parents [" << core
->getMFParents()->size() << "] #";
194 for(; pIt
!= pEnd
; ++pIt
)
196 Node
*parent
= dynamic_cast<Node
*>(*pIt
);
199 << "] [" << (getName(parent
) ? getName(parent
) : "<unnamed>")
206 // if there is a print function registered for this core type call it
207 PrintFuncMapConstIt pfIt
= _printFuncMap
.find(core
->getType().getId());
209 if(pfIt
!= _printFuncMap
.end())
212 (pfIt
->second
)(this, core
);
216 return Action::Continue
;
219 Action::ResultE
SceneGraphPrinter::traverseLeave(
220 Node
*node
, Action::ResultE res
)
223 return Action::Continue
;
227 return Action::Continue
;