root/OpenSceneGraph/trunk/src/osg/CopyOp.cpp @ 10362

Revision 10362, 2.7 kB (checked in by robert, 6 years ago)

From Cedric Pinson and Robert Osfield, addition of NodeCallbacks? to osg::CopyOp? and osg::Node copy constructor.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
RevLine 
[5328]1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
[1529]2 *
3 * This library is open source and may be redistributed and/or modified under 
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
[329]13#include <osg/CopyOp>
14#include <osg/Node>
15#include <osg/StateSet>
[1099]16#include <osg/Texture>
[329]17#include <osg/Drawable>
[972]18#include <osg/Array>
[1166]19#include <osg/PrimitiveSet>
[1242]20#include <osg/Shape>
[329]21
22using namespace osg;
23
[2861]24#define COPY_OP( TYPE, FLAG ) \
25TYPE* CopyOp::operator() (const TYPE* obj) const \
26{ \
27    if (obj && _flags&FLAG) \
28        return dynamic_cast<TYPE*>( obj->clone(*this) ); \
29    else \
30        return const_cast<TYPE*>(obj); \
31}
32
[6459]33COPY_OP( Object,         DEEP_COPY_OBJECTS )
34COPY_OP( Node,           DEEP_COPY_NODES )
35COPY_OP( Drawable,       DEEP_COPY_DRAWABLES )
36COPY_OP( StateSet,       DEEP_COPY_STATESETS )
37COPY_OP( Texture,        DEEP_COPY_TEXTURES )
38COPY_OP( Image,          DEEP_COPY_IMAGES )
39COPY_OP( Array,          DEEP_COPY_ARRAYS )
40COPY_OP( PrimitiveSet,   DEEP_COPY_PRIMITIVES )
41COPY_OP( Shape,          DEEP_COPY_SHAPES )
42COPY_OP( Uniform,        DEEP_COPY_UNIFORMS )
[2861]43
[329]44Referenced* CopyOp::operator() (const Referenced* ref) const
45{
46    return const_cast<Referenced*>(ref);
47}
48
49StateAttribute* CopyOp::operator() (const StateAttribute* attr) const
50{
51    if (attr && _flags&DEEP_COPY_STATEATTRIBUTES)
52    {
[1099]53        const Texture* textbase = dynamic_cast<const Texture*>(attr);
[1073]54        if (textbase)
[329]55        {
[1073]56            return operator()(textbase);
[329]57        }
[1073]58        else 
59        {
[1099]60            return dynamic_cast<StateAttribute*>(attr->clone(*this));
[1073]61        }
[329]62    }
63    else
64        return const_cast<StateAttribute*>(attr);
65}
66
67
[10362]68NodeCallback* CopyOp::operator() (const NodeCallback* nc) const
69{
70    if (nc && _flags&DEEP_COPY_NODECALLBACKS)
71    {
72        // deep copy the full chain of callback
73        osg::NodeCallback* first = dynamic_cast<osg::NodeCallback*>(nc->clone(*this));
74        first->setNestedCallback(0);
75        nc = nc->getNestedCallback();
76        while (nc)
77        {
78            osg::NodeCallback* ucb = dynamic_cast<osg::NodeCallback*>(nc->clone(*this));
79            ucb->setNestedCallback(0);
80            first->addNestedCallback(ucb);
81            nc = nc->getNestedCallback();
82        }
83        return first;
84    }
85    else
86        return const_cast<NodeCallback*>(nc);
87}
Note: See TracBrowser for help on using the browser.