Refactor PickEvent Hierarchy to have a basis in Caf

This commit is contained in:
Gaute Lindkvist 2019-02-05 16:01:29 +01:00
parent fad4dc91d7
commit 5d35678d97
5 changed files with 133 additions and 8 deletions

View File

@ -125,6 +125,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicExportFeatureImpl.cpp
${CMAKE_CURRENT_LIST_DIR}/RicSelectOrCreateViewFeatureImpl.cpp
${CMAKE_CURRENT_LIST_DIR}/RicPickEventHandler.cpp
${CMAKE_CURRENT_LIST_DIR}/RicContourMapPickEventHandler.cpp
# General delete of any object in a child array field

View File

@ -0,0 +1,53 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2019- Equinor ASA
//
// ResInsight 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.
//
// ResInsight 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.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicPickEventHandler.h"
#include "RiuViewerCommands.h"
#include <typeinfo>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicPickEventHandler::registerAsPickEventHandler()
{
RiuViewerCommands::setPickEventHandler(this);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicPickEventHandler::unregisterAsPickEventHandler()
{
RiuViewerCommands::removePickEventHandlerIfActive(this);
}
//--------------------------------------------------------------------------------------------------
/// Override from caf::PickEventHandler. Translates to a 3d Pick event.
//--------------------------------------------------------------------------------------------------
bool RicPickEventHandler::handlePickEvent(const caf::PickEvent& eventObject)
{
try
{
const Ric3DPickEvent& eventObject3d = dynamic_cast<const Ric3DPickEvent&>(eventObject);
return handlePickEvent(eventObject3d);
}
catch (const std::bad_cast&)
{
return false;
}
}

View File

@ -19,12 +19,15 @@
#pragma once
#include "RiuPickItemInfo.h"
#include "cafCmdFeature.h"
#include "cafPickEventHandler.h"
#include "cafPdmField.h"
#include "cvfBase.h"
#include "cvfObject.h"
#include "cvfVector3.h"
#include "RiuPickItemInfo.h"
namespace cvf {
class Part;
@ -35,7 +38,7 @@ class Rim3dView;
//==================================================================================================
///
//==================================================================================================
class Ric3DPickEvent
class Ric3DPickEvent : public caf::PickEvent
{
public:
Ric3DPickEvent(const std::vector<RiuPickItemInfo>& pickItemInfos,
@ -62,10 +65,13 @@ public:
//==================================================================================================
/// A temporary, dynamic pick handler that overrides the default ones
//==================================================================================================
class RicPickEventHandler
class RicPickEventHandler : public caf::PickEventHandler
{
public:
// Override from caf
void registerAsPickEventHandler() override;
void unregisterAsPickEventHandler() override;
bool handlePickEvent(const caf::PickEvent& eventObject) override;
virtual bool handlePickEvent(const Ric3DPickEvent& eventObject) = 0;
virtual void notifyUnregistered() = 0;
};

View File

@ -52,8 +52,8 @@ set (MOC_HEADER_FILES
cafPdmUiTreeSelectionQModel.h
cafPdmUiFormLayoutObjectEditor.h
cafPdmUiDoubleValueEditor.h
cafPdmUniqueIdValidator.h
cafPdmDoubleStringValidator.h
cafPdmUniqueIdValidator.h
cafPdmDoubleStringValidator.h
)
if ( NOT CMAKE_AUTOMOC )
@ -156,8 +156,9 @@ set( PROJECT_FILES
cafQTreeViewStateSerializer.cpp
cafMemoryInspector.h
cafMemoryInspector.cpp
cafPdmUniqueIdValidator.cpp
cafPdmDoubleStringValidator.cpp
cafPdmUniqueIdValidator.cpp
cafPdmDoubleStringValidator.cpp
cafPickEventHandler.h
)
add_library( ${PROJECT_NAME}

View File

@ -0,0 +1,64 @@
//##################################################################################################
//
// 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.
//
//##################################################################################################
#pragma once
namespace caf
{
//==================================================================================================
/// Interface for Pick Events
//==================================================================================================
class PickEvent
{
public:
virtual ~PickEvent() {}
};
//==================================================================================================
/// Interface for Pick handlers
//==================================================================================================
class PickEventHandler
{
public:
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;
};
}