ResInsight/ApplicationLibCode/ProjectDataModelCommands/RimcProject.cpp
Kristian Bendiksen ff209ad7c2
Refactor ensemble import dialog
* #9773 Refactor ensemble import dialog.
* #9773 Add support for ensemble import of StimPlan/Reveal summary data.
* #9773 Add method for finding min and max time steps.
* #9773 Add option for resampling to hour intervals.
* #9773 Add option for resampling to minute intervals.
* #9773 Ensemble statistics: determine sub-sampling period dynamically.
* Use RiaWeightedMeanCalculator for curve resampling.
* Add HOUR and MINUTE to date time app enum.
* #9773 Generate better ensembles for StimPlan summaries.
* #9773 Fix parameters.txt lookup for StimPlan summaries
* Refactor: Improve interface of RicImportSummaryCasesFreature::createSummaryCasesFromFiles

Co-authored-by: Magne Sjaastad <magne.sjaastad@ceetronsolutions.com>
2023-04-20 10:16:43 +02:00

223 lines
8.2 KiB
C++

/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2020- 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 "RimcProject.h"
#include "RiaApplication.h"
#include "RiaGuiApplication.h"
#include "RicImportSummaryCasesFeature.h"
#include "RimFileSummaryCase.h"
#include "RimOilField.h"
#include "RimProject.h"
#include "RimSummaryCase.h"
#include "RimSurfaceCollection.h"
#include "RiuPlotMainWindow.h"
#include "cafPdmFieldScriptingCapability.h"
#include <QDir>
#include <QFileInfo>
#include <memory>
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimProject, RimProject_importSummaryCase, "importSummaryCase" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimProject_importSummaryCase::RimProject_importSummaryCase( caf::PdmObjectHandle* self )
: caf::PdmObjectMethod( self )
{
CAF_PDM_InitObject( "Import Summary Case", "", "", "Import Summary Case" );
CAF_PDM_InitScriptableFieldNoDefault( &m_fileName, "FileName", "" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmObjectHandle* RimProject_importSummaryCase::execute()
{
QString absolutePath = m_fileName;
QFileInfo projectPathInfo( absolutePath );
if ( !projectPathInfo.exists() )
{
QDir startDir( RiaApplication::instance()->startDir() );
absolutePath = startDir.absoluteFilePath( m_fileName );
}
QStringList summaryFileNames{ absolutePath };
RicImportSummaryCasesFeature::CreateConfig createConfig{ .fileType = RiaDefines::FileType::SMSPEC,
.ensembleOrGroup = false,
.allowDialogs = false };
auto [isOk, newCases] = RicImportSummaryCasesFeature::createSummaryCasesFromFiles( summaryFileNames, createConfig );
if ( isOk )
{
RicImportSummaryCasesFeature::addSummaryCases( newCases );
if ( RiaGuiApplication::isRunning() )
{
RiuPlotMainWindow* mainPlotWindow = RiaGuiApplication::instance()->mainPlotWindow();
if ( mainPlotWindow && !newCases.empty() )
{
mainPlotWindow->updateMultiPlotToolBar();
}
}
if ( newCases.size() == 1 )
{
return newCases[0];
}
}
return nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimProject_importSummaryCase::resultIsPersistent() const
{
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::unique_ptr<caf::PdmObjectHandle> RimProject_importSummaryCase::defaultResult() const
{
return std::unique_ptr<caf::PdmObjectHandle>( new RimFileSummaryCase );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimProject_importSummaryCase::isNullptrValidResult() const
{
return true;
}
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimProject, RimProject_summaryCase, "summaryCase" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimProject_summaryCase::RimProject_summaryCase( caf::PdmObjectHandle* self )
: caf::PdmObjectMethod( self )
{
CAF_PDM_InitObject( "Find Summary Case", "", "", "Find Summary Case" );
CAF_PDM_InitScriptableField( &m_caseId, "CaseId", -1, "" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmObjectHandle* RimProject_summaryCase::execute()
{
auto proj = RimProject::current();
auto sumCases = proj->allSummaryCases();
for ( auto s : sumCases )
{
if ( s->caseId() == m_caseId ) return s;
}
return nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimProject_summaryCase::resultIsPersistent() const
{
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::unique_ptr<caf::PdmObjectHandle> RimProject_summaryCase::defaultResult() const
{
return std::unique_ptr<caf::PdmObjectHandle>( new RimFileSummaryCase );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimProject_summaryCase::isNullptrValidResult() const
{
return true;
}
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimProject, RimProject_surfaceFolder, "surfaceFolder" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimProject_surfaceFolder::RimProject_surfaceFolder( caf::PdmObjectHandle* self )
: caf::PdmObjectMethod( self )
{
CAF_PDM_InitObject( "Get Surface Folder", "", "", "Get Surface Folder" );
CAF_PDM_InitScriptableFieldNoDefault( &m_folderName, "FolderName", "" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmObjectHandle* RimProject_surfaceFolder::execute()
{
auto proj = RimProject::current();
RimSurfaceCollection* surfcoll = proj->activeOilField()->surfaceCollection();
// Blank foldername parameter should return the topmost folder
if ( m_folderName().isEmpty() ) return surfcoll;
for ( auto s : surfcoll->subCollections() )
{
if ( s->collectionName() == m_folderName() ) return s;
}
return nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimProject_surfaceFolder::resultIsPersistent() const
{
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::unique_ptr<caf::PdmObjectHandle> RimProject_surfaceFolder::defaultResult() const
{
return std::unique_ptr<caf::PdmObjectHandle>( new RimSurfaceCollection );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimProject_surfaceFolder::isNullptrValidResult() const
{
return true;
}