ResInsight/ApplicationLibCode/CommandFileInterface/RicfExportVisibleCells.cpp

137 lines
5.7 KiB
C++
Raw Normal View History

/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil ASA
2018-11-11 07:07:42 -06: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
//
// 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>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicfExportVisibleCells.h"
#include "RiaFilePathTools.h"
#include "RiaViewRedrawScheduler.h"
#include "ExportCommands/RicSaveEclipseInputVisibleCellsFeature.h"
#include "ExportCommands/RicSaveEclipseInputVisibleCellsUi.h"
2018-11-11 07:07:42 -06:00
#include "RicfApplicationTools.h"
#include "RicfCommandFileExecutor.h"
#include "RiaApplication.h"
#include "RiaLogging.h"
#include "RimEclipseCase.h"
2018-11-11 07:07:42 -06:00
#include "RimEclipseCaseCollection.h"
#include "RimEclipseCellColors.h"
2018-11-11 07:07:42 -06:00
#include "RimEclipseView.h"
#include "RimOilField.h"
#include "RimProject.h"
#include "RifEclipseInputFileTools.h"
#include "cafPdmFieldScriptingCapability.h"
#include <cafUtils.h>
#include <QDir>
CAF_PDM_SOURCE_INIT( RicfExportVisibleCells, "exportVisibleCells" );
namespace caf
{
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" );
addItem( RicfExportVisibleCells::ExportKeyword::ACTNUM, "ACTNUM", "ACTNUM" );
2020-04-24 01:22:32 -05:00
setDefault( RicfExportVisibleCells::ExportKeyword::FLUXNUM );
}
2018-11-11 07:07:42 -06:00
} // namespace caf
//--------------------------------------------------------------------------------------------------
2018-11-11 07:07:42 -06:00
///
//--------------------------------------------------------------------------------------------------
RicfExportVisibleCells::RicfExportVisibleCells()
{
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" );
CAF_PDM_InitScriptableField( &m_exportKeyword, "exportKeyword", caf::AppEnum<RicfExportVisibleCells::ExportKeyword>(), "Export Keyword" );
CAF_PDM_InitScriptableField( &m_visibleActiveCellsValue, "visibleActiveCellsValue", 1, "Visible Active Cells Value" );
CAF_PDM_InitScriptableField( &m_hiddenActiveCellsValue, "hiddenActiveCellsValue", 0, "Hidden Active Cells Value" );
CAF_PDM_InitScriptableField( &m_inactiveCellsValue, "inactiveCellsValue", 0, "Inactive Cells Value" );
}
//--------------------------------------------------------------------------------------------------
2018-11-11 07:07:42 -06:00
///
//--------------------------------------------------------------------------------------------------
caf::PdmScriptResponse RicfExportVisibleCells::execute()
{
if ( m_caseId < 0 || ( m_viewName().isEmpty() && m_viewId() < 0 ) )
{
QString error( "exportVisibleCells: CaseId or view name or view id not specified" );
RiaLogging::error( error );
return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, error );
}
RimEclipseView* eclipseView = nullptr;
if ( m_viewId() >= 0 )
{
eclipseView = RicfApplicationTools::viewFromCaseIdAndViewId( m_caseId, m_viewId() );
}
else
{
eclipseView = RicfApplicationTools::viewFromCaseIdAndViewName( m_caseId, m_viewName );
}
if ( !eclipseView )
{
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 ) );
RiaLogging::error( error );
return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, error );
}
2020-04-24 01:22:32 -05:00
QString exportFolder = RicfCommandFileExecutor::instance()->getExportPath( RicfCommandFileExecutor::ExportType::CELLS );
if ( exportFolder.isNull() )
{
2023-11-16 07:24:28 -06:00
exportFolder = RiaApplication::instance()->currentProjectPath();
}
RiaViewRedrawScheduler::instance()->clearViewsScheduledForUpdate();
RicSaveEclipseInputVisibleCellsUi exportSettings;
buildExportSettings( exportFolder, &exportSettings );
RicSaveEclipseInputVisibleCellsFeature::executeCommand( eclipseView, exportSettings, "exportVisibleCells" );
return caf::PdmScriptResponse();
}
//--------------------------------------------------------------------------------------------------
2018-11-11 07:07:42 -06:00
///
//--------------------------------------------------------------------------------------------------
void RicfExportVisibleCells::buildExportSettings( const QString& exportFolder, RicSaveEclipseInputVisibleCellsUi* exportSettings )
{
QDir baseDir( exportFolder );
exportSettings->exportFilename = baseDir.absoluteFilePath( QString( "%1.grdecl" ).arg( m_exportKeyword().text() ) );
if ( m_exportKeyword == ExportKeyword::FLUXNUM )
2018-11-11 07:07:42 -06:00
exportSettings->exportKeyword = RicSaveEclipseInputVisibleCellsUi::FLUXNUM;
else if ( m_exportKeyword == ExportKeyword::MULTNUM )
2018-11-11 07:07:42 -06:00
exportSettings->exportKeyword = RicSaveEclipseInputVisibleCellsUi::MULTNUM;
else if ( m_exportKeyword == ExportKeyword::ACTNUM )
exportSettings->exportKeyword = RicSaveEclipseInputVisibleCellsUi::ACTNUM;
exportSettings->visibleActiveCellsValue = m_visibleActiveCellsValue;
2018-11-11 07:07:42 -06:00
exportSettings->hiddenActiveCellsValue = m_hiddenActiveCellsValue;
exportSettings->inactiveCellsValue = m_inactiveCellsValue;
}