#14772 Python: Add WellPathCollection.import_well_paths as object method and forward importWellPaths to it

RimWellPathCollection_importWellPaths imports well path files given
explicitly and/or all well path files in a folder, and returns the
names of the imported well paths. The legacy RicImportWellPaths
command (a RICF_SOURCE_INIT feature in Commands/) forwards to it.
This commit is contained in:
Kristian Bendiksen committed 2026-09-22 14:19:23 +02:00
1 parent 6548c4f4db
commit 06d6e2da65
4 files changed
+294 -66

No files matched your search

@@ -29,6 +29,8 @@
#include "RimProject.h"
#include "RimWellPath.h"
#include "RimWellPathCollection.h"
#include "RimcDataContainerString.h"
#include "RimcWellPathCollection.h"
#include "Riu3DMainWindowTools.h"
#include "RiuFileDialogTools.h"
@@ -74,83 +76,47 @@ RicImportWellPaths::RicImportWellPaths()
//--------------------------------------------------------------------------------------------------
caf::PdmScriptResponse RicImportWellPaths::execute()
{
QStringList errorMessages, warningMessages;
QStringList wellPathFiles;
QDir wellPathDir;
if ( m_wellPathFolder().isEmpty() )
RimProject* project = RimProject::current();
if ( !project || !project->activeOilField() || !project->activeOilField()->wellPathCollection() )
{
wellPathDir = QDir( RiaApplication::instance()->startDir() );
}
else
{
wellPathDir = QDir( m_wellPathFolder );
return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, "importWellPaths: No well path collection available" );
}
if ( !m_wellPathFolder().isEmpty() )
{
if ( wellPathDir.exists() )
{
QStringList nameFilters;
nameFilters << RicImportWellPaths::wellPathNameFilters();
QStringList relativePaths = wellPathDir.entryList( nameFilters, QDir::Files | QDir::NoDotAndDotDot );
for ( const QString& relativePath : relativePaths )
{
wellPathFiles.push_back( wellPathDir.absoluteFilePath( relativePath ) );
}
}
else
{
errorMessages << ( wellPathDir.absolutePath() + " does not exist" );
}
}
RimWellPathCollection_importWellPaths method( project->activeOilField()->wellPathCollection() );
method.setWellPathFiles( m_wellPathFiles() );
method.setWellPathFolder( m_wellPathFolder() );
for ( const QString& wellPathFile : m_wellPathFiles() )
{
if ( QFileInfo::exists( wellPathFile ) )
{
wellPathFiles.push_back( wellPathFile );
}
else if ( QFileInfo::exists( wellPathDir.absoluteFilePath( wellPathFile ) ) )
{
wellPathFiles.push_back( wellPathDir.absoluteFilePath( wellPathFile ) );
}
else
{
errorMessages << ( wellPathFile + " does not exist" );
}
}
auto result = method.execute();
caf::PdmScriptResponse response;
if ( !wellPathFiles.empty() )
{
std::vector<RimWellPath*> importedWellPaths = importWellPaths( wellPathFiles, &warningMessages );
if ( !importedWellPaths.empty() )
{
RicImportWellPathsResult* wellPathsResult = new RicImportWellPathsResult;
for ( RimWellPath* wellPath : importedWellPaths )
{
wellPathsResult->wellPathNames.v().push_back( wellPath->name() );
}
response.setResult( wellPathsResult );
}
}
else
{
warningMessages << "No well paths found";
}
for ( const QString& warningMessage : warningMessages )
for ( const QString& warningMessage : method.warnings() )
{
response.updateStatus( caf::PdmScriptResponse::COMMAND_WARNING, warningMessage );
}
for ( const 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 path files found" )
{
response.updateStatus( caf::PdmScriptResponse::COMMAND_WARNING, "No well paths found" );
}
else
{
response.updateStatus( caf::PdmScriptResponse::COMMAND_ERROR, result.error() );
}
return response;
}
auto* names = dynamic_cast<RimcDataContainerString*>( result.value() );
if ( names && !names->m_stringValues().empty() )
{
auto* wellPathsResult = new RicImportWellPathsResult;
wellPathsResult->wellPathNames = names->m_stringValues();
response.setResult( wellPathsResult );
}
delete names;
return response;
}
@@ -43,10 +43,9 @@ public:
caf::PdmScriptResponse execute() override;
static std::vector<RimWellPath*> importWellPaths( const QStringList& wellPathFilePaths, QStringList* errorMessages );
static QStringList wellPathNameFilters();
protected:
static QStringList wellPathNameFilters();
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;