trajectory_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 {
42 TrajectoryPanel::TrajectoryPanel(QWidget* parent) : Panel(parent)
43 {
44 }
45 
47 {
48 }
49 
51 {
52  slider_ = new QSlider(Qt::Horizontal);
53  slider_->setTickInterval(1);
54  slider_->setMinimum(0);
55  slider_->setMaximum(0);
56  slider_->setTickPosition(QSlider::TicksBelow);
57  slider_->setPageStep(1);
58  slider_->setEnabled(false);
59  connect(slider_, SIGNAL(valueChanged(int)), this, SLOT(sliderValueChanged(int)));
60 
61  maximum_label_ = new QLabel(QString::number(slider_->maximum()));
62  minimum_label_ = new QLabel(QString::number(slider_->minimum()));
63  minimum_label_->setFixedWidth(20);
64 
65  button_ = new QPushButton();
66  button_->setText("Pause");
67  button_->setEnabled(false);
68  connect(button_, SIGNAL(clicked()), this, SLOT(buttonClicked()));
69 
70  QHBoxLayout* layout = new QHBoxLayout;
71  layout->addWidget(new QLabel("Waypoint:"));
72  layout->addWidget(minimum_label_);
73  layout->addWidget(slider_);
74  layout->addWidget(maximum_label_);
75  layout->addWidget(button_);
76  setLayout(layout);
77 
78  paused_ = false;
79  parentWidget()->setVisible(false);
80 }
81 
83 {
84  show();
85  parentWidget()->show();
86 }
87 
89 {
90  hide();
91  paused_ = false;
92  parentWidget()->hide();
93 }
94 
95 void TrajectoryPanel::update(int way_point_count)
96 {
97  int max_way_point = std::max(0, way_point_count - 1);
98 
99  slider_->setEnabled(way_point_count != 0);
100  button_->setEnabled(way_point_count != 0);
101 
102  last_way_point_ = max_way_point;
103  paused_ = false;
104  slider_->setSliderPosition(0);
105  slider_->setMaximum(max_way_point);
106  maximum_label_->setText(QString::number(max_way_point));
107 }
108 
110 {
111  if (pause)
112  {
113  button_->setText("Play");
114  paused_ = true;
115  }
116  else
117  {
118  button_->setText("Pause");
119  paused_ = false;
120  if (slider_->sliderPosition() == last_way_point_)
121  slider_->setSliderPosition(0);
122  }
123 }
124 
126 {
127  slider_->setSliderPosition(position);
128 }
129 
131 {
132  minimum_label_->setText(QString::number(value));
133 }
134 
136 {
137  if (paused_)
138  pauseButton(false);
139  else
140  pauseButton(true);
141 }
142 
143 } // namespace moveit_rviz_plugin
void update(int way_point_count)


visualization
Author(s): Ioan Sucan , Dave Coleman , Sachin Chitta
autogenerated on Sun Oct 18 2020 13:19:09