This class gives the user an indication of the progress of an operation and it is used to reassure him that the application is still running. More...
#include <Sequencer.h>
Public Member Functions | |
virtual bool | isBlocking () const |
Returns true if the running sequencer is blocking any user input. | |
bool | isLocked () const |
Returns true if the sequencer was locked, false otherwise. | |
bool | isRunning () const |
Returns true if the sequencer is running, otherwise returns false. | |
bool | setLocked (bool bLock) |
If bLock is true then the sequencer gets locked. | |
bool | wasCanceled () const |
Returns true if the pending operation was canceled. | |
Static Public Member Functions | |
static SequencerBase & | Instance () |
Returns the last created sequencer instance. | |
Protected Member Functions | |
bool | next (bool canAbort=false) |
Performs the next step and returns true if the operation is not yet finished. | |
virtual void | nextStep (bool canAbort) |
This method can be reimplemented in sub-classes to give the user a feedback when the next is performed. | |
size_t | numberOfSteps () const |
Returns the number of steps. | |
virtual void | pause () |
Breaks the sequencer if needed. | |
int | progressInPercent () const |
Returns the current state of progress in percent. | |
void | rejectCancel () |
If you tried to cancel but then decided to continue the operation. | |
virtual void | resetData () |
Resets internal data. | |
virtual void | resume () |
Continues with progress. | |
SequencerBase () | |
construction | |
virtual void | setProgress (size_t) |
Sets the progress indicator to a certain position. | |
virtual void | setText (const char *pszTxt) |
Sets a text what the pending operation is doing. | |
bool | start (const char *pszStr, size_t steps) |
Starts a new operation, returns false if there is already a pending operation, otherwise it returns true. | |
virtual void | startStep () |
This method can be reimplemented in sub-classes to give the user a feedback when a new sequence starts. | |
bool | stop () |
Stops the sequencer if all operations are finished. | |
void | tryToCancel () |
Try to cancel the pending operation(s). | |
virtual | ~SequencerBase () |
Destruction. | |
Protected Attributes | |
size_t | nProgress |
Stores the current amount of progress. | |
size_t | nTotalSteps |
Stores the total number of steps. | |
Friends | |
class | SequencerLauncher |
This class gives the user an indication of the progress of an operation and it is used to reassure him that the application is still running.
Here are some code snippets of how to use the sequencer:
#include <Base/Sequencer.h> //first example Base::SequencerLauncher seq("my text", 10)) for (int i=0; i<10; i++) { // do something seq.next (); } //second example Base::SequencerLauncher seq("my text", 10)) do { // do something } while (seq.next());
The implementation of this class also supports several nested instances at a time. But note, that only the first instance has an effect. Any further sequencer instance doesn't influence the total numer of iteration steps. This is simply because it's impossible to get the exact number of iteration steps for nested instances and thus we have either too few steps estimated then the sequencer may indicate 100% but the algorithm still running or we have too many steps estimated so that the an algorithm may stop long before the sequencer reaches 100%.
try { //start the first operation Base::SequencerLauncher seq1("my text", 10) for (int i=0; i<10, i++) { // do something // start the second operation while the first one is still running Base::SequencerLauncher seq2("another text", 10); for (int j=0; j<10; j++) { // do something different seq2.next (); } seq1.next ( true ); // allow to cancel } } catch(const Base::AbortException&){ // cleanup your data if needed }
Definition at line 115 of file Sequencer.h.
SequencerBase::SequencerBase | ( | ) | [protected] |
construction
Definition at line 83 of file Sequencer.cpp.
References Base::SequencerP::appendInstance().
SequencerBase::~SequencerBase | ( | ) | [protected, virtual] |
Destruction.
Definition at line 89 of file Sequencer.cpp.
References Base::SequencerP::removeInstance().
SequencerBase & SequencerBase::Instance | ( | void | ) | [static] |
Returns the last created sequencer instance.
If you create an instance of a class inheriting SequencerBase this object is retrieved instead.
This mechanism is very useful to have an own sequencer for each layer of FreeCAD. For example, if FreeCAD is running in server mode you have/need no GUI layer and therewith no (graphical) progress bar; in this case ConsoleSequencer is taken. But in cases FreeCAD is running with GUI the Gui::ProgressBar is taken instead.
Definition at line 73 of file Sequencer.cpp.
References Base::SequencerP::_instances, and Base::SequencerP::getInstance().
Referenced by Base::SequencerLauncher::next(), Base::SequencerLauncher::numberOfSteps(), Base::Sequencer(), Base::SequencerLauncher::SequencerLauncher(), Base::SequencerLauncher::setProgress(), Base::SequencerLauncher::setText(), Base::SequencerLauncher::wasCanceled(), and Base::SequencerLauncher::~SequencerLauncher().
bool SequencerBase::isBlocking | ( | ) | const [virtual] |
Returns true if the running sequencer is blocking any user input.
This might be only of interest of the GUI where the progress bar or dialog is used from a thread. If started from a thread this method should return false, otherwise true. The default implementation always returns true.
Reimplemented in Gui::Sequencer, and Gui::SequencerDialog.
Definition at line 161 of file Sequencer.cpp.
bool SequencerBase::isLocked | ( | ) | const |
Returns true if the sequencer was locked, false otherwise.
Definition at line 174 of file Sequencer.cpp.
References Base::SequencerP::mutex.
bool SequencerBase::isRunning | ( | ) | const |
Returns true if the sequencer is running, otherwise returns false.
Definition at line 180 of file Sequencer.cpp.
References Base::SequencerP::_topLauncher, and Base::SequencerP::mutex.
Referenced by Gui::ProgressBar::delayedShow(), Gui::ProgressDialog::eventFilter(), and Gui::ProgressBar::eventFilter().
bool SequencerBase::next | ( | bool | canAbort = false |
) | [protected] |
Performs the next step and returns true if the operation is not yet finished.
But note, when 0 was passed to start() as the number of total steps this method always returns false.
In this method nextStep() gets invoked that can be reimplemented in sub-classes. If canAbort is true then the operations can be aborted, otherwise (the default) the operation cannot be aborted. In case it gets aborted an exception AbortException is thrown.
Definition at line 121 of file Sequencer.cpp.
References SketcherExample::f, Py::int, nextStep(), nProgress, and nTotalSteps.
Referenced by Base::SequencerLauncher::next().
void SequencerBase::nextStep | ( | bool | canAbort | ) | [protected, virtual] |
This method can be reimplemented in sub-classes to give the user a feedback when the next is performed.
The default implementation does nothing. If canAbort is true then the pending operation can aborted, otherwise not. Depending on the re-implementation this method can throw an AbortException if canAbort is true.
Reimplemented in Base::ConsoleSequencer, Gui::Sequencer, and Gui::SequencerDialog.
Definition at line 139 of file Sequencer.cpp.
Referenced by next().
size_t SequencerBase::numberOfSteps | ( | ) | const [protected] |
Returns the number of steps.
Definition at line 112 of file Sequencer.cpp.
References nTotalSteps.
Referenced by Base::SequencerLauncher::numberOfSteps().
void SequencerBase::pause | ( | ) | [protected, virtual] |
Breaks the sequencer if needed.
The default implementation does nothing. Every pause() must eventually be followed by a corresponding resume().
Reimplemented in Gui::Sequencer, and Gui::SequencerDialog.
Definition at line 153 of file Sequencer.cpp.
int SequencerBase::progressInPercent | ( | ) | const [protected] |
Returns the current state of progress in percent.
Definition at line 202 of file Sequencer.cpp.
Referenced by Base::ConsoleSequencer::nextStep().
void SequencerBase::rejectCancel | ( | ) | [protected] |
If you tried to cancel but then decided to continue the operation.
E.g. in Gui::ProgressBar a dialog appears asking if you really want to cancel. If you decide to continue this method must be called.
Definition at line 197 of file Sequencer.cpp.
Referenced by Gui::SequencerDialog::nextStep(), and Gui::Sequencer::nextStep().
void SequencerBase::resetData | ( | ) | [protected, virtual] |
Resets internal data.
If you want to reimplement this method, it is very important to call it ín the re-implemented method.
Reimplemented in Gui::Sequencer, and Gui::SequencerDialog.
Definition at line 207 of file Sequencer.cpp.
Referenced by stop().
void SequencerBase::resume | ( | ) | [protected, virtual] |
Continues with progress.
The default implementation does nothing.
Reimplemented in Gui::Sequencer, and Gui::SequencerDialog.
Definition at line 157 of file Sequencer.cpp.
bool SequencerBase::setLocked | ( | bool | bLock | ) |
If bLock is true then the sequencer gets locked.
startStep() and nextStep() don't get invoked any more until the sequencer gets unlocked again. This method returns the previous lock state.
Definition at line 166 of file Sequencer.cpp.
References Base::SequencerP::mutex.
void SequencerBase::setProgress | ( | size_t | ) | [protected, virtual] |
Sets the progress indicator to a certain position.
Reimplemented in Gui::Sequencer.
Definition at line 143 of file Sequencer.cpp.
Referenced by Base::SequencerLauncher::setProgress().
void SequencerBase::setText | ( | const char * | pszTxt | ) | [protected, virtual] |
Sets a text what the pending operation is doing.
The default implementation does nothing.
Reimplemented in Gui::Sequencer, and Gui::SequencerDialog.
Definition at line 212 of file Sequencer.cpp.
Referenced by Base::SequencerLauncher::setText(), and start().
bool SequencerBase::start | ( | const char * | pszStr, | |
size_t | steps | |||
) | [protected] |
Starts a new operation, returns false if there is already a pending operation, otherwise it returns true.
In this method startStep() gets invoked that can be reimplemented in sub-classes.
Definition at line 94 of file Sequencer.cpp.
References nProgress, nTotalSteps, setText(), and startStep().
Referenced by Base::SequencerLauncher::SequencerLauncher().
void SequencerBase::startStep | ( | ) | [protected, virtual] |
This method can be reimplemented in sub-classes to give the user a feedback when a new sequence starts.
The default implementation does nothing.
Reimplemented in Base::ConsoleSequencer, Gui::Sequencer, and Gui::SequencerDialog.
Definition at line 117 of file Sequencer.cpp.
Referenced by start().
bool SequencerBase::stop | ( | ) | [protected] |
Stops the sequencer if all operations are finished.
It returns false if there are still pending operations, otherwise it returns true.
Definition at line 147 of file Sequencer.cpp.
References resetData().
Referenced by Base::SequencerLauncher::~SequencerLauncher().
void SequencerBase::tryToCancel | ( | ) | [protected] |
Try to cancel the pending operation(s).
E.g. Gui::ProgressBar calls this method after the ESC button was pressed.
Definition at line 192 of file Sequencer.cpp.
Referenced by Gui::ProgressBar::eventFilter(), and Gui::ProgressDialog::onCancel().
bool SequencerBase::wasCanceled | ( | ) | const |
Returns true if the pending operation was canceled.
Definition at line 186 of file Sequencer.cpp.
References Base::SequencerP::mutex.
Referenced by Gui::ProgressBar::delayedShow(), Gui::SequencerDialog::nextStep(), Gui::Sequencer::nextStep(), and Base::SequencerLauncher::wasCanceled().
friend class SequencerLauncher [friend] |
Definition at line 117 of file Sequencer.h.
size_t Base::SequencerBase::nProgress [protected] |
Stores the current amount of progress.
Definition at line 237 of file Sequencer.h.
Referenced by next(), Gui::SequencerDialog::nextStep(), Gui::Sequencer::nextStep(), and start().
size_t Base::SequencerBase::nTotalSteps [protected] |
Stores the total number of steps.
Definition at line 238 of file Sequencer.h.
Referenced by next(), Base::ConsoleSequencer::nextStep(), numberOfSteps(), start(), Gui::SequencerDialog::startStep(), and Gui::Sequencer::startStep().