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  experimental_cb_ = new QCheckBox("Experimental");
57  experimental_cb_->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
58 
59  pause_button_ = new QPushButton("Pause");
60  pause_button_->setToolTip("Freeze ROS time.");
61  pause_button_->setCheckable(true);
62 
63  sync_mode_selector_ = new QComboBox(this);
64  sync_mode_selector_->addItem("Off");
65  sync_mode_selector_->addItem("Exact");
66  sync_mode_selector_->addItem("Approximate");
67  sync_mode_selector_->setSizeAdjustPolicy(QComboBox::AdjustToContents);
68  sync_mode_selector_->setToolTip(
69  "Allows you to synchronize the ROS time and Tf transforms to a given source.");
70 
71  // choose time sync signal
72  sync_source_selector_ = new QComboBox(this);
73  sync_source_selector_->setSizeAdjustPolicy(QComboBox::AdjustToContents);
74  sync_source_selector_->setToolTip("Time source to use for synchronization.");
75 
76  experimental_widget_ = new QWidget(this);
77  QHBoxLayout* experimental_layout = new QHBoxLayout(this);
78  experimental_layout->addWidget(pause_button_);
79  experimental_layout->addWidget(new QLabel("Synchronization:"));
80  experimental_layout->addWidget(sync_mode_selector_);
81  experimental_layout->addWidget(new QLabel("Source:"));
82  experimental_layout->addWidget(sync_source_selector_);
83  experimental_layout->addSpacing(20);
84  experimental_layout->setContentsMargins(0, 0, 20, 0);
85  experimental_widget_->setLayout(experimental_layout);
86 
87  old_widget_ = new QWidget(this);
88  QHBoxLayout* old_layout = new QHBoxLayout(this);
89  old_layout->addWidget(new QLabel("ROS Elapsed:"));
90  old_layout->addWidget(ros_elapsed_label_);
91  old_layout->addWidget(new QLabel("Wall Time:"));
92  old_layout->addWidget(wall_time_label_);
93  old_layout->addWidget(new QLabel("Wall Elapsed:"));
94  old_layout->addWidget(wall_elapsed_label_);
95  old_layout->setContentsMargins(0, 0, 20, 0);
96  old_widget_->setLayout(old_layout);
97 
98  QHBoxLayout* layout = new QHBoxLayout(this);
99 
100  layout->addWidget(experimental_widget_);
101  layout->addWidget(new QLabel("ROS Time:"));
102  layout->addWidget(ros_time_label_);
103  layout->addWidget(old_widget_);
104  layout->addStretch(100);
105  layout->addWidget(experimental_cb_);
106 
107  layout->addStretch();
108  layout->setContentsMargins(11, 5, 11, 5);
109 
110  connect(experimental_cb_, SIGNAL(toggled(bool)), this, SLOT(experimentalToggled(bool)));
111  connect(pause_button_, SIGNAL(toggled(bool)), this, SLOT(pauseToggled(bool)));
112  connect(sync_mode_selector_, SIGNAL(activated(int)), this, SLOT(syncModeSelected(int)));
113  connect(sync_source_selector_, SIGNAL(activated(int)), this, SLOT(syncSourceSelected(int)));
114 }
115 
117 {
118  connect(vis_manager_, SIGNAL(preUpdate()), this, SLOT(update()));
119 
120  DisplayGroup* display_group = vis_manager_->getRootDisplayGroup();
121  onDisplayAdded(display_group);
122 
123  syncModeSelected(0);
124  pauseToggled(false);
125 }
126 
127 void TimePanel::load(const Config& config)
128 {
129  Panel::load(config);
130  int sync_mode;
131  if (config.mapGetInt("SyncMode", &sync_mode))
132  {
133  sync_mode_selector_->setCurrentIndex(sync_mode);
134  syncModeSelected(sync_mode);
135  }
136  config.mapGetString("SyncSource", &config_sync_source_);
137  bool experimental = false;
138  config.mapGetBool("Experimental", &experimental);
139  experimental_cb_->setChecked(experimental);
140  experimentalToggled(experimental);
141 }
142 
143 void TimePanel::save(Config config) const
144 {
145  Panel::save(config);
146  config.mapSetValue("SyncMode", sync_mode_selector_->currentIndex());
147  config.mapSetValue("SyncSource", sync_source_selector_->currentText());
148  config.mapSetValue("Experimental", experimental_cb_->checkState() == Qt::Checked);
149 }
150 
152 {
153  DisplayGroup* display_group = qobject_cast<DisplayGroup*>(display);
154  if (display_group)
155  {
156  connect(display_group, SIGNAL(displayAdded(rviz::Display*)), this,
157  SLOT(onDisplayAdded(rviz::Display*)));
158  connect(display_group, SIGNAL(displayRemoved(rviz::Display*)), this,
160 
161  for (int i = 0; i < display_group->numDisplays(); i++)
162  {
163  rviz::Display* display = display_group->getDisplayAt(i);
164  onDisplayAdded(display);
165  }
166  }
167  else
168  {
169  connect(display, SIGNAL(timeSignal(ros::Time)), this, SLOT(onTimeSignal(ros::Time)));
170  }
171 }
172 
174 {
175  QString name = display->getName();
176  int index = sync_source_selector_->findData(QVariant((qulonglong)display));
177  if (index >= 0)
178  {
179  sync_source_selector_->removeItem(index);
180  }
181 }
182 
184 {
185  Display* display = qobject_cast<Display*>(sender());
186  if (!display)
187  return;
188 
189  QString name = display->getName();
190  int index = sync_source_selector_->findData(QVariant((qulonglong)display));
191 
192  // if we loaded the sync source name from the config, we need to
193  // switch to it as soon as we get a signal
194  if (index < 0 && name == config_sync_source_)
195  {
196  sync_source_selector_->addItem(name, QVariant((qulonglong)display));
197  index = sync_source_selector_->findData(QVariant((qulonglong)display));
198  sync_source_selector_->setCurrentIndex(index);
199  config_sync_source_.clear();
200  }
201 
202  if (index < 0)
203  {
204  sync_source_selector_->addItem(name, QVariant((qulonglong)display));
205  }
206  else
207  {
208  sync_source_selector_->setItemText(index, name);
209  if (sync_source_selector_->currentIndex() == index)
210  {
212  }
213  }
214 }
215 
217 {
218  QLineEdit* label = new QLineEdit;
219  label->setReadOnly(true);
220  return label;
221 }
222 
223 void TimePanel::fillTimeLabel(QLineEdit* label, double time)
224 {
225  label->setText(QString::number(time, 'f', 2));
226 }
227 
229 {
234 }
235 
236 void TimePanel::pauseToggled(bool checked)
237 {
239 }
240 
242 {
243  old_widget_->setVisible(!checked);
244  experimental_widget_->setVisible(checked);
246  {
247  if (!checked)
248  {
249  pauseToggled(false);
250  syncModeSelected(0);
251  }
252  else
253  {
254  pauseToggled(pause_button_->isChecked());
255  syncModeSelected(sync_mode_selector_->currentIndex());
256  }
257  }
258 }
259 
260 void TimePanel::syncSourceSelected(int /*index*/)
261 {
262  // clear whatever was loaded from the config
263  config_sync_source_.clear();
265 }
266 
268 {
270  sync_source_selector_->setEnabled(mode != FrameManager::SyncOff);
272 }
273 
274 } // namespace rviz
QLineEdit * wall_elapsed_label_
Definition: time_panel.h:99
QPushButton * pause_button_
Definition: time_panel.h:92
QWidget * experimental_widget_
Definition: time_panel.h:86
QString config_sync_source_
Definition: time_panel.h:88
VisualizationManager * vis_manager_
Definition: panel.h:113
void save(Config config) const override
Definition: time_panel.cpp:143
FrameManager * getFrameManager() const override
Return the FrameManager instance.
QComboBox * sync_source_selector_
Definition: time_panel.h:93
void fillTimeLabel(QLineEdit *label, double time)
Definition: time_panel.cpp:223
void pauseToggled(bool checked)
Definition: time_panel.cpp:236
virtual int numDisplays() const
Return the number of child Displays.
QCheckBox * experimental_cb_
Definition: time_panel.h:90
QComboBox * sync_mode_selector_
Definition: time_panel.h:94
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
bool mapGetString(const QString &key, QString *value_out) const
Convenience function for looking up a named string.
Definition: config.cpp:293
TimePanel(QWidget *parent=nullptr)
Definition: time_panel.cpp:49
void mapSetValue(const QString &key, QVariant value)
Set a named child to the given value.
Definition: config.cpp:196
void onInitialize() override
Definition: time_panel.cpp:116
Configuration data storage class.
Definition: config.h:124
double getWallClock()
Return the wall clock time, in seconds since 1970.
QWidget * old_widget_
Definition: time_panel.h:85
QLineEdit * ros_elapsed_label_
Definition: time_panel.h:97
QLineEdit * ros_time_label_
Definition: time_panel.h:96
double getROSTimeElapsed()
Return the ROS time in seconds since the last reset.
void experimentalToggled(bool checked)
Definition: time_panel.cpp:241
A Display object which stores other Displays as children.
Definition: display_group.h:47
DisplayGroup * getRootDisplayGroup() const override
virtual Display * getDisplayAt(int index) const
Return the index-th Display in this group, or NULL if the index is invalid.
virtual QString getName() const
Return the name of this Property as a QString.
Definition: property.cpp:164
void onTimeSignal(ros::Time time)
Definition: time_panel.cpp:183
void syncSourceSelected(int index)
Definition: time_panel.cpp:260
double getROSTime()
Return the ROS time, in seconds.
void setPause(bool pause)
Enable/disable pause mode.
void onDisplayAdded(rviz::Display *display)
Definition: time_panel.cpp:151
void syncModeSelected(int index)
Definition: time_panel.cpp:267
bool mapGetBool(const QString &key, bool *value_out) const
Convenience function for looking up a named boolean.
Definition: config.cpp:282
QLineEdit * makeTimeLabel()
Definition: time_panel.cpp:216
void syncTime(ros::Time time)
Synchronize with given time.
void load(const Config &config) override
Definition: time_panel.cpp:127
double getWallClockElapsed()
Return the wall clock time in seconds since the last reset.
void setSyncMode(SyncMode mode)
Set synchronization mode (off/exact/approximate)
void notifyConfigChanged()
Notify this VisualizationManager that something about its display configuration has changed...
QLineEdit * wall_time_label_
Definition: time_panel.h:98
virtual void load(const Config &config)
Override to load configuration data. This version loads the name of the panel.
Definition: panel.cpp:56
bool mapGetInt(const QString &key, int *value_out) const
Convenience function for looking up a named integer.
Definition: config.cpp:240
void onDisplayRemoved(rviz::Display *display)
Definition: time_panel.cpp:173


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat May 27 2023 02:06:25