Merge pull request #4848 from OPM/command-line-snapshots

#4847 Command Line Snapshots : Make sure image size is handled correctly
This commit is contained in:
Magne Sjaastad 2019-10-11 14:01:54 +02:00 committed by GitHub
commit 715a1c66e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 181 additions and 74 deletions

View File

@ -39,6 +39,7 @@
#include "ExportCommands/RicSnapshotViewToFileFeature.h"
#include "HoloLensCommands/RicHoloLensSessionManager.h"
#include "RicImportGeneralDataFeature.h"
#include "SummaryPlotCommands/RicSummaryPlotFeatureImpl.h"
#include "Rim2dIntersectionViewCollection.h"
#include "RimAnnotationCollection.h"
@ -90,6 +91,7 @@
#include "Riu3dSelectionManager.h"
#include "RiuDockWidgetTools.h"
#include "RiuMainWindow.h"
#include "RiuMainWindowTools.h"
#include "RiuMdiMaximizeWindowGuard.h"
#include "RiuMessagePanel.h"
#include "RiuPlotMainWindow.h"
@ -133,7 +135,6 @@
#ifdef USE_UNIT_TESTS
#include "gtest/gtest.h"
#endif // USE_UNIT_TESTS
#include "SummaryPlotCommands/RicSummaryPlotFeatureImpl.h"
namespace caf
{
@ -649,15 +650,46 @@ RiaApplication::ApplicationStatus RiaGuiApplication::handleArguments( cvf::Progr
if ( cvf::Option o = progOpt->option( "size" ) )
{
RiuMainWindow* mainWnd = RiuMainWindow::instance();
int width = o.safeValue( 0 ).toInt( -1 );
int height = o.safeValue( 1 ).toInt( -1 );
if ( mainWnd && width > 0 && height > 0 )
int width = o.safeValue( 0 ).toInt( -1 );
int height = o.safeValue( 1 ).toInt( -1 );
if ( width > 0 && height > 0 )
{
mainWnd->resize( width, height );
auto mainWindow = RiuMainWindow::instance();
if ( mainWindow )
{
mainWindow->resize( width, height );
}
auto plotWindow = mainPlotWindow();
if ( plotWindow )
{
plotWindow->resize( width, height );
}
}
}
int snapshotWidth = -1;
int snapshotHeight = -1;
if ( cvf::Option o = progOpt->option( "snapshotsize" ) )
{
int width = o.safeValue( 0 ).toInt( -1 );
int height = o.safeValue( 1 ).toInt( -1 );
if ( width > 0 && height > 0 )
{
snapshotWidth = width;
snapshotHeight = height;
}
}
QString snapshotFolderFromCommandLine;
if ( cvf::Option o = progOpt->option( "snapshotfolder" ) )
{
CVF_ASSERT( o.valueCount() == 1 );
snapshotFolderFromCommandLine = cvfqt::Utils::toQString( o.value( 0 ) );
}
if ( cvf::Option o = progOpt->option( "summaryplot" ) )
{
RicSummaryPlotFeatureImpl::createSummaryPlotsFromArgumentLine( cvfqt::Utils::toQStringList( o.values() ) );
@ -821,31 +853,60 @@ RiaApplication::ApplicationStatus RiaGuiApplication::handleArguments( cvf::Progr
}
}
QString exportFolder = QDir::currentPath() + "/snapshots";
QString snapshotFolder;
if ( snapshotViews )
if ( snapshotFolderFromCommandLine.isEmpty() )
{
RiuMainWindow* mainWnd = RiuMainWindow::instance();
CVF_ASSERT( mainWnd );
mainWnd->hideAllDockWidgets();
RicSnapshotAllViewsToFileFeature::exportSnapshotOfViewsIntoFolder( exportFolder );
mainWnd->loadWinGeoAndDockToolBarLayout();
snapshotFolder = QDir::currentPath() + "/snapshots";
}
else
{
snapshotFolder = snapshotFolderFromCommandLine;
}
if ( snapshotPlots )
{
if ( mainPlotWindow() )
auto mainPlotWnd = mainPlotWindow();
if ( mainPlotWnd )
{
mainPlotWindow()->hideAllDockWidgets();
mainPlotWnd->show();
mainPlotWnd->raise();
RicSnapshotAllPlotsToFileFeature::exportSnapshotOfPlotsIntoFolder( exportFolder );
if ( snapshotHeight > -1 && snapshotWidth > -1 )
{
RiuMainWindowTools::setWindowSizeOnWidgetsInMdiWindows( mainPlotWnd, snapshotWidth, snapshotHeight );
}
mainPlotWindow()->loadWinGeoAndDockToolBarLayout();
processEvents();
RicSnapshotAllPlotsToFileFeature::exportSnapshotOfPlotsIntoFolder( snapshotFolder );
}
}
if ( snapshotViews )
{
auto mainWnd = RiuMainWindow::instance();
mainWnd->show();
mainWnd->raise();
if ( snapshotHeight > -1 && snapshotWidth > -1 )
{
RiuMainWindowTools::setFixedWindowSizeFor3dViews( mainWnd, snapshotWidth, snapshotHeight );
}
processEvents();
RicSnapshotAllViewsToFileFeature::exportSnapshotOfViewsIntoFolder( snapshotFolder );
}
auto mainPlotWnd = mainPlotWindow();
if ( mainPlotWnd )
{
mainPlotWnd->loadWinGeoAndDockToolBarLayout();
}
RiuMainWindow::instance()->loadWinGeoAndDockToolBarLayout();
closeProject();
return EXIT_COMPLETED;

View File

@ -100,6 +100,14 @@ bool RiaArgumentParser::parseArguments( cvf::ProgramOptions* progOpt )
"'commandFileReplaceCases'.\n",
cvf::ProgramOptions::SINGLE_VALUE );
progOpt->registerOption( "snapshotsize",
"<width> <height>",
"Set size of exported snapshot images.",
cvf::ProgramOptions::MULTI_VALUE );
progOpt->registerOption( "snapshotfolder",
"<folder>",
"Set the destination folder for exported snapshot images.\n",
cvf::ProgramOptions::SINGLE_VALUE );
progOpt->registerOption( "savesnapshots",
"all|views|plots",
"Save snapshot of all views or plots to project file location sub folder 'snapshots'. "

View File

@ -34,6 +34,7 @@
#include "RimProject.h"
#include "RiuMainWindow.h"
#include "RiuMainWindowTools.h"
#include "RiuPlotMainWindow.h"
#include "RiuViewer.h"
@ -203,7 +204,7 @@ void RiaRegressionTestRunner::runRegressionTest()
// Wait until all command objects have completed
app->waitUntilCommandObjectsHasBeenProcessed();
regressionTestConfigureProject();
setDefaultFixedWindowSizeFor3dViews();
resizePlotWindows();
@ -469,39 +470,14 @@ void RiaRegressionTestRunner::removeDirectoryWithContent( QDir& dirToDelete )
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaRegressionTestRunner::regressionTestConfigureProject()
void RiaRegressionTestRunner::setDefaultFixedWindowSizeFor3dViews()
{
RiuMainWindow* mainWnd = RiuMainWindow::instance();
if ( !mainWnd ) return;
RimProject* proj = RiaApplication::instance()->project();
if ( !proj ) return;
QSize defaultSize = RiaRegressionTestRunner::regressionDefaultImageSize();
std::vector<RimCase*> projectCases;
proj->allCases( projectCases );
for ( RimCase* cas : projectCases )
{
if ( !cas ) continue;
std::vector<Rim3dView*> views = cas->views();
for ( Rim3dView* riv : views )
{
if ( riv && riv->viewer() )
{
// Make sure all views are maximized for snapshotting
QMdiSubWindow* subWnd = mainWnd->findMdiSubWindow( riv->viewer()->layoutWidget() );
if ( subWnd )
{
subWnd->showMaximized();
}
// This size is set to match the regression test reference images
riv->viewer()->setFixedSize( RiaRegressionTestRunner::regressionDefaultImageSize() );
}
}
}
RiuMainWindowTools::setFixedWindowSizeFor3dViews( mainWnd, defaultSize.width(), defaultSize.height() );
}
//--------------------------------------------------------------------------------------------------
@ -509,34 +485,12 @@ void RiaRegressionTestRunner::regressionTestConfigureProject()
//--------------------------------------------------------------------------------------------------
void RiaRegressionTestRunner::resizePlotWindows()
{
RimProject* proj = RiaApplication::instance()->project();
if ( !proj ) return;
RiuPlotMainWindow* plotMainWindow = RiaGuiApplication::instance()->mainPlotWindow();
if ( !plotMainWindow ) return;
std::vector<RimViewWindow*> viewWindows;
QSize defaultSize = RiaRegressionTestRunner::regressionDefaultImageSize();
proj->mainPlotCollection()->descendantsIncludingThisOfType( viewWindows );
for ( auto viewWindow : viewWindows )
{
if ( viewWindow->isMdiWindow() )
{
QWidget* viewWidget = viewWindow->viewWidget();
if ( viewWidget )
{
QMdiSubWindow* mdiWindow = plotMainWindow->findMdiSubWindow( viewWidget );
if ( mdiWindow )
{
mdiWindow->showNormal();
viewWidget->resize( RiaRegressionTestRunner::regressionDefaultImageSize() );
}
}
}
}
RiuMainWindowTools::setWindowSizeOnWidgetsInMdiWindows( plotMainWindow, defaultSize.width(), defaultSize.height() );
}
//--------------------------------------------------------------------------------------------------

View File

@ -42,7 +42,7 @@ public:
bool useOpenMPForGeometryCreation() const;
static void updateRegressionTest( const QString& testRootPath );
static void regressionTestConfigureProject();
static void setDefaultFixedWindowSizeFor3dViews();
private:
RiaRegressionTestRunner();

View File

@ -59,7 +59,7 @@ RicfCommandResponse RicfOpenProject::execute()
if ( RiaRegressionTestRunner::instance()->isRunningRegressionTests() )
{
RiaRegressionTestRunner::regressionTestConfigureProject();
RiaRegressionTestRunner::setDefaultFixedWindowSizeFor3dViews();
}
RicfCommandFileExecutor::instance()->setLastProjectPath( projectPath );

View File

@ -20,12 +20,24 @@
#include "RiaGuiApplication.h"
#include "RimViewWindow.h"
#include "Rim3dView.h"
#include "RimCase.h"
#include "RimProject.h"
#include "RiuInterfaceToViewWindow.h"
#include "RiuMainWindow.h"
#include "RiuMainWindowBase.h"
#include "RiuPlotMainWindow.h"
#include "RiuViewer.h"
#include "cafPdmUiTreeOrdering.h"
#include "cafPdmUiTreeView.h"
#include <QMainWindow>
#include <QMdiSubWindow>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -82,3 +94,67 @@ void RiuMainWindowTools::collapseSiblings( const caf::PdmUiItem* sourceUiItem )
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuMainWindowTools::setWindowSizeOnWidgetsInMdiWindows( RiuMainWindowBase* mainWindow, int width, int height )
{
if ( !mainWindow ) return;
auto widgets = mainWindow->findChildren<QMdiSubWindow*>();
for ( auto w : widgets )
{
if ( !w ) continue;
w->showNormal();
auto viewWindow = RiuInterfaceToViewWindow::viewWindowFromWidget( w->widget() );
if ( viewWindow && viewWindow->viewWidget() )
{
QWidget* viewWidget = viewWindow->viewWidget();
viewWidget->resize( width, height );
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuMainWindowTools::setFixedWindowSizeFor3dViews( RiuMainWindowBase* mainWindow, int width, int height )
{
if ( !mainWindow ) return;
RimProject* proj = RiaApplication::instance()->project();
if ( !proj ) return;
std::vector<RimCase*> projectCases;
proj->allCases( projectCases );
for ( RimCase* cas : projectCases )
{
if ( !cas ) continue;
std::vector<Rim3dView*> views = cas->views();
for ( Rim3dView* riv : views )
{
if ( riv && riv->viewer() )
{
// Make sure all views are maximized for snapshotting
QMdiSubWindow* subWnd = mainWindow->findMdiSubWindow( riv->viewer()->layoutWidget() );
if ( subWnd )
{
subWnd->showMaximized();
}
// This size is set to match the regression test reference images
QSize windowSize( width, height );
riv->viewer()->setFixedSize( windowSize );
}
}
}
}

View File

@ -23,8 +23,16 @@ namespace caf
class PdmUiItem;
} // namespace caf
class RiuMainWindowBase;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
class RiuMainWindowTools
{
public:
static void collapseSiblings( const caf::PdmUiItem* uiItem );
static void setWindowSizeOnWidgetsInMdiWindows( RiuMainWindowBase* mainWindow, int width, int height );
static void setFixedWindowSizeFor3dViews( RiuMainWindowBase* mainWindow, int width, int height );
};