Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable right click menu when using measuring tool #458

Merged
merged 35 commits into from
Dec 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7d4ab56
init plugin template
Oct 22, 2020
32236cc
some updates
Oct 28, 2020
a062e20
Add marker placement
Nov 10, 2020
af399c9
Complete functionality
Nov 10, 2020
3f7f265
Tidy up
Nov 11, 2020
8f107d6
Merge branch 'ign-gazebo3' into jshep1/tape_measure_plugin
Nov 11, 2020
041e54b
Update docs
Nov 11, 2020
22d1c0f
Clean up
Nov 11, 2020
f0b022a
revert some changes
Nov 11, 2020
0dfec2f
Add crosshair cursor
Nov 11, 2020
38a6e4e
Merge branch 'ign-gazebo3' into jshep1/tape_measure_plugin
Nov 11, 2020
a0f20f6
Add shortcut and new icon
Nov 11, 2020
cf77ad8
Merge branch 'jshep1/tape_measure_plugin' of https://github.com/ignit…
Nov 11, 2020
2a84ddd
disable right menu when measuring
Nov 11, 2020
b07c5d9
Add docs
Nov 12, 2020
83b0a43
Updates
Nov 12, 2020
e69d95a
Add in trashcan icon
Nov 13, 2020
161e979
Merge branch 'ign-gazebo3' into jshep1/tape_measure_plugin
Nov 16, 2020
59d5b33
Merge branch 'ign-gazebo3' into jshep1/tape_measure_plugin
Nov 17, 2020
df26ea2
Merge branch 'ign-gazebo3' into jshep1/tape_measure_plugin
Nov 20, 2020
a7cbc13
add in gui events
Nov 20, 2020
a31264c
Remove events from gazebo gui
Nov 20, 2020
dda9038
requested fixes
Nov 20, 2020
4d41ebe
More fixes
Nov 20, 2020
744e2db
Merge branch 'ign-gazebo3' into jshep1/tape_measure_plugin
Nov 24, 2020
65d122a
handle key presses on cpp side
Nov 24, 2020
acaac9c
Merge branch 'ign-gazebo3' into jshep1/tape_measure_plugin
Dec 7, 2020
d8a7404
Merge branch 'ign-gazebo3' into jshep1/tape_measure_plugin
Dec 10, 2020
521939a
Merge branch 'jshep1/tape_measure_plugin' into jshep1/tape_measure_pl…
Dec 10, 2020
a07db06
Update for new gui events
Dec 11, 2020
0dd5811
Merge branch 'ign-gazebo3' into jshep1/tape_measure_plugin_pt2
Dec 16, 2020
8be928a
Merge branch 'ign-gazebo3' into jshep1/tape_measure_plugin_pt2
chapulina Dec 18, 2020
de63c5b
Merge branch 'ign-gazebo3' into jshep1/tape_measure_plugin_pt2
Dec 18, 2020
2957f5c
Merge branch 'ign-gazebo3' into jshep1/tape_measure_plugin_pt2
Dec 28, 2020
255a162
suggested fixes and lint
Dec 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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