AnnotationEventCallback with multi Viewers

classic Classic list List threaded Threaded
1 message Options
LvQing LvQing
Reply | Threaded
Open this post in threaded view
|

AnnotationEventCallback with multi Viewers



As picture shown above,We use osgEarth::Annotation::PlaceNode  to present the label of a aircraft,such as PAD001,PAD002.Then we attach a osgEarth::Util::AnnotationEventCallback to each PlaceNode,code like:

osg::ref_ptr<osgEarth::Util::AnnotationEventCallback> cb = new osgEarth::Util::AnnotationEventCallback();
cb->addHandler( new CBattleObjectEventHandler());
PlaceNode->addEventCallback(cb.get());

CBattleObjectEventHandler is a custom AnnotationEventHandler which handle mouse event attched with the  PlaceNode ,such as  right click the PlaceNode  to popup a menu.

It works well so far. Until we decide to add a second view as a "follow center dialog" which to follow  a certain aircraft as the picture above.

The "follow center dialog" viewer and the main viewer are both under a same CompositeViewer,and share
a  same  SceneData.

Then the problem is ,all AnnotationEventCallback seems failed to the main viewer,but worked to the "follow center dialog" viewer!Means We can right click the PlaceNode  to popup a menu but only in the "follow center dialog" viewer not in the main viewer!Or more specific ,any PlaceNode  appeard in the  "follow center dialog" viewer are lose the fuction of its CBattleObjectEventHandler!

Our needs is the AnnotationEventHandler of PlaceNode  must functional in the main viewer.Functional in the "follow center dialog" viewer is only optional.

We dig a little up source code in \src\osgEarthUtil\AnnotationEvents.cpp

void
AnnotationEventCallback::operator()( osg::Node* node, osg::NodeVisitor* nv )

it gets a view like follow:

{
    osgGA::EventVisitor* ev = static_cast<osgGA::EventVisitor*>(nv);
    osgGA::EventVisitor::EventList& events = ev->getEvents();
    osgViewer::View* view = static_cast<osgViewer::View*>(ev->getActionAdapter());
}

but failed pick something when click PlaceNode in the main viewer if there are two viewers share
a same SceneData:

{
        Picker picker( view, node );
        Picker::Hits hits;
        if ( picker.pick( _args.x, _args.y, hits ) )   //failed return false
}


Need help
                                                                                                                                               thx!