diff --git a/ApplicationCode/Commands/IntersectionBoxCommands/RicBoxManipulatorEventHandler.cpp b/ApplicationCode/Commands/IntersectionBoxCommands/RicBoxManipulatorEventHandler.cpp index 7d0f9db350..85c48c22b1 100644 --- a/ApplicationCode/Commands/IntersectionBoxCommands/RicBoxManipulatorEventHandler.cpp +++ b/ApplicationCode/Commands/IntersectionBoxCommands/RicBoxManipulatorEventHandler.cpp @@ -29,6 +29,7 @@ #include "cvfModelBasicList.h" #include "cvfPart.h" #include "cvfRay.h" +#include "cvfRayIntersectSpec.h" #include #include @@ -50,6 +51,26 @@ RicBoxManipulatorEventHandler::RicBoxManipulatorEventHandler( caf::Viewer* viewe RicBoxManipulatorEventHandler::~RicBoxManipulatorEventHandler() { if ( m_viewer ) m_viewer->removeEventFilter( this ); + + for ( auto viewer : m_otherViewers ) + { + if ( viewer ) + { + m_viewer->removeEventFilter( this ); + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicBoxManipulatorEventHandler::registerInAdditionalViewer( caf::Viewer* viewer ) +{ + if ( viewer ) + { + m_otherViewers.push_back( viewer ); + viewer->installEventFilter( this ); + } } //-------------------------------------------------------------------------------------------------- @@ -85,6 +106,10 @@ void RicBoxManipulatorEventHandler::appendPartsToModel( cvf::ModelBasicList* mod //-------------------------------------------------------------------------------------------------- bool RicBoxManipulatorEventHandler::eventFilter( QObject* obj, QEvent* inputEvent ) { + caf::Viewer* viewer = dynamic_cast( obj ); + + if ( !viewer ) return false; + if ( inputEvent->type() == QEvent::MouseButtonPress ) { QMouseEvent* mouseEvent = static_cast( inputEvent ); @@ -92,7 +117,7 @@ bool RicBoxManipulatorEventHandler::eventFilter( QObject* obj, QEvent* inputEven if ( mouseEvent->button() == Qt::LeftButton ) { cvf::HitItemCollection hitItems; - if ( m_viewer->rayPick( mouseEvent->x(), mouseEvent->y(), &hitItems ) ) + if ( viewer->rayPick( mouseEvent->x(), mouseEvent->y(), &hitItems ) ) { m_partManager->tryToActivateManipulator( hitItems.firstItem() ); @@ -111,16 +136,12 @@ bool RicBoxManipulatorEventHandler::eventFilter( QObject* obj, QEvent* inputEven { QMouseEvent* mouseEvent = static_cast( inputEvent ); - // qDebug() << "Inside mouse move"; - // qDebug() << mouseEvent->pos(); + cvf::ref rayIS = + viewer->rayIntersectSpecFromWindowCoordinates( mouseEvent->pos().x(), mouseEvent->pos().y() ); - int translatedMousePosX = mouseEvent->pos().x(); - int translatedMousePosY = m_viewer->height() - mouseEvent->pos().y(); - - cvf::ref ray = m_viewer->mainCamera()->rayFromWindowCoordinates( translatedMousePosX, - translatedMousePosY ); + if (rayIS.notNull()) { - m_partManager->updateManipulatorFromRay( ray.p() ); + m_partManager->updateManipulatorFromRay( rayIS->ray() ); cvf::Vec3d origin; cvf::Vec3d size; diff --git a/ApplicationCode/Commands/IntersectionBoxCommands/RicBoxManipulatorEventHandler.h b/ApplicationCode/Commands/IntersectionBoxCommands/RicBoxManipulatorEventHandler.h index adb9958fb7..258b64716b 100644 --- a/ApplicationCode/Commands/IntersectionBoxCommands/RicBoxManipulatorEventHandler.h +++ b/ApplicationCode/Commands/IntersectionBoxCommands/RicBoxManipulatorEventHandler.h @@ -52,6 +52,8 @@ public: explicit RicBoxManipulatorEventHandler( caf::Viewer* viewer ); ~RicBoxManipulatorEventHandler() override; + void registerInAdditionalViewer( caf::Viewer* viewer); + void setOrigin( const cvf::Vec3d& origin ); void setSize( const cvf::Vec3d& size ); @@ -66,6 +68,7 @@ protected: private: QPointer m_viewer; + std::vector> m_otherViewers; cvf::ref m_partManager; }; diff --git a/ApplicationCode/ProjectDataModel/RimIntersectionBox.cpp b/ApplicationCode/ProjectDataModel/RimIntersectionBox.cpp index a1e3d5dfcd..9292c4e4ef 100644 --- a/ApplicationCode/ProjectDataModel/RimIntersectionBox.cpp +++ b/ApplicationCode/ProjectDataModel/RimIntersectionBox.cpp @@ -311,6 +311,13 @@ void RimIntersectionBox::fieldChangedByUi( const caf::PdmFieldHandle* changedFie { m_boxManipulator = new RicBoxManipulatorEventHandler( viewer() ); + Rim3dView* rimView = nullptr; + this->firstAncestorOrThisOfType( rimView ); + for (Rim3dView * mainView : rimView->viewsUsingThisAsComparisonView()) + { + m_boxManipulator->registerInAdditionalViewer( mainView->viewer()); + } + connect( m_boxManipulator, SIGNAL( notifyRedraw() ), this, SLOT( slotScheduleRedraw() ) ); connect( m_boxManipulator, SIGNAL( notifyUpdate( const cvf::Vec3d&, const cvf::Vec3d& ) ),