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 "OSGConvertInlineGraphOp.h"
40 #include "OSGGraphOpFactory.h"
41 #include "OSGAction.h"
42 #include "OSGInline.h"
44 #include "OSGVisitSubTree.h"
48 #include <boost/bind.hpp>
50 /*! \class OSG::ConvertInlineGraphOp
51 \ingroup GrpSystemNodeCoresDrawablesGeometry
53 replaces inline cores by group cores and move the inline root
61 static bool registerOp(void)
63 GraphOpRefPtr newOp
= ConvertInlineGraphOp::create();
65 GraphOpFactory::the()->registerOp(newOp
);
69 static OSG::StaticInitFuncWrapper
registerOpWrapper(registerOp
);
72 const char *ConvertInlineGraphOp::getClassname(void)
74 return "ConvertInlineGraphOp";
77 ConvertInlineGraphOp::ConvertInlineGraphOp(const char* name
) :
79 _bTreeCloneShared(false)
84 ConvertInlineGraphOpTransitPtr
ConvertInlineGraphOp::create(void)
86 return ConvertInlineGraphOpTransitPtr(new ConvertInlineGraphOp
);
89 GraphOpTransitPtr
ConvertInlineGraphOp::clone(void)
91 return GraphOpTransitPtr(new ConvertInlineGraphOp
);
94 void ConvertInlineGraphOp::setParams(const std::string params
)
98 ps("treecloneshared", _bTreeCloneShared
);
100 std::string out
= ps
.getUnusedParams();
103 FWARNING(("ConvertInlineGraphOp doesn't have parameters '%s'.\n",
108 std::string
ConvertInlineGraphOp::usage(void)
111 "ConvertInline: replaces inline core by group/visit sub tree core.\n"
112 "Params: name (type, default)\n"
113 " treeCloneShared (bool, false): clone tree if inline core is shared,"
114 " default : use VisitSubTree\n";
119 ConvertInlineGraphOp::~ConvertInlineGraphOp(void)
125 Action::ResultE
ConvertInlineGraphOp::traverseEnter(Node
* const node
)
127 if(isInExcludeList(node
))
130 Inline
*pInline
= dynamic_cast<Inline
*>(node
->getCore());
133 return Action::Continue
;
135 if(pInline
->getMFParents()->size() > 1)
137 if(_bTreeCloneShared
== false)
139 VisitSubTreeUnrecPtr pVS
= VisitSubTree::create();
141 pVS
->setSubTreeRoot(pInline
->getRoot());
147 NodeUnrecPtr pClone
= cloneTree(pInline
->getRoot());
149 node
->addChild(pClone
);
151 node
->setCore(Group::create());
153 // fprintf(stderr, "multi parent inline not handled\n");
156 return Action::Continue
;
160 pInline
->moveRootTo(node
);
162 node
->setCore(Group::create());
165 return Action::Continue
;
168 Action::ResultE
ConvertInlineGraphOp::traverseLeave(
170 Action::ResultE res
)
172 return Action::Continue
;