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

Added Reset button to world_control #476

Merged
merged 8 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
12 changes: 12 additions & 0 deletions src/plugins/world_control/WorldControl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,18 @@ void WorldControl::OnPause()
this->dataPtr->SendEventMsg(msg);
}

/////////////////////////////////////////////////
void WorldControl::OnReset()
{
gz::msgs::WorldControl msg;
auto msgReset = new gz::msgs::WorldReset();
ahcorde marked this conversation as resolved.
Show resolved Hide resolved
msgReset->set_all(true);
msg.set_pause(true);
msg.set_allocated_reset(msgReset);

this->dataPtr->SendEventMsg(msg);
}

/////////////////////////////////////////////////
void WorldControl::OnStepCount(const unsigned int _steps)
{
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/world_control/WorldControl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ namespace plugins
/// \brief Callback in Qt thread when pause button is clicked.
public slots: void OnPause();

/// \brief Callback in Qt thread when reset button is clicked.
public slots: void OnReset();

/// \brief Callback in Qt thread when step button is clicked.
public slots: void OnStep();

Expand All @@ -102,6 +105,9 @@ namespace plugins
/// \brief Notify that it's now paused.
signals: void paused();

/// \brief Notify that it's now resetted.
signals: void reset();

/// \brief Subscriber callback when new world statistics are received
private: void OnWorldStatsMsg(const gz::msgs::WorldStatistics &_msg);

Expand Down
30 changes: 29 additions & 1 deletion src/plugins/world_control/WorldControl.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ RowLayout {
id: worldControl
width: 200
spacing: 2
Layout.minimumWidth: 121
Layout.minimumWidth: 200
Layout.minimumHeight: 100

Connections {
Expand Down Expand Up @@ -52,6 +52,11 @@ RowLayout {
*/
property bool showPlay: false

/**
* True to show reset button
*/
property bool showReset: true

/**
* True to show step buttons
*/
Expand All @@ -67,6 +72,11 @@ RowLayout {
*/
property string playIcon: "\u25B6"

/**
* Reset button
*/
property string resetIcon: "\u25A0"

/**
* Pause icon
*/
Expand All @@ -82,6 +92,24 @@ RowLayout {
*/
property bool paused: false

/**
* Reset
*/
RoundButton {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a hovered tooltip that states what reset does?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id: stopButton
objectName: "stopButton"
visible: showReset
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should reset only be visible if the sim is paused?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you might want to reset when the simulation is running

text: resetIcon
checkable: true
Layout.alignment : Qt.AlignVCenter
Layout.minimumWidth: width
Layout.leftMargin: 10
onClicked: {
WorldControl.OnReset()
}
Material.background: Material.primary
}

/**
* Play / pause
*/
Expand Down
1 change: 1 addition & 0 deletions src/plugins/world_control/WorldControlEventListener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ bool WorldControlEventListener::eventFilter(QObject *_obj, QEvent *_event)
{
this->listenedToPlay = !worldControlEvent->WorldControlInfo().pause();
this->listenedToPause = worldControlEvent->WorldControlInfo().pause();
this->listenedToReset = worldControlEvent->WorldControlInfo().reset().all();
this->listenedToStep =
worldControlEvent->WorldControlInfo().multi_step() > 0u;
}
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/world_control/WorldControlEventListener.hh
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ namespace gui
/// \brief Whether a pause event has been received (true) or not (false)
public: bool listenedToPause{false};

/// \brief Whether a pause event has been received (true) or not (false)
/// \brief Whether a step event has been received (true) or not (false)
public: bool listenedToStep{false};

/// \brief Whether a reset event has been received (true) or not (false)
public: bool listenedToReset{false};
};
}
}
Expand Down