RTXI  2.4
The Real-Time eXperiment Interface Documentation
scope.h
Go to the documentation of this file.
1 /*
2  The Real-Time eXperiment Interface (RTXI)
3  Copyright (C) 2011 Georgia Institute of Technology, University of Utah, Weill Cornell Medical College
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18 */
19 
20 /*
21  This class instantiates a single scope instance.
22  This includes the painting director, the canvass,
23  and the functions necessary for modifying those
24  scopes. Multiple scope objects can be instantiated,
25  and each instance will have it's own set of settings
26  that can be edited with the Panel class.
27  */
28 
29 #ifndef SCOPE_H
30 #define SCOPE_H
31 
32 #include <QtWidgets>
33 
34 #include <qwt_scale_engine.h>
35 #include <qwt_plot_grid.h>
36 #include <qwt_plot_layout.h>
37 #include <qwt_plot_canvas.h>
38 #include <qwt_plot_marker.h>
39 #include <qwt_plot_curve.h>
40 #include <qwt_plot_directpainter.h>
41 #include <qwt_plot.h>
42 #include <qwt_plot_legenditem.h>
43 #include <qwt.h>
44 #include <qwt_curve_fitter.h>
45 #include <qwt_painter.h>
46 #include <qwt_system_clock.h>
47 #include <qwt_interval.h>
48 
49 #include <list>
50 #include <vector>
51 
52 class Scope : public QwtPlot
53 {
54 
55  Q_OBJECT
56 
57  friend class Panel;
58 
59 public:
60 
61  class Channel
62  {
63  friend class Scope;
64 
65  public:
66  Channel(void);
67  virtual ~Channel(void);
68  void *getInfo(void);
69  const void *getInfo(void) const;
70  double getScale(void) const;
71  double getOffset(void) const;
72  QPen getPen(void) const;
73  QString getLabel(void) const;
74 
75  private:
76  QString label;
77  double scale;
78  double offset;
79  std::vector<double> data;
80  QwtPlotCurve *curve;
81  void *info;
82  }; // Channel
83 
84  class LegendItem : public QwtPlotLegendItem
85  {
86 
87  public:
89  {
90  setRenderHint(QwtPlotItem::RenderAntialiased);
91  QColor color(Qt::black);
92  setTextPen(color);
93  }
94  }; // LegendItem
95 
96  class Canvas : public QwtPlotCanvas
97  {
98 
99  public:
100  Canvas(QwtPlot *plot = NULL) : QwtPlotCanvas(plot)
101  {
102  setPaintAttribute(QwtPlotCanvas::BackingStore, false);
103 
104  if(QwtPainter::isX11GraphicsSystem())
105  {
106 #if QT_VERSION < 0x050000
107  setAttribute( Qt::WA_PaintOutsidePaintEvent, true );
108 #endif
109  if(testPaintAttribute(QwtPlotCanvas::BackingStore))
110  {
111  setAttribute(Qt::WA_PaintOnScreen, true);
112  setAttribute(Qt::WA_NoSystemBackground, true);
113  }
114  }
115  setupPalette();
116  }
117 
118  private:
119  void setupPalette()
120  {
121  QPalette pal = palette();
122 
123 #if QT_VERSION >= 0x040400
124  QLinearGradient gradient;
125  gradient.setCoordinateMode(QGradient::StretchToDeviceMode);
126  gradient.setColorAt(1.0, QColor(Qt::white));
127  pal.setBrush(QPalette::Window, QBrush(gradient));
128 #else
129  pal.setBrush(QPalette::Window, QBrush(color));
130 #endif
131  pal.setColor(QPalette::WindowText, Qt::green);
132  setPalette(pal);
133  }
134  }; // Canvas
135 
136  enum trig_t
137  {
141  };
142 
143  Scope(QWidget * = NULL);
144  virtual ~Scope(void);
145 
146  bool paused(void) const;
147  std::list<Channel>::iterator insertChannel(QString,double,double,const QPen &,QwtPlotCurve *,void *);
148  void *removeChannel(std::list<Channel>::iterator);
149  size_t getChannelCount(void) const;
150  std::list<Channel>::iterator getChannelsBegin(void);
151  std::list<Channel>::iterator getChannelsEnd(void);
152 
153  std::list<Channel>::const_iterator getChannelsBegin(void) const;
154  std::list<Channel>::const_iterator getChannelsEnd(void) const;
155 
156  void clearData(void);
157  void setData(double *,size_t);
158  size_t getDataSize(void) const;
159  void setDataSize(size_t);
160 
162  double getTriggerThreshold(void);
163  double getTriggerWindow(void);
164  std::list<Channel>::iterator getTriggerChannel(void);
165  void setTrigger(trig_t,double,std::list<Channel>::iterator,double);
166 
167  double getDivT(void) const;
168  void setDivT(double);
169 
170  void setPeriod(double);
171  size_t getDivX(void) const;
172  size_t getDivY(void) const;
173 
174  size_t getRefresh(void) const;
175  void setRefresh(size_t);
176 
177  bool isPaused;
178 
179  void setChannelScale(std::list<Channel>::iterator,double);
180  void setChannelOffset(std::list<Channel>::iterator,double);
181  void setChannelPen(std::list<Channel>::iterator,const QPen &);
182  void setChannelLabel(std::list<Channel>::iterator,const QString &);
183 
184 private slots:
185  void timeoutEvent(void);
186 
187 protected:
188  void resizeEvent(QResizeEvent *);
189 
190 private:
191  void drawCurves(void);
192  size_t divX;
193  size_t divY;
194  size_t data_idx;
195  size_t data_size;
196  double hScl; // horizontal scale for time (ms)
197  double period; // real-time period of system (ms)
198  size_t refresh;
199  bool triggering;
200  trig_t triggerDirection;
201  double triggerThreshold;
202  double triggerWindow;
203  std::list<size_t> triggerQueue;
204  std::list<Channel>::iterator triggerChannel;
205 
206  // Scope primary paint element
207  QwtPlotDirectPainter *d_directPainter;
208 
209  // Scope painter elements
210  QwtPlotGrid *grid;
211  QwtPlotMarker *origin;
212 
213  // Scaling engine
214  QwtScaleMap *scaleMapY;
215  QwtScaleMap *scaleMapX;
216 
217  // Legend
218  LegendItem *legendItem;
219 
220  QTimer *timer;
221  QString dtLabel;
222  std::list<Channel> channels;
223 }; // Scope
224 
225 #endif // SCOPE_H
Scope::setRefresh
void setRefresh(size_t)
Definition: scope.cpp:391
Scope::getDivX
size_t getDivX(void) const
Definition: scope.cpp:373
Scope::Channel::getOffset
double getOffset(void) const
Definition: scope.cpp:62
Scope::Panel
friend class Panel
Definition: scope.h:57
Scope::POS
@ POS
Definition: scope.h:139
Scope::getTriggerDirection
trig_t getTriggerDirection(void)
Definition: scope.cpp:300
Scope::getDataSize
size_t getDataSize(void) const
Definition: scope.cpp:286
Scope::insertChannel
std::list< Channel >::iterator insertChannel(QString, double, double, const QPen &, QwtPlotCurve *, void *)
Definition: scope.cpp:177
Scope::NEG
@ NEG
Definition: scope.h:140
Scope::removeChannel
void * removeChannel(std::list< Channel >::iterator)
Definition: scope.cpp:195
Scope::LegendItem
Definition: scope.h:84
Scope::getTriggerThreshold
double getTriggerThreshold(void)
Definition: scope.cpp:305
Scope::setDivT
void setDivT(double)
Definition: scope.cpp:353
Scope::Channel
Definition: scope.h:61
Scope::getRefresh
size_t getRefresh(void) const
Definition: scope.cpp:385
Scope::isPaused
bool isPaused
Definition: scope.h:177
Scope::Channel::getLabel
QString getLabel(void) const
Definition: scope.cpp:68
Scope::NONE
@ NONE
Definition: scope.h:138
Scope::Channel::Channel
Channel(void)
Definition: scope.cpp:32
Scope::LegendItem::LegendItem
LegendItem()
Definition: scope.h:88
Scope::setDataSize
void setDataSize(size_t)
Definition: scope.cpp:291
Scope::resizeEvent
void resizeEvent(QResizeEvent *)
Definition: scope.cpp:205
Scope::getChannelCount
size_t getChannelCount(void) const
Definition: scope.cpp:212
Scope::setChannelOffset
void setChannelOffset(std::list< Channel >::iterator, double)
Definition: scope.cpp:404
Scope::Scope
Scope(QWidget *=NULL)
Definition: scope.cpp:74
Scope::~Scope
virtual ~Scope(void)
Definition: scope.cpp:158
Scope::Channel::getInfo
void * getInfo(void)
Definition: scope.cpp:38
Scope::getDivY
size_t getDivY(void) const
Definition: scope.cpp:379
Scope
Definition: scope.h:52
Scope::Channel::getPen
QPen getPen(void) const
Definition: scope.cpp:50
Scope::Channel::getScale
double getScale(void) const
Definition: scope.cpp:56
Scope::setData
void setData(double *, size_t)
Definition: scope.cpp:251
Scope::paused
bool paused(void) const
Definition: scope.cpp:164
Scope::trig_t
trig_t
Definition: scope.h:136
Scope::setPeriod
void setPeriod(double)
Definition: scope.cpp:367
Scope::getTriggerChannel
std::list< Channel >::iterator getTriggerChannel(void)
Definition: scope.cpp:315
Scope::getChannelsEnd
std::list< Channel >::iterator getChannelsEnd(void)
Definition: scope.cpp:224
Scope::setChannelPen
void setChannelPen(std::list< Channel >::iterator, const QPen &)
Definition: scope.cpp:410
Scope::setChannelLabel
void setChannelLabel(std::list< Channel >::iterator, const QString &)
Definition: scope.cpp:416
Scope::getChannelsBegin
std::list< Channel >::iterator getChannelsBegin(void)
Definition: scope.cpp:218
Scope::clearData
void clearData(void)
Definition: scope.cpp:242
Scope::getDivT
double getDivT(void) const
Definition: scope.cpp:347
Scope::setTrigger
void setTrigger(trig_t, double, std::list< Channel >::iterator, double)
Definition: scope.cpp:320
Scope::getTriggerWindow
double getTriggerWindow(void)
Definition: scope.cpp:310
Scope::Canvas
Definition: scope.h:96
Scope::setChannelScale
void setChannelScale(std::list< Channel >::iterator, double)
Definition: scope.cpp:398
Scope::Canvas::Canvas
Canvas(QwtPlot *plot=NULL)
Definition: scope.h:100
Scope::Channel::~Channel
virtual ~Channel(void)
Definition: scope.cpp:35