mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#7965 Import ensemble: Add option to group import of multiple ensembles
This commit is contained in:
parent
02b5246a20
commit
4a6a1eed41
@ -28,6 +28,63 @@
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaEnsembleNameTools::findSuitableEnsembleName( const QStringList& fileNames )
|
||||
{
|
||||
QStringList iterations = findUniqueIterations( fileNames );
|
||||
if ( iterations.size() == 1u )
|
||||
{
|
||||
return iterations.front();
|
||||
}
|
||||
|
||||
if ( !iterations.empty() )
|
||||
{
|
||||
return QString( "Multiple iterations: %1" ).arg( iterations.join( ", " ) );
|
||||
}
|
||||
|
||||
QString root = RiaFilePathTools::commonRootOfFileNames( fileNames );
|
||||
|
||||
QRegularExpression trimRe( "[^a-zA-Z0-9]+$" );
|
||||
QString trimmedRoot = root.replace( trimRe, "" );
|
||||
if ( trimmedRoot.length() >= 4 )
|
||||
{
|
||||
return trimmedRoot;
|
||||
}
|
||||
|
||||
return "Ensemble";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<QStringList> RiaEnsembleNameTools::groupFilesByEnsemble( const QStringList& fileNames )
|
||||
{
|
||||
QStringList iterations = findUniqueIterations( fileNames );
|
||||
if ( iterations.size() <= 1 )
|
||||
{
|
||||
// All the files are in the same ensemble
|
||||
return { fileNames };
|
||||
}
|
||||
|
||||
std::vector<QStringList> groupedByIteration;
|
||||
for ( auto iteration : iterations )
|
||||
{
|
||||
QStringList fileNamesFromIteration;
|
||||
for ( auto filePath : fileNames )
|
||||
{
|
||||
if ( filePath.contains( iteration ) )
|
||||
{
|
||||
fileNamesFromIteration << filePath;
|
||||
}
|
||||
}
|
||||
groupedByIteration.push_back( fileNamesFromIteration );
|
||||
}
|
||||
|
||||
return groupedByIteration;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QStringList RiaEnsembleNameTools::findUniqueIterations( const QStringList& fileNames )
|
||||
{
|
||||
std::vector<QStringList> componentsForAllFilePaths;
|
||||
|
||||
@ -55,27 +112,7 @@ QString RiaEnsembleNameTools::findSuitableEnsembleName( const QStringList& fileN
|
||||
}
|
||||
|
||||
iterations.removeDuplicates();
|
||||
|
||||
if ( iterations.size() == 1u )
|
||||
{
|
||||
return iterations.front();
|
||||
}
|
||||
|
||||
if ( !iterations.empty() )
|
||||
{
|
||||
return QString( "Multiple iterations: %1" ).arg( iterations.join( ", " ) );
|
||||
}
|
||||
|
||||
QString root = RiaFilePathTools::commonRootOfFileNames( fileNames );
|
||||
|
||||
QRegularExpression trimRe( "[^a-zA-Z0-9]+$" );
|
||||
QString trimmedRoot = root.replace( trimRe, "" );
|
||||
if ( trimmedRoot.length() >= 4 )
|
||||
{
|
||||
return trimmedRoot;
|
||||
}
|
||||
|
||||
return "Ensemble";
|
||||
return iterations;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include <QString>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
@ -37,4 +38,7 @@ public:
|
||||
static QString uniqueShortNameFromComponents( const QString& sourceFileName,
|
||||
const std::map<QString, QStringList>& keyFileComponentsForAllFiles,
|
||||
const QString& ensembleCaseName );
|
||||
|
||||
static QStringList findUniqueIterations( const QStringList& fileNames );
|
||||
static std::vector<QStringList> groupFilesByEnsemble( const QStringList& fileNames );
|
||||
};
|
||||
|
@ -223,36 +223,40 @@ void RicCreateEnsembleWellLogFeature::executeCommand( const RicCreateEnsembleWel
|
||||
|
||||
if ( ui.autoCreateEnsembleWellLogs() )
|
||||
{
|
||||
RimEnsembleWellLogs* ensembleWellLogs =
|
||||
std::vector<RimEnsembleWellLogs*> ensembleWellLogs =
|
||||
RicImportEnsembleWellLogsFeature::createEnsembleWellLogsFromFiles( allLasFileNames );
|
||||
if ( ensembleWellLogs )
|
||||
|
||||
for ( auto ensembleWellLog : ensembleWellLogs )
|
||||
{
|
||||
RimEclipseCase* eclipseCase = nullptr;
|
||||
|
||||
// Create the well log plot
|
||||
RimWellLogPlot* wellLogPlot =
|
||||
RimcWellLogPlotCollection_newWellLogPlot::createWellLogPlot( plotCollection, wellPath, eclipseCase );
|
||||
|
||||
// Create a track per property
|
||||
for ( const auto& property : properties )
|
||||
if ( ensembleWellLog )
|
||||
{
|
||||
// Create well log track
|
||||
cvf::Color3f color = RiaColorTables::normalPaletteColors().cycledColor3f( wellLogPlot->plotCount() );
|
||||
QString title = QString( "Track %1" ).arg( wellLogPlot->plotCount() );
|
||||
RimWellLogTrack* wellLogTrack =
|
||||
RimcWellLogPlot_newWellLogTrack::createWellLogTrack( wellLogPlot, eclipseCase, wellPath, title );
|
||||
RimEnsembleWellLogCurveSet* ensembleWellLogCurveSet = new RimEnsembleWellLogCurveSet();
|
||||
ensembleWellLogCurveSet->setEnsembleWellLogs( ensembleWellLogs );
|
||||
ensembleWellLogCurveSet->setColor( color );
|
||||
ensembleWellLogCurveSet->setWellLogChannelName( property.first );
|
||||
wellLogTrack->setEnsembleWellLogCurveSet( ensembleWellLogCurveSet );
|
||||
ensembleWellLogCurveSet->loadDataAndUpdate( true );
|
||||
RimEclipseCase* eclipseCase = nullptr;
|
||||
|
||||
// Create the well log plot
|
||||
RimWellLogPlot* wellLogPlot =
|
||||
RimcWellLogPlotCollection_newWellLogPlot::createWellLogPlot( plotCollection, wellPath, eclipseCase );
|
||||
|
||||
// Create a track per property
|
||||
for ( const auto& property : properties )
|
||||
{
|
||||
// Create well log track
|
||||
cvf::Color3f color = RiaColorTables::normalPaletteColors().cycledColor3f( wellLogPlot->plotCount() );
|
||||
QString title = QString( "Track %1" ).arg( wellLogPlot->plotCount() );
|
||||
RimWellLogTrack* wellLogTrack =
|
||||
RimcWellLogPlot_newWellLogTrack::createWellLogTrack( wellLogPlot, eclipseCase, wellPath, title );
|
||||
RimEnsembleWellLogCurveSet* ensembleWellLogCurveSet = new RimEnsembleWellLogCurveSet();
|
||||
ensembleWellLogCurveSet->setEnsembleWellLogs( ensembleWellLog );
|
||||
ensembleWellLogCurveSet->setColor( color );
|
||||
ensembleWellLogCurveSet->setWellLogChannelName( property.first );
|
||||
wellLogTrack->setEnsembleWellLogCurveSet( ensembleWellLogCurveSet );
|
||||
ensembleWellLogCurveSet->loadDataAndUpdate( true );
|
||||
}
|
||||
|
||||
wellLogPlot->updateConnectedEditors();
|
||||
|
||||
RiuPlotMainWindowTools::showPlotMainWindow();
|
||||
RiuPlotMainWindowTools::selectAsCurrentItem( wellLogPlot );
|
||||
}
|
||||
|
||||
wellLogPlot->updateConnectedEditors();
|
||||
|
||||
RiuPlotMainWindowTools::showPlotMainWindow();
|
||||
RiuPlotMainWindowTools::selectAsCurrentItem( wellLogPlot );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -70,13 +70,24 @@ bool RicImportEnsembleFeature::isCommandEnabled()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicImportEnsembleFeature::onActionTriggered( bool isChecked )
|
||||
{
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
QString pathCacheName = "ENSEMBLE_FILES";
|
||||
QStringList fileNames =
|
||||
QString pathCacheName = "ENSEMBLE_FILES";
|
||||
QStringList fileNames =
|
||||
RicImportSummaryCasesFeature::runRecursiveSummaryCaseFileSearchDialog( "Import Ensemble", pathCacheName );
|
||||
|
||||
if ( fileNames.isEmpty() ) return;
|
||||
|
||||
std::vector<QStringList> groupedByEnsemble = RiaEnsembleNameTools::groupFilesByEnsemble( fileNames );
|
||||
for ( const QStringList& groupedFileNames : groupedByEnsemble )
|
||||
{
|
||||
importSingleEnsemble( groupedFileNames );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicImportEnsembleFeature::importSingleEnsemble( const QStringList& fileNames )
|
||||
{
|
||||
QString ensembleNameSuggestion = RiaEnsembleNameTools::findSuitableEnsembleName( fileNames );
|
||||
|
||||
QString ensembleName = askForEnsembleName( ensembleNameSuggestion );
|
||||
@ -102,7 +113,7 @@ void RicImportEnsembleFeature::onActionTriggered( bool isChecked )
|
||||
}
|
||||
|
||||
std::vector<RimCase*> allCases;
|
||||
app->project()->allCases( allCases );
|
||||
RiaApplication::instance()->project()->allCases( allCases );
|
||||
|
||||
if ( allCases.size() == 0 )
|
||||
{
|
||||
|
@ -37,5 +37,6 @@ protected:
|
||||
void onActionTriggered( bool isChecked ) override;
|
||||
void setupActionLook( QAction* actionToSetup ) override;
|
||||
|
||||
QString askForEnsembleName( const QString& suggestion );
|
||||
static QString askForEnsembleName( const QString& suggestion );
|
||||
static void importSingleEnsemble( const QStringList& fileNames );
|
||||
};
|
||||
|
@ -76,6 +76,18 @@ void RicImportEnsembleSurfaceFeature::importEnsembleSurfaceFromFiles( const QStr
|
||||
{
|
||||
if ( fileNames.isEmpty() ) return;
|
||||
|
||||
std::vector<QStringList> groupedByEnsemble = RiaEnsembleNameTools::groupFilesByEnsemble( fileNames );
|
||||
for ( const QStringList& groupedFileNames : groupedByEnsemble )
|
||||
{
|
||||
importSingleEnsembleSurfaceFromFiles( groupedFileNames );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicImportEnsembleSurfaceFeature::importSingleEnsembleSurfaceFromFiles( const QStringList& fileNames )
|
||||
{
|
||||
// Create a list of file names for each layer
|
||||
std::map<QString, QStringList> fileNamesForEachLayer;
|
||||
for ( const auto& name : fileNames )
|
||||
@ -104,7 +116,7 @@ void RicImportEnsembleSurfaceFeature::importEnsembleSurfaceFromFiles( const QStr
|
||||
RiaFilePathTools::keyPathComponentsForEachFilePath( fileNames );
|
||||
|
||||
std::vector<RimFileSurface*> surfaces;
|
||||
for ( size_t i = 0; i < fileNames.size(); i++ )
|
||||
for ( int i = 0; i < fileNames.size(); i++ )
|
||||
{
|
||||
surfaces.push_back( new RimFileSurface );
|
||||
}
|
||||
|
@ -42,6 +42,8 @@ protected:
|
||||
|
||||
QStringList runRecursiveFileSearchDialog( const QString& dialogTitle, const QString& pathCacheName );
|
||||
|
||||
static void importSingleEnsembleSurfaceFromFiles( const QStringList& fileNames );
|
||||
|
||||
private:
|
||||
QString m_pathFilter;
|
||||
QString m_fileNameFilter;
|
||||
|
@ -69,7 +69,25 @@ void RicImportEnsembleWellLogsFeature::onActionTriggered( bool isChecked )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimEnsembleWellLogs* RicImportEnsembleWellLogsFeature::createEnsembleWellLogsFromFiles( const QStringList& fileNames )
|
||||
std::vector<RimEnsembleWellLogs*>
|
||||
RicImportEnsembleWellLogsFeature::createEnsembleWellLogsFromFiles( const QStringList& fileNames )
|
||||
{
|
||||
std::vector<RimEnsembleWellLogs*> ensembleWellLogs;
|
||||
|
||||
std::vector<QStringList> groupedByEnsemble = RiaEnsembleNameTools::groupFilesByEnsemble( fileNames );
|
||||
for ( const QStringList& groupedFileNames : groupedByEnsemble )
|
||||
{
|
||||
auto ensembleWellLog = createSingleEnsembleWellLogsFromFiles( groupedFileNames );
|
||||
ensembleWellLogs.push_back( ensembleWellLog );
|
||||
}
|
||||
|
||||
return ensembleWellLogs;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimEnsembleWellLogs* RicImportEnsembleWellLogsFeature::createSingleEnsembleWellLogsFromFiles( const QStringList& fileNames )
|
||||
{
|
||||
if ( fileNames.isEmpty() ) return nullptr;
|
||||
|
||||
|
@ -33,7 +33,9 @@ class RicImportEnsembleWellLogsFeature : public caf::CmdFeature
|
||||
|
||||
RicImportEnsembleWellLogsFeature();
|
||||
|
||||
static RimEnsembleWellLogs* createEnsembleWellLogsFromFiles( const QStringList& fileNames );
|
||||
static RimEnsembleWellLogs* createSingleEnsembleWellLogsFromFiles( const QStringList& fileNames );
|
||||
|
||||
static std::vector<RimEnsembleWellLogs*> createEnsembleWellLogsFromFiles( const QStringList& fileNames );
|
||||
|
||||
protected:
|
||||
// Overrides
|
||||
|
Loading…
Reference in New Issue
Block a user