Commit a4f29091 authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

[CHANGE] use WPickInfo instead of strings for propagating pick information.

WROIBox still needs improvements
parent afcb9c05
......@@ -28,12 +28,13 @@
#include <osg/Vec3>
#include "WPickHandler.h"
#include "WPickInfo.h"
WPickHandler::~WPickHandler()
{
}
std::string WPickHandler::getHitResult()
WPickInfo WPickHandler::getHitResult()
{
return m_hitResult;
}
......@@ -43,7 +44,7 @@ wmath::WPosition WPickHandler::getHitPosition()
return m_hitPosGlobal;
}
boost::signals2::signal1< void, std::string >* WPickHandler::getPickSignal()
boost::signals2::signal1< void, WPickInfo >* WPickHandler::getPickSignal()
{
return &m_pickSignal;
}
......@@ -97,10 +98,10 @@ bool WPickHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAda
void WPickHandler::unpick( )
{
if( m_hitResult != "" )
if( m_hitResult != WPickInfo( "", wmath::WPosition(), WPickInfo::NONE ) )
{
m_hitResult = "unpick";
m_lastPick = "";
m_hitResult = WPickInfo( "unpick", wmath::WPosition(), WPickInfo::NONE );
m_lastPick = WPickInfo( "", wmath::WPosition(), WPickInfo::NONE );
}
m_pickSignal( getHitResult() );
}
......@@ -122,7 +123,7 @@ std::string extractSuitableName( osgUtil::LineSegmentIntersector::Intersections:
void WPickHandler::pick( osgViewer::View* view, const osgGA::GUIEventAdapter& ea )
{
osgUtil::LineSegmentIntersector::Intersections intersections;
m_hitResult = "";
m_hitResult = WPickInfo();
float x = ea.getX();
float y = ea.getY();
......@@ -132,9 +133,11 @@ void WPickHandler::pick( osgViewer::View* view, const osgGA::GUIEventAdapter& ea
bool lastPickIsStillInList = false;
osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin();
while( ( hitr != intersections.end() ) && !lastPickIsStillInList ) // got to lastPicked if it can be found in intersections list
{
lastPickIsStillInList |= ( extractSuitableName( hitr ) == m_lastPick );
WPickInfo pickInfoTmp( extractSuitableName( hitr ), wmath::WPosition(), WPickInfo::NONE );
lastPickIsStillInList |= ( pickInfoTmp.getName() == m_lastPick.getName() );
if( !lastPickIsStillInList ) // if iteration not finished yet go on in list
{
......@@ -147,15 +150,23 @@ void WPickHandler::pick( osgViewer::View* view, const osgGA::GUIEventAdapter& ea
hitr = intersections.begin();
}
std::ostringstream os;
os << "Object \"" << extractSuitableName( hitr ) << "\"" << std::endl;
m_lastPick = extractSuitableName( hitr );
wmath::WPosition pickPos;
pickPos[0] = hitr->getLocalIntersectPoint()[0];
pickPos[1] = hitr->getLocalIntersectPoint()[1];
pickPos[2] = hitr->getLocalIntersectPoint()[2];
WPickInfo pickInfo( extractSuitableName( hitr ), pickPos, WPickInfo::NONE );
// std::ostringstream os;
// os << "Object \"" << extractSuitableName( hitr ) << "\"" << std::endl;
// m_lastPick = extractSuitableName( hitr );
// os << " local coords vertex(" << hitr->getLocalIntersectPoint() << ")" << " normal(" << hitr->getLocalIntersectNormal() << ")"
// << std::endl;
// os << " world coords vertex(" << hitr->getWorldIntersectPoint() << ")" << " normal(" << hitr->getWorldIntersectNormal() << ")"
// << std::endl;
// m_hitResult += os.str();
os << " local coords vertex(" << hitr->getLocalIntersectPoint() << ")" << " normal(" << hitr->getLocalIntersectNormal() << ")"
<< std::endl;
os << " world coords vertex(" << hitr->getWorldIntersectPoint() << ")" << " normal(" << hitr->getWorldIntersectNormal() << ")"
<< std::endl;
m_hitResult += os.str();
m_hitResult = pickInfo;
osg::Vec3 globalHit = hitr->getWorldIntersectPoint();
m_hitPosGlobal = wmath::WPosition( globalHit[0], globalHit[1], globalHit[2] );
......
......@@ -47,6 +47,7 @@
#include <osgText/Text>
#include "../math/WPosition.h"
#include "WPickInfo.h"
/**
* class to handle events with a pick
......@@ -76,7 +77,7 @@ public:
/**
* Gives information about the picked object.
*/
std::string getHitResult();
WPickInfo getHitResult();
/**
* Returns the position where the first object was picked.
......@@ -86,7 +87,7 @@ public:
/**
* returns the m_pickSignal to for registering to it.
*/
boost::signals2::signal1< void, std::string >* getPickSignal();
boost::signals2::signal1< void, WPickInfo >* getPickSignal();
protected:
/**
......@@ -100,12 +101,12 @@ protected:
*/
virtual ~WPickHandler();
std::string m_hitResult; //!< Textual representation of the result of a pick.
WPickInfo m_hitResult; //!< Textual representation of the result of a pick.
wmath::WPosition m_hitPosGlobal; //!< Global coordinates of the first hit of the pick.
std::string m_lastPick; //!< indicates what was last picked. Should be "" after unpick.
WPickInfo m_lastPick; //!< indicates what was last picked. Should be "" after unpick.
private:
boost::signals2::signal1<void, std::string > m_pickSignal; //!< One can register to this signal to receive pick events.
boost::signals2::signal1<void, WPickInfo > m_pickSignal; //!< One can register to this signal to receive pick events.
};
#endif // WPICKHANDLER_H
......@@ -40,6 +40,7 @@ public:
*/
enum modifierKey
{
NONE,
SHIFT,
STRG,
ALT,
......@@ -52,7 +53,12 @@ public:
* \param pickPosition position where object was hit
* \param modKey relevant modifier key pressed during the pick
*/
WPickInfo( std::string name, wmath::WPosition pickPosition, WPickInfo::modifierKey modKey );
inline WPickInfo( std::string name, wmath::WPosition pickPosition, modifierKey modKey );
/**
* Creates an object with the empty name, zero position and no modkey.
*/
inline WPickInfo();
/**
* Get the modifier key associated with the pick
......@@ -69,6 +75,18 @@ public:
*/
inline wmath::WPosition getPickPosition();
/**
* Tests two pick infos for equality
* \param rhs right hand side of comparison
*/
inline bool operator==( WPickInfo rhs );
/**
* Tests two pick infos for inequality
* \param rhs right hand side of comparison
*/
inline bool operator!=( WPickInfo rhs );
protected:
private:
......@@ -77,13 +95,20 @@ private:
modifierKey m_modKey; //!< modifier key associated with the pick
};
WPickInfo::WPickInfo( std::string name, wmath::WPosition pickPosition, WPickInfo::modifierKey modKey ) :
WPickInfo::WPickInfo( std::string name, wmath::WPosition pickPosition, modifierKey modKey ) :
m_name( name ),
m_pickPosition( pickPosition ),
m_modKey( modKey )
{
}
WPickInfo::WPickInfo() :
m_name( "" ),
m_pickPosition( wmath::WPosition() ),
m_modKey( WPickInfo::NONE )
{
}
WPickInfo::modifierKey WPickInfo::getModifierKey()
{
return m_modKey;
......@@ -99,4 +124,16 @@ wmath::WPosition WPickInfo::getPickPosition()
return m_pickPosition;
}
inline bool WPickInfo::operator==( WPickInfo rhs )
{
return ( this->m_name == rhs.m_name
&& this->m_pickPosition == rhs.m_pickPosition
&& this->m_modKey == rhs.m_modKey );
}
inline bool WPickInfo::operator!=( WPickInfo rhs )
{
return !( *this == rhs );
}
#endif // WPICKINFO_H
......@@ -89,12 +89,6 @@ private:
* updates the graphics
*/
virtual void updateGFX() = 0;
/**
* Registers whether udate is needed.
* \param text The info text that indicates the type of request.
*/
virtual void registerRedrawRequest( std::string text ) = 0;
};
#endif // WROI_H
......@@ -191,12 +191,12 @@ bool WROIBox::isModified()
return tmp;
}
void WROIBox::registerRedrawRequest( std::string text )
void WROIBox::registerRedrawRequest( WPickInfo pickInfo )
{
boost::unique_lock< boost::shared_mutex > lock;
lock = boost::unique_lock< boost::shared_mutex >( m_updateLock );
m_pickText = text;
m_pickInfo = pickInfo;
lock.unlock();
}
......@@ -207,8 +207,8 @@ void WROIBox::updateGFX()
lock = boost::unique_lock< boost::shared_mutex >( m_updateLock );
std::stringstream ss;
ss << "\"ROIBox" << boxId << "\"";
if ( m_pickText.find( "Object " ) != std::string::npos && m_pickText.find( ss.str() ) != std::string::npos )
ss << "ROIBox" << boxId << "";
if ( m_pickInfo.getName() == ss.str() )
{
// connect updateGFX with picking
boost::shared_ptr< WGraphicsEngine > ge = WGraphicsEngine::getGraphicsEngine();
......@@ -248,12 +248,13 @@ void WROIBox::updateGFX()
m_signalIsModified();
}
if ( m_isPicked && m_pickText.find( "unpick" ) != std::string::npos )
if ( m_isPicked && m_pickInfo.getName() == "unpick" )
{
osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back( osg::Vec4( 0.f, 0.f, 1.f, 0.5f ) );
( ( osg::Geometry* ) ( m_geode->getDrawable( 0 ) ) )->setColorArray( colors );
m_isPicked = false;
}
lock.unlock();
}
......@@ -73,13 +73,13 @@ private:
wmath::WPosition m_pickedPosition; //!< Caches the old picked position to a allow for cmoparison
boost::shared_mutex m_updateLock; //!< Lock to prevent concurrent threads trying to update the osg node
std::string m_pickText; //!< Stores the pick text that contains information for potential redraw
WPickInfo m_pickInfo; //!< Stores the pick information for potential redraw
/**
* note that there was a pick
* \param text info from pick
* \param pickInfo info from pick
*/
void registerRedrawRequest( std::string text );
void registerRedrawRequest( WPickInfo pickInfo );
/**
* updates the graphics
......
......@@ -94,11 +94,6 @@ public:
*/
virtual std::vector< boost::shared_ptr< WDataSet > > getDataSetList( int subjectId, bool onlyTextures = false ) = 0;
/**
* getter functions for the signales proved by the gui
*/
virtual boost::signals2::signal1< void, std::string >* getPickSignal() = 0;
/**
* Instruct the MainWindow to open a new custom widget.
*
......
......@@ -290,12 +290,6 @@ boost::signals2::signal2< void, boost::shared_ptr< WModule >, boost::shared_ptr<
return &m_moduleButtonSignal;
}
boost::signals2::signal1< void, std::string >* WMainWindow::getPickSignal()
{
return m_mainGLWidget->getPickSignal();
}
WPropertyManager* WMainWindow::getPropertyManager()
{
return &m_propertyManager;
......
......@@ -115,13 +115,6 @@ public:
*/
boost::signals2::signal2< void, boost::shared_ptr< WModule >, boost::shared_ptr< WModule > >* getModuleButtonSignal();
/**
* Returns a point to a boost signal object which emits the coordinates of a mouseclick
*
* \return the signal
*/
boost::signals2::signal1< void, std::string >* getPickSignal();
/**
* Searches for a custom dock widget with a given name and returns it, if
* found.
......
......@@ -197,11 +197,6 @@ boost::signals2::signal1< void, std::vector< std::string > >* WQt4Gui::getLoadBu
return m_mainWindow->getLoaderSignal();
}
boost::signals2::signal1< void, std::string >* WQt4Gui::getPickSignal()
{
return m_mainWindow->getPickSignal();
}
boost::shared_ptr< WCustomWidget > WQt4Gui::openCustomWidget( std::string title, WGECamera::ProjectionMode projectionMode,
boost::shared_ptr< WCondition > shutdownCondition )
{
......
......@@ -112,8 +112,6 @@ public:
*/
boost::signals2::signal1< void, std::vector< std::string > >* getLoadButtonSignal();
boost::signals2::signal1< void, std::string >* getPickSignal();
/**
* Instruct the WMainWindow to open a new custom widget.
*
......
......@@ -261,7 +261,6 @@ void WQtGLWidget::keyReleaseEvent( QKeyEvent* event )
void WQtGLWidget::mousePressEvent( QMouseEvent* event )
{
m_Viewer->mouseEvent( WGEViewer::MOUSEPRESS, event->x(), event->y(), translateButton( event ) );
m_pickSignal( m_Viewer->getPickHandler()->getHitResult() );
}
void WQtGLWidget::mouseDoubleClickEvent( QMouseEvent* event )
......@@ -295,8 +294,3 @@ void WQtGLWidget::wheelEvent( QWheelEvent* event )
m_Viewer->mouseEvent( WGEViewer::MOUSESCROLL, x, y, 0 );
}
#endif
boost::signals2::signal1< void, std::string >* WQtGLWidget::getPickSignal()
{
return &m_pickSignal;
}
......@@ -117,13 +117,6 @@ public:
*/
const WBoolFlag& isInitialized() const;
/**
* Returns the signal used for pick events.
*
* \return the signal fired on pick events.
*/
boost::signals2::signal1< void, std::string >* getPickSignal();
protected:
/**
* The viewer to the scene.
......@@ -249,11 +242,6 @@ private:
*/
WBoolFlag m_isInitialized;
/**
* The signal used for picking events inside this widget.
*/
boost::signals2::signal1<void, std::string > m_pickSignal;
/**
* True when the widget got drawn the very first time.
*/
......
......@@ -38,8 +38,6 @@
#include "../../math/WVector3D.h"
class WPickHandler;
/**
* Gauss filtering for WDataSetSingle
*
......
......@@ -192,12 +192,14 @@ void WMHud::init()
viewer->getPickHandler()->getPickSignal()->connect( boost::bind( &WMHud::updatePickText, this, _1 ) );
}
void WMHud::updatePickText( std::string text )
void WMHud::updatePickText( WPickInfo pickInfo )
{
boost::unique_lock< boost::shared_mutex > lock;
lock = boost::unique_lock< boost::shared_mutex >( m_updateLock );
m_pickText = text;
std::ostringstream os;
os << pickInfo.getName() << "\n" << pickInfo.getPickPosition();
m_pickText = os.str();
lock.unlock();
}
......
......@@ -69,9 +69,9 @@ public:
/**
* Sets pick text member vairable
*
* \param text the pick text
* \param pickInfo information about the pick
*/
void updatePickText( std::string text );
void updatePickText( WPickInfo pickInfo );
protected:
......
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