Files
ResInsight/ApplicationLibCode/Commands/RicReplaceSummaryCaseFeature.cpp
T

106 lines
3.9 KiB
C++
Raw Normal View History

2019-11-05 15:55:35 +01:00
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2019- 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 "RicReplaceSummaryCaseFeature.h"
2024-01-25 10:41:57 +01:00
#include "RiaEclipseFileNameTools.h"
2019-11-05 15:55:35 +01:00
#include "RiaLogging.h"
#include "RiaSummaryTools.h"
#include "RicImportGeneralDataFeature.h"
2024-01-25 10:41:57 +01:00
#include "RimEclipseCase.h"
2019-11-05 15:55:35 +01:00
#include "RimFileSummaryCase.h"
2024-01-25 10:41:57 +01:00
#include "RimReloadCaseTools.h"
2019-11-05 15:55:35 +01:00
#include "cafPdmObject.h"
#include "cafSelectionManager.h"
#include <QAction>
2024-01-25 10:41:57 +01:00
#include <QFileInfo>
#include <QMessageBox>
2019-11-05 15:55:35 +01:00
CAF_CMD_SOURCE_INIT( RicReplaceSummaryCaseFeature, "RicReplaceSummaryCaseFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2023-06-26 14:28:46 +02:00
bool RicReplaceSummaryCaseFeature::isCommandEnabled() const
2019-11-05 15:55:35 +01:00
{
2024-01-25 10:41:57 +01:00
auto rimSummaryCase = caf::SelectionManager::instance()->selectedItemOfType<RimFileSummaryCase>();
2019-11-05 15:55:35 +01:00
return rimSummaryCase != nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicReplaceSummaryCaseFeature::onActionTriggered( bool isChecked )
{
2024-01-25 10:41:57 +01:00
auto* summaryCase = caf::SelectionManager::instance()->selectedItemOfType<RimFileSummaryCase>();
2019-11-05 15:55:35 +01:00
if ( !summaryCase ) return;
2020-02-12 11:43:15 +01:00
const QStringList fileNames =
2020-04-24 07:29:32 +02:00
RicImportGeneralDataFeature::getEclipseFileNamesWithDialog( RiaDefines::ImportFileType::ECLIPSE_SUMMARY_FILE );
2019-11-05 15:55:35 +01:00
if ( fileNames.isEmpty() ) return;
2024-01-25 10:41:57 +01:00
auto gridModel = RimReloadCaseTools::gridModelFromSummaryCase( summaryCase );
2019-11-05 15:55:35 +01:00
QString oldSummaryHeaderFilename = summaryCase->summaryHeaderFilename();
2024-01-25 10:41:57 +01:00
const auto& newFileName = fileNames.front();
summaryCase->setSummaryHeaderFileName( newFileName );
RiaSummaryTools::reloadSummaryCase( summaryCase );
2019-11-05 15:55:35 +01:00
2024-01-25 10:41:57 +01:00
RiaLogging::info( QString( "Replaced summary data for %1" ).arg( oldSummaryHeaderFilename ) );
2024-01-25 10:41:57 +01:00
RiaEclipseFileNameTools helper( newFileName );
auto newGridFileName = helper.findRelatedGridFile();
if ( gridModel && !newGridFileName.isEmpty() )
{
2024-01-25 10:41:57 +01:00
QMessageBox msgBox;
msgBox.setIcon( QMessageBox::Question );
2024-01-25 10:41:57 +01:00
QString questionText;
questionText =
QString( "Found an open grid case for the same reservoir model.\n\nDo you want to replace the file name in the grid case?" );
msgBox.setText( questionText );
msgBox.setStandardButtons( QMessageBox::Yes | QMessageBox::No );
int ret = msgBox.exec();
if ( ret == QMessageBox::Yes )
{
2024-01-25 10:41:57 +01:00
auto previousGridFileName = gridModel->gridFileName();
gridModel->setGridFileName( newGridFileName );
RimReloadCaseTools::reloadEclipseGrid( gridModel );
RiaLogging::info( QString( "Replaced grid data for %1" ).arg( previousGridFileName ) );
}
2019-11-05 15:55:35 +01:00
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicReplaceSummaryCaseFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Replace" );
2019-11-29 13:37:38 +01:00
actionToSetup->setIcon( QIcon( ":/ReplaceCase16x16.png" ) );
2019-11-05 15:55:35 +01:00
}