diff --git a/include/gepetto/gui/bodytreewidget.hh b/include/gepetto/gui/bodytreewidget.hh index 2c3dc6f22d0df7b4998fb6ad7369418048562476..c6a49a970f404cd74447438472b6cfa9a5928756 100644 --- a/include/gepetto/gui/bodytreewidget.hh +++ b/include/gepetto/gui/bodytreewidget.hh @@ -59,11 +59,10 @@ namespace gepetto { return model_; } - /// Handle a selection event - /// - /// Does not re-emit a selection event when the body tree selection - /// is updated. - void handleSelectionEvent (const SelectionEvent* event); + void emitBodySelected (SelectionEvent* event); + + signals: + void bodySelected (SelectionEvent* event); public slots: /// \addtogroup available_in_python Python API @@ -111,6 +110,12 @@ namespace gepetto { const QModelIndex &previous); private: + /// Handle a selection event + /// + /// Does not re-emit a selection event when the body tree selection + /// is updated. + void handleSelectionEvent (const SelectionEvent* event); + QTreeView* view_; QStandardItemModel* model_; WindowsManagerPtr_t osg_; diff --git a/include/gepetto/gui/osgwidget.hh b/include/gepetto/gui/osgwidget.hh index 83e750a08d861e6d6c6bc4af7f03514259711c7d..09df30ef5768b19851aeab4793f961f15070e861 100644 --- a/include/gepetto/gui/osgwidget.hh +++ b/include/gepetto/gui/osgwidget.hh @@ -57,9 +57,6 @@ namespace gepetto { WindowsManager::WindowID windowID () const; -signals: - void clicked (SelectionEvent* event); - public slots: /// Load an urdf file in the viewer. /// \param robotName name of the robot @@ -76,7 +73,6 @@ signals: void cameraManipulationMode (); void addFloor(); void attachToWindow (const std::string nodeName); - void emitClicked (SelectionEvent* event); protected: diff --git a/include/gepetto/gui/selection-handler.hh b/include/gepetto/gui/selection-handler.hh index 89f97c7a744f7ad4891ec3e41833ae2885d693f2..14312306b4fa9a9610abef3a1dfacd1dd7f5a936 100644 --- a/include/gepetto/gui/selection-handler.hh +++ b/include/gepetto/gui/selection-handler.hh @@ -78,8 +78,6 @@ namespace gepetto { SelectionHandler(WindowsManagerPtr_t wsm, QWidget* parent = 0); ~SelectionHandler(); - void setParentOSG(OSGWidget* parent); - SelectionMode* mode (); public slots: @@ -95,7 +93,6 @@ namespace gepetto { void initWidget(); std::vector<SelectionMode *> modes_; - OSGWidget* osg_; int index_; WindowsManagerPtr_t wsm_; QStringList selected_; diff --git a/pyplugins/gepetto/gui/pythonwidget.py b/pyplugins/gepetto/gui/pythonwidget.py index abb48b0a91f731f01835c9144b3e5138da533979..33d614e5189d69d2750ae366f30c372663a39c40 100644 --- a/pyplugins/gepetto/gui/pythonwidget.py +++ b/pyplugins/gepetto/gui/pythonwidget.py @@ -100,10 +100,11 @@ class Plugin(QtGui.QDockWidget): self.main = mainWindow self.windowsManager = windowsManager mainWindow.connect('refresh()', self.refresh) + mainWindow.bodyTree().connect('bodySelected(SelectionEvent*)', self.selected) ### If present, this function is called when a new OSG Widget is created. def osgWidget(self, osgWindow): - osgWindow.connect('clicked(SelectionEvent*)', self.selected) + pass def resetConnection(self): self.client = Client() diff --git a/src/gui/bodytreewidget.cc b/src/gui/bodytreewidget.cc index 05ceefe73c3be542104375ccfe6dee52f3568d6b..57cb313d29b52e93abbfd6581e72b461079b761e 100644 --- a/src/gui/bodytreewidget.cc +++ b/src/gui/bodytreewidget.cc @@ -132,7 +132,6 @@ namespace gepetto { if (matches.empty()) view_->clearSelection(); else { - qDebug() << event->modKey(); if (event->modKey() == Qt::ControlModifier) view_->selectionModel()->setCurrentIndex (matches.first()->index(), @@ -147,6 +146,16 @@ namespace gepetto { SLOT (currentChanged(QModelIndex,QModelIndex))); } + void BodyTreeWidget::emitBodySelected(SelectionEvent* event) + { + emit bodySelected (event); + if (event->type() != SelectionEvent::FromBodyTree) { + MainWindow* main = MainWindow::instance(); + handleSelectionEvent(event); + main->requestSelectJointFromBodyName(event->nodeName()); + } + } + void BodyTreeWidget::currentChanged (const QModelIndex ¤t, const QModelIndex &/*previous*/) { @@ -160,7 +169,7 @@ namespace gepetto { ); if (item) { SelectionEvent *event = new SelectionEvent(SelectionEvent::FromBodyTree, item->node(), QApplication::keyboardModifiers()); - MainWindow::instance()->centralWidget()->emitClicked(event); + emit bodySelected(event); } } diff --git a/src/gui/mainwindow.cc b/src/gui/mainwindow.cc index 3b7fd438f1b1054c4f99ed0c5def51f64f46d4bf..34f73c39e23adecfac5a5f2d0ee4e92784009c96 100644 --- a/src/gui/mainwindow.cc +++ b/src/gui/mainwindow.cc @@ -244,7 +244,6 @@ namespace gepetto { osg()->addSceneToWindow("hpp-gui", centralWidget_->windowID()); connect(ui_->actionAdd_floor, SIGNAL (triggered()), centralWidget_, SLOT (addFloor())); - selectionHandler_->setParentOSG(centralWidget()); } osgWindows_.append(osgWidget); } diff --git a/src/gui/osgwidget.cc b/src/gui/osgwidget.cc index c67eaf021e33f608d1f4ffd114ff3fc5d8d48413..a423f6c1c7db4f220240cf65a01799b15d81595e 100644 --- a/src/gui/osgwidget.cc +++ b/src/gui/osgwidget.cc @@ -36,7 +36,6 @@ #include <gepetto/viewer/OSGManipulator/keyboard-manipulator.h> #include <gepetto/gui/windows-manager.hh> -#include <gepetto/gui/bodytreewidget.hh> #include <gepetto/gui/selection-event.hh> namespace gepetto { @@ -180,16 +179,6 @@ namespace gepetto { // wsm_->lock().unlock(); } - void OSGWidget::emitClicked(SelectionEvent* event) - { - emit clicked (event); - if (event->type() != SelectionEvent::FromBodyTree) { - MainWindow* main = MainWindow::instance(); - main->bodyTree()->handleSelectionEvent(event); - main->requestSelectJointFromBodyName(event->nodeName()); - } - } - void OSGWidget::onHome() { viewer_->home (); diff --git a/src/gui/pick-handler.cc b/src/gui/pick-handler.cc index 453abf70647cd65dc3eb586b93e1426e4975fa4f..17c04caaa5590bcea6d86703b70ea5208d752dad 100644 --- a/src/gui/pick-handler.cc +++ b/src/gui/pick-handler.cc @@ -89,6 +89,7 @@ namespace gepetto { const float &x, const float &y, int modKeyMask) { + BodyTreeWidget* bt = MainWindow::instance()->bodyTree(); std::list<graphics::NodePtr_t> nodes; osgViewer::View* viewer = dynamic_cast<osgViewer::View*>( &aa ); if( viewer ) @@ -108,7 +109,7 @@ namespace gepetto { camera->accept( iv ); if( !intersector->containsIntersections() ) { - parent_->emitClicked(new SelectionEvent(SelectionEvent::FromOsgWindow, QApplication::keyboardModifiers())); + bt->emitBodySelected(new SelectionEvent(SelectionEvent::FromOsgWindow, QApplication::keyboardModifiers())); return nodes; } @@ -125,12 +126,12 @@ namespace gepetto { n, mapper_.getQtModKey(modKeyMask)); event->setupIntersection(intersection); - parent_->emitClicked(event); + bt->emitBodySelected(event); return nodes; } } } - parent_->emitClicked(new SelectionEvent(SelectionEvent::FromOsgWindow, QApplication::keyboardModifiers())); + bt->emitBodySelected(new SelectionEvent(SelectionEvent::FromOsgWindow, QApplication::keyboardModifiers())); return nodes; } diff --git a/src/gui/selection-handler.cc b/src/gui/selection-handler.cc index b7ec358871be2a6e6e8db7e9daa38593444feeaf..e0f6680f70c5acaa2631fe883079277f04060079 100644 --- a/src/gui/selection-handler.cc +++ b/src/gui/selection-handler.cc @@ -4,16 +4,16 @@ #include <QAction> #include <QDebug> +#include <gepetto/gui/bodytreewidget.hh> +#include <gepetto/gui/mainwindow.hh> #include <gepetto/gui/selection-event.hh> #include <gepetto/gui/windows-manager.hh> -#include "gepetto/gui/osgwidget.hh" #include "gepetto/gui/selection-handler.hh" namespace gepetto { namespace gui { SelectionHandler::SelectionHandler(WindowsManagerPtr_t wsm, QWidget *parent) : QComboBox(parent), - osg_(NULL), index_(-1), wsm_(wsm) { @@ -24,12 +24,6 @@ namespace gepetto { { } - void SelectionHandler::setParentOSG(OSGWidget* parent) - { - osg_ = parent; - changeMode(currentIndex()); - } - SelectionMode* SelectionHandler::mode () { assert(index_ >= 0 && index_ < (int)modes_.size()); @@ -38,23 +32,22 @@ namespace gepetto { void SelectionHandler::changeMode(int index) { - if (osg_ != NULL) { - foreach(QString name, selected_) { - wsm_->setHighlight(name.toStdString(), 0); - } - if (index_ != -1) { - modes_[index_]->reset(); - disconnect(osg_, SIGNAL(clicked(SelectionEvent*)), - modes_[index_], SLOT(onSelect(SelectionEvent*))); - disconnect(modes_[index_], SIGNAL(selectedBodies(QStringList)), - this, SLOT(getBodies(QStringList))); - } - index_ = index; - connect(osg_, SIGNAL(clicked(SelectionEvent*)), - modes_[index], SLOT(onSelect(SelectionEvent*))); - connect(modes_[index], SIGNAL(selectedBodies(QStringList)), - SLOT(getBodies(QStringList))); + BodyTreeWidget* bt = MainWindow::instance()->bodyTree(); + foreach(QString name, selected_) { + wsm_->setHighlight(name.toStdString(), 0); + } + if (index_ != -1) { + modes_[index_]->reset(); + disconnect(bt, SIGNAL(bodySelected(SelectionEvent*)), + modes_[index_], SLOT(onSelect(SelectionEvent*))); + disconnect(modes_[index_], SIGNAL(selectedBodies(QStringList)), + this, SLOT(getBodies(QStringList))); } + index_ = index; + connect(bt, SIGNAL(bodySelected(SelectionEvent*)), + modes_[index], SLOT(onSelect(SelectionEvent*))); + connect(modes_[index], SIGNAL(selectedBodies(QStringList)), + SLOT(getBodies(QStringList))); } void SelectionHandler::addMode(SelectionMode* mode)