2022-03-19 20:43:29 +08:00
|
|
|
|
|
2022-03-19 21:04:48 +08:00
|
|
|
|
// MCADoc.cpp: CMCADoc 类的实现
|
2022-03-19 20:43:29 +08:00
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#include "pch.h"
|
|
|
|
|
#include "framework.h"
|
2022-05-30 16:36:01 +08:00
|
|
|
|
|
2022-03-19 20:43:29 +08:00
|
|
|
|
// SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的
|
|
|
|
|
// ATL 项目中进行定义,并允许与该项目共享文档代码。
|
|
|
|
|
#ifndef SHARED_HANDLERS
|
2022-03-19 21:04:48 +08:00
|
|
|
|
#include "MCA.h"
|
2022-03-19 20:43:29 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
2022-03-19 21:04:48 +08:00
|
|
|
|
#include "MCADoc.h"
|
2022-03-19 20:43:29 +08:00
|
|
|
|
|
2022-05-30 16:36:01 +08:00
|
|
|
|
#include <stdio.h>
|
2022-06-03 20:32:15 +08:00
|
|
|
|
#include <fstream>
|
2022-03-19 20:43:29 +08:00
|
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
#define new DEBUG_NEW
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-03-19 21:04:48 +08:00
|
|
|
|
// CMCADoc
|
2022-03-19 20:43:29 +08:00
|
|
|
|
|
2022-03-19 21:04:48 +08:00
|
|
|
|
IMPLEMENT_DYNCREATE(CMCADoc, CDocument)
|
2022-03-19 20:43:29 +08:00
|
|
|
|
|
2022-03-19 21:04:48 +08:00
|
|
|
|
BEGIN_MESSAGE_MAP(CMCADoc, CDocument)
|
2022-03-19 20:43:29 +08:00
|
|
|
|
END_MESSAGE_MAP()
|
|
|
|
|
|
|
|
|
|
|
2022-03-19 21:04:48 +08:00
|
|
|
|
// CMCADoc 构造/析构
|
2022-06-03 13:36:34 +08:00
|
|
|
|
CMCADoc::CMCADoc() noexcept {
|
2022-05-30 16:36:01 +08:00
|
|
|
|
FILE *stream_tmp;
|
|
|
|
|
int channel_id, channel_count;
|
|
|
|
|
|
2022-05-31 22:21:20 +08:00
|
|
|
|
srand((unsigned)time(0));
|
2022-05-30 16:36:01 +08:00
|
|
|
|
|
2022-06-02 10:08:38 +08:00
|
|
|
|
for (int i = 0; i < 1024; i++) m_nChannelCount[i] = 0;
|
|
|
|
|
for (int i = 0; i < 1024; i++) m_nChannelSmooth[i] = 0;
|
2022-05-30 16:36:01 +08:00
|
|
|
|
|
2022-06-03 20:32:15 +08:00
|
|
|
|
std::ifstream probeFile("data/Co60.txt");
|
|
|
|
|
if (!probeFile.good()) {
|
|
|
|
|
AfxMessageBox((CString)"未搜索到数据文件!");
|
|
|
|
|
throw "FileNotFoundError";
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-30 16:36:01 +08:00
|
|
|
|
freopen_s(&stream_tmp, "data/Co60.txt", "r", stdin);
|
|
|
|
|
for (int i = 0; i < 1024; i++)
|
|
|
|
|
{
|
|
|
|
|
scanf_s("%d,%d", &channel_id, &channel_count);
|
|
|
|
|
es_Co60[i] = channel_count;
|
|
|
|
|
if (i > 0) es_Co60[i] += es_Co60[i-1];
|
|
|
|
|
}
|
|
|
|
|
fclose(stdin);
|
|
|
|
|
freopen_s(&stream_tmp, "data/Cs137.txt", "r", stdin);
|
|
|
|
|
for (int i = 0; i < 1024; i++)
|
|
|
|
|
{
|
|
|
|
|
scanf_s("%d,%d", &channel_id, &channel_count);
|
|
|
|
|
es_Cs137[i] = channel_count;
|
|
|
|
|
if (i > 0) es_Cs137[i] += es_Cs137[i-1];
|
|
|
|
|
}
|
|
|
|
|
fclose(stdin);
|
|
|
|
|
freopen_s(&stream_tmp, "data/Na22.txt", "r", stdin);
|
|
|
|
|
for (int i = 0; i < 1024; i++)
|
|
|
|
|
{
|
|
|
|
|
scanf_s("%d,%d", &channel_id, &channel_count);
|
|
|
|
|
es_Na22[i] = channel_count;
|
|
|
|
|
if (i > 0) es_Na22[i] += es_Na22[i-1];
|
|
|
|
|
}
|
|
|
|
|
fclose(stdin);
|
|
|
|
|
for (int i = 0; i < 1024; i++)
|
|
|
|
|
{
|
|
|
|
|
es_Co60[i] /= es_Co60[1023];
|
|
|
|
|
es_Cs137[i] /= es_Cs137[1023];
|
|
|
|
|
es_Na22[i] /= es_Na22[1023];
|
|
|
|
|
}
|
2022-03-19 20:43:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-03 13:36:34 +08:00
|
|
|
|
CMCADoc::~CMCADoc() {
|
2022-03-19 20:43:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-03 13:36:34 +08:00
|
|
|
|
BOOL CMCADoc::OnNewDocument() {
|
2022-03-19 20:43:29 +08:00
|
|
|
|
if (!CDocument::OnNewDocument())
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
// TODO: 在此添加重新初始化代码
|
|
|
|
|
// (SDI 文档将重用该文档)
|
2022-05-31 22:21:20 +08:00
|
|
|
|
SetTitle(TEXT("MultiChannel Analyzer"));
|
2022-03-19 20:43:29 +08:00
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-19 21:04:48 +08:00
|
|
|
|
// CMCADoc 序列化
|
2022-06-03 13:36:34 +08:00
|
|
|
|
void CMCADoc::Serialize(CArchive& ar) {
|
2022-03-19 20:43:29 +08:00
|
|
|
|
if (ar.IsStoring())
|
|
|
|
|
{
|
|
|
|
|
// TODO: 在此添加存储代码
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// TODO: 在此添加加载代码
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef SHARED_HANDLERS
|
|
|
|
|
// 缩略图的支持
|
2022-06-03 13:36:34 +08:00
|
|
|
|
void CMCADoc::OnDrawThumbnail(CDC& dc, LPRECT lprcBounds) {
|
2022-03-19 20:43:29 +08:00
|
|
|
|
// 修改此代码以绘制文档数据
|
|
|
|
|
dc.FillSolidRect(lprcBounds, RGB(255, 255, 255));
|
|
|
|
|
|
|
|
|
|
CString strText = _T("TODO: implement thumbnail drawing here");
|
|
|
|
|
LOGFONT lf;
|
|
|
|
|
|
|
|
|
|
CFont* pDefaultGUIFont = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT));
|
|
|
|
|
pDefaultGUIFont->GetLogFont(&lf);
|
|
|
|
|
lf.lfHeight = 36;
|
|
|
|
|
|
|
|
|
|
CFont fontDraw;
|
|
|
|
|
fontDraw.CreateFontIndirect(&lf);
|
|
|
|
|
|
|
|
|
|
CFont* pOldFont = dc.SelectObject(&fontDraw);
|
|
|
|
|
dc.DrawText(strText, lprcBounds, DT_CENTER | DT_WORDBREAK);
|
|
|
|
|
dc.SelectObject(pOldFont);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 搜索处理程序的支持
|
2022-06-03 13:36:34 +08:00
|
|
|
|
void CMCADoc::InitializeSearchContent() {
|
2022-03-19 20:43:29 +08:00
|
|
|
|
CString strSearchContent;
|
|
|
|
|
// 从文档数据设置搜索内容。
|
|
|
|
|
// 内容部分应由“;”分隔
|
|
|
|
|
|
|
|
|
|
// 例如: strSearchContent = _T("point;rectangle;circle;ole object;");
|
|
|
|
|
SetSearchContent(strSearchContent);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-03 13:36:34 +08:00
|
|
|
|
void CMCADoc::SetSearchContent(const CString& value) {
|
2022-03-19 20:43:29 +08:00
|
|
|
|
if (value.IsEmpty())
|
|
|
|
|
{
|
|
|
|
|
RemoveChunk(PKEY_Search_Contents.fmtid, PKEY_Search_Contents.pid);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CMFCFilterChunkValueImpl *pChunk = nullptr;
|
|
|
|
|
ATLTRY(pChunk = new CMFCFilterChunkValueImpl);
|
|
|
|
|
if (pChunk != nullptr)
|
|
|
|
|
{
|
|
|
|
|
pChunk->SetTextValue(PKEY_Search_Contents, value, CHUNK_TEXT);
|
|
|
|
|
SetChunkValue(pChunk);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif // SHARED_HANDLERS
|
|
|
|
|
|
2022-03-19 21:04:48 +08:00
|
|
|
|
// CMCADoc 诊断
|
2022-03-19 20:43:29 +08:00
|
|
|
|
#ifdef _DEBUG
|
2022-06-03 13:36:34 +08:00
|
|
|
|
void CMCADoc::AssertValid() const {
|
2022-03-19 20:43:29 +08:00
|
|
|
|
CDocument::AssertValid();
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-03 13:36:34 +08:00
|
|
|
|
void CMCADoc::Dump(CDumpContext& dc) const {
|
2022-03-19 20:43:29 +08:00
|
|
|
|
CDocument::Dump(dc);
|
|
|
|
|
}
|
|
|
|
|
#endif //_DEBUG
|
|
|
|
|
|
2022-03-19 21:04:48 +08:00
|
|
|
|
// CMCADoc 命令
|
2022-06-03 13:36:34 +08:00
|
|
|
|
double CMCADoc::Uniform() {
|
2022-05-30 16:36:01 +08:00
|
|
|
|
int x = rand();
|
2022-05-31 22:21:20 +08:00
|
|
|
|
double y = (x % 10000) / 10000.0;
|
2022-05-30 16:36:01 +08:00
|
|
|
|
return y;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-03 13:36:34 +08:00
|
|
|
|
void CMCADoc::RandomPeak(CString name, int n) {
|
2022-05-31 22:21:20 +08:00
|
|
|
|
__int64 K;
|
|
|
|
|
double eps;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
|
eps = Uniform();
|
|
|
|
|
|
|
|
|
|
if (name == "Co60") K = std::lower_bound(es_Co60, es_Co60 + 1024, eps) - es_Co60;
|
|
|
|
|
else if (name == "Cs137") K = std::lower_bound(es_Cs137, es_Cs137 + 1024, eps) - es_Cs137;
|
|
|
|
|
else K = std::lower_bound(es_Na22, es_Na22 + 1024, eps) - es_Na22;
|
|
|
|
|
|
|
|
|
|
m_nChannelCount[K] += 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-03 13:36:34 +08:00
|
|
|
|
int CMCADoc::GetTotal(int L, int R) {
|
2022-05-31 22:21:20 +08:00
|
|
|
|
int cSum = 0;
|
2022-06-02 10:08:38 +08:00
|
|
|
|
for (int i = L; i <= min(1023, R); i++) cSum += m_nChannelCount[i];
|
2022-05-31 22:21:20 +08:00
|
|
|
|
return cSum;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-03 13:36:34 +08:00
|
|
|
|
int CMCADoc::GetMax(int L, int R) {
|
2022-05-31 22:21:20 +08:00
|
|
|
|
int cMax = 0;
|
2022-06-02 10:08:38 +08:00
|
|
|
|
for (int i = L; i <= min(1023, R); i++)
|
2022-05-31 22:21:20 +08:00
|
|
|
|
if (m_nChannelCount[i] > cMax)
|
|
|
|
|
cMax = m_nChannelCount[i];
|
|
|
|
|
return cMax;
|
|
|
|
|
}
|
2022-05-30 16:36:01 +08:00
|
|
|
|
|
2022-06-03 13:36:34 +08:00
|
|
|
|
CView* CMCADoc::GetView(CRuntimeClass* pClass) {
|
2022-05-31 22:21:20 +08:00
|
|
|
|
CView* pView{};
|
|
|
|
|
POSITION pos = GetFirstViewPosition();
|
2022-06-02 18:01:18 +08:00
|
|
|
|
while (pos != NULL) {
|
2022-05-31 22:21:20 +08:00
|
|
|
|
pView = GetNextView(pos);
|
|
|
|
|
if (pView->IsKindOf(pClass)) break;
|
|
|
|
|
}
|
|
|
|
|
if (!pView->IsKindOf(pClass)) {
|
|
|
|
|
AfxMessageBox((CString)"Cannot Locate the View!");
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
return pView;
|
|
|
|
|
}
|