time_panel.cpp
Go to the documentation of this file.
1 
2 /*
3  * Copyright (c) 2008, Willow Garage, Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * * Neither the name of the Willow Garage, Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include <QLabel>
32 #include <QLineEdit>
33 #include <QPushButton>
34 #include <QHBoxLayout>
35 #include <QButtonGroup>
36 #include <QCheckBox>
37 #include <QSlider>
38 #include <QComboBox>
39 
40 #include "visualization_manager.h"
41 #include "frame_manager.h"
42 
43 #include "display_group.h"
44 
45 #include "time_panel.h"
46 
47 namespace rviz
48 {
49 TimePanel::TimePanel(QWidget* parent) : Panel(parent)
50 {
55 
56  pause_button_ = new QPushButton(QIcon::fromTheme("media-playback-pause"), "Pause");
57  pause_button_->setToolTip("Freeze ROS time.");
58  pause_button_->setCheckable(true);
59 
60  sync_mode_selector_ = new QComboBox(this);
61  sync_mode_selector_->addItem("Off");
62  sync_mode_selector_->setItemData(FrameManager::SyncOff, "Display data using latest TF data",
63  Qt::ToolTipRole);
64  sync_mode_selector_->addItem("Exact");
65  sync_mode_selector_->setItemData(FrameManager::SyncExact, "Synchronize TF lookups to a source display",
66  Qt::ToolTipRole);
67  sync_mode_selector_->addItem("Approximate");
68  sync_mode_selector_->setItemData(
69  FrameManager::SyncApprox, "Synchronize to a source display in a smooth fashion", Qt::ToolTipRole);
70  sync_mode_selector_->addItem("Frame");
71  sync_mode_selector_->setItemData(FrameManager::SyncFrame, "Synchronize TF lookups within a frame",
72  Qt::ToolTipRole);
73  sync_mode_selector_->setSizeAdjustPolicy(QComboBox::AdjustToContents);
74  sync_mode_selector_->setToolTip(
75  "Allows you to synchronize the ROS time and Tf transforms to a given source.");
76 
77  // choose time sync signal
78  sync_source_selector_ = new QComboBox(this);
79  sync_source_selector_->setSizeAdjustPolicy(QComboBox::AdjustToContents);
80  sync_source_selector_->setToolTip("Time source to use for synchronization.");
81 
82  QHBoxLayout* layout = new QHBoxLayout(this);
83  layout->addWidget(pause_button_);
84  layout->addSpacing(10);
85 
86  layout->addWidget(new QLabel("Synchronization:"));
87  layout->addWidget(sync_mode_selector_);
88  layout->addWidget(sync_source_selector_);
89  layout->addSpacing(10);
90 
91  layout->addWidget(new QLabel("ROS Time:"));
92  layout->addWidget(ros_time_label_);
93  layout->addWidget(new QLabel("ROS Elapsed:"));
94  layout->addWidget(ros_elapsed_label_);
95  layout->addWidget(new QLabel("Wall Time:"));
96  layout->addWidget(wall_time_label_);
97  layout->addWidget(new QLabel("Wall Elapsed:"));
98  layout->addWidget(wall_elapsed_label_);
99 
100  layout->setContentsMargins(11, 5, 11, 5);
101  this->setLayout(layout);
102 
103  connect(pause_button_, &QPushButton::toggled, this, &TimePanel::pauseToggled);
104  connect(sync_mode_selector_, qOverload<int>(&QComboBox::activated), this, &TimePanel::syncModeSelected);
105  connect(sync_source_selector_, qOverload<int>(&QComboBox::activated), this,
107 }
108 
110 {
112 
113  DisplayGroup* display_group = vis_manager_->getRootDisplayGroup();
114  onDisplayAdded(display_group);
115 
116  syncModeSelected(0);
117  pauseToggled(false);
118 }
119 
120 void TimePanel::load(const Config& config)
121 {
123  int sync_mode;
124  if (config.mapGetInt("SyncMode", &sync_mode))
125  {
126  sync_mode_selector_->setCurrentIndex(sync_mode);
127  syncModeSelected(sync_mode);
128  }
129  config.mapGetString("SyncSource", &config_sync_source_);
130 }
131 
132 void TimePanel::save(Config config) const
133 {
135  config.mapSetValue("SyncMode", sync_mode_selector_->currentIndex());
136  config.mapSetValue("SyncSource", sync_source_selector_->currentText());
137 }
138 
140 {
141  DisplayGroup* display_group = qobject_cast<DisplayGroup*>(display);
142  if (display_group)
143  {
144  connect(display_group, &DisplayGroup::displayAdded, this, &TimePanel::onDisplayAdded);
145  connect(display_group, &DisplayGroup::displayRemoved, this, &TimePanel::onDisplayRemoved);
146 
147  for (int i = 0; i < display_group->numDisplays(); i++)
148  {
149  rviz::Display* display = display_group->getDisplayAt(i);
150  onDisplayAdded(display);
151  }
152  }
153  else
154  {
155  connect(display, &Display::timeSignal, this, &TimePanel::onTimeSignal);
156  }
157 }
158 
160 {
161  QString name = display->getName();
162  int index = sync_source_selector_->findData(QVariant((qulonglong)display));
163  if (index >= 0)
164  {
165  sync_source_selector_->removeItem(index);
166  }
167 }
168 
170 {
171  Display* display = qobject_cast<Display*>(sender());
172  if (!display)
173  return;
174 
175  QString name = display->getName();
176  int index = sync_source_selector_->findData(QVariant((qulonglong)display));
177 
178  // if we loaded the sync source name from the config, we need to
179  // switch to it as soon as we get a signal
180  if (index < 0 && name == config_sync_source_)
181  {
182  sync_source_selector_->addItem(name, QVariant((qulonglong)display));
183  index = sync_source_selector_->findData(QVariant((qulonglong)display));
184  sync_source_selector_->setCurrentIndex(index);
185  config_sync_source_.clear();
186  }
187 
188  if (index < 0)
189  {
190  sync_source_selector_->addItem(name, QVariant((qulonglong)display));
191  }
192  else
193  {
194  sync_source_selector_->setItemText(index, name);
195  if (sync_source_selector_->currentIndex() == index)
196  {
198  }
199  }
200 }
201 
203 {
204  QLineEdit* label = new QLineEdit;
205  label->setReadOnly(true);
206  return label;
207 }
208 
209 void TimePanel::fillTimeLabel(QLineEdit* label, double time)
210 {
211  label->setText(QString::number(time, 'f', 2));
212 }
213 
215 {
220 }
221 
222 void TimePanel::pauseToggled(bool checked)
223 {
225 }
226 
227 void TimePanel::syncSourceSelected(int /*index*/)
228 {
229  // clear whatever was loaded from the config
230  config_sync_source_.clear();
232 }
233 
235 {
239 }
240 
241 } // namespace rviz
rviz::VisualizationManager::getROSTimeElapsed
double getROSTimeElapsed()
Return the ROS time in seconds since the last reset.
Definition: visualization_manager.cpp:499
rviz::DisplayGroup::displayAdded
void displayAdded(rviz::Display *display)
rviz::VisualizationManager::getROSTime
double getROSTime()
Return the ROS time, in seconds.
Definition: visualization_manager.cpp:489
frame_manager.h
rviz::VisualizationManager::getRootDisplayGroup
DisplayGroup * getRootDisplayGroup() const override
Definition: visualization_manager.h:343
rviz::TimePanel::pauseToggled
void pauseToggled(bool checked)
Definition: time_panel.cpp:222
rviz::Panel
Definition: panel.h:41
rviz::TimePanel::sync_mode_selector_
QComboBox * sync_mode_selector_
Definition: time_panel.h:88
rviz::TimePanel::fillTimeLabel
void fillTimeLabel(QLineEdit *label, double time)
Definition: time_panel.cpp:209
rviz::TimePanel::wall_elapsed_label_
QLineEdit * wall_elapsed_label_
Definition: time_panel.h:93
rviz::TimePanel::save
void save(Config config) const override
Definition: time_panel.cpp:132
rviz::DisplayGroup::getDisplayAt
virtual Display * getDisplayAt(int index) const
Return the index-th Display in this group, or NULL if the index is invalid.
Definition: display_group.cpp:211
rviz::VisualizationManager::notifyConfigChanged
void notifyConfigChanged()
Notify this VisualizationManager that something about its display configuration has changed.
Definition: visualization_manager.cpp:580
rviz::VisualizationManager::getWallClockElapsed
double getWallClockElapsed()
Return the wall clock time in seconds since the last reset.
Definition: visualization_manager.cpp:494
rviz::TimePanel::sync_source_selector_
QComboBox * sync_source_selector_
Definition: time_panel.h:87
rviz::TimePanel::ros_time_label_
QLineEdit * ros_time_label_
Definition: time_panel.h:90
rviz::TimePanel::onInitialize
void onInitialize() override
Definition: time_panel.cpp:109
rviz::FrameManager::SyncOff
@ SyncOff
Definition: frame_manager.h:70
rviz::FrameManager::setSyncMode
void setSyncMode(SyncMode mode)
Set synchronization mode (off/exact/approximate)
Definition: frame_manager.cpp:115
rviz::Display
Definition: display.h:63
rviz::TimePanel::ros_elapsed_label_
QLineEdit * ros_elapsed_label_
Definition: time_panel.h:91
rviz::TimePanel::TimePanel
TimePanel(QWidget *parent=nullptr)
Definition: time_panel.cpp:49
rviz::DisplayGroup::displayRemoved
void displayRemoved(rviz::Display *display)
time_panel.h
rviz
Definition: add_display_dialog.cpp:54
rviz::Display::timeSignal
void timeSignal(ros::Time time, QPrivateSignal)
rviz::TimePanel::onTimeSignal
void onTimeSignal(ros::Time time)
Definition: time_panel.cpp:169
rviz::TimePanel::onDisplayAdded
void onDisplayAdded(rviz::Display *display)
Definition: time_panel.cpp:139
rviz::DisplayGroup::numDisplays
virtual int numDisplays() const
Return the number of child Displays.
Definition: display_group.cpp:342
rviz::TimePanel::makeTimeLabel
QLineEdit * makeTimeLabel()
Definition: time_panel.cpp:202
display_group.h
rviz::VisualizationManager::getFrameManager
FrameManager * getFrameManager() const override
Return the FrameManager instance.
Definition: visualization_manager.h:310
rviz::TimePanel::update
void update()
Definition: time_panel.cpp:214
rviz::FrameManager::syncTime
void syncTime(ros::Time time)
Synchronize with given time.
Definition: frame_manager.cpp:123
visualization_manager.h
rviz::FrameManager::SyncMode
SyncMode
Definition: frame_manager.h:68
rviz::FrameManager::SyncApprox
@ SyncApprox
Definition: frame_manager.h:72
rviz::TimePanel::wall_time_label_
QLineEdit * wall_time_label_
Definition: time_panel.h:92
rviz::Property::getName
virtual QString getName() const
Return the name of this Property as a QString.
Definition: property.cpp:164
rviz::FrameManager::SyncFrame
@ SyncFrame
Definition: frame_manager.h:73
ros::Time
rviz::TimePanel::syncSourceSelected
void syncSourceSelected(int index)
Definition: time_panel.cpp:227
rviz::Panel::load
virtual void load(const Config &config)
Override to load configuration data. This version loads the name of the panel.
Definition: panel.cpp:56
rviz::TimePanel::load
void load(const Config &config) override
Definition: time_panel.cpp:120
rviz::Panel::save
virtual void save(Config config) const
Override to save configuration data. This version saves the name and class ID of the panel.
Definition: panel.cpp:50
rviz::VisualizationManager::preUpdate
void preUpdate()
Emitted before updating all Displays.
rviz::TimePanel::onDisplayRemoved
void onDisplayRemoved(rviz::Display *display)
Definition: time_panel.cpp:159
rviz::VisualizationManager::getWallClock
double getWallClock()
Return the wall clock time, in seconds since 1970.
Definition: visualization_manager.cpp:484
rviz::TimePanel::syncModeSelected
void syncModeSelected(int index)
Definition: time_panel.cpp:234
rviz::TimePanel::pause_button_
QPushButton * pause_button_
Definition: time_panel.h:86
config
config
rviz::TimePanel::config_sync_source_
QString config_sync_source_
Definition: time_panel.h:84
rviz::Config
Configuration data storage class.
Definition: config.h:124
rviz::DisplayGroup
A Display object which stores other Displays as children.
Definition: display_group.h:47
rviz::FrameManager::setPause
void setPause(bool pause)
Enable/disable pause mode.
Definition: frame_manager.cpp:110
rviz::Panel::vis_manager_
VisualizationManager * vis_manager_
Definition: panel.h:113
rviz::FrameManager::SyncExact
@ SyncExact
Definition: frame_manager.h:71


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust, William Woodall
autogenerated on Fri Aug 2 2024 08:43:10