2017-07-27 03:23:05 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2017 Statoil ASA
|
2018-10-11 00:31:15 -05:00
|
|
|
//
|
2017-07-27 03:23:05 -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.
|
2018-10-11 00:31:15 -05:00
|
|
|
//
|
2017-07-27 03:23:05 -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.
|
2018-10-11 00:31:15 -05:00
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2017-07-27 03:23:05 -05:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RicfExportProperty.h"
|
|
|
|
|
2018-10-11 00:31:15 -05:00
|
|
|
#include "RiaLogging.h"
|
2017-07-27 03:23:05 -05:00
|
|
|
|
2019-10-30 03:12:13 -05:00
|
|
|
#include "ExportCommands/RicEclipseCellResultToFileImpl.h"
|
2018-11-07 08:42:45 -06:00
|
|
|
#include "RicfApplicationTools.h"
|
2018-10-11 00:31:15 -05:00
|
|
|
#include "RicfCommandFileExecutor.h"
|
2018-10-10 08:12:54 -05:00
|
|
|
|
2018-10-11 00:31:15 -05:00
|
|
|
#include "RifEclipseInputFileTools.h"
|
2017-07-27 07:26:59 -05:00
|
|
|
|
2018-10-03 08:44:38 -05:00
|
|
|
#include "RigCaseCellResultsData.h"
|
|
|
|
#include "RigEclipseCaseData.h"
|
2017-07-27 03:23:05 -05:00
|
|
|
#include "RimEclipseCase.h"
|
2018-10-11 00:31:15 -05:00
|
|
|
#include "RimEclipseCaseCollection.h"
|
2017-07-27 03:23:05 -05:00
|
|
|
#include "RimEclipseCellColors.h"
|
2018-10-11 00:31:15 -05:00
|
|
|
#include "RimEclipseView.h"
|
|
|
|
#include "RimProject.h"
|
2017-07-27 03:23:05 -05:00
|
|
|
|
2020-08-21 04:13:07 -05:00
|
|
|
#include "cafPdmFieldScriptingCapability.h"
|
2017-08-29 02:39:06 -05:00
|
|
|
#include "cafUtils.h"
|
|
|
|
|
2017-07-27 03:23:05 -05:00
|
|
|
#include <QDir>
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
CAF_PDM_SOURCE_INIT( RicfExportProperty, "exportProperty" );
|
2017-07-27 03:23:05 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-10-11 00:31:15 -05:00
|
|
|
///
|
2017-07-27 03:23:05 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RicfExportProperty::RicfExportProperty()
|
|
|
|
{
|
2018-10-11 00:31:15 -05:00
|
|
|
// clang-format off
|
2020-08-21 04:13:07 -05:00
|
|
|
CAF_PDM_InitScriptableField(&m_caseId, "caseId", -1, "Case ID", "", "", "");
|
|
|
|
CAF_PDM_InitScriptableField(&m_timeStepIndex, "timeStep", -1, "Time Step Index", "", "", "");
|
|
|
|
CAF_PDM_InitScriptableField(&m_propertyName, "property", QString(), "Property Name", "", "", "");
|
|
|
|
CAF_PDM_InitScriptableField(&m_eclipseKeyword, "eclipseKeyword", QString(), "Eclipse Keyword", "", "", "");
|
|
|
|
CAF_PDM_InitScriptableField(&m_undefinedValue, "undefinedValue", 0.0, "Undefined Value", "", "", "");
|
|
|
|
CAF_PDM_InitScriptableField(&m_exportFileName, "exportFile", QString(), "Export FileName", "", "", "");
|
2018-10-11 00:31:15 -05:00
|
|
|
// clang-format on
|
2017-07-27 03:23:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-10-11 00:31:15 -05:00
|
|
|
///
|
2017-07-27 03:23:05 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-03-10 08:11:22 -05:00
|
|
|
caf::PdmScriptResponse RicfExportProperty::execute()
|
2017-07-27 03:23:05 -05:00
|
|
|
{
|
2018-11-07 08:42:45 -06:00
|
|
|
using TOOLS = RicfApplicationTools;
|
2018-10-11 00:31:15 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
RimEclipseCase* eclipseCase = TOOLS::caseFromId( m_caseId() );
|
2018-11-07 08:42:45 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !eclipseCase )
|
2017-07-27 03:23:05 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
QString error = QString( "exportProperty: Could not find case with ID %1" ).arg( m_caseId() );
|
|
|
|
RiaLogging::error( error );
|
2020-03-10 08:11:22 -05:00
|
|
|
return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, error );
|
2017-07-27 03:23:05 -05:00
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !eclipseCase->eclipseCaseData() )
|
2018-10-05 03:20:38 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !eclipseCase->openReserviorCase() )
|
2019-01-29 03:06:30 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
QString error = QString( "exportProperty: Could not find eclipseCaseData with ID %1" ).arg( m_caseId() );
|
|
|
|
RiaLogging::error( error );
|
2020-03-10 08:11:22 -05:00
|
|
|
return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, error );
|
2019-01-29 03:06:30 -06:00
|
|
|
}
|
2018-10-05 03:20:38 -05:00
|
|
|
}
|
2017-07-27 03:23:05 -05:00
|
|
|
}
|
|
|
|
|
2018-10-11 00:31:15 -05:00
|
|
|
RigEclipseCaseData* eclipseCaseData = eclipseCase->eclipseCaseData();
|
2018-10-03 08:44:38 -05:00
|
|
|
|
2020-04-23 23:53:06 -05:00
|
|
|
RigCaseCellResultsData* cellResultsData = eclipseCaseData->results( RiaDefines::PorosityModelType::MATRIX_MODEL );
|
2018-10-03 08:44:38 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !cellResultsData->ensureKnownResultLoaded( RigEclipseResultAddress( m_propertyName ) ) )
|
2018-10-03 08:44:38 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
QString error = QString( "exportProperty: Could not find result property : %1" ).arg( m_propertyName() );
|
|
|
|
RiaLogging::error( error );
|
2020-03-10 08:11:22 -05:00
|
|
|
return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, error );
|
2018-10-03 08:44:38 -05:00
|
|
|
}
|
2018-10-11 00:31:15 -05:00
|
|
|
|
2018-10-11 00:54:55 -05:00
|
|
|
QString filePath = m_exportFileName;
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( filePath.isNull() )
|
2018-10-03 08:44:38 -05:00
|
|
|
{
|
2020-04-24 01:22:32 -05:00
|
|
|
QDir propertiesDir(
|
|
|
|
RicfCommandFileExecutor::instance()->getExportPath( RicfCommandFileExecutor::ExportType::PROPERTIES ) );
|
2019-09-06 03:40:57 -05:00
|
|
|
QString fileName = QString( "%1-%2" ).arg( eclipseCase->caseUserDescription() ).arg( m_propertyName );
|
|
|
|
fileName = caf::Utils::makeValidFileBasename( fileName );
|
|
|
|
filePath = propertiesDir.filePath( fileName );
|
2018-10-03 08:44:38 -05:00
|
|
|
}
|
|
|
|
|
2018-10-11 00:31:15 -05:00
|
|
|
QString eclipseKeyword = m_eclipseKeyword;
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( eclipseKeyword.isNull() )
|
2018-10-03 08:44:38 -05:00
|
|
|
{
|
2018-10-11 00:31:15 -05:00
|
|
|
eclipseKeyword = m_propertyName;
|
2018-10-03 08:44:38 -05:00
|
|
|
}
|
2017-07-27 03:23:05 -05:00
|
|
|
|
2019-05-23 06:59:19 -05:00
|
|
|
QString errMsg;
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !RicEclipseCellResultToFileImpl::writePropertyToTextFile( filePath,
|
|
|
|
eclipseCase->eclipseCaseData(),
|
|
|
|
m_timeStepIndex,
|
|
|
|
m_propertyName,
|
|
|
|
eclipseKeyword,
|
|
|
|
m_undefinedValue,
|
|
|
|
&errMsg ) )
|
2019-05-23 06:59:19 -05:00
|
|
|
{
|
2020-03-10 08:11:22 -05:00
|
|
|
return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, errMsg );
|
2019-05-23 06:59:19 -05:00
|
|
|
}
|
|
|
|
|
2020-03-10 08:11:22 -05:00
|
|
|
return caf::PdmScriptResponse();
|
2017-07-27 03:23:05 -05:00
|
|
|
}
|