Commit 1512f5e4 authored by schurade's avatar schurade

[ADD] support for paint modes and picking with left mouse button

parent 6b2a7887
......@@ -28,9 +28,10 @@
WGEZoomTrackballManipulator::WGEZoomTrackballManipulator():
TrackballManipulator(),
m_allowThrow( false )
m_zoom( 1.0 ),
m_allowThrow( false ),
m_paintMode( 0 )
{
m_zoom = 1.0;
setTrackballSize( .3 ); // changes the effect of a mouse move for rotation
WPreferences::getPreference( "ge.zoomTrackballManipulator.allowThrow", &m_allowThrow );
}
......@@ -130,12 +131,28 @@ bool WGEZoomTrackballManipulator::handle( const osgGA::GUIEventAdapter& ea, osgG
}
// NOTE: we need to ignore the right mouse-button drag! This manipulates the underlying Trackball Manipulator while, at the same time, is
// used for moving ROIS! Zooming is done using Scroll Wheel or +/- keys.
else if ( ( ea.getEventType() == osgGA::GUIEventAdapter::DRAG ) && ( ea.getButtonMask() == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON ) )
else if ( ( ea.getEventType() == osgGA::GUIEventAdapter::DRAG ) || ( ea.getEventType() == osgGA::GUIEventAdapter::PUSH ) )
{
return true;
if ( ea.getButtonMask() == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON )
{
return true;
}
else if ( ( ea.getButtonMask() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON ) && ( m_paintMode == 1 ) )
{
return true;
}
else
{
return TrackballManipulator::handle( ea, us );
}
}
else
{
return TrackballManipulator::handle( ea, us );
}
}
void WGEZoomTrackballManipulator::setPaintMode( int mode )
{
m_paintMode = mode;
}
......@@ -81,6 +81,14 @@ public:
*/
void setZoom( double zoom );
/**
* setter for paint mode
* when set to something different from 0, a left drag should move the scene
*
* \param mode the mode
*/
void setPaintMode( int mode );
protected:
private:
......@@ -93,6 +101,8 @@ private:
double m_zoom; //!< Zoom factor.
bool m_allowThrow; //!< Do we want the auto-rotation thingy?
int m_paintMode; //!<paint mode
};
inline double WGEZoomTrackballManipulator::getZoom() const
......
......@@ -35,7 +35,9 @@ WPickHandler::WPickHandler()
m_startPick( WPickInfo() ),
m_shift( false ),
m_ctrl( false ),
m_viewerName( "" )
m_viewerName( "" ),
m_paintMode( 0 ),
m_mouseButton( WPickInfo::NOMOUSE )
{
}
......@@ -44,7 +46,9 @@ WPickHandler::WPickHandler( std::string viewerName )
m_startPick( WPickInfo() ),
m_shift( false ),
m_ctrl( false ),
m_viewerName( viewerName )
m_viewerName( viewerName ),
m_paintMode( 0 ),
m_mouseButton( WPickInfo::NOMOUSE )
{
}
......@@ -72,6 +76,16 @@ bool WPickHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAda
unsigned int buttonMask = ea.getButtonMask();
if( buttonMask == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON )
{
m_mouseButton = WPickInfo::MOUSE_RIGHT;
osgViewer::View* view = static_cast< osgViewer::View* >( &aa );
if ( view )
{
pick( view, ea );
}
}
if( ( buttonMask == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON ) && ( m_paintMode == 1 ) )
{
m_mouseButton = WPickInfo::MOUSE_LEFT;
osgViewer::View* view = static_cast< osgViewer::View* >( &aa );
if ( view )
{
......@@ -82,6 +96,7 @@ bool WPickHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAda
}
case osgGA::GUIEventAdapter::RELEASE : // Mousebutton released
{
m_mouseButton = WPickInfo::NOMOUSE;
osgViewer::View* view = static_cast< osgViewer::View* >( &aa );
if ( view )
{
......@@ -159,7 +174,7 @@ void WPickHandler::pick( osgViewer::View* view, const osgGA::GUIEventAdapter& ea
{
WPickInfo pickInfo;
pickInfo = WPickInfo( "", m_viewerName, m_startPick.getPickPosition(), std::make_pair( x, y ),
m_startPick.getModifierKey(), m_startPick.getPickNormal() );
m_startPick.getModifierKey(), m_mouseButton, m_startPick.getPickNormal() );
m_hitResult = pickInfo;
// if nothing was picked before remember the currently picked.
......@@ -186,7 +201,7 @@ void WPickHandler::pick( osgViewer::View* view, const osgGA::GUIEventAdapter& ea
{
std::string nodeName = extractSuitableName( hitr );
// now we skip everything that starts with an underscore
if( nodeName[0] == '_' )
if( nodeName[0] == '_' && ( m_paintMode == 0 ) )
{
++hitr;
}
......@@ -238,14 +253,15 @@ void WPickHandler::pick( osgViewer::View* view, const osgGA::GUIEventAdapter& ea
pickNormal[0] = hitr->getWorldIntersectNormal()[0];
pickNormal[1] = hitr->getWorldIntersectNormal()[1];
pickNormal[2] = hitr->getWorldIntersectNormal()[2];
pickInfo = WPickInfo( extractSuitableName( hitr ), m_viewerName, pickPos, std::make_pair( x, y ), WPickInfo::NONE, pickNormal );
pickInfo = WPickInfo( extractSuitableName( hitr ), m_viewerName, pickPos, std::make_pair( x, y ),
WPickInfo::NONE, m_mouseButton, pickNormal );
}
// Use the old PickInfo with updated pixel info if we have previously picked something but the old is not in list anymore
if( !startPickIsStillInList && m_startPick.getName() != "" && m_startPick.getName() != "unpick" )
{
pickInfo = WPickInfo( m_startPick.getName(), m_viewerName, m_startPick.getPickPosition(), std::make_pair( x, y ),
m_startPick.getModifierKey(), m_startPick.getPickNormal() );
m_startPick.getModifierKey(), m_mouseButton, m_startPick.getPickNormal() );
}
if( m_shift )
......@@ -260,3 +276,8 @@ void WPickHandler::pick( osgViewer::View* view, const osgGA::GUIEventAdapter& ea
m_pickSignal( getHitResult() );
}
void WPickHandler::setPaintMode( int mode )
{
m_paintMode = mode;
}
......@@ -100,6 +100,12 @@ public:
*/
boost::signals2::signal1< void, WPickInfo >* getPickSignal();
/**
* setter for paint mode
* \param mode the paint mode
*/
void setPaintMode( int mode );
protected:
/**
* Virtual destructor needed because of virtual function.
......@@ -117,6 +123,9 @@ protected:
bool m_shift; //!< is shift pressed?
bool m_ctrl; //!< is ctrl pressed?
std::string m_viewerName; //!< which viewer sends the signal
int m_paintMode; //!< the paint mode
WPickInfo::WMouseButton m_mouseButton; //!< stores mouse button that initiated the pick
private:
boost::signals2::signal1<void, WPickInfo > m_pickSignal; //!< One can register to this signal to receive pick events.
......
......@@ -32,6 +32,7 @@
#include "../common/math/WVector3D.h"
#include "WExportWGE.h"
/**
* Encapsulates info for pick action.
*/
......@@ -50,6 +51,20 @@ public:
WIN
};
/**
* Different types of mouse buttons.
*/
typedef enum
{
NOMOUSE,
MOUSE_LEFT,
MOUSE_RIGHT,
MOUSE_MIDDLE,
MOUSE4,
MOUSE5
}
WMouseButton;
/**
* Creates an object with the needed information.
* \param name name of picked object
......@@ -57,6 +72,7 @@ public:
* \param pickPosition position where object was hit
* \param pixelCoords pixel coordinates of the mouse
* \param modKey relevant modifier key pressed during the pick
* \param mButton mouse button that initiated the pick
* \param pickNormal normal at position where object was hit. (0,0,0) means not set.
*/
inline WPickInfo( std::string name,
......@@ -64,6 +80,7 @@ public:
wmath::WPosition pickPosition,
std::pair< float, float > pixelCoords,
modifierKey modKey,
WMouseButton mButton = WPickInfo::MOUSE_LEFT,
wmath::WVector3D pickNormal = wmath::WVector3D() );
/**
......@@ -76,12 +93,24 @@ public:
*/
inline modifierKey getModifierKey() const;
/**
* Get the mouse button associated with the pick
*/
inline WMouseButton getMouseButton() const;
/**
* Set the modifier key associated with the pick
* \param modKey new modifier key
*/
inline void setModifierKey( const modifierKey& modKey );
/**
* Set the modifier key associated with the pick
* \param mButton new mouse button
*/
inline void setMouseButton( const WMouseButton& mButton );
/**
* Get name of picked object.
*/
......@@ -127,6 +156,7 @@ private:
wmath::WPosition m_pickPosition; //!< position where object was hit.
std::pair< float, float > m_pixelCoords; //!< Pixel coordinates of the mouse.
modifierKey m_modKey; //!< modifier key associated with the pick
WMouseButton m_mouseButton; //!< which mouse button was used for the pick
wmath::WVector3D m_pickNormal; //!< normal at position where object was hit.
};
......@@ -135,12 +165,14 @@ WPickInfo::WPickInfo( std::string name,
wmath::WPosition pickPosition,
std::pair< float, float > pixelCoords,
modifierKey modKey,
WMouseButton mButton,
wmath::WVector3D pickNormal ) :
m_name( name ),
m_viewerName( viewerName ),
m_pickPosition( pickPosition ),
m_pixelCoords( pixelCoords ),
m_modKey( modKey ),
m_mouseButton( mButton ),
m_pickNormal( pickNormal )
{
}
......@@ -150,7 +182,8 @@ WPickInfo::WPickInfo() :
m_viewerName( "" ),
m_pickPosition( wmath::WPosition() ),
m_pixelCoords( std::make_pair( 0, 0 ) ),
m_modKey( WPickInfo::NONE )
m_modKey( WPickInfo::NONE ),
m_mouseButton( WPickInfo::MOUSE_LEFT )
{
}
......@@ -164,6 +197,15 @@ void WPickInfo::setModifierKey( const modifierKey& modKey )
m_modKey = modKey;
}
WPickInfo::WMouseButton WPickInfo::getMouseButton() const
{
return m_mouseButton;
}
void WPickInfo::setMouseButton( const WMouseButton& mButton )
{
m_mouseButton = mButton;
}
std::string WPickInfo::getName() const
{
......
......@@ -29,6 +29,8 @@
#include "WKernel.h"
#include "../common/math/WLinearAlgebraFunctions.h"
#include "../graphicsEngine/WGEZoomTrackballManipulator.h"
#include "WSelectionManager.h"
using wmath::WVector3D;
......@@ -36,7 +38,8 @@ using wmath::WPosition;
using wmath::WMatrix;
WSelectionManager::WSelectionManager()
WSelectionManager::WSelectionManager() :
m_paintMode( PAINTMODE_NONE )
{
m_crosshair = boost::shared_ptr< WCrosshair >( new WCrosshair() );
}
......@@ -106,3 +109,18 @@ int WSelectionManager::getFrontSector()
}
return quadrant;
}
void WSelectionManager::setPaintMode( WPaintMode mode )
{
m_paintMode = mode;
osg::static_pointer_cast<WGEZoomTrackballManipulator>(
WKernel::getRunningKernel()->getGraphicsEngine()->getViewer()->getCameraManipulator() )->setPaintMode( mode );
WKernel::getRunningKernel()->getGraphicsEngine()->getViewer()->getPickHandler()->setPaintMode( mode );
}
WPaintMode WSelectionManager::getPaintMode()
{
return m_paintMode;
}
......@@ -31,6 +31,13 @@
#include "WExportKernel.h"
typedef enum
{
PAINTMODE_NONE = 0,
PAINTMODE_PAINT = 1
}
WPaintMode;
/**
* manages the several selection tools
*/
......@@ -59,9 +66,25 @@ public:
*/
int getFrontSector();
/**
* setter for paint mode, also forwards it to the graphics engine
*
* \param mode
*/
void setPaintMode( WPaintMode mode );
/**
* getter for paint mode
*
* \return the mode
*/
WPaintMode getPaintMode();
protected:
private:
boost::shared_ptr< WCrosshair >m_crosshair; //!< stores pointer to crosshair
WPaintMode m_paintMode; //!< stores the currently selected paint mode
};
#endif // WSELECTIONMANAGER_H
......@@ -438,9 +438,9 @@ void WMNavSlices::setSlicePosFromPick( WPickInfo pickInfo )
return;
}
if ( pickInfo.getName() == "Axial Slice"
if ( ( pickInfo.getName() == "Axial Slice"
|| pickInfo.getName() == "Coronal Slice"
|| pickInfo.getName() == "Sagittal Slice" )
|| pickInfo.getName() == "Sagittal Slice" ) && pickInfo.getMouseButton() == WPickInfo::MOUSE_RIGHT )
{
boost::unique_lock< boost::shared_mutex > lock;
lock = boost::unique_lock< boost::shared_mutex >( m_updateLock );
......@@ -548,9 +548,9 @@ osg::ref_ptr<osg::Geometry> WMNavSlices::createGeometry( int slice )
float ySlice = static_cast< float >( m_coronalPos->get( true ) );
float zSlice = static_cast< float >( m_axialPos->get( true ) );
float xPos = xSlice + 0.5f;
float yPos = ySlice + 0.5f;
float zPos = zSlice + 0.5f;
float xPos = xSlice;
float yPos = ySlice;
float zPos = zSlice;
osg::ref_ptr<osg::Geometry> sliceGeometry = osg::ref_ptr<osg::Geometry>( new osg::Geometry() );
......
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