| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 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 | |
|---|
| 23 | using namespace osg; |
|---|
| 24 | |
|---|
| 25 | #define COPY_OP( TYPE, FLAG ) \ |
|---|
| 26 | TYPE* CopyOp::operator() (const TYPE* obj) const \ |
|---|
| 27 | { \ |
|---|
| 28 | if (obj && _flags&FLAG) \ |
|---|
| 29 | return dynamic_cast<TYPE*>( obj->clone(*this) ); \ |
|---|
| 30 | else \ |
|---|
| 31 | return const_cast<TYPE*>(obj); \ |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | COPY_OP( Object, DEEP_COPY_OBJECTS ) |
|---|
| 35 | COPY_OP( Node, DEEP_COPY_NODES ) |
|---|
| 36 | COPY_OP( Drawable, DEEP_COPY_DRAWABLES ) |
|---|
| 37 | COPY_OP( StateSet, DEEP_COPY_STATESETS ) |
|---|
| 38 | COPY_OP( Texture, DEEP_COPY_TEXTURES ) |
|---|
| 39 | COPY_OP( Image, DEEP_COPY_IMAGES ) |
|---|
| 40 | COPY_OP( Array, DEEP_COPY_ARRAYS ) |
|---|
| 41 | COPY_OP( PrimitiveSet, DEEP_COPY_PRIMITIVES ) |
|---|
| 42 | COPY_OP( Shape, DEEP_COPY_SHAPES ) |
|---|
| 43 | COPY_OP( Uniform, DEEP_COPY_UNIFORMS ) |
|---|
| 44 | |
|---|
| 45 | Referenced* CopyOp::operator() (const Referenced* ref) const |
|---|
| 46 | { |
|---|
| 47 | return const_cast<Referenced*>(ref); |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | StateAttribute* CopyOp::operator() (const StateAttribute* attr) const |
|---|
| 51 | { |
|---|
| 52 | if (attr && _flags&DEEP_COPY_STATEATTRIBUTES) |
|---|
| 53 | { |
|---|
| 54 | const Texture* textbase = dynamic_cast<const Texture*>(attr); |
|---|
| 55 | if (textbase) |
|---|
| 56 | { |
|---|
| 57 | return operator()(textbase); |
|---|
| 58 | } |
|---|
| 59 | else |
|---|
| 60 | { |
|---|
| 61 | return dynamic_cast<StateAttribute*>(attr->clone(*this)); |
|---|
| 62 | } |
|---|
| 63 | } |
|---|
| 64 | else |
|---|
| 65 | return const_cast<StateAttribute*>(attr); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | NodeCallback* CopyOp::operator() (const NodeCallback* nc) const |
|---|
| 70 | { |
|---|
| 71 | if (nc && _flags&DEEP_COPY_CALLBACKS) |
|---|
| 72 | { |
|---|
| 73 | |
|---|
| 74 | osg::NodeCallback* first = dynamic_cast<osg::NodeCallback*>(nc->clone(*this)); |
|---|
| 75 | first->setNestedCallback(0); |
|---|
| 76 | nc = nc->getNestedCallback(); |
|---|
| 77 | while (nc) |
|---|
| 78 | { |
|---|
| 79 | osg::NodeCallback* ucb = dynamic_cast<osg::NodeCallback*>(nc->clone(*this)); |
|---|
| 80 | ucb->setNestedCallback(0); |
|---|
| 81 | first->addNestedCallback(ucb); |
|---|
| 82 | nc = nc->getNestedCallback(); |
|---|
| 83 | } |
|---|
| 84 | return first; |
|---|
| 85 | } |
|---|
| 86 | else |
|---|
| 87 | return const_cast<NodeCallback*>(nc); |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | StateAttributeCallback* CopyOp::operator() (const StateAttributeCallback* sc) const |
|---|
| 92 | { |
|---|
| 93 | if (sc && _flags&DEEP_COPY_CALLBACKS) |
|---|
| 94 | { |
|---|
| 95 | |
|---|
| 96 | StateAttributeCallback* cb = dynamic_cast<StateAttributeCallback*>(sc->clone(*this)); |
|---|
| 97 | return cb; |
|---|
| 98 | } |
|---|
| 99 | else |
|---|
| 100 | return const_cast<StateAttributeCallback*>(sc); |
|---|
| 101 | } |
|---|