diff --git a/ApplicationLibCode/CommandFileInterface/RicfImportWellLogFiles.cpp b/ApplicationLibCode/CommandFileInterface/RicfImportWellLogFiles.cpp index ec9fe1343f..4b639d5aed 100644 --- a/ApplicationLibCode/CommandFileInterface/RicfImportWellLogFiles.cpp +++ b/ApplicationLibCode/CommandFileInterface/RicfImportWellLogFiles.cpp @@ -17,17 +17,16 @@ ///////////////////////////////////////////////////////////////////////////////// #include "RicfImportWellLogFiles.h" -#include "WellLogCommands/RicWellLogsImportFileFeature.h" +#include "RicfCommandForwarding.h" -#include "RiaApplication.h" -#include "RimWellLogLasFile.h" +#include "RimOilField.h" +#include "RimProject.h" +#include "RimWellPathCollection.h" +#include "RimcDataContainerString.h" +#include "RimcWellPathCollection.h" #include "cafPdmFieldScriptingCapability.h" -#include -#include -#include - CAF_PDM_SOURCE_INIT( RicfImportWellLogFilesResult, "importWellLogFilesResult" ); //-------------------------------------------------------------------------------------------------- @@ -52,80 +51,48 @@ RicfImportWellLogFiles::RicfImportWellLogFiles() caf::PdmScriptResponse RicfImportWellLogFiles::execute() { - QStringList errorMessages, warningMessages; - QStringList wellLogFilePaths; + const QString commandName = classKeyword(); - QDir wellLogDir; - if ( m_wellLogFileFolder().isEmpty() ) + RimProject* project = RimProject::current(); + if ( !project || !project->activeOilField() || !project->activeOilField()->wellPathCollection() ) { - wellLogDir = QDir( RiaApplication::instance()->startDir() ); - } - else - { - wellLogDir = QDir( m_wellLogFileFolder ); + return RicfForwarding::errorResponse( "No well path collection available", commandName ); } - if ( !m_wellLogFileFolder().isEmpty() ) - { - QStringList nameFilters; - nameFilters << RicWellLogsImportFileFeature::wellLogFileNameFilters(); - QStringList relativePaths = wellLogDir.entryList( nameFilters, QDir::Files | QDir::NoDotAndDotDot ); - for ( QString relativePath : relativePaths ) - { - wellLogFilePaths.push_back( wellLogDir.absoluteFilePath( relativePath ) ); - } - } - else - { - errorMessages << ( m_wellLogFileFolder() + " doesn't exist" ); - } + RimWellPathCollection_importWellLogFiles method( project->activeOilField()->wellPathCollection() ); + method.setWellLogFiles( m_wellLogFilePaths() ); + method.setWellLogFolder( m_wellLogFileFolder() ); - for ( QString wellLogFilePath : m_wellLogFilePaths() ) - { - if ( QFileInfo::exists( wellLogFilePath ) ) - { - wellLogFilePaths.push_back( wellLogFilePath ); - } - else if ( QFileInfo::exists( wellLogDir.absoluteFilePath( wellLogFilePath ) ) ) - { - wellLogFilePaths.push_back( wellLogDir.absoluteFilePath( wellLogFilePath ) ); - } - else - { - errorMessages << ( wellLogFilePath + " doesn't exist" ); - } - } + auto result = method.execute(); caf::PdmScriptResponse response; - - if ( !wellLogFilePaths.empty() ) - { - std::vector importedWellLogFiles = - RicWellLogsImportFileFeature::importWellLogFiles( wellLogFilePaths, &warningMessages ); - if ( !importedWellLogFiles.empty() ) - { - RicfImportWellLogFilesResult* result = new RicfImportWellLogFilesResult; - for ( RimWellLogLasFile* wellLogFile : importedWellLogFiles ) - { - result->wellPathNames.v().push_back( wellLogFile->wellName() ); - } - response.setResult( result ); - } - } - else - { - warningMessages << "No well log files found"; - } - - for ( QString warningMessage : warningMessages ) + for ( const QString& warningMessage : method.warnings() ) { response.updateStatus( caf::PdmScriptResponse::COMMAND_WARNING, warningMessage ); } - for ( QString errorMessage : errorMessages ) + if ( !result ) { - response.updateStatus( caf::PdmScriptResponse::COMMAND_ERROR, errorMessage ); + // Legacy behavior: "no files found" is a warning, missing files are errors + if ( result.error() == "No well log files found" ) + { + response.updateStatus( caf::PdmScriptResponse::COMMAND_WARNING, result.error() ); + } + else + { + response.updateStatus( caf::PdmScriptResponse::COMMAND_ERROR, result.error() ); + } + return response; } + auto* names = dynamic_cast( result.value() ); + if ( names && !names->m_stringValues().empty() ) + { + auto* filesResult = new RicfImportWellLogFilesResult; + filesResult->wellPathNames = names->m_stringValues(); + response.setResult( filesResult ); + } + delete names; + return response; } diff --git a/GrpcInterface/Python/rips/project.py b/GrpcInterface/Python/rips/project.py index 6a8d1fee36..b76b449cca 100644 --- a/GrpcInterface/Python/rips/project.py +++ b/GrpcInterface/Python/rips/project.py @@ -395,7 +395,7 @@ def import_well_paths(self, well_path_files=None, well_path_folder=""): """Import well paths into project Arguments: - well_path_files(list): List of file paths to import + well_path_files(list): list of file paths to import well_path_folder(str): A folder path containing files to import Returns: @@ -404,13 +404,11 @@ def import_well_paths(self, well_path_files=None, well_path_folder=""): if well_path_files is None: well_path_files = [] - res = self._execute_command( - importWellPaths=Commands_pb2.ImportWellPathsRequest( - wellPathFolder=well_path_folder, wellPathFiles=well_path_files - ) + names = self.well_path_collection().import_well_paths( + well_path_files=well_path_files, well_path_folder=well_path_folder ) well_paths = [] - for well_path_name in res.importWellPathsResult.wellPathNames: + for well_path_name in names.values: well_paths.append(self.well_path_by_name(well_path_name)) return well_paths @@ -444,21 +442,19 @@ def import_well_log_files(self, well_log_files=None, well_log_folder=""): """Import well log files into project Arguments: - well_log_files(list): List of file paths to import + well_log_files(list): list of file paths to import well_log_folder(str): A folder path containing files to import Returns: - A list of well path names (strings) that had logs imported + A list of well path names (strings) """ - if well_log_files is None: well_log_files = [] - res = self._execute_command( - importWellLogFiles=Commands_pb2.ImportWellLogFilesRequest( - wellLogFolder=well_log_folder, wellLogFiles=well_log_files - ) + + names = self.well_path_collection().import_well_log_files( + well_log_files=well_log_files, well_log_folder=well_log_folder ) - return res.importWellLogFilesResult.wellPathNames + return list(names.values) @add_method(Project) diff --git a/GrpcInterface/Python/rips/tests/test_project.py b/GrpcInterface/Python/rips/tests/test_project.py index e2e6a7dc9e..90653c8abc 100644 --- a/GrpcInterface/Python/rips/tests/test_project.py +++ b/GrpcInterface/Python/rips/tests/test_project.py @@ -344,6 +344,33 @@ def test_import_well_log_files(rips_instance, initialize_test): assert "RIPS_TEST" in well_path_names +def test_import_well_paths_and_logs_object_methods(rips_instance, initialize_test): + collection = rips_instance.project.well_path_collection() + + # Import by folder: both .dev files in the test model folder + names = collection.import_well_paths( + well_path_folder=dataroot.PATH + "/TEST10K_FLT_LGR_NNC" + ) + assert sorted(names.values) == ["Well Path A", "Well Path B"] + assert len(rips_instance.project.well_paths()) == 2 + + with pytest.raises(rips.RipsError): + collection.import_well_paths(well_path_files=["/does/not/exist.dev"]) + with pytest.raises(rips.RipsError): + collection.import_well_paths() + + with tempfile.TemporaryDirectory(prefix="rips") as tmpdirname: + las_path = os.path.join(tmpdirname, "rips_test.las") + with open(las_path, "w") as las_file: + las_file.write(_MINIMAL_LAS) + + names = collection.import_well_log_files(well_log_files=[las_path]) + assert list(names.values) == ["RIPS_TEST"] + + with pytest.raises(rips.RipsError): + collection.import_well_log_files() + + def test_exportSnapshots(rips_instance, initialize_test): if not rips_instance.is_gui(): pytest.skip("Cannot run test without a GUI")