26Plotter::Plotter(
const QString &title,
int gridx,
int gridy,
int hspan,
int vspan,
float minval,
float maxval,
int size,
const QString &bgcolor,
bool autorescale, QObject *parent) :
37 autorescale(autorescale),
47#if !defined(QCUSTOMPLOT_VERSION) || (QCUSTOMPLOT_VERSION < 0x020000)
48 customPlot.axisRect()->axis(QCPAxis::atBottom)->setTickLabelType(QCPAxis::ltNumber);
49 customPlot.axisRect()->axis(QCPAxis::atBottom)->setAutoTickStep(
false);
50 customPlot.axisRect()->axis(QCPAxis::atBottom)->setTickStep(25);
52 QSharedPointer<QCPAxisTickerFixed> fixedTicker(
new QCPAxisTickerFixed);
53 customPlot.axisRect()->axis(QCPAxis::atBottom)->setTicker(fixedTicker);
54 fixedTicker->setTickStep(25);
55 fixedTicker->setScaleStrategy(QCPAxisTickerFixed::ssNone);
59 customPlot.setInteractions( QCP::iRangeDrag | QCP::iRangeZoom );
60 auto* textLabel =
new QCPItemText(&
customPlot);
61#if !defined(QCUSTOMPLOT_VERSION) || (QCUSTOMPLOT_VERSION < 0x020000)
66 textLabel->setPositionAlignment(Qt::AlignTop|Qt::AlignHCenter);
67 textLabel->position->setType(QCPItemPosition::ptAxisRectRatio);
68 textLabel->position->setCoords(0.5, 0);
69 textLabel->setText(
title);
119Graph *
Plotter::addGraph(QString remotePort,QString localPort,
int index, QString title, QString color, QString type,
int size,
double graph_y_scale)
121 Graph *graph =
nullptr;
122 graph =
new Graph(index,
title,color,type,
size,graph_y_scale,this->size);
140 QCPGraph *customGraph =
customPlot.addGraph();
141 customGraph->setPen(QPen(QColor(color),
size));
142 customGraph->setAntialiased(
false);
143 customGraph->setLineStyle(QCPGraph::lsLine);
145 if(type ==
"points"){
146 customGraph->setLineStyle(QCPGraph::lsNone);
147 customGraph->setScatterStyle(QCPScatterStyle::ssDot);
151 customGraph->setLineStyle(QCPGraph::lsImpulse);
152 customGraph->setScatterStyle(QCPScatterStyle::ssNone);
156 QCPGraph *customGraphPoint =
customPlot.addGraph();
157 customGraphPoint->setPen(QPen(QColor(color)));
158 customGraphPoint->setLineStyle(QCPGraph::lsNone);
159 customGraphPoint->setScatterStyle(QCPScatterStyle::ssDisc);
179 for (
int j=0;j < c; j++) {
182 if(graph->deleteConnection){
183 b = graph->curr_connection->localPort->
read(
false);
185 b = graph->curr_connection->localPort->lastRead();
189 graph->appendPreviousValues();
196 graph->curr_connection->localPort->getEnvelope(stmp);
199 qWarning() <<
"bottle size =" << b->
size() <<
" requested index =" << graph->index;
207 if (graph->curr_connection->realTime && stmp.
isValid()) {
208 t = (float)(stmp.
getTime() - graph->curr_connection->initialTime);
213 graph->appendValues(y,t);
237 for (
int j=0;j <
graphList.count(); j++) {
246Graph::Graph(
int index, QString title, QString color, QString type,
int size,
double graph_y_scale,
int buffer_size, QObject *parent) :
251 deleteConnection(true),
252 customGraphPoint(nullptr),
253 customGraph(nullptr),
255 graph_y_scale(graph_y_scale),
256 curr_connection(nullptr),
257 buffer_size(buffer_size),
258 numberAcquiredData(0),
260 type(
std::move(type)),
261 color(
std::move(color)),
263 title(
std::move(title))
268 QString localPortName,
280 style.
carrier = carrier.toLatin1().data();
303 if(type.compare(
"lines") == 0){
306 if(type.compare(
"bars") == 0){
309 if(type.compare(
"points") == 0){
339 _t = (float)numberAcquiredData;
345 lastX = numberAcquiredData;
351#if !defined(QCUSTOMPLOT_VERSION) || (QCUSTOMPLOT_VERSION < 0x020000)
357#if !defined(QCUSTOMPLOT_VERSION) || (QCUSTOMPLOT_VERSION < 0x020000)
362 numberAcquiredData++;
388#if !defined(QCUSTOMPLOT_VERSION) || (QCUSTOMPLOT_VERSION < 0x020000)
395#if !defined(QCUSTOMPLOT_VERSION) || (QCUSTOMPLOT_VERSION < 0x020000)
442 qWarning() <<
"Connection from port" << realLocalPortName.toLatin1().data() <<
"to port" <<
remotePortName.toLatin1().data()
443 <<
"was NOT successful. Waiting from explicit connection from user.";
445 qDebug(
"Listening to port %s from port %s",
remotePortName.toLatin1().data(),realLocalPortName.toLatin1().data());
453 qDebug(
"will use real time for port %s",
remotePortName.toLatin1().data());
457 qDebug(
"will NOT use real time for port %s",
remotePortName.toLatin1().data());
int SIGNAL(int pid, int signum)
Class representing a Connection.
Connection(QString remotePortName, QString localPortName, QObject *parent=0)
yarp::os::ContactStyle style
yarp::os::BufferedPort< yarp::os::Bottle > * localPort
void connect(const yarp::os::ContactStyle &style)
Connect local port to remote port.
Class representing a Graph.
void init(QString remotePortName, QString localPortName, QString carrier, bool persistent)
QCPGraph * customGraphPoint
int getLineSize()
Return tickness of the graph.
void setCustomGraphPoint(QCPGraph *)
Sets the Custom Graph Point from the QCustomPlot class to this graph.
Connection * getConnection()
void setCustomGraph(QCPGraph *)
Sets the Custom Graph from the QCustomPlot class to this graph.
void appendPreviousValues()
Append the previous values acquired.
void clearData()
Clears the custom graph datas.
void appendValues(float y, float t)
Append the new values acquired.
int getType()
Return the graph type.
Graph(int index, QString title, QString color, QString type, int size, double graph_y_scale, int buffer_size, QObject *parent=0)
QString getColor()
Return color of the grpah.
Connection * curr_connection
void rescale()
Rescales the plotter and its graphs.
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.
void setPaintGeometry(QRectF)
Sets the paint geometry for this Plotter.
QList< QObject * > graphList
void onTimeout()
Timeout on which the data is acquired.
void clear()
Clears the graphs data.
void onInteract()
Sets the interaction mode to true.
Plotter(const QString &title, int gridx, int gridy, int hspan, int vspan, float minval, float maxval, int size, const QString &bgcolor, bool autorescale, QObject *parent=0)
Constructor of the class.
A simple collection of objects that can be described and transmitted in a portable way.
size_type size() const
Gets the number of elements in the bottle.
bool read(ConnectionReader &reader) override
Set the bottle's value based on input from a network connection.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
A mini-server for performing network communication in the background.
std::string getName() const override
Get name of port.
bool getEnvelope(PortReader &envelope) override
Get the envelope information (e.g., a timestamp) from the last message received on the port.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
static bool connect(const std::string &src, const std::string &dest, const std::string &carrier="", bool quiet=true)
Request that an output port connect to an input port.
static bool disconnect(const std::string &src, const std::string &dest, bool quiet)
Request that an output port disconnect from an input port.
An abstraction for a time stamp and/or sequence number.
double getTime() const
Get the time stamp.
bool isValid() const
Check if this Stamp is valid.
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
virtual bool isList() const
Checks if value is a list.
virtual Bottle * asList() const
Get list value.
double now()
Return the current time in seconds, relative to an arbitrary starting point.
#define GRAPH_TYPE_POINTS