Commit f7438892 authored by cornimueller's avatar cornimueller
Browse files

[MEGRE]

parents 38f3fef9 923fd54a
......@@ -54,10 +54,9 @@ private:
bool m_useColor; //!< Indicated whether m_color should be used for display.
/**
* updates the graphics
* \param text text info from pick
* updates the graphics. Remember that this shoudl only be called from a node callback
*/
virtual void updateGFX( std::string text ) = 0;
virtual void updateGFX() = 0;
};
#endif // WROI_H
......@@ -111,7 +111,8 @@ void setVertices( osg::Vec3Array* vertices, wmath::WPosition minPos, wmath::WPos
WROIBox::WROIBox( wmath::WPosition minPos, wmath::WPosition maxPos ) :
WROI(),
boxId( maxBoxId++ )
boxId( maxBoxId++ ),
needUpdate( false )
{
m_minPos = minPos;
m_maxPos = maxPos;
......@@ -122,11 +123,14 @@ WROIBox::WROIBox( wmath::WPosition minPos, wmath::WPosition maxPos ) :
boost::shared_ptr< WGEViewer > viewer = ge->getViewerByName( "main" );
assert( viewer );
m_pickHandler = viewer->getPickHandler();
m_pickHandler->getPickSignal()->connect( boost::bind( &WROIBox::updateGFX, this, _1 ) );
m_pickHandler->getPickSignal()->connect( boost::bind( &WROIBox::registerPick, this, _1 ) );
osg::Geometry* surfaceGeometry = new osg::Geometry();
m_geode = new osg::Geode;
m_geode->setUserData( this );
m_geode->setUpdateCallback( new ROIBoxNodeCallback );
std::stringstream ss;
ss << "ROIBox" << boxId;
......@@ -180,16 +184,32 @@ wmath::WPosition WROIBox::getMaxPos() const
return m_maxPos;
}
void WROIBox::registerPick( std::string text )
{
boost::unique_lock<boost::shared_mutex> slock;
slock = boost::unique_lock<boost::shared_mutex>( m_updateLock );
infoText = text;
needUpdate = true;
void WROIBox::updateGFX( std::string text )
slock.unlock();
}
void WROIBox::updateGFX()
{
boost::shared_lock<boost::shared_mutex> slock;
slock = boost::shared_lock<boost::shared_mutex>( m_updateLock );
boost::unique_lock<boost::shared_mutex> slock;
slock = boost::unique_lock<boost::shared_mutex>( m_updateLock );
if( !needUpdate ) // exit early if we do not need an update
{
slock.unlock();
return;
}
std::stringstream ss;
ss << "\"ROIBox" << boxId << "\"";
if( text.find( "Object ") != std::string::npos
&& text.find( ss.str() ) != std::string::npos )
if( infoText.find( "Object ") != std::string::npos
&& infoText.find( ss.str() ) != std::string::npos )
{
wmath::WPosition newPos( m_pickHandler->getHitPosition() );
if( m_isPicked )
......@@ -210,7 +230,7 @@ void WROIBox::updateGFX( std::string text )
m_pickedPosition = newPos;
m_isPicked = true;
}
if( m_isPicked && text.find( "unpick" ) != std::string::npos )
if( m_isPicked && infoText.find( "unpick" ) != std::string::npos )
{
osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back( osg::Vec4( 0.f, 0.f, 1.f, 0.5f ) );
......
......@@ -37,7 +37,7 @@
/**
* A box representing a region of interest.
*/
class WROIBox : public WROI
class WROIBox : public WROI, public osg::Referenced
{
public:
/**
......@@ -68,11 +68,44 @@ 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 infoText; //!< The info text coming from the last pick.
bool needUpdate; //!< Indicates whether the grafics need update due to changed text.
/**
* updates the graphics
* \param text text info from pick
* note that there was a pick
* \param text info from pick
*/
virtual void updateGFX( std::string text );
void registerPick( std::string text );
/**
* updates the graphics
*/
void updateGFX();
/**
* Node callback to handle updates properly
*/
class ROIBoxNodeCallback : public osg::NodeCallback
{
public: // NOLINT
/**
* operator ()
*
* \param node the osg node
* \param nv the node visitor
*/
virtual void operator()( osg::Node* node, osg::NodeVisitor* nv )
{
osg::ref_ptr< WROIBox > module = static_cast< WROIBox* > ( node->getUserData() );
if ( module )
{
module->updateGFX();
}
traverse( node, nv );
}
};
};
#endif // WROIBOX_H
......@@ -253,7 +253,7 @@ void WQtDatasetBrowser::selectTreeItem()
module = ( ( WQtModuleTreeItem* ) m_treeWidget->selectedItems().at( 0 ) )->getModule();
}
// every module may have compatibles: create ribbon menu entry
// every module may have compatibles: create toolBar entry
std::set< boost::shared_ptr< WModule > > comps = WModuleFactory::getModuleFactory()->getCompatiblePrototypes( module );
for ( std::set< boost::shared_ptr< WModule > >::iterator iter = comps.begin(); iter != comps.end(); ++iter )
{
......
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