diff --git a/include/gepetto/gui/mainwindow.hh b/include/gepetto/gui/mainwindow.hh index 618f6d4b56a57e3403e7b938be50bb4b4915339e..26e5ce248ad0927ffcfd3acce20516970dc6eba4 100644 --- a/include/gepetto/gui/mainwindow.hh +++ b/include/gepetto/gui/mainwindow.hh @@ -109,9 +109,6 @@ namespace gepetto { signals: void sendToBackground (WorkItem* item); - /// You should not need to call this function. - /// Use MainWindow::createView(const std::string&) - void createViewOnMainThread(const std::string& name); /// Triggered when an OSGWidget is created. void viewCreated (OSGWidget* widget); void refresh (); @@ -268,7 +265,6 @@ signals: ActionSearchBar* actionSearchBar_; - QMutex delayedCreateView_; QStringList robotNames_; QStringList lastBodiesInCollision_; diff --git a/src/gui/mainwindow.cc b/src/gui/mainwindow.cc index aae4baed879b941ef5f7f6a5dc15c123a4fda096..c2fe6f2b7645e9f2c2ccb9101e53266fd5327459 100644 --- a/src/gui/mainwindow.cc +++ b/src/gui/mainwindow.cc @@ -76,8 +76,6 @@ namespace gepetto { osg()->createScene("hpp-gui"); // Setup the main OSG widget - connect (this, SIGNAL (createViewOnMainThread(std::string)), SLOT (createView(std::string))); - connect (ui_->actionRefresh, SIGNAL (triggered()), SLOT (requestRefresh())); connect (&backgroundQueue_, SIGNAL (done(int)), this, SLOT (handleWorkerDone(int))); @@ -227,23 +225,18 @@ namespace gepetto { OSGWidget *MainWindow::createView(const std::string& name) { if (thread() != QThread::currentThread()) { - delayedCreateView_.lock(); - emit createViewOnMainThread(name); - delayedCreateView_.lock(); - delayedCreateView_.unlock(); - return osgWindows_.last(); - } else { - OSGWidget* osgWidget = new OSGWidget (osgViewerManagers_, name, this, 0 + qDebug() << "createView must be called from the main thread."; + throw std::runtime_error("Cannot create a new window."); + } + OSGWidget* osgWidget = new OSGWidget (osgViewerManagers_, name, this, 0 #if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) - , osgViewer::Viewer::SingleThreaded + , osgViewer::Viewer::SingleThreaded #endif - ); - osgWidget->setObjectName(name.c_str()); - addOSGWidget (osgWidget); - emit viewCreated(osgWidget); - delayedCreateView_.unlock(); - return osgWidget; - } + ); + osgWidget->setObjectName(name.c_str()); + addOSGWidget (osgWidget); + emit viewCreated(osgWidget); + return osgWidget; } void MainWindow::requestRefresh() diff --git a/src/gui/windows-manager.cc b/src/gui/windows-manager.cc index e8ab11fcd990be3796f1a14384ac0fcc26bd4139..e60f1f3922acd9b4ffca878b6e3cec1d1dc08f61 100644 --- a/src/gui/windows-manager.cc +++ b/src/gui/windows-manager.cc @@ -38,7 +38,13 @@ namespace gepetto { WindowsManager::WindowID WindowsManager::createWindow(const std::string& windowName) { - return MainWindow::instance()->createView(windowName)->windowID(); + MainWindow* main = MainWindow::instance(); + OSGWidget* widget; + QMetaObject::invokeMethod (main, "createView", + Qt::BlockingQueuedConnection, + Q_RETURN_ARG (OSGWidget*, widget), + Q_ARG (std::string, windowName)); + return widget->windowID(); } WindowsManager::WindowID WindowsManager::createWindow(const std::string& windowName,