From d9971311ed2efb6f68fb92002f51a2bce0e67ef4 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 5 Jul 2012 13:27:17 +0200 Subject: [PATCH] Fix problems with picking callback function --- src/Mod/Part/Gui/DlgPrimitives.cpp | 47 ++++++++++++++++++++++-------- src/Mod/Part/Gui/DlgPrimitives.h | 4 ++- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/Mod/Part/Gui/DlgPrimitives.cpp b/src/Mod/Part/Gui/DlgPrimitives.cpp index 3e4628646..7ef822edf 100644 --- a/src/Mod/Part/Gui/DlgPrimitives.cpp +++ b/src/Mod/Part/Gui/DlgPrimitives.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include #include @@ -270,6 +271,9 @@ DlgPrimitives::~DlgPrimitives() void DlgPrimitives::pickCallback(void * ud, SoEventCallback * n) { const SoMouseButtonEvent * mbe = static_cast(n->getEvent()); + Picker* pick = reinterpret_cast(ud); + if (pick->exitCode >= 0) + pick->loop.exit(pick->exitCode); // Mark all incoming mouse button events as handled, especially, to deactivate the selection node n->setHandled(); @@ -277,16 +281,14 @@ void DlgPrimitives::pickCallback(void * ud, SoEventCallback * n) if (mbe->getState() == SoButtonEvent::DOWN) { const SoPickedPoint * point = n->getPickedPoint(); if (point) { - Picker* pick = reinterpret_cast(ud); if (pick->pickedPoint(point)) { - pick->loop.exit(0); + pick->exitCode = 0; } } } } else if (mbe->getButton() == SoMouseButtonEvent::BUTTON2) { if (mbe->getState() == SoButtonEvent::UP) { - Picker* pick = reinterpret_cast(ud); pick->loop.exit(1); } } @@ -305,9 +307,17 @@ void DlgPrimitives::executeCallback(Picker* p) if (!viewer->isEditing()) { viewer->setEditing(true); viewer->setRedirectToSceneGraph(true); + SoNode* root = viewer->getSceneGraph(); + int mode; + if (root && root->getTypeId().isDerivedFrom(Gui::SoFCUnifiedSelection::getClassTypeId())) { + mode = static_cast(root)->selectionMode.getValue(); + static_cast(root)->selectionMode.setValue(Gui::SoFCUnifiedSelection::OFF); + } viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), pickCallback, p); this->setDisabled(true); int ret = p->loop.exec(); + if (root && root->getTypeId().isDerivedFrom(Gui::SoFCUnifiedSelection::getClassTypeId())) + static_cast(root)->selectionMode.setValue(mode); this->setEnabled(true); viewer->setEditing(false); viewer->setRedirectToSceneGraph(false); @@ -587,6 +597,9 @@ Location::~Location() viewer->setEditing(false); viewer->setRedirectToSceneGraph(false); viewer->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), pickCallback,this); + SoNode* root = viewer->getSceneGraph(); + if (root && root->getTypeId().isDerivedFrom(Gui::SoFCUnifiedSelection::getClassTypeId())) + static_cast(root)->selectionMode.setValue(this->mode); } } @@ -605,6 +618,11 @@ void Location::on_viewPositionButton_clicked() viewer->setEditing(true); viewer->setRedirectToSceneGraph(true); viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), pickCallback, this); + SoNode* root = viewer->getSceneGraph(); + if (root && root->getTypeId().isDerivedFrom(Gui::SoFCUnifiedSelection::getClassTypeId())) { + this->mode = static_cast(root)->selectionMode.getValue(); + static_cast(root)->selectionMode.setValue(Gui::SoFCUnifiedSelection::OFF); + } } } } @@ -617,15 +635,7 @@ void Location::pickCallback(void * ud, SoEventCallback * n) // Mark all incoming mouse button events as handled, especially, to deactivate the selection node n->getAction()->setHandled(); if (mbe->getButton() == SoMouseButtonEvent::BUTTON1) { - if (mbe->getState() == SoButtonEvent::UP) { - n->setHandled(); - view->setEditing(false); - view->setRedirectToSceneGraph(false); - Location* dlg = reinterpret_cast(ud); - dlg->activeView = 0; - view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), pickCallback,ud); - } - else if (mbe->getState() == SoButtonEvent::DOWN) { + if (mbe->getState() == SoButtonEvent::DOWN) { const SoPickedPoint * point = n->getPickedPoint(); if (point) { SbVec3f pnt = point->getPoint(); @@ -637,6 +647,19 @@ void Location::pickCallback(void * ud, SoEventCallback * n) } } } + else if (mbe->getButton() == SoMouseButtonEvent::BUTTON2) { + if (mbe->getState() == SoButtonEvent::UP) { + n->setHandled(); + view->setEditing(false); + view->setRedirectToSceneGraph(false); + Location* dlg = reinterpret_cast(ud); + dlg->activeView = 0; + view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), pickCallback,ud); + SoNode* root = view->getSceneGraph(); + if (root && root->getTypeId().isDerivedFrom(Gui::SoFCUnifiedSelection::getClassTypeId())) + static_cast(root)->selectionMode.setValue(static_cast(ud)->mode); + } + } } QString Location::toPlacement() const diff --git a/src/Mod/Part/Gui/DlgPrimitives.h b/src/Mod/Part/Gui/DlgPrimitives.h index 178dff08a..4be65c31a 100644 --- a/src/Mod/Part/Gui/DlgPrimitives.h +++ b/src/Mod/Part/Gui/DlgPrimitives.h @@ -39,7 +39,7 @@ namespace PartGui { class Picker { public: - Picker() + Picker() : exitCode(-1) { } virtual ~Picker() @@ -51,6 +51,7 @@ public: void createPrimitive(QWidget* widget, const QString&, Gui::Document*); QString toPlacement(const gp_Ax2&) const; + int exitCode; QEventLoop loop; }; @@ -88,6 +89,7 @@ private Q_SLOTS: private: static void pickCallback(void * ud, SoEventCallback * n); + int mode; QPointer activeView; Ui_Location ui; };