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 6 commits
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 @@ -311,6 +311,18 @@ void WorldControl::OnPause()
this->dataPtr->SendEventMsg(msg);
}

/////////////////////////////////////////////////
void WorldControl::OnReset()
{
msgs::WorldControl msg;
auto msgReset = new msgs::WorldReset();
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 @@ -82,6 +82,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 @@ -95,6 +98,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
75 changes: 74 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: "\u21bb"

/**
* Pause icon
*/
Expand All @@ -82,6 +92,66 @@ 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: {
confirmationDialogOnReset.open()
}
Material.background: Material.primary
ToolTip.visible: hovered
ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval
ToolTip.text: qsTr("Reset the simulation")
}

Shortcut {
sequence: "Ctrl+R"
onActivated: confirmationDialogOnReset.open()
}


/**
* Confirmation dialog on close button
*/
Dialog {
id: confirmationDialogOnReset
title: "Do you really want to reset the simulation?"
objectName: "confirmationDialogOnReset"

modal: true
focus: true
parent: ApplicationWindow.overlay
width: 500
x: (parent.width - width) / 2
y: (parent.height - height) / 2
closePolicy: Popup.CloseOnEscape
standardButtons: Dialog.Ok | Dialog.Discard

onAboutToShow: function () {
footer.standardButton(Dialog.Discard).text = "Abort"
footer.standardButton(Dialog.Ok).text = "Reset"
}

footer:
DialogButtonBox {
onClicked: function (btn) {
confirmationDialogOnReset.close()
if (btn == this.standardButton(Dialog.Ok)) {
WorldControl.OnReset()
}
}
}
}

/**
* Play / pause
*/
Expand All @@ -100,6 +170,9 @@ RowLayout {
else
WorldControl.OnPause()
}
ToolTip.visible: hovered
ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval
ToolTip.text: paused ? qsTr("Run the simulation") : qsTr("Pause the simulation")
Material.background: Material.primary
}

Expand Down
2 changes: 2 additions & 0 deletions src/plugins/world_control/WorldControlEventListener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ 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