viewCtrl.cpp
Go to the documentation of this file.
1 
9 #include <gui/viewCtrl.hpp>
10 #include <QPainter>
11 #include <QPaintEvent>
12 
13 
14 // Returns the graphical point corresponding to a couple of velocities.
15 // Parameters vel The velocities, a couple of real values.
16 // Returns The graphical point corresponding to the velocities.
17 QPoint ViewCtrlWdgt::plot(const QPointF& vel) const {
18  const double &v = vel.x(), &om = vel.y(),
19  &minV = model.minTranslVel(),
20  &maxV = model.maxTranslVel(), &maxOm = model.maxRotVel();
21  const QSize &sz = size();
22  // both axes are reversed: left rotation is positive but is
23  // on the left side of the drawing which is negative, and front is
24  // on top which has low pixel ordinate values
25  return QPoint( (int)( (1 - om / maxOm) / 2 * sz.width() ),
26  (int)( (maxV - v) / (maxV - minV) * sz.height() ) );
27 } // end of QPoint ViewCtrlWdgt::plot(const QPointF&) const ----------
28 
29 // Draws the ROS node's velocities and their evolution.
30 // Parameters event The drawing event, giving the region
31 // which should be redrawn.
32 // See vel_drawing Since 0.2.2.
33 void ViewCtrlWdgt::paintEvent(QPaintEvent *event) {
34  static const int nb_points = 2;
35  static const Qt::GlobalColor colors[nb_points]
36  = {Qt::green, Qt::blue};
37  QPainter painter(this);
38  const QRect& drawing_rect = event->rect();
39  const QSize& sz = size();
40  const QPoint origin = plot( QPointF() );
41  const QPointF *points[nb_points] = {&velocities, &commands};
42  const double &xOrig = origin.x(), &yOrig = origin.y();
43 
44  painter.eraseRect(drawing_rect); // clean the region
45  // draw the axes
46  painter.drawLine( xOrig, 0, xOrig, sz.height() );
47  painter.drawLine( 0, yOrig, sz.width(), yOrig );
48  // draw the velocities (current = odometry and aimed = command)
49  for(int i = 0; i < nb_points; i++) {
50  painter.setPen(colors[i]); // set the border color
51  painter.setBrush(colors[i]); // set the fill color
52  painter.drawPie(region(*points[i]), 0, 360 * 16); // fill the disk
53  } // end of for (each point = velocities)
54 } // end of void ViewCtrlWdgt::paintEvent(QPaintEvent*) --------------
55 
56 /* The constructor need the main window containing this widget,
57  * and main()'s arguments (they can be forwarded by the ROS node
58  * to ROS).
59  *
60  * Parameters: parent The containing graphical object,
61  * motion_model the motion model,
62  * control the controller whose behaviour is shown.
63  *
64  * See QWidget.
65  */
66 ViewCtrlWdgt::ViewCtrlWdgt(QWidget& parent, Controller& control,
67  const MotionModel& motion_model)
68  : QWidget(&parent), ControlWidget(control, motion_model) {
69  // setting up the widget's background color to white
70  setBackgroundRole(QPalette::Base);
71  // setting up the widget's minimum size
72  setMinimumSize(200, 200);
73 } // end of ViewCtrlWdgt::ViewCtrlWdgt(QWidget&, Controller&, ...) ---
Controller is the abstract class inherited by all the implemented controllers.
Definition: controller.hpp:28
Qt control widget showing current and aimed velocities.
QPoint plot(const QPointF &velocities) const
Returns the graphical point corresponding to a couple of velocities.
Definition: viewCtrl.cpp:17
const double & maxRotVel() const
Descriptive method, giving the maximum rotation velocity.
Definition: motion.hpp:96
This abstract class is inherited by all those containing a Qt widget intended to show the controller&#39;...
Definition: ctrlWdgt.hpp:24
ViewCtrlWdgt(QWidget &parent, Controller &control, const MotionModel &motion_model)
The constructor needs the containing graphical object, the motion model and the related controller...
Definition: viewCtrl.cpp:66
const MotionModel & model
The motion model and its limits values.
Definition: ctrlWdgt.hpp:31
const double & maxTranslVel() const
Descriptive method, giving the maximum translation velocity.
Definition: motion.hpp:92
void paintEvent(QPaintEvent *event)
Draws the controller&#39;s velocities and their evolution.
Definition: viewCtrl.cpp:33
This class defines a motion model, with the motion limits.
Definition: motion.hpp:28
const double & minTranslVel() const
Descriptive method, giving the minimum translation velocity.
Definition: motion.hpp:88
QRect region(const QPointF &vel) const
Returns the graphical region drawn around velocities.
Definition: viewCtrl.hpp:40
QPointF commands
The velocities sent as commands.
Definition: viewCtrl.hpp:29
QPointF velocities
The velocities from the odometry.
Definition: viewCtrl.hpp:28


qt_ctrl
Author(s): Alexis Scheuer
autogenerated on Wed Dec 16 2020 15:51:32