2018-04-18 13:56:01 +02:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2016- Statoil ASA
|
2019-02-18 13:09:50 +01:00
|
|
|
//
|
2018-04-18 13:56:01 +02:00
|
|
|
// ResInsight is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
2019-02-18 13:09:50 +01:00
|
|
|
//
|
2018-04-18 13:56:01 +02:00
|
|
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
2019-02-18 13:09:50 +01:00
|
|
|
//
|
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2018-04-18 13:56:01 +02:00
|
|
|
// for more details.
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2018-04-19 14:00:00 +02:00
|
|
|
#include "RicImportEnsembleFeature.h"
|
2018-04-18 13:56:01 +02:00
|
|
|
|
2025-04-25 10:44:55 +02:00
|
|
|
#include "Ensemble/RiaEnsembleImportTools.h"
|
2018-04-18 13:56:01 +02:00
|
|
|
#include "RiaApplication.h"
|
2021-08-26 15:12:27 +02:00
|
|
|
#include "RiaEnsembleNameTools.h"
|
2024-10-21 14:40:25 +02:00
|
|
|
#include "Summary/RiaSummaryDefines.h"
|
2025-02-12 13:06:58 +01:00
|
|
|
#include "Summary/RiaSummaryPlotTools.h"
|
2024-10-21 14:40:25 +02:00
|
|
|
#include "Summary/RiaSummaryTools.h"
|
2018-04-18 13:56:01 +02:00
|
|
|
|
2019-02-18 13:09:50 +01:00
|
|
|
#include "RicImportSummaryCasesFeature.h"
|
2018-04-18 13:56:01 +02:00
|
|
|
|
2025-05-15 18:16:27 +02:00
|
|
|
#include "EnsembleFileSet/RimEnsembleFileSet.h"
|
|
|
|
|
#include "EnsembleFileSet/RimEnsembleFileSetCollection.h"
|
|
|
|
|
#include "EnsembleFileSet/RimEnsembleFileSetTools.h"
|
2018-04-18 13:56:01 +02:00
|
|
|
#include "RimProject.h"
|
|
|
|
|
#include "RimSummaryCase.h"
|
|
|
|
|
#include "RimSummaryCaseMainCollection.h"
|
2024-07-29 15:38:17 +02:00
|
|
|
#include "RimSummaryEnsemble.h"
|
2025-05-15 18:16:27 +02:00
|
|
|
#include "Summary/Ensemble/RimSummaryFileSetEnsemble.h"
|
2018-04-18 13:56:01 +02:00
|
|
|
|
|
|
|
|
#include "RiuMainWindow.h"
|
2025-03-17 15:07:58 +01:00
|
|
|
#include "RiuPlotMainWindowTools.h"
|
2018-04-18 13:56:01 +02:00
|
|
|
|
|
|
|
|
#include <QAction>
|
|
|
|
|
#include <QInputDialog>
|
|
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
CAF_CMD_SOURCE_INIT( RicImportEnsembleFeature, "RicImportEnsembleFeature" );
|
2018-04-18 13:56:01 +02:00
|
|
|
|
2025-03-17 15:07:58 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RimSummaryEnsemble* RicImportEnsembleFeature::createSummaryEnsemble( std::vector<RimSummaryCase*> cases )
|
|
|
|
|
{
|
|
|
|
|
if ( cases.empty() ) return nullptr;
|
|
|
|
|
|
|
|
|
|
RiaDefines::EnsembleGroupingMode groupingMode = RiaDefines::EnsembleGroupingMode::NONE;
|
|
|
|
|
QString name = "Ensemble";
|
|
|
|
|
if ( cases.front()->ensemble() )
|
|
|
|
|
{
|
|
|
|
|
groupingMode = cases.front()->ensemble()->groupingMode();
|
|
|
|
|
name = cases.front()->ensemble()->name();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList fileNames;
|
|
|
|
|
for ( auto summaryCase : cases )
|
|
|
|
|
{
|
|
|
|
|
fileNames.append( summaryCase->summaryHeaderFilename() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool useEnsembleNameDialog = false;
|
2025-05-15 18:16:27 +02:00
|
|
|
return importSingleEnsembleFileSet( fileNames, useEnsembleNameDialog, groupingMode, RiaDefines::FileType::SMSPEC, name );
|
2025-03-17 15:07:58 +01:00
|
|
|
}
|
|
|
|
|
|
2018-05-11 08:32:44 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-02-18 13:09:50 +01:00
|
|
|
///
|
2018-05-11 08:32:44 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
void RicImportEnsembleFeature::onActionTriggered( bool isChecked )
|
2018-05-11 08:32:44 +02:00
|
|
|
{
|
2021-09-21 22:27:36 +02:00
|
|
|
QString pathCacheName = "ENSEMBLE_FILES";
|
2026-05-28 16:06:39 +02:00
|
|
|
auto result =
|
|
|
|
|
RicImportSummaryCasesFeature::runRecursiveSummaryCaseFileSearchDialogWithGrouping( "Custom Summary Ensemble Import", pathCacheName );
|
2025-02-28 16:14:55 +01:00
|
|
|
QStringList fileNames = result.files;
|
|
|
|
|
RiaDefines::EnsembleGroupingMode ensembleGroupingMode = result.groupingMode;
|
|
|
|
|
RiaDefines::FileType fileType = RicRecursiveFileSearchDialog::mapSummaryFileType( result.fileType );
|
2019-02-18 13:09:50 +01:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( fileNames.isEmpty() ) return;
|
2018-05-11 08:32:44 +02:00
|
|
|
|
2025-02-28 16:14:55 +01:00
|
|
|
if ( ensembleGroupingMode == RiaDefines::EnsembleGroupingMode::NONE )
|
2021-09-17 14:17:58 +02:00
|
|
|
{
|
2021-09-30 09:08:09 +02:00
|
|
|
bool useEnsembleNameDialog = true;
|
2023-04-20 10:16:43 +02:00
|
|
|
importSingleEnsemble( fileNames, useEnsembleNameDialog, ensembleGroupingMode, fileType );
|
2021-09-30 09:08:09 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-04-24 16:04:36 +02:00
|
|
|
if ( fileType == RiaDefines::FileType::STIMPLAN_SUMMARY || fileType == RiaDefines::FileType::REVEAL_SUMMARY )
|
2021-09-21 22:27:36 +02:00
|
|
|
{
|
2023-04-24 16:04:36 +02:00
|
|
|
std::map<QString, QStringList> groupedByEnsemble = RiaEnsembleNameTools::groupFilesByCustomEnsemble( fileNames, fileType );
|
2023-04-20 10:16:43 +02:00
|
|
|
for ( const auto& [ensembleName, groupedFileNames] : groupedByEnsemble )
|
|
|
|
|
{
|
|
|
|
|
bool useEnsembleNameDialog = false;
|
|
|
|
|
importSingleEnsemble( groupedFileNames, useEnsembleNameDialog, ensembleGroupingMode, fileType, ensembleName );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-05-15 18:16:27 +02:00
|
|
|
std::vector<RimSummaryEnsemble*> ensembles;
|
|
|
|
|
auto grouping = RiaEnsembleNameTools::groupFilesByEnsembleName( fileNames, ensembleGroupingMode );
|
2025-02-28 16:14:55 +01:00
|
|
|
for ( const auto& [groupName, fileNames] : grouping )
|
2023-04-20 10:16:43 +02:00
|
|
|
{
|
|
|
|
|
bool useEnsembleNameDialog = false;
|
2025-05-15 18:16:27 +02:00
|
|
|
if ( auto ensemble = importSingleEnsembleFileSet( fileNames, useEnsembleNameDialog, ensembleGroupingMode, fileType, groupName ) )
|
|
|
|
|
{
|
|
|
|
|
ensembles.push_back( ensemble );
|
|
|
|
|
}
|
2023-04-20 10:16:43 +02:00
|
|
|
}
|
2025-02-28 16:14:55 +01:00
|
|
|
|
2025-03-25 06:45:39 +01:00
|
|
|
RiaSummaryTools::updateSummaryEnsembleNames();
|
2025-05-15 18:16:27 +02:00
|
|
|
|
|
|
|
|
for ( auto ensemble : ensembles )
|
|
|
|
|
{
|
|
|
|
|
RiaSummaryPlotTools::createAndAppendDefaultSummaryMultiPlot( {}, { ensemble } );
|
|
|
|
|
}
|
|
|
|
|
RiaSummaryTools::summaryCaseMainCollection()->updateConnectedEditors();
|
2021-09-21 22:27:36 +02:00
|
|
|
}
|
|
|
|
|
}
|
2025-06-03 14:29:44 +02:00
|
|
|
|
|
|
|
|
RiuPlotMainWindowTools::showPlotMainWindow();
|
2021-09-17 14:17:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2025-03-17 15:07:58 +01:00
|
|
|
RimSummaryEnsemble* RicImportEnsembleFeature::importSingleEnsemble( const QStringList& fileNames,
|
|
|
|
|
bool useEnsembleNameDialog,
|
|
|
|
|
RiaDefines::EnsembleGroupingMode groupingMode,
|
|
|
|
|
RiaDefines::FileType fileType,
|
|
|
|
|
const QString& defaultEnsembleName )
|
2021-09-17 14:17:58 +02:00
|
|
|
{
|
2023-04-20 10:16:43 +02:00
|
|
|
QString ensembleName = !defaultEnsembleName.isEmpty() ? defaultEnsembleName
|
|
|
|
|
: RiaEnsembleNameTools::findSuitableEnsembleName( fileNames, groupingMode );
|
2021-09-21 23:49:18 +02:00
|
|
|
|
|
|
|
|
if ( useEnsembleNameDialog ) ensembleName = askForEnsembleName( ensembleName );
|
2020-09-02 15:04:48 +02:00
|
|
|
|
2025-03-17 15:07:58 +01:00
|
|
|
if ( ensembleName.isEmpty() ) return nullptr;
|
2018-05-11 08:32:44 +02:00
|
|
|
|
2025-07-18 08:05:35 +02:00
|
|
|
RiaEnsembleImportTools::CreateConfig createConfig{ .fileType = fileType,
|
|
|
|
|
.ensembleOrGroup = true,
|
|
|
|
|
.allowDialogs = true,
|
|
|
|
|
.buildSummaryAddresses = false };
|
|
|
|
|
|
|
|
|
|
auto cases = RiaEnsembleImportTools::createSummaryCasesFromFiles( fileNames, createConfig );
|
2025-05-12 12:30:15 +02:00
|
|
|
if ( cases.empty() ) return nullptr;
|
2021-02-16 13:31:26 +01:00
|
|
|
|
2025-03-17 15:07:58 +01:00
|
|
|
RimSummaryEnsemble* ensemble = RicImportEnsembleFeature::groupSummaryCases( cases, ensembleName, groupingMode, true );
|
2018-05-11 08:32:44 +02:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( ensemble )
|
2018-05-11 08:32:44 +02:00
|
|
|
{
|
2021-02-16 13:31:26 +01:00
|
|
|
for ( auto summaryCase : ensemble->allSummaryCases() )
|
|
|
|
|
{
|
2025-03-28 10:30:24 +01:00
|
|
|
summaryCase->setDisplayNameOption( RimCaseDisplayNameTools::DisplayName::SHORT_CASE_NAME );
|
2021-02-16 13:31:26 +01:00
|
|
|
summaryCase->updateAutoShortName();
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-25 06:45:39 +01:00
|
|
|
RiaSummaryTools::updateSummaryEnsembleNames();
|
|
|
|
|
|
2025-02-12 13:06:58 +01:00
|
|
|
RiaSummaryPlotTools::createAndAppendDefaultSummaryMultiPlot( {}, { ensemble } );
|
2018-05-11 08:32:44 +02:00
|
|
|
}
|
|
|
|
|
|
2023-09-11 15:12:18 +02:00
|
|
|
std::vector<RimCase*> allCases = RiaApplication::instance()->project()->allGridCases();
|
2023-04-20 10:16:43 +02:00
|
|
|
if ( allCases.empty() )
|
2018-05-11 08:32:44 +02:00
|
|
|
{
|
2022-05-23 10:54:09 +02:00
|
|
|
RiuMainWindow::closeIfOpen();
|
2018-05-11 08:32:44 +02:00
|
|
|
}
|
2025-03-17 15:07:58 +01:00
|
|
|
|
|
|
|
|
return ensemble;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-15 18:16:27 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RimSummaryEnsemble* RicImportEnsembleFeature::importSingleEnsembleFileSet( const QStringList& fileNames,
|
|
|
|
|
bool useEnsembleNameDialog,
|
|
|
|
|
RiaDefines::EnsembleGroupingMode groupingMode,
|
|
|
|
|
RiaDefines::FileType fileType,
|
|
|
|
|
const QString& defaultEnsembleName )
|
|
|
|
|
{
|
|
|
|
|
auto fileSets = RimEnsembleFileSetTools::createEnsembleFileSets( fileNames, groupingMode );
|
|
|
|
|
auto ensembles = RimEnsembleFileSetTools::createSummaryEnsemblesFromFileSets( fileSets );
|
|
|
|
|
if ( !ensembles.empty() ) return ensembles.front();
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-17 15:07:58 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RimSummaryEnsemble* RicImportEnsembleFeature::groupSummaryCases( std::vector<RimSummaryCase*> cases,
|
|
|
|
|
const QString& groupName,
|
|
|
|
|
RiaDefines::EnsembleGroupingMode groupingMode,
|
|
|
|
|
bool isEnsemble /*= false */ )
|
|
|
|
|
{
|
|
|
|
|
RimSummaryCaseMainCollection* summaryCaseMainCollection = RiaSummaryTools::summaryCaseMainCollection();
|
|
|
|
|
if ( !cases.empty() )
|
|
|
|
|
{
|
|
|
|
|
auto newGroup = summaryCaseMainCollection->addEnsemble( cases, groupName, isEnsemble );
|
|
|
|
|
newGroup->setGroupingMode( groupingMode );
|
|
|
|
|
summaryCaseMainCollection->updateConnectedEditors();
|
|
|
|
|
|
|
|
|
|
RiuPlotMainWindowTools::showPlotMainWindow();
|
|
|
|
|
return newGroup;
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
2018-05-11 08:32:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-02-18 13:09:50 +01:00
|
|
|
///
|
2018-05-11 08:32:44 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
void RicImportEnsembleFeature::setupActionLook( QAction* actionToSetup )
|
2018-05-11 08:32:44 +02:00
|
|
|
{
|
2020-10-01 17:25:19 +02:00
|
|
|
actionToSetup->setIcon( QIcon( ":/SummaryEnsemble.svg" ) );
|
2026-05-28 16:06:39 +02:00
|
|
|
actionToSetup->setText( "Custom Summary Ensemble Import..." );
|
2018-05-11 08:32:44 +02:00
|
|
|
}
|
|
|
|
|
|
2018-04-18 13:56:01 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-02-18 13:09:50 +01:00
|
|
|
///
|
2018-04-18 13:56:01 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-09-02 15:04:48 +02:00
|
|
|
QString RicImportEnsembleFeature::askForEnsembleName( const QString& suggestion )
|
2018-04-18 13:56:01 +02:00
|
|
|
{
|
2024-07-29 15:38:17 +02:00
|
|
|
RimProject* project = RimProject::current();
|
2025-04-25 11:06:02 +02:00
|
|
|
std::vector<RimSummaryEnsemble*> ensembles = project->summaryEnsembles();
|
|
|
|
|
int ensemblesStartingWithRoot = std::count_if( ensembles.begin(),
|
|
|
|
|
ensembles.end(),
|
2024-07-29 15:38:17 +02:00
|
|
|
[suggestion]( RimSummaryEnsemble* group )
|
2023-04-13 07:05:53 +02:00
|
|
|
{ return group->isEnsemble() && group->name().startsWith( suggestion ); } );
|
2018-04-18 13:56:01 +02:00
|
|
|
|
|
|
|
|
QInputDialog dialog;
|
2019-09-06 10:40:57 +02:00
|
|
|
dialog.setInputMode( QInputDialog::TextInput );
|
|
|
|
|
dialog.setWindowTitle( "Ensemble Name" );
|
|
|
|
|
dialog.setLabelText( "Ensemble Name" );
|
2020-09-02 15:04:48 +02:00
|
|
|
if ( ensemblesStartingWithRoot > 0 )
|
|
|
|
|
{
|
|
|
|
|
dialog.setTextValue( QString( "%1 %2" ).arg( suggestion ).arg( ensemblesStartingWithRoot + 1 ) );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dialog.setTextValue( suggestion );
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
dialog.resize( 300, 50 );
|
2018-04-18 13:56:01 +02:00
|
|
|
dialog.exec();
|
2019-09-06 10:40:57 +02:00
|
|
|
return dialog.result() == QDialog::Accepted ? dialog.textValue() : QString( "" );
|
2018-04-18 13:56:01 +02:00
|
|
|
}
|