MultiplotPlugin.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  * Copyright (C) 2015 by Ralf Kaestner                                        *
00003  * ralf.kaestner@gmail.com                                                    *
00004  *                                                                            *
00005  * This program is free software; you can redistribute it and/or modify       *
00006  * it under the terms of the Lesser GNU General Public License as published by*
00007  * the Free Software Foundation; either version 3 of the License, or          *
00008  * (at your option) any later version.                                        *
00009  *                                                                            *
00010  * This program is distributed in the hope that it will be useful,            *
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the               *
00013  * Lesser GNU General Public License for more details.                        *
00014  *                                                                            *
00015  * You should have received a copy of the Lesser GNU General Public License   *
00016  * along with this program. If not, see <http://www.gnu.org/licenses/>.       *
00017  ******************************************************************************/
00018 
00019 #include <string>
00020 #include <vector>
00021 
00022 #include <QByteArray>
00023 #include <QCloseEvent>
00024 #include <QUrl>
00025 
00026 #include <boost/program_options.hpp>
00027 
00028 #include <pluginlib/class_list_macros.h>
00029 
00030 #include <rqt_multiplot/MultiplotWidget.h>
00031 
00032 #include "rqt_multiplot/MultiplotPlugin.h"
00033 
00034 PLUGINLIB_EXPORT_CLASS(rqt_multiplot::MultiplotPlugin, rqt_gui_cpp::Plugin)
00035 
00036 namespace rqt_multiplot {
00037 
00038 /*****************************************************************************/
00039 /* Constructors and Destructor                                               */
00040 /*****************************************************************************/
00041 
00042 MultiplotPlugin::MultiplotPlugin() :
00043   widget_(0),
00044   runAllPlotsOnStart_(false) {
00045   setObjectName("MultiplotPlugin");
00046 }
00047 
00048 MultiplotPlugin::~MultiplotPlugin() {
00049 }
00050 
00051 /*****************************************************************************/
00052 /* Methods                                                                   */
00053 /*****************************************************************************/
00054 
00055 void MultiplotPlugin::initPlugin(qt_gui_cpp::PluginContext& context) {
00056   widget_ = new MultiplotWidget();
00057 
00058   context.addWidget(widget_);
00059 
00060   parseArguments(context.argv());
00061 }
00062 
00063 void MultiplotPlugin::shutdownPlugin() {
00064 }
00065 
00066 void MultiplotPlugin::saveSettings(qt_gui_cpp::Settings& pluginSettings,
00067     qt_gui_cpp::Settings& instanceSettings) const {
00068   size_t maxConfigHistoryLength = widget_->getMaxConfigHistoryLength();
00069   QStringList configHistory = widget_->getConfigHistory();
00070 
00071   instanceSettings.remove("history");
00072 
00073   instanceSettings.setValue("history/max_length",
00074     (unsigned int)maxConfigHistoryLength);
00075 
00076   for (size_t i = 0; i < configHistory.count(); ++i)
00077     instanceSettings.setValue("history/config_"+QString::number(i),
00078       configHistory[i]);
00079 }
00080 
00081 void MultiplotPlugin::restoreSettings(const qt_gui_cpp::Settings&
00082     pluginSettings, const qt_gui_cpp::Settings& instanceSettings) {
00083   size_t maxConfigHistoryLength = widget_->getMaxConfigHistoryLength();
00084 
00085   // the config history may already be populated with one element
00086   // loaded from the command line, make sure that is kept before
00087   // appending more.
00088   QStringList configHistory = widget_->getConfigHistory();
00089 
00090   maxConfigHistoryLength = instanceSettings.value("history/max_length",
00091     (unsigned int)maxConfigHistoryLength).toUInt();
00092 
00093   while (instanceSettings.contains("history/config_"+QString::
00094       number(configHistory.count())))
00095     configHistory.append(instanceSettings.value("history/config_"+
00096       QString::number(configHistory.count())).toString());
00097 
00098   widget_->setMaxConfigHistoryLength(maxConfigHistoryLength);
00099   widget_->setConfigHistory(configHistory);
00100   if (runAllPlotsOnStart_) {
00101     widget_->runPlots();
00102   }
00103 }
00104 
00105 void MultiplotPlugin::parseArguments(const QStringList& arguments) {
00106   size_t argc = arguments.count();
00107   std::vector<QByteArray> args;
00108 
00109   const char *argv[argc+1];
00110   argv[0] = "rqt_multiplot";
00111 
00112   for (int i = 0; i < argc; ++i) {
00113     args.push_back(arguments[i].toLocal8Bit());
00114     argv[i+1] = args[i].constData();
00115   }
00116 
00117   boost::program_options::variables_map variables;
00118   boost::program_options::options_description options;
00119 
00120   options.add_options()
00121     ("multiplot-config,c", boost::program_options::value<std::string>(), "");
00122   options.add_options()
00123     ("multiplot-bag,b", boost::program_options::value<std::string>(), "");
00124   options.add_options()
00125     ("multiplot-run-all,r", boost::program_options::bool_switch(
00126       &runAllPlotsOnStart_), "");
00127 
00128 
00129   try {
00130     boost::program_options::store(boost::program_options::parse_command_line(
00131       argc+1, argv, options), variables);
00132     boost::program_options::notify(variables);
00133 
00134     if (variables.count("multiplot-config")) {
00135       QUrl url = QUrl::fromUserInput(QString::fromStdString(
00136         variables["multiplot-config"].as<std::string>()));
00137       widget_->loadConfig(url.toString());
00138     }
00139     if (variables.count("multiplot-bag"))
00140       widget_->readBag(QString::fromStdString(
00141         variables["multiplot-bag"].as<std::string>()));
00142   }
00143   catch (const std::exception& exception) {
00144     ROS_ERROR("Error parsing command line: %s", exception.what());
00145   }
00146 }
00147 
00148 }


rqt_multiplot
Author(s): Ralf Kaestner
autogenerated on Thu Jun 6 2019 21:49:11