OpenCurves  0.9
PlotExpressionGenerator Class Reference

A PlotGenerator which generated plots by evaluating PlotExpression objects. More...

#include <plotexpressiongenerator.h>

Inheritance diagram for PlotExpressionGenerator:
PlotGenerator

Public Types

enum  AddExpressionResult { AER_QueuedPartial = -1, AER_AlreadyComplete, AER_Queued }
 Return value sfor addExpression() and addExpressions(). More...
 
- Public Types inherited from PlotGenerator
enum  ControlFlag { None = 0, RelativeTime = (1 << 0) }
 Plot generation control flags. Must be set before execution. More...
 

Public Member Functions

 PlotExpressionGenerator (Curves *curves, const QList< PlotExpression * > &expressions, const QStringList &sourceNames)
 Create an expression generator based on the given expressions and curves. More...
 
 PlotExpressionGenerator (Curves *curves, const QList< const PlotExpression * > &expressions, const QStringList &sourceNames)
 
 ~PlotExpressionGenerator ()
 Destructor.
 
int addExpression (const PlotExpression *expression)
 Adds an expression to be generated even if already running. More...
 
int addExpressions (const QList< const PlotExpression * > &expressions)
 Adds a set of expression to be generated even if already running. More...
 
bool removeExpression (const PlotExpression *expression)
 Aborts generation of expression if it has yet to be generated. More...
 
- Public Member Functions inherited from PlotGenerator
 PlotGenerator (Curves *curves)
 Instantiate the generator thread to load data into curves. More...
 
virtual ~PlotGenerator ()
 Destructor. The thread should generally be stopped before destructing.
 
const Curvescurves () const
 Access the curves model to load data into.
 
void setTimeColumn (uint number)
 Set the expected time column for all curves created by this generator. More...
 
uint timeColumn () const
 The time column value in used. More...
 
void setTimeScale (double scale)
 Set the scale factor applied to all curves created by this generator. More...
 
double timeScale () const
 Access the time scale used by this generator. More...
 
void setControlFlags (uint flags)
 Sets ControlFlag values for this generator. More...
 
void setControlFlags (uint flags, bool on)
 Set the state of subset of ControlFlag values without affecting other flags. More...
 
uint controlFlags () const
 Access the current ControlFlag values.
 
void quit ()
 Call to request the generator terminate operation.
 
virtual bool isFileLoad () const
 True if this is a file loader. More...
 

Protected Member Functions

void run () override
 Generation loop.
 
bool curveExists (const PlotInstance &curve) const
 Check if the curve exists. More...
 

Additional Inherited Members

- Public Slots inherited from PlotGenerator
void abortLoad ()
 Request loading abort.
 
- Signals inherited from PlotGenerator
void itemName (const QString &name)
 Signal the current item name. More...
 
void itemProgress (int current)
 Update progress through the current item. More...
 
void overallProgress (int current, int total)
 This signal reports overall progress. More...
 
void beginNewCurves ()
 Begin the addition of new curves via Curves::newCurve() Block notification occurs at a per PlotSource level. More...
 
void endNewCurves ()
 End notification of new curves via Curves::newCurve(). More...
 
void loadComplete (int curveCount)
 Notify completion of curve generation. More...
 
- Protected Attributes inherited from PlotGenerator
Curves_curves
 Curves data model.
 
QMutex * _dataMutex
 Data mutex.
 
uint _controlFlags
 ControlFlag values affecting generation.
 
uint _timeColumn
 Index of the time column, zero for none.
 
double _timeScale
 Time scaling factor.
 
bool _abortFlag
 Abort requested?
 

Detailed Description

A PlotGenerator which generated plots by evaluating PlotExpression objects.

The generator is designed to run asynchronously. As such, it makes copies of the data on which to operate in case these are destroyed. However, the PlotInstance::expression member is always set as the original expression, not the internal copy.

More explicitly, plots generated herein refer to the original PlotExpression objects, but internal calculations use a copy of the expressions for thread safety. The original expressions should remain valid and unmodified while the generator executes, but failure to do so will not result in a failure within the generator object. Instead, generated plots may be out of date or reference an invalid expression.

Plot binding is exhaustive, supporting regular expression based PlotExpression trees. However, this can lead to multiple bindings of the same data when referencing regular expressions from different plots. For example, the expression:

///   r'samples-.*'|'value' - r'samples-.*'|'value'
/// 

Consider where we have two files loaded 'samples-a' and 'samples-b'. This expression will bind the following:

  • 'samples-a'|'value' - 'samples-a'|'value'
  • 'samples-a'|'value' - 'samples-a'|'value'
  • 'samples-a'|'value' - 'samples-b'|'value'
  • 'samples-b'|'value' - 'samples-b'|'value'
Note
The PlotSource for PlotInstance objects generated here is the same as the original source. Expression curves can be distinguished by the fact that PlotInstance::expression() is not null.

Member Enumeration Documentation

Return value sfor addExpression() and addExpressions().

Enumerator
AER_QueuedPartial 

Returned when some of the new expressions are successfully queued, while others have already been generated.

AER_AlreadyComplete 

Returned when all of the expression begin added have already been generated.

This occurs either because the generator thread has completed or because the expressions already exist and have been processed (or are currently being processed).

AER_Queued 

Returned when all the new expressions are successfully queued and will be generated.

Constructor & Destructor Documentation

PlotExpressionGenerator::PlotExpressionGenerator ( Curves curves,
const QList< PlotExpression * > &  expressions,
const QStringList &  sourceNames 
)

Create an expression generator based on the given expressions and curves.

The generator makes copies of the PlotExpression and PlotInstance objects for internal calculations. However, a copy of the original expression list is maintained so that the original expression objects are assigned to generated PlotInstance objects. See class comments.

Parameters
curvesThe Curves model containing existing curves from which to generate new ones. New curves are added to this model.
expressionsThe expressions to generate new curves from. These objects must remain valid until the generator completes.
sourceNamesList of all the source files from which curves were loaded.
PlotExpressionGenerator::PlotExpressionGenerator ( Curves curves,
const QList< const PlotExpression * > &  expressions,
const QStringList &  sourceNames 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Member Function Documentation

int PlotExpressionGenerator::addExpression ( const PlotExpression expression)

Adds an expression to be generated even if already running.

Thread-safe.

The caller retains ownership of expression.

Returns
One of the values in AddExpressionResult. Does not return AER_QueuedPartial.
int PlotExpressionGenerator::addExpressions ( const QList< const PlotExpression * > &  expressions)

Adds a set of expression to be generated even if already running.

Thread-safe.

The caller retains ownership of expression.

Returns
One of the values in AddExpressionResult.
bool PlotExpressionGenerator::curveExists ( const PlotInstance curve) const
protected

Check if the curve exists.

This is used to duplicate binding.

Looks in _existingCurves for an item with the same PlotSource::name() and PlotInstance::name().

Parameters
curveThe curve to look for a duplicate of.
Returns
True if a matching curves exists.
bool PlotExpressionGenerator::removeExpression ( const PlotExpression expression)

Aborts generation of expression if it has yet to be generated.

Thread-safe.

Returns
True if the given expression has been removed or was not present. False if the expression has already been generated.

The documentation for this class was generated from the following file: