2016-05-31 06:42:27 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2016- Statoil ASA
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2016-05-31 06:42:27 -05: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-09-06 03:40:57 -05:00
|
|
|
//
|
2016-05-31 06:42:27 -05: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-09-06 03:40:57 -05:00
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2016-05-31 06:42:27 -05:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RimGridSummaryCase.h"
|
2016-09-23 06:10:54 -05:00
|
|
|
|
2020-02-24 08:42:23 -06:00
|
|
|
#include "RicfCommandObject.h"
|
2021-04-27 02:28:23 -05:00
|
|
|
|
|
|
|
#include "RifSummaryReaderInterface.h"
|
2017-09-22 02:11:39 -05:00
|
|
|
|
2016-05-31 06:42:27 -05:00
|
|
|
#include "RimEclipseCase.h"
|
2017-09-22 02:11:39 -05:00
|
|
|
#include "RimFileSummaryCase.h"
|
2017-04-04 05:14:13 -05:00
|
|
|
#include "RimProject.h"
|
2016-09-23 06:10:54 -05:00
|
|
|
|
2020-08-21 04:13:07 -05:00
|
|
|
#include "cafPdmObjectScriptingCapability.h"
|
2020-03-10 08:11:22 -05:00
|
|
|
|
2016-05-31 06:42:27 -05:00
|
|
|
#include <QFileInfo>
|
|
|
|
|
|
|
|
//==================================================================================================
|
|
|
|
//
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2016-05-31 06:42:27 -05:00
|
|
|
//
|
|
|
|
//==================================================================================================
|
|
|
|
|
2020-02-24 08:42:23 -06:00
|
|
|
CAF_PDM_SOURCE_INIT( RimGridSummaryCase, "GridSummaryCase" );
|
2016-05-31 06:42:27 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2016-05-31 06:42:27 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimGridSummaryCase::RimGridSummaryCase()
|
|
|
|
{
|
2020-03-06 16:14:58 -06:00
|
|
|
CAF_PDM_InitScriptableObject( "Grid Summary Case",
|
|
|
|
":/SummaryCases16x16.png",
|
|
|
|
"",
|
|
|
|
"A Summary Case based on extracting grid data." );
|
2021-11-14 07:15:12 -06:00
|
|
|
CAF_PDM_InitFieldNoDefault( &m_eclipseCase, "Associated3DCase", "Eclipse Case" );
|
2019-09-06 03:40:57 -05:00
|
|
|
m_eclipseCase.uiCapability()->setUiHidden( true );
|
2016-11-16 02:21:27 -06:00
|
|
|
|
2021-11-14 07:15:12 -06:00
|
|
|
CAF_PDM_InitFieldNoDefault( &m_cachedCaseName, "CachedCasename", "Case Name" );
|
2019-09-06 03:40:57 -05:00
|
|
|
m_cachedCaseName.uiCapability()->setUiHidden( true );
|
2017-04-04 05:14:13 -05:00
|
|
|
|
2021-11-14 07:15:12 -06:00
|
|
|
CAF_PDM_InitFieldNoDefault( &m_eclipseGridFileName, "Associated3DCaseGridFileName", "Grid File Name" );
|
2019-09-06 03:40:57 -05:00
|
|
|
m_eclipseGridFileName.registerGetMethod( this, &RimGridSummaryCase::eclipseGridFileName );
|
|
|
|
m_eclipseGridFileName.uiCapability()->setUiReadOnly( true );
|
|
|
|
m_eclipseGridFileName.xmlCapability()->setIOWritable( false );
|
2016-11-16 02:21:27 -06:00
|
|
|
|
2021-11-14 07:15:12 -06:00
|
|
|
CAF_PDM_InitField( &m_includeRestartFiles, "IncludeRestartFiles", false, "Include Restart Files" );
|
2019-09-06 03:40:57 -05:00
|
|
|
m_includeRestartFiles.uiCapability()->setUiHidden( true );
|
2016-05-31 06:42:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2016-05-31 06:42:27 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-12 04:13:38 -06:00
|
|
|
RimGridSummaryCase::~RimGridSummaryCase()
|
|
|
|
{
|
|
|
|
}
|
2016-05-31 06:42:27 -05:00
|
|
|
|
2017-09-22 02:11:39 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-09-22 02:11:39 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
QString summaryHeaderFilenameFromEclipseCase( RimEclipseCase* eclCase )
|
2017-04-04 05:14:13 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !eclCase ) return QString();
|
2017-04-04 05:14:13 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
QFileInfo gridFileInfo( eclCase->gridFileName() );
|
2017-04-04 05:14:13 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
QString possibleSumHeaderFileName = gridFileInfo.path() + "/" + gridFileInfo.completeBaseName() + ".SMSPEC";
|
2017-04-04 05:14:13 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
return possibleSumHeaderFileName;
|
2017-04-04 05:14:13 -05:00
|
|
|
}
|
|
|
|
|
2017-09-22 02:11:39 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-09-22 02:11:39 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
QString caseNameFromEclipseCase( RimEclipseCase* eclCase )
|
2017-04-04 05:14:13 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !eclCase ) return QString();
|
2017-04-04 05:14:13 -05:00
|
|
|
|
|
|
|
return eclCase->caseUserDescription();
|
|
|
|
}
|
|
|
|
|
2016-05-31 06:42:27 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2016-05-31 06:42:27 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RimGridSummaryCase::setAssociatedEclipseCase( RimEclipseCase* eclipseCase )
|
2016-05-31 06:42:27 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
m_eclipseCase = eclipseCase;
|
|
|
|
m_summaryHeaderFilename = summaryHeaderFilenameFromEclipseCase( eclipseCase );
|
|
|
|
m_cachedCaseName = caseNameFromEclipseCase( eclipseCase );
|
2017-04-04 05:14:13 -05:00
|
|
|
|
2016-08-05 04:05:58 -05:00
|
|
|
this->updateAutoShortName();
|
|
|
|
this->updateTreeItemName();
|
2016-05-31 06:42:27 -05:00
|
|
|
}
|
|
|
|
|
2016-10-06 08:41:31 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2016-10-06 08:41:31 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimEclipseCase* RimGridSummaryCase::associatedEclipseCase()
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !m_eclipseCase() )
|
2017-04-04 05:14:13 -05:00
|
|
|
{
|
|
|
|
// Find a possible associated eclipse case
|
|
|
|
|
|
|
|
RimProject* project;
|
2019-09-06 03:40:57 -05:00
|
|
|
firstAncestorOrThisOfTypeAsserted( project );
|
2017-04-04 05:14:13 -05:00
|
|
|
std::vector<RimCase*> allCases;
|
2019-09-06 03:40:57 -05:00
|
|
|
project->allCases( allCases );
|
|
|
|
for ( RimCase* someCase : allCases )
|
2017-04-04 05:14:13 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
auto eclCase = dynamic_cast<RimEclipseCase*>( someCase );
|
2017-04-04 05:14:13 -05:00
|
|
|
if ( eclCase )
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
QString sumHeaderFileName = summaryHeaderFilenameFromEclipseCase( eclCase );
|
2019-12-10 09:12:21 -06:00
|
|
|
if ( sumHeaderFileName == m_summaryHeaderFilename().path() )
|
2017-04-04 05:14:13 -05:00
|
|
|
{
|
|
|
|
m_eclipseCase = eclCase;
|
|
|
|
this->updateAutoShortName();
|
|
|
|
this->updateTreeItemName();
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-06 08:41:31 -05:00
|
|
|
return m_eclipseCase();
|
|
|
|
}
|
|
|
|
|
2016-05-31 06:42:27 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2016-05-31 06:42:27 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QString RimGridSummaryCase::summaryHeaderFilename() const
|
|
|
|
{
|
2021-09-02 08:09:50 -05:00
|
|
|
if ( m_eclipseCase() )
|
|
|
|
{
|
|
|
|
auto candidate = summaryHeaderFilenameFromEclipseCase( m_eclipseCase );
|
|
|
|
if ( QFileInfo::exists( candidate ) ) return candidate;
|
|
|
|
}
|
2016-05-31 06:42:27 -05:00
|
|
|
|
2021-09-02 08:09:50 -05:00
|
|
|
return m_summaryHeaderFilename().path();
|
2016-05-31 06:42:27 -05:00
|
|
|
}
|
|
|
|
|
2016-06-27 06:23:00 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2016-06-27 06:23:00 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
QString RimGridSummaryCase::caseName() const
|
2016-06-27 06:23:00 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( m_eclipseCase() ) m_cachedCaseName = caseNameFromEclipseCase( m_eclipseCase() );
|
2016-09-23 06:10:54 -05:00
|
|
|
|
2017-04-04 05:14:13 -05:00
|
|
|
return m_cachedCaseName;
|
2016-06-27 06:23:00 -05:00
|
|
|
}
|
|
|
|
|
2016-11-16 02:21:27 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2016-11-16 02:21:27 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QString RimGridSummaryCase::eclipseGridFileName() const
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !m_eclipseCase() ) return QString();
|
2016-11-16 02:21:27 -06:00
|
|
|
|
|
|
|
return m_eclipseCase()->gridFileName();
|
|
|
|
}
|
|
|
|
|
2017-09-22 02:11:39 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-09-22 02:11:39 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RimGridSummaryCase::createSummaryReaderInterface()
|
|
|
|
{
|
2021-04-08 08:53:38 -05:00
|
|
|
m_summaryFileReader = RimFileSummaryCase::findRelatedFilesAndCreateReader( this->summaryHeaderFilename(),
|
|
|
|
m_includeRestartFiles,
|
|
|
|
nullptr );
|
2017-09-22 02:11:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-09-22 02:11:39 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RifSummaryReaderInterface* RimGridSummaryCase::summaryReader()
|
|
|
|
{
|
2020-09-07 06:59:30 -05:00
|
|
|
if ( m_summaryFileReader.isNull() )
|
|
|
|
{
|
|
|
|
createSummaryReaderInterface();
|
|
|
|
}
|
2017-09-22 02:11:39 -05:00
|
|
|
return m_summaryFileReader.p();
|
|
|
|
}
|
|
|
|
|
2018-03-20 08:32:24 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2018-03-20 08:32:24 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RimGridSummaryCase::setIncludeRestartFiles( bool includeRestartFiles )
|
2018-03-20 08:32:24 -05:00
|
|
|
{
|
|
|
|
m_includeRestartFiles = includeRestartFiles;
|
|
|
|
}
|
|
|
|
|
2018-05-15 08:43:04 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2018-05-15 08:43:04 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimFileSummaryCase* RimGridSummaryCase::createFileSummaryCaseCopy()
|
|
|
|
{
|
|
|
|
RimFileSummaryCase* fileSummaryCase = new RimFileSummaryCase();
|
2019-09-06 03:40:57 -05:00
|
|
|
fileSummaryCase->copyFrom( *this );
|
|
|
|
fileSummaryCase->setIncludeRestartFiles( m_includeRestartFiles() );
|
2018-05-15 08:43:04 -05:00
|
|
|
return fileSummaryCase;
|
|
|
|
}
|