#include <MComputation.h>
Interupt monitor for long computations.
An MComputation allows long computations to check for user interrupts. It is very simple to use. Create a new MComputation object and call the beginComputation method at the beginning of the computation and call the endComputation method when you finish. Then, during the computation, use the isInterruptRequested method to check if the user has requested that the computation terminate.
Example: (of a simple traversal)
An alternate form of computation with a progress indicator is supported. In this case, the beginProgressiveComputation method is called along with the progress methods.
Example: (of a simple progressive traversal)
Public Member Functions | |
MComputation () | |
Constructor for MComputation. More... | |
virtual | ~MComputation () |
Class destructor. | |
void | beginComputation (bool showProgressBar=false, bool isInterruptable=true, bool useWaitCursor=true) |
Mark the beginning of a long computation. More... | |
bool | isInterruptRequested () |
Query whether a user-interrupt has occurred. More... | |
void | endComputation () |
Mark the ending of a long computation. More... | |
MStatus | setProgressRange (const int minValue, const int maxValue) |
Sets the range (minValue, maxValue) of the progress indicator. More... | |
int | progressMin (MStatus *ReturnStatus=NULL) const |
Get the minimum progress value. More... | |
int | progressMax (MStatus *ReturnStatus=NULL) const |
Get the maximum progress value. More... | |
MStatus | setProgress (const int amount) |
Sets the progress value. More... | |
int | progress (MStatus *ReturnStatus=NULL) const |
Get the progress value. More... | |
MStatus | setProgressStatus (const MString &) |
Sets the progress status string. More... | |
Static Public Member Functions | |
static const char * | className () |
Returns the name of this class. More... | |
MComputation | ( | ) |
Constructor for MComputation.
Instantiate an MComputation before entering a long computation that should be interruptible.
void beginComputation | ( | bool | showProgressBar = false , |
bool | isInterruptable = true , |
||
bool | useWaitCursor = true |
||
) |
Mark the beginning of a long computation.
The application will begin looking for user interupts.
[in] | showProgressBar | if true a progress bar is displayed |
[in] | isInterruptable | ESC can be used in conjunction with the isInterruptRequested() method to stop the computation. In this case setProgressStatus() should not be called. |
[in] | useWaitCursor | if true, cursor goes busy during computation |
bool isInterruptRequested | ( | ) |
Query whether a user-interrupt has occurred.
void endComputation | ( | ) |
Mark the ending of a long computation.
The application will stop looking for user interupts.
MStatus setProgressRange | ( | const int | minValue, |
const int | maxValue | ||
) |
Sets the range (minValue, maxValue) of the progress indicator.
When the progress value is set to a value of minValue, the progress bar is displayed as empty. When the progress value is set to a value of maxValue, the progress bar is displayed as full. Intermediate progress values are displayed as intermediate positions of the progress bar.
[in] | minValue | Minimum progress value |
[in] | maxValue | Maximum progress value |
int progressMin | ( | MStatus * | ReturnStatus = NULL | ) | const |
Get the minimum progress value.
[out] | ReturnStatus | Status code |
int progressMax | ( | MStatus * | ReturnStatus = NULL | ) | const |
Get the maximum progress value.
[out] | ReturnStatus | Status code |
MStatus setProgress | ( | const int | amount | ) |
Sets the progress value.
Advancing the progress value updates the progress bar to show the new amount of progress.
[in] | amount | New progress value |
int progress | ( | MStatus * | ReturnStatus = NULL | ) | const |
Get the progress value.
[out] | ReturnStatus | Status code |
Sets the progress status string.
For example, you could use this to display the percentage of the computation which has been completed.
[in] | progressString | New status string |
|
static |
Returns the name of this class.