Snapshot work in progress

This commit is contained in:
jonjenssen
2026-06-17 13:55:32 +02:00
committed by JJ
parent 361b4bc3db
commit 52df6fd283
20 changed files with 103 additions and 89 deletions
@@ -887,15 +887,9 @@ RiaApplication::ApplicationStatus RiaGuiApplication::handleArguments( gsl::not_n
mainPlotWnd->show();
mainPlotWnd->raise();
if ( snapshotHeight > -1 && snapshotWidth > -1 )
{
// TODO - handle snapshot view sizes
// RiuMainWindowTools::setWindowSizeOnWidgetsInViewWindows( mainPlotWnd, snapshotWidth, snapshotHeight );
}
processEvents();
RicSnapshotAllPlotsToFileFeature::exportSnapshotOfPlotsIntoFolder( snapshotFolder );
RicSnapshotAllPlotsToFileFeature::exportSnapshotOfPlotsIntoFolder( snapshotFolder, snapshotWidth, snapshotHeight );
}
}
@@ -905,15 +899,9 @@ RiaApplication::ApplicationStatus RiaGuiApplication::handleArguments( gsl::not_n
mainWnd->show();
mainWnd->raise();
if ( snapshotHeight > -1 && snapshotWidth > -1 )
{
// TODO - handle snapshot view sizes
// RiuMainWindowTools::setFixedWindowSizeFor3dViews( mainWnd, snapshotWidth, snapshotHeight );
}
processEvents();
RicSnapshotAllViewsToFileFeature::exportSnapshotOfViewsIntoFolder( snapshotFolder );
RicSnapshotAllViewsToFileFeature::exportSnapshotOfViewsIntoFolder( snapshotFolder, snapshotWidth, snapshotHeight );
}
auto mainPlotWnd = mainPlotWindow();
@@ -249,18 +249,20 @@ void RiaRegressionTestRunner::runRegressionTest()
QString fullPathGeneratedFolder = testCaseFolder.absoluteFilePath( generatedFolderName );
if ( regressionTestConfig.exportSnapshots3dViews )
{
setDefaultSnapshotSizeFor3dViews();
RicSnapshotAllViewsToFileFeature::exportSnapshotOfViewsIntoFolder( fullPathGeneratedFolder );
QSize defaultSize = RiaRegressionTestRunner::regressionDefaultImageSize();
RicSnapshotAllViewsToFileFeature::exportSnapshotOfViewsIntoFolder( fullPathGeneratedFolder,
defaultSize.width(),
defaultSize.height() );
QApplication::processEvents();
}
if ( regressionTestConfig.exportSnapshotsPlots )
{
setDefaultSnapshotSizeForPlotWindows();
RicSnapshotAllPlotsToFileFeature::exportSnapshotOfPlotsIntoFolder( fullPathGeneratedFolder );
QSize defaultSize = RiaRegressionTestRunner::regressionDefaultImageSize();
RicSnapshotAllPlotsToFileFeature::exportSnapshotOfPlotsIntoFolder( fullPathGeneratedFolder,
defaultSize.width(),
defaultSize.height() );
}
uint64_t usedMemoryBeforeClose = caf::MemoryInspector::getApplicationPhysicalMemoryUsageMiB();
@@ -546,32 +548,6 @@ void RiaRegressionTestRunner::removeDirectoryWithContent( QDir& dirToDelete )
caf::Utils::removeDirectoryAndFilesRecursively( dirToDelete.absolutePath() );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaRegressionTestRunner::setDefaultSnapshotSizeFor3dViews()
{
RiuMainWindow* mainWnd = RiuMainWindow::instance();
if ( !mainWnd ) return;
// TODO - fix snapshot view sizes
// QSize defaultSize = RiaRegressionTestRunner::regressionDefaultImageSize();
// RiuMainWindowTools::setFixedWindowSizeFor3dViews( mainWnd, defaultSize.width(), defaultSize.height() );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaRegressionTestRunner::setDefaultSnapshotSizeForPlotWindows()
{
RiuPlotMainWindow* plotMainWindow = RiaGuiApplication::instance()->mainPlotWindow();
if ( !plotMainWindow ) return;
// TODO - fix snapshot view sizes
// QSize defaultSize = RiaRegressionTestRunner::regressionDefaultImageSize();
// RiuMainWindowTools::setWindowSizeOnWidgetsInViewWindows( plotMainWindow, defaultSize.width(), defaultSize.height() );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -45,8 +45,7 @@ public:
static void updateRegressionTest( const QString& testRootPath );
static void setDefaultSnapshotSizeFor3dViews();
static void setDefaultSnapshotSizeForPlotWindows();
static QSize regressionDefaultImageSize();
private:
RiaRegressionTestRunner();
@@ -64,7 +63,6 @@ private:
const QDir& testDir );
static void removeDirectoryWithContent( QDir& dirToDelete );
static QSize regressionDefaultImageSize();
static QString diff2htmlHeaderText( const QString& testRootPath );
QFileInfoList subDirectoriesForTestExecution( const QDir& directory );
@@ -69,6 +69,8 @@ RicfExportSnapshots::RicfExportSnapshots()
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" );
CAF_PDM_InitScriptableField( &m_width, "width", -1, "Width" );
CAF_PDM_InitScriptableField( &m_height, "height", -1, "Height" );
}
//--------------------------------------------------------------------------------------------------
@@ -83,13 +85,16 @@ caf::PdmScriptResponse RicfExportSnapshots::execute()
return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, error );
}
int width = m_width();
int height = m_height();
RiuMainWindow* mainWnd = RiuMainWindow::instance();
CVF_ASSERT( mainWnd );
QByteArray curState = mainWnd->dockManager()->saveState( 0 );
mainWnd->dockManager()->restoreState( RiuDockWidgetTools::defaultDockState( RiuDockWidgetTools::dockStateHideAll3DWindowName() ) );
// QByteArray curState = mainWnd->dockManager()->saveState( 0 );
// mainWnd->dockManager()->restoreState( RiuDockWidgetTools::defaultDockState( RiuDockWidgetTools::dockStateHideAll3DWindowName() ) );
QApplication::processEvents();
// QApplication::processEvents();
QString absolutePathToSnapshotDir = RicfCommandFileExecutor::instance()->getExportPath( RicfCommandFileExecutor::ExportType::SNAPSHOTS );
@@ -105,21 +110,26 @@ caf::PdmScriptResponse RicfExportSnapshots::execute()
{
if ( RiaRegressionTestRunner::instance()->isRunningRegressionTests() )
{
RiaRegressionTestRunner::setDefaultSnapshotSizeFor3dViews();
QApplication::processEvents();
QSize defaultSize = RiaRegressionTestRunner::regressionDefaultImageSize();
width = defaultSize.width();
height = defaultSize.height();
}
RicSnapshotAllViewsToFileFeature::exportSnapshotOfViewsIntoFolder( absolutePathToSnapshotDir, m_prefix, m_caseId(), m_viewId() );
RicSnapshotAllViewsToFileFeature::exportSnapshotOfViewsIntoFolder( absolutePathToSnapshotDir,
width,
height,
m_prefix,
m_caseId(),
m_viewId() );
}
if ( m_type == RicfExportSnapshots::SnapshotsType::PLOTS || m_type == RicfExportSnapshots::SnapshotsType::ALL )
{
bool activateWidget = false;
if ( RiaRegressionTestRunner::instance()->isRunningRegressionTests() )
{
RiaRegressionTestRunner::setDefaultSnapshotSizeForPlotWindows();
QApplication::processEvents();
QSize defaultSize = RiaRegressionTestRunner::regressionDefaultImageSize();
width = defaultSize.width();
height = defaultSize.height();
}
else
{
@@ -128,12 +138,18 @@ caf::PdmScriptResponse RicfExportSnapshots::execute()
QString fileSuffix = ".png";
if ( m_plotOutputFormat == PlotOutputFormat::PDF ) fileSuffix = ".pdf";
RicSnapshotAllPlotsToFileFeature::exportSnapshotOfPlotsIntoFolder( absolutePathToSnapshotDir, activateWidget, m_prefix, m_viewId(), fileSuffix );
RicSnapshotAllPlotsToFileFeature::exportSnapshotOfPlotsIntoFolder( absolutePathToSnapshotDir,
width,
height,
activateWidget,
m_prefix,
m_viewId(),
fileSuffix );
}
QApplication::processEvents();
mainWnd->dockManager()->restoreState( curState );
// mainWnd->dockManager()->restoreState( curState );
return caf::PdmScriptResponse();
}
@@ -62,4 +62,6 @@ private:
caf::PdmField<int> m_viewId;
caf::PdmField<QString> m_exportFolder;
caf::PdmField<PreferredOutputFormatEnum> m_plotOutputFormat;
caf::PdmField<int> m_width;
caf::PdmField<int> m_height;
};
@@ -19,6 +19,8 @@
#include "RicfSetMainWindowSize.h"
#include "RiaLogging.h"
#include "RiuMainWindow.h"
#include "cafPdmFieldScriptingCapability.h"
@@ -39,6 +41,6 @@ RicfSetMainWindowSize::RicfSetMainWindowSize()
//--------------------------------------------------------------------------------------------------
caf::PdmScriptResponse RicfSetMainWindowSize::execute()
{
if ( RiuMainWindow::instance() ) RiuMainWindow::instance()->resize( m_width, m_height );
RiaLogging::warning( "Method set_main_window_size has been obsoleted. Set size of image snapshots directly in the snapshot methods." );
return caf::PdmScriptResponse();
}
@@ -56,8 +56,8 @@ void RicSnapshotAllPlotsToFileFeature::saveAllPlots()
// Save images in snapshot catalog relative to project directory
QString snapshotFolderName = app->createAbsolutePathFromProjectRelativePath( "snapshots" );
bool activateWidget = true;
exportSnapshotOfPlotsIntoFolder( snapshotFolderName, activateWidget );
// save using existing plot sizes
exportSnapshotOfPlotsIntoFolder( snapshotFolderName, -1, -1, true /* activateWidget */ );
QString text = QString( "Exported snapshots to folder : \n%1" ).arg( snapshotFolderName );
RiaLogging::info( text.toStdString() );
@@ -67,6 +67,8 @@ void RicSnapshotAllPlotsToFileFeature::saveAllPlots()
///
//--------------------------------------------------------------------------------------------------
void RicSnapshotAllPlotsToFileFeature::exportSnapshotOfPlotsIntoFolder( const QString& snapshotFolderName,
int width,
int height,
bool activateWidget,
const QString& prefix,
int viewId,
@@ -106,7 +108,7 @@ void RicSnapshotAllPlotsToFileFeature::exportSnapshotOfPlotsIntoFolder( const QS
QString absoluteFileName = caf::Utils::constructFullFileName( absSnapshotPath, fileName, preferredFileSuffix );
RicSnapshotViewToFileFeature::saveSnapshotAs( absoluteFileName, viewWindow );
RicSnapshotViewToFileFeature::saveSnapshotAs( absoluteFileName, viewWindow, width, height );
}
}
}
@@ -33,6 +33,8 @@ public:
static void saveAllPlots();
static void exportSnapshotOfPlotsIntoFolder( const QString& snapshotFolderName,
int width = -1,
int height = -1,
bool activateWidget = false,
const QString& prefix = "",
int viewId = -1,
@@ -70,11 +70,14 @@ void RicSnapshotAllViewsToFileFeature::saveAllViews()
//--------------------------------------------------------------------------------------------------
/// Export snapshots of a given view (or viewId == -1 for all views) for the given case (or caseId == -1 for all cases)
/// -1 for width and height means to use the existing view size
//--------------------------------------------------------------------------------------------------
void RicSnapshotAllViewsToFileFeature::exportSnapshotOfViewsIntoFolder( const QString& snapshotFolderName,
const QString& prefix /*= ""*/,
int caseId /*= -1*/,
int viewId /*= -1*/ )
int width,
int height,
const QString& prefix,
int caseId,
int viewId )
{
RimProject* project = RimProject::current();
if ( project == nullptr ) return;
@@ -136,7 +139,7 @@ void RicSnapshotAllViewsToFileFeature::exportSnapshotOfViewsIntoFolder( const QS
QString absoluteFileName = caf::Utils::constructFullFileName( absSnapshotPath, fileName, ".png" );
RicSnapshotViewToFileFeature::saveSnapshotAs( absoluteFileName, riv );
RicSnapshotViewToFileFeature::saveSnapshotAs( absoluteFileName, riv, width, height );
if ( RimGridView* rigv = dynamic_cast<RimGridView*>( riv ) )
{
@@ -29,8 +29,12 @@ class RicSnapshotAllViewsToFileFeature : public caf::CmdFeature
public:
static void saveAllViews();
static void
exportSnapshotOfViewsIntoFolder( const QString& snapshotFolderName, const QString& prefix = "", int caseId = -1, int viewId = -1 );
static void exportSnapshotOfViewsIntoFolder( const QString& snapshotFolderName,
int width = -1,
int height = -1,
const QString& prefix = "",
int caseId = -1,
int viewId = -1 );
protected:
void onActionTriggered( bool isChecked ) override;
@@ -48,7 +48,7 @@ CAF_CMD_SOURCE_INIT( RicSnapshotViewToFileFeature, "RicSnapshotViewToFileFeature
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSnapshotViewToFileFeature::saveSnapshotAs( const QString& fileName, RimViewWindow* viewWindow )
void RicSnapshotViewToFileFeature::saveSnapshotAs( const QString& fileName, RimViewWindow* viewWindow, int width, int height )
{
auto* plotWindow = dynamic_cast<RimPlotWindow*>( viewWindow );
if ( plotWindow && fileName.endsWith( ".pdf" ) )
@@ -57,7 +57,7 @@ void RicSnapshotViewToFileFeature::saveSnapshotAs( const QString& fileName, RimV
}
else if ( viewWindow )
{
QImage image = viewWindow->snapshotWindowContent();
QImage image = viewWindow->captureSnapshot( width, height );
saveSnapshotAs( fileName, image );
}
}
@@ -32,7 +32,7 @@ class RicSnapshotViewToFileFeature : public caf::CmdFeature
CAF_CMD_HEADER_INIT;
public:
static void saveSnapshotAs( const QString& fileName, RimViewWindow* viewWindow );
static void saveSnapshotAs( const QString& fileName, RimViewWindow* viewWindow, int width = -1, int height = -1 );
static void saveSnapshotAs( const QString& fileName, const QImage& image );
static void savePlotPdfReportAs( const QString& fileName, RimPlotWindow* plotWindow );
@@ -651,7 +651,7 @@ QImage RimMultiPlot::captureSnapshot( int width, int height )
QSize orgViewSize = m_viewer->size();
image = captureImage( m_viewer->bookWidget(), width, height );
image = RimViewWindow::captureSnapshot( m_viewer->bookWidget(), width, height );
m_viewer->resize( orgViewSize );
doUpdateLayout();
@@ -228,19 +228,28 @@ QImage RimViewWindow::snapshotWindowContent()
//--------------------------------------------------------------------------------------------------
QImage RimViewWindow::captureSnapshot( int width, int height )
{
return captureImage( viewWidget(), width, height );
return captureSnapshot( viewWidget(), width, height );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QImage RimViewWindow::captureImage( QWidget* widget, int width, int height )
QImage RimViewWindow::captureSnapshot( QWidget* widget, int width, int height )
{
if ( !widget ) return QImage();
QSize orgSize = widget->size();
bool shouldResize = width > 0 && height > 0 && ( widget->width() != width || widget->height() != height );
widget->setFixedSize( width, height );
QSize orgSize = widget->size();
if ( shouldResize )
{
widget->setFixedSize( width, height );
}
else
{
width = widget->width();
height = widget->height();
}
QPixmap pix( width, height );
pix.fill( Qt::transparent );
@@ -248,10 +257,12 @@ QImage RimViewWindow::captureImage( QWidget* widget, int width, int height )
QPainter painter( &pix );
widget->render( &painter );
// reset fixed size and restore original size
widget->setMinimumSize( 0, 0 );
widget->setMaximumSize( QWIDGETSIZE_MAX, QWIDGETSIZE_MAX );
widget->resize( orgSize );
if ( shouldResize )
{
widget->setMinimumSize( 0, 0 );
widget->setMaximumSize( QWIDGETSIZE_MAX, QWIDGETSIZE_MAX );
widget->resize( orgSize );
}
return pix.toImage();
}
@@ -25,6 +25,8 @@
#include "cafPdmField.h"
#include "cafPdmObject.h"
#include <QImage>
class RimDockWindowController;
namespace ads
@@ -101,7 +103,7 @@ protected:
void defineObjectEditorAttribute( QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override;
QImage captureImage( QWidget* widget, int width, int height );
QImage captureSnapshot( QWidget* widget, int width, int height );
private:
friend class RimProject;
+2
View File
@@ -55,6 +55,8 @@ message ExportSnapshotsRequest {
int32 viewId = 4;
string exportFolder = 5;
PlotOutputFormat plotOutputFormat = 6;
int32 width = 7;
int32 height = 8;
}
message ExportPropertyRequest {
@@ -15,7 +15,7 @@ export_folder = tempfile.mkdtemp()
print("Exporting to: " + export_folder)
for plot in plots:
plot.export_snapshot(export_folder=export_folder)
plot.export_snapshot(export_folder=export_folder, width=1024, height=768)
plot.export_snapshot(export_folder=export_folder, output_format="PDF")
if isinstance(plot, rips.WellLogPlot):
plot.export_data_as_las(export_folder=export_folder)
@@ -10,7 +10,7 @@ resinsight = rips.Instance.find()
cases = resinsight.project.cases()
# Set main window size
resinsight.set_main_window_size(width=800, height=500)
# resinsight.set_main_window_size(width=1280, height=900)
n = 5 # every n-th time_step for snapshot
property_list = ["SOIL", "PRESSURE"] # list of parameter for snapshot
@@ -42,4 +42,4 @@ for case in cases:
)
for time_step in range(0, len(time_steps), 10):
view.set_time_step(time_step=time_step)
view.export_snapshot()
view.export_snapshot(width=1024, height=768)
+5 -1
View File
@@ -9,13 +9,15 @@ from .resinsight_classes import PlotWindow as PlotWindow, Plot as Plot
@add_method(PlotWindow)
def export_snapshot(self, export_folder="", file_prefix="", output_format="PNG"):
def export_snapshot(self, export_folder="", file_prefix="", output_format="PNG", width=-1, height=-1):
"""Export snapshot for the current plot
Arguments:
export_folder(str): The path to export to. By default will use the global export folder
prefix (str): Exported file name prefix
output_format(str): Enum string. Can be 'PNG' or 'PDF'.
width (int): The width of the exported snapshot. By default will use the existing size.
height (int): The height of the exported snapshot. By default will use the existing size.
"""
return self._execute_command(
@@ -25,5 +27,7 @@ def export_snapshot(self, export_folder="", file_prefix="", output_format="PNG")
viewId=self.id,
exportFolder=export_folder,
plotOutputFormat=output_format,
width=width,
height=height,
)
)
+3 -1
View File
@@ -245,7 +245,7 @@ def visible_cells(self, time_step=0):
@add_method(ViewWindow)
def export_snapshot(self, prefix="", export_folder=""):
def export_snapshot(self, prefix="", export_folder="", width=-1, height=-1):
"""Export snapshot for the current view
Arguments:
@@ -260,5 +260,7 @@ def export_snapshot(self, prefix="", export_folder=""):
caseId=case_id,
viewId=self.id,
exportFolder=export_folder,
width=width,
height=height
)
)