OpenCurves  0.9
plotinstance.h
1 //
2 // author Kazys Stepanas
3 //
4 // Copyright (c) CSIRO 2015
5 //
6 #ifndef PLOTINSTANCE_H_
7 #define PLOTINSTANCE_H_
8 
9 #include "plotsconfig.h"
10 
11 #include "plotsource.h"
12 
13 #include <QColor>
14 #include <QMutex>
15 #include <QPointF>
16 #include <QString>
17 
18 #include <cstdint>
19 #include <vector>
20 
21 class PlotDataCurve;
22 class PointSeriesData;
23 class PlotExpression;
24 
44 {
45 public:
47  enum Flag
48  {
51  DataComplete = (1 << 0),
53  RingBuffer = (1 << 1),
56  ExplicitColour = (1 << 2),
58  FilterNaN = (1 << 3),
60  FilterInf = (1 << 4),
65  ExplicitTime = (1 << 5),
66  };
67 
69  enum Defaults
70  {
72  };
73 
77 
79  PlotInstance(const PlotInstance &other);
80 
82  ~PlotInstance();
83 
86  PlotSource &source();
87 
90  const PlotSource &source() const;
91 
93  void setDefaultProperties();
94 
97  inline QString name() const { return _name; }
98 
101  inline void setName(QString name) { _name = name; }
102 
105  inline int style() const { return _style; }
106 
109  inline void setStyle(unsigned style) { _style = std::int8_t(style); }
110 
113  inline unsigned width() const { return _width; }
114 
117  inline void setWidth(unsigned width) { _width = std::uint8_t(width); }
118 
121  inline int symbol() const { return _symbol; }
122 
125  inline void setSymbol(int symbol) { _symbol = std::int8_t(symbol); }
126 
129  inline unsigned symbolSize() const { return _symbolSize; }
130 
133  inline void setSymbolSize(unsigned size) { _symbolSize = std::uint8_t(size); }
134 
137  inline const std::vector<QPointF> &data() const { return _data; }
138 
141  inline const QRgb &colour() const { return _colour; }
142 
146  void setColour(const QRgb &colour, bool markExplicit = true);
147 
152  inline const PlotExpression *expression() const { return _expression; }
153 
157  inline void setExpression(const PlotExpression *expression) { _expression = expression; }
158 
161  inline size_t ringHead() const { return _ringHead; }
162 
165  inline std::uint16_t flags() const { return _flags; }
166 
169  inline bool testFlags(std::uint16_t flags) { return (_flags & flags) == flags; }
170 
174  inline bool dataComplete() const { return (_flags & DataComplete) != 0; }
175 
177  inline void setComplete() { setFlagsState(DataComplete, true); }
178 
181  inline bool isRingBuffer() const { return (_flags & RingBuffer) != 0; }
182 
187  void makeRingBuffer(size_t bufferSize);
188 
191  inline bool explicitColour() const { return (_flags & ExplicitColour) != 0; }
192 
195  inline bool filterNaN() const { return (_flags & FilterNaN) != 0; }
196 
199  inline void setFilterNaN(bool filter) { setFlagsState(FilterNaN, filter); }
200 
203  inline bool filterInf() const { return (_flags & FilterInf) != 0; }
204 
207  inline void setFilterInf(bool filter) { setFlagsState(FilterInf, filter); }
208 
211  inline bool explicitTime() const { return (_flags & ExplicitTime) != 0; }
212 
215  inline void setExplicitTime(bool explct) { setFlagsState(ExplicitTime, explct); }
216 
223  QPointF sample(size_t index) const;
224 
227  void addPoint(const QPointF &p);
228 
232  void addPoints(const QPointF *points, size_t pointCount);
233 
235  bool migrateBuffer();
236 
240  PlotInstance &operator=(const PlotInstance &other);
241 
242 private:
246  void setFlagsState(std::uint16_t flags, bool set);
247 
248  std::vector<QPointF> _data;
249  PlotSource::Ptr _source;
250  QString _name;
251  QRgb _colour;
252  const PlotExpression *_expression;
253  size_t _ringHead;
255  std::uint16_t _flags;
256  std::int8_t _style;
257  std::uint8_t _width;
258  std::int8_t _symbol;
259  std::uint8_t _symbolSize;
260 
261  QMutex _mutex;
262  std::vector<QPointF> _buffer;
263 };
264 
265 
267 {
268  return *_source;
269 }
270 
271 
272 inline const PlotSource &PlotInstance::source() const
273 {
274  return *_source;
275 }
276 
277 
278 inline void PlotInstance::setColour(const QRgb &colour, bool markExplicit)
279 {
280  _colour = colour;
281  // Set ExplicitColour flag as requested.
282  setFlagsState(ExplicitColour, markExplicit);
283 }
284 
285 
286 inline void PlotInstance::setFlagsState(std::uint16_t flags, bool set)
287 {
288  _flags = (_flags & ~flags) | (!!set * flags);
289 }
290 
291 #endif // PLOTINSTANCE_H_
Set to filter NaN values, replacing them with zero.
Definition: plotinstance.h:58
void addPoints(const QPointF *points, size_t pointCount)
Add multiple points to the back buffer.
bool explicitColour() const
Using an explicit colour?
Definition: plotinstance.h:191
Flag
Status, control and display flags.
Definition: plotinstance.h:47
QPointF sample(size_t index) const
Samples the point at the given index.
int style() const
Get the draw style: matches QwtPlotCurve::CurveStyle.
Definition: plotinstance.h:105
void setExplicitTime(bool explct)
Set the state of the ExplicitTime Flag.
Definition: plotinstance.h:215
void setFilterInf(bool filter)
Set or clear infinite value filtering.
Definition: plotinstance.h:207
const PlotExpression * expression() const
Get the expression which generated this plot (Expression source() only).
Definition: plotinstance.h:152
void setName(QString name)
Set the plot name.
Definition: plotinstance.h:101
bool filterNaN() const
Filter NaN values on display?
Definition: plotinstance.h:195
Set when all data have been loaded and the curve is complete.
Definition: plotinstance.h:51
~PlotInstance()
Destructor.
void setSymbolSize(unsigned size)
Set the symbol size: limited to 255.
Definition: plotinstance.h:133
PlotInstance(const PlotSource::Ptr &source)
Create a plot instance from the given source.
Set if the data member acts as a ring buffer. Affects sample(), addPoint(), addPoints().
Definition: plotinstance.h:53
void setDefaultProperties()
Restore the default style, colour, etc properties.
Set to filter infinite values, replacing them zero.
Definition: plotinstance.h:60
Holds data for a single curve.
Definition: plotinstance.h:43
const std::vector< QPointF > & data() const
Direct access to the data buffer.
Definition: plotinstance.h:137
void setFilterNaN(bool filter)
Set or clear NaN filtering.
Definition: plotinstance.h:199
Default size for displaying plot symbols.
Definition: plotinstance.h:71
PlotInstance & operator=(const PlotInstance &other)
Assignment operator.
bool explicitTime() const
Has the curve been generated with explicit time values?
Definition: plotinstance.h:211
bool migrateBuffer()
Migrate from the back buffer to data(). Main thread only.
PlotSource & source()
Access the plot source.
Definition: plotinstance.h:266
void addPoint(const QPointF &p)
Add a point to the back buffer (thread-safe).
void setComplete()
Marks data complete.
Definition: plotinstance.h:177
void makeRingBuffer(size_t bufferSize)
Converts the plot data to a ring buffer of the given size.
QString name() const
Get the plot name.
Definition: plotinstance.h:97
bool dataComplete() const
Is data loading complete?
Definition: plotinstance.h:174
std::uint16_t flags() const
Get the status, control and display Flag values.
Definition: plotinstance.h:165
A specialisation of QwtPlotCurve used to visualisation PlotInstanceData.
Definition: plotdatacurve.h:22
const QRgb & colour() const
Get the display colour for the plot.
Definition: plotinstance.h:141
Provides details about a source from which PlotInstance objects have been generated.
Definition: plotsource.h:28
unsigned symbolSize() const
Get the symbol size.
Definition: plotinstance.h:129
void setColour(const QRgb &colour, bool markExplicit=true)
Set the display colour, making it explicit unless requested otherwise.
Definition: plotinstance.h:278
Has the curve been generated with explicit time samples? Some generated curves have explicit times an...
Definition: plotinstance.h:65
void setSymbol(int symbol)
Set the draw symbol: matches QwtSymbol::Style.
Definition: plotinstance.h:125
unsigned width() const
Get the draw width.
Definition: plotinstance.h:113
int symbol() const
Get the draw symbol: matches QwtSymbol::Style.
Definition: plotinstance.h:121
void setStyle(unsigned style)
Set the draw style: matches QwtPlotCurve::CurveStyle.
Definition: plotinstance.h:109
void setExpression(const PlotExpression *expression)
Sets the expression which generated this plot.
Definition: plotinstance.h:157
Defaults
Some default values for plots.
Definition: plotinstance.h:69
size_t ringHead() const
The read head of the ring buffer.
Definition: plotinstance.h:161
A PlotExpression represents an operation in a plot equation.
Definition: plotexpression.h:91
Set if the graph has been assigned an explicit colour.
Definition: plotinstance.h:56
bool filterInf() const
Filter infinite values on display?
Definition: plotinstance.h:203
void setWidth(unsigned width)
Set the pen draw width: limited to 255.
Definition: plotinstance.h:117
bool isRingBuffer() const
Is this a ring buffer?
Definition: plotinstance.h:181
bool testFlags(std::uint16_t flags)
Sets that all flags are set in the flags() member.
Definition: plotinstance.h:169