#279 Use frame buffer objects for snapshots when available, otherwise use grabFrameBuffer()

This commit is contained in:
Magne Sjaastad
2016-08-31 17:34:31 +02:00
parent 457c3c732b
commit 0128baddff
7 changed files with 145 additions and 66 deletions

View File

@@ -108,6 +108,8 @@
#ifdef WIN32
#include <fcntl.h>
#endif
#include "RiuSummaryQwtPlot.h"
#include "RiuWellLogPlot.h"
namespace caf
{
@@ -1392,6 +1394,43 @@ RiuMainPlotWindow* RiaApplication::mainPlotWindow()
return m_mainPlotWindow;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimViewWindow* RiaApplication::activeViewWindow()
{
RimViewWindow* viewWindow = NULL;
QWidget* topLevelWidget = RiaApplication::activeWindow();
if (dynamic_cast<RiuMainWindow*>(topLevelWidget))
{
viewWindow = RiaApplication::instance()->activeReservoirView();
}
if (dynamic_cast<RiuMainPlotWindow*>(topLevelWidget))
{
RiuMainPlotWindow* mainPlotWindow = dynamic_cast<RiuMainPlotWindow*>(topLevelWidget);
QList<QMdiSubWindow*> subwindows = mainPlotWindow->subWindowList(QMdiArea::StackingOrder);
if (subwindows.size() > 0)
{
RiuSummaryQwtPlot* summaryQwtPlot = dynamic_cast<RiuSummaryQwtPlot*>(subwindows.back()->widget());
if (summaryQwtPlot)
{
viewWindow = summaryQwtPlot->ownerPlotDefinition();
}
RiuWellLogPlot* wellLogPlot = dynamic_cast<RiuWellLogPlot*>(subwindows.back()->widget());
if (wellLogPlot)
{
viewWindow = wellLogPlot->ownerPlotDefinition();
}
}
}
return viewWindow;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -1777,9 +1816,9 @@ void RiaApplication::saveSnapshotAs(const QString& fileName)
//--------------------------------------------------------------------------------------------------
void RiaApplication::copySnapshotToClipboard()
{
QClipboard* clipboard = QApplication::clipboard();
if (clipboard)
{
QClipboard* clipboard = QApplication::clipboard();
if (clipboard)
{
QImage image = grabFrameBufferImage();
if (!image.isNull())
{
@@ -2160,21 +2199,26 @@ cvf::Font* RiaApplication::customFont()
//--------------------------------------------------------------------------------------------------
QImage RiaApplication::grabFrameBufferImage()
{
// TODO: Create a general solution that also works with well log plots and summary plots
// For now, only reservoir views are supported by this solution
/*
RimViewWindow* viewWindow = RiaApplication::activeViewWindow();
if (viewWindow)
{
return viewWindow->snapshotWindowContent();
}
return QImage();
*/
QImage image;
if (m_activeReservoirView && m_activeReservoirView->viewer())
{
m_activeReservoirView->viewer()->repaint();
GLint currentReadBuffer;
glGetIntegerv(GL_READ_BUFFER, &currentReadBuffer);
glReadBuffer(GL_FRONT);
image = m_activeReservoirView->viewer()->grabFrameBuffer();
glReadBuffer(currentReadBuffer);
return m_activeReservoirView->snapshotWindowContent();
}
return image;
}
//--------------------------------------------------------------------------------------------------

View File

@@ -48,6 +48,7 @@ class RimEclipseView;
class RimProject;
class RimSummaryPlot;
class RimView;
class RimViewWindow;
class RimWellLogPlot;
class RiuMainPlotWindow;
@@ -178,6 +179,8 @@ public:
RiuMainPlotWindow* getOrCreateAndShowMainPlotWindow();
RiuMainPlotWindow* mainPlotWindow();
static RimViewWindow* activeViewWindow();
private:
enum ProjectLoadAction
{

View File

@@ -20,15 +20,7 @@
#include "RiaApplication.h"
#include "RimSummaryPlot.h"
#include "RimView.h"
#include "RimViewWindow.h"
#include "RimWellLogPlot.h"
#include "RiuMainPlotWindow.h"
#include "RiuMainWindow.h"
#include "RiuSummaryQwtPlot.h"
#include "RiuWellLogPlot.h"
#include <QAction>
#include <QClipboard>
@@ -49,34 +41,7 @@ bool RicSnapshotViewToClipboardFeature::isCommandEnabled()
//--------------------------------------------------------------------------------------------------
void RicSnapshotViewToClipboardFeature::onActionTriggered(bool isChecked)
{
RimViewWindow* viewWindow = NULL;
QWidget* topLevelWidget = RiaApplication::activeWindow();
if (dynamic_cast<RiuMainWindow*>(topLevelWidget))
{
viewWindow = RiaApplication::instance()->activeReservoirView();
}
if (dynamic_cast<RiuMainPlotWindow*>(topLevelWidget))
{
RiuMainPlotWindow* mainPlotWindow = dynamic_cast<RiuMainPlotWindow*>(topLevelWidget);
QList<QMdiSubWindow*> subwindows = mainPlotWindow->subWindowList(QMdiArea::StackingOrder);
if (subwindows.size() > 0)
{
RiuSummaryQwtPlot* summaryQwtPlot = dynamic_cast<RiuSummaryQwtPlot*>(subwindows.back()->widget());
if (summaryQwtPlot)
{
viewWindow = summaryQwtPlot->ownerPlotDefinition();
}
RiuWellLogPlot* wellLogPlot = dynamic_cast<RiuWellLogPlot*>(subwindows.back()->widget());
if (wellLogPlot)
{
viewWindow = wellLogPlot->ownerPlotDefinition();
}
}
}
RimViewWindow* viewWindow = RiaApplication::activeViewWindow();
if (viewWindow)
{

View File

@@ -255,21 +255,14 @@ void RimView::updateViewerWidget()
//--------------------------------------------------------------------------------------------------
QImage RimView::snapshotWindowContent()
{
QImage image;
if (m_viewer)
{
m_viewer->repaint();
GLint currentReadBuffer;
glGetIntegerv(GL_READ_BUFFER, &currentReadBuffer);
glReadBuffer(GL_FRONT);
image = m_viewer->grabFrameBuffer();
glReadBuffer(currentReadBuffer);
return m_viewer->snapshotImage();
}
return image;
return QImage();
}
//--------------------------------------------------------------------------------------------------

View File

@@ -154,6 +154,7 @@ public:
void selectOverlayInfoConfig();
virtual QImage snapshotWindowContent() override;
virtual void zoomAll() override;
@@ -197,9 +198,6 @@ protected:
virtual void resetLegendsInViewer() = 0;
virtual void calculateCurrentTotalCellVisibility(cvf::UByteArray* totalVisibility) = 0;
virtual QImage snapshotWindowContent() override;
QPointer<RiuViewer> m_viewer;
caf::PdmField<int> m_currentTimeStep;