Files
ResInsight/ApplicationLibCode/Commands/SummaryPlotCommands/RicReplaceSummaryEnsembleFeature.cpp
T
Magne Sjaastad 88e0aad8cf Several adjustments user interface and project file
* Avoid writing error message if observed data for a well is not present
* Add missing log text during replace summary ensemble
* Make sure plot window is visible after importing summary ensemble
* Add observed FMU folder to path section
* Move worker functions to RiaProjectFileTools
* Reset numbering of path IDs when saving project.
* Remove warning when fault name is longer than 8 characters
2025-06-03 14:29:44 +02:00

125 lines
4.8 KiB
C++

/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2025 Equinor ASA
//
// 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.
//
// 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.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicReplaceSummaryEnsembleFeature.h"
#include "Ensemble/RiaEnsembleImportTools.h"
#include "RiaLogging.h"
#include "Summary/RiaSummaryTools.h"
#include "RicImportSummaryCasesFeature.h"
#include "EnsembleFileSet/RimEnsembleFileSet.h"
#include "EnsembleFileSet/RimEnsembleFileSetCollection.h"
#include "RimProject.h"
#include "RimSummaryCase.h"
#include "RimSummaryCaseMainCollection.h"
#include "RimSummaryEnsemble.h"
#include "Summary/Ensemble/RimSummaryFileSetEnsemble.h"
#include "cafPdmObject.h"
#include "cafSelectionManager.h"
#include <QAction>
CAF_CMD_SOURCE_INIT( RicReplaceSummaryEnsembleFeature, "RicReplaceSummaryEnsembleFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicReplaceSummaryEnsembleFeature::isCommandEnabled() const
{
auto summaryEnsemble = caf::SelectionManager::instance()->selectedItemOfType<RimSummaryEnsemble>();
return summaryEnsemble != nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicReplaceSummaryEnsembleFeature::onActionTriggered( bool isChecked )
{
auto summaryEnsemble = caf::SelectionManager::instance()->selectedItemOfType<RimSummaryEnsemble>();
if ( !summaryEnsemble ) return;
RiaLogging::info( QString( "Starting replace ensemble for '" ) + summaryEnsemble->name() + "'" );
QString pathCacheName = "ENSEMBLE_FILES";
auto result = RicImportSummaryCasesFeature::runRecursiveSummaryCaseFileSearchDialogWithGrouping( "Import Ensemble", pathCacheName );
QStringList fileNames = result.files;
RiaDefines::FileType fileType = RicRecursiveFileSearchDialog::mapSummaryFileType( result.fileType );
if ( fileNames.isEmpty() ) return;
if ( fileType != RiaDefines::FileType::SMSPEC ) return;
if ( auto fileSetEnsemble = dynamic_cast<RimSummaryFileSetEnsemble*>( summaryEnsemble ) )
{
if ( auto fileSet = fileSetEnsemble->ensembleFileSet() )
{
auto collection = RimProject::current()->ensembleFileSetCollection();
fileSet->findAndSetPathPatternAndRangeString( fileNames );
collection->updateFileSetNames();
collection->updateAllRequiredEditors();
RiaLogging::info( QString( "Completed replace ensemble, new name is '" ) + summaryEnsemble->name() + "'" );
return;
}
RiaLogging::error( "Failed to get ensemble file set from summary ensemble." );
return;
}
RiaEnsembleImportTools::CreateConfig createConfig{ .fileType = fileType, .ensembleOrGroup = false, .allowDialogs = false };
auto newCases = RiaEnsembleImportTools::createSummaryCasesFromFiles( fileNames, createConfig );
if ( newCases.empty() )
{
RiaLogging::warning( "No new cases are created." );
return;
}
summaryEnsemble->replaceCases( newCases );
// Update name of cases and ensemble after all cases are added
for ( auto summaryCase : newCases )
{
summaryCase->setDisplayNameOption( RimCaseDisplayNameTools::DisplayName::SHORT_CASE_NAME );
summaryCase->updateAutoShortName();
}
if ( auto sumCaseMainColl = RiaSummaryTools::summaryCaseMainCollection() )
{
sumCaseMainColl->updateEnsembleNames();
sumCaseMainColl->updateAllRequiredEditors();
}
RiaSummaryTools::updateConnectedPlots( summaryEnsemble );
RiaLogging::info( QString( "Completed replace ensemble, new name is '" ) + summaryEnsemble->name() + "'" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicReplaceSummaryEnsembleFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Replace" );
actionToSetup->setIcon( QIcon( ":/ReplaceCase16x16.png" ) );
}