| 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 | |
|---|
| 22 | using namespace osg; |
|---|
| 23 | |
|---|
| 24 | #define COPY_OP( TYPE, FLAG ) \ |
|---|
| 25 | TYPE* 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 | |
|---|
| 33 | COPY_OP( Object, DEEP_COPY_OBJECTS ) |
|---|
| 34 | COPY_OP( Node, DEEP_COPY_NODES ) |
|---|
| 35 | COPY_OP( Drawable, DEEP_COPY_DRAWABLES ) |
|---|
| 36 | COPY_OP( StateSet, DEEP_COPY_STATESETS ) |
|---|
| 37 | COPY_OP( Texture, DEEP_COPY_TEXTURES ) |
|---|
| 38 | COPY_OP( Image, DEEP_COPY_IMAGES ) |
|---|
| 39 | COPY_OP( Array, DEEP_COPY_ARRAYS ) |
|---|
| 40 | COPY_OP( PrimitiveSet, DEEP_COPY_PRIMITIVES ) |
|---|
| 41 | COPY_OP( Shape, DEEP_COPY_SHAPES ) |
|---|
| 42 | COPY_OP( Uniform, DEEP_COPY_UNIFORMS ) |
|---|
| 43 | |
|---|
| 44 | Referenced* CopyOp::operator() (const Referenced* ref) const |
|---|
| 45 | { |
|---|
| 46 | return const_cast<Referenced*>(ref); |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | StateAttribute* CopyOp::operator() (const StateAttribute* attr) const |
|---|
| 50 | { |
|---|
| 51 | if (attr && _flags&DEEP_COPY_STATEATTRIBUTES) |
|---|
| 52 | { |
|---|
| 53 | const Texture* textbase = dynamic_cast<const Texture*>(attr); |
|---|
| 54 | if (textbase) |
|---|
| 55 | { |
|---|
| 56 | return operator()(textbase); |
|---|
| 57 | } |
|---|
| 58 | else |
|---|
| 59 | { |
|---|
| 60 | return dynamic_cast<StateAttribute*>(attr->clone(*this)); |
|---|
| 61 | } |
|---|
| 62 | } |
|---|
| 63 | else |
|---|
| 64 | return const_cast<StateAttribute*>(attr); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | NodeCallback* CopyOp::operator() (const NodeCallback* nc) const |
|---|
| 69 | { |
|---|
| 70 | if (nc && _flags&DEEP_COPY_NODECALLBACKS) |
|---|
| 71 | { |
|---|
| 72 | |
|---|
| 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 | } |
|---|