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, 0xFFFFFFF0 );
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];
bool m_inPickMode
if true, the pick handler currently is in pick mode.
WVector3d getPickNormal() const
Get normal at position where object was hit.
WPosition getPickPosition() const
Get position where object was hit.
void setPaintMode(int mode)
setter for paint mode
This only is a 3d double vector.
void setModifierKey(const modifierKey &modKey)
Set the modifier key associated with the pick.
WPickInfo m_hitResult
Textual representation of the result of a pick.
void updatePickInfoModifierKeys(WPickInfo *pickInfo)
Sets the current modifiers to the provided pickInfo.
virtual void pick(osgViewer::View *view, const osgGA::GUIEventAdapter &ea)
Send a pick signal with the pick information as string.
int m_paintMode
the paint mode
WPickHandler()
Constructor that initalizes members with sensible defaults.
modifierKey getModifierKey() const
Get the modifier key associated with the pick.
boost::signals2::signal1< void, WPickInfo > * getPickSignal()
returns the m_pickSignal to for registering to it.
WPickInfo getHitResult()
Gives information about the picked object.
virtual void unpick()
Send a pick signal with the string "unpick".
bool m_ctrl
is ctrl pressed?
bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
Deals with the events found by the osg.
int32_t m_scrollWheel
the virtual value of the scrollwheel
Encapsulates info for pick action.
WPickInfo m_startPick
indicates what was first picked. Should be "" after unpick.
boost::signals2::signal1< void, WPickInfo > m_pickSignal
One can register to this signal to receive pick events.
virtual ~WPickHandler()
Virtual destructor needed because of virtual function.
std::string m_viewerName
which viewer sends the signal
bool m_shift
is shift pressed?
WPickInfo::WMouseButton m_mouseButton
stores mouse button that initiated the pick
std::string getName() const
Get name of picked object.