This repository has been archived on 2022-07-04. You can view files and clone it, but cannot push or open issues or pull requests.
Multichannel-Analyzer/MCA/ControlView.cpp

227 lines
5.3 KiB
C++
Raw Normal View History

2022-03-20 15:14:44 +08:00
// ControlView.cpp: 实现文件
//
#include <chrono>
2022-03-20 15:14:44 +08:00
#include "pch.h"
#include "math.h"
#include "MCA.h"
#include "MCADoc.h"
#include "MainFrm.h"
#include "ControlView.h"
// CControlView
IMPLEMENT_DYNCREATE(CControlView, CFormView)
CControlView::CControlView()
: CFormView(IDD_DIALOG_CONTROL)
, m_nCond(100)
, m_nT0(0)
, m_nTime(0)
, m_nTimeStr((CString)'0')
, m_nTotalCount(0)
, m_nPartCount(0)
, m_nMaxCount(0)
, m_nRange(4)
, m_nCursor1(0)
, m_nCursor2(1023)
, m_nCursorROI(0)
, m_nCursorROICount(0)
2022-03-20 15:14:44 +08:00
{
}
CControlView::~CControlView()
{
}
void CControlView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
DDX_Text(pDX, IDC_COND, m_nCond);
DDX_Text(pDX, IDC_TIME, m_nTimeStr);
DDX_Text(pDX, IDC_TCOUNT, m_nTotalCount);
DDX_Text(pDX, IDC_PCOUNT, m_nPartCount);
DDX_Text(pDX, IDC_MCOUNT, m_nMaxCount);
DDX_Control(pDX, IDC_MODE, m_ComboMode);
DDX_Control(pDX, IDC_AXIS, m_ComboAxis);
DDX_Text(pDX, IDC_RANGE, m_nRange);
DDX_Text(pDX, IDC_CURSOR1, m_nCursor1);
DDX_Text(pDX, IDC_CURSOR2, m_nCursor2);
DDX_Text(pDX, IDC_CURSORROI, m_nCursorROI);
DDX_Text(pDX, IDC_CURSORROI_COUNT, m_nCursorROICount);
2022-03-20 15:14:44 +08:00
}
BEGIN_MESSAGE_MAP(CControlView, CFormView)
ON_WM_SIZE()
ON_COMMAND(ID_STA_START, &CControlView::OnStaStart)
ON_COMMAND(ID_STA_STOP, &CControlView::OnStaStop)
ON_UPDATE_COMMAND_UI(ID_STA_START, &CControlView::OnUpdateStaStart)
ON_UPDATE_COMMAND_UI(ID_STA_STOP, &CControlView::OnUpdateStaStop)
ON_COMMAND(ID_STA_CLEAR, &CControlView::OnStaClear)
ON_UPDATE_COMMAND_UI(ID_STA_CLEAR, &CControlView::OnUpdateStaClear)
ON_WM_TIMER()
ON_COMMAND(ID_SIMU_CO, &CControlView::OnSimuCo)
ON_COMMAND(ID_SIMU_CS, &CControlView::OnSimuCs)
ON_COMMAND(ID_SIMU_NA, &CControlView::OnSimuNa)
2022-03-20 15:14:44 +08:00
END_MESSAGE_MAP()
// CControlView 诊断
#ifdef _DEBUG
void CControlView::AssertValid() const
{
CFormView::AssertValid();
}
#ifndef _WIN32_WCE
void CControlView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif
#endif //_DEBUG
// CControlView 消息处理程序
void CControlView::OnSize(UINT nType, int cx, int cy)
{
CFormView::OnSize(nType, cx, cy);
CRect rect;
GetClientRect(&rect); // 获取当前客户区view大小
CSize size;
size.cx = rect.right - rect.left;
size.cy = rect.bottom - rect.top;
SetScrollSizes(MM_HIMETRIC, size); // 将CScrollView的大小设置为当前客户区大小
}
void CControlView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
// 添加运行模式
m_ComboMode.AddString((CString)"时间");
m_ComboMode.AddString((CString)"计数");
m_ComboMode.SetCurSel(0);
// 添加坐标轴模式
m_ComboAxis.AddString((CString)"线性");
m_ComboAxis.AddString((CString)"对数");
m_ComboAxis.SetCurSel(0);
m_Menu.LoadMenuW(IDR_MAINFRAME);
m_wndToolBar.LoadToolBar(IDR_MAINFRAME);
SetMenu(&m_Menu);
}
void CControlView::OnUpdate(CView* /*pSender*/, LPARAM /*lHint*/, CObject* /*pHint*/)
{
}
double CControlView::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 CControlView::OnStaStart()
{
// 重置结束条件
m_nT0 = GetMilliTime();
// 设置状态
startFlag = FALSE;
stopFlag = TRUE;
clearFlag = FALSE;
((CEdit*)GetDlgItem(IDC_COND))->EnableWindow(FALSE);
// 获取屏幕值至变量
UpdateData(TRUE);
// 设置更新
SetTimer(1, 100, NULL);
}
void CControlView::OnUpdateStaStart(CCmdUI* pCmdUI)
{
pCmdUI->Enable(startFlag);
}
void CControlView::OnStaStop()
{
// 设置状态
startFlag = TRUE;
stopFlag = FALSE;
clearFlag = TRUE;
((CEdit*)GetDlgItem(IDC_COND))->EnableWindow(TRUE);
// 停止更新
KillTimer(1);
}
void CControlView::OnUpdateStaStop(CCmdUI* pCmdUI)
{
pCmdUI->Enable(stopFlag);
}
void CControlView::OnStaClear()
{
CMCADoc* pDoc = (CMCADoc*)GetDocument();
// 重置
m_nTime = 0;
m_nMaxCount = 0;
m_nPartCount = 0;
m_nTotalCount = 0;
m_nTimeStr = (CString)"0.0";
// 获取屏幕值至变量
UpdateData(FALSE);
// 设置曲线
for (int i = 0; i < pDoc->m_nChannelNum; i++)
pDoc->m_nChannelCount[i] = 0;
pDoc->UpdateAllViews(NULL);
}
void CControlView::OnUpdateStaClear(CCmdUI* pCmdUI)
{
pCmdUI->Enable(clearFlag);
}
void CControlView::OnTimer(UINT_PTR nIDEvent)
{
CString tmp;
CMCADoc* pDoc = (CMCADoc*)GetDocument();
m_nTotalCount = pDoc->GetTotal(0, 1023);
m_nMaxCount = pDoc->GetMax(0, 1023);
m_nPartCount = pDoc->GetTotal(m_nCursor1, m_nCursor2);
m_nTime += GetMilliTime() - m_nT0;
m_nTimeStr.Format(_T("%.1f"), m_nTime);
m_nT0 = GetMilliTime();
m_ComboMode.GetWindowText(tmp);
if (tmp == "时间" && m_nTime >= m_nCond) OnStaStop();
if (tmp == "计数" && m_nTotalCount >= m_nCond) OnStaStop();
UpdateData(FALSE);
int n = rand() % 50 + 25;
((CMCADoc*)GetDocument())->RandomPeak(source, n);
((CMCADoc*)GetDocument())->UpdateAllViews(NULL);
CFormView::OnTimer(nIDEvent);
}
void CControlView::OnSimuCo()
{
source = (CString)"Co60";
}
void CControlView::OnSimuCs()
{
source = (CString)"Cs137";
}
void CControlView::OnSimuNa()
{
source = (CString)"Na22";
}