Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

progressmonitor.h

Go to the documentation of this file.
00001 /*
00002     Sheep - A Rigid Body Dynamics Engine
00003     Copyright (C) 2001-2004 Francois Beaune
00004     Contact: http://toxicengine.sourceforge.net/
00005 
00006     This file is part of Sheep.
00007 
00008     Sheep is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     Sheep is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with Sheep; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 */
00022 
00023 #ifndef SHEEP_MISC_PROGRESSMONITOR_H
00024 #define SHEEP_MISC_PROGRESSMONITOR_H
00025 
00026 #include "common/math/real.h"
00027 
00028 #include <cassert>
00029 #include <string>
00030 
00031 namespace sheep {
00032 
00033     class ProgressMonitor {
00034     public:
00035         //! Initializes the object by calling the Reset() method.
00036         ProgressMonitor();
00037 
00038         //! Resets this ProgressMonitor object.
00039         void Reset();
00040 
00041         //! Starts a new job. Cumulated duration of all jobs must be equal to 1.0.
00042         //! Triggers the update callback.
00043         void StartJob(Real range_min, Real range_max, Real duration = 1.0);
00044 
00045         //! Ends the current job. Triggers the update callback.
00046         void EndJob();
00047 
00048         //! Any resolution below or equal 0.0 will make the UpdateCallback() method
00049         //! be called at each progress update. Maximum resolution is 1.0. Default
00050         //! resolution is 1.0 / 100.
00051         void SetUpdateResolution(Real resolution);
00052 
00053         //! Changes the current message. Triggers the update callback.
00054         void SetMessage(const std::string &message);
00055 
00056         //! Returns the current message.
00057         const std::string &GetMessage() const;
00058 
00059         //! Sets the current job's progress. 'progress' must lies in [range_min, range_max].
00060         //! Triggers the update callback.
00061         void SetJobProgress(Real progress);
00062 
00063         //! Returns the total progress. This is the value that should be displayed.
00064         Real GetProgress() const;
00065 
00066         //! This method should be called when all jobs are done. It calls EndJob()
00067         //! if necessary. Triggers the update callback.
00068         void Done();
00069 
00070         //! Returns true if all jobs are done, false otherwise.
00071         bool IsDone() const;
00072 
00073         //! Typically implemented using GetProgress(), IsDone() and GetMessage() methods.
00074         virtual void UpdateCallback() = 0;
00075 
00076     private:
00077         Real m_job_start;           //!< Start time of the current job.
00078         Real m_job_duration;        //!< Duration of the current job.
00079         Real m_job_range_min;       //!< Lower bound of the current job's range.
00080         Real m_job_range_max;       //!< Upper bound of the current job's range.
00081         Real m_job_progress_scale;  //!< m_job_duration / (m_job_range_max - m_job_range_min).
00082         bool m_job_done;            //!< Is the current job done?
00083 
00084         Real m_update_resolution;   //!< Minimum progress change required to trigger the update callback.
00085         std::string m_message;      //!< Current message.
00086 
00087         Real m_progress;            //!< Total progress.
00088         bool m_done;                //!< Are all jobs done?
00089 
00090         Real m_last_update;         //!< Time of the last update.
00091 
00092         void post_update();
00093     };
00094 
00095 #include "progressmonitor.inl"
00096 
00097 }
00098 
00099 #endif  // !SHEEP_MISC_PROGRESSMONITOR_H

Generated on Tue May 11 01:31:51 2004 for toxic by doxygen 1.3.6