mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#6367 Improve the way we automatically name ensembles and cases
This commit is contained in:
@@ -19,7 +19,9 @@
|
||||
#include "RicImportEnsembleFeature.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaFilePathTools.h"
|
||||
#include "RiaPreferences.h"
|
||||
#include "RiaTextStringTools.h"
|
||||
|
||||
#include "RicCreateSummaryCaseCollectionFeature.h"
|
||||
#include "RicImportSummaryCasesFeature.h"
|
||||
@@ -44,8 +46,13 @@
|
||||
#include "SummaryPlotCommands/RicNewSummaryPlotFeature.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QDebug>
|
||||
#include <QFileInfo>
|
||||
#include <QInputDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include <set>
|
||||
|
||||
CAF_CMD_SOURCE_INIT( RicImportEnsembleFeature, "RicImportEnsembleFeature" );
|
||||
|
||||
@@ -69,7 +76,14 @@ void RicImportEnsembleFeature::onActionTriggered( bool isChecked )
|
||||
|
||||
if ( fileNames.isEmpty() ) return;
|
||||
|
||||
QString ensembleName = askForEnsembleName();
|
||||
QString root = commonRoot( fileNames );
|
||||
|
||||
QRegularExpression trimRe( "[^a-zA-Z0-9]+$" );
|
||||
QString trimmedRoot = root.replace( trimRe, "" );
|
||||
QString suggestion = trimmedRoot;
|
||||
if ( suggestion.isEmpty() ) suggestion = "Ensemble";
|
||||
|
||||
QString ensembleName = askForEnsembleName( trimmedRoot );
|
||||
if ( ensembleName.isEmpty() ) return;
|
||||
|
||||
std::vector<RimSummaryCase*> cases;
|
||||
@@ -79,6 +93,11 @@ void RicImportEnsembleFeature::onActionTriggered( bool isChecked )
|
||||
RimSummaryCaseCollection* ensemble =
|
||||
RicCreateSummaryCaseCollectionFeature::groupSummaryCases( cases, ensembleName, true );
|
||||
|
||||
for ( auto summaryCase : ensemble->allSummaryCases() )
|
||||
{
|
||||
summaryCase->updateAutoShortName();
|
||||
}
|
||||
|
||||
if ( ensemble )
|
||||
{
|
||||
RicNewSummaryEnsembleCurveSetFeature::createPlotForCurveSetsAndUpdate( {ensemble} );
|
||||
@@ -105,21 +124,45 @@ void RicImportEnsembleFeature::setupActionLook( QAction* actionToSetup )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RicImportEnsembleFeature::askForEnsembleName()
|
||||
QString RicImportEnsembleFeature::askForEnsembleName( const QString& suggestion )
|
||||
{
|
||||
RimProject* project = RimProject::current();
|
||||
std::vector<RimSummaryCaseCollection*> groups = project->summaryGroups();
|
||||
int ensembleCount = std::count_if( groups.begin(), groups.end(), []( RimSummaryCaseCollection* group ) {
|
||||
return group->isEnsemble();
|
||||
} );
|
||||
ensembleCount += 1;
|
||||
int ensemblesStartingWithRoot =
|
||||
std::count_if( groups.begin(), groups.end(), [suggestion]( RimSummaryCaseCollection* group ) {
|
||||
return group->isEnsemble() && group->name().startsWith( suggestion );
|
||||
} );
|
||||
|
||||
QInputDialog dialog;
|
||||
dialog.setInputMode( QInputDialog::TextInput );
|
||||
dialog.setWindowTitle( "Ensemble Name" );
|
||||
dialog.setLabelText( "Ensemble Name" );
|
||||
dialog.setTextValue( QString( "Ensemble %1" ).arg( ensembleCount ) );
|
||||
if ( ensemblesStartingWithRoot > 0 )
|
||||
{
|
||||
dialog.setTextValue( QString( "%1 %2" ).arg( suggestion ).arg( ensemblesStartingWithRoot + 1 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
dialog.setTextValue( suggestion );
|
||||
}
|
||||
|
||||
dialog.resize( 300, 50 );
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user