@@ -482,66 +482,35 @@ QVBoxLayout * AutowareStatePanel::makeVelocityLimitGroup()
482
482
483
483
void AutowareStatePanel::onOperationMode (const OperationModeState::ConstSharedPtr msg)
484
484
{
485
- auto changeButtonState = [this ](
486
- CustomSegmentedButtonItem * button,
487
- const bool is_desired_mode_available,
488
- const uint8_t current_mode = OperationModeState::UNKNOWN,
489
- const uint8_t desired_mode = OperationModeState::STOP) {
490
- // reset all button states
485
+ auto updateButtonState = [](CustomSegmentedButtonItem* button, bool is_available,
486
+ uint8_t current_mode, uint8_t desired_mode, bool disable) {
487
+ bool is_checked = (current_mode == desired_mode);
491
488
button->setHovered (false );
492
- button->setChecked (false );
493
- button->setActivated (false );
494
- button->setDisabledButton (true );
495
- button->setCheckableButton (false );
496
-
497
- // and set them accordingly
498
- if (is_desired_mode_available) {
499
- if (current_mode == desired_mode) {
500
- // Enabled and Checked
501
- button->setChecked (true );
502
- button->setActivated (true );
503
- button->setCheckableButton (false );
504
- button->setDisabledButton (false );
505
- } else {
506
- // Enabled and Checkable
507
- button->setChecked (false );
508
- button->setActivated (false );
509
- button->setCheckableButton (true );
510
- button->setDisabledButton (false );
511
- }
512
- } else {
513
- // Disabled and Unchecked
514
- button->setChecked (false );
515
- button->setActivated (false );
516
- button->setCheckableButton (false );
517
- button->setDisabledButton (true );
518
- }
489
+
490
+ button->setActivated (is_checked);
491
+ button->setChecked (is_checked);
492
+ button->setDisabledButton (disable || !is_available);
493
+ button->setCheckableButton (!disable && is_available && !is_checked);
519
494
};
520
495
521
- // Button
522
- changeButtonState (
523
- auto_button_ptr_, msg->is_autonomous_mode_available , msg->mode , OperationModeState::AUTONOMOUS);
524
- changeButtonState (
525
- stop_button_ptr_, msg->is_stop_mode_available , msg->mode , OperationModeState::STOP);
526
- changeButtonState (
527
- local_button_ptr_, msg->is_local_mode_available , msg->mode , OperationModeState::LOCAL);
528
- changeButtonState (
529
- remote_button_ptr_, msg->is_remote_mode_available , msg->mode , OperationModeState::REMOTE);
496
+ bool disable_buttons = msg->is_in_transition ;
497
+
498
+ updateButtonState (auto_button_ptr_, msg->is_autonomous_mode_available , msg->mode , OperationModeState::AUTONOMOUS, disable_buttons);
499
+ updateButtonState (stop_button_ptr_, msg->is_stop_mode_available , msg->mode , OperationModeState::STOP, disable_buttons);
500
+ updateButtonState (local_button_ptr_, msg->is_local_mode_available , msg->mode , OperationModeState::LOCAL, disable_buttons);
501
+ updateButtonState (remote_button_ptr_, msg->is_remote_mode_available , msg->mode , OperationModeState::REMOTE, disable_buttons);
530
502
531
503
// toggle switch for control mode
532
- auto changeToggleSwitchState = [this ](CustomToggleSwitch * toggle_switch, const bool is_enabled) {
533
- bool oldState = toggle_switch->blockSignals (true ); // Block signals
504
+ auto changeToggleSwitchState = [](CustomToggleSwitch * toggle_switch, const bool is_enabled) {
505
+ // Flick the switch without triggering its function
506
+ bool old_state = toggle_switch->blockSignals (true );
534
507
toggle_switch->setCheckedState (!is_enabled);
535
- toggle_switch->blockSignals (oldState); // Restore original signal blocking state
508
+ toggle_switch->blockSignals (old_state);
536
509
};
537
- if (!msg->is_in_transition ) { // would cause a on off on flicker if in transition
538
- changeToggleSwitchState (control_mode_switch_ptr_, !msg->is_autoware_control_enabled );
539
- }
540
510
541
- // routing
542
- if (msg->is_in_transition ) {
543
- routing_icon->updateStyle (
544
- Pending, QColor (autoware::state_rviz_plugin::colors::default_colors.warning .c_str ()));
511
+ if (!msg->is_in_transition ) {
512
+ // would cause an on/off/on flicker if in transition
513
+ changeToggleSwitchState (control_mode_switch_ptr_, !msg->is_autoware_control_enabled );
545
514
}
546
515
}
547
516
0 commit comments