TuttleOFX  1
TuttleOFX/libraries/tuttle/src/tuttle/plugin/OfxProgress.cpp
Go to the documentation of this file.
00001 #include "OfxProgress.hpp"
00002 
00003 #include <ofxsMultiThread.h>
00004 
00005 namespace tuttle {
00006 namespace plugin {
00007 
00008 /**
00009  * @brief Start the algorithm progress bar.
00010  *
00011  * @param[in]       numSteps   number of steps
00012  *
00013  */
00014 void OfxProgress::progressBegin( const int numSteps, const std::string& msg )
00015 {
00016         _counter = 0.0;
00017         _stepSize = 1.0 / static_cast<double>( numSteps );
00018         _effect.progressStart( msg );
00019 }
00020 
00021 /**
00022  * @brief Put the progress bar forward.
00023  *
00024  * @param[in]       nSteps   Number of steps processed since last call.
00025  *
00026  * @return true = effect aborted,
00027  *         false = continu rendering
00028  *
00029  */
00030 bool OfxProgress::progressForward( const int nSteps )
00031 {
00032         _mutex.lock();
00033         _counter += _stepSize * static_cast<double>( nSteps );
00034         /// @todo why not unlock the mutex here?
00035         if( _effect.abort() )
00036         {
00037                 _mutex.unlock();
00038                 _effect.progressEnd();
00039                 return true;
00040         }
00041         const bool res = _effect.progressUpdate( _counter );
00042         _mutex.unlock();
00043         return res;
00044 }
00045 
00046 bool OfxProgress::progressUpdate( const double p )
00047 {
00048         if( _effect.abort() )
00049         {
00050                 return true;
00051         }
00052         _counter = p;
00053         return _effect.progressUpdate( _counter );
00054 }
00055 
00056 /**
00057  * @brief Ends the algorithm progress bar.
00058  *
00059  */
00060 void OfxProgress::progressEnd()
00061 {
00062         // Wait for the end
00063         _mutex.lock();
00064         _mutex.unlock();
00065         _effect.progressEnd();
00066 }
00067 
00068 OfxProgress& OfxProgress::operator=( const OfxProgress& p )
00069 {
00070         if( this == &p )
00071                 return *this;                                                                                                                                                                                                                                                                                               // Gracefully handle self assignment
00072         _counter  = p._counter;
00073         _stepSize = p._stepSize;
00074         return *this;
00075 }
00076 
00077 }
00078 }
00079