From 78464b772fda16ac262f89cabf5e5641123a7a8a Mon Sep 17 00:00:00 2001 From: Kristian Bendiksen Date: Thu, 25 Aug 2022 15:10:23 +0200 Subject: [PATCH] #9100 Thermal Fracture: add action to place using template data --- .../FractureCommands/CMakeLists_files.cmake | 2 + ...hermalFractureUsingTemplateDataFeature.cpp | 106 ++++++++++++++++++ ...eThermalFractureUsingTemplateDataFeature.h | 39 +++++++ .../RimThermalFractureTemplate.cpp | 16 +++ .../Completions/RimThermalFractureTemplate.h | 2 + .../RimContextCommandBuilder.cpp | 2 + 6 files changed, 167 insertions(+) create mode 100644 ApplicationLibCode/Commands/FractureCommands/RicPlaceThermalFractureUsingTemplateDataFeature.cpp create mode 100644 ApplicationLibCode/Commands/FractureCommands/RicPlaceThermalFractureUsingTemplateDataFeature.h diff --git a/ApplicationLibCode/Commands/FractureCommands/CMakeLists_files.cmake b/ApplicationLibCode/Commands/FractureCommands/CMakeLists_files.cmake index 44b3c832ed..e9061068e8 100644 --- a/ApplicationLibCode/Commands/FractureCommands/CMakeLists_files.cmake +++ b/ApplicationLibCode/Commands/FractureCommands/CMakeLists_files.cmake @@ -21,6 +21,7 @@ set(SOURCE_GROUP_HEADER_FILES ${CMAKE_CURRENT_LIST_DIR}/RicCreateMultipleFracturesUi.h ${CMAKE_CURRENT_LIST_DIR}/RicNewOptionItemFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicDeleteOptionItemFeature.h + ${CMAKE_CURRENT_LIST_DIR}/RicPlaceThermalFractureUsingTemplateDataFeature.h ) set(SOURCE_GROUP_SOURCE_FILES @@ -46,6 +47,7 @@ set(SOURCE_GROUP_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/RicCreateMultipleFracturesUi.cpp ${CMAKE_CURRENT_LIST_DIR}/RicNewOptionItemFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicDeleteOptionItemFeature.cpp + ${CMAKE_CURRENT_LIST_DIR}/RicPlaceThermalFractureUsingTemplateDataFeature.cpp ) list(APPEND COMMAND_CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES}) diff --git a/ApplicationLibCode/Commands/FractureCommands/RicPlaceThermalFractureUsingTemplateDataFeature.cpp b/ApplicationLibCode/Commands/FractureCommands/RicPlaceThermalFractureUsingTemplateDataFeature.cpp new file mode 100644 index 0000000000..91c66482e2 --- /dev/null +++ b/ApplicationLibCode/Commands/FractureCommands/RicPlaceThermalFractureUsingTemplateDataFeature.cpp @@ -0,0 +1,106 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2022- 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 "RicPlaceThermalFractureUsingTemplateDataFeature.h" + +#include "RiaLogging.h" + +#include "RigWellPath.h" +#include "RimProject.h" +#include "RimThermalFractureTemplate.h" +#include "RimWellPath.h" +#include "RimWellPathFracture.h" + +#include "cafSelectionManager.h" + +#include "cvfAssert.h" + +#include +#include + +CAF_CMD_SOURCE_INIT( RicPlaceThermalFractureUsingTemplateDataFeature, "RicPlaceThermalFractureUsingTemplateDataFeature" ); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicPlaceThermalFractureUsingTemplateDataFeature::onActionTriggered( bool isChecked ) +{ + RimWellPathFracture* fracture = RicPlaceThermalFractureUsingTemplateDataFeature::selectedThermalFracture(); + if ( !fracture ) return; + + if ( !fracture->fractureTemplate() ) return; + + RimThermalFractureTemplate* thermalTemplate = dynamic_cast( fracture->fractureTemplate() ); + if ( !thermalTemplate ) return; + + RimWellPath* wellPath = nullptr; + fracture->firstAncestorOrThisOfTypeAsserted( wellPath ); + + auto wellPathGeometry = wellPath->wellPathGeometry(); + if ( !wellPathGeometry ) return; + + auto [centerPosition, rotation] = thermalTemplate->computePositionAndRotation(); + + // TODO: y conversion is workaround for strange test data + centerPosition.y() = std::fabs( centerPosition.y() ); + centerPosition.z() *= -1.0; + + double md = wellPathGeometry->closestMeasuredDepth( centerPosition ); + + RiaLogging::info( QString( "Placing thermal fracture. Posotion: [%1 %2 %3]" ) + .arg( centerPosition.x() ) + .arg( centerPosition.y() ) + .arg( centerPosition.z() ) ); + RiaLogging::info( QString( "Computed MD: %1" ).arg( md ) ); + + fracture->setMeasuredDepth( md ); + + fracture->updateConnectedEditors(); + RimProject* project = RimProject::current(); + project->reloadCompletionTypeResultsInAllViews(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicPlaceThermalFractureUsingTemplateDataFeature::setupActionLook( QAction* actionToSetup ) +{ + actionToSetup->setText( "Place Using Template Data" ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicPlaceThermalFractureUsingTemplateDataFeature::isCommandEnabled() +{ + return selectedThermalFracture() != nullptr; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimWellPathFracture* RicPlaceThermalFractureUsingTemplateDataFeature::selectedThermalFracture() +{ + auto fracture = caf::SelectionManager::instance()->selectedItemOfType(); + if ( !fracture->fractureTemplate() ) return nullptr; + + RimThermalFractureTemplate* thermalTemplate = dynamic_cast( fracture->fractureTemplate() ); + if ( !thermalTemplate ) return nullptr; + + return fracture; +} diff --git a/ApplicationLibCode/Commands/FractureCommands/RicPlaceThermalFractureUsingTemplateDataFeature.h b/ApplicationLibCode/Commands/FractureCommands/RicPlaceThermalFractureUsingTemplateDataFeature.h new file mode 100644 index 0000000000..5087b2f74a --- /dev/null +++ b/ApplicationLibCode/Commands/FractureCommands/RicPlaceThermalFractureUsingTemplateDataFeature.h @@ -0,0 +1,39 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2022- 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 "cafCmdFeature.h" + +class RimWellPathFracture; + +//================================================================================================== +/// +//================================================================================================== +class RicPlaceThermalFractureUsingTemplateDataFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; + +protected: + void onActionTriggered( bool isChecked ) override; + void setupActionLook( QAction* actionToSetup ) override; + bool isCommandEnabled() override; + +private: + static RimWellPathFracture* selectedThermalFracture(); +}; diff --git a/ApplicationLibCode/ProjectDataModel/Completions/RimThermalFractureTemplate.cpp b/ApplicationLibCode/ProjectDataModel/Completions/RimThermalFractureTemplate.cpp index 9742eeb8a8..36d7df426e 100644 --- a/ApplicationLibCode/ProjectDataModel/Completions/RimThermalFractureTemplate.cpp +++ b/ApplicationLibCode/ProjectDataModel/Completions/RimThermalFractureTemplate.cpp @@ -689,3 +689,19 @@ QString RimThermalFractureTemplate::wellPathDepthAtFractureUiName() const { return "Well/Fracture Intersection Depth"; } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::pair RimThermalFractureTemplate::computePositionAndRotation() const +{ + cvf::Vec3d centerPosition = cvf::Vec3d::UNDEFINED; + cvf::Vec3d rotation = cvf::Vec3d::UNDEFINED; + + if ( m_fractureDefinitionData ) + { + centerPosition = m_fractureDefinitionData->centerPosition(); + } + + return std::make_pair( centerPosition, rotation ); +} diff --git a/ApplicationLibCode/ProjectDataModel/Completions/RimThermalFractureTemplate.h b/ApplicationLibCode/ProjectDataModel/Completions/RimThermalFractureTemplate.h index f2d5fd46d4..f3e1f77d56 100644 --- a/ApplicationLibCode/ProjectDataModel/Completions/RimThermalFractureTemplate.h +++ b/ApplicationLibCode/ProjectDataModel/Completions/RimThermalFractureTemplate.h @@ -100,6 +100,8 @@ public: static std::pair widthParameterNameAndUnit( std::shared_ptr fractureDefinitionData ); + std::pair computePositionAndRotation() const; + protected: QString getFileSelectionFilter() const override; QStringList conductivityResultNames() const override; diff --git a/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp index 5069f5b709..416541cd28 100644 --- a/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -457,6 +457,8 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection() dynamic_cast( firstUiItem ) ) { menuBuilder << "RicNewWellPathFractureFeature"; + if ( dynamic_cast( firstUiItem ) ) + menuBuilder << "RicPlaceThermalFractureUsingTemplateDataFeature"; appendExportCompletions( menuBuilder ); } else if ( dynamic_cast( firstUiItem ) )