MultiplotPlugin.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (C) 2015 by Ralf Kaestner *
3  * ralf.kaestner@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the Lesser GNU General Public License as published by*
7  * the Free Software Foundation; either version 3 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * Lesser GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the Lesser GNU General Public License *
16  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17  ******************************************************************************/
18 
19 #include <string>
20 #include <vector>
21 
22 #include <QByteArray>
23 #include <QCloseEvent>
24 #include <QUrl>
25 
26 #include <boost/program_options.hpp>
27 
29 
31 
33 
35 
36 namespace rqt_multiplot {
37 
38 /*****************************************************************************/
39 /* Constructors and Destructor */
40 /*****************************************************************************/
41 
42 MultiplotPlugin::MultiplotPlugin() :
43  widget_(0),
44  runAllPlotsOnStart_(false) {
45  setObjectName("MultiplotPlugin");
46 }
47 
49 }
50 
51 /*****************************************************************************/
52 /* Methods */
53 /*****************************************************************************/
54 
56  widget_ = new MultiplotWidget();
57 
58  context.addWidget(widget_);
59 
60  parseArguments(context.argv());
61 }
62 
64 }
65 
67  qt_gui_cpp::Settings& instanceSettings) const {
68  size_t maxConfigHistoryLength = widget_->getMaxConfigHistoryLength();
69  QStringList configHistory = widget_->getConfigHistory();
70 
71  instanceSettings.remove("history");
72 
73  instanceSettings.setValue("history/max_length",
74  (unsigned int)maxConfigHistoryLength);
75 
76  for (size_t i = 0; i < configHistory.count(); ++i)
77  instanceSettings.setValue("history/config_"+QString::number(i),
78  configHistory[i]);
79 }
80 
82  pluginSettings, const qt_gui_cpp::Settings& instanceSettings) {
83  size_t maxConfigHistoryLength = widget_->getMaxConfigHistoryLength();
84 
85  // the config history may already be populated with one element
86  // loaded from the command line, make sure that is kept before
87  // appending more.
88  QStringList configHistory = widget_->getConfigHistory();
89 
90  maxConfigHistoryLength = instanceSettings.value("history/max_length",
91  (unsigned int)maxConfigHistoryLength).toUInt();
92 
93  while (instanceSettings.contains("history/config_"+QString::
94  number(configHistory.count())))
95  configHistory.append(instanceSettings.value("history/config_"+
96  QString::number(configHistory.count())).toString());
97 
98  widget_->setMaxConfigHistoryLength(maxConfigHistoryLength);
99  widget_->setConfigHistory(configHistory);
100  if (runAllPlotsOnStart_) {
101  widget_->runPlots();
102  }
103 }
104 
105 void MultiplotPlugin::parseArguments(const QStringList& arguments) {
106  size_t argc = arguments.count();
107  std::vector<QByteArray> args;
108 
109  const char *argv[argc+1];
110  argv[0] = "rqt_multiplot";
111 
112  for (int i = 0; i < argc; ++i) {
113  args.push_back(arguments[i].toLocal8Bit());
114  argv[i+1] = args[i].constData();
115  }
116 
117  boost::program_options::variables_map variables;
118  boost::program_options::options_description options;
119 
120  options.add_options()
121  ("multiplot-config,c", boost::program_options::value<std::string>(), "");
122  options.add_options()
123  ("multiplot-bag,b", boost::program_options::value<std::string>(), "");
124  options.add_options()
125  ("multiplot-run-all,r", boost::program_options::bool_switch(
126  &runAllPlotsOnStart_), "");
127 
128 
129  try {
130  boost::program_options::store(boost::program_options::parse_command_line(
131  argc+1, argv, options), variables);
132  boost::program_options::notify(variables);
133 
134  if (variables.count("multiplot-config")) {
135  QUrl url = QUrl::fromUserInput(QString::fromStdString(
136  variables["multiplot-config"].as<std::string>()));
137  widget_->loadConfig(url.toString());
138  }
139  if (variables.count("multiplot-bag"))
140  widget_->readBag(QString::fromStdString(
141  variables["multiplot-bag"].as<std::string>()));
142  }
143  catch (const std::exception& exception) {
144  ROS_ERROR("Error parsing command line: %s", exception.what());
145  }
146 }
147 
148 }
void parseArguments(const QStringList &arguments)
void setConfigHistory(const QStringList &history)
QStringList getConfigHistory() const
size_t getMaxConfigHistoryLength() const
void readBag(const QString &url)
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
void addWidget(QWidget *widget)
void loadConfig(const QString &url)
bool contains(const QString &key) const
const QStringList & argv() const
void setValue(const QString &key, const QVariant &value)
void saveSettings(qt_gui_cpp::Settings &pluginSettings, qt_gui_cpp::Settings &instanceSettings) const
void initPlugin(qt_gui_cpp::PluginContext &context)
void remove(const QString &key)
void restoreSettings(const qt_gui_cpp::Settings &pluginSettings, const qt_gui_cpp::Settings &instanceSettings)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
#define ROS_ERROR(...)
void setMaxConfigHistoryLength(size_t length)


rqt_multiplot
Author(s): Ralf Kaestner
autogenerated on Wed Jul 10 2019 03:49:44