I have a quick question that I may be over-thinking, of which I have yet
to find a simple answer.

Imagine that I have a class Derived from osg::MatrixTransform--let's
call this osgWidget::Window. In my derived Window class, I have a number
of osg::ref_ptr<> objects referencing various things that get added to
the Window object itself, and which I keep around for ease of use
elsewhere in the API.

I want to provide suitable copy constructors (and am required to do so
by using the META_Object macro, thankfully), but I'm beginning to see a
definite problem when setting the pointers in the "new" copies ref_ptr
object. Usually I can come up with clever tricks to do so, but generally
it's not very straightforward--which leads me to my main question: is it
generally bad design to keep ref_ptr's around like this when designing
classes that will directly derive from OSG objects? Using
osg::CopyOp::DEEP_COPY_ALL ensures that I will get a full copy of the
subgraph, which is certainly the desired behavior, but I'm not entirely
sure I know the best way to easily set any internal ref_ptr's to the new
subgraph after copy other than--like I mentioned earlier--clever
tricks. :) Below is an example of one such abomination:



// Here we're in the copy ctor()
Window::Window(const Window& w, const CopyOp& co):
MatrixTransform(w, co) {
        ColorArray* c = dynamic_cast<ColorArray*>(getColorArray());
        
        if(c) _c = c;
}



...where _c is my osg::ref_ptr<ColorArray> object, and where
getColorArray() works because we're using DEEP_COPY_ALL and we assume
all of the geometry was deeply copied into the new object.

I really feel like I'm missing an easier way to do this...

_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to