Skip to content

Commit

Permalink
Disable right click menu when using measuring tool (#458)
Browse files Browse the repository at this point in the history
Signed-off-by: John Shepherd <[email protected]>

Co-authored-by: Louise Poubel <[email protected]>
  • Loading branch information
John Shepherd and chapulina authored Dec 29, 2020
1 parent ae2a1da commit 43412b5
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/gui/plugins/scene3d/Scene3D.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -900,6 +904,7 @@ void IgnRenderer::HandleMouseEvent()
std::lock_guard<std::mutex> lock(this->dataPtr->mutex);
this->BroadcastHoverPos();
this->BroadcastLeftClick();
this->BroadcastRightClick();
this->HandleMouseContextMenu();
this->HandleModelPlacement();
this->HandleMouseTransformControl();
Expand Down Expand Up @@ -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<ignition::gui::MainWindow *>(),
&rightClickToSceneEvent);
}
}

/////////////////////////////////////////////////
void IgnRenderer::HandleMouseContextMenu()
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<ignition::gui::events::DropdownMenuEnabled *>(_event);
if (dropdownMenuEnabledEvent)
{
auto renderWindow = this->PluginItem()->findChild<RenderWindowItem *>();
renderWindow->SetDropdownMenuEnabled(
dropdownMenuEnabledEvent->MenuEnabled());
}
}

// Standard event processing
return QObject::eventFilter(_obj, _event);
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions src/gui/plugins/scene3d/Scene3D.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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"
Expand Down
32 changes: 32 additions & 0 deletions src/gui/plugins/tape_measure/TapeMeasure.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<ignition::gui::MainWindow *>(),
&dropdownMenuEnabledEvent);
}

/////////////////////////////////////////////////
Expand All @@ -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<ignition::gui::MainWindow *>(),
&dropdownMenuEnabledEvent);
}

/////////////////////////////////////////////////
Expand Down Expand Up @@ -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<ignition::gui::MainWindow *>(),
&dropdownMenuEnabledEvent);
}
this->dataPtr->currentId = this->dataPtr->kEndPointId;
}
Expand All @@ -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);
}

Expand Down

0 comments on commit 43412b5

Please sign in to comment.