Filter Library | Camera | Interface Physics |
00001 /* 00002 * ProgressDlg.h - progress dialog for computational intensive operations. 00003 * 00004 * This file is part of the Camera Filter Library. 00005 * Computer Aided Measurement Environment for Realtime Atomic imaging (Camera) 00006 * 00007 * Copyright (C) 2005, Leiden Probe Microscopy. 00008 * Copyright (C) 2005, Universiteit Leiden. 00009 * 00010 * Author(s): 00011 * 00012 * $Id: ProgressDlg.h 347 2006-03-01 13:57:50Z moene $ 00013 */ 00014 00015 #ifndef CFL_PROGRESSDLG_H 00016 #define CFL_PROGRESSDLG_H 00017 00018 #if _MSC_VER > 1000 00019 #pragma once 00020 #endif // _MSC_VER > 1000 00021 00022 #include <afxmt.h> // for class CCriticalSection 00023 00024 /** 00025 * \addtogroup cfl_dialog 00026 * 00027 * @{ 00028 */ 00029 00030 /** 00031 * dialog to indicate progress of computational intensive operations, like 00032 * \ref cfl_filtercrosscorrelate "cross-correlation" in the spatial domain. 00033 * 00034 * The progress dialog is used to indicate the progress of computational intensive 00035 * operations and to enable the user to stop the computation prematurely. 00036 * See for example \ref cfl_filtercrosscorrelate "cross-correlation" in the 00037 * spatial domain. 00038 * 00039 * Class CProgressDlg is used as follows. 00040 * - the filter class creates a CProgressDlg object and saves information about itself in it; 00041 * the progress dialog sets-up a timer to update its progress bar 00042 * - the filter class creates a suspended worker thread to do the computation 00043 * - the filter class calls dlg.DoModal( hThread ) wich resumes the worker thread 00044 * - the worker thread sets the progress bar range and text variables 00045 * - the worker thread performs the computation and based on its progress, updates 00046 * the dialog's progress bar position variable 00047 * - the timer lets the progress dialog periodically update its text and progress 00048 * bar range and position 00049 * - finally the worker thread terminates the progress dialog by sending it a 00050 * WM_CLOSE message (see CProgressDlg::Terminate() ) 00051 * - WM_CLOSE activates the dialog's OnCancel() handler which stops the timer 00052 * used to update the progress bar 00053 * 00054 * The user may cancel the computation prematurely by pressing the Cancel-button 00055 * on the progress dialog or by pressing the Esc-key. 00056 * In this case the progress dialog's OnCancel() handler is called and the 00057 * following happens. 00058 * - OnCancel() sets a flag to signal the computation to stop (dlg->StopRequested()) 00059 * - OnCancel() waits for the worker thread to finish, unless it has not been 00060 * resumed before 00061 * - OnCancel() stops the timer used to update the dialog's progress bar 00062 * - the worker thread calls CProgressDlg::Terminate() but in the case it may not 00063 * and does not generate a WM_CLOSE message, because the dialog is closing 00064 * already ( CProgressDlg::IsCanceling() ) 00065 * 00066 * <b>Note 1</b>: handling of the Esc-key press was not implemented in the original version.\n 00067 * <b>Note 2</b>: waiting for the worker thread was not implemented in the original version. 00068 * 00069 * Class CProgressDlg uses a critical section (CCriticalSection) to guard access 00070 * to the dialog text, and progress bar range and position from different threads. 00071 * 00072 * For more information, see the implementation of class CScanFilterCrossCorrelate. 00073 */ 00074 class CProgressDlg : public CDialog 00075 { 00076 public: 00077 /// 00078 /// \name Construction 00079 /// @{ 00080 00081 /** 00082 * (default) constructor. 00083 */ 00084 CProgressDlg( CWnd* pParent = NULL ); 00085 00086 /** 00087 * destructor. 00088 */ 00089 ~CProgressDlg(); 00090 00091 /// @} 00092 /// \name Predicates 00093 /// @{ 00094 00095 /** 00096 * the thread has informed us that it has been resumed. 00097 */ 00098 BOOL IsResumed(); 00099 00100 /** 00101 * Cancel-button or Escape-key pressed (window close message). 00102 */ 00103 BOOL IsCanceling(); 00104 00105 /** 00106 * Cancel-button or Esc-key pressed; alias for IsCanceling(). 00107 */ 00108 BOOL StopRequested(); 00109 00110 /// @} 00111 /// \name Mutators 00112 /// @{ 00113 00114 /** 00115 * set resumed flag. 00116 */ 00117 void SetResumed(); 00118 00119 /** 00120 * set progress bar range; Note just store, OnTimer updates dialog. 00121 */ 00122 void SetRange( int nLower, int nUpper ); 00123 00124 /** 00125 * set progress bar position; Note just store, OnTimer updates dialog. 00126 */ 00127 void SetPos( int nPos ); 00128 00129 /** 00130 * set progress dialog message text; Note just store, OnTimer updates dialog. 00131 */ 00132 void SetText( LPCTSTR lpcsText ); 00133 00134 /** 00135 * close the progress dialog window. 00136 */ 00137 void Terminate(); 00138 00139 /** 00140 * display dialog as a modal window. 00141 */ 00142 virtual int DoModal( CWinThread *pTread = NULL ); 00143 00144 /// @} 00145 00146 protected: 00147 /** 00148 * Dialog Data Exchange (DDX) / Dialog Data Validation (DDV) support. 00149 */ 00150 // ClassWizard generated virtual function overrides 00151 //{{AFX_VIRTUAL(CProgressDlg) 00152 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support 00153 //}}AFX_VIRTUAL 00154 00155 // Generated message map functions 00156 //{{AFX_MSG(CProgressDlg) 00157 virtual BOOL OnInitDialog(); ///< initialize the dialog 00158 afx_msg void OnCancel(); ///< handle cancel message (button) 00159 afx_msg void OnClose(); ///< handle close message (button, Esc) 00160 afx_msg void OnTimer( UINT nIDEvent ); ///< handle timer event 00161 //}}AFX_MSG 00162 DECLARE_MESSAGE_MAP() 00163 00164 /** 00165 * resume the given thread. 00166 */ 00167 BOOL ResumeComputationThread( CWinThread *pThread ); 00168 00169 protected: 00170 CWinThread* m_pThread; ///< the computation thread 00171 SECProgressCtrl m_wndProgress; ///< advanced progress bar from Rogue Wave Objective Toolkit 00172 volatile BOOL m_bInitialized; ///< dialog is initialized flag 00173 volatile BOOL m_bCancel; ///< Cancel-button or Esc-key pressed flag 00174 volatile BOOL m_bResumed; ///< computation thread has been resumed flag 00175 CString m_csMessage; ///< progress dialog message text 00176 volatile int m_nLowerPosition; ///< progress bar lower position 00177 volatile int m_nUpperPosition; ///< progress bar upper position 00178 volatile int m_nCurrentPosition; ///< progress bar current position 00179 00180 private: 00181 //{{AFX_DATA(CProgressDlg) 00182 enum { IDD = IDD_PROGRESSDLG }; 00183 //}}AFX_DATA 00184 00185 /** 00186 * our timer event. 00187 */ 00188 static const int c_nTimerIDEvent; 00189 00190 /** 00191 * critical section guard. 00192 */ 00193 CCriticalSection m_criticalSection; 00194 }; 00195 00196 //{{AFX_INSERT_LOCATION}} 00197 // Microsoft Visual C++ will insert additional declarations immediately before the previous line. 00198 00199 /// @} 00200 00201 #endif // #ifndef CFL_PROGRESSDLG_H 00202 00203 /* 00204 * end of file 00205 */