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