2018-10-04 06:50:29 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2017 Statoil ASA
|
2018-11-11 07:07:42 -06:00
|
|
|
//
|
2018-10-04 06:50:29 -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-11-11 07:07:42 -06:00
|
|
|
//
|
2018-10-04 06:50:29 -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-11-11 07:07:42 -06:00
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2018-10-04 06:50:29 -05:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RicfExportVisibleCells.h"
|
|
|
|
|
|
|
|
#include "RiaFilePathTools.h"
|
2018-11-11 07:07:06 -06:00
|
|
|
#include "RiaViewRedrawScheduler.h"
|
2018-10-04 06:50:29 -05:00
|
|
|
|
2019-04-25 08:29:46 -05:00
|
|
|
#include "ExportCommands/RicSaveEclipseInputVisibleCellsFeature.h"
|
|
|
|
#include "ExportCommands/RicSaveEclipseInputVisibleCellsUi.h"
|
2018-11-11 07:07:42 -06:00
|
|
|
#include "RicfApplicationTools.h"
|
|
|
|
#include "RicfCommandFileExecutor.h"
|
2018-10-04 06:50:29 -05:00
|
|
|
|
|
|
|
#include "RiaApplication.h"
|
|
|
|
#include "RiaLogging.h"
|
|
|
|
|
|
|
|
#include "RimEclipseCase.h"
|
2018-11-11 07:07:42 -06:00
|
|
|
#include "RimEclipseCaseCollection.h"
|
2018-10-04 06:50:29 -05:00
|
|
|
#include "RimEclipseCellColors.h"
|
2018-11-11 07:07:42 -06:00
|
|
|
#include "RimEclipseView.h"
|
|
|
|
#include "RimOilField.h"
|
|
|
|
#include "RimProject.h"
|
2018-10-04 06:50:29 -05:00
|
|
|
|
|
|
|
#include "RifEclipseInputFileTools.h"
|
|
|
|
|
2020-08-21 04:13:07 -05:00
|
|
|
#include "cafPdmFieldScriptingCapability.h"
|
2018-10-04 06:50:29 -05:00
|
|
|
#include <cafUtils.h>
|
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
CAF_PDM_SOURCE_INIT( RicfExportVisibleCells, "exportVisibleCells" );
|
2018-10-04 06:50:29 -05:00
|
|
|
|
|
|
|
namespace caf
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
template <>
|
2018-11-11 07:07:42 -06:00
|
|
|
void AppEnum<RicfExportVisibleCells::ExportKeyword>::setUp()
|
|
|
|
{
|
2020-04-24 01:22:32 -05:00
|
|
|
addItem( RicfExportVisibleCells::ExportKeyword::FLUXNUM, "FLUXNUM", "FLUXNUM" );
|
|
|
|
addItem( RicfExportVisibleCells::ExportKeyword::MULTNUM, "MULTNUM", "MULTNUM" );
|
2021-04-23 01:25:51 -05:00
|
|
|
addItem( RicfExportVisibleCells::ExportKeyword::ACTNUM, "ACTNUM", "ACTNUM" );
|
2018-10-04 06:50:29 -05:00
|
|
|
|
2020-04-24 01:22:32 -05:00
|
|
|
setDefault( RicfExportVisibleCells::ExportKeyword::FLUXNUM );
|
2018-10-04 06:50:29 -05:00
|
|
|
}
|
2018-11-11 07:07:42 -06:00
|
|
|
} // namespace caf
|
2018-10-04 06:50:29 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-11 07:07:42 -06:00
|
|
|
///
|
2018-10-04 06:50:29 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RicfExportVisibleCells::RicfExportVisibleCells()
|
|
|
|
{
|
2021-11-14 07:15:12 -06:00
|
|
|
CAF_PDM_InitScriptableField( &m_caseId, "caseId", -1, "Case ID" );
|
|
|
|
CAF_PDM_InitScriptableField( &m_viewId, "viewId", -1, "View ID" );
|
|
|
|
CAF_PDM_InitScriptableField( &m_viewName, "viewName", QString(), "View Name" );
|
2023-02-26 03:48:40 -06:00
|
|
|
CAF_PDM_InitScriptableField( &m_exportKeyword, "exportKeyword", caf::AppEnum<RicfExportVisibleCells::ExportKeyword>(), "Export Keyword" );
|
2022-01-07 01:31:52 -06:00
|
|
|
CAF_PDM_InitScriptableField( &m_visibleActiveCellsValue, "visibleActiveCellsValue", 1, "Visible Active Cells Value" );
|
2021-11-14 07:15:12 -06:00
|
|
|
CAF_PDM_InitScriptableField( &m_hiddenActiveCellsValue, "hiddenActiveCellsValue", 0, "Hidden Active Cells Value" );
|
|
|
|
CAF_PDM_InitScriptableField( &m_inactiveCellsValue, "inactiveCellsValue", 0, "Inactive Cells Value" );
|
2018-10-04 06:50:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-11 07:07:42 -06:00
|
|
|
///
|
2018-10-04 06:50:29 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-03-10 08:11:22 -05:00
|
|
|
caf::PdmScriptResponse RicfExportVisibleCells::execute()
|
2018-10-04 06:50:29 -05:00
|
|
|
{
|
2019-09-23 04:50:33 -05:00
|
|
|
if ( m_caseId < 0 || ( m_viewName().isEmpty() && m_viewId() < 0 ) )
|
2018-10-04 06:50:29 -05:00
|
|
|
{
|
2019-09-23 04:50:33 -05:00
|
|
|
QString error( "exportVisibleCells: CaseId or view name or view id not specified" );
|
2019-09-06 03:40:57 -05:00
|
|
|
RiaLogging::error( error );
|
2020-03-10 08:11:22 -05:00
|
|
|
return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, error );
|
2018-10-04 06:50:29 -05:00
|
|
|
}
|
2019-09-23 04:50:33 -05:00
|
|
|
RimEclipseView* eclipseView = nullptr;
|
|
|
|
if ( m_viewId() >= 0 )
|
|
|
|
{
|
|
|
|
eclipseView = RicfApplicationTools::viewFromCaseIdAndViewId( m_caseId, m_viewId() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
eclipseView = RicfApplicationTools::viewFromCaseIdAndViewName( m_caseId, m_viewName );
|
|
|
|
}
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !eclipseView )
|
2018-10-04 06:50:29 -05:00
|
|
|
{
|
2023-02-26 03:48:40 -06:00
|
|
|
QString error(
|
|
|
|
QString( "exportVisibleCells: Could not find view of id %1 or named '%2' in case ID %3" ).arg( m_viewId ).arg( m_viewName ).arg( m_caseId ) );
|
2019-09-06 03:40:57 -05:00
|
|
|
RiaLogging::error( error );
|
2020-03-10 08:11:22 -05:00
|
|
|
return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, error );
|
2018-10-04 06:50:29 -05:00
|
|
|
}
|
|
|
|
|
2020-04-24 01:22:32 -05:00
|
|
|
QString exportFolder = RicfCommandFileExecutor::instance()->getExportPath( RicfCommandFileExecutor::ExportType::CELLS );
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( exportFolder.isNull() )
|
2018-10-04 06:50:29 -05:00
|
|
|
{
|
2023-11-16 07:24:28 -06:00
|
|
|
exportFolder = RiaApplication::instance()->currentProjectPath();
|
2018-10-04 06:50:29 -05:00
|
|
|
}
|
|
|
|
|
2018-11-11 07:07:06 -06:00
|
|
|
RiaViewRedrawScheduler::instance()->clearViewsScheduledForUpdate();
|
|
|
|
|
2019-04-25 08:29:46 -05:00
|
|
|
RicSaveEclipseInputVisibleCellsUi exportSettings;
|
2019-09-06 03:40:57 -05:00
|
|
|
buildExportSettings( exportFolder, &exportSettings );
|
|
|
|
RicSaveEclipseInputVisibleCellsFeature::executeCommand( eclipseView, exportSettings, "exportVisibleCells" );
|
2019-05-23 06:59:19 -05:00
|
|
|
|
2020-03-10 08:11:22 -05:00
|
|
|
return caf::PdmScriptResponse();
|
2018-10-04 06:50:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-11 07:07:42 -06:00
|
|
|
///
|
2018-10-04 06:50:29 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2023-02-26 03:48:40 -06:00
|
|
|
void RicfExportVisibleCells::buildExportSettings( const QString& exportFolder, RicSaveEclipseInputVisibleCellsUi* exportSettings )
|
2018-10-04 06:50:29 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
QDir baseDir( exportFolder );
|
|
|
|
exportSettings->exportFilename = baseDir.absoluteFilePath( QString( "%1.grdecl" ).arg( m_exportKeyword().text() ) );
|
2018-10-04 06:50:29 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( m_exportKeyword == ExportKeyword::FLUXNUM )
|
2018-11-11 07:07:42 -06:00
|
|
|
exportSettings->exportKeyword = RicSaveEclipseInputVisibleCellsUi::FLUXNUM;
|
2019-09-06 03:40:57 -05:00
|
|
|
else if ( m_exportKeyword == ExportKeyword::MULTNUM )
|
2018-11-11 07:07:42 -06:00
|
|
|
exportSettings->exportKeyword = RicSaveEclipseInputVisibleCellsUi::MULTNUM;
|
2021-04-23 01:25:51 -05:00
|
|
|
else if ( m_exportKeyword == ExportKeyword::ACTNUM )
|
|
|
|
exportSettings->exportKeyword = RicSaveEclipseInputVisibleCellsUi::ACTNUM;
|
2018-10-04 06:50:29 -05:00
|
|
|
|
|
|
|
exportSettings->visibleActiveCellsValue = m_visibleActiveCellsValue;
|
2018-11-11 07:07:42 -06:00
|
|
|
exportSettings->hiddenActiveCellsValue = m_hiddenActiveCellsValue;
|
2019-04-25 08:29:46 -05:00
|
|
|
exportSettings->inactiveCellsValue = m_inactiveCellsValue;
|
2018-10-04 06:50:29 -05:00
|
|
|
}
|