mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Changing Ensemble naming suggestion to be the iteration
This commit is contained in:
parent
e6dcb8257d
commit
f6613a072d
@ -19,6 +19,7 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RiaFilePathTools.h"
|
||||
#include "RiaTextStringTools.h"
|
||||
|
||||
#include "cafAssert.h"
|
||||
|
||||
@ -178,6 +179,22 @@ QString RiaFilePathTools::rootSearchPathFromSearchFilter( const QString& searchF
|
||||
return pathPartList.join( separator() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaFilePathTools::commonRootOfFileNames( const QStringList& fileList )
|
||||
{
|
||||
QStringList fileNameList;
|
||||
for ( auto filePath : fileList )
|
||||
{
|
||||
QFileInfo fileInfo( filePath );
|
||||
QString fileNameWithoutExt = fileInfo.baseName();
|
||||
fileNameList.push_back( fileNameWithoutExt );
|
||||
}
|
||||
QString root = RiaTextStringTools::findCommonRoot( fileNameList );
|
||||
return root;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -43,6 +43,7 @@ public:
|
||||
static std::pair<QString, QString> toFolderAndFileName( const QString& absFileName );
|
||||
static QString removeDuplicatePathSeparators( const QString& path );
|
||||
static QString rootSearchPathFromSearchFilter( const QString& searchFilter );
|
||||
static QString commonRootOfFileNames( const QStringList& filePaths );
|
||||
|
||||
static QStringList splitPathIntoComponents( const QString& path, bool splitExtensionIntoSeparateEntry = false );
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
#include "RiaSummaryTools.h"
|
||||
|
||||
#include "RiaFilePathTools.h"
|
||||
#include "RifEclipseSummaryAddress.h"
|
||||
|
||||
#include "RimMainPlotCollection.h"
|
||||
@ -36,6 +37,8 @@
|
||||
|
||||
#include "cafPdmObject.h"
|
||||
|
||||
#include <QRegularExpression>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -209,3 +212,56 @@ void RiaSummaryTools::getSummaryCasesAndAddressesForCalculation( int
|
||||
addresses.push_back( v->summaryAddress()->address() );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaSummaryTools::findSuitableEnsembleName( const QStringList& summaryCaseFileNames )
|
||||
{
|
||||
std::vector<QStringList> componentsForAllFilePaths;
|
||||
|
||||
for ( auto filePath : summaryCaseFileNames )
|
||||
{
|
||||
QStringList components = RiaFilePathTools::splitPathIntoComponents( filePath );
|
||||
componentsForAllFilePaths.push_back( components );
|
||||
}
|
||||
|
||||
// Find list of all folders inside a folder matching realization-*
|
||||
QRegularExpression realizationRe( "realization\\-\\d+" );
|
||||
|
||||
QStringList iterations;
|
||||
for ( const auto& fileComponents : componentsForAllFilePaths )
|
||||
{
|
||||
QString lastComponent = "";
|
||||
for ( auto it = fileComponents.rbegin(); it != fileComponents.rend(); ++it )
|
||||
{
|
||||
if ( realizationRe.match( *it ).hasMatch() )
|
||||
{
|
||||
iterations.push_back( lastComponent );
|
||||
}
|
||||
lastComponent = *it;
|
||||
}
|
||||
}
|
||||
|
||||
iterations.removeDuplicates();
|
||||
|
||||
if ( iterations.size() == 1u )
|
||||
{
|
||||
return iterations.front();
|
||||
}
|
||||
else if ( !iterations.empty() )
|
||||
{
|
||||
return QString( "Multiple iterations: %1" ).arg( iterations.join( ", " ) );
|
||||
}
|
||||
|
||||
QString root = RiaFilePathTools::commonRootOfFileNames( summaryCaseFileNames );
|
||||
|
||||
QRegularExpression trimRe( "[^a-zA-Z0-9]+$" );
|
||||
QString trimmedRoot = root.replace( trimRe, "" );
|
||||
if ( trimmedRoot.length() >= 4 )
|
||||
{
|
||||
return trimmedRoot;
|
||||
}
|
||||
|
||||
return "Ensemble";
|
||||
}
|
||||
|
@ -18,6 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include <vector>
|
||||
|
||||
class RimSummaryPlotCollection;
|
||||
@ -29,7 +31,7 @@ class RimSummaryCase;
|
||||
|
||||
class RifEclipseSummaryAddress;
|
||||
|
||||
class QString;
|
||||
class QStringList;
|
||||
|
||||
namespace caf
|
||||
{
|
||||
@ -59,4 +61,6 @@ public:
|
||||
static void getSummaryCasesAndAddressesForCalculation( int id,
|
||||
std::vector<RimSummaryCase*>& cases,
|
||||
std::vector<RifEclipseSummaryAddress>& addresses );
|
||||
|
||||
static QString findSuitableEnsembleName( const QStringList& summaryCaseFileNames );
|
||||
};
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaFilePathTools.h"
|
||||
#include "RiaPreferences.h"
|
||||
#include "RiaSummaryTools.h"
|
||||
#include "RiaTextStringTools.h"
|
||||
|
||||
#include "RicCreateSummaryCaseCollectionFeature.h"
|
||||
@ -76,14 +77,9 @@ void RicImportEnsembleFeature::onActionTriggered( bool isChecked )
|
||||
|
||||
if ( fileNames.isEmpty() ) return;
|
||||
|
||||
QString root = commonRoot( fileNames );
|
||||
QString ensembleNameSuggestion = RiaSummaryTools::findSuitableEnsembleName( fileNames );
|
||||
|
||||
QRegularExpression trimRe( "[^a-zA-Z0-9]+$" );
|
||||
QString trimmedRoot = root.replace( trimRe, "" );
|
||||
QString suggestion = trimmedRoot;
|
||||
if ( suggestion.isEmpty() ) suggestion = "Ensemble";
|
||||
|
||||
QString ensembleName = askForEnsembleName( trimmedRoot );
|
||||
QString ensembleName = askForEnsembleName( ensembleNameSuggestion );
|
||||
if ( ensembleName.isEmpty() ) return;
|
||||
|
||||
std::vector<RimSummaryCase*> cases;
|
||||
@ -150,19 +146,3 @@ QString RicImportEnsembleFeature::askForEnsembleName( const QString& suggestion
|
||||
dialog.exec();
|
||||
return dialog.result() == QDialog::Accepted ? dialog.textValue() : QString( "" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RicImportEnsembleFeature::commonRoot( const QStringList& fileList )
|
||||
{
|
||||
QStringList fileNameList;
|
||||
for ( auto filePath : fileList )
|
||||
{
|
||||
QFileInfo fileInfo( filePath );
|
||||
QString fileNameWithoutExt = fileInfo.baseName();
|
||||
fileNameList.push_back( fileNameWithoutExt );
|
||||
}
|
||||
QString root = RiaTextStringTools::findCommonRoot( fileNameList );
|
||||
return root;
|
||||
}
|
||||
|
@ -40,5 +40,4 @@ protected:
|
||||
void setupActionLook( QAction* actionToSetup ) override;
|
||||
|
||||
QString askForEnsembleName( const QString& suggestion );
|
||||
QString commonRoot( const QStringList& fileList );
|
||||
};
|
||||
|
@ -330,13 +330,13 @@ QString RimSummaryCase::uniqueShortNameForCase( RimSummaryCase* summaryCase )
|
||||
{
|
||||
keyComponent = keyComponent.replace( numberGroup, "" );
|
||||
|
||||
QString stem = keyComponent.left( 2 );
|
||||
QString stem = keyComponent.left( 4 );
|
||||
if ( !stem.isEmpty() ) subComponents.push_back( stem );
|
||||
subComponents.push_back( numberGroup );
|
||||
}
|
||||
else
|
||||
{
|
||||
subComponents.push_back( keyComponent.left( 4 ) );
|
||||
subComponents.push_back( keyComponent.left( 6 ) );
|
||||
}
|
||||
|
||||
shortNameComponents.push_back( subComponents.join( "-" ) );
|
||||
|
Loading…
Reference in New Issue
Block a user