00001 // ***************************************************************************** 00002 // 00003 // Copyright (c) 2015, Southwest Research Institute® (SwRI®) 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 // * Redistributions of source code must retain the above copyright 00009 // notice, this list of conditions and the following disclaimer. 00010 // * Redistributions in binary form must reproduce the above copyright 00011 // notice, this list of conditions and the following disclaimer in the 00012 // documentation and/or other materials provided with the distribution. 00013 // * Neither the name of Southwest Research Institute® (SwRI®) nor the 00014 // names of its contributors may be used to endorse or promote products 00015 // derived from this software without specific prior written permission. 00016 // 00017 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 // ARE DISCLAIMED. IN NO EVENT SHALL Southwest Research Institute® BE LIABLE 00021 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00023 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00024 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00025 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00026 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00027 // DAMAGE. 00028 // 00029 // ***************************************************************************** 00030 00031 #include <QFileDialog> 00032 #include <QDir> 00033 00034 #include "include/swri_console/bag_reader.h" 00035 00036 #include <rosbag/bag.h> 00037 #include <rosbag/view.h> 00038 00039 using namespace swri_console; 00040 00041 void BagReader::readBagFile(const QString& filename) 00042 { 00043 rosbag::Bag bag; 00044 bag.open(filename.toStdString(), rosbag::bagmode::Read); 00045 00046 std::vector<std::string> topics; 00047 topics.push_back(std::string("/rosout")); 00048 00049 rosbag::View view(bag, rosbag::TopicQuery(topics)); 00050 rosbag::View::const_iterator iter; 00051 00052 for(iter = view.begin(); iter != view.end(); ++iter) 00053 { 00054 rosgraph_msgs::LogConstPtr log = iter->instantiate<rosgraph_msgs::Log>(); 00055 if (log != NULL ) { 00056 emit logReceived(log); 00057 } 00058 else { 00059 qWarning("Got a message that was not a log message but a: %s", iter->getDataType().c_str()); 00060 } 00061 } 00062 00063 emit finishedReading(); 00064 } 00065 00066 void BagReader::promptForBagFile() 00067 { 00068 QString filename = QFileDialog::getOpenFileName(NULL, 00069 tr("Open Bag File"), 00070 QDir::homePath(), 00071 tr("Bag Files (*.bag)")); 00072 00073 if (filename != NULL) 00074 { 00075 readBagFile(filename); 00076 } 00077 }