mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-25 14:40:26 -05:00
#12177 Summary Ensemble: Improve automatic naming
This commit is contained in:
1 parent
d05de77748
commit
edeb0cdbe2
32 files changed
+761
-201
No files matched your search
@@ -21,6 +21,7 @@
|
||||
#include "RiaFilePathTools.h"
|
||||
#include "RiaTextStringTools.h"
|
||||
#include "Summary/RiaSummaryDefines.h"
|
||||
#include "Tools/RiaStdStringTools.h"
|
||||
|
||||
#include "RimCaseDisplayNameTools.h"
|
||||
#include "RimProject.h"
|
||||
@@ -32,21 +33,114 @@
|
||||
#include <QFileInfo>
|
||||
#include <QRegularExpression>
|
||||
|
||||
template <>
|
||||
void caf::AppEnum<RiaEnsembleNameTools::EnsembleGroupingMode>::setUp()
|
||||
#include <regex>
|
||||
|
||||
namespace internal
|
||||
{
|
||||
addItem( RiaEnsembleNameTools::EnsembleGroupingMode::FMU_FOLDER_STRUCTURE, "FMU_FOLDER_MODE", "Sub Folder" );
|
||||
addItem( RiaEnsembleNameTools::EnsembleGroupingMode::EVEREST_FOLDER_STRUCTURE, "EVEREST_FOLDER_MODE", "Main Folder" );
|
||||
addItem( RiaEnsembleNameTools::EnsembleGroupingMode::NONE, "None", "None" );
|
||||
setDefault( RiaEnsembleNameTools::EnsembleGroupingMode::FMU_FOLDER_STRUCTURE );
|
||||
|
||||
// Find the last common folder in the common prefix of paths
|
||||
std::string findLastCommonFolder( const std::vector<std::string>& paths )
|
||||
{
|
||||
if ( paths.empty() )
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
auto commonPrefix = RiaStdStringTools::findCommonPrefix( paths );
|
||||
if ( commonPrefix.empty() )
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
// Handle the case where common prefix doesn't end at a folder boundary
|
||||
// Find the last slash in the common prefix
|
||||
size_t lastSlashPos = commonPrefix.find_last_of( '/' );
|
||||
if ( lastSlashPos == std::string::npos )
|
||||
{
|
||||
// No folder structure in the common prefix
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string commonPath = commonPrefix.substr( 0, lastSlashPos );
|
||||
std::vector<std::string> folders = RiaStdStringTools::splitString( commonPath, '/' );
|
||||
return folders.empty() ? "" : folders.back();
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::map<std::pair<std::string, std::string>, std::vector<std::string>>
|
||||
RiaEnsembleNameTools::groupFilePathsFmu( const std::vector<std::string>& filepaths )
|
||||
{
|
||||
std::map<std::pair<std::string, std::string>, std::vector<std::string>> groupedPaths;
|
||||
|
||||
// Example path
|
||||
// "f:/Models/scratch/project_a/realization-0/iter-0/eclipse/model/PROJECT-0.SMSPEC"
|
||||
//
|
||||
// Regex pattern to extract case name and iteration folder
|
||||
// Group 1: Case folder name (top level folder)
|
||||
// Group 2: Iteration folder name
|
||||
std::regex pattern( R"(.*[\\/]+([^\\/]+)[\\/]+realization-\d+[\\/]+([^\\/]+).*)", std::regex::icase );
|
||||
|
||||
for ( const std::string& filepath : filepaths )
|
||||
{
|
||||
std::smatch matches;
|
||||
if ( std::regex_match( filepath, matches, pattern ) )
|
||||
{
|
||||
auto key = std::make_pair( matches[1].str(), matches[2].str() );
|
||||
groupedPaths[key].push_back( filepath );
|
||||
}
|
||||
}
|
||||
|
||||
return groupedPaths;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaEnsembleNameTools::findSuitableEnsembleName( const QStringList& fileNames, EnsembleGroupingMode folderLevel )
|
||||
std::map<std::pair<std::string, std::string>, std::vector<std::string>>
|
||||
RiaEnsembleNameTools::groupFilePathsEverest( const std::vector<std::string>& filepaths )
|
||||
{
|
||||
if ( folderLevel == EnsembleGroupingMode::EVEREST_FOLDER_STRUCTURE )
|
||||
std::map<std::pair<std::string, std::string>, std::vector<std::string>> groupedPaths;
|
||||
|
||||
std::vector<std::string> normalizedPaths;
|
||||
for ( const auto& filepath : filepaths )
|
||||
{
|
||||
normalizedPaths.push_back( RiaFilePathTools::normalizePath( filepath ) );
|
||||
}
|
||||
|
||||
auto commonPrefix = RiaStdStringTools::findCommonPrefix( normalizedPaths );
|
||||
|
||||
// strip partial folder name in prefix
|
||||
auto lastSlashPos = commonPrefix.find_last_of( '/' );
|
||||
if ( lastSlashPos != std::string::npos )
|
||||
{
|
||||
commonPrefix = commonPrefix.substr( 0, lastSlashPos );
|
||||
}
|
||||
|
||||
auto commonFolder = internal::findLastCommonFolder( normalizedPaths );
|
||||
|
||||
for ( const auto& filepath : normalizedPaths )
|
||||
{
|
||||
auto rest = filepath.substr( commonPrefix.size() );
|
||||
auto parts = RiaStdStringTools::splitString( rest, '/' );
|
||||
|
||||
std::string firstFolder = parts.empty() ? "" : parts.front();
|
||||
|
||||
groupedPaths[{ commonFolder, firstFolder }].push_back( filepath );
|
||||
}
|
||||
|
||||
return groupedPaths;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaEnsembleNameTools::findSuitableEnsembleName( const QStringList& fileNames, RiaDefines::EnsembleGroupingMode folderLevel )
|
||||
{
|
||||
if ( folderLevel == RiaDefines::EnsembleGroupingMode::EVEREST_FOLDER_STRUCTURE )
|
||||
{
|
||||
QString commonRoot = RiaTextStringTools::commonRoot( fileNames );
|
||||
commonRoot = commonRoot.left( commonRoot.lastIndexOf( '/' ) );
|
||||
@@ -92,7 +186,7 @@ QString RiaEnsembleNameTools::findSuitableEnsembleName( const QStringList& fileN
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<QStringList> RiaEnsembleNameTools::groupFilesByEnsemble( const QStringList& fileNames, EnsembleGroupingMode groupingMode )
|
||||
std::vector<QStringList> RiaEnsembleNameTools::groupFilesByEnsemble( const QStringList& fileNames, RiaDefines::EnsembleGroupingMode groupingMode )
|
||||
{
|
||||
std::vector<QStringList> componentsForAllFilePaths;
|
||||
|
||||
@@ -176,6 +270,79 @@ std::map<QString, QStringList> RiaEnsembleNameTools::groupFilesByCustomEnsemble(
|
||||
return groupedByIteration;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::map<QString, QStringList> RiaEnsembleNameTools::groupFilesByEnsembleName( const QStringList& fileNames,
|
||||
RiaDefines::EnsembleGroupingMode groupingMode )
|
||||
{
|
||||
std::map<QString, QStringList> ensemblePaths;
|
||||
|
||||
if ( groupingMode == RiaDefines::EnsembleGroupingMode::FMU_FOLDER_STRUCTURE )
|
||||
{
|
||||
std::vector<std::string> allPaths;
|
||||
for ( const auto& fileName : fileNames )
|
||||
{
|
||||
allPaths.push_back( fileName.toStdString() );
|
||||
}
|
||||
|
||||
auto groupedPaths = RiaEnsembleNameTools::groupFilePathsFmu( allPaths );
|
||||
|
||||
auto shouldIncludeTopLevel = []( const auto& paths ) -> bool
|
||||
{
|
||||
std::set<std::string> topLevelFolderNames;
|
||||
for ( auto group : paths )
|
||||
{
|
||||
topLevelFolderNames.insert( group.first.first );
|
||||
}
|
||||
|
||||
return topLevelFolderNames.size() > 1;
|
||||
};
|
||||
|
||||
bool includeTopLevel = shouldIncludeTopLevel( groupedPaths );
|
||||
|
||||
for ( auto group : groupedPaths )
|
||||
{
|
||||
std::string ensembleName;
|
||||
if ( includeTopLevel )
|
||||
{
|
||||
ensembleName += group.first.first;
|
||||
ensembleName += ", ";
|
||||
}
|
||||
ensembleName += group.first.second;
|
||||
|
||||
QStringList groupPaths;
|
||||
for ( const auto& path : group.second )
|
||||
{
|
||||
groupPaths.push_back( QString::fromStdString( path ) );
|
||||
}
|
||||
|
||||
ensemblePaths[QString::fromStdString( ensembleName )] = groupPaths;
|
||||
}
|
||||
}
|
||||
else if ( groupingMode == RiaDefines::EnsembleGroupingMode::EVEREST_FOLDER_STRUCTURE )
|
||||
{
|
||||
std::vector<std::string> allPaths;
|
||||
for ( const auto& fileName : fileNames )
|
||||
{
|
||||
allPaths.push_back( fileName.toStdString() );
|
||||
}
|
||||
auto groupedPaths = RiaEnsembleNameTools::groupFilePathsEverest( allPaths );
|
||||
for ( auto group : groupedPaths )
|
||||
{
|
||||
std::string ensembleName = group.first.first + ", " + group.first.second;
|
||||
QStringList groupPaths;
|
||||
for ( const auto& path : group.second )
|
||||
{
|
||||
groupPaths.push_back( QString::fromStdString( path ) );
|
||||
}
|
||||
ensemblePaths[QString::fromStdString( ensembleName )] = groupPaths;
|
||||
}
|
||||
}
|
||||
|
||||
return ensemblePaths;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -233,6 +400,37 @@ std::map<QString, std::pair<QString, QString>>
|
||||
return mapping;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaEnsembleNameTools::updateAutoNameEnsembles( std::vector<RimSummaryEnsemble*> ensembles )
|
||||
{
|
||||
std::set<std::string> key1;
|
||||
std::set<std::string> key2;
|
||||
|
||||
for ( const auto& ensemble : ensembles )
|
||||
{
|
||||
const auto keys = ensemble->nameKeys();
|
||||
key1.insert( keys.first );
|
||||
key2.insert( keys.second );
|
||||
}
|
||||
|
||||
bool useKey1 = key1.size() > 1;
|
||||
bool useKey2 = key2.size() > 1;
|
||||
|
||||
if ( !useKey1 && !useKey2 )
|
||||
{
|
||||
useKey2 = true;
|
||||
}
|
||||
|
||||
for ( auto ensemble : ensembles )
|
||||
{
|
||||
ensemble->setUsePathKey1( useKey1 );
|
||||
ensemble->setUsePathKey2( useKey2 );
|
||||
ensemble->ensureNameIsUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -283,12 +481,12 @@ QString RiaEnsembleNameTools::uniqueShortNameForSummaryCase( RimSummaryCase* sum
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QStringList RiaEnsembleNameTools::findUniqueEnsembleNames( const QStringList& fileNames,
|
||||
const std::vector<QStringList>& fileNameComponents,
|
||||
EnsembleGroupingMode groupingMode )
|
||||
QStringList RiaEnsembleNameTools::findUniqueEnsembleNames( const QStringList& fileNames,
|
||||
const std::vector<QStringList>& fileNameComponents,
|
||||
RiaDefines::EnsembleGroupingMode groupingMode )
|
||||
{
|
||||
QStringList iterations;
|
||||
if ( groupingMode == EnsembleGroupingMode::EVEREST_FOLDER_STRUCTURE )
|
||||
if ( groupingMode == RiaDefines::EnsembleGroupingMode::EVEREST_FOLDER_STRUCTURE )
|
||||
{
|
||||
QString commonRoot = RiaTextStringTools::commonRoot( fileNames );
|
||||
QStringList rootComponents = RiaFilePathTools::splitPathIntoComponents( commonRoot );
|
||||
@@ -319,7 +517,7 @@ QStringList RiaEnsembleNameTools::findUniqueEnsembleNames( const QStringList&
|
||||
iterations.push_back( ensembleName );
|
||||
}
|
||||
}
|
||||
else if ( groupingMode == EnsembleGroupingMode::FMU_FOLDER_STRUCTURE )
|
||||
else if ( groupingMode == RiaDefines::EnsembleGroupingMode::FMU_FOLDER_STRUCTURE )
|
||||
{
|
||||
// Find list of all folders inside a folder matching realization-*
|
||||
QRegularExpression realizationRe( "realization\\-\\d+" );
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "Summary/RiaSummaryDefines.h"
|
||||
|
||||
class RimSummaryCase;
|
||||
class RimSummaryEnsemble;
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
@@ -33,15 +34,7 @@ class RimSummaryCase;
|
||||
class RiaEnsembleNameTools
|
||||
{
|
||||
public:
|
||||
enum class EnsembleGroupingMode
|
||||
{
|
||||
FMU_FOLDER_STRUCTURE,
|
||||
EVEREST_FOLDER_STRUCTURE,
|
||||
NONE
|
||||
};
|
||||
|
||||
public:
|
||||
static QString findSuitableEnsembleName( const QStringList& fileNames, EnsembleGroupingMode groupingMode );
|
||||
static QString findSuitableEnsembleName( const QStringList& fileNames, RiaDefines::EnsembleGroupingMode groupingMode );
|
||||
static QString findCommonBaseName( const QStringList& fileNames );
|
||||
|
||||
static QString
|
||||
@@ -51,18 +44,28 @@ public:
|
||||
const std::map<QString, QStringList>& keyFileComponentsForAllFiles,
|
||||
const QString& ensembleCaseName );
|
||||
|
||||
static std::vector<QStringList> groupFilesByEnsemble( const QStringList& fileNames, EnsembleGroupingMode groupingMode );
|
||||
static std::map<std::pair<std::string, std::string>, std::vector<std::string>>
|
||||
groupFilePathsFmu( const std::vector<std::string>& filepaths );
|
||||
|
||||
static std::map<std::pair<std::string, std::string>, std::vector<std::string>>
|
||||
groupFilePathsEverest( const std::vector<std::string>& filepaths );
|
||||
|
||||
static std::vector<QStringList> groupFilesByEnsemble( const QStringList& fileNames, RiaDefines::EnsembleGroupingMode groupingMode );
|
||||
static std::map<QString, QStringList> groupFilesByEnsembleName( const QStringList& fileNames,
|
||||
RiaDefines::EnsembleGroupingMode groupingMode );
|
||||
static std::map<QString, QStringList> groupFilesByCustomEnsemble( const QStringList& fileNames, RiaDefines::FileType fileType );
|
||||
|
||||
static std::map<QString, std::pair<QString, QString>> findUniqueCustomEnsembleNames( RiaDefines::FileType fileType,
|
||||
const QStringList& fileNames,
|
||||
const std::vector<QStringList>& fileNameComponents );
|
||||
|
||||
static void updateAutoNameEnsembles( std::vector<RimSummaryEnsemble*> ensembles );
|
||||
|
||||
static QString uniqueShortNameForEnsembleCase( RimSummaryCase* summaryCase );
|
||||
static QString uniqueShortNameForSummaryCase( RimSummaryCase* summaryCase );
|
||||
|
||||
private:
|
||||
static QStringList findUniqueEnsembleNames( const QStringList& fileNames,
|
||||
const std::vector<QStringList>& fileNameComponents,
|
||||
EnsembleGroupingMode groupingMode );
|
||||
static QStringList findUniqueEnsembleNames( const QStringList& fileNames,
|
||||
const std::vector<QStringList>& fileNameComponents,
|
||||
RiaDefines::EnsembleGroupingMode groupingMode );
|
||||
};
|
||||
@@ -29,10 +29,13 @@
|
||||
#include <memory>
|
||||
#include <set>
|
||||
|
||||
namespace RiaFilePathTools
|
||||
{
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const QChar RiaFilePathTools::separator()
|
||||
const QChar separator()
|
||||
{
|
||||
return '/';
|
||||
}
|
||||
@@ -40,7 +43,7 @@ const QChar RiaFilePathTools::separator()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaFilePathTools::toInternalSeparator( const QString& path )
|
||||
QString toInternalSeparator( const QString& path )
|
||||
{
|
||||
QString currNativeSep = QDir::separator();
|
||||
|
||||
@@ -58,7 +61,16 @@ QString RiaFilePathTools::toInternalSeparator( const QString& path )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString& RiaFilePathTools::appendSeparatorIfNo( QString& path )
|
||||
std::string normalizePath( std::string path )
|
||||
{
|
||||
std::replace( path.begin(), path.end(), '\\', '/' );
|
||||
return path;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString& appendSeparatorIfNo( QString& path )
|
||||
{
|
||||
if ( !path.endsWith( separator() ) )
|
||||
{
|
||||
@@ -70,7 +82,7 @@ QString& RiaFilePathTools::appendSeparatorIfNo( QString& path )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaFilePathTools::relativePath( const QString& rootDir, const QString& dir )
|
||||
QString relativePath( const QString& rootDir, const QString& dir )
|
||||
{
|
||||
if ( dir.startsWith( rootDir ) )
|
||||
{
|
||||
@@ -89,7 +101,7 @@ QString RiaFilePathTools::relativePath( const QString& rootDir, const QString& d
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaFilePathTools::equalPaths( const QString& path1, const QString& path2 )
|
||||
bool equalPaths( const QString& path1, const QString& path2 )
|
||||
{
|
||||
QString p1 = path1;
|
||||
QString p2 = path2;
|
||||
@@ -101,7 +113,7 @@ bool RiaFilePathTools::equalPaths( const QString& path1, const QString& path2 )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Own canonicalPath method since the QDir::canonicalPath seems to not work
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaFilePathTools::canonicalPath( const QString& path )
|
||||
QString canonicalPath( const QString& path )
|
||||
{
|
||||
return QDir( path ).absolutePath();
|
||||
}
|
||||
@@ -109,7 +121,7 @@ QString RiaFilePathTools::canonicalPath( const QString& path )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::pair<QString, QString> RiaFilePathTools::toFolderAndFileName( const QString& absFileName )
|
||||
std::pair<QString, QString> toFolderAndFileName( const QString& absFileName )
|
||||
{
|
||||
auto absFN = toInternalSeparator( absFileName );
|
||||
int lastSep = absFN.lastIndexOf( separator() );
|
||||
@@ -126,7 +138,7 @@ std::pair<QString, QString> RiaFilePathTools::toFolderAndFileName( const QString
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaFilePathTools::removeDuplicatePathSeparators( const QString& path )
|
||||
QString removeDuplicatePathSeparators( const QString& path )
|
||||
{
|
||||
QString correctedPath = path;
|
||||
QString prefix;
|
||||
@@ -154,7 +166,7 @@ QString RiaFilePathTools::removeDuplicatePathSeparators( const QString& path )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaFilePathTools::rootSearchPathFromSearchFilter( const QString& searchFilter )
|
||||
QString rootSearchPathFromSearchFilter( const QString& searchFilter )
|
||||
{
|
||||
QStringList pathPartList = searchFilter.split( separator() );
|
||||
|
||||
@@ -184,7 +196,7 @@ QString RiaFilePathTools::rootSearchPathFromSearchFilter( const QString& searchF
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaFilePathTools::commonRootOfFileNames( const QStringList& fileList )
|
||||
QString commonRootOfFileNames( const QStringList& fileList )
|
||||
{
|
||||
QStringList fileNameList;
|
||||
for ( auto filePath : fileList )
|
||||
@@ -200,7 +212,7 @@ QString RiaFilePathTools::commonRootOfFileNames( const QStringList& fileList )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QStringList RiaFilePathTools::splitPathIntoComponents( const QString& inputPath, bool splitExtensionIntoSeparateEntry )
|
||||
QStringList splitPathIntoComponents( const QString& inputPath, bool splitExtensionIntoSeparateEntry )
|
||||
{
|
||||
auto path = QDir::cleanPath( inputPath );
|
||||
|
||||
@@ -325,7 +337,7 @@ void pathToNode( PathNode* node, QStringList* path )
|
||||
/// Takes a list of file paths and returns a map with the key components that separate the path
|
||||
/// from the others.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::map<QString, QStringList> RiaFilePathTools::keyPathComponentsForEachFilePath( const QStringList& filePaths )
|
||||
std::map<QString, QStringList> keyPathComponentsForEachFilePath( const QStringList& filePaths )
|
||||
{
|
||||
std::map<QString, QStringList> allComponents;
|
||||
|
||||
@@ -360,7 +372,7 @@ std::map<QString, QStringList> RiaFilePathTools::keyPathComponentsForEachFilePat
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaFilePathTools::isFirstOlderThanSecond( const std::string& firstFileName, const std::string& secondFileName )
|
||||
bool isFirstOlderThanSecond( const std::string& firstFileName, const std::string& secondFileName )
|
||||
{
|
||||
if ( !std::filesystem::exists( firstFileName ) || !std::filesystem::exists( secondFileName ) ) return false;
|
||||
|
||||
@@ -373,7 +385,7 @@ bool RiaFilePathTools::isFirstOlderThanSecond( const std::string& firstFileName,
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::string RiaFilePathTools::makeSuitableAsFileName( const std::string candidateName )
|
||||
std::string makeSuitableAsFileName( const std::string candidateName )
|
||||
{
|
||||
if ( candidateName.empty() ) return "noname";
|
||||
|
||||
@@ -388,3 +400,5 @@ std::string RiaFilePathTools::makeSuitableAsFileName( const std::string candidat
|
||||
|
||||
return tmp.toStdString();
|
||||
}
|
||||
|
||||
} // namespace RiaFilePathTools
|
||||
@@ -28,27 +28,25 @@
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RiaFilePathTools
|
||||
namespace RiaFilePathTools
|
||||
{
|
||||
public:
|
||||
static const QChar separator();
|
||||
static QString toInternalSeparator( const QString& path );
|
||||
static QString& appendSeparatorIfNo( QString& path );
|
||||
static QString relativePath( const QString& rootDir, const QString& dir );
|
||||
static bool equalPaths( const QString& path1, const QString& path2 );
|
||||
static QString canonicalPath( const QString& path );
|
||||
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 std::string makeSuitableAsFileName( const std::string candidateName );
|
||||
const QChar separator();
|
||||
QString toInternalSeparator( const QString& path );
|
||||
QString& appendSeparatorIfNo( QString& path );
|
||||
QString relativePath( const QString& rootDir, const QString& dir );
|
||||
bool equalPaths( const QString& path1, const QString& path2 );
|
||||
QString canonicalPath( const QString& path );
|
||||
std::pair<QString, QString> toFolderAndFileName( const QString& absFileName );
|
||||
QString removeDuplicatePathSeparators( const QString& path );
|
||||
QString rootSearchPathFromSearchFilter( const QString& searchFilter );
|
||||
QString commonRootOfFileNames( const QStringList& filePaths );
|
||||
std::string makeSuitableAsFileName( const std::string candidateName );
|
||||
std::string normalizePath( std::string path );
|
||||
|
||||
static QStringList splitPathIntoComponents( const QString& path, bool splitExtensionIntoSeparateEntry = false );
|
||||
QStringList splitPathIntoComponents( const QString& path, bool splitExtensionIntoSeparateEntry = false );
|
||||
|
||||
static std::map<QString, QStringList> keyPathComponentsForEachFilePath( const QStringList& filePaths );
|
||||
std::map<QString, QStringList> keyPathComponentsForEachFilePath( const QStringList& filePaths );
|
||||
|
||||
static bool isFirstOlderThanSecond( const std::string& firstFileName, const std::string& secondFileName );
|
||||
};
|
||||
bool isFirstOlderThanSecond( const std::string& firstFileName, const std::string& secondFileName );
|
||||
}; // namespace RiaFilePathTools
|
||||
@@ -465,3 +465,45 @@ std::string RiaStdStringTools::formatRangeSelection( const std::vector<int>& val
|
||||
|
||||
return result.str();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::string RiaStdStringTools::findCommonPrefix( const std::vector<std::string>& strings )
|
||||
{
|
||||
if ( strings.empty() )
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
if ( strings.size() == 1 )
|
||||
{
|
||||
return strings[0];
|
||||
}
|
||||
|
||||
// Find the shortest string length as a starting point
|
||||
// We only need to check up to the length of the shortest string
|
||||
size_t minLength = strings[0].length();
|
||||
for ( const auto& str : strings )
|
||||
{
|
||||
minLength = std::min( minLength, str.length() );
|
||||
}
|
||||
|
||||
// Compare characters from left to right
|
||||
for ( size_t i = 0; i < minLength; ++i )
|
||||
{
|
||||
char current = strings[0][i];
|
||||
|
||||
for ( size_t j = 1; j < strings.size(); ++j )
|
||||
{
|
||||
if ( strings[j][i] != current )
|
||||
{
|
||||
// Found a mismatch, return the prefix up to this point
|
||||
return strings[0].substr( 0, i );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we got here, all characters matched up to minLength
|
||||
return strings[0].substr( 0, minLength );
|
||||
}
|
||||
@@ -70,6 +70,8 @@ public:
|
||||
// Create a string from a set of values. {1, 2, 3, 5, 6, 7, 8, 10, 11, 12} will be converted to "1, 2, 3, 5-8, 10-12"
|
||||
static std::string formatRangeSelection( const std::vector<int>& values );
|
||||
|
||||
static std::string findCommonPrefix( const std::vector<std::string>& strings );
|
||||
|
||||
private:
|
||||
template <class Container>
|
||||
static void splitByDelimiter( const std::string& str, Container& cont, char delimiter = ' ' );
|
||||
|
||||
@@ -38,6 +38,15 @@ void caf::AppEnum<RiaDefines::SummaryCurveTypeMode>::setUp()
|
||||
setDefault( RiaDefines::SummaryCurveTypeMode::AUTO );
|
||||
}
|
||||
|
||||
template <>
|
||||
void caf::AppEnum<RiaDefines::EnsembleGroupingMode>::setUp()
|
||||
{
|
||||
addItem( RiaDefines::EnsembleGroupingMode::FMU_FOLDER_STRUCTURE, "FMU_FOLDER_MODE", "Sub Folder" );
|
||||
addItem( RiaDefines::EnsembleGroupingMode::EVEREST_FOLDER_STRUCTURE, "EVEREST_FOLDER_MODE", "Main Folder" );
|
||||
addItem( RiaDefines::EnsembleGroupingMode::NONE, "None", "None" );
|
||||
setDefault( RiaDefines::EnsembleGroupingMode::FMU_FOLDER_STRUCTURE );
|
||||
}
|
||||
|
||||
} // namespace caf
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -183,3 +192,19 @@ QString RiaDefines::summaryRealizationNumber()
|
||||
{
|
||||
return "RI:REALIZATION_NUM";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::key1VariableName()
|
||||
{
|
||||
return "$KEY1";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaDefines::key2VariableName()
|
||||
{
|
||||
return "$KEY2";
|
||||
}
|
||||
@@ -29,6 +29,13 @@ enum class FileType
|
||||
STIMPLAN_SUMMARY
|
||||
};
|
||||
|
||||
enum class EnsembleGroupingMode
|
||||
{
|
||||
FMU_FOLDER_STRUCTURE,
|
||||
EVEREST_FOLDER_STRUCTURE,
|
||||
NONE
|
||||
};
|
||||
|
||||
enum class HorizontalAxisType
|
||||
{
|
||||
TIME,
|
||||
@@ -61,4 +68,7 @@ QString summaryCalculated();
|
||||
|
||||
QString summaryRealizationNumber();
|
||||
|
||||
QString key1VariableName();
|
||||
QString key2VariableName();
|
||||
|
||||
}; // namespace RiaDefines
|
||||
Reference in new issue
Block a user