Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Interface/Modules/Render/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ SET(Interface_Modules_Render_FORMS
Materials.ui
ObjectSelection.ui
OrientationAxes.ui
Screenshot.ui
ScaleBar.ui
ClippingPlanes.ui
InputControls.ui
Expand Down
56 changes: 2 additions & 54 deletions src/Interface/Modules/Render/Screenshot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,10 @@ using namespace SCIRun::Core::Datatypes;

Screenshot::Screenshot(QOpenGLWidget *glwidget, QObject *parent)
: QObject(parent),
viewport_(glwidget),
index_(0)
viewport_(glwidget)
{
}

QString Screenshot::screenshotDirectory()
{
// static const QString filePath = QDir::homePath() + QLatin1String("/scirun5screenshots");
QString filePath = QString::fromStdString(Core::Preferences::Instance().screenshotDirectory().string());

if (filePath.isEmpty())
{
filePath = QDir::homePath() + QLatin1String("/scirun5screenshots");

QDir dir(filePath);
if (!dir.exists())
{
dir.mkpath(filePath);
}
}

return filePath;
}

void Screenshot::takeScreenshot()
{
screenshot_ = getScreenshot();
Expand All @@ -81,42 +61,10 @@ QImage Screenshot::getScreenshot()
return image;
}

void Screenshot::saveScreenshot()
{
index_++;
const auto fileName = screenshotFile();
if (!fileName.isEmpty())
{
QMessageBox::information(nullptr, "ViewScene Screenshot", "Saving ViewScene screenshot to: " + fileName);
screenshot_.save(fileName);
}
}

void Screenshot::saveScreenshot(const QString& filename)
void Screenshot::saveScreenshot(const QString& fileName)
{
screenshot_.save(filename);
}

void Screenshot::saveScreenshotFromPath(bool prompt)
{
index_++;
auto fileName = screenshotFileFromPreferences();
if (!fileName.isEmpty())
{
if (prompt)
QMessageBox::information(nullptr, "ViewScene Screenshot", "Saving ViewScene screenshot to: " + fileName);
screenshot_.save(fileName);
}
}

QString Screenshot::screenshotFileFromPreferences() const
{
return screenshotDirectory() + QString("/viewScene_%1_%2.png").arg(QDateTime::currentDateTime().toString("yyyy.MM.dd.HHmmss.zzz")).arg(index_);
}

QString Screenshot::screenshotFile() const
{
return QFileDialog::getSaveFileName(viewport_, "Save screenshot...", screenshotDirectory(), "*.png");
}

SCIRun::Modules::Render::RGBMatrices Screenshot::toMatrix() const
Expand Down
6 changes: 0 additions & 6 deletions src/Interface/Modules/Render/Screenshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,12 @@ namespace SCIRun
explicit Screenshot(QOpenGLWidget *glwidget, QObject *parent = nullptr);
void takeScreenshot();
QImage getScreenshot();
void saveScreenshot();
void saveScreenshot(const QString& filename);
void saveScreenshotFromPath(bool prompt);
QString screenshotFileFromPreferences() const;
QString screenshotFile() const;
Modules::Render::RGBMatrices toMatrix() const;
static QString screenshotDirectory();

private:
QOpenGLWidget* viewport_;
QImage screenshot_;
uint index_;
};
}
}
Expand Down
66 changes: 66 additions & 0 deletions src/Interface/Modules/Render/Screenshot.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Screenshot</class>
<widget class="QWidget" name="Screenshot">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>397</width>
<height>115</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>337</width>
<height>115</height>
</size>
</property>
<property name="windowTitle">
<string>Orientation Axes</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Default Screenshot Path</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="defaultScreenshotPath_"/>
</item>
<item>
<widget class="QPushButton" name="screenshotPathButton_">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Set...</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QPushButton" name="screenshotSaveAsButton_">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Save Screenshot As...</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
68 changes: 40 additions & 28 deletions src/Interface/Modules/Render/ViewScene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ namespace Gui {
ViewAxisChooserControls* viewAxisChooser_{nullptr};
ObjectSelectionControls* objectSelectionControls_{nullptr};
OrientationAxesControls* orientationAxesControls_{nullptr};
ScreenshotControls* screenshotControls_{nullptr};
ScaleBarControls* scaleBarControls_{nullptr};
ClippingPlaneControls* clippingPlaneControls_{nullptr};
InputControls* inputControls_{nullptr};
Expand Down Expand Up @@ -448,6 +449,8 @@ ViewSceneDialog::ViewSceneDialog(const std::string& name, ModuleStateHandle stat
glLayout->addWidget(impl_->toolBar2_, 1, 0);
glLayout->update();

addLineEditManager(impl_->screenshotControls_->defaultScreenshotPath_, Parameters::ScreenshotDirectory);

viewSceneManager.addViewScene(this);
}

Expand Down Expand Up @@ -488,7 +491,6 @@ void ViewSceneDialog::addToolBar()
addObjectSelectionButton();
addAutoViewButton();
addScreenshotButton();
addQuickScreenshotButton();
addAutoRotateButton();
addColorOptionsButton();
addLightButtons();
Expand Down Expand Up @@ -684,18 +686,9 @@ void ViewSceneDialog::addScreenshotButton()
screenshotButton->setToolTip("Take Screenshot");
screenshotButton->setIcon(QPixmap(":/general/Resources/ViewScene/screenshot.png"));
screenshotButton->setShortcut(Qt::Key_F12);
connect(screenshotButton, SIGNAL(clicked(bool)), this, SLOT(screenshotClicked()));
addToolbarButton(screenshotButton, 1);
}

void ViewSceneDialog::addQuickScreenshotButton()
{
auto* quickScreenshotButton = new QPushButton(this);
quickScreenshotButton->setToolTip("Take Quick Screenshot");
quickScreenshotButton->setIcon(QPixmap(":/general/Resources/ViewScene/quickscreenshot.png"));
quickScreenshotButton->setShortcut(Qt::Key_F12);
connect(quickScreenshotButton, &QPushButton::clicked, this, &ViewSceneDialog::quickScreenshotClicked);
addToolbarButton(quickScreenshotButton, 1);
connect(screenshotButton, SIGNAL(clicked(bool)), this, SLOT(quickScreenshotClicked()));
impl_->screenshotControls_ = new ScreenshotControls(this);
addToolbarButton(screenshotButton, 1, impl_->screenshotControls_);
}

using V = glm::vec3;
Expand Down Expand Up @@ -1206,7 +1199,7 @@ void ViewSceneDialog::newGeometryValue(bool forceAllObjectsToUpdate, bool clippi
}

if (impl_->saveScreenshotOnNewGeometry_)
quickScreenshot(false);
autoSaveScreenshot();
}

void ViewSceneDialog::lockMutex()
Expand Down Expand Up @@ -2671,28 +2664,49 @@ void ViewSceneDialog::setTransparencySortTypeLists(bool)
updateAllGeometries();
}

void ViewSceneDialog::screenshotClicked()
void ViewSceneDialog::screenshotSaveAs()
{
takeScreenshot();
impl_->screenshotTaker_->saveScreenshot();
auto fileName = QFileDialog::getSaveFileName(impl_->mGLWidget, "Save screenshot...", QString::fromStdString(state_->getValue(Parameters::ScreenshotDirectory).toString()), "*.png");

saveScreenshot(fileName, true);
}

void ViewSceneDialog::quickScreenshot(bool prompt)
void ViewSceneDialog::quickScreenshot()
{
takeScreenshot();
impl_->screenshotTaker_->saveScreenshotFromPath(prompt);
auto fileName = QString::fromStdString(state_->getValue(Parameters::ScreenshotDirectory).toString()) +
QString("/%1_%2.png").arg(QString::fromStdString(getName()).replace(':', '-')).arg(QTime::currentTime().toString("hh.mm.ss.zzz"));

saveScreenshot(fileName, true);
}

void ViewSceneDialog::setScreenshotDirectory()
{
auto dir = QFileDialog::getExistingDirectory(this, tr("Choose Screenshot Directory"), QString::fromStdString(state_->getValue(Parameters::ScreenshotDirectory).toString()));

state_->setValue(Parameters::ScreenshotDirectory, dir.toStdString());
}

void ViewSceneDialog::saveScreenshot(QString fileName, bool notify)
{
if(!fileName.isEmpty())
{
takeScreenshot();
if(notify)
QMessageBox::information(nullptr, "ViewScene Screenshot", "Saving ViewScene screenshot to: " + fileName);

impl_->screenshotTaker_->saveScreenshot(fileName);
}
}

void ViewSceneDialog::autoSaveScreenshot()
{
QThread::sleep(1);
takeScreenshot();
const auto file = Screenshot::screenshotDirectory() +
const auto file = QString::fromStdString(state_->getValue(Parameters::ScreenshotDirectory).toString()) +
QString("/%1_%2.png")
.arg(windowTitle().replace(':', '-'))
.arg(QString::fromStdString(getName()).replace(':', '-'))
.arg(QTime::currentTime().toString("hh.mm.ss.zzz"));

impl_->screenshotTaker_->saveScreenshot(file);
saveScreenshot(file, false);
}

void ViewSceneDialog::sendBugReport()
Expand All @@ -2701,10 +2715,8 @@ void ViewSceneDialog::sendBugReport()
const QString gpuVersion = reinterpret_cast<const char *>(glGetString(GL_RENDERER));

// Temporarily save screenshot so that it can be sent over email
takeScreenshot();
const QImage image = impl_->screenshotTaker_->getScreenshot();
QString location = Screenshot::screenshotDirectory() + ("/scirun_bug.png");
image.save(location);
QString location = QString::fromStdString(state_->getValue(Parameters::ScreenshotDirectory).toString()) + ("/scirun_bug.png");
saveScreenshot(location, false);

// Generate email template
const QString askForScreenshot = "\nIMPORTANT: Make sure to attach the screenshot of the ViewScene located at "
Expand Down
11 changes: 7 additions & 4 deletions src/Interface/Modules/Render/ViewScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,11 @@ namespace SCIRun {
void setTransparencySortTypeContinuous(bool index);
void setTransparencySortTypeUpdate(bool index);
void setTransparencySortTypeLists(bool index);
void screenshotClicked();
void quickScreenshot(bool prompt);
void quickScreenshotClicked() { quickScreenshot(true); }
void screenshotSaveAs();
void screenshotSaveAsClicked() { screenshotSaveAs(); };
void quickScreenshot();
void quickScreenshotClicked() { quickScreenshot(); }
void setScreenshotDirectory();
void saveNewGeometryChanged(int state);


Expand Down Expand Up @@ -223,7 +225,6 @@ namespace SCIRun {
void setupMaterials();
void addAutoViewButton();
void addScreenshotButton();
void addQuickScreenshotButton();
void addViewBarButton();
void addControlLockButton();
void addAutoRotateButton();
Expand Down Expand Up @@ -283,6 +284,7 @@ namespace SCIRun {
//---------------- Misc. ---------------------------------------------------------------------
void takeScreenshot();
void sendScreenshotDownstreamForTesting();
void saveScreenshot(QString directory, bool notify);

std::unique_ptr<ViewSceneDialogImpl> impl_;

Expand All @@ -293,6 +295,7 @@ namespace SCIRun {
friend class MaterialsControls;
friend class ObjectSelectionControls;
friend class OrientationAxesControls;
friend class ScreenshotControls;
friend class ScaleBarControls;
friend class LightControls;
friend class ClippingPlaneControls;
Expand Down
8 changes: 8 additions & 0 deletions src/Interface/Modules/Render/ViewSceneControlsDock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,14 @@ void OrientationAxesControls::toggleButton()
updateToolbarButton("lightGray");
}

ScreenshotControls::ScreenshotControls(ViewSceneDialog* parent)
: QWidget(parent)
{
setupUi(this);
connect(screenshotSaveAsButton_, SIGNAL(clicked()), parent, SLOT(screenshotSaveAsClicked()));
connect(screenshotPathButton_, SIGNAL(clicked()), parent, SLOT(setScreenshotDirectory()));
}

ScaleBarControls::ScaleBarControls(ViewSceneDialog* parent, QPushButton* toolbarButton)
: QWidget(parent), ButtonStylesheetToggler(toolbarButton, [this]() { toggleCheckable(showScaleBarTextGroupBox_); })
{
Expand Down
13 changes: 13 additions & 0 deletions src/Interface/Modules/Render/ViewSceneControlsDock.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "Interface/Modules/Render/ui_Fog.h"
#include "Interface/Modules/Render/ui_ObjectSelection.h"
#include "Interface/Modules/Render/ui_OrientationAxes.h"
#include "Interface/Modules/Render/ui_Screenshot.h"
#include "Interface/Modules/Render/ui_ScaleBar.h"
#include "Interface/Modules/Render/ui_ClippingPlanes.h"
#include "Interface/Modules/Render/ui_InputControls.h"
Expand Down Expand Up @@ -174,6 +175,18 @@ namespace SCIRun {
void setSliderCenterPos();
};

class SCISHARE ScreenshotControls : public QWidget, public Ui::Screenshot
{
Q_OBJECT

public:
explicit ScreenshotControls(ViewSceneDialog* parent);
void setScreenshotDirectory(const QString& dir);
private:
void setSliderDefaultPos();
void setSliderCenterPos();
};

struct SCISHARE ScaleBarData
{
bool visible;
Expand Down
1 change: 1 addition & 0 deletions src/Modules/Render/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ SCIRUN_ADD_LIBRARY(Modules_Render
TARGET_LINK_LIBRARIES(Modules_Render
Dataflow_Network
Core_Datatypes
Core_Application_Preferences
)

IF(BUILD_SHARED_LIBS)
Expand Down
Loading