diff --git a/include/gepetto/gui/osgwidget.hh b/include/gepetto/gui/osgwidget.hh index 6583b465ee82447c527735bc00e3530207f7e51e..ebdbbca5fea2a6e7ce04976afc7a666d93463972 100644 --- a/include/gepetto/gui/osgwidget.hh +++ b/include/gepetto/gui/osgwidget.hh @@ -35,6 +35,9 @@ class QTextBrowser; namespace gepetto { namespace gui { + typedef graphics::WindowManagerPtr_t WindowManagerPtr_t; + typedef WindowsManager::WindowID WindowID; + /// Widget that displays scenes. class OSGWidget : public QWidget { @@ -48,9 +51,9 @@ namespace gepetto { virtual ~OSGWidget(); - WindowsManager::WindowID windowID () const; + WindowID windowID () const; - graphics::WindowManagerPtr_t window () const; + WindowManagerPtr_t window () const; WindowsManagerPtr_t osg () const; @@ -62,6 +65,10 @@ namespace gepetto { void toggleCapture (bool active); + void captureFrame (const std::string& filename); + bool startCapture (const std::string& filename, const std::string& extension); + bool stopCapture (); + protected: virtual void paintEvent(QPaintEvent* event); diff --git a/include/gepetto/gui/windows-manager.hh b/include/gepetto/gui/windows-manager.hh index 6f2eb0bcc09372eb17017c7ad66511b160a10342..1b3eaf62729c3acd0edd9666cc912beae9adcb00 100644 --- a/include/gepetto/gui/windows-manager.hh +++ b/include/gepetto/gui/windows-manager.hh @@ -39,6 +39,7 @@ namespace gepetto { WindowID createWindow(const std::string& windowName); WindowID createWindow(const std::string& windowName, + OSGWidget* widget, osgViewer::Viewer* viewer, osg::GraphicsContext *gc); @@ -48,6 +49,11 @@ namespace gepetto { 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: int createWindow(QString windowName); protected: @@ -67,6 +73,8 @@ namespace gepetto { const NodePtr_t& node, const BodyTreeItems_t& groups, bool isGroup); void deleteBodyItem(const std::string& nodeName); + + std::vector<OSGWidget*> widgets_; }; } // namespace gui } // namespace gepetto diff --git a/src/gui/bodytreewidget.cc b/src/gui/bodytreewidget.cc index f68913c0644d65a2ef4dcbd5a19f7f7624a671b5..4358f3aec434d21ac076d989e344935c0cbf430a 100644 --- a/src/gui/bodytreewidget.cc +++ b/src/gui/bodytreewidget.cc @@ -24,7 +24,6 @@ #include <gepetto/gui/node-action.hh> #include <QSignalMapper> -#include <QColorDialog> #include <QHBoxLayout> #include <QApplication> diff --git a/src/gui/osgwidget.cc b/src/gui/osgwidget.cc index 13c41312b3ebbfd376762171c4cc2ac2a8fb151e..5215f32af83b455953e73b62c30f028ab95515e8 100644 --- a/src/gui/osgwidget.cc +++ b/src/gui/osgwidget.cc @@ -116,7 +116,7 @@ namespace gepetto { viewer_->addEventHandler(new osgViewer::HelpHandler); viewer_->addEventHandler(pickHandler_); - wid_ = wm->createWindow (name, viewer_, graphicsWindow_.get()); + wid_ = wm->createWindow (name, this, viewer_, graphicsWindow_.get()); wm_ = wsm_->getWindowManager (wid_); viewer_->setThreadingModel(threadingModel); @@ -151,9 +151,8 @@ namespace gepetto { void OSGWidget::paintEvent(QPaintEvent*) { - wsm_->osgFrameMutex().lock(); + graphics::ScopedLock lock(wsm_->osgFrameMutex()); viewer_->frame(); - wsm_->osgFrameMutex().unlock(); } graphics::WindowsManager::WindowID OSGWidget::windowID() const @@ -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() { pOutput_->append(process_->readAll()); diff --git a/src/gui/windows-manager.cc b/src/gui/windows-manager.cc index 246b3f92adfb98c770dc9e72b046f8b67cb61be6..e8ab11fcd990be3796f1a14384ac0fcc26bd4139 100644 --- a/src/gui/windows-manager.cc +++ b/src/gui/windows-manager.cc @@ -42,11 +42,14 @@ namespace gepetto { } WindowsManager::WindowID WindowsManager::createWindow(const std::string& windowName, + gepetto::gui::OSGWidget* widget, osgViewer::Viewer *viewer, osg::GraphicsContext *gc) { graphics::WindowManagerPtr_t newWindow = graphics::WindowManager::create (viewer, gc); WindowID windowId = addWindow (windowName, newWindow); + assert (windowId == widgets_.size()); + widgets_.push_back(widget); return windowId; } @@ -186,5 +189,42 @@ namespace gepetto { } 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 gepetto