-
Notifications
You must be signed in to change notification settings - Fork 102
Expand file tree
/
Copy pathRicfExportProperty.cpp
More file actions
127 lines (107 loc) · 5.21 KB
/
Copy pathRicfExportProperty.cpp
File metadata and controls
127 lines (107 loc) · 5.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil 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 "RicfExportProperty.h"
#include "RiaLogging.h"
#include "ExportCommands/RicEclipseCellResultToFileImpl.h"
#include "RicfApplicationTools.h"
#include "RicfCommandFileExecutor.h"
#include "RifEclipseInputFileTools.h"
#include "RigCaseCellResultsData.h"
#include "RigEclipseCaseData.h"
#include "RigEclipseResultAddress.h"
#include "RimEclipseCase.h"
#include "RimEclipseCaseCollection.h"
#include "RimEclipseCellColors.h"
#include "RimEclipseView.h"
#include "RimProject.h"
#include "cafPdmFieldScriptingCapability.h"
#include "cafUtils.h"
#include <QDir>
CAF_PDM_SOURCE_INIT( RicfExportProperty, "exportProperty" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicfExportProperty::RicfExportProperty()
{
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" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmScriptResponse RicfExportProperty::execute()
{
using TOOLS = RicfApplicationTools;
RimEclipseCase* eclipseCase = TOOLS::caseFromId( m_caseId() );
{
if ( !eclipseCase )
{
QString error = QString( "exportProperty: Could not find case with ID %1" ).arg( m_caseId() );
RiaLogging::error( error.toStdString() );
return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, error );
}
if ( !eclipseCase->eclipseCaseData() )
{
if ( !eclipseCase->openReservoirCase() )
{
QString error = QString( "exportProperty: Could not find eclipseCaseData with ID %1" ).arg( m_caseId() );
RiaLogging::error( error.toStdString() );
return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, error );
}
}
}
RigEclipseCaseData* eclipseCaseData = eclipseCase->eclipseCaseData();
RigCaseCellResultsData* cellResultsData = eclipseCaseData->results( RiaDefines::PorosityModelType::MATRIX_MODEL );
if ( !cellResultsData->ensureKnownResultLoaded( RigEclipseResultAddress( m_propertyName ) ) )
{
QString error = QString( "exportProperty: Could not find result property : %1" ).arg( m_propertyName() );
RiaLogging::error( error.toStdString() );
return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, error );
}
QString filePath = m_exportFileName;
if ( filePath.isNull() )
{
QDir propertiesDir( RicfCommandFileExecutor::instance()->getExportPath( RicfCommandFileExecutor::ExportType::PROPERTIES ) );
QString fileName = QString( "%1-%2" ).arg( eclipseCase->caseUserDescription() ).arg( m_propertyName );
fileName = caf::Utils::makeValidFileBasename( fileName );
filePath = propertiesDir.filePath( fileName );
}
QString eclipseKeyword = m_eclipseKeyword;
if ( eclipseKeyword.isNull() )
{
eclipseKeyword = m_propertyName;
}
bool writeEchoKeywords = false;
QString errMsg;
if ( !RicEclipseCellResultToFileImpl::writePropertyToTextFile( filePath,
eclipseCase->eclipseCaseData(),
m_timeStepIndex,
m_propertyName,
eclipseKeyword,
m_undefinedValue,
writeEchoKeywords,
&errMsg ) )
{
return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, errMsg );
}
return caf::PdmScriptResponse();
}