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


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat Apr 27 2019 02:33:42