From c4f5065032997a3356a86688a819cd32515b9b11 Mon Sep 17 00:00:00 2001 From: Gaute Lindkvist Date: Wed, 6 Feb 2019 13:20:33 +0100 Subject: [PATCH] #4045 Don't accept pick events if the current selected object isn't the object owning the pick handler. --- .../RicMeasurementPickEventHandler.cpp | 7 +++ .../RicMeasurementPickEventHandler.h | 1 + .../Commands/Ric3dViewPickEventHandler.cpp | 7 +++ .../Commands/Ric3dViewPickEventHandler.h | 4 ++ .../Commands/RicVec3dPickEventHandler.cpp | 26 +++++++---- .../Commands/RicVec3dPickEventHandler.h | 2 +- .../RicCreateWellTargetsPickEventHandler.cpp | 4 +- .../RicPolylineTargetsPickEventHandler.cpp | 4 +- .../Annotations/RimReachCircleAnnotation.cpp | 2 +- .../Annotations/RimTextAnnotation.cpp | 4 +- Fwk/AppFwk/cafUserInterface/CMakeLists.txt | 1 + .../cafUserInterface/cafPickEventHandler.cpp | 44 +++++++++++++++++++ .../cafUserInterface/cafPickEventHandler.h | 9 ++++ 13 files changed, 98 insertions(+), 17 deletions(-) create mode 100644 Fwk/AppFwk/cafUserInterface/cafPickEventHandler.cpp diff --git a/ApplicationCode/Commands/MeasurementCommands/RicMeasurementPickEventHandler.cpp b/ApplicationCode/Commands/MeasurementCommands/RicMeasurementPickEventHandler.cpp index 92aa3fdf92..3dc23bd0c7 100644 --- a/ApplicationCode/Commands/MeasurementCommands/RicMeasurementPickEventHandler.cpp +++ b/ApplicationCode/Commands/MeasurementCommands/RicMeasurementPickEventHandler.cpp @@ -43,6 +43,13 @@ RicMeasurementPickEventHandler* RicMeasurementPickEventHandler::instance() return singleton; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicMeasurementPickEventHandler::RicMeasurementPickEventHandler() + : Ric3dViewPickEventHandler(nullptr) +{} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Commands/MeasurementCommands/RicMeasurementPickEventHandler.h b/ApplicationCode/Commands/MeasurementCommands/RicMeasurementPickEventHandler.h index c86bbdcc72..23315271f9 100644 --- a/ApplicationCode/Commands/MeasurementCommands/RicMeasurementPickEventHandler.h +++ b/ApplicationCode/Commands/MeasurementCommands/RicMeasurementPickEventHandler.h @@ -29,6 +29,7 @@ public: static RicMeasurementPickEventHandler* instance(); protected: + RicMeasurementPickEventHandler(); bool handle3dPickEvent(const Ric3dPickEvent& eventObject) override; void notifyUnregistered() override; }; diff --git a/ApplicationCode/Commands/Ric3dViewPickEventHandler.cpp b/ApplicationCode/Commands/Ric3dViewPickEventHandler.cpp index 1185847025..f94d682cb8 100644 --- a/ApplicationCode/Commands/Ric3dViewPickEventHandler.cpp +++ b/ApplicationCode/Commands/Ric3dViewPickEventHandler.cpp @@ -20,6 +20,13 @@ #include +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +Ric3dViewPickEventHandler::Ric3dViewPickEventHandler(const caf::PdmObjectHandle* handlingObject) + : caf::PickEventHandler(handlingObject) +{} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Commands/Ric3dViewPickEventHandler.h b/ApplicationCode/Commands/Ric3dViewPickEventHandler.h index 70ec0d7ccc..aeb7347c44 100644 --- a/ApplicationCode/Commands/Ric3dViewPickEventHandler.h +++ b/ApplicationCode/Commands/Ric3dViewPickEventHandler.h @@ -20,6 +20,7 @@ #include "RicPickEventHandler.h" #include "cafPdmField.h" +#include "cafPdmObjectHandle.h" //================================================================================================== /// A temporary, dynamic pick handler that overrides the default ones @@ -27,11 +28,14 @@ class Ric3dViewPickEventHandler : public caf::PickEventHandler { public: + Ric3dViewPickEventHandler(const caf::PdmObjectHandle* handlingObject); + // Override from caf void registerAsPickEventHandler() override; void unregisterAsPickEventHandler() override; bool handlePickEvent(const caf::PickEvent& eventObject) override; virtual bool handle3dPickEvent(const Ric3dPickEvent& eventObject) = 0; + }; diff --git a/ApplicationCode/Commands/RicVec3dPickEventHandler.cpp b/ApplicationCode/Commands/RicVec3dPickEventHandler.cpp index 0387725af8..e32b34b9f4 100644 --- a/ApplicationCode/Commands/RicVec3dPickEventHandler.cpp +++ b/ApplicationCode/Commands/RicVec3dPickEventHandler.cpp @@ -20,12 +20,15 @@ #include "Rim3dView.h" #include "cafDisplayCoordTransform.h" +#include "cafSelectionManager.h" //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RicVec3dPickEventHandler::RicVec3dPickEventHandler(caf::PdmField* vectorField) - : m_vectorField(vectorField) +RicVec3dPickEventHandler::RicVec3dPickEventHandler(const caf::PdmObjectHandle* handlingObject, + caf::PdmField* vectorField) + : Ric3dViewPickEventHandler(handlingObject) + , m_vectorField(vectorField) { } @@ -34,14 +37,19 @@ RicVec3dPickEventHandler::RicVec3dPickEventHandler(caf::PdmField* ve //-------------------------------------------------------------------------------------------------- bool RicVec3dPickEventHandler::handle3dPickEvent(const Ric3dPickEvent& eventObject) { - const Rim3dView* rimView = eventObject.m_view; + caf::PdmObjectHandle* selectedObject = caf::SelectionManager::instance()->selectedItemOfType(); + if (isObjectBeingModified(selectedObject)) + { + const Rim3dView* rimView = eventObject.m_view; - cvf::ref transForm = rimView->displayCoordTransform(); - cvf::Vec3d pickedPositionInUTM = transForm->transformToDomainCoord(eventObject.m_pickItemInfos.front().globalPickedPoint()); - - pickedPositionInUTM.z() *= -1.0; - m_vectorField->setValueWithFieldChanged(pickedPositionInUTM); - return true; + cvf::ref transForm = rimView->displayCoordTransform(); + cvf::Vec3d pickedPositionInUTM = transForm->transformToDomainCoord(eventObject.m_pickItemInfos.front().globalPickedPoint()); + + pickedPositionInUTM.z() *= -1.0; + m_vectorField->setValueWithFieldChanged(pickedPositionInUTM); + return true; + } + return false; } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Commands/RicVec3dPickEventHandler.h b/ApplicationCode/Commands/RicVec3dPickEventHandler.h index 0eedb03ecd..f71eeaacd3 100644 --- a/ApplicationCode/Commands/RicVec3dPickEventHandler.h +++ b/ApplicationCode/Commands/RicVec3dPickEventHandler.h @@ -29,7 +29,7 @@ class Rim3dView; class RicVec3dPickEventHandler : public Ric3dViewPickEventHandler { public: - RicVec3dPickEventHandler(caf::PdmField* vectorField); + RicVec3dPickEventHandler(const caf::PdmObjectHandle* handlingObject, caf::PdmField* vectorField); bool handle3dPickEvent(const Ric3dPickEvent& eventObject) override; void notifyUnregistered() override; diff --git a/ApplicationCode/Commands/WellPathCommands/RicCreateWellTargetsPickEventHandler.cpp b/ApplicationCode/Commands/WellPathCommands/RicCreateWellTargetsPickEventHandler.cpp index 36023304a4..26ab9d912e 100644 --- a/ApplicationCode/Commands/WellPathCommands/RicCreateWellTargetsPickEventHandler.cpp +++ b/ApplicationCode/Commands/WellPathCommands/RicCreateWellTargetsPickEventHandler.cpp @@ -55,7 +55,7 @@ /// //-------------------------------------------------------------------------------------------------- RicCreateWellTargetsPickEventHandler::RicCreateWellTargetsPickEventHandler(RimWellPathGeometryDef* wellGeometryDef) - : m_geometryToAddTargetsTo(wellGeometryDef) + : Ric3dViewPickEventHandler(wellGeometryDef), m_geometryToAddTargetsTo(wellGeometryDef) { } @@ -77,7 +77,7 @@ void RicCreateWellTargetsPickEventHandler::notifyUnregistered() //-------------------------------------------------------------------------------------------------- bool RicCreateWellTargetsPickEventHandler::handle3dPickEvent(const Ric3dPickEvent& eventObject) { - if (!caf::SelectionManager::instance()->isSelected(m_geometryToAddTargetsTo.p(), 0)) + if (!isObjectBeingModified(caf::SelectionManager::instance()->selectedItemOfType())) { m_geometryToAddTargetsTo->enableTargetPointPicking(false); diff --git a/ApplicationCode/Commands/WellPathCommands/RicPolylineTargetsPickEventHandler.cpp b/ApplicationCode/Commands/WellPathCommands/RicPolylineTargetsPickEventHandler.cpp index fd662c97bb..df97f852ad 100644 --- a/ApplicationCode/Commands/WellPathCommands/RicPolylineTargetsPickEventHandler.cpp +++ b/ApplicationCode/Commands/WellPathCommands/RicPolylineTargetsPickEventHandler.cpp @@ -40,7 +40,7 @@ /// //-------------------------------------------------------------------------------------------------- RicPolylineTargetsPickEventHandler::RicPolylineTargetsPickEventHandler(RimUserDefinedPolylinesAnnotation* polylineDef) - : m_polylineDef(polylineDef) + : Ric3dViewPickEventHandler(polylineDef), m_polylineDef(polylineDef) { } @@ -62,7 +62,7 @@ void RicPolylineTargetsPickEventHandler::notifyUnregistered() //-------------------------------------------------------------------------------------------------- bool RicPolylineTargetsPickEventHandler::handle3dPickEvent(const Ric3dPickEvent& eventObject) { - if (!caf::SelectionManager::instance()->isSelected(m_polylineDef.p(), 0)) + if (!isObjectBeingModified(caf::SelectionManager::instance()->selectedItemOfType())) { return false; } diff --git a/ApplicationCode/ProjectDataModel/Annotations/RimReachCircleAnnotation.cpp b/ApplicationCode/ProjectDataModel/Annotations/RimReachCircleAnnotation.cpp index f2a5f0ba0b..69302e06b9 100644 --- a/ApplicationCode/ProjectDataModel/Annotations/RimReachCircleAnnotation.cpp +++ b/ApplicationCode/ProjectDataModel/Annotations/RimReachCircleAnnotation.cpp @@ -52,7 +52,7 @@ RimReachCircleAnnotation::RimReachCircleAnnotation() m_appearance.uiCapability()->setUiTreeHidden(true); m_appearance.uiCapability()->setUiTreeChildrenHidden(true); - m_centerPointEventHandler.reset(new RicVec3dPickEventHandler(&m_centerPointXyd)); + m_centerPointEventHandler.reset(new RicVec3dPickEventHandler(this, &m_centerPointXyd)); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/Annotations/RimTextAnnotation.cpp b/ApplicationCode/ProjectDataModel/Annotations/RimTextAnnotation.cpp index 5e3848cf1d..c41cfd40f4 100644 --- a/ApplicationCode/ProjectDataModel/Annotations/RimTextAnnotation.cpp +++ b/ApplicationCode/ProjectDataModel/Annotations/RimTextAnnotation.cpp @@ -67,8 +67,8 @@ RimTextAnnotation::RimTextAnnotation() m_nameProxy.uiCapability()->setUiReadOnly(true); m_nameProxy.xmlCapability()->disableIO(); - m_anchorPointPickEventHandler.reset(new RicVec3dPickEventHandler(&m_anchorPointXyd)); - m_labelPointPickEventHandler.reset(new RicVec3dPickEventHandler(&m_labelPointXyd)); + m_anchorPointPickEventHandler.reset(new RicVec3dPickEventHandler(this, &m_anchorPointXyd)); + m_labelPointPickEventHandler.reset(new RicVec3dPickEventHandler(this, &m_labelPointXyd)); } diff --git a/Fwk/AppFwk/cafUserInterface/CMakeLists.txt b/Fwk/AppFwk/cafUserInterface/CMakeLists.txt index b68d10575e..f41f657d69 100644 --- a/Fwk/AppFwk/cafUserInterface/CMakeLists.txt +++ b/Fwk/AppFwk/cafUserInterface/CMakeLists.txt @@ -159,6 +159,7 @@ set( PROJECT_FILES cafPdmUniqueIdValidator.cpp cafPdmDoubleStringValidator.cpp cafPickEventHandler.h + cafPickEventHandler.cpp ) add_library( ${PROJECT_NAME} diff --git a/Fwk/AppFwk/cafUserInterface/cafPickEventHandler.cpp b/Fwk/AppFwk/cafUserInterface/cafPickEventHandler.cpp new file mode 100644 index 0000000000..835a8b5f17 --- /dev/null +++ b/Fwk/AppFwk/cafUserInterface/cafPickEventHandler.cpp @@ -0,0 +1,44 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2019- Ceetron Solution AS +// +// This library may be used under the terms of either the GNU General Public License or +// the GNU Lesser General Public License as follows: +// +// GNU General Public License Usage +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +// GNU Lesser General Public License Usage +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU Lesser General Public License at <> +// for more details. +// +//################################################################################################## +#include "cafPickEventHandler.h" + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool caf::PickEventHandler::isObjectBeingModified(const PdmObjectHandle* object) const +{ + return m_objectBeingModified == object; +} diff --git a/Fwk/AppFwk/cafUserInterface/cafPickEventHandler.h b/Fwk/AppFwk/cafUserInterface/cafPickEventHandler.h index 7c0af4074b..3c6f5fd860 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPickEventHandler.h +++ b/Fwk/AppFwk/cafUserInterface/cafPickEventHandler.h @@ -36,6 +36,8 @@ #pragma once +#include "cafPdmObjectHandle.h" + namespace caf { @@ -54,11 +56,18 @@ public: class PickEventHandler { public: + PickEventHandler(const PdmObjectHandle* objectBeingModified) : m_objectBeingModified(objectBeingModified) {} + + bool isObjectBeingModified(const PdmObjectHandle* testObject) const; + virtual void registerAsPickEventHandler() = 0; virtual void unregisterAsPickEventHandler() = 0; // TODO: Rename to just handlePickEvent when the RicPickEventHandler::handlePickEvent has been renamed virtual bool handlePickEvent(const PickEvent& eventObject) = 0; virtual void notifyUnregistered() = 0; + +private: + const PdmObjectHandle* m_objectBeingModified; }; }