#4045 Don't accept pick events if the current selected object isn't the object owning the pick handler.

This commit is contained in:
Gaute Lindkvist 2019-02-06 13:20:33 +01:00
parent dbe21b7809
commit c4f5065032
13 changed files with 98 additions and 17 deletions

View File

@ -43,6 +43,13 @@ RicMeasurementPickEventHandler* RicMeasurementPickEventHandler::instance()
return singleton;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicMeasurementPickEventHandler::RicMeasurementPickEventHandler()
: Ric3dViewPickEventHandler(nullptr)
{}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -29,6 +29,7 @@ public:
static RicMeasurementPickEventHandler* instance();
protected:
RicMeasurementPickEventHandler();
bool handle3dPickEvent(const Ric3dPickEvent& eventObject) override;
void notifyUnregistered() override;
};

View File

@ -20,6 +20,13 @@
#include <typeinfo>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Ric3dViewPickEventHandler::Ric3dViewPickEventHandler(const caf::PdmObjectHandle* handlingObject)
: caf::PickEventHandler(handlingObject)
{}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -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;
};

View File

@ -20,12 +20,15 @@
#include "Rim3dView.h"
#include "cafDisplayCoordTransform.h"
#include "cafSelectionManager.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicVec3dPickEventHandler::RicVec3dPickEventHandler(caf::PdmField<cvf::Vec3d>* vectorField)
: m_vectorField(vectorField)
RicVec3dPickEventHandler::RicVec3dPickEventHandler(const caf::PdmObjectHandle* handlingObject,
caf::PdmField<cvf::Vec3d>* vectorField)
: Ric3dViewPickEventHandler(handlingObject)
, m_vectorField(vectorField)
{
}
@ -34,14 +37,19 @@ RicVec3dPickEventHandler::RicVec3dPickEventHandler(caf::PdmField<cvf::Vec3d>* ve
//--------------------------------------------------------------------------------------------------
bool RicVec3dPickEventHandler::handle3dPickEvent(const Ric3dPickEvent& eventObject)
{
const Rim3dView* rimView = eventObject.m_view;
caf::PdmObjectHandle* selectedObject = caf::SelectionManager::instance()->selectedItemOfType<caf::PdmObjectHandle>();
if (isObjectBeingModified(selectedObject))
{
const Rim3dView* rimView = eventObject.m_view;
cvf::ref<caf::DisplayCoordTransform> 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<caf::DisplayCoordTransform> 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;
}
//--------------------------------------------------------------------------------------------------

View File

@ -29,7 +29,7 @@ class Rim3dView;
class RicVec3dPickEventHandler : public Ric3dViewPickEventHandler
{
public:
RicVec3dPickEventHandler(caf::PdmField<cvf::Vec3d>* vectorField);
RicVec3dPickEventHandler(const caf::PdmObjectHandle* handlingObject, caf::PdmField<cvf::Vec3d>* vectorField);
bool handle3dPickEvent(const Ric3dPickEvent& eventObject) override;
void notifyUnregistered() override;

View File

@ -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<caf::PdmObjectHandle>()))
{
m_geometryToAddTargetsTo->enableTargetPointPicking(false);

View File

@ -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<caf::PdmObjectHandle>()))
{
return false;
}

View File

@ -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));
}
//--------------------------------------------------------------------------------------------------

View File

@ -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));
}

View File

@ -159,6 +159,7 @@ set( PROJECT_FILES
cafPdmUniqueIdValidator.cpp
cafPdmDoubleStringValidator.cpp
cafPickEventHandler.h
cafPickEventHandler.cpp
)
add_library( ${PROJECT_NAME}

View File

@ -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 <<http://www.gnu.org/licenses/gpl.html>>
// 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 <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#include "cafPickEventHandler.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool caf::PickEventHandler::isObjectBeingModified(const PdmObjectHandle* object) const
{
return m_objectBeingModified == object;
}

View File

@ -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;
};
}