27 #include "WPickHandler.h"
28 #include "../common/WAssert.h"
40 m_inPickMode( false ),
50 m_viewerName( viewerName ),
53 m_inPickMode( false ),
74 switch( ea.getEventType() )
76 case osgGA::GUIEventAdapter::DRAG :
77 case osgGA::GUIEventAdapter::PUSH :
79 unsigned int buttonMask = ea.getButtonMask();
80 if( buttonMask == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON )
83 osgViewer::View* view =
static_cast< osgViewer::View*
>( &aa );
89 if( ( buttonMask == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON ) && (
m_paintMode ) )
92 osgViewer::View* view =
static_cast< osgViewer::View*
>( &aa );
100 case osgGA::GUIEventAdapter::RELEASE :
103 osgViewer::View* view =
static_cast< osgViewer::View*
>( &aa );
110 case osgGA::GUIEventAdapter::SCROLL :
114 switch( ea.getScrollingMotion() )
116 case osgGA::GUIEventAdapter::SCROLL_UP:
119 case osgGA::GUIEventAdapter::SCROLL_DOWN:
122 case osgGA::GUIEventAdapter::SCROLL_2D:
124 if( ea.getScrollingDeltaY() > 0 )
138 osgViewer::View* view =
static_cast< osgViewer::View*
>( &aa );
143 ea.setHandled(
true );
148 case osgGA::GUIEventAdapter::KEYUP :
154 case osgGA::GUIEventAdapter::KEYDOWN :
156 if( ea.getKey() ==
'c' )
158 osgViewer::View* view =
static_cast< osgViewer::View*
>( &aa );
159 osg::ref_ptr< osgGA::GUIEventAdapter >
event =
new osgGA::GUIEventAdapter( ea );
160 event->setX( ( ea.getXmin() + ea.getXmax() ) * 0.5 );
161 event->setY( ( ea.getYmin() + ea.getYmax() ) * 0.5 );
164 pick( view, *event );
167 if( ea.getKey() == osgGA::GUIEventAdapter::KEY_Shift_L )
171 if( ea.getKey() == osgGA::GUIEventAdapter::KEY_Control_L || ea.getKey() == osgGA::GUIEventAdapter::KEY_Control_R )
194 std::string extractSuitableName( osgUtil::LineSegmentIntersector::Intersections::iterator hitr )
196 if( !hitr->nodePath.empty() && !( hitr->nodePath.back()->getName().empty() ) )
198 return hitr->nodePath.back()->getName();
200 else if( hitr->drawable.valid() )
202 return hitr->drawable->className();
204 assert( 0 &&
"This should not happen. Tell \"wiebel\" if it does." );
223 osgUtil::LineSegmentIntersector::Intersections intersections;
247 bool intersetionsExist = view->computeIntersections( x, y, intersections, 0xFFFFFFF0 );
250 bool startPickIsStillInList =
false;
251 osgUtil::LineSegmentIntersector::Intersections::iterator hitr;
252 if( intersetionsExist )
254 hitr = intersections.begin();
257 while( hitr != intersections.end() )
259 std::string nodeName = extractSuitableName( hitr );
260 std::cout << nodeName << std::endl;
264 std::cout <<
"-----------" << std::endl;
267 assert( intersections.size() );
268 hitr = intersections.begin();
270 bool ignoreFirst =
m_ctrl;
272 while( hitr != intersections.end() )
274 std::string nodeName = extractSuitableName( hitr );
275 WAssert( nodeName.size() > 2,
"Geode name too short for picking." );
278 if( nodeName[0] ==
'_' && nodeName[1] ==
'_' )
293 else if( ignoreFirst )
304 if( hitr == intersections.end() )
317 while( ( hitr != intersections.end() ) && !startPickIsStillInList )
322 if( !startPickIsStillInList )
350 pickPos[0] = hitr->getWorldIntersectPoint()[0];
351 pickPos[1] = hitr->getWorldIntersectPoint()[1];
352 pickPos[2] = hitr->getWorldIntersectPoint()[2];
360 const osgUtil::LineSegmentIntersector::Intersection::IndexList& vil = hitr->indexList;
361 osg::ref_ptr< osg::Geometry > geo =
dynamic_cast< osg::Geometry*
>( hitr->drawable.get() );
362 float* normals = (
float* ) geo->getNormalArray()->getDataPointer();
363 size_t vertexIdx = vil[0];
364 pickNormal[0] = normals[vertexIdx * 3];
365 pickNormal[1] = normals[vertexIdx * 3 + 1];
366 pickNormal[2] = normals[vertexIdx * 3 + 2];
395 WAssert( mode == 1 || mode == 0,
"Unexpected value" );
virtual void unpick()
Send a pick signal with the unpickString.
WPickInfo m_hitResult
Textual representation of the result of a pick.
WPickHandler()
Constructor that initalizes members with sensible defaults.
bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
Deals with the events found by the osg.
bool m_shift
is shift pressed?
WPickInfo m_startPick
indicates what was first picked. Should be "" after unpick.
boost::signals2::signal< void(WPickInfo) > m_pickSignal
One can register to this signal to receive pick events.
std::string m_viewerName
which viewer sends the signal
void updatePickInfoModifierKeys(WPickInfo *pickInfo)
Sets the current modifiers to the provided pickInfo.
bool m_ctrl
is ctrl pressed?
boost::signals2::signal< void(WPickInfo) > * getPickSignal()
virtual void pick(osgViewer::View *view, const osgGA::GUIEventAdapter &ea)
Send a pick signal with the pick information as string.
WPickInfo::WMouseButton m_mouseButton
stores mouse button that initiated the pick
bool m_inPickMode
if true, the pick handler currently is in pick mode.
WPickInfo getHitResult()
Gives information about the picked object.
int32_t m_scrollWheel
the virtual value of the scrollwheel
virtual ~WPickHandler()
Virtual destructor needed because of virtual function.
bool m_paintMode
the paint mode
OW_API_DEPRECATED void setPaintMode(int mode)
setter for paint mode
static const std::string unpickString
The string indicating picking has stopped.
Encapsulates info for pick action.
WPosition getPickPosition() const
Get position where object was hit.
void setModifierKey(const modifierKey &modKey)
Set the modifier key associated with the pick.
WVector3d getPickNormal() const
Get normal at position where object was hit.
std::string getName() const
Get name of picked object.
modifierKey getModifierKey() const
Get the modifier key associated with the pick.
This only is a 3d double vector.