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

Revision 13041, 2.8 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
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*/
13#include <osg/CopyOp>
14#include <osg/Node>
15#include <osg/StateSet>
16#include <osg/Texture>
17#include <osg/Drawable>
18#include <osg/Array>
19#include <osg/PrimitiveSet>
20#include <osg/Shape>
21#include <osg/StateAttribute>
22
23using namespace osg;
24
25#define COPY_OP( TYPE, FLAG ) \
26TYPE* CopyOp::operator() (const TYPE* obj) const \
27{ \
28    if (obj && _flags&FLAG) \
29        return osg::clone(obj, *this); \
30    else \
31        return const_cast<TYPE*>(obj); \
32}
33
34COPY_OP( Object,                   DEEP_COPY_OBJECTS )
35COPY_OP( Node,                     DEEP_COPY_NODES )
36COPY_OP( StateSet,                 DEEP_COPY_STATESETS )
37COPY_OP( Image,                    DEEP_COPY_IMAGES )
38COPY_OP( Uniform,                  DEEP_COPY_UNIFORMS )
39COPY_OP( StateAttributeCallback,   DEEP_COPY_CALLBACKS )
40COPY_OP( Drawable,                 DEEP_COPY_DRAWABLES )
41COPY_OP( Texture,                  DEEP_COPY_TEXTURES )
42COPY_OP( Array,                    DEEP_COPY_ARRAYS )
43COPY_OP( PrimitiveSet,             DEEP_COPY_PRIMITIVES )
44COPY_OP( Shape,                    DEEP_COPY_SHAPES )
45
46Referenced* CopyOp::operator() (const Referenced* ref) const
47{
48    return const_cast<Referenced*>(ref);
49}
50
51StateAttribute* CopyOp::operator() (const StateAttribute* attr) const
52{
53    if (attr && _flags&DEEP_COPY_STATEATTRIBUTES)
54    {
55        const Texture* textbase = dynamic_cast<const Texture*>(attr);
56        if (textbase)
57        {
58            return operator()(textbase);
59        }
60        else
61        {
62            return osg::clone(attr, *this);
63        }
64    }
65    else
66        return const_cast<StateAttribute*>(attr);
67}
68
69NodeCallback* CopyOp::operator() (const NodeCallback* nc) const
70{
71    if (nc && _flags&DEEP_COPY_CALLBACKS)
72    {
73        // deep copy the full chain of callback
74        osg::NodeCallback* first = osg::clone(nc, *this);
75        if (!first) return 0;
76
77        first->setNestedCallback(0);
78        nc = nc->getNestedCallback();
79        while (nc)
80        {
81            osg::NodeCallback* ucb = osg::clone(nc, *this);
82            if (ucb)
83            {
84                ucb->setNestedCallback(0);
85                first->addNestedCallback(ucb);
86            }
87            nc = nc->getNestedCallback();
88        }
89        return first;
90    }
91    else
92        return const_cast<NodeCallback*>(nc);
93}
Note: See TracBrowser for help on using the browser.