// MCADoc.cpp: CMCADoc 类的实现 // #include "pch.h" #include "framework.h" // SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的 // ATL 项目中进行定义,并允许与该项目共享文档代码。 #ifndef SHARED_HANDLERS #include "MCA.h" #endif #include "MCADoc.h" #include #include #include #include #include #ifdef _DEBUG #define new DEBUG_NEW #endif // CMCADoc IMPLEMENT_DYNCREATE(CMCADoc, CDocument) BEGIN_MESSAGE_MAP(CMCADoc, CDocument) END_MESSAGE_MAP() // CMCADoc 构造/析构 CMCADoc::CMCADoc() noexcept { FILE *stream_tmp; int channel_id, channel_count; srand((unsigned)time(NULL)); m_nChannelCount = new int[m_nChannelNum]; for (int i = 0; i < m_nChannelNum; i++) m_nChannelCount[i] = 0; 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]; } } CMCADoc::~CMCADoc() { } BOOL CMCADoc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; // TODO: 在此添加重新初始化代码 // (SDI 文档将重用该文档) return TRUE; } // CMCADoc 序列化 void CMCADoc::Serialize(CArchive& ar) { if (ar.IsStoring()) { // TODO: 在此添加存储代码 } else { // TODO: 在此添加加载代码 } } #ifdef SHARED_HANDLERS // 缩略图的支持 void CMCADoc::OnDrawThumbnail(CDC& dc, LPRECT lprcBounds) { // 修改此代码以绘制文档数据 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); } // 搜索处理程序的支持 void CMCADoc::InitializeSearchContent() { CString strSearchContent; // 从文档数据设置搜索内容。 // 内容部分应由“;”分隔 // 例如: strSearchContent = _T("point;rectangle;circle;ole object;"); SetSearchContent(strSearchContent); } void CMCADoc::SetSearchContent(const CString& value) { 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 // CMCADoc 诊断 #ifdef _DEBUG void CMCADoc::AssertValid() const { CDocument::AssertValid(); } void CMCADoc::Dump(CDumpContext& dc) const { CDocument::Dump(dc); } #endif //_DEBUG // CMCADoc 命令 double CMCADoc::uniform() { int x = rand(); double y = (float)(x % 100) / 100; return y; } void CMCADoc::random_peaks(std::string name) { int K; double 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; }