console_master.cpp
Go to the documentation of this file.
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 <swri_console/console_master.h>
00032 #include <swri_console/console_window.h>
00033 #include <swri_console/settings_keys.h>
00034 
00035 #include <QFontDialog>
00036 #include <QSettings>
00037 
00038 namespace swri_console
00039 {
00040 ConsoleMaster::ConsoleMaster(int argc, char** argv):
00041   ros_thread_(argc, argv),
00042   connected_(false),
00043   window_font_(QFont("Ubuntu Mono", 9))
00044 {
00045   // The RosThread takes advantage of queued connections when emitting log messages
00046   // to ensure that the messages are processed in the console window's event thread.
00047   // In order for that to work, we have to manually register the message type with
00048   // Qt's QMetaType system.
00049   qRegisterMetaType<rosgraph_msgs::LogConstPtr>("rosgraph_msgs::LogConstPtr");
00050 
00051   QObject::connect(&bag_reader_, SIGNAL(logReceived(const rosgraph_msgs::LogConstPtr& )),
00052                    &db_, SLOT(queueMessage(const rosgraph_msgs::LogConstPtr&) ));
00053   QObject::connect(&bag_reader_, SIGNAL(finishedReading()),
00054                    &db_, SLOT(processQueue()));
00055   QObject::connect(&log_reader_, SIGNAL(logReceived(const rosgraph_msgs::LogConstPtr& )),
00056                    &db_, SLOT(queueMessage(const rosgraph_msgs::LogConstPtr&) ));
00057   QObject::connect(&log_reader_, SIGNAL(finishedReading()),
00058                    &db_, SLOT(processQueue()));
00059 }
00060 
00061 ConsoleMaster::~ConsoleMaster()
00062 {
00063   ros_thread_.shutdown();
00064   ros_thread_.wait();
00065 }
00066 
00067 void ConsoleMaster::createNewWindow()
00068 {
00069   ConsoleWindow* win = new ConsoleWindow(&db_);
00070   windows_.append(win);
00071 
00072   QSettings settings;
00073   window_font_ = settings.value(SettingsKeys::FONT, QFont("Ubuntu Mono", 9)).value<QFont>();
00074   win->setFont(window_font_);
00075   QObject::connect(win, SIGNAL(createNewWindow()),
00076                    this, SLOT(createNewWindow()));
00077 
00078   QObject::connect(&ros_thread_, SIGNAL(connected(bool)),
00079                    win, SLOT(connected(bool)));
00080 
00081   QObject::connect(this,
00082                    SIGNAL(fontChanged(const QFont &)),
00083                    win, SLOT(setFont(const QFont &)));
00084 
00085   QObject::connect(win, SIGNAL(selectFont()),
00086                    this, SLOT(selectFont()));
00087 
00088   QObject::connect(win, SIGNAL(readBagFile()),
00089                    &bag_reader_, SLOT(promptForBagFile()));
00090 
00091   QObject::connect(win, SIGNAL(readLogFile()),
00092                    &log_reader_, SLOT(promptForLogFile()));
00093 
00094   QObject::connect(win, SIGNAL(readLogDirectory()),
00095                    &log_reader_, SLOT(promptForLogDirectory()));
00096 
00097 
00098   if (!ros_thread_.isRunning())
00099   {
00100     // There's only one ROS thread, and it services every window.  We need to initialize
00101     // it and its connections to the LogDatabase when we first create a window, but
00102     // after that it doesn't need to be modified again.
00103     QObject::connect(&ros_thread_, SIGNAL(logReceived(const rosgraph_msgs::LogConstPtr& )),
00104                      &db_, SLOT(queueMessage(const rosgraph_msgs::LogConstPtr&) ));
00105 
00106     QObject::connect(&ros_thread_, SIGNAL(spun()),
00107                      &db_, SLOT(processQueue()));
00108 
00109     ros_thread_.start();
00110   }
00111 
00112   win->show();
00113 }
00114 
00115 void ConsoleMaster::fontSelectionChanged(const QFont &font)
00116 {
00117   window_font_ = font;
00118   QSettings settings;
00119   settings.setValue(SettingsKeys::FONT, font);
00120   Q_EMIT fontChanged(window_font_);
00121 }
00122 
00123 void ConsoleMaster::selectFont()
00124 {
00125   QFont starting_font = window_font_;
00126 
00127   QFontDialog dlg(window_font_);
00128     
00129   QObject::connect(&dlg, SIGNAL(currentFontChanged(const QFont &)),
00130                    this, SLOT(fontSelectionChanged(const QFont &)));
00131 
00132   int ret = dlg.exec();
00133 
00134   if (ret == QDialog::Accepted) {
00135     if (window_font_ != dlg.selectedFont()) {
00136       window_font_ = dlg.selectedFont();
00137       Q_EMIT fontChanged(window_font_);
00138     }
00139   } else {
00140     if (window_font_ != starting_font) {
00141       window_font_ = starting_font;
00142       Q_EMIT fontChanged(window_font_);
00143     }
00144   }
00145 }
00146 }  // namespace swri_console


swri_console
Author(s):
autogenerated on Sat Jun 8 2019 18:46:13