diff --git a/ApplicationLibCode/CommandFileInterface/RicfScaleFractureTemplate.cpp b/ApplicationLibCode/CommandFileInterface/RicfScaleFractureTemplate.cpp index f48e3fd67d..88e01041cd 100644 --- a/ApplicationLibCode/CommandFileInterface/RicfScaleFractureTemplate.cpp +++ b/ApplicationLibCode/CommandFileInterface/RicfScaleFractureTemplate.cpp @@ -19,11 +19,10 @@ #include "RicfScaleFractureTemplate.h" -#include "RiaLogging.h" +#include "RicfCommandForwarding.h" #include "RimFractureTemplate.h" -#include "RimFractureTemplateCollection.h" -#include "RimProject.h" +#include "RimcFractureTemplate.h" #include "cafPdmFieldScriptingCapability.h" @@ -48,36 +47,17 @@ RicfScaleFractureTemplate::RicfScaleFractureTemplate() //-------------------------------------------------------------------------------------------------- caf::PdmScriptResponse RicfScaleFractureTemplate::execute() { - if ( m_id < 0 ) - { - QString error( "scaleFractureTemplate: Fracture template id not specified" ); - RiaLogging::error( error.toStdString() ); - return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, error ); - } + const QString commandName = classKeyword(); - RimProject* project = RimProject::current(); + if ( m_id < 0 ) return RicfForwarding::errorResponse( "Fracture template id not specified", commandName ); - if ( !project ) - { - QString error( "scaleFractureTemplate: Project not found" ); - RiaLogging::error( error.toStdString() ); - return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, error ); - } + auto fractureTemplate = RicfForwarding::findFractureTemplate( m_id() ); + if ( !fractureTemplate ) return RicfForwarding::errorResponse( fractureTemplate.error(), commandName ); - RimFractureTemplateCollection* templColl = - !project->allFractureTemplateCollections().empty() ? project->allFractureTemplateCollections()[0] : nullptr; - RimFractureTemplate* templ = templColl ? templColl->fractureTemplate( m_id ) : nullptr; + RimcFractureTemplate_setScaleFactors method( fractureTemplate.value() ); + method.setScaleFactors( m_halfLengthScaleFactor(), m_heightScaleFactor(), m_dFactorScaleFactor(), m_conductivityScaleFactor() ); - if ( !templ ) - { - QString error = QString( "scaleFractureTemplate: Fracture template not found. Id=%1" ).arg( m_id() ); - RiaLogging::error( error.toStdString() ); - return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, error ); - } - - templ->setScaleFactors( m_halfLengthScaleFactor, m_heightScaleFactor, m_dFactorScaleFactor, m_conductivityScaleFactor ); - templ->loadDataAndUpdateGeometryHasChanged(); - return caf::PdmScriptResponse(); + return RicfForwarding::toScriptResponse( method.execute(), commandName ); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Completions/RimFractureTemplate.cpp b/ApplicationLibCode/ProjectDataModel/Completions/RimFractureTemplate.cpp index 9e8160dfbf..1bbc15246c 100644 --- a/ApplicationLibCode/ProjectDataModel/Completions/RimFractureTemplate.cpp +++ b/ApplicationLibCode/ProjectDataModel/Completions/RimFractureTemplate.cpp @@ -109,7 +109,7 @@ RimFractureTemplate::RimFractureTemplate() { CAF_PDM_InitScriptableObject( "Fracture Template", ":/FractureTemplate16x16.png" ); - CAF_PDM_InitField( &m_id, "Id", -1, "ID" ); + CAF_PDM_InitScriptableField( &m_id, "Id", -1, "ID" ); m_id.uiCapability()->setUiReadOnly( true ); CAF_PDM_InitScriptableField( &m_name, "UserDescription", QString( "Fracture Template" ), "Name" ); diff --git a/ApplicationLibCode/ProjectDataModelCommands/RimcFractureTemplate.cpp b/ApplicationLibCode/ProjectDataModelCommands/RimcFractureTemplate.cpp index de5065987f..51ba1f7cc0 100644 --- a/ApplicationLibCode/ProjectDataModelCommands/RimcFractureTemplate.cpp +++ b/ApplicationLibCode/ProjectDataModelCommands/RimcFractureTemplate.cpp @@ -40,6 +40,17 @@ RimcFractureTemplate_setScaleFactors::RimcFractureTemplate_setScaleFactors( caf: CAF_PDM_InitScriptableField( &m_conductivity, "Conductivity", 1.0, "Conductivity" ); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimcFractureTemplate_setScaleFactors::setScaleFactors( double halfLength, double height, double dFactor, double conductivity ) +{ + m_halfLength = halfLength; + m_height = height; + m_dFactor = dFactor; + m_conductivity = conductivity; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -59,3 +70,44 @@ std::expected RimcFractureTemplate_setScaleFacto return nullptr; } + +CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimFractureTemplate, RimFractureTemplate_setContainment, "setContainment" ); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimFractureTemplate_setContainment::RimFractureTemplate_setContainment( caf::PdmObjectHandle* self ) + : caf::PdmVoidObjectMethod( self ) +{ + CAF_PDM_InitObject( "Set Fracture Containment", "", "", "Set the K layer range fractures from this template are contained within" ); + + CAF_PDM_InitScriptableField( &m_topLayer, "TopLayer", -1, "Top Layer", "", "", "Zero-based K index of the top layer" ); + CAF_PDM_InitScriptableField( &m_baseLayer, "BaseLayer", -1, "Base Layer", "", "", "Zero-based K index of the base layer" ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimFractureTemplate_setContainment::setLayers( int topLayer, int baseLayer ) +{ + m_topLayer = topLayer; + m_baseLayer = baseLayer; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::expected RimFractureTemplate_setContainment::execute() +{ + auto* fractureTemplate = self(); + if ( !fractureTemplate ) return std::unexpected( "No fracture template is available." ); + + if ( m_topLayer() < 0 || m_baseLayer() < 0 ) return std::unexpected( "Top and base layer must be non-negative." ); + if ( m_topLayer() > m_baseLayer() ) return std::unexpected( "Top layer must not be below the base layer." ); + + fractureTemplate->setContainmentTopKLayer( m_topLayer() ); + fractureTemplate->setContainmentBaseKLayer( m_baseLayer() ); + fractureTemplate->loadDataAndUpdateGeometryHasChanged(); + + return nullptr; +} diff --git a/ApplicationLibCode/ProjectDataModelCommands/RimcFractureTemplate.h b/ApplicationLibCode/ProjectDataModelCommands/RimcFractureTemplate.h index 7dea6cd69f..d1f5255356 100644 --- a/ApplicationLibCode/ProjectDataModelCommands/RimcFractureTemplate.h +++ b/ApplicationLibCode/ProjectDataModelCommands/RimcFractureTemplate.h @@ -36,6 +36,8 @@ class RimcFractureTemplate_setScaleFactors : public caf::PdmVoidObjectMethod public: RimcFractureTemplate_setScaleFactors( caf::PdmObjectHandle* self ); + void setScaleFactors( double halfLength, double height, double dFactor, double conductivity ); + std::expected execute() override; private: @@ -44,3 +46,22 @@ private: caf::PdmField m_dFactor; caf::PdmField m_conductivity; }; + +//================================================================================================== +/// Set the K layer range the fractures created from this template are contained within. +//================================================================================================== +class RimFractureTemplate_setContainment : public caf::PdmVoidObjectMethod +{ + CAF_PDM_HEADER_INIT; + +public: + RimFractureTemplate_setContainment( caf::PdmObjectHandle* self ); + + void setLayers( int topLayer, int baseLayer ); + + std::expected execute() override; + +private: + caf::PdmField m_topLayer; + caf::PdmField m_baseLayer; +}; diff --git a/GrpcInterface/Python/rips/project.py b/GrpcInterface/Python/rips/project.py index 18d7ab5e7b..2ef1e1b9a3 100644 --- a/GrpcInterface/Python/rips/project.py +++ b/GrpcInterface/Python/rips/project.py @@ -20,8 +20,10 @@ import Project_pb2_grpc import KeyValueStore_pb2_grpc import KeyValueStore_pb2 +from .exception import RipsError from .resinsight_classes import ( ColorLegendCollection, + FractureTemplate, PlotWindow, Project, Reservoir, @@ -356,12 +358,21 @@ def export_well_paths(self, well_paths=None, md_step_size=5.0): ) +def _fracture_template_by_id(project, template_id): + for template in project.descendants(FractureTemplate): + if template.id == template_id: + return template + raise RipsError(f"Could not find fracture template with ID {template_id}") + + @add_method(Project) def scale_fracture_template( self, template_id, half_length, height, d_factor, conductivity ): """Scale fracture template parameters + Deprecated: use FractureTemplate.set_scale_factors(...) on the template object instead. + Arguments: template_id(int): ID of fracture template half_length (double): Half Length scale factor @@ -369,14 +380,17 @@ def scale_fracture_template( d_factor (double): D-factor scale factor conductivity (double): Conductivity scale factor """ - return self._execute_command( - scaleFractureTemplate=Commands_pb2.ScaleFractureTemplateRequest( - id=template_id, - halfLength=half_length, - height=height, - dFactor=d_factor, - conductivity=conductivity, - ) + warnings.warn( + "Project.scale_fracture_template(template_id=...) is deprecated, use FractureTemplate.set_scale_factors() instead", + DeprecationWarning, + stacklevel=3, + ) + template = _fracture_template_by_id(self, template_id) + template.set_scale_factors( + half_length=half_length, + height=height, + d_factor=d_factor, + conductivity=conductivity, ) @@ -384,16 +398,20 @@ def scale_fracture_template( def set_fracture_containment(self, template_id, top_layer, base_layer): """Set fracture template containment parameters + Deprecated: use FractureTemplate.set_containment(...) on the template object instead. + Arguments: template_id(int): ID of fracture template top_layer (int): Top layer containment base_layer (int): Base layer containment """ - return self._execute_command( - setFractureContainment=Commands_pb2.SetFracContainmentRequest( - id=template_id, topLayer=top_layer, baseLayer=base_layer - ) + warnings.warn( + "Project.set_fracture_containment(template_id=...) is deprecated, use FractureTemplate.set_containment() instead", + DeprecationWarning, + stacklevel=3, ) + template = _fracture_template_by_id(self, template_id) + template.set_containment(top_layer=top_layer, base_layer=base_layer) @add_method(Project) diff --git a/GrpcInterface/Python/rips/tests/test_project.py b/GrpcInterface/Python/rips/tests/test_project.py index f203eec90e..a0adfd065d 100644 --- a/GrpcInterface/Python/rips/tests/test_project.py +++ b/GrpcInterface/Python/rips/tests/test_project.py @@ -186,9 +186,10 @@ def test_scale_fracture_template_and_set_containment(rips_instance, initialize_t assert template.d_factor_scale_factor == 1.0 assert template.conductivity_factor == 1.0 - project.scale_fracture_template( - template_id=0, half_length=2.0, height=3.0, d_factor=4.0, conductivity=5.0 - ) + with pytest.warns(DeprecationWarning): + project.scale_fracture_template( + template_id=0, half_length=2.0, height=3.0, d_factor=4.0, conductivity=5.0 + ) after_scale = project.descendants(rips.FractureTemplate)[0] assert after_scale.width_scale_factor == 2.0 @@ -196,7 +197,24 @@ def test_scale_fracture_template_and_set_containment(rips_instance, initialize_t assert after_scale.d_factor_scale_factor == 4.0 assert after_scale.conductivity_factor == 5.0 - project.set_fracture_containment(template_id=0, top_layer=5, base_layer=10) + # Object method + template.set_scale_factors( + half_length=1.5, height=2.5, d_factor=3.5, conductivity=4.5 + ) + after_scale = project.descendants(rips.FractureTemplate)[0] + assert after_scale.width_scale_factor == 1.5 + assert after_scale.conductivity_factor == 4.5 + + with pytest.raises(rips.RipsError): + project.scale_fracture_template( + template_id=999, half_length=1, height=1, d_factor=1, conductivity=1 + ) + + with pytest.warns(DeprecationWarning): + project.set_fracture_containment(template_id=0, top_layer=5, base_layer=10) + + with pytest.raises(rips.RipsError): + template.set_containment(top_layer=10, base_layer=5) # RimFractureContainment fields are not scriptable, so verify the change # made it through by saving the project and inspecting the .rsp XML.