The SequencerLauncher class is provided for convenience. More...
#include <Sequencer.h>
Public Member Functions | |
bool | next (bool canAbort=false) |
size_t | numberOfSteps () const |
SequencerLauncher (const char *pszStr, size_t steps) | |
void | setProgress (size_t) |
void | setText (const char *pszTxt) |
bool | wasCanceled () const |
~SequencerLauncher () |
The SequencerLauncher class is provided for convenience.
It allows you to run an instance of the sequencer by instantiating an object of this class -- most suitable on the stack. So this mechanism can be used for try-catch-blocks to destroy the object automatically if the C++ exception mechanism cleans up the stack.
This class has been introduced to simplify the use with the sequencer. In the FreeCAD Gui layer there is a subclass of SequencerBase called ProgressBar that grabs the keyboard and filters most of the incoming events. If the programmer uses the API of SequencerBase directly to start an instance without due diligence with exceptions then a not handled exception could block the whole application -- the user has to kill the application then.
Below is an example of a not correctly used sequencer.
#include <Base/Sequencer.h> void runOperation(); void myTest() { try{ runOperation(); } catch(...) { // the programmer forgot to stop the sequencer here // Under circumstances the sequencer never gets stopped so the keyboard never gets ungrabbed and // all Gui events still gets filtered. } } void runOperation() { Base::Sequencer().start ("my text", 10); for (int i=0; i<10; i++) { // do something where an exception be thrown ... Base::Sequencer().next (); } Base::Sequencer().stop (); }
To avoid such problems the SequencerLauncher class can be used as follows:
#include <Base/Sequencer.h> void runOperation(); void myTest() { try{ runOperation(); } catch(...) { // the programmer forgot to halt the sequencer here // If SequencerLauncher leaves its scope the object gets destructed automatically and // stops the running sequencer. } } void runOperation() { // create an instance on the stack (not on any terms on the heap) SequencerLauncher seq("my text", 10); for (int i=0; i<10; i++) { // do something (e.g. here can be thrown an exception) ... seq.next (); } }
Definition at line 364 of file Sequencer.h.
SequencerLauncher::SequencerLauncher | ( | const char * | pszStr, | |
size_t | steps | |||
) |
Definition at line 261 of file Sequencer.cpp.
References Base::SequencerP::_topLauncher, Base::SequencerBase::Instance(), Base::SequencerP::mutex, and Base::SequencerBase::start().
SequencerLauncher::~SequencerLauncher | ( | ) |
Definition at line 271 of file Sequencer.cpp.
References Base::SequencerP::_topLauncher, Base::SequencerBase::Instance(), Base::SequencerP::mutex, and Base::SequencerBase::stop().
bool SequencerLauncher::next | ( | bool | canAbort = false |
) |
Definition at line 287 of file Sequencer.cpp.
References Base::SequencerP::_topLauncher, Base::SequencerBase::Instance(), Base::SequencerP::mutex, and Base::SequencerBase::next().
Referenced by CmdTestProgress4::activated(), CmdTestProgress3::activated(), CmdTestProgress2::activated(), CmdTestProgress1::activated(), CmdSandboxDocThreadWithSeq::activated(), MeshCore::MeshBuilder::AddFacet(), PartGui::CrossSections::apply(), Reen::BSplineParameterCorrection::CalcFirstSmoothMatrix(), Reen::BSplineParameterCorrection::CalcSecondSmoothMatrix(), Reen::BSplineParameterCorrection::CalcThirdSmoothMatrix(), MeshCore::MeshEvalSelfIntersection::Evaluate(), Robot::Edge2TracObject::execute(), MeshCore::MeshEvalSelfIntersection::GetIntersections(), Points::PointsAlgos::LoadAscii(), MeshCore::MeshInput::LoadInventor(), MeshPart::CurveProjectorWithToolMesh::makeToolMesh(), MeshPart::CurveProjectorSimple::projectCurve(), Sandbox::WorkerThread::run(), BarThread::run(), Raytracing::PovTools::writeShape(), and Raytracing::PovTools::writeShapeCSV().
size_t SequencerLauncher::numberOfSteps | ( | ) | const |
Definition at line 301 of file Sequencer.cpp.
References Base::SequencerBase::Instance(), Base::SequencerP::mutex, and Base::SequencerBase::numberOfSteps().
void SequencerLauncher::setProgress | ( | size_t | pos | ) |
Definition at line 295 of file Sequencer.cpp.
References Base::SequencerBase::Instance(), Base::SequencerP::mutex, and Base::SequencerBase::setProgress().
void SequencerLauncher::setText | ( | const char * | pszTxt | ) |
Definition at line 281 of file Sequencer.cpp.
References Base::SequencerBase::Instance(), Base::SequencerP::mutex, and Base::SequencerBase::setText().
bool SequencerLauncher::wasCanceled | ( | ) | const |
Definition at line 307 of file Sequencer.cpp.
References Base::SequencerBase::Instance(), and Base::SequencerBase::wasCanceled().