Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00040
00041
00042 MultiplotPlugin::MultiplotPlugin() :
00043 widget_(0),
00044 runAllPlotsOnStart_(false) {
00045 setObjectName("MultiplotPlugin");
00046 }
00047
00048 MultiplotPlugin::~MultiplotPlugin() {
00049 }
00050
00051
00052
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
00086
00087
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 }