diff --git a/src/gui/plugins/scene3d/Scene3D.cc b/src/gui/plugins/scene3d/Scene3D.cc index 99bbe5b7d4..b6e3dc9af1 100644 --- a/src/gui/plugins/scene3d/Scene3D.cc +++ b/src/gui/plugins/scene3d/Scene3D.cc @@ -264,6 +264,10 @@ inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { /// resource with the shapes plugin or not public: bool isPlacing = false; + /// \brief Atomic bool indicating whether the dropdown menu + /// is currently enabled or disabled. + public: std::atomic_bool dropdownMenuEnabled = true; + /// \brief The SDF string of the resource to be used with plugins that spawn /// entities. public: std::string spawnSdfString; @@ -900,6 +904,7 @@ void IgnRenderer::HandleMouseEvent() std::lock_guard lock(this->dataPtr->mutex); this->BroadcastHoverPos(); this->BroadcastLeftClick(); + this->BroadcastRightClick(); this->HandleMouseContextMenu(); this->HandleModelPlacement(); this->HandleMouseTransformControl(); @@ -936,6 +941,26 @@ void IgnRenderer::BroadcastLeftClick() } } +///////////////////////////////////////////////// +void IgnRenderer::BroadcastRightClick() +{ + if (this->dataPtr->mouseEvent.Button() == common::MouseEvent::RIGHT && + this->dataPtr->mouseEvent.Type() == common::MouseEvent::RELEASE && + !this->dataPtr->mouseEvent.Dragging() && this->dataPtr->mouseDirty) + { + // If the dropdown menu is disabled, quash the mouse event + if (!this->dataPtr->dropdownMenuEnabled) + this->dataPtr->mouseDirty = false; + + math::Vector3d pos = this->ScreenToScene(this->dataPtr->mouseEvent.Pos()); + + ignition::gui::events::RightClickToScene rightClickToSceneEvent(pos); + ignition::gui::App()->sendEvent( + ignition::gui::App()->findChild(), + &rightClickToSceneEvent); + } +} + ///////////////////////////////////////////////// void IgnRenderer::HandleMouseContextMenu() { @@ -1821,6 +1846,12 @@ void IgnRenderer::SetModelPath(const std::string &_filePath) this->dataPtr->spawnSdfPath = _filePath; } +///////////////////////////////////////////////// +void IgnRenderer::SetDropdownMenuEnabled(bool _enableDropdownMenu) +{ + this->dataPtr->dropdownMenuEnabled = _enableDropdownMenu; +} + ///////////////////////////////////////////////// void IgnRenderer::SetRecordVideo(bool _record, const std::string &_format, const std::string &_savePath) @@ -2901,6 +2932,18 @@ bool Scene3D::eventFilter(QObject *_obj, QEvent *_event) renderWindow->SetModelPath(spawnPreviewPathEvent->FilePath()); } } + else if (_event->type() == + ignition::gui::events::DropdownMenuEnabled::kType) + { + auto dropdownMenuEnabledEvent = + reinterpret_cast(_event); + if (dropdownMenuEnabledEvent) + { + auto renderWindow = this->PluginItem()->findChild(); + renderWindow->SetDropdownMenuEnabled( + dropdownMenuEnabledEvent->MenuEnabled()); + } + } // Standard event processing return QObject::eventFilter(_obj, _event); @@ -2932,6 +2975,13 @@ void RenderWindowItem::SetModelPath(const std::string &_filePath) this->dataPtr->renderThread->ignRenderer.SetModelPath(_filePath); } +///////////////////////////////////////////////// +void RenderWindowItem::SetDropdownMenuEnabled(bool _enableDropdownMenu) +{ + this->dataPtr->renderThread->ignRenderer.SetDropdownMenuEnabled( + _enableDropdownMenu); +} + ///////////////////////////////////////////////// void RenderWindowItem::SetRecordVideo(bool _record, const std::string &_format, const std::string &_savePath) diff --git a/src/gui/plugins/scene3d/Scene3D.hh b/src/gui/plugins/scene3d/Scene3D.hh index 112de34a2b..cf966a4efe 100644 --- a/src/gui/plugins/scene3d/Scene3D.hh +++ b/src/gui/plugins/scene3d/Scene3D.hh @@ -199,6 +199,11 @@ inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { /// \param[in] _filePath Sdf path of the model to load in for the user. public: void SetModelPath(const std::string &_filePath); + /// \brief Set if the dropdown menu is enabled or disabled. + /// \param[in] _enableDropdownMenu The boolean to enable or disable + /// the dropdown menu + public: void SetDropdownMenuEnabled(bool _enableDropdownMenu); + /// \brief Set whether to record video /// \param[in] _record True to start video recording, false to stop. /// \param[in] _format Video encoding format: "mp4", "ogv" @@ -369,6 +374,9 @@ inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { /// \brief Broadcasts a left click within the scene private: void BroadcastLeftClick(); + /// \brief Broadcasts a right click within the scene + private: void BroadcastRightClick(); + /// \brief Generate a unique entity id. /// \return The unique entity id private: Entity UniqueId(); @@ -526,6 +534,11 @@ inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE { /// \param[in] _filePath File path of the model to load in for the user. public: void SetModelPath(const std::string &_filePath); + /// \brief Set if the dropdown menu is enabled or disabled. + /// \param[in] _enableDropdownMenu The boolean to enable or disable + /// the menu + public: void SetDropdownMenuEnabled(bool _enableDropdownMenu); + /// \brief Set whether to record video /// \param[in] _record True to start video recording, false to stop. /// \param[in] _format Video encoding format: "mp4", "ogv" diff --git a/src/gui/plugins/tape_measure/TapeMeasure.cc b/src/gui/plugins/tape_measure/TapeMeasure.cc index adbec33d47..882ce7e9c3 100644 --- a/src/gui/plugins/tape_measure/TapeMeasure.cc +++ b/src/gui/plugins/tape_measure/TapeMeasure.cc @@ -127,6 +127,13 @@ void TapeMeasure::Measure() this->Reset(); this->dataPtr->measure = true; QGuiApplication::setOverrideCursor(Qt::CrossCursor); + + // Notify Scene3D to disable the right click menu while we use it to + // cancel our current measuring action + ignition::gui::events::DropdownMenuEnabled dropdownMenuEnabledEvent(false); + ignition::gui::App()->sendEvent( + ignition::gui::App()->findChild(), + &dropdownMenuEnabledEvent); } ///////////////////////////////////////////////// @@ -149,6 +156,13 @@ void TapeMeasure::Reset() this->dataPtr->measure = false; this->newDistance(); QGuiApplication::restoreOverrideCursor(); + + // Notify Scene3D that we are done using the right click, so it can + // re-enable the settings menu + ignition::gui::events::DropdownMenuEnabled dropdownMenuEnabledEvent(true); + ignition::gui::App()->sendEvent( + ignition::gui::App()->findChild(), + &dropdownMenuEnabledEvent); } ///////////////////////////////////////////////// @@ -271,6 +285,15 @@ bool TapeMeasure::eventFilter(QObject *_obj, QEvent *_event) this->dataPtr->startPoint.Distance(this->dataPtr->endPoint); this->newDistance(); QGuiApplication::restoreOverrideCursor(); + + // Notify Scene3D that we are done using the right click, so it can + // re-enable the settings menu + ignition::gui::events::DropdownMenuEnabled + dropdownMenuEnabledEvent(true); + + ignition::gui::App()->sendEvent( + ignition::gui::App()->findChild(), + &dropdownMenuEnabledEvent); } this->dataPtr->currentId = this->dataPtr->kEndPointId; } @@ -293,6 +316,15 @@ bool TapeMeasure::eventFilter(QObject *_obj, QEvent *_event) this->Reset(); } } + // Cancel the current action if a right click is detected + else if (_event->type() == ignition::gui::events::RightClickToScene::kType) + { + if (this->dataPtr->measure) + { + this->Reset(); + } + } + return QObject::eventFilter(_obj, _event); }