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

progressmonitor.inl

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 inline
00024 ProgressMonitor::ProgressMonitor() {
00025     Reset();
00026 }
00027 
00028 inline
00029 void ProgressMonitor::Reset() {
00030     // The following members are set when a job starts:
00031     // m_job_start, m_job_duration, m_job_range_min, m_job_range_max, m_job_progress_scale.
00032 
00033     m_job_done = true;
00034 
00035     m_update_resolution = 1.0 / 100.0;
00036     m_message.erase();
00037 
00038     m_progress = 0.0;
00039     m_done = false;
00040 
00041     m_last_update = -2.0;   // trigger the update callback
00042 }
00043 
00044 inline
00045 void ProgressMonitor::StartJob(Real range_min, Real range_max, Real duration /*= 1.0*/) {
00046     assert(m_job_done);
00047     assert(!m_done);
00048 
00049     assert(m_progress < 1.0);
00050     m_job_start = m_progress;
00051 
00052     assert(duration > 0.0);
00053     assert(m_job_start + duration <= 1.0);
00054     m_job_duration = duration;
00055 
00056     assert(range_min < range_max);
00057     m_job_range_min = range_min;
00058     m_job_range_max = range_max;
00059     m_job_progress_scale = m_job_duration / (m_job_range_max - m_job_range_min);
00060 
00061     m_job_done = false;
00062 
00063     post_update();
00064 }
00065 
00066 inline
00067 void ProgressMonitor::EndJob() {
00068     assert(!m_job_done);
00069 
00070     m_progress = m_job_start + m_job_duration;
00071     m_job_done = true;
00072 
00073     // Bypass the post_update() mechanism because we want to trigger
00074     // the update callback even if no progress have been made.
00075     UpdateCallback();
00076 }
00077 
00078 inline
00079 void ProgressMonitor::SetUpdateResolution(Real resolution) {
00080     assert(resolution <= 1.0);
00081 
00082     m_update_resolution = resolution;
00083 }
00084 
00085 inline
00086 void ProgressMonitor::SetMessage(const std::string &message) {
00087     m_message = message;
00088 
00089     // Bypass the post_update() mechanism because we want to trigger
00090     // the update callback even if no progress have been made.
00091     UpdateCallback();
00092 }
00093 
00094 inline
00095 const std::string &ProgressMonitor::GetMessage() const {
00096     return m_message;
00097 }
00098 
00099 inline
00100 void ProgressMonitor::SetJobProgress(Real progress) {
00101     assert(!m_job_done);
00102     assert(!m_done);
00103     assert(progress >= m_job_range_min);
00104     assert(progress <= m_job_range_max);
00105 
00106     m_progress = m_job_start +
00107         (progress - m_job_range_min) * m_job_progress_scale;
00108 
00109     post_update();
00110 }
00111 
00112 inline
00113 Real ProgressMonitor::GetProgress() const {
00114     return m_progress;
00115 }
00116 
00117 inline
00118 void ProgressMonitor::Done() {
00119     assert(!m_done);
00120 
00121     if(!m_job_done)
00122         EndJob();
00123 
00124     assert(m_job_done);
00125 
00126     m_progress = 1.0;
00127     m_done = true;
00128 
00129     // Bypass the post_update() mechanism because we want to trigger
00130     // the update callback even if no progress have been made.
00131     UpdateCallback();
00132 }
00133 
00134 inline
00135 bool ProgressMonitor::IsDone() const {
00136     return m_done;
00137 }
00138 
00139 inline
00140 void ProgressMonitor::post_update() {
00141     const Real elapsed = m_progress - m_last_update;
00142 
00143     assert(elapsed >= 0.0);
00144 
00145     if(elapsed >= m_update_resolution) {
00146         UpdateCallback();
00147 
00148         m_last_update = m_progress;
00149     }
00150 }

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