From 529fef359a2434dd65640af8853b416227a09610 Mon Sep 17 00:00:00 2001 From: Joseph Mirabel <jmirabel@laas.fr> Date: Mon, 30 May 2016 14:09:29 +0200 Subject: [PATCH] PickHandler also returns position of mouse click on world frame. --- include/gepetto/gui/osgwidget.hh | 6 ++---- include/gepetto/gui/pick-handler.hh | 5 +---- pyplugins/gepetto/gui/pythonwidget.py | 6 +++--- src/gui/osgwidget.cc | 12 +++++------- src/gui/pick-handler.cc | 10 +++++++--- 5 files changed, 18 insertions(+), 21 deletions(-) diff --git a/include/gepetto/gui/osgwidget.hh b/include/gepetto/gui/osgwidget.hh index 09769c1..c213de1 100644 --- a/include/gepetto/gui/osgwidget.hh +++ b/include/gepetto/gui/osgwidget.hh @@ -58,7 +58,7 @@ namespace gepetto { WindowsManager::WindowID windowID () const; signals: - void selected (QString name); + void selected (QString name, QVector3D positionInWorldFrame); void requestMotion (graphics::NodePtr_t node, graphics::Node::Arrow direction, float speed); @@ -85,10 +85,8 @@ signals: virtual void paintEvent( QPaintEvent* paintEvent ); - private slots: - void transferSelected (QString name); - private: + void emitSelected (QString name, QVector3D positionInWorldFrame); osgGA::EventQueue* getEventQueue() const; osg::ref_ptr<osgQt::GraphicsWindowQt> graphicsWindow_; diff --git a/include/gepetto/gui/pick-handler.hh b/include/gepetto/gui/pick-handler.hh index 0bb88ce..fd281b2 100644 --- a/include/gepetto/gui/pick-handler.hh +++ b/include/gepetto/gui/pick-handler.hh @@ -16,7 +16,7 @@ namespace gepetto { Q_OBJECT public: - PickHandler (WindowsManagerPtr_t wsm); + PickHandler (OSGWidget* parent, WindowsManagerPtr_t wsm); virtual ~PickHandler(); @@ -31,9 +31,6 @@ namespace gepetto { void bodyTreeCurrentChanged (const QModelIndex ¤t, const QModelIndex &previous); - signals: - void selected (QString name); - private: std::list <graphics::NodePtr_t> computeIntersection (osgGA::GUIActionAdapter& aa, const float& x, const float& y); diff --git a/pyplugins/gepetto/gui/pythonwidget.py b/pyplugins/gepetto/gui/pythonwidget.py index 979cd2f..3356dbf 100644 --- a/pyplugins/gepetto/gui/pythonwidget.py +++ b/pyplugins/gepetto/gui/pythonwidget.py @@ -85,7 +85,7 @@ class Plugin(QtGui.QDockWidget): ### If present, this function is called when a new OSG Widget is created. def osgWidget(self, osgWindow): - osgWindow.connect('selected(QString)', self.selected) + osgWindow.connect('selected(QString,QVector3D)', self.selected) def resetConnection(self): self.client = Client() @@ -93,5 +93,5 @@ class Plugin(QtGui.QDockWidget): def refresh(self): self.nodeCreator.update() - def selected(self, name): - QtGui.QMessageBox.information(self, "Selected object", name) + def selected(self, name, posInWorldFrame): + QtGui.QMessageBox.information(self, "Selected object", name + " " + str(posInWorldFrame)) diff --git a/src/gui/osgwidget.cc b/src/gui/osgwidget.cc index 5737ea4..63ff462 100644 --- a/src/gui/osgwidget.cc +++ b/src/gui/osgwidget.cc @@ -81,7 +81,7 @@ namespace gepetto { : QWidget( parent, f ) , graphicsWindow_() , wsm_ (wm) - , pickHandler_ (new PickHandler (wsm_)) + , pickHandler_ (new PickHandler (this, wsm_)) , wid_ (-1) , wm_ () , viewer_ (new osgViewer::Viewer) @@ -134,8 +134,6 @@ namespace gepetto { 1); viewer_->addEventHandler(screenCapture_); viewer_->addEventHandler(new osgViewer::HelpHandler); - - connect(pickHandler_, SIGNAL(selected(QString)), SLOT(transferSelected(QString))); viewer_->addEventHandler(pickHandler_); wid_ = wm->createWindow (name.c_str(), viewer_, graphicsWindow_.get()); @@ -155,8 +153,8 @@ namespace gepetto { render_.start (); parent->bodyTree()->connect(this, - SIGNAL (selected(QString)), SLOT (selectBodyByName(QString))); - parent->connect(this, SIGNAL (selected(QString)), + SIGNAL (selected(QString,QVector3D)), SLOT (selectBodyByName(QString))); + parent->connect(this, SIGNAL (selected(QString,QVector3D)), SLOT (requestSelectJointFromBodyName(QString))); } @@ -198,9 +196,9 @@ namespace gepetto { // wsm_->lock().unlock(); } - void gepetto::gui::OSGWidget::transferSelected(QString name) + void OSGWidget::emitSelected(QString name, QVector3D positionInWorldFrame) { - emit selected (name); + emit selected (name, positionInWorldFrame); } void OSGWidget::onHome() diff --git a/src/gui/pick-handler.cc b/src/gui/pick-handler.cc index 13e25f2..e66f082 100644 --- a/src/gui/pick-handler.cc +++ b/src/gui/pick-handler.cc @@ -20,8 +20,10 @@ namespace gepetto { namespace gui { - PickHandler::PickHandler(WindowsManagerPtr_t wsm) - : wsm_ (wsm) + PickHandler::PickHandler(OSGWidget *parent, WindowsManagerPtr_t wsm) + : QObject (parent) + , wsm_ (wsm) + , parent_ (parent) , last_ () , pushed_ (false) , lastX_ (0) @@ -130,7 +132,9 @@ namespace gepetto { if (boost::regex_match (n->getID(), boost::regex ("^.*_[0-9]+$"))) continue; select (n); - emit selected (QString::fromStdString(n->getID ())); + osg::Vec3d p = it->getWorldIntersectPoint(); + QVector3D pWF (p[0],p[1],p[2]); + parent_->emitSelected(QString::fromStdString(n->getID ()), pWF); return nodes; // nodes.push_back(n); // break; -- GitLab