$search
00001 00002 /* 00003 * Copyright (c) 2008, Willow Garage, Inc. 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions are met: 00008 * 00009 * * Redistributions of source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * * Redistributions in binary form must reproduce the above copyright 00012 * notice, this list of conditions and the following disclaimer in the 00013 * documentation and/or other materials provided with the distribution. 00014 * * Neither the name of the Willow Garage, Inc. nor the names of its 00015 * contributors may be used to endorse or promote products derived from 00016 * this software without specific prior written permission. 00017 * 00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00021 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00022 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00028 * POSSIBILITY OF SUCH DAMAGE. 00029 */ 00030 00031 #include <QLabel> 00032 #include <QLineEdit> 00033 #include <QPushButton> 00034 #include <QHBoxLayout> 00035 00036 #include "visualization_manager.h" 00037 00038 #include "time_panel.h" 00039 00040 namespace rviz 00041 { 00042 00043 TimePanel::TimePanel( QWidget* parent ) 00044 : QWidget( parent ) 00045 , manager_( NULL ) 00046 { 00047 wall_time_label_ = makeTimeLabel(); 00048 wall_elapsed_label_ = makeTimeLabel(); 00049 ros_time_label_ = makeTimeLabel(); 00050 ros_elapsed_label_ = makeTimeLabel(); 00051 00052 QPushButton* reset_button = new QPushButton( "Reset" ); 00053 00054 QHBoxLayout* layout = new QHBoxLayout; 00055 layout->addWidget( new QLabel( "Wall Time:" )); 00056 layout->addWidget( wall_time_label_ ); 00057 layout->addStretch( 1000 ); 00058 layout->addWidget( new QLabel( "Wall Elapsed:" )); 00059 layout->addWidget( wall_elapsed_label_ ); 00060 layout->addStretch( 1000 ); 00061 layout->addWidget( new QLabel( "ROS Time:" )); 00062 layout->addWidget( ros_time_label_ ); 00063 layout->addStretch( 1000 ); 00064 layout->addWidget( new QLabel( "ROS Elapsed:" )); 00065 layout->addWidget( ros_elapsed_label_ ); 00066 layout->addStretch( 1000 ); 00067 layout->addWidget( reset_button ); 00068 layout->setContentsMargins( 11, 5, 11, 5 ); 00069 setLayout( layout ); 00070 00071 connect( reset_button, SIGNAL( clicked( bool )), this, SLOT( reset() )); 00072 } 00073 00074 QLineEdit* TimePanel::makeTimeLabel() 00075 { 00076 QLineEdit* label = new QLineEdit; 00077 label->setReadOnly( true ); 00078 return label; 00079 } 00080 00081 void TimePanel::initialize(VisualizationManager* manager) 00082 { 00083 manager_ = manager; 00084 00085 connect( manager_, SIGNAL( timeChanged() ), this, SLOT( update() )); 00086 } 00087 00088 void TimePanel::fillTimeLabel( QLineEdit* label, double time ) 00089 { 00090 label->setText( QString::number( time, 'f', 2 )); 00091 } 00092 00093 void TimePanel::update() 00094 { 00095 fillTimeLabel( wall_time_label_, manager_->getWallClock() ); 00096 fillTimeLabel( wall_elapsed_label_, manager_->getWallClockElapsed() ); 00097 fillTimeLabel( ros_time_label_, manager_->getROSTime() ); 00098 fillTimeLabel( ros_elapsed_label_, manager_->getROSTimeElapsed() ); 00099 } 00100 00101 void TimePanel::reset() 00102 { 00103 manager_->resetTime(); 00104 } 00105 00106 } // namespace rviz 00107