2017-07-27 03:12:57 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2017 Statoil ASA
|
2018-11-21 03:26:46 -06:00
|
|
|
//
|
2017-07-27 03:12:57 -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-21 03:26:46 -06:00
|
|
|
//
|
2017-07-27 03:12:57 -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-21 03:26:46 -06:00
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2017-07-27 03:12:57 -05:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RicfExportSnapshots.h"
|
|
|
|
|
|
|
|
#include "RicfCommandFileExecutor.h"
|
|
|
|
|
2017-08-03 09:22:02 -05:00
|
|
|
#include "ExportCommands/RicSnapshotAllPlotsToFileFeature.h"
|
2017-08-04 04:25:17 -05:00
|
|
|
#include "ExportCommands/RicSnapshotAllViewsToFileFeature.h"
|
2017-07-27 03:12:57 -05:00
|
|
|
|
2019-05-06 03:36:05 -05:00
|
|
|
#include "RiaGuiApplication.h"
|
|
|
|
#include "RiaLogging.h"
|
2019-12-05 02:25:44 -06:00
|
|
|
#include "RiaRegressionTestRunner.h"
|
2017-07-27 03:12:57 -05:00
|
|
|
|
2022-08-10 10:06:13 -05:00
|
|
|
#include "RiuDockWidgetTools.h"
|
2017-07-27 03:12:57 -05:00
|
|
|
#include "RiuMainWindow.h"
|
|
|
|
|
2023-02-02 00:41:45 -06:00
|
|
|
#include "DockManager.h"
|
|
|
|
|
2020-08-21 04:13:07 -05:00
|
|
|
#include "cafPdmFieldScriptingCapability.h"
|
2020-03-10 08:11:22 -05:00
|
|
|
|
2017-07-27 03:12:57 -05:00
|
|
|
#include <QFileInfo>
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
CAF_PDM_SOURCE_INIT( RicfExportSnapshots, "exportSnapshots" );
|
2017-07-27 03:12:57 -05:00
|
|
|
|
2018-11-21 03:26:46 -06:00
|
|
|
namespace caf
|
|
|
|
{
|
2020-01-21 05:36:22 -06:00
|
|
|
template <>
|
|
|
|
void RicfExportSnapshots::PreferredOutputFormatEnum::setUp()
|
|
|
|
{
|
|
|
|
addItem( RicfExportSnapshots::PlotOutputFormat::PNG, "PNG", "PNG" );
|
|
|
|
addItem( RicfExportSnapshots::PlotOutputFormat::PDF, "PDF", "PDF" );
|
|
|
|
setDefault( RicfExportSnapshots::PlotOutputFormat::PNG );
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
template <>
|
2018-11-21 03:26:46 -06:00
|
|
|
void RicfExportSnapshots::SnapshotsTypeEnum::setUp()
|
|
|
|
{
|
2020-04-24 01:22:32 -05:00
|
|
|
addItem( RicfExportSnapshots::SnapshotsType::ALL, "ALL", "All" );
|
|
|
|
addItem( RicfExportSnapshots::SnapshotsType::VIEWS, "VIEWS", "Views" );
|
|
|
|
addItem( RicfExportSnapshots::SnapshotsType::PLOTS, "PLOTS", "Plots" );
|
|
|
|
setDefault( RicfExportSnapshots::SnapshotsType::ALL );
|
2017-07-27 03:12:57 -05:00
|
|
|
}
|
2018-11-21 03:26:46 -06:00
|
|
|
} // namespace caf
|
2017-07-27 03:12:57 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-21 03:26:46 -06:00
|
|
|
///
|
2017-07-27 03:12:57 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RicfExportSnapshots::RicfExportSnapshots()
|
|
|
|
{
|
2021-11-14 07:15:12 -06:00
|
|
|
CAF_PDM_InitScriptableField( &m_type, "type", RicfExportSnapshots::SnapshotsTypeEnum(), "Type" );
|
|
|
|
CAF_PDM_InitScriptableField( &m_prefix, "prefix", QString(), "Prefix" );
|
|
|
|
CAF_PDM_InitScriptableField( &m_caseId, "caseId", -1, "Case Id" );
|
|
|
|
CAF_PDM_InitScriptableField( &m_viewId, "viewId", -1, "View Id" );
|
|
|
|
CAF_PDM_InitScriptableField( &m_exportFolder, "exportFolder", QString(), "Export Folder" );
|
|
|
|
CAF_PDM_InitScriptableFieldNoDefault( &m_plotOutputFormat, "plotOutputFormat", "Output Format" );
|
2017-07-27 03:12:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-21 03:26:46 -06:00
|
|
|
///
|
2017-07-27 03:12:57 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-03-10 08:11:22 -05:00
|
|
|
caf::PdmScriptResponse RicfExportSnapshots::execute()
|
2017-07-27 03:12:57 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !RiaGuiApplication::isRunning() )
|
2019-05-06 03:36:05 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
QString error( "RicfExportSnapshot: Command cannot run without a GUI" );
|
|
|
|
RiaLogging::error( error );
|
2020-03-10 08:11:22 -05:00
|
|
|
return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, error );
|
2019-05-06 03:36:05 -05:00
|
|
|
}
|
|
|
|
|
2017-07-27 03:12:57 -05:00
|
|
|
RiuMainWindow* mainWnd = RiuMainWindow::instance();
|
2019-09-06 03:40:57 -05:00
|
|
|
CVF_ASSERT( mainWnd );
|
2022-08-10 10:06:13 -05:00
|
|
|
|
|
|
|
QByteArray curState = mainWnd->dockManager()->saveState( 0 );
|
2023-02-26 03:48:40 -06:00
|
|
|
mainWnd->dockManager()->restoreState( RiuDockWidgetTools::defaultDockState( RiuDockWidgetTools::dockStateHideAll3DWindowName() ) );
|
2022-08-10 10:06:13 -05:00
|
|
|
|
2023-10-03 02:04:08 -05:00
|
|
|
QApplication::processEvents();
|
2017-07-27 03:12:57 -05:00
|
|
|
|
2023-02-26 03:48:40 -06:00
|
|
|
QString absolutePathToSnapshotDir = RicfCommandFileExecutor::instance()->getExportPath( RicfCommandFileExecutor::ExportType::SNAPSHOTS );
|
2019-10-09 02:21:28 -05:00
|
|
|
|
|
|
|
if ( !m_exportFolder().isEmpty() )
|
|
|
|
{
|
|
|
|
absolutePathToSnapshotDir = m_exportFolder;
|
|
|
|
}
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( absolutePathToSnapshotDir.isNull() )
|
2017-07-27 03:12:57 -05:00
|
|
|
{
|
2023-02-26 03:48:40 -06:00
|
|
|
absolutePathToSnapshotDir = RiaApplication::instance()->createAbsolutePathFromProjectRelativePath( "snapshots" );
|
2017-07-27 03:12:57 -05:00
|
|
|
}
|
2020-04-24 01:22:32 -05:00
|
|
|
if ( m_type == RicfExportSnapshots::SnapshotsType::VIEWS || m_type == RicfExportSnapshots::SnapshotsType::ALL )
|
2017-07-27 03:12:57 -05:00
|
|
|
{
|
2019-12-05 02:25:44 -06:00
|
|
|
if ( RiaRegressionTestRunner::instance()->isRunningRegressionTests() )
|
|
|
|
{
|
|
|
|
RiaRegressionTestRunner::setDefaultSnapshotSizeFor3dViews();
|
|
|
|
|
|
|
|
QApplication::processEvents();
|
|
|
|
}
|
|
|
|
|
2023-02-26 03:48:40 -06:00
|
|
|
RicSnapshotAllViewsToFileFeature::exportSnapshotOfViewsIntoFolder( absolutePathToSnapshotDir, m_prefix, m_caseId(), m_viewId() );
|
2017-07-27 03:12:57 -05:00
|
|
|
}
|
2020-04-24 01:22:32 -05:00
|
|
|
if ( m_type == RicfExportSnapshots::SnapshotsType::PLOTS || m_type == RicfExportSnapshots::SnapshotsType::ALL )
|
2017-07-27 03:12:57 -05:00
|
|
|
{
|
2020-08-28 06:19:51 -05:00
|
|
|
bool activateWidget = false;
|
2019-12-05 02:25:44 -06:00
|
|
|
if ( RiaRegressionTestRunner::instance()->isRunningRegressionTests() )
|
|
|
|
{
|
|
|
|
RiaRegressionTestRunner::setDefaultSnapshotSizeForPlotWindows();
|
|
|
|
|
|
|
|
QApplication::processEvents();
|
|
|
|
}
|
2020-08-28 06:19:51 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
activateWidget = true;
|
|
|
|
}
|
2019-12-05 02:25:44 -06:00
|
|
|
|
2020-01-21 05:36:22 -06:00
|
|
|
QString fileSuffix = ".png";
|
|
|
|
if ( m_plotOutputFormat == PlotOutputFormat::PDF ) fileSuffix = ".pdf";
|
2023-02-26 03:48:40 -06:00
|
|
|
RicSnapshotAllPlotsToFileFeature::exportSnapshotOfPlotsIntoFolder( absolutePathToSnapshotDir, activateWidget, m_prefix, m_viewId(), fileSuffix );
|
2017-07-27 03:12:57 -05:00
|
|
|
}
|
|
|
|
|
2023-10-03 02:04:08 -05:00
|
|
|
QApplication::processEvents();
|
2019-05-23 06:59:19 -05:00
|
|
|
|
2022-08-10 10:06:13 -05:00
|
|
|
mainWnd->dockManager()->restoreState( curState );
|
|
|
|
|
2020-03-10 08:11:22 -05:00
|
|
|
return caf::PdmScriptResponse();
|
2017-07-27 03:12:57 -05:00
|
|
|
}
|