Added functions used to create 2D images from 3D views

p4#: 20385
This commit is contained in:
Magne Sjaastad 2013-02-06 11:43:26 +01:00
parent d1f8110deb
commit 7648a63f02
4 changed files with 180 additions and 13 deletions

View File

@ -943,3 +943,114 @@ void RIApplication::setDefaultFileDialogDirectory(const QString& dialogName, con
{
m_fileDialogDefaultDirectories[dialogName] = defaultDirectory;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RIApplication::saveSnapshotPromtpForFilename()
{
QString startPath;
if (!m_project->fileName().isEmpty())
{
QFileInfo fi(m_project->fileName());
startPath = fi.absolutePath();
}
else
{
startPath = defaultFileDialogDirectory("IMAGE_SNAPSHOT");
}
startPath += "/image.png";
QString fileName = QFileDialog::getSaveFileName(NULL, tr("Save File"), startPath, tr("Image files (*.bmp *.png * *.jpg)"));
if (fileName.isEmpty())
{
return;
}
// Remember the directory to next time
setDefaultFileDialogDirectory("IMAGE_SNAPSHOT", QFileInfo(fileName).absolutePath());
saveSnapshotAs(fileName);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RIApplication::saveSnapshotAs(const QString& fileName)
{
if (m_activeReservoirView && m_activeReservoirView->viewer())
{
QImage image = m_activeReservoirView->viewer()->grabFrameBuffer();
image.save(fileName);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RIApplication::copySnapshotToClipboard()
{
if (m_activeReservoirView && m_activeReservoirView->viewer())
{
QImage image = m_activeReservoirView->viewer()->grabFrameBuffer();
QClipboard* clipboard = QApplication::clipboard();
if (clipboard)
{
clipboard->setImage(image);
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RIApplication::saveSnapshotForAllViews()
{
RIMainWindow* mainWnd = RIMainWindow::instance();
if (!mainWnd) return;
if (m_project.isNull()) return;
if (m_project->fileName().isEmpty()) return;
QFileInfo fi(m_project->fileName());
QDir projectDir(fi.absolutePath());
QString snapshotFolderName = "snapshots";
if (!projectDir.exists(snapshotFolderName))
{
if (!projectDir.mkdir(snapshotFolderName)) return;
}
QString snapshotPath = projectDir.absolutePath();
snapshotPath += "/" + snapshotFolderName;
for (size_t i = 0; i < m_project->reservoirs().size(); ++i)
{
RimReservoir* ri = m_project->reservoirs()[i];
if (!ri) continue;
for (size_t j = 0; j < ri->reservoirViews().size(); j++)
{
RimReservoirView* riv = ri->reservoirViews()[j];
if (riv && riv->viewer())
{
setActiveReservoirView(riv);
RIViewer* viewer = riv->viewer();
mainWnd->setActiveViewer(viewer);
// Process all events to avoid a black image when grabbing frame buffer
QCoreApplication::processEvents();
QString fileName = ri->caseName() + "-" + riv->name();
QString absoluteFileName = caf::Utils::constructFullFileName(snapshotPath, fileName, ".PNG");
saveSnapshotAs(absoluteFileName);
}
}
}
}

View File

@ -90,6 +90,11 @@ public:
bool saveProjectPromptForFileName();
bool closeProject(bool askToSaveIfDirty);
void copySnapshotToClipboard();
void saveSnapshotPromtpForFilename();
void saveSnapshotAs(const QString& fileName);
void saveSnapshotForAllViews();
void processNonGuiEvents();
static const char* getVersionStringApp(bool includeCrtInfo);

View File

@ -185,6 +185,10 @@ void RIMainWindow::createActions()
m_mockLargeResultsModelAction = new QAction("Large Mock Model", this);
m_mockInputModelAction = new QAction("Input Mock Model", this);
m_snapshotToFile = new QAction("Snapshot To File", this);
m_snapshotToClipboard = new QAction("Snapshot To Clipboard", this);
m_snapshotAllViewsToFile = new QAction("Snapshot All Views To File", this);
m_saveProjectAction = new QAction(QIcon(":/Save.png"), "&Save Project", this);
m_saveProjectAsAction = new QAction(QIcon(":/Save.png"), "Save Project &As", this);
@ -201,6 +205,10 @@ void RIMainWindow::createActions()
connect(m_mockLargeResultsModelAction, SIGNAL(triggered()), SLOT(slotMockLargeResultsModel()));
connect(m_mockInputModelAction, SIGNAL(triggered()), SLOT(slotInputMockModel()));
connect(m_snapshotToFile, SIGNAL(triggered()), SLOT(slotSnapshotToFile()));
connect(m_snapshotToClipboard, SIGNAL(triggered()), SLOT(slotSnapshotToClipboard()));
connect(m_snapshotAllViewsToFile, SIGNAL(triggered()), SLOT(slotSnapshotAllViewsToFile()));
connect(m_saveProjectAction, SIGNAL(triggered()), SLOT(slotSaveProject()));
connect(m_saveProjectAsAction, SIGNAL(triggered()), SLOT(slotSaveProjectAs()));
@ -298,6 +306,11 @@ void RIMainWindow::createMenus()
debugMenu->addAction(m_mockLargeResultsModelAction);
debugMenu->addAction(m_mockInputModelAction);
debugMenu->addSeparator();
debugMenu->addAction(m_snapshotToClipboard);
debugMenu->addAction(m_snapshotToFile);
debugMenu->addAction(m_snapshotAllViewsToFile);
connect(debugMenu, SIGNAL(aboutToShow()), SLOT(slotRefreshDebugActions()));
m_windowMenu = menuBar()->addMenu("&Windows");
@ -1179,3 +1192,33 @@ void RIMainWindow::slotNewObjectPropertyView()
connect(treeView, SIGNAL(selectedObjectChanged( caf::PdmObject* )), propView, SLOT(showProperties( caf::PdmObject* )));
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RIMainWindow::slotSnapshotToFile()
{
RIApplication* app = RIApplication::instance();
app->saveSnapshotPromtpForFilename();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RIMainWindow::slotSnapshotToClipboard()
{
RIApplication* app = RIApplication::instance();
app->copySnapshotToClipboard();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RIMainWindow::slotSnapshotAllViewsToFile()
{
RIApplication* app = RIApplication::instance();
app->saveSnapshotForAllViews();
}

View File

@ -106,10 +106,6 @@ private:
QAction* m_openInputEclipseFileAction;
QAction* m_openProjectAction;
QAction* m_openLastUsedProjectAction;
QAction* m_mockModelAction;
QAction* m_mockResultsModelAction;
QAction* m_mockLargeResultsModelAction;
QAction* m_mockInputModelAction;
QAction* m_saveProjectAction;
QAction* m_saveProjectAsAction;
QAction* m_closeAction;
@ -117,6 +113,7 @@ private:
// Edit actions
QAction* m_editPreferences;
QAction* m_newPropertyView;
// View actions
QAction* m_viewFromNorth;
@ -127,8 +124,15 @@ private:
QAction* m_viewFromBelow;
QAction* m_zoomAll;
// Debug actions
QAction* m_newPropertyView;
// Mock actions
QAction* m_mockModelAction;
QAction* m_mockResultsModelAction;
QAction* m_mockLargeResultsModelAction;
QAction* m_mockInputModelAction;
QAction* m_snapshotToFile;
QAction* m_snapshotToClipboard;
QAction* m_snapshotAllViewsToFile;
// Help actions
QAction* m_aboutAction;
@ -158,12 +162,6 @@ private slots:
void slotOpenInputFiles();
void slotOpenProject();
void slotOpenLastUsedProject();
void slotMockModel();
void slotMockResultsModel();
void slotMockLargeResultsModel();
void slotInputMockModel();
void slotSaveProject();
void slotSaveProjectAs();
void slotCloseProject();
@ -173,6 +171,7 @@ private slots:
// Edit slots
void slotRefreshEditActions();
void slotEditPreferences();
void slotNewObjectPropertyView();
// View slots
void slotRefreshViewActions();
@ -188,7 +187,16 @@ private slots:
void slotRefreshDebugActions();
void slotUseShaders(bool enable);
void slotShowPerformanceInfo(bool enable);
void slotNewObjectPropertyView();
void slotSnapshotToFile();
void slotSnapshotToClipboard();
void slotSnapshotAllViewsToFile();
// Mock models
void slotMockModel();
void slotMockResultsModel();
void slotMockLargeResultsModel();
void slotInputMockModel();
// Windows slots
void slotBuildWindowActions();