Skip to content
Snippets Groups Projects
Commit 0de1e083 authored by Joseph Mirabel's avatar Joseph Mirabel
Browse files

Fix saving of scene to image

parent 9da85584
No related branches found
No related tags found
No related merge requests found
...@@ -35,6 +35,9 @@ class QTextBrowser; ...@@ -35,6 +35,9 @@ class QTextBrowser;
namespace gepetto { namespace gepetto {
namespace gui { namespace gui {
typedef graphics::WindowManagerPtr_t WindowManagerPtr_t;
typedef WindowsManager::WindowID WindowID;
/// Widget that displays scenes. /// Widget that displays scenes.
class OSGWidget : public QWidget class OSGWidget : public QWidget
{ {
...@@ -48,9 +51,9 @@ namespace gepetto { ...@@ -48,9 +51,9 @@ namespace gepetto {
virtual ~OSGWidget(); virtual ~OSGWidget();
WindowsManager::WindowID windowID () const; WindowID windowID () const;
graphics::WindowManagerPtr_t window () const; WindowManagerPtr_t window () const;
WindowsManagerPtr_t osg () const; WindowsManagerPtr_t osg () const;
...@@ -62,6 +65,10 @@ namespace gepetto { ...@@ -62,6 +65,10 @@ namespace gepetto {
void toggleCapture (bool active); void toggleCapture (bool active);
void captureFrame (const std::string& filename);
bool startCapture (const std::string& filename, const std::string& extension);
bool stopCapture ();
protected: protected:
virtual void paintEvent(QPaintEvent* event); virtual void paintEvent(QPaintEvent* event);
......
...@@ -39,6 +39,7 @@ namespace gepetto { ...@@ -39,6 +39,7 @@ namespace gepetto {
WindowID createWindow(const std::string& windowName); WindowID createWindow(const std::string& windowName);
WindowID createWindow(const std::string& windowName, WindowID createWindow(const std::string& windowName,
OSGWidget* widget,
osgViewer::Viewer* viewer, osgViewer::Viewer* viewer,
osg::GraphicsContext *gc); osg::GraphicsContext *gc);
...@@ -48,6 +49,11 @@ namespace gepetto { ...@@ -48,6 +49,11 @@ namespace gepetto {
BodyTreeItems_t bodyTreeItems (const std::string& name) const; BodyTreeItems_t bodyTreeItems (const std::string& name) const;
void captureFrame (const WindowID windowId, const std::string& filename);
bool startCapture (const WindowID windowId, const std::string& filename,
const std::string& extension);
bool stopCapture (const WindowID windowId);
public slots: public slots:
int createWindow(QString windowName); int createWindow(QString windowName);
protected: protected:
...@@ -67,6 +73,8 @@ namespace gepetto { ...@@ -67,6 +73,8 @@ namespace gepetto {
const NodePtr_t& node, const BodyTreeItems_t& groups, const NodePtr_t& node, const BodyTreeItems_t& groups,
bool isGroup); bool isGroup);
void deleteBodyItem(const std::string& nodeName); void deleteBodyItem(const std::string& nodeName);
std::vector<OSGWidget*> widgets_;
}; };
} // namespace gui } // namespace gui
} // namespace gepetto } // namespace gepetto
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include <gepetto/gui/node-action.hh> #include <gepetto/gui/node-action.hh>
#include <QSignalMapper> #include <QSignalMapper>
#include <QColorDialog>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QApplication> #include <QApplication>
......
...@@ -116,7 +116,7 @@ namespace gepetto { ...@@ -116,7 +116,7 @@ namespace gepetto {
viewer_->addEventHandler(new osgViewer::HelpHandler); viewer_->addEventHandler(new osgViewer::HelpHandler);
viewer_->addEventHandler(pickHandler_); viewer_->addEventHandler(pickHandler_);
wid_ = wm->createWindow (name, viewer_, graphicsWindow_.get()); wid_ = wm->createWindow (name, this, viewer_, graphicsWindow_.get());
wm_ = wsm_->getWindowManager (wid_); wm_ = wsm_->getWindowManager (wid_);
viewer_->setThreadingModel(threadingModel); viewer_->setThreadingModel(threadingModel);
...@@ -151,9 +151,8 @@ namespace gepetto { ...@@ -151,9 +151,8 @@ namespace gepetto {
void OSGWidget::paintEvent(QPaintEvent*) void OSGWidget::paintEvent(QPaintEvent*)
{ {
wsm_->osgFrameMutex().lock(); graphics::ScopedLock lock(wsm_->osgFrameMutex());
viewer_->frame(); viewer_->frame();
wsm_->osgFrameMutex().unlock();
} }
graphics::WindowsManager::WindowID OSGWidget::windowID() const graphics::WindowsManager::WindowID OSGWidget::windowID() const
...@@ -220,6 +219,27 @@ namespace gepetto { ...@@ -220,6 +219,27 @@ namespace gepetto {
} }
} }
void OSGWidget::captureFrame (const std::string& filename)
{
graphics::ScopedLock lock(wsm_->osgFrameMutex());
wm_->captureFrame (filename);
}
bool OSGWidget::startCapture (const std::string& filename,
const std::string& extension)
{
graphics::ScopedLock lock(wsm_->osgFrameMutex());
wm_->startCapture (filename, extension);
return true;
}
bool OSGWidget::stopCapture ()
{
graphics::ScopedLock lock(wsm_->osgFrameMutex());
wm_->stopCapture ();
return true;
}
void OSGWidget::readyReadProcessOutput() void OSGWidget::readyReadProcessOutput()
{ {
pOutput_->append(process_->readAll()); pOutput_->append(process_->readAll());
......
...@@ -42,11 +42,14 @@ namespace gepetto { ...@@ -42,11 +42,14 @@ namespace gepetto {
} }
WindowsManager::WindowID WindowsManager::createWindow(const std::string& windowName, WindowsManager::WindowID WindowsManager::createWindow(const std::string& windowName,
gepetto::gui::OSGWidget* widget,
osgViewer::Viewer *viewer, osgViewer::Viewer *viewer,
osg::GraphicsContext *gc) osg::GraphicsContext *gc)
{ {
graphics::WindowManagerPtr_t newWindow = graphics::WindowManager::create (viewer, gc); graphics::WindowManagerPtr_t newWindow = graphics::WindowManager::create (viewer, gc);
WindowID windowId = addWindow (windowName, newWindow); WindowID windowId = addWindow (windowName, newWindow);
assert (windowId == widgets_.size());
widgets_.push_back(widget);
return windowId; return windowId;
} }
...@@ -186,5 +189,42 @@ namespace gepetto { ...@@ -186,5 +189,42 @@ namespace gepetto {
} }
return false; return false;
} }
void WindowsManager::captureFrame (const WindowID wid, const std::string& filename)
{
WindowManagerPtr_t wm = getWindowManager(wid, true);
OSGWidget* widget = widgets_[wid];
assert(widget->windowID()==wid);
QMetaObject::invokeMethod (widget, "captureFrame",
Qt::BlockingQueuedConnection,
Q_ARG (std::string, filename));
}
bool WindowsManager::startCapture (const WindowID wid, const std::string& filename,
const std::string& extension)
{
WindowManagerPtr_t wm = getWindowManager(wid, true);
OSGWidget* widget = widgets_[wid];
assert(widget->windowID()==wid);
bool res;
QMetaObject::invokeMethod (widget, "startCapture",
Qt::BlockingQueuedConnection,
Q_RETURN_ARG (bool, res),
Q_ARG (std::string, filename),
Q_ARG (std::string, extension));
return res;
}
bool WindowsManager::stopCapture (const WindowID wid)
{
WindowManagerPtr_t wm = getWindowManager(wid, true);
OSGWidget* widget = widgets_[wid];
assert(widget->windowID()==wid);
bool res;
QMetaObject::invokeMethod (widget, "stopCapture",
Qt::BlockingQueuedConnection,
Q_RETURN_ARG (bool, res));
return res;
}
} // namespace gui } // namespace gui
} // namespace gepetto } // namespace gepetto
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment