Commit 0123a060 authored by Alexander Wiebel's avatar Alexander Wiebel

[FIX #214] get pick signal directly from GE now. Thus we do not have the

pick delay anymore.
parent ead0ee25
......@@ -27,10 +27,6 @@
#include "WPickHandler.h"
WPickHandler::WPickHandler()
{
}
WPickHandler::~WPickHandler()
{
}
......@@ -40,18 +36,25 @@ std::string WPickHandler::getHitResult()
return m_hitResult;
}
boost::signals2::signal1< void, std::string >* WPickHandler::getPickSignal()
{
return &m_pickSignal;
}
bool WPickHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
switch ( ea.getEventType() )
{
case( osgGA::GUIEventAdapter::PUSH ):
case osgGA::GUIEventAdapter::PUSH : // Mousebutton pushed
{
osgViewer::View* view = static_cast< osgViewer::View* >( &aa );
if ( view )
{
pick( view, ea );
}
return false;
}
case( osgGA::GUIEventAdapter::KEYDOWN ):
case osgGA::GUIEventAdapter::KEYDOWN : // Key on keyboard pushed.
{
if ( ea.getKey() == 'c' )
{
......@@ -99,4 +102,5 @@ void WPickHandler::pick( osgViewer::View* view, const osgGA::GUIEventAdapter& ea
<< std::endl;
m_hitResult += os.str();
}
m_pickSignal( getHitResult() );
}
......@@ -28,6 +28,8 @@
#include <sstream>
#include <string>
#include <boost/signals2/signal.hpp>
#include <osgUtil/Optimizer>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
......@@ -51,19 +53,30 @@
class WPickHandler: public osgGA::GUIEventHandler
{
public:
WPickHandler();
/**
* Virtual destructor needed because of virtual fuction.
*/
virtual ~WPickHandler();
bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa );
virtual void pick( osgViewer::View* view, const osgGA::GUIEventAdapter& ea );
/**
* Gives information about the picked object.
*/
std::string getHitResult();
/**
* returns the m_pickSignal to for registering to it.
*/
boost::signals2::signal1< void, std::string >* getPickSignal();
protected:
std::string m_hitResult;
std::string m_hitResult; //!< Textual representation of the result of a pick.
private:
boost::signals2::signal1<void, std::string > m_pickSignal; //!< One can register to this signal to receive pick events.
};
#endif // WPICKHANDLER_H
......@@ -186,7 +186,10 @@ void WMHud::init()
m_rootNode->setNodeMask( 0x0 );
}
WKernel::getRunningKernel()->getGui()->getPickSignal()->connect( boost::bind( &WMHud::updatePickText, this, _1 ) );
// connect updateGFX with picking
boost::shared_ptr< WGEViewer > viewer = WKernel::getRunningKernel()->getGraphicsEngine()->getViewerByName( "main" );
assert( viewer );
viewer->getPickHandler()->getPickSignal()->connect( boost::bind( &WMHud::updatePickText, this, _1 ) );
}
void WMHud::updatePickText( std::string text )
......
......@@ -82,6 +82,11 @@ void WMPrototypeBoxManipulation::moduleMain()
// use the m_input "data changed" flag
m_moduleState.add( m_input->getDataChangedCondition() );
// connect updateGFX with picking
boost::shared_ptr< WGEViewer > viewer = WKernel::getRunningKernel()->getGraphicsEngine()->getViewerByName( "main" );
assert( viewer );
viewer->getPickHandler()->getPickSignal()->connect( boost::bind( &WMPrototypeBoxManipulation::updateGFX, this, _1 ) );
// signal ready state
ready();
......@@ -253,17 +258,22 @@ void WMPrototypeBoxManipulation::draw()
osg::ref_ptr<osg::LightModel> lightModel = new osg::LightModel();
lightModel->setTwoSided( true );
state->setAttributeAndModes( lightModel.get(), osg::StateAttribute::ON );
state->setMode( GL_BLEND, osg::StateAttribute::ON );
state->setMode( GL_BLEND, osg::StateAttribute::ON );
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->addChild( m_geode );
debugLog() << "Intial draw " << std::endl;
}
void WMPrototypeBoxManipulation::updateGFX()
void WMPrototypeBoxManipulation::updateGFX( std::string text )
{
boost::shared_lock<boost::shared_mutex> slock;
slock = boost::shared_lock<boost::shared_mutex>( m_updateLock );
if( text.find( "Object ") != std::string::npos
&& text.find( "\"Box\"" ) != std::string::npos )
{
std::cout << "Picked Box with Info: " << text << std::endl;
}
slock.unlock();
}
......@@ -81,8 +81,9 @@ public:
/**
* updates the graphics
* \param text text info from pick
*/
void updateGFX();
void updateGFX( std::string text );
protected:
/**
......@@ -146,7 +147,7 @@ inline void BoxNodeCallback::operator()( osg::Node* node, osg::NodeVisitor* nv )
{
if ( m_module )
{
m_module->updateGFX();
m_module->updateGFX( "..." );
}
traverse( node, nv );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment