task_solution_panel.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2017, Yannick Jonetzko
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Yannick Jonetzko */
36 
38 #include <QHBoxLayout>
39 
40 namespace moveit_rviz_plugin {
41 TaskSolutionPanel::TaskSolutionPanel(QWidget* parent) : Panel(parent) {
42  empty_ = false;
43 }
44 
46 
48  slider_ = new QSlider(Qt::Horizontal);
49  slider_->setTickInterval(1);
50  slider_->setMinimum(0);
51  slider_->setMaximum(0);
52  slider_->setTickPosition(QSlider::TicksBelow);
53  slider_->setPageStep(1);
54  slider_->setEnabled(false);
55  connect(slider_, SIGNAL(valueChanged(int)), this, SLOT(sliderValueChanged(int)));
56 
57  maximum_label_ = new QLabel(QString::number(slider_->maximum()));
58  minimum_label_ = new QLabel(QString::number(slider_->minimum()));
59  minimum_label_->setFixedWidth(20);
60 
61  button_ = new QPushButton();
62  button_->setText("Pause");
63  button_->setEnabled(false);
64  connect(button_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
65 
66  QHBoxLayout* layout = new QHBoxLayout;
67  layout->addWidget(new QLabel("Waypoint:"));
68  layout->addWidget(minimum_label_);
69  layout->addWidget(slider_);
70  layout->addWidget(maximum_label_);
71  layout->addWidget(button_);
72  setLayout(layout);
73 
74  paused_ = false;
75  parentWidget()->setVisible(false);
76 }
77 
79  parentWidget()->show();
80 }
81 
83  paused_ = false;
84  parentWidget()->hide();
85 }
86 
87 void TaskSolutionPanel::update(int way_point_count) {
88  int max_way_point = std::max(1, way_point_count - 1);
89  empty_ = (way_point_count == 0);
90 
91  slider_->setEnabled(way_point_count >= 0);
92  button_->setEnabled(way_point_count >= 0);
93 
94  paused_ = false;
95  slider_->setMaximum(max_way_point);
96  maximum_label_->setText(way_point_count >= 0 ? QString::number(way_point_count) : "");
97  slider_->setSliderPosition(0);
98 }
99 
100 void TaskSolutionPanel::pauseButton(bool pause) {
101  if (pause) {
102  button_->setText("Play");
103  paused_ = true;
104  } else {
105  button_->setText("Pause");
106  paused_ = false;
107  if (slider_->sliderPosition() == slider_->maximum())
108  slider_->setSliderPosition(0);
109  }
110 }
111 
112 void TaskSolutionPanel::setSliderPosition(int position) {
113  slider_->setSliderPosition(position);
114 }
115 
117  QString text;
118  if (!slider_->isEnabled())
119  text = "";
120  else if (empty_)
121  text = value == 0 ? "S" : "E";
122  else
123  text = QString::number(value + 1);
124  minimum_label_->setText(text);
125 }
126 
128  if (paused_)
129  pauseButton(false);
130  else
131  pauseButton(true);
132 }
133 
134 } // namespace moveit_rviz_plugin
moveit_rviz_plugin::TaskSolutionPanel::empty_
bool empty_
Definition: task_solution_panel.h:148
task_solution_panel.h
moveit_rviz_plugin::TaskSolutionPanel::paused_
bool paused_
Definition: task_solution_panel.h:147
moveit_rviz_plugin::TaskSolutionPanel::onInitialize
void onInitialize() override
Definition: task_solution_panel.cpp:79
moveit_rviz_plugin::TaskSolutionPanel::button_
QPushButton * button_
Definition: task_solution_panel.h:145
moveit_rviz_plugin::TaskSolutionPanel::onDisable
void onDisable()
Definition: task_solution_panel.cpp:114
moveit_rviz_plugin::TaskSolutionPanel::onEnable
void onEnable()
Definition: task_solution_panel.cpp:110
moveit_rviz_plugin::TaskSolutionPanel::slider_
QSlider * slider_
Definition: task_solution_panel.h:142
moveit_rviz_plugin::TaskSolutionPanel::TaskSolutionPanel
TaskSolutionPanel(QWidget *parent=nullptr)
Definition: task_solution_panel.cpp:73
moveit_rviz_plugin::TaskSolutionPanel::minimum_label_
QLabel * minimum_label_
Definition: task_solution_panel.h:144
moveit_rviz_plugin::TaskSolutionPanel::sliderValueChanged
void sliderValueChanged(int value)
Definition: task_solution_panel.cpp:148
value
float value
moveit_rviz_plugin::TaskSolutionPanel::maximum_label_
QLabel * maximum_label_
Definition: task_solution_panel.h:143
text
text
moveit_rviz_plugin
moveit_rviz_plugin::TaskSolutionPanel::pauseButton
void pauseButton(bool check)
Definition: task_solution_panel.cpp:132
moveit_rviz_plugin::TaskSolutionPanel::buttonClicked
void buttonClicked()
Definition: task_solution_panel.cpp:159
moveit_rviz_plugin::TaskSolutionPanel::update
void update(int way_point_count)
Definition: task_solution_panel.cpp:119
moveit_rviz_plugin::TaskSolutionPanel::~TaskSolutionPanel
~TaskSolutionPanel() override
Definition: task_solution_panel.cpp:77
moveit_rviz_plugin::TaskSolutionPanel::setSliderPosition
void setSliderPosition(int position)
Definition: task_solution_panel.cpp:144


visualization
Author(s): Robert Haschke
autogenerated on Thu Feb 27 2025 03:39:51