#3249 Add possibility to add and remove pickEventHandlers

This commit is contained in:
Jacob Støren 2018-08-29 15:44:47 +02:00
parent 99bdece40e
commit 9cd9173000
2 changed files with 40 additions and 13 deletions

View File

@ -108,6 +108,8 @@
//
//==================================================================================================
std::vector<RicPickEventHandler*> RiuViewerCommands::sm_pickEventHandlers;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -119,16 +121,11 @@ RiuViewerCommands::RiuViewerCommands(RiuViewer* ownerViewer)
, m_currentPickPositionInDomainCoords(cvf::Vec3d::UNDEFINED)
, m_viewer(ownerViewer)
{
if ( sm_pickEventHandlers.empty() )
{
m_pickEventHandlers.push_back(dynamic_cast<RicPickEventHandler*>(RicIntersectionPickEventHandler::instance()));
}
{
m_pickEventHandlers.push_back(dynamic_cast<RicPickEventHandler*>(Ric3dWellLogCurvePickEventHandler::instance()));
}
{
m_pickEventHandlers.push_back(dynamic_cast<RicPickEventHandler*>(RicWellPathPickEventHandler::instance()));
addPickEventHandler(RicIntersectionPickEventHandler::instance());
addPickEventHandler(Ric3dWellLogCurvePickEventHandler::instance());
addPickEventHandler(RicWellPathPickEventHandler::instance());
}
}
@ -533,9 +530,9 @@ void RiuViewerCommands::handlePickAction(int winPosX, int winPosY, Qt::KeyboardM
Ric3DPickEvent viewerEventObject(pickItemInfos,
m_reservoirView);
for ( size_t i = 0; i < m_pickEventHandlers.size(); i++ )
for ( size_t i = 0; i < sm_pickEventHandlers.size(); i++ )
{
if ( m_pickEventHandlers[i]->handlePickEvent(viewerEventObject) )
if ( sm_pickEventHandlers[i]->handlePickEvent(viewerEventObject) )
{
return;
}
@ -888,6 +885,33 @@ cvf::Vec3d RiuViewerCommands::lastPickPositionInDomainCoords() const
return m_currentPickPositionInDomainCoords;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuViewerCommands::addPickEventHandler(RicPickEventHandler* pickEventHandler)
{
removePickEventHandler(pickEventHandler);
if (pickEventHandler)
{
sm_pickEventHandlers.push_back(pickEventHandler);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuViewerCommands::removePickEventHandler(RicPickEventHandler* pickEventHandler)
{
for ( auto it = sm_pickEventHandlers.begin(); it != sm_pickEventHandlers.end(); ++it )
{
if ( *it == pickEventHandler )
{
sm_pickEventHandlers.erase(it);
break;
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -58,8 +58,11 @@ public:
void displayContextMenu(QMouseEvent* event);
void handlePickAction(int winPosX, int winPosY, Qt::KeyboardModifiers keyboardModifiers);
cvf::Vec3d lastPickPositionInDomainCoords() const;
static void addPickEventHandler(RicPickEventHandler* pickEventHandler);
static void removePickEventHandler(RicPickEventHandler* pickEventHandler);
cvf::Vec3d lastPickPositionInDomainCoords() const;
private:
void findCellAndGridIndex(const RivIntersectionSourceInfo* crossSectionSourceInfo, cvf::uint firstPartTriangleIndex, size_t* cellIndex, size_t* gridIndex);
void findCellAndGridIndex(const RivIntersectionBoxSourceInfo* intersectionBoxSourceInfo, cvf::uint firstPartTriangleIndex, size_t* cellIndex, size_t* gridIndex);
@ -79,5 +82,5 @@ private:
cvf::Vec3d m_currentPickPositionInDomainCoords;
caf::PdmPointer<Rim3dView> m_reservoirView;
QPointer<RiuViewer> m_viewer;
std::vector<RicPickEventHandler*> m_pickEventHandlers;
static std::vector<RicPickEventHandler*> sm_pickEventHandlers;
};