Commit 9f361012 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE] click handling an matrix query callback now used in transfercal module

parent dcaf8b4d
......@@ -25,6 +25,7 @@
#ifndef WGETMATRIXCALLBACK_H
#define WGETMATRIXCALLBACK_H
#include <osg/ref_ptr>
#include <osg/NodeCallback>
#include <osg/NodeVisitor>
#include <osg/Node>
......@@ -39,6 +40,16 @@
class WGetMatrixCallback: public osg::NodeCallback
{
public:
/**
* Reference counted pointer
*/
typedef osg::ref_ptr< WGetMatrixCallback > RefPtr;
/**
* Reference counted pointer
*/
typedef osg::ref_ptr< const WGetMatrixCallback > ConstRefPtr;
/**
* Default constructor.
*/
......
......@@ -27,7 +27,8 @@
#include "WViewEventHandler.h"
WViewEventHandler::WViewEventHandler():
osgGA::GUIEventHandler()
osgGA::GUIEventHandler(),
m_wasDrag( false )
{
// initialize members
}
......@@ -37,7 +38,7 @@ WViewEventHandler::~WViewEventHandler()
// cleanup
}
bool WViewEventHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& /*aa*/ )
bool WViewEventHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
// handle the interesting events
switch( ea.getEventType() )
......@@ -48,16 +49,25 @@ bool WViewEventHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActi
// middle and right button initiates dragging. Store initial mouse coordinates
if( ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON )
{
m_onLeftClick( WVector2i( ea.getX(), ea.getY() ) );
// if this was a drag, ignore it as onLeftClick only reacts on pure clicks
if( !m_wasDrag )
{
m_onLeftClick( WVector2i( ea.getX(), ea.getY() ) );
}
m_wasDrag = false;
}
break;
case osgGA::GUIEventAdapter::DOUBLECLICK:
break;
default:
return false;
case osgGA::GUIEventAdapter::DRAG:
m_wasDrag = true;
break;
default:
break;
}
return true;
// in ALL cases, allow standard handling
return osgGA::GUIEventHandler::handle( ea, aa );
}
boost::signals2::connection WViewEventHandler::onLeftClick( t_MouseHandlerType handler )
......
......@@ -99,6 +99,11 @@ private:
* Signal for left click events.
*/
t_MouseHandlerSignalType m_onLeftClick;
/**
* If true, the next release will be after a drag event
*/
bool m_wasDrag;
};
#endif // WVIEWEVENTHANDLER_H
......
......@@ -50,6 +50,9 @@
#include "core/graphicsEngine/WGEUtils.h"
#include "core/graphicsEngine/WGERequirement.h"
#include "../interaction/WViewEventHandler.h"
#include "../interaction/WGetMatrixCallback.h"
#include "WMTransferCalc.xpm"
#include "WMTransferCalc.h"
......@@ -111,6 +114,13 @@ void WMTransferCalc::requirements()
m_requirements.push_back( new WGERequirement() );
}
void WMTransferCalc::onClick( WVector2i mousePos )
{
debugLog() << "Left Click at " << mousePos;
debugLog() << "Projection Matrix: " << m_matrixCallback->getProjectionMatrix()->get();
debugLog() << "ModelView Matrix: " << m_matrixCallback->getModelViewMatrix()->get();
}
void WMTransferCalc::moduleMain()
{
debugLog() << "moduleMain started...";
......@@ -126,6 +136,15 @@ void WMTransferCalc::moduleMain()
//m_rootNode->addUpdateCallback( new TranslateCallback( this ) );
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->insert( m_rootNode );
// Create and add an event handler for the main view as we are interested in click events
WViewEventHandler::RefPtr handler( new WViewEventHandler() );
WKernel::getRunningKernel()->getGraphicsEngine()->getViewer()->getView()->addEventHandler( handler );
handler->onLeftClick( boost::bind( &WMTransferCalc::onClick, this, _1 ) );
// as we need the projection and view matrices: add a callback which queries this
m_matrixCallback = new WGetMatrixCallback();
m_rootNode->addCullCallback( m_matrixCallback );
debugLog() << "Entering main loop";
while( !m_shutdownFlag() )
{
......@@ -320,6 +339,8 @@ void WMTransferCalc::moduleMain()
}
}
// we technically need to remove the event handler too but there is no method available to do this ...
// WKernel::getRunningKernel()->getGraphicsEngine()->getViewer()->removeEventHandler( handler );
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->remove( m_rootNode );
}
......
......@@ -48,6 +48,7 @@
#include "../dataStructures/WRay.h"
#include "../dataStructures/WRaySample.h"
#include "../dataStructures/WRayProfile.h"
#include "../interaction/WGetMatrixCallback.h"
/**
* --
......@@ -125,9 +126,16 @@ protected:
osg::ref_ptr< osg::Geode > m_geode;
private:
/**
* Handle click events in the main view
*
* \param mousePos the mouse position
*/
void onClick( WVector2i mousePos );
/**
* Trilinear interpolation within the grid for a given position
*
*
* \param position Position for which the value should be determined.
* \param grid The grid which contains the values.
*
......@@ -137,9 +145,9 @@ private:
/**
* Calculating a WVector3d out of a given WVector4d
*
*
* \param vec 4D vector which shall be transfered to 3D
*
*
* \return Calculated Vector.
*/
WVector3d getAs3D( WVector4d vec );
......@@ -221,6 +229,11 @@ private:
*/
bool m_initialUpdate;
};
/**
* Needed to query the modelview and projection matrices of the m_rootNode;
*/
WGetMatrixCallback::RefPtr m_matrixCallback;
};
#endif // WMTRANSFERCALC_H
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