YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
simpleloader.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: GPL-3.0-or-later
4 */
5
6#include "simpleloader.h"
7#include <yarp/os/Value.h>
8/*
9 QString plot_bgcolor;
10 int plot_size;
11 float plot_minval;
12 float plot_maxval;
13 bool plot_autorescale;
14 bool plot_realtime;
15 bool plot_triggermode;
16 QString plot_title;
17
18 QString graph_localport;
19 QString graph_remote;
20 QString graph_title;
21 QString graph_color;
22 QString graph_type;
23 int graph_index;
24 int graph_size;*/
25
26SimpleLoader::SimpleLoader(/* FIXME const */ yarp::os::ResourceFinder *options, PlotManager *plotManager, bool *ok, QObject *parent) :
27 GenericLoader(parent),
28 plotManager(plotManager),
29 plot_bgcolor(default_plot_bgcolor),
30 plot_size(default_plot_size),
31 plot_minval(default_plot_minval),
32 plot_maxval(default_plot_maxval),
33 plot_autorescale(options->check("autorescale")),
34 plot_realtime(options->check("realtime")),
35 plot_triggermode(options->check("triggermode")),
36 plot_title(default_plot_title),
37 graph_remote(),
38 graph_index(-1),
39 graph_localport(default_portscope_localport),
40 graph_title(default_graph_title),
41 graph_color(default_graph_color),
42 graph_type(default_graph_type),
43 graph_size(default_graph_size)
44{
45 if (!options->check("remote")) {
46 qDebug("Missing \"remote\" argument. Will wait for external connection");
47 } else {
48 graph_remote = QString("%1").arg(options->find("remote").toString().c_str());
49 plot_title = graph_remote;
50 }
51
52 if (options->check("carrier")) {
53 portscope_carrier = QString("%1").arg(options->find("carrier").asString().c_str());
54 }
55 if (options->check("no-persistent")) {
57 } else if (options->check("persistent")) {
59 }
60
61 if (!options->check("index")) {
62 qWarning() << "Missing \"index\" argument. Will use index = 0";
63 }
64 const yarp::os::Value &indexValue = options->find("index");
65
66
67 if (options->check("plot_title")) {
68 plot_title = QString("%1").arg(options->find("plot_title").toString().c_str());
69 }
70
71 if (options->check("min")) {
72 plot_minval = (float)options->find("min").asFloat64();
73 }
74
75 if (options->check("max")) {
76 plot_maxval = (float)options->find("max").asFloat64();
77 }
78
79 if (options->check("size")) {
80 plot_size = options->find("size").asInt32();
81 }
82
83 if (options->check("bgcolor")) {
84 plot_bgcolor = QString("%1").arg(options->find("bgcolor").asString().c_str());
85 }
86
87 // TODO enable realtime mode
88 Q_UNUSED(plot_realtime); // UNUSED
89
90 // TODO enable trigger mode
91 Q_UNUSED(plot_triggermode); // UNUSED
92
93 Plotter *plotter = plotManager->addPlot(plot_title, 0, 0, 1, 1, plot_minval, plot_maxval, plot_size, plot_bgcolor, plot_autorescale);
94
95
96 if (!indexValue.isList()) {
97 // SINGLE PLOT
98 graph_index = indexValue.asInt32();
99
100 if (options->check("graph_title")) {
101 if (options->find("graph_title").isList()) {
102 qCritical(R"("graph_title" and "index" arguments should have the same number of elements)");
103 *ok = false;
104 return;
105 }
106 graph_title = QString("%1").arg(options->find("graph_title").toString().c_str());
107 }
108
109 if (options->check("color")) {
110 if (options->find("color").isList()) {
111 qCritical(R"("color" and "index" arguments should have the same number of elements)");
112 *ok = false;
113 return;
114 }
115 graph_color = QString("%1").arg(options->find("color").toString().c_str());
116 }
117
118 if (options->check("type")) {
119 if (options->find("type").isList()) {
120 qCritical(R"("type" and "index" arguments should have the same number of elements)");
121 *ok = false;
122 return;
123 }
124 graph_type = QString("%1").arg(options->find("type").toString().c_str());
125 }
126
127 if (options->check("graph_size")) {
128 if (options->find("graph_size").isList()) {
129 qCritical(R"("graph_size" and "index" arguments should have the same number of elements)");
130 *ok = false;
131 return;
132 }
133 graph_size = options->find("graph_size").asInt32();
134 } else {
135 graph_size = default_graph_size;
136 }
137
138 Graph *graph = plotter->addGraph(graph_remote, graph_localport,graph_index, graph_title, graph_color, graph_type, graph_size);
139 if(graph){
140 graph->init(graph_remote, graph_localport, portscope_carrier, portscope_persistent);
141 }
142
143 } else {
144 const yarp::os::Bottle &indexes = *indexValue.asList();
145 yarp::os::Bottle titles, colors, types, sizes;
146
147 if (options->check("graph_title")) {
148 const yarp::os::Value &titlesValue = options->find("graph_title");
149 if (!titlesValue.isList()) {
150 qCritical(R"("graph_title" and "index" arguments should have the same number of elements)");
151 *ok = false;
152 return;
153 }
154 titles = *titlesValue.asList();
155 if (titles.size() != indexes.size()) {
156 qCritical(R"("graph_title" and "index" arguments should have the same number of elements)");
157 *ok = false;
158 return;
159 }
160 } else {
162 }
163
164 if (options->check("color")) {
165 const yarp::os::Value &colorsValue = options->find("color");
166 if (!colorsValue.isList()) {
167 qCritical(R"("color" and "index" arguments should have the same number of elements)");
168 *ok = false;
169 return;
170 }
171 colors = *colorsValue.asList();
172 if (colors.size() != indexes.size()) {
173 qCritical(R"("color" and "index" arguments should have the same number of elements)");
174 *ok = false;
175 return;
176 }
177 } else {
179 }
180
181 if (options->check("type")) {
182 const yarp::os::Value &typesValue = options->find("type");
183 if (!typesValue.isList()) {
184 qCritical(R"("type" and "index" arguments should have the same number of elements)");
185 *ok = false;
186 return;
187 }
188 types = *typesValue.asList();
189 if (types.size() != indexes.size()) {
190 qCritical(R"("type" and "index" arguments should have the same number of elements)");
191 *ok = false;
192 return;
193 }
194 } else {
196 }
197
198 if (options->check("graph_size")) {
199 const yarp::os::Value &sizesValue = options->find("graph_size");
200 if (!sizesValue.isList()) {
201 qCritical(R"("graph_size" and "index" arguments should have the same number of elements)");
202 *ok = false;
203 return;
204 }
205 sizes = *sizesValue.asList();
206 if (sizes.size() != indexes.size()) {
207 qCritical(R"("graph_size" and "index" arguments should have the same number of elements)");
208 *ok = false;
209 return;
210 }
211 } else {
213 }
214
215 for (size_t i = 0; i < indexes.size(); i++) {
216 graph_index = indexes.get(i).asInt32();
217
218 if (!titles.isNull()) {
219 graph_title = QString("%1").arg(titles.get(i).asString().data());
220 }
221
222 if (!colors.isNull()) {
223 graph_color = QString("%1").arg(colors.get(i).asString().data());
224 }
225
226 if (!types.isNull()) {
227 graph_type = QString("%1").arg(types.get(i).asString().data());
228 }
229
230 if (!sizes.isNull()) {
231 graph_size = sizes.get(i).asInt32();
232 } else {
233 graph_size = default_graph_size;
234 }
235 Graph *graph = plotter->addGraph( graph_remote, graph_localport,graph_index, graph_title, graph_color, graph_type, graph_size);
236 if(graph){
237 graph->init(graph_remote, graph_localport, portscope_carrier, portscope_persistent);
238 }
239 }
240 }
241 *ok = true;
242
243}
Base Class for the Loaders.
bool portscope_persistent
QString portscope_carrier
const int default_graph_size
Class representing a Graph.
Definition plotter.h:26
void init(QString remotePortName, QString localPortName, QString carrier, bool persistent)
Definition plotter.cpp:267
The Manager of the plotters.
Definition plotmanager.h:19
Plotter * addPlot(const QString &title, int gridx, int gridy, int hspan, int vspan, float minval, float maxval, int size, const QString &bgcolor, bool autorescale)
Adds a new Plotter.
Class representing a Plotter.
Definition plotter.h:115
Graph * addGraph(QString remotePort, QString localPort, int index, QString title, QString color, QString type, int size, double graph_y_scale=1.0)
Add a Graph to the current Plotter.
Definition plotter.cpp:119
SimpleLoader(yarp::os::ResourceFinder *options, PlotManager *plotManager, bool *ok, QObject *parent=0)
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
static Bottle & getNullBottle()
A special Bottle with no content.
Definition Bottle.cpp:315
size_type size() const
Gets the number of elements in the bottle.
Definition Bottle.cpp:251
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition Bottle.cpp:246
bool isNull() const override
Checks if the object is invalid.
Definition Bottle.cpp:343
Helper class for finding config files and other external resources.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
A single value (typically within a Bottle).
Definition Value.h:43
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
Definition Value.cpp:222
virtual std::int32_t asInt32() const
Get 32-bit integer value.
Definition Value.cpp:204
virtual bool isList() const
Checks if value is a list.
Definition Value.cpp:162
virtual Bottle * asList() const
Get list value.
Definition Value.cpp:240
std::string toString() const override
Return a standard text representation of the content of the object.
Definition Value.cpp:356
virtual std::string asString() const
Get string value.
Definition Value.cpp:234