Files
ResInsight/ApplicationLibCode/Commands/RicReplaceCaseFeature.cpp
T

131 lines
4.7 KiB
C++
Raw Normal View History

2019-11-07 12:59:30 +01:00
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015- Statoil ASA
// Copyright (C) 2015- Ceetron Solutions AS
//
// 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 "RicReplaceCaseFeature.h"
2024-01-25 10:41:57 +01:00
#include "RiaEclipseFileNameTools.h"
2019-11-07 12:59:30 +01:00
#include "RiaGuiApplication.h"
#include "RiaSummaryTools.h"
#include "RicImportGeneralDataFeature.h"
#include "RimEclipseCase.h"
#include "RimEclipseResultCase.h"
#include "RimReloadCaseTools.h"
#include "RimSummaryCase.h"
#include "RimSummaryCaseMainCollection.h"
#include "RimSummaryMultiPlot.h"
#include "RimSummaryMultiPlotCollection.h"
2019-11-07 12:59:30 +01:00
#include "RimSummaryPlot.h"
#include "RimTimeStepFilter.h"
#include "Riu3dSelectionManager.h"
#include "cafPdmObject.h"
#include "cafSelectionManager.h"
#include <QAction>
#include <QFileInfo>
2024-01-25 10:41:57 +01:00
#include <QMessageBox>
2019-11-07 12:59:30 +01:00
CAF_CMD_SOURCE_INIT( RicReplaceCaseFeature, "RicReplaceCaseFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2023-06-26 14:28:46 +02:00
bool RicReplaceCaseFeature::isCommandEnabled() const
2019-11-07 12:59:30 +01:00
{
std::vector<caf::PdmObject*> selectedFormationNamesCollObjs;
caf::SelectionManager::instance()->objectsByType( &selectedFormationNamesCollObjs );
for ( caf::PdmObject* pdmObject : selectedFormationNamesCollObjs )
{
if ( dynamic_cast<RimEclipseResultCase*>( pdmObject ) )
{
return true;
}
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicReplaceCaseFeature::onActionTriggered( bool isChecked )
{
2024-01-25 10:41:57 +01:00
auto eclipseResultCase = caf::SelectionManager::instance()->selectedItemOfType<RimEclipseResultCase>();
if ( !eclipseResultCase ) return;
auto summaryCase = RimReloadCaseTools::findSummaryCaseFromEclipseResultCase( eclipseResultCase );
2019-11-07 12:59:30 +01:00
RiaGuiApplication::clearAllSelections();
2023-02-26 10:48:40 +01:00
const QStringList fileNames = RicImportGeneralDataFeature::getEclipseFileNamesWithDialog( RiaDefines::ImportFileType::ECLIPSE_RESULT_GRID );
2019-11-07 12:59:30 +01:00
if ( fileNames.isEmpty() ) return;
2024-01-25 10:41:57 +01:00
const auto& fileName = fileNames.front();
eclipseResultCase->setGridFileName( fileName );
eclipseResultCase->reloadEclipseGridFile();
2019-11-07 12:59:30 +01:00
2024-01-25 10:41:57 +01:00
std::vector<RimTimeStepFilter*> timeStepFilter = eclipseResultCase->descendantsIncludingThisOfType<RimTimeStepFilter>();
if ( timeStepFilter.size() == 1 )
2019-11-07 12:59:30 +01:00
{
2024-01-25 10:41:57 +01:00
timeStepFilter[0]->clearFilteredTimeSteps();
}
2019-11-07 12:59:30 +01:00
2024-01-25 10:41:57 +01:00
RimReloadCaseTools::reloadEclipseGrid( eclipseResultCase );
eclipseResultCase->updateConnectedEditors();
2019-11-07 12:59:30 +01:00
2024-01-25 10:41:57 +01:00
// Use the file base name as case user description
QFileInfo fileInfoNew( fileName );
eclipseResultCase->setCaseUserDescription( fileInfoNew.baseName() );
2019-11-07 12:59:30 +01:00
2024-01-25 10:41:57 +01:00
RiaEclipseFileNameTools helper( fileName );
auto summaryFileNames = helper.findSummaryFileCandidates();
if ( summaryCase && !summaryFileNames.empty() )
{
QMessageBox msgBox;
msgBox.setIcon( QMessageBox::Question );
QString questionText;
questionText = QString(
"Found an open summary case for the same reservoir model.\n\nDo you want to replace the file name for the summary case?" );
2019-11-07 12:59:30 +01:00
2024-01-25 10:41:57 +01:00
msgBox.setText( questionText );
msgBox.setStandardButtons( QMessageBox::Yes | QMessageBox::No );
int ret = msgBox.exec();
if ( ret == QMessageBox::Yes )
2019-11-07 12:59:30 +01:00
{
2024-01-25 10:41:57 +01:00
summaryCase->setSummaryHeaderFileName( summaryFileNames.front() );
RiaSummaryTools::reloadSummaryCase( summaryCase );
2019-11-07 12:59:30 +01:00
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicReplaceCaseFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Replace" );
2019-11-29 13:37:38 +01:00
actionToSetup->setIcon( QIcon( ":/ReplaceCase16x16.png" ) );
2019-11-07 12:59:30 +01:00
}