Make scriptability a CAF-feature

This commit is contained in:
Gaute Lindkvist
2020-03-03 10:43:07 +01:00
parent 5473fa64d5
commit b2f55a3101
55 changed files with 974 additions and 489 deletions

View File

@@ -0,0 +1,28 @@
# Load ResInsight Processing Server Client Library
import rips
# Connect to ResInsight instance
resinsight = rips.Instance.find()
# Get the project
project = resinsight.project
# Find all the well bore stability plots in the project
wbsplots = project.descendants(rips.WellBoreStabilityPlot)
# Chose a sensible output folder
dirname = "C:/temp"
# Loop through all Well Bore Stability plots
for wbsplot in wbsplots:
# Set depth type a parameter and export snapshot
wbsplot.depth_type = "TRUE_VERTICAL_DEPTH_RKB"
# Example of setting parameters for existing plots
params = wbsplot.parameters()
params.user_poisson_ratio = 0.654321
params.update()
wbsplot.update()
wbsplot.export_snapshot(export_folder=dirname)

View File

@@ -6,60 +6,33 @@ import rips
# Connect to ResInsight instance
resInsight = rips.Instance.find()
cases = resInsight.project.cases()
well_paths = resInsight.project.import_well_paths(well_path_folder='D:/Projects/ResInsight-regression-test/ModelData/Norne_WellPaths')
well_log_files = resInsight.project.import_well_log_files(well_log_folder='D:/Projects/ResInsight-regression-test/ModelData/Norne_PLT_LAS')
# Get all GeoMech cases
cases = resInsight.project.descendants(rips.GeoMechCase)
# Get all well paths
well_paths = resInsight.project.well_paths()
# Ensure there's at least one well path
if len(well_paths) < 1:
print("No well paths in project")
exit(1)
well_paths = well_paths[0:4]
print(well_paths)
# Example of creating parameters for new plots
wbs_parameters = rips.WbsParameters()
wbs_parameters.user_poisson_ratio = 0.412347
wbs_parameters.pore_pressure_outside_reservoir_source = "USER_DEFINED"
wbs_parameters.user_pp_outside_reservoir = 1.1
wbs_parameters.fg_shale_source = "PROPORTIONAL_TO_SH"
wbs_parameters.user_fg_shale = 1.13
# Loop through all cases
for case in cases:
if case.type == "GeoMechCase":
min_res_depth, max_res_depth = case.reservoir_depth_range()
print (case.id)
case_path = case.file_path
folder_name = os.path.dirname(case_path)
case.import_formation_names(formation_files=['D:/Projects/ResInsight-regression-test/ModelData/norne/Norne_ATW2013.lyr'])
assert(isinstance(case, rips.GeoMechCase))
min_res_depth, max_res_depth = case.reservoir_depth_range()
# create a folder to hold the snapshots
dirname = os.path.join(folder_name, 'snapshots')
print("Exporting to: " + dirname)
# Find a good output path
case_path = case.file_path
folder_name = os.path.dirname(case_path)
for well_path in well_paths:
try:
# Create plot with parameters
wbsplot = case.create_well_bore_stability_plot(well_path=well_path.name, time_step=0, wbs_parameters=wbs_parameters)
# Example of setting parameters for existing plots
replace_params = wbsplot.parameters()
replace_params.user_poisson_ratio = 0.654321
replace_params.user_fg_shale = 1.0321
wbsplot.set_parameters(replace_params)
# Demonstrate altering general well log plot settings
min_depth = max(wbsplot.minimum_depth, min_res_depth)
max_depth = min(wbsplot.maximum_depth, max_res_depth)
wbsplot.minimum_depth = min_depth
wbsplot.maximum_depth = max_depth
wbsplot.update()
#wbsplot.depth_type = "TRUE_VERTICAL_DEPTH_RKB"
wbsplot.export_snapshot(export_folder=dirname)
# Import formation names
case.import_formation_names(formation_files=['D:/Projects/ResInsight-regression-test/ModelData/norne/Norne_ATW2013.lyr'])
except grpc.RpcError as e:
print("Error: ", e.details())
# create a folder to hold the snapshots
dirname = os.path.join(folder_name, 'snapshots')
print("Exporting to: " + dirname)
for well_path in well_paths[0:4]: # Loop through the first five well paths
# Create plot with parameters
wbsplot = case.create_well_bore_stability_plot(well_path=well_path.name, time_step=0)

View File

@@ -25,6 +25,7 @@
#include "RimProject.h"
#include "cafPdmObject.h"
#include "cafPdmObjectScriptabilityRegister.h"
using namespace rips;
@@ -336,7 +337,7 @@ grpc::Status RiaGrpcPdmObjectService::GetAncestorPdmObject( grpc::ServerContext*
std::vector<caf::PdmObject*> objectsOfCurrentClass;
QString scriptClassName = QString::fromStdString( request->object().class_keyword() );
QString classKeyword = RicfObjectCapability::classKeywordFromScriptClassName( scriptClassName );
QString classKeyword = caf::PdmObjectScriptabilityRegister::classKeywordFromScriptClassName( scriptClassName );
project->descendantsIncludingThisFromClassKeyword( classKeyword, objectsOfCurrentClass );
@@ -353,7 +354,8 @@ grpc::Status RiaGrpcPdmObjectService::GetAncestorPdmObject( grpc::ServerContext*
{
caf::PdmObject* parentObject = nullptr;
QString ancestorScriptName = QString::fromStdString( request->parent_keyword() );
QString ancestorClassKeyword = RicfObjectCapability::classKeywordFromScriptClassName( ancestorScriptName );
QString ancestorClassKeyword =
caf::PdmObjectScriptabilityRegister::classKeywordFromScriptClassName( ancestorScriptName );
matchingObject->firstAncestorOrThisFromClassKeyword( ancestorClassKeyword, parentObject );
if ( parentObject )
{
@@ -376,8 +378,8 @@ grpc::Status RiaGrpcPdmObjectService::GetDescendantPdmObjects( grpc::ServerConte
if ( matchingObject )
{
std::vector<caf::PdmObject*> childObjects;
QString childClassKeyword =
RicfObjectCapability::classKeywordFromScriptClassName( QString::fromStdString( request->child_keyword() ) );
QString childClassKeyword = caf::PdmObjectScriptabilityRegister::classKeywordFromScriptClassName(
QString::fromStdString( request->child_keyword() ) );
matchingObject->descendantsIncludingThisFromClassKeyword( childClassKeyword, childObjects );
for ( auto pdmChild : childObjects )
{
@@ -549,7 +551,7 @@ caf::PdmObject* RiaGrpcPdmObjectService::findCafObjectFromRipsObject( const rips
std::vector<caf::PdmObject*> objectsOfCurrentClass;
QString scriptClassName = QString::fromStdString( ripsObject.class_keyword() );
QString classKeyword = RicfObjectCapability::classKeywordFromScriptClassName( scriptClassName );
QString classKeyword = caf::PdmObjectScriptabilityRegister::classKeywordFromScriptClassName( scriptClassName );
project->descendantsIncludingThisFromClassKeyword( classKeyword, objectsOfCurrentClass );

View File

@@ -29,6 +29,7 @@
#include "cafPdmChildField.h"
#include "cafPdmDataValueField.h"
#include "cafPdmObject.h"
#include "cafPdmObjectScriptabilityRegister.h"
#include "cafPdmProxyValueField.h"
#include "cafPdmXmlFieldHandle.h"
@@ -72,7 +73,7 @@ void RiaGrpcServiceInterface::copyPdmObjectFromCafToRips( const caf::PdmObjectHa
CAF_ASSERT( source && destination && source->xmlCapability() );
QString classKeyword = source->xmlCapability()->classKeyword();
QString scriptName = RicfObjectCapability::scriptClassNameFromClassKeyword( classKeyword );
QString scriptName = caf::PdmObjectScriptabilityRegister::scriptClassNameFromClassKeyword( classKeyword );
destination->set_class_keyword( scriptName.toStdString() );
destination->set_address( reinterpret_cast<uint64_t>( source ) );
@@ -107,7 +108,7 @@ void RiaGrpcServiceInterface::copyPdmObjectFromCafToRips( const caf::PdmObjectHa
QString text;
QTextStream outStream( &text );
ricfHandle->writeFieldData( outStream, false );
( *parametersMap )[ricfHandle->fieldName().toStdString()] = text.toStdString();
( *parametersMap )[ricfHandle->scriptFieldName().toStdString()] = text.toStdString();
}
}
}
@@ -146,7 +147,7 @@ void RiaGrpcServiceInterface::copyPdmObjectFromRipsToCaf( const rips::PdmObject*
auto ricfHandle = pdmValueField->template capability<RicfFieldHandle>();
if ( ricfHandle )
{
QString keyword = ricfHandle->fieldName();
QString keyword = ricfHandle->scriptFieldName();
QString value = QString::fromStdString( parametersMap[keyword.toStdString()] );
QVariant oldValue, newValue;