27 #include "../common/WLogger.h"
29 #include "WPickHandler.h"
39 m_inPickMode( false ),
49 m_viewerName( viewerName ),
52 m_inPickMode( false ),
73 switch( ea.getEventType() )
75 case osgGA::GUIEventAdapter::DRAG :
76 case osgGA::GUIEventAdapter::PUSH :
78 unsigned int buttonMask = ea.getButtonMask();
79 if( buttonMask == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON )
82 osgViewer::View* view =
static_cast< osgViewer::View*
>( &aa );
88 if( ( buttonMask == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON ) && (
m_paintMode == 1 ) )
91 osgViewer::View* view =
static_cast< osgViewer::View*
>( &aa );
99 case osgGA::GUIEventAdapter::RELEASE :
102 osgViewer::View* view =
static_cast< osgViewer::View*
>( &aa );
109 case osgGA::GUIEventAdapter::SCROLL :
113 switch( ea.getScrollingMotion() )
115 case osgGA::GUIEventAdapter::SCROLL_UP:
118 case osgGA::GUIEventAdapter::SCROLL_DOWN:
120 case osgGA::GUIEventAdapter::SCROLL_2D:
122 if( ea.getScrollingDeltaY() > 0 )
136 osgViewer::View* view =
static_cast< osgViewer::View*
>( &aa );
141 ea.setHandled(
true );
146 case osgGA::GUIEventAdapter::KEYUP :
152 case osgGA::GUIEventAdapter::KEYDOWN :
154 if( ea.getKey() ==
'c' )
156 osgViewer::View* view =
static_cast< osgViewer::View*
>( &aa );
157 osg::ref_ptr< osgGA::GUIEventAdapter >
event =
new osgGA::GUIEventAdapter( ea );
158 event->setX( ( ea.getXmin() + ea.getXmax() ) * 0.5 );
159 event->setY( ( ea.getYmin() + ea.getYmax() ) * 0.5 );
162 pick( view, *event );
165 if( ea.getKey() == osgGA::GUIEventAdapter::KEY_Shift_L )
169 if( ea.getKey() == osgGA::GUIEventAdapter::KEY_Control_L || ea.getKey() == osgGA::GUIEventAdapter::KEY_Control_R )
192 std::string extractSuitableName( osgUtil::LineSegmentIntersector::Intersections::iterator hitr )
194 if( !hitr->nodePath.empty() && !( hitr->nodePath.back()->getName().empty() ) )
196 return hitr->nodePath.back()->getName();
198 else if( hitr->drawable.valid() )
200 return hitr->drawable->className();
202 assert( 0 &&
"This should not happen. Tell \"wiebel\" if it does." );
221 osgUtil::LineSegmentIntersector::Intersections intersections;
245 bool intersetionsExist = view->computeIntersections( x, y, intersections );
248 bool startPickIsStillInList =
false;
249 osgUtil::LineSegmentIntersector::Intersections::iterator hitr;
250 if( intersetionsExist )
252 assert( intersections.size() );
253 hitr = intersections.begin();
255 bool ignoreFirst =
m_ctrl;
257 while( hitr != intersections.end() )
259 std::string nodeName = extractSuitableName( hitr );
266 else if( ignoreFirst )
277 if( hitr == intersections.end() )
290 while( ( hitr != intersections.end() ) && !startPickIsStillInList )
295 if( !startPickIsStillInList )
323 pickPos[0] = hitr->getWorldIntersectPoint()[0];
324 pickPos[1] = hitr->getWorldIntersectPoint()[1];
325 pickPos[2] = hitr->getWorldIntersectPoint()[2];
328 pickNormal[0] = hitr->getWorldIntersectNormal()[0];
329 pickNormal[1] = hitr->getWorldIntersectNormal()[1];
330 pickNormal[2] = hitr->getWorldIntersectNormal()[2];