Janitor : Encapsulate dynamic cast to selection item type

This commit is contained in:
Magne Sjaastad 2021-06-29 09:59:45 +02:00
parent 96ac51c011
commit 3a1f2c8a05
12 changed files with 27 additions and 85 deletions

View File

@ -40,7 +40,7 @@ CAF_CMD_SOURCE_INIT( RicNewFishbonesSubsAtMeasuredDepthFeature, "RicNewFishbones
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicNewFishbonesSubsAtMeasuredDepthFeature::onActionTriggered( bool isChecked ) void RicNewFishbonesSubsAtMeasuredDepthFeature::onActionTriggered( bool isChecked )
{ {
RiuWellPathSelectionItem* wellPathSelItem = wellPathSelectionItem(); RiuWellPathSelectionItem* wellPathSelItem = RiuWellPathSelectionItem::wellPathSelectionItem();
CVF_ASSERT( wellPathSelItem ); CVF_ASSERT( wellPathSelItem );
RimWellPath* wellPath = wellPathSelItem->m_wellpath; RimWellPath* wellPath = wellPathSelItem->m_wellpath;
@ -63,19 +63,6 @@ void RicNewFishbonesSubsAtMeasuredDepthFeature::onActionTriggered( bool isChecke
proj->reloadCompletionTypeResultsInAllViews(); proj->reloadCompletionTypeResultsInAllViews();
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuWellPathSelectionItem* RicNewFishbonesSubsAtMeasuredDepthFeature::wellPathSelectionItem()
{
Riu3dSelectionManager* riuSelManager = Riu3dSelectionManager::instance();
RiuSelectionItem* selItem = riuSelManager->selectedItem( Riu3dSelectionManager::RUI_TEMPORARY );
RiuWellPathSelectionItem* wellPathItem = dynamic_cast<RiuWellPathSelectionItem*>( selItem );
return wellPathItem;
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -90,7 +77,7 @@ void RicNewFishbonesSubsAtMeasuredDepthFeature::setupActionLook( QAction* action
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
bool RicNewFishbonesSubsAtMeasuredDepthFeature::isCommandEnabled() bool RicNewFishbonesSubsAtMeasuredDepthFeature::isCommandEnabled()
{ {
if ( wellPathSelectionItem() ) if ( RiuWellPathSelectionItem::wellPathSelectionItem() )
{ {
return true; return true;
} }

View File

@ -20,8 +20,6 @@
#include "cafCmdFeature.h" #include "cafCmdFeature.h"
class RiuWellPathSelectionItem;
//================================================================================================== //==================================================================================================
/// ///
//================================================================================================== //==================================================================================================
@ -33,7 +31,4 @@ protected:
void onActionTriggered( bool isChecked ) override; void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override; void setupActionLook( QAction* actionToSetup ) override;
bool isCommandEnabled() override; bool isCommandEnabled() override;
private:
static RiuWellPathSelectionItem* wellPathSelectionItem();
}; };

View File

@ -41,7 +41,7 @@ CAF_CMD_SOURCE_INIT( RicNewPerforationIntervalAtMeasuredDepthFeature, "RicNewPer
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicNewPerforationIntervalAtMeasuredDepthFeature::onActionTriggered( bool isChecked ) void RicNewPerforationIntervalAtMeasuredDepthFeature::onActionTriggered( bool isChecked )
{ {
RiuWellPathSelectionItem* wellPathSelItem = wellPathSelectionItem(); RiuWellPathSelectionItem* wellPathSelItem = RiuWellPathSelectionItem::wellPathSelectionItem();
CVF_ASSERT( wellPathSelItem ); CVF_ASSERT( wellPathSelItem );
RimWellPath* wellPath = wellPathSelItem->m_wellpath; RimWellPath* wellPath = wellPathSelItem->m_wellpath;
@ -64,19 +64,6 @@ void RicNewPerforationIntervalAtMeasuredDepthFeature::onActionTriggered( bool is
Riu3DMainWindowTools::selectAsCurrentItem( perforationInterval ); Riu3DMainWindowTools::selectAsCurrentItem( perforationInterval );
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuWellPathSelectionItem* RicNewPerforationIntervalAtMeasuredDepthFeature::wellPathSelectionItem()
{
Riu3dSelectionManager* riuSelManager = Riu3dSelectionManager::instance();
RiuSelectionItem* selItem = riuSelManager->selectedItem( Riu3dSelectionManager::RUI_TEMPORARY );
RiuWellPathSelectionItem* wellPathItem = dynamic_cast<RiuWellPathSelectionItem*>( selItem );
return wellPathItem;
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -91,7 +78,7 @@ void RicNewPerforationIntervalAtMeasuredDepthFeature::setupActionLook( QAction*
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
bool RicNewPerforationIntervalAtMeasuredDepthFeature::isCommandEnabled() bool RicNewPerforationIntervalAtMeasuredDepthFeature::isCommandEnabled()
{ {
if ( wellPathSelectionItem() ) if ( RiuWellPathSelectionItem::wellPathSelectionItem() )
{ {
return true; return true;
} }

View File

@ -33,7 +33,4 @@ protected:
void onActionTriggered( bool isChecked ) override; void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override; void setupActionLook( QAction* actionToSetup ) override;
bool isCommandEnabled() override; bool isCommandEnabled() override;
private:
static RiuWellPathSelectionItem* wellPathSelectionItem();
}; };

View File

@ -41,7 +41,7 @@ CAF_CMD_SOURCE_INIT( RicNewValveAtMeasuredDepthFeature, "RicNewValveAtMeasuredDe
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicNewValveAtMeasuredDepthFeature::onActionTriggered( bool isChecked ) void RicNewValveAtMeasuredDepthFeature::onActionTriggered( bool isChecked )
{ {
RiuWellPathSelectionItem* wellPathSelItem = wellPathSelectionItem(); RiuWellPathSelectionItem* wellPathSelItem = RiuWellPathSelectionItem::wellPathSelectionItem();
CVF_ASSERT( wellPathSelItem ); CVF_ASSERT( wellPathSelItem );
RimWellPath* wellPath = wellPathSelItem->m_wellpath; RimWellPath* wellPath = wellPathSelItem->m_wellpath;
@ -91,23 +91,11 @@ void RicNewValveAtMeasuredDepthFeature::setupActionLook( QAction* actionToSetup
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
bool RicNewValveAtMeasuredDepthFeature::isCommandEnabled() bool RicNewValveAtMeasuredDepthFeature::isCommandEnabled()
{ {
if ( wellPathSelectionItem() && dynamic_cast<RimPerforationInterval*>( wellPathSelectionItem()->m_wellPathComponent ) ) auto wellPathSelectionItem = RiuWellPathSelectionItem::wellPathSelectionItem();
if ( wellPathSelectionItem && dynamic_cast<RimPerforationInterval*>( wellPathSelectionItem->m_wellPathComponent ) )
{ {
return true; return true;
} }
return false; return false;
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuWellPathSelectionItem* RicNewValveAtMeasuredDepthFeature::wellPathSelectionItem()
{
Riu3dSelectionManager* riuSelManager = Riu3dSelectionManager::instance();
RiuSelectionItem* selItem = riuSelManager->selectedItem( Riu3dSelectionManager::RUI_TEMPORARY );
RiuWellPathSelectionItem* wellPathItem = dynamic_cast<RiuWellPathSelectionItem*>( selItem );
return wellPathItem;
}

View File

@ -20,8 +20,6 @@
#include "cafCmdFeature.h" #include "cafCmdFeature.h"
class RiuWellPathSelectionItem;
//================================================================================================== //==================================================================================================
/// ///
//================================================================================================== //==================================================================================================
@ -33,7 +31,4 @@ protected:
void onActionTriggered( bool isChecked ) override; void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override; void setupActionLook( QAction* actionToSetup ) override;
bool isCommandEnabled() override; bool isCommandEnabled() override;
private:
static RiuWellPathSelectionItem* wellPathSelectionItem();
}; };

View File

@ -33,10 +33,7 @@ CAF_CMD_SOURCE_INIT( RicNewWellPathFractureAtPosFeature, "RicNewWellPathFracture
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicNewWellPathFractureAtPosFeature::onActionTriggered( bool isChecked ) void RicNewWellPathFractureAtPosFeature::onActionTriggered( bool isChecked )
{ {
Riu3dSelectionManager* riuSelManager = Riu3dSelectionManager::instance(); RiuWellPathSelectionItem* wellPathItem = RiuWellPathSelectionItem::wellPathSelectionItem();
RiuSelectionItem* selItem = riuSelManager->selectedItem( Riu3dSelectionManager::RUI_TEMPORARY );
RiuWellPathSelectionItem* wellPathItem = dynamic_cast<RiuWellPathSelectionItem*>( selItem );
if ( !wellPathItem ) return; if ( !wellPathItem ) return;
RimWellPath* wellPath = wellPathItem->m_wellpath; RimWellPath* wellPath = wellPathItem->m_wellpath;

View File

@ -38,10 +38,7 @@ CAF_CMD_SOURCE_INIT( RicNewWellPathStimPlanModelAtPosFeature, "RicNewWellPathSti
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicNewWellPathStimPlanModelAtPosFeature::onActionTriggered( bool isChecked ) void RicNewWellPathStimPlanModelAtPosFeature::onActionTriggered( bool isChecked )
{ {
Riu3dSelectionManager* riuSelManager = Riu3dSelectionManager::instance(); RiuWellPathSelectionItem* wellPathItem = RiuWellPathSelectionItem::wellPathSelectionItem();
RiuSelectionItem* selItem = riuSelManager->selectedItem( Riu3dSelectionManager::RUI_TEMPORARY );
RiuWellPathSelectionItem* wellPathItem = dynamic_cast<RiuWellPathSelectionItem*>( selItem );
if ( !wellPathItem ) return; if ( !wellPathItem ) return;
RimWellPath* wellPath = wellPathItem->m_wellpath; RimWellPath* wellPath = wellPathItem->m_wellpath;

View File

@ -48,7 +48,7 @@ CAF_CMD_SOURCE_INIT( RicNewWellPathLateralAtDepthFeature, "RicNewWellPathLateral
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
bool RicNewWellPathLateralAtDepthFeature::isCommandEnabled() bool RicNewWellPathLateralAtDepthFeature::isCommandEnabled()
{ {
if ( wellPathSelectionItem() ) if ( RiuWellPathSelectionItem::wellPathSelectionItem() )
{ {
return true; return true;
} }
@ -61,7 +61,7 @@ bool RicNewWellPathLateralAtDepthFeature::isCommandEnabled()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicNewWellPathLateralAtDepthFeature::onActionTriggered( bool isChecked ) void RicNewWellPathLateralAtDepthFeature::onActionTriggered( bool isChecked )
{ {
RiuWellPathSelectionItem* wellPathSelItem = wellPathSelectionItem(); RiuWellPathSelectionItem* wellPathSelItem = RiuWellPathSelectionItem::wellPathSelectionItem();
CVF_ASSERT( wellPathSelItem ); CVF_ASSERT( wellPathSelItem );
RimWellPath* parentWellPath = wellPathSelItem->m_wellpath; RimWellPath* parentWellPath = wellPathSelItem->m_wellpath;
@ -131,19 +131,6 @@ RimWellPath* RicNewWellPathLateralAtDepthFeature::createLateralAtMeasuredDepth(
return nullptr; return nullptr;
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuWellPathSelectionItem* RicNewWellPathLateralAtDepthFeature::wellPathSelectionItem()
{
Riu3dSelectionManager* riuSelManager = Riu3dSelectionManager::instance();
RiuSelectionItem* selItem = riuSelManager->selectedItem( Riu3dSelectionManager::RUI_TEMPORARY );
RiuWellPathSelectionItem* wellPathItem = dynamic_cast<RiuWellPathSelectionItem*>( selItem );
return wellPathItem;
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@ -20,7 +20,6 @@
#include "cafCmdFeature.h" #include "cafCmdFeature.h"
class RiuWellPathSelectionItem;
class RimWellPath; class RimWellPath;
//================================================================================================== //==================================================================================================
@ -37,7 +36,4 @@ public:
static RimWellPath* createLateralAtMeasuredDepth( RimWellPath* parentWellPath, double parentWellMD ); static RimWellPath* createLateralAtMeasuredDepth( RimWellPath* parentWellPath, double parentWellMD );
static QString updateNameOfParentAndFindNameOfSideStep( RimWellPath* parentWellPath ); static QString updateNameOfParentAndFindNameOfSideStep( RimWellPath* parentWellPath );
private:
static RiuWellPathSelectionItem* wellPathSelectionItem();
}; };

View File

@ -283,6 +283,14 @@ RiuWellPathSelectionItem::RiuWellPathSelectionItem( const RivWellPathSourceInfo*
m_wellpath = wellPathSourceInfo->wellPath(); m_wellpath = wellPathSourceInfo->wellPath();
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuWellPathSelectionItem* RiuWellPathSelectionItem::wellPathSelectionItem()
{
return Riu3dSelectionManager::instance()->objectByType<RiuWellPathSelectionItem>( Riu3dSelectionManager::RUI_TEMPORARY );
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@ -84,6 +84,12 @@ public:
bool isEmpty( int role = RUI_APPLICATION_GLOBAL ) const; bool isEmpty( int role = RUI_APPLICATION_GLOBAL ) const;
template <typename T>
T* objectByType( int role ) const
{
return dynamic_cast<T*>( selectedItem( role ) );
}
private: private:
Riu3dSelectionManager(); Riu3dSelectionManager();
~Riu3dSelectionManager(); ~Riu3dSelectionManager();
@ -243,6 +249,8 @@ public:
RiuSelectionType type() const override { return WELLPATH_SELECTION_OBJECT; } RiuSelectionType type() const override { return WELLPATH_SELECTION_OBJECT; }
static RiuWellPathSelectionItem* wellPathSelectionItem();
public: public:
RimWellPath* m_wellpath; RimWellPath* m_wellpath;
cvf::Vec3d m_pipeCenterlineIntersectionInDomainCoords; cvf::Vec3d m_pipeCenterlineIntersectionInDomainCoords;