From 195bcf28175d75cfecddf7d0be0bc76d69472505 Mon Sep 17 00:00:00 2001 From: Gaute Lindkvist Date: Mon, 19 Oct 2020 14:53:38 +0200 Subject: [PATCH] Skeleton for toggling grouping of well paths --- .../WellPathCommands/CMakeLists_files.cmake | 2 + .../RicToggleWellPathGrouping.cpp | 163 ++++++++++++++++++ .../RicToggleWellPathGrouping.h | 55 ++++++ .../RimContextCommandBuilder.cpp | 6 + .../RimWellPathCollection.cpp | 16 ++ .../ProjectDataModel/RimWellPathCollection.h | 2 + 6 files changed, 244 insertions(+) create mode 100644 ApplicationCode/Commands/WellPathCommands/RicToggleWellPathGrouping.cpp create mode 100644 ApplicationCode/Commands/WellPathCommands/RicToggleWellPathGrouping.h diff --git a/ApplicationCode/Commands/WellPathCommands/CMakeLists_files.cmake b/ApplicationCode/Commands/WellPathCommands/CMakeLists_files.cmake index ae1f8833b6..2b8c567426 100644 --- a/ApplicationCode/Commands/WellPathCommands/CMakeLists_files.cmake +++ b/ApplicationCode/Commands/WellPathCommands/CMakeLists_files.cmake @@ -2,6 +2,7 @@ set (SOURCE_GROUP_HEADER_FILES ${CMAKE_CURRENT_LIST_DIR}/RicImportWellPaths.h ${CMAKE_CURRENT_LIST_DIR}/RicImportGroupedWellPaths.h +${CMAKE_CURRENT_LIST_DIR}/RicToggleWellPathGrouping.h ${CMAKE_CURRENT_LIST_DIR}/RicNewEditableWellPathFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicShowWellPlanFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicNewWellPathListTargetFeature.h @@ -30,6 +31,7 @@ ${CMAKE_CURRENT_LIST_DIR}/PointTangentManipulator/RicPolylineTarget3dEditor.h set (SOURCE_GROUP_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/RicImportWellPaths.cpp ${CMAKE_CURRENT_LIST_DIR}/RicImportGroupedWellPaths.cpp +${CMAKE_CURRENT_LIST_DIR}/RicToggleWellPathGrouping.cpp ${CMAKE_CURRENT_LIST_DIR}/RicNewEditableWellPathFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicShowWellPlanFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicNewWellPathListTargetFeature.cpp diff --git a/ApplicationCode/Commands/WellPathCommands/RicToggleWellPathGrouping.cpp b/ApplicationCode/Commands/WellPathCommands/RicToggleWellPathGrouping.cpp new file mode 100644 index 0000000000..1cbfb07341 --- /dev/null +++ b/ApplicationCode/Commands/WellPathCommands/RicToggleWellPathGrouping.cpp @@ -0,0 +1,163 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2020- 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// +#include "RicToggleWellPathGrouping.h" + +#include "RigWellPath.h" + +#include "RimOilField.h" +#include "RimProject.h" +#include "RimWellPath.h" +#include "RimWellPathCollection.h" + +#include "cafPdmFieldScriptingCapability.h" +#include "cafSelectionManager.h" + +#include + +RICF_SOURCE_INIT( RicToggleWellPathGrouping, "RicToggleWellPathGroupingFeature", "groupWellPaths" ); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicToggleWellPathGrouping::RicToggleWellPathGrouping() +{ + CAF_PDM_InitScriptableField( &m_groupeWellPaths, "group", false, "", "", "", "" ); + CAF_PDM_InitScriptableFieldNoDefault( &m_wellPaths, "wellPaths", "", "", "", "" ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +caf::PdmScriptResponse RicToggleWellPathGrouping::execute() +{ + caf::PdmScriptResponse response; + + auto wellPaths = m_wellPaths.ptrReferencedObjects(); + if ( wellPaths.empty() ) + { + return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_WARNING, "No well paths provided" ); + } + + RimProject* project = RimProject::current(); + + if ( project ) + { + project->scheduleCreateDisplayModelAndRedrawAllViews(); + RimOilField* oilField = project->activeOilField(); + + if ( oilField ) + { + if ( m_groupeWellPaths() ) + { + oilField->wellPathCollection->groupWellPaths( wellPaths ); + return caf::PdmScriptResponse(); + } + else + { + oilField->wellPathCollection->ungroupWellPaths( wellPaths ); + return caf::PdmScriptResponse(); + } + } + } + return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, "No project open" ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicToggleWellPathGrouping::isCommandEnabled() +{ + auto wellPaths = selectedWellPaths(); + return wellPaths.size() > 1u && containsUngroupedWellPathsWithCommonGeometry( wellPaths ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicToggleWellPathGrouping::onActionTriggered( bool isChecked ) +{ + auto wellPaths = selectedWellPaths(); + + if ( containsUngroupedWellPathsWithCommonGeometry( wellPaths ) ) + { + m_groupeWellPaths = true; + } + else if ( containsGroupedWellPaths( wellPaths ) ) + { + m_groupeWellPaths = false; + } + else + { + return; + } + + m_wellPaths.setValue( wellPaths ); + execute(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicToggleWellPathGrouping::setupActionLook( QAction* actionToSetup ) +{ + auto wellPaths = selectedWellPaths(); + if ( containsUngroupedWellPathsWithCommonGeometry( wellPaths ) ) + { + actionToSetup->setText( "Group the selected well paths into a Well Tree" ); + actionToSetup->setIcon( QIcon( ":/Well.png" ) ); + } + else if ( containsGroupedWellPaths( wellPaths ) ) + { + actionToSetup->setText( "Ungroup the selected well paths" ); + actionToSetup->setIcon( QIcon( ":/Well.png" ) ); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector RicToggleWellPathGrouping::selectedWellPaths() +{ + std::vector wellPaths; + caf::SelectionManager::instance()->objectsByTypeStrict( &wellPaths ); + return wellPaths; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicToggleWellPathGrouping::containsGroupedWellPaths( const std::vector& wellPaths ) +{ + // TODO: add real check + return std::any_of( wellPaths.begin(), wellPaths.end(), []( RimWellPath* wellPath ) { return true; } ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicToggleWellPathGrouping::containsUngroupedWellPathsWithCommonGeometry( const std::vector& wellPaths ) +{ + // TODO: add check for whether the well paths are grouped. + std::vector geometries; + for ( auto wellPath : wellPaths ) + { + geometries.push_back( wellPath->wellPathGeometry() ); + } + RigWellPath commonGeometry = RigWellPath::commonGeometry( geometries ); + return !commonGeometry.wellPathPoints().empty(); +} diff --git a/ApplicationCode/Commands/WellPathCommands/RicToggleWellPathGrouping.h b/ApplicationCode/Commands/WellPathCommands/RicToggleWellPathGrouping.h new file mode 100644 index 0000000000..f10285b4ff --- /dev/null +++ b/ApplicationCode/Commands/WellPathCommands/RicToggleWellPathGrouping.h @@ -0,0 +1,55 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2020- 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "CommandFileInterface/Core/RicfCommandObject.h" + +#include "cafCmdFeature.h" +#include "cafPdmField.h" +#include "cafPdmPtrArrayField.h" + +#include + +class RimWellPath; + +//================================================================================================== +/// +//================================================================================================== +class RicToggleWellPathGrouping : public caf::CmdFeature, public RicfCommandObject +{ + RICF_HEADER_INIT; + +public: + RicToggleWellPathGrouping(); + caf::PdmScriptResponse execute() override; + +protected: + // Overrides + bool isCommandEnabled() override; + void onActionTriggered( bool isChecked ) override; + void setupActionLook( QAction* actionToSetup ) override; + + static std::vector selectedWellPaths(); + static bool containsGroupedWellPaths( const std::vector& wellPaths ); + static bool containsUngroupedWellPathsWithCommonGeometry( const std::vector& wellPaths ); + +protected: + caf::PdmField m_groupeWellPaths; + caf::PdmPtrArrayField m_wellPaths; +}; diff --git a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp index be604f059a..b03269a01a 100644 --- a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -1158,6 +1158,12 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection() menuBuilder << "RicMoveItemsToTopFeature"; } + if ( caf::CmdFeatureManager::instance()->getCommandFeature( "RicToggleWellPathGroupingFeature" )->canFeatureBeExecuted() ) + { + menuBuilder << "Separator"; + menuBuilder << "RicToggleWellPathGroupingFeature"; + } + if ( caf::CmdFeatureManager::instance()->getCommandFeature( "RicDeleteItemFeature" )->canFeatureBeExecuted() ) { menuBuilder << "Separator"; diff --git a/ApplicationCode/ProjectDataModel/RimWellPathCollection.cpp b/ApplicationCode/ProjectDataModel/RimWellPathCollection.cpp index 2840392ec9..5cfab6d027 100644 --- a/ApplicationCode/ProjectDataModel/RimWellPathCollection.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellPathCollection.cpp @@ -574,6 +574,22 @@ void RimWellPathCollection::deleteAllWellPaths() updateAllRequiredEditors(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimWellPathCollection::groupWellPaths( const std::vector wellPaths ) +{ + // TODO: implement +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimWellPathCollection::ungroupWellPaths( const std::vector wellPaths ) +{ + // TODO: implement +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimWellPathCollection.h b/ApplicationCode/ProjectDataModel/RimWellPathCollection.h index d6c2de2a16..83cb4a5da6 100644 --- a/ApplicationCode/ProjectDataModel/RimWellPathCollection.h +++ b/ApplicationCode/ProjectDataModel/RimWellPathCollection.h @@ -97,6 +97,8 @@ public: std::vector allWellPaths() const; void removeWellPath( RimWellPath* wellPath ); void deleteAllWellPaths(); + void groupWellPaths( const std::vector wellPaths ); + void ungroupWellPaths( const std::vector wellPaths ); RimWellPath* mostRecentlyUpdatedWellPath();