@ -65,8 +65,7 @@ BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_UPDATE_COMMAND_UI ( ID_DATA_5 , & CMainFrame : : OnUpdateData5 )
END_MESSAGE_MAP ( )
static UINT indicators [ ] =
{
static UINT indicators [ ] = {
ID_SEPARATOR , // 状态行指示器
ID_INDICATOR_CAPS ,
ID_INDICATOR_NUM ,
@ -75,17 +74,14 @@ static UINT indicators[] =
// CMainFrame 构造/析构
CMainFrame : : CMainFrame ( ) noexcept
{
CMainFrame : : CMainFrame ( ) noexcept {
// TODO: 在此添加成员初始化代码
}
CMainFrame : : ~ CMainFrame ( )
{
CMainFrame : : ~ CMainFrame ( ) {
}
int CMainFrame : : OnCreate ( LPCREATESTRUCT lpCreateStruct )
{
int CMainFrame : : OnCreate ( LPCREATESTRUCT lpCreateStruct ) {
if ( CFrameWnd : : OnCreate ( lpCreateStruct ) = = - 1 )
return - 1 ;
@ -116,8 +112,7 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
}
BOOL CMainFrame : : OnCreateClient ( LPCREATESTRUCT /*lpcs*/ ,
CCreateContext * pContext )
{
CCreateContext * pContext ) {
// 左右拆分窗口, 1行2列
VERIFY ( m_wndSplitter . CreateStatic ( this , 1 , 2 ,
WS_CHILD | WS_VISIBLE , AFX_IDW_PANE_FIRST ) ) ;
@ -137,8 +132,7 @@ BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/,
return TRUE ;
}
BOOL CMainFrame : : PreCreateWindow ( CREATESTRUCT & cs )
{
BOOL CMainFrame : : PreCreateWindow ( CREATESTRUCT & cs ) {
if ( ! CFrameWnd : : PreCreateWindow ( cs ) )
return FALSE ;
cs . style & = ~ WS_THICKFRAME ;
@ -146,8 +140,7 @@ BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
return TRUE ;
}
void CMainFrame : : OnLoadToolBarIcon ( )
{
void CMainFrame : : OnLoadToolBarIcon ( ) {
HICON icon ;
m_imgList . Create ( 50 , 50 , TRUE | ILC_COLOR32 , 10 , 0 ) ;
@ -176,35 +169,30 @@ void CMainFrame::OnLoadToolBarIcon()
// CMainFrame 诊断
# ifdef _DEBUG
void CMainFrame : : AssertValid ( ) const
{
void CMainFrame : : AssertValid ( ) const {
CFrameWnd : : AssertValid ( ) ;
}
void CMainFrame : : Dump ( CDumpContext & dc ) const
{
void CMainFrame : : Dump ( CDumpContext & dc ) const {
CFrameWnd : : Dump ( dc ) ;
}
# endif //_DEBUG
int CMainFrame : : RoundupPowerof2 ( int val )
{
int RoundupPowerof2 ( int val ) {
if ( ( val & ( val - 1 ) ) = = 0 ) return val ;
int andv = 1 < < 30 ;
while ( ( andv & val ) = = 0 ) andv = andv > > 1 ;
return andv < < 1 ;
}
double CMainFrame : : GetMilliTime ( )
{
double GetMilliTime ( ) {
std : : chrono : : milliseconds ms = std : : chrono : : duration_cast < std : : chrono : : milliseconds > (
std : : chrono : : system_clock : : now ( ) . time_since_epoch ( )
) ;
return ms . count ( ) / 1000. ;
}
void CMainFrame : : UpdateValue ( )
{
void CMainFrame : : UpdateValue ( ) {
if ( pDoc = = nullptr ) pDoc = ( CMCADoc * ) GetActiveDocument ( ) ;
if ( pView = = nullptr ) pView = ( CControlView * ) pDoc - > GetView ( RUNTIME_CLASS ( CControlView ) ) ;
@ -230,14 +218,12 @@ void CMainFrame::UpdateValue()
pView - > UpdateData ( FALSE ) ;
}
void CMainFrame : : SaveFirst ( )
{
void CMainFrame : : SaveFirst ( ) {
int res = MessageBox ( TEXT ( " 打开前是否保存? " ) , TEXT ( " 保存文件 " ) , MB_YESNO | MB_ICONQUESTION ) ;
if ( res = = IDYES ) OnOptSave ( ) ;
}
void CMainFrame : : SmoothThree ( )
{
void CMainFrame : : SmoothThree ( ) {
pDoc - > m_nChannelSmooth [ 0 ] = ( 5 * pDoc - > m_nChannelCount [ 0 ] + 2 * pDoc - > m_nChannelCount [ 1 ] - pDoc - > m_nChannelCount [ 2 ] ) / 6 ;
for ( int i = 1 ; i < 1023 ; i + + )
pDoc - > m_nChannelSmooth [ i ] = ( pDoc - > m_nChannelCount [ i - 1 ] + pDoc - > m_nChannelCount [ i ] + pDoc - > m_nChannelCount [ i + 1 ] ) / 3 ;
@ -245,8 +231,7 @@ void CMainFrame::SmoothThree()
for ( int i = 0 ; i < 1024 ; i + + ) pDoc - > m_nChannelSmooth [ i ] = max ( 0 , pDoc - > m_nChannelSmooth [ i ] ) ;
}
void CMainFrame : : SmoothFive ( )
{
void CMainFrame : : SmoothFive ( ) {
pDoc - > m_nChannelSmooth [ 0 ] = ( 3 * pDoc - > m_nChannelCount [ 0 ] + 2 * pDoc - > m_nChannelCount [ 1 ] + pDoc - > m_nChannelCount [ 2 ] - pDoc - > m_nChannelCount [ 4 ] ) / 5 ;
pDoc - > m_nChannelSmooth [ 1 ] = ( 4 * pDoc - > m_nChannelCount [ 0 ] + 3 * pDoc - > m_nChannelCount [ 1 ] + 2 * pDoc - > m_nChannelCount [ 2 ] + pDoc - > m_nChannelCount [ 3 ] ) / 10 ;
for ( int i = 2 ; i < 1022 ; i + + )
@ -256,17 +241,46 @@ void CMainFrame::SmoothFive()
for ( int i = 0 ; i < 1024 ; i + + ) pDoc - > m_nChannelSmooth [ i ] = max ( 0 , pDoc - > m_nChannelSmooth [ i ] ) ;
}
void CMainFrame : : OnSimuCoOpt ( ) {
if ( pDoc = = nullptr ) pDoc = ( CMCADoc * ) GetActiveDocument ( ) ;
if ( pView = = nullptr ) pView = ( CControlView * ) pDoc - > GetView ( RUNTIME_CLASS ( CControlView ) ) ;
pView - > m_sSource = ( CString ) " Co60 " ;
pView - > m_ComboSource . SetCurSel ( 0 ) ;
m_bCoFlag = FALSE ;
m_bCsFlag = TRUE ;
m_bNaFlag = TRUE ;
}
void CMainFrame : : OnSimuCsOpt ( ) {
if ( pDoc = = nullptr ) pDoc = ( CMCADoc * ) GetActiveDocument ( ) ;
if ( pView = = nullptr ) pView = ( CControlView * ) pDoc - > GetView ( RUNTIME_CLASS ( CControlView ) ) ;
pView - > m_sSource = ( CString ) " Cs137 " ;
pView - > m_ComboSource . SetCurSel ( 1 ) ;
m_bCoFlag = TRUE ;
m_bCsFlag = FALSE ;
m_bNaFlag = TRUE ;
}
void CMainFrame : : OnSimuNaOpt ( ) {
if ( pDoc = = nullptr ) pDoc = ( CMCADoc * ) GetActiveDocument ( ) ;
if ( pView = = nullptr ) pView = ( CControlView * ) pDoc - > GetView ( RUNTIME_CLASS ( CControlView ) ) ;
pView - > m_sSource = ( CString ) " Na22 " ;
pView - > m_ComboSource . SetCurSel ( 2 ) ;
m_bCoFlag = TRUE ;
m_bCsFlag = TRUE ;
m_bNaFlag = FALSE ;
}
// CMainFrame 消息处理程序
void CMainFrame : : OnTimer ( UINT_PTR nIDEvent )
{
void CMainFrame : : OnTimer ( UINT_PTR nIDEvent ) {
if ( pDoc = = nullptr ) pDoc = ( CMCADoc * ) GetActiveDocument ( ) ;
if ( pView = = nullptr ) pView = ( CControlView * ) pDoc - > GetView ( RUNTIME_CLASS ( CControlView ) ) ;
pDoc - > SetModifiedFlag ( TRUE ) ;
// 判断终止
CString tmp ;
pView - > m_ComboMode . GetWindowText ( tmp ) ;
if ( ( tmp = = " 时间 " & & pView - > m_nTime > = pView - > m_nCond ) | | ( tmp = = " 计数 " & & pView - > m_nTotalCount > = pView - > m_nCond ) )
if ( ( pView - > m_sMode = = " Time " & & pView - > m_nTime > = pView - > m_nCond ) | | ( pView - > m_sMode = = " Count " & & pView - > m_nTotalCount > = pView - > m_nCond ) )
OnStaStop ( ) ;
else {
// 生成随机信号
@ -277,17 +291,11 @@ void CMainFrame::OnTimer(UINT_PTR nIDEvent)
UpdateValue ( ) ;
}
// 修改坐标轴
pView - > m_ComboAxis . GetWindowText ( tmp ) ;
if ( tmp = = " 对数 " ) OnAxisLog ( ) ;
else OnAxisLinear ( ) ;
pDoc - > UpdateAllViews ( NULL ) ;
CFrameWnd : : OnTimer ( nIDEvent ) ;
}
void CMainFrame : : OnClose ( )
{
void CMainFrame : : OnClose ( ) {
if ( pDoc = = nullptr ) pDoc = ( CMCADoc * ) GetActiveDocument ( ) ;
if ( pDoc - > IsModified ( ) ) {
int res = MessageBox ( TEXT ( " 退出前是否保存? " ) , TEXT ( " 保存文件 " ) , MB_YESNO | MB_ICONQUESTION ) ;
@ -297,8 +305,7 @@ void CMainFrame::OnClose()
CFrameWnd : : OnClose ( ) ;
}
BOOL CMainFrame : : PreTranslateMessage ( MSG * pMsg )
{
BOOL CMainFrame : : PreTranslateMessage ( MSG * pMsg ) {
if ( pDoc = = nullptr ) pDoc = ( CMCADoc * ) GetActiveDocument ( ) ;
if ( pView = = nullptr ) pView = ( CControlView * ) pDoc - > GetView ( RUNTIME_CLASS ( CControlView ) ) ;
if ( pMsg - > message = = WM_KEYDOWN & & pMsg - > wParam > = 0x25 & & pMsg - > wParam < = 0x28 ) {
@ -315,8 +322,7 @@ BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
return CFrameWnd : : PreTranslateMessage ( pMsg ) ;
}
void CMainFrame : : OnOptOpen ( )
{
void CMainFrame : : OnOptOpen ( ) {
if ( pDoc = = nullptr ) pDoc = ( CMCADoc * ) GetActiveDocument ( ) ;
if ( pView = = nullptr ) pView = ( CControlView * ) pDoc - > GetView ( RUNTIME_CLASS ( CControlView ) ) ;
@ -371,8 +377,7 @@ void CMainFrame::OnOptOpen()
}
}
void CMainFrame : : OnOptSave ( )
{
void CMainFrame : : OnOptSave ( ) {
if ( pDoc = = nullptr ) pDoc = ( CMCADoc * ) GetActiveDocument ( ) ;
if ( pView = = nullptr ) pView = ( CControlView * ) pDoc - > GetView ( RUNTIME_CLASS ( CControlView ) ) ;
@ -383,8 +388,9 @@ void CMainFrame::OnOptSave()
CString szfile = fileDlg . GetPathName ( ) ;
std : : ofstream ofs ( szfile ) ;
std : : string str = CStringA ( pView - > m_sSource ) ;
ofs < < pView - > m_nTime < < std : : endl ;
ofs < < pView- > m_sSource < < std : : endl ;
ofs < < str. c_str ( ) < < std : : endl ;
for ( int i = 0 ; i < 1024 ; i + + )
ofs < < i < < " , " < < pDoc - > m_nChannelCount [ i ] < < std : : endl ;
@ -393,8 +399,7 @@ void CMainFrame::OnOptSave()
pDoc - > SetModifiedFlag ( FALSE ) ;
}
void CMainFrame : : OnStaStart ( )
{
void CMainFrame : : OnStaStart ( ) {
if ( pDoc = = nullptr ) pDoc = ( CMCADoc * ) GetActiveDocument ( ) ;
if ( pView = = nullptr ) pView = ( CControlView * ) pDoc - > GetView ( RUNTIME_CLASS ( CControlView ) ) ;
@ -411,13 +416,11 @@ void CMainFrame::OnStaStart()
SetTimer ( 1 , 20 , NULL ) ;
}
void CMainFrame : : OnUpdateStaStart ( CCmdUI * pCmdUI )
{
void CMainFrame : : OnUpdateStaStart ( CCmdUI * pCmdUI ) {
pCmdUI - > Enable ( m_bStartFlag ) ;
}
void CMainFrame : : OnStaStop ( )
{
void CMainFrame : : OnStaStop ( ) {
// 设置状态
m_bStartFlag = TRUE ;
m_bStopFlag = FALSE ;
@ -427,13 +430,11 @@ void CMainFrame::OnStaStop()
KillTimer ( 1 ) ;
}
void CMainFrame : : OnUpdateStaStop ( CCmdUI * pCmdUI )
{
void CMainFrame : : OnUpdateStaStop ( CCmdUI * pCmdUI ) {
pCmdUI - > Enable ( m_bStopFlag ) ;
}
void CMainFrame : : OnStaClear ( )
{
void CMainFrame : : OnStaClear ( ) {
if ( pDoc = = nullptr ) pDoc = ( CMCADoc * ) GetActiveDocument ( ) ;
if ( pView = = nullptr ) pView = ( CControlView * ) pDoc - > GetView ( RUNTIME_CLASS ( CControlView ) ) ;
@ -454,99 +455,77 @@ void CMainFrame::OnStaClear()
pDoc - > SetModifiedFlag ( FALSE ) ;
}
void CMainFrame : : OnUpdateStaClear ( CCmdUI * pCmdUI )
{
void CMainFrame : : OnUpdateStaClear ( CCmdUI * pCmdUI ) {
pCmdUI - > Enable ( m_bClearFlag ) ;
}
void CMainFrame : : OnSimuCo ( )
{
void CMainFrame : : OnSimuCo ( ) {
if ( pDoc = = nullptr ) pDoc = ( CMCADoc * ) GetActiveDocument ( ) ;
if ( pView = = nullptr ) pView = ( CControlView * ) pDoc - > GetView ( RUNTIME_CLASS ( CControlView ) ) ;
pView - > m_sSource = ( CString ) " Co60 " ;
m_bCoFlag = FALSE ;
m_bCsFlag = TRUE ;
m_bNaFlag = TRUE ;
OnSimuCoOpt ( ) ;
OnStaStop ( ) ;
OnStaClear ( ) ;
}
void CMainFrame : : OnUpdateSimuCo ( CCmdUI * pCmdUI )
{
void CMainFrame : : OnUpdateSimuCo ( CCmdUI * pCmdUI ) {
pCmdUI - > Enable ( m_bCoFlag ) ;
}
void CMainFrame : : OnSimuCs ( )
{
void CMainFrame : : OnSimuCs ( ) {
if ( pDoc = = nullptr ) pDoc = ( CMCADoc * ) GetActiveDocument ( ) ;
if ( pView = = nullptr ) pView = ( CControlView * ) pDoc - > GetView ( RUNTIME_CLASS ( CControlView ) ) ;
pView - > m_sSource = ( CString ) " Cs137 " ;
m_bCoFlag = TRUE ;
m_bCsFlag = FALSE ;
m_bNaFlag = TRUE ;
OnSimuCoOpt ( ) ;
OnStaStop ( ) ;
OnStaClear ( ) ;
}
void CMainFrame : : OnUpdateSimuCs ( CCmdUI * pCmdUI )
{
void CMainFrame : : OnUpdateSimuCs ( CCmdUI * pCmdUI ) {
pCmdUI - > Enable ( m_bCsFlag ) ;
}
void CMainFrame : : OnSimuNa ( )
{
void CMainFrame : : OnSimuNa ( ) {
if ( pDoc = = nullptr ) pDoc = ( CMCADoc * ) GetActiveDocument ( ) ;
if ( pView = = nullptr ) pView = ( CControlView * ) pDoc - > GetView ( RUNTIME_CLASS ( CControlView ) ) ;
pView - > m_sSource = ( CString ) " Na22 " ;
m_bCoFlag = TRUE ;
m_bCsFlag = TRUE ;
m_bNaFlag = FALSE ;
OnSimuCoOpt ( ) ;
OnStaStop ( ) ;
OnStaClear ( ) ;
}
void CMainFrame : : OnUpdateSimuNa ( CCmdUI * pCmdUI )
{
void CMainFrame : : OnUpdateSimuNa ( CCmdUI * pCmdUI ) {
pCmdUI - > Enable ( m_bNaFlag ) ;
}
void CMainFrame : : OnAxisLinear ( )
{
void CMainFrame : : OnAxisLinear ( ) {
if ( pDoc = = nullptr ) pDoc = ( CMCADoc * ) GetActiveDocument ( ) ;
if ( pView = = nullptr ) pView = ( CControlView * ) pDoc - > GetView ( RUNTIME_CLASS ( CControlView ) ) ;
pView - > m_sAxisMode = ( CString ) " Linear " ;
pView - > m_ComboAxis . SetCurSel ( 0 ) ;
m_bLinearFlag = FALSE ;
m_bLogFlag = TRUE ;
}
void CMainFrame : : OnUpdateAxisLinear ( CCmdUI * pCmdUI )
{
void CMainFrame : : OnUpdateAxisLinear ( CCmdUI * pCmdUI ) {
pCmdUI - > Enable ( m_bLinearFlag ) ;
}
void CMainFrame : : OnAxisLog ( )
{
void CMainFrame : : OnAxisLog ( ) {
if ( pDoc = = nullptr ) pDoc = ( CMCADoc * ) GetActiveDocument ( ) ;
if ( pView = = nullptr ) pView = ( CControlView * ) pDoc - > GetView ( RUNTIME_CLASS ( CControlView ) ) ;
pView - > m_sAxisMode = ( CString ) " Log " ;
pView - > m_sRangeMode = " Auto " ;
pView - > m_ComboAxis . SetCurSel ( 1 ) ;
m_bAutoFlag = FALSE ;
m_bLinearFlag = TRUE ;
m_bLogFlag = FALSE ;
}
void CMainFrame : : OnUpdateAxisLog ( CCmdUI * pCmdUI )
{
void CMainFrame : : OnUpdateAxisLog ( CCmdUI * pCmdUI ) {
pCmdUI - > Enable ( m_bLogFlag ) ;
}
void CMainFrame : : OnRangeAuto ( )
{
void CMainFrame : : OnRangeAuto ( ) {
if ( pDoc = = nullptr ) pDoc = ( CMCADoc * ) GetActiveDocument ( ) ;
if ( pView = = nullptr ) pView = ( CControlView * ) pDoc - > GetView ( RUNTIME_CLASS ( CControlView ) ) ;
@ -556,13 +535,11 @@ void CMainFrame::OnRangeAuto()
pDoc - > UpdateAllViews ( NULL ) ;
}
void CMainFrame : : OnUpdateRangeAuto ( CCmdUI * pCmdUI )
{
void CMainFrame : : OnUpdateRangeAuto ( CCmdUI * pCmdUI ) {
pCmdUI - > Enable ( m_bAutoFlag ) ;
}
void CMainFrame : : OnRangeD4 ( )
{
void CMainFrame : : OnRangeD4 ( ) {
if ( pDoc = = nullptr ) pDoc = ( CMCADoc * ) GetActiveDocument ( ) ;
if ( pView = = nullptr ) pView = ( CControlView * ) pDoc - > GetView ( RUNTIME_CLASS ( CControlView ) ) ;
@ -573,8 +550,7 @@ void CMainFrame::OnRangeD4()
pDoc - > UpdateAllViews ( NULL ) ;
}
void CMainFrame : : OnRangeD2 ( )
{
void CMainFrame : : OnRangeD2 ( ) {
if ( pDoc = = nullptr ) pDoc = ( CMCADoc * ) GetActiveDocument ( ) ;
if ( pView = = nullptr ) pView = ( CControlView * ) pDoc - > GetView ( RUNTIME_CLASS ( CControlView ) ) ;
@ -585,8 +561,7 @@ void CMainFrame::OnRangeD2()
pDoc - > UpdateAllViews ( NULL ) ;
}
void CMainFrame : : OnRangeM2 ( )
{
void CMainFrame : : OnRangeM2 ( ) {
if ( pDoc = = nullptr ) pDoc = ( CMCADoc * ) GetActiveDocument ( ) ;
if ( pView = = nullptr ) pView = ( CControlView * ) pDoc - > GetView ( RUNTIME_CLASS ( CControlView ) ) ;
@ -597,8 +572,7 @@ void CMainFrame::OnRangeM2()
pDoc - > UpdateAllViews ( NULL ) ;
}
void CMainFrame : : OnRangeM4 ( )
{
void CMainFrame : : OnRangeM4 ( ) {
if ( pDoc = = nullptr ) pDoc = ( CMCADoc * ) GetActiveDocument ( ) ;
if ( pView = = nullptr ) pView = ( CControlView * ) pDoc - > GetView ( RUNTIME_CLASS ( CControlView ) ) ;
@ -609,8 +583,7 @@ void CMainFrame::OnRangeM4()
pDoc - > UpdateAllViews ( NULL ) ;
}
void CMainFrame : : OnDataOrigin ( )
{
void CMainFrame : : OnDataOrigin ( ) {
if ( pDoc = = nullptr ) pDoc = ( CMCADoc * ) GetActiveDocument ( ) ;
if ( pView = = nullptr ) pView = ( CControlView * ) pDoc - > GetView ( RUNTIME_CLASS ( CControlView ) ) ;
@ -622,13 +595,11 @@ void CMainFrame::OnDataOrigin()
pDoc - > UpdateAllViews ( NULL ) ;
}
void CMainFrame : : OnUpdateDataOrigin ( CCmdUI * pCmdUI )
{
void CMainFrame : : OnUpdateDataOrigin ( CCmdUI * pCmdUI ) {
pCmdUI - > Enable ( m_bOriginFlag ) ;
}
void CMainFrame : : OnData3 ( )
{
void CMainFrame : : OnData3 ( ) {
if ( pDoc = = nullptr ) pDoc = ( CMCADoc * ) GetActiveDocument ( ) ;
if ( pView = = nullptr ) pView = ( CControlView * ) pDoc - > GetView ( RUNTIME_CLASS ( CControlView ) ) ;
@ -640,13 +611,11 @@ void CMainFrame::OnData3()
pDoc - > UpdateAllViews ( NULL ) ;
}
void CMainFrame : : OnUpdateData3 ( CCmdUI * pCmdUI )
{
void CMainFrame : : OnUpdateData3 ( CCmdUI * pCmdUI ) {
pCmdUI - > Enable ( m_bTSmoothFlag ) ;
}
void CMainFrame : : OnData5 ( )
{
void CMainFrame : : OnData5 ( ) {
if ( pDoc = = nullptr ) pDoc = ( CMCADoc * ) GetActiveDocument ( ) ;
if ( pView = = nullptr ) pView = ( CControlView * ) pDoc - > GetView ( RUNTIME_CLASS ( CControlView ) ) ;
@ -658,13 +627,11 @@ void CMainFrame::OnData5()
pDoc - > UpdateAllViews ( NULL ) ;
}
void CMainFrame : : OnUpdateData5 ( CCmdUI * pCmdUI )
{
void CMainFrame : : OnUpdateData5 ( CCmdUI * pCmdUI ) {
pCmdUI - > Enable ( m_bFSmoothFlag ) ;
}
void CMainFrame : : OnDataPeak ( )
{
void CMainFrame : : OnDataPeak ( ) {
if ( pDoc = = nullptr ) pDoc = ( CMCADoc * ) GetActiveDocument ( ) ;
if ( pView = = nullptr ) pView = ( CControlView * ) pDoc - > GetView ( RUNTIME_CLASS ( CControlView ) ) ;