Marine systems simulation
newplot.h
1#ifndef NEWPLOT_H
2#define NEWPLOT_H
3
4#include <cmath>
5#include <QtGui/QDialog>
6#include "qwt_plot.h"
7#include <qwt_plot_curve.h>
8#include <QTimer>
9#include <qwt_plot_grid.h>
10#include <qwt_plot_panner.h>
11#include <QString>
12#include <algorithm>
13
14
18
19
20class newplot : public QwtPlot
21{
22 Q_OBJECT
23
24public:
25 newplot(QWidget *parent = 0):m_curve(NULL)
26
27 {
28 m_time = 0;
29 for (int i = 0; i < 1000; i++)
30 {
31 m_x[i] = 0;
32 m_y[i] = 0.0;
33
34 }
35 this->setTitle("Winch 1");
36 this->setAxisTitle(QwtPlot::xBottom, "Time/seconds");
37 this->setAxisTitle(QwtPlot::yLeft, "Force [N]");
38 //this->axisAutoScale(QwtPlot::yLeft);
39
40 this->setAutoReplot(true);
41 timeFrame = 10; //default amount of seconds displayed on the x-axis
42 }
43
44 void appendData( double x, double y){
45
46 memmove(m_y, &m_y[1], 999 * sizeof(double));
47 memmove(m_x, &m_x[1], 999 * sizeof(double));
48
49 m_y[999] = y;
50 m_x[999] = x;
51 }
52
53
54 private slots:
55
56
57 void TimeFrame( const QString &mystring)
58 {
59 timeFrame =mystring.toDouble();
60
61 }
62
63
64 void draw()
65 {
66
67 if (!m_curve)
68 {
69 m_curve = new QwtPlotCurve();
70 m_curve->setPen(QPen(QColor::fromRgb(255, 0, 0), 3));
71 m_curve->setRawSamples(m_x, m_y, 1000);
72 m_curve->attach(this);
73 }
74
75
76 double max = *(std::max_element(&m_y[0], &m_y[999]));
77 double min = *(std::min_element(&m_y[0], &m_y[999]));
78
79 //this->setAxisScale(QwtPlot::yLeft, -100, 100);
80 this->setAxisScale(QwtPlot::xBottom, m_x[999]-timeFrame, m_x[999]); // auto replots
81 this->setAxisScale(QwtPlot::yLeft, min, max);
82 this->replot();
83
84
85
86// Grid deactivated because of performance issues
87//QwtPlotGrid *grid = new QwtPlotGrid;
88//grid->enableXMin(true);
89//grid->enableYMin(true);
90//grid->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
91//grid->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine));
92//grid->attach(this);
93
94// Plot panner deactivated because of performance issues
95//QwtPlotPanner* megaPanner = new QwtPlotPanner(this->canvas());
96//megaPanner->setMouseButton(Qt::RightButton);
97//megaPanner->setAxisEnabled(QwtPlot::xBottom, false);
98
99 }
100
101private:
102 QwtPlotCurve *m_curve;
103 int m_time;
104 double m_x[1000]; //time array
105 double m_y[1000]; //data array
106 double timeFrame; //displayed time on the x-axis
107};
108
109#endif // NEWPLOT_H
Definition: newplot.h:21