#pragma once #include "stdafx.h" #include "resource.h" #include "ReportProjFileMgr.h" #include "MeasureResultInfo.h" #include "BSEImgFileMgr.h" #include "PosXrayFileMgr.h" #include "PartSizeFileMgr.h" #include "TrioCal.h" #include "CGBCalculate.h" #include "GBFieldData.h" #include "OTSHelper.h" #include "OTSFileSys.h" #include "RptParamFileMgr.h" #include "GBImgPropCal.h" namespace OTSMODEL { using namespace std; // constructor CReportProjFileMgr::CReportProjFileMgr(CReportProjFilePtr a_pReportProjFile) { m_pReportProjFile = a_pReportProjFile; m_listPropParams.clear(); m_listSmplMgrs.clear(); m_bModify = FALSE; m_strPathName = _T(""); m_nWorkingSampeIndex = -1; m_nPartSizeIndex = -1; //load param file CRptParamFileMgr paramFleMgr; paramFleMgr.Load(OTSMODEL::OTS_SOFT_PACKAGE_ID::OTSIncA); m_rptparamfile = paramFleMgr.GetRptParamFile(); double dScale = m_rptparamfile->GetScale(); m_pReportProjFile->SetScale(dScale); } // destructor CReportProjFileMgr::~CReportProjFileMgr() { } CRptParamFilePtr CReportProjFileMgr::GetRptParamFilePtr() { return m_rptparamfile; } // class methods // public void CReportProjFileMgr::SetPropertyParams(CPropParamsList a_listPropertyParams) { m_listPropParams.clear(); m_listPropParams = a_listPropertyParams; } // property parameters CPropParamPtr CReportProjFileMgr::GetPropertyParamImage() { return m_listPropParams[(int)DISPLAY_PICTURE_TYPE::IMAGE]; } CPropParamPtr CReportProjFileMgr::GetPropertyParamGrid() { return m_listPropParams[(int)DISPLAY_PICTURE_TYPE::TABLE]; } CPropParamPtr CReportProjFileMgr::GetPropertyParamChart() { return m_listPropParams[(int)DISPLAY_PICTURE_TYPE::CHART]; } // reset property parameters BOOL CReportProjFileMgr::ResetPropertyParams(BOOL a_bClear /*= FALSE*/) { // clear property parameters list if (a_bClear) { m_listPropParams.clear(); } // get data source names list std::vector listDataSourceNames = GetDataSourceNamesList(); // data source names list can't be empty if (listDataSourceNames.empty()) { LogErrorTrace(__FILE__, __LINE__, _T("ResetPropertyParams: empty data source name list.")); return FALSE; } // particle STD data CPartSTDDataPtr pPartSTDData = m_pReportProjFile->GetPartSTDData(); ASSERT(pPartSTDData); if (!pPartSTDData) { LogErrorTrace(__FILE__, __LINE__, _T("ResetPropertyParams: STD data empty.")); return FALSE; } // trio chart mode // add property parameters into the list if (m_listPropParams.empty()) { //Image display picture's property CPropParamPtr pPropParam = CPropParamPtr(new CPropParamImage()); pPropParam->SetDataSourceList(listDataSourceNames); pPropParam->SetDataSourceId(m_nWorkingSampeIndex); pPropParam->SetWorkingSTDLib(pPartSTDData); pPropParam->SetSizeClassFileFolder(m_rptparamfile->GetSizeFileFolder()); if (*pPartSTDData.get() == CPartSTDData()) { pPropParam->SetSTDId(0); } pPropParam->SetType(DISPLAY_PICTURE_TYPE::IMAGE); m_listPropParams.push_back(pPropParam); //grid table display picture's property pPropParam = CPropParamPtr(new CPropParamGrid()); pPropParam->SetDataSourceList(listDataSourceNames); pPropParam->SetDataSourceId(m_nWorkingSampeIndex); pPropParam->SetWorkingSTDLib(pPartSTDData); pPropParam->SetSizeClassFileFolder(m_rptparamfile->GetSizeFileFolder()); if (*pPartSTDData.get() == CPartSTDData()) { pPropParam->SetSTDId(0); } pPropParam->SetType(DISPLAY_PICTURE_TYPE::TABLE); m_listPropParams.push_back(pPropParam); //chart display picture's property object pPropParam = CPropParamPtr(new CPropParamChart()); pPropParam->SetDataSourceList(listDataSourceNames); pPropParam->SetDataSourceId(m_nWorkingSampeIndex); pPropParam->SetWorkingSTDLib(pPartSTDData); pPropParam->SetSizeClassFileFolder(m_rptparamfile->GetSizeFileFolder()); pPropParam->SetTriTempFile(m_rptparamfile->GetTriTempFile()); if (*pPartSTDData.get() == CPartSTDData()) { pPropParam->SetSTDId(0); } pPropParam->SetType(DISPLAY_PICTURE_TYPE::CHART); m_listPropParams.push_back(pPropParam); } else { for (auto pPropParam : m_listPropParams) { pPropParam->SetDataSourceList(listDataSourceNames); pPropParam->SetDataSourceId(m_nWorkingSampeIndex); pPropParam->SetWorkingSTDLib(pPartSTDData); } } // ok, return TRUE return TRUE; } BOOL CReportProjFileMgr::NewFile() { // set file name SetPathName(UNTITLED_NEW_FILE_NAME); return TRUE; } // Load BOOL CReportProjFileMgr::Load(CString a_strPathname /*= _T("")*/) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); // check file name a_strPathname.Trim(); if (a_strPathname.IsEmpty()) { // open CFileDialog dlg(TRUE, REPORT_PROJRCT_FILE_EXT, NULL, OFN_FILEMUSTEXIST, REPORT_PROJRCT_FILE_FILTER); if (dlg.DoModal() != IDOK) { // user canceled loading LogTrace(__FILE__, __LINE__, _T("Load: user canceled loading.")); return FALSE; } a_strPathname = dlg.GetPathName(); } // open the file (for read) // create report project file file CReportProjFilePtr pReportProjFile = CReportProjFilePtr(new CReportProjFile()); // load from file tinyxml2::XMLDocument doc; doc.LoadFile(a_strPathname);//载入xml文件 tinyxml2::XMLElement *rootNode; rootNode = doc.FirstChildElement(RootClassName); pReportProjFile->Serialize(false, &doc, rootNode); SetPathName(a_strPathname); // file version CString strFileVersion = pReportProjFile->GetFileVersion(); DWORD nFileVersion = COTSHelper::GetVersionFromString(strFileVersion); if (nFileVersion == 0) { // invalid file LogErrorTrace(__FILE__, __LINE__, _T("Load: invalid sample measure result file %s"), a_strPathname); return FALSE; } // set report project file m_pReportProjFile = pReportProjFile; // load sample measure result files m_listSmplMgrs.clear(); std::vector listSmplMsrResultFilePathNames; for (auto strSmplMsrResultFilePathName : m_pReportProjFile->GetSmplMsrResultFilePathNames()) { if (strSmplMsrResultFilePathName.IsEmpty()) { // sample measure result file pathname can't be an empty string LogTrace(__FILE__, __LINE__, _T("Load: sample measure result file pathname can't be an empty string.")); SetModify(); continue; } // create a sample measure result manager CSmplMsrResultFileMgrPtr pSmplMsrResultFileMgr = CSmplMsrResultFileMgrPtr(new CSmplMsrResultFileMgr(strSmplMsrResultFilePathName)); if (!pSmplMsrResultFileMgr->Load(strSmplMsrResultFilePathName)) { // failed to load sample measure result file LogTrace(__FILE__, __LINE__, _T("Load: failed to load sample measure result file (%s)."), strSmplMsrResultFilePathName); SetModify(); continue; } // this file is ok listSmplMsrResultFilePathNames.push_back(strSmplMsrResultFilePathName); m_listSmplMgrs.push_back(pSmplMsrResultFileMgr); } m_pReportProjFile->SetSmplMsrResultFilePathNames(listSmplMsrResultFilePathNames); // set working sample if (m_listSmplMgrs.size() > 0) { m_nWorkingSampeIndex = 0; } else { m_nWorkingSampeIndex = -1; } ResetPropertyParams(); return TRUE; } // Save BOOL CReportProjFileMgr::Save() { AFX_MANAGE_STATE(AfxGetStaticModuleState()); // safety check ASSERT(m_pReportProjFile); if (!m_pReportProjFile) { // invalid report project file pointer LogErrorTrace(__FILE__, __LINE__, _T("Save: invalid report project file pointer.")); return FALSE; } // Save or Save As, if strPathName is not empty, it is exist in the computer, this is a save action CString strPathName = GetPathName(); // is this a new file? strPathName.Trim(); if (strPathName.CompareNoCase(UNTITLED_NEW_FILE_NAME) == 0) { // this is a new file // return save as result return SaveAs(); } // store data to file tinyxml2::XMLDocument doc; doc.LoadFile(strPathName);//载入xml文件 doc.Clear(); tinyxml2::XMLDeclaration* declaration = doc.NewDeclaration();//添加xml文件头申明 doc.InsertFirstChild(declaration); tinyxml2::XMLElement *rootNode; rootNode = doc.NewElement(RootClassName); doc.InsertEndChild(rootNode); m_pReportProjFile->Serialize(true, &doc, rootNode); int result = doc.SaveFile(strPathName); // set modify flag to FALSE SetModify(FALSE); // ok, return TRUE return TRUE; } BOOL CReportProjFileMgr::SaveAs() { AFX_MANAGE_STATE(AfxGetStaticModuleState()); // safety check ASSERT(m_pReportProjFile); if (!m_pReportProjFile) { // invalid report project file pointer LogErrorTrace(__FILE__, __LINE__, _T("SaveAs: invalid report project file pointer.")); return FALSE; } // save file dialog CString strFileName = _T(""); // file save as dialog CFileDialog dlg(FALSE, REPORT_PROJRCT_FILE_EXT, NULL, OFN_OVERWRITEPROMPT, REPORT_PROJRCT_FILE_FILTER); if (dlg.DoModal() != IDOK) { // user canceled loading LogTrace(__FILE__, __LINE__, _T("Save: user canceled save.")); return FALSE; } // get file pathname strFileName = dlg.GetPathName(); // Open the file // store to file tinyxml2::XMLDocument doc; doc.LoadFile(strFileName);//载入xml文件 doc.Clear(); tinyxml2::XMLDeclaration* declaration = doc.NewDeclaration();//添加xml文件头申明 doc.InsertFirstChild(declaration); tinyxml2::XMLElement *rootNode; rootNode = doc.NewElement(RootClassName); doc.InsertEndChild(rootNode); m_pReportProjFile->Serialize(true, &doc, rootNode); int result = doc.SaveFile(strFileName); // set file modify flag m_bModify = FALSE; // Set project Path SetPathName(strFileName); // Ok, return TRUE return TRUE; } BOOL CReportProjFileMgr::IsValid() { ASSERT(m_pReportProjFile); if (!m_pReportProjFile) { LogErrorTrace(__FILE__, __LINE__, _T("IsValid: not invalid report project file pointer.")); return FALSE; } // triangle template file CTriTempFilePtr pTriTemp = m_pReportProjFile->GetTriTemp(); // Ok, return TRUE return TRUE; } // particle STD data CPartSTDDataPtr CReportProjFileMgr::GetPartSTDData() { // check report project file pointer ASSERT(m_pReportProjFile); if (!m_pReportProjFile) { // invalid report project file pointer LogErrorTrace(__FILE__, __LINE__, _T("GetPartSTDData: invalid report project file pointer.")); return FALSE; } return m_pReportProjFile->GetPartSTDData(); } BOOL CReportProjFileMgr::SetPartSTDData(CPartSTDDataPtr a_pPartSTDData) { // input check ASSERT(a_pPartSTDData); if (!a_pPartSTDData) { // invalid particle STD data pointer LogErrorTrace(__FILE__, __LINE__, _T("SetPartSTDData: invalid particle STD data pointer.")); return FALSE; } // check report project file pointer ASSERT(m_pReportProjFile); if (!m_pReportProjFile) { // invalid report project file pointer LogErrorTrace(__FILE__, __LINE__, _T("SetPartSTDData: invalid report project file pointer.")); return FALSE; } // create a copy of the particle STD data //CPartSTDDataPtr pPartSTDData = CPartSTDDataPtr(new CPartSTDData(a_pPartSTDData.get())); CPartSTDDataPtr pPartSTDData = a_pPartSTDData; // set particle STD data m_pReportProjFile->SetPartSTDData(pPartSTDData); // ok, return TRUE return TRUE; } // sample measure result files BOOL CReportProjFileMgr::AddASmplMsrResultMgr(CString a_strPathName /*= _T("")*/) { /*int tmpFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); tmpFlag |= _CRTDBG_LEAK_CHECK_DF; _CrtSetDbgFlag(tmpFlag);*/ //_CrtSetBreakAlloc(351380); // check report project file pointer ASSERT(m_pReportProjFile); if (!m_pReportProjFile) { // invalid report project file pointer LogErrorTrace(__FILE__, __LINE__, _T("SetPartSTDData: invalid report project file pointer.")); return FALSE; } CSmplMsrResultFileMgrPtr pSmplMsrResultFileMgrPtr = CSmplMsrResultFileMgrPtr(new CSmplMsrResultFileMgr(a_strPathName)); // load sample result file if (!pSmplMsrResultFileMgrPtr->Load(a_strPathName)) { return FALSE; } //判断新打开的测量结果文件名,是否已经在打开的测量结果列表名中,是的话,不打开,防止同名 CString strSampleNameNew = pSmplMsrResultFileMgrPtr->GetSmplMsrResultFile()->GetSample()->GetName(); for (int i = 0; i < m_listSmplMgrs.size(); i++) { if (m_listSmplMgrs[i]->GetSmplMsrResultFile()->GetSample()->GetName() == strSampleNameNew) { LogErrorTrace(__FILE__, __LINE__, _T("AddASmplMsrResultMgr: The measurement result name is already included.")); return FALSE; } } // get the particle STD data of the sample result file CPartSTDDataPtr pPartSTDData = pSmplMsrResultFileMgrPtr->GetPartSTDData(); ASSERT(pPartSTDData); if (!pPartSTDData) { // sample result file particle STD data invalid LogErrorTrace(__FILE__, __LINE__, _T("AddASmplMsrResultMgr: sample result file particle STD data invalid.")); return FALSE; } // is the first sample result file in the list? if (m_listSmplMgrs.empty()) { // yes // set particle STD data if (!SetPartSTDData(pPartSTDData)) { // failed to call SetPartSTDData method LogErrorTrace(__FILE__, __LINE__, _T("AddASmplMsrResultMgr: failed to call SetPartSTDData method.")); return FALSE; } } else { // not // check if the particle STD data of the input sample result file is same with the project file CPartSTDDataPtr pPartSTDDataProj = m_pReportProjFile->GetPartSTDData(); ASSERT(pPartSTDDataProj); if (!pPartSTDDataProj) { // invalid report project particle STD data file pointer LogErrorTrace(__FILE__, __LINE__, _T("AddASmplMsrResultMgr: invalid report project particle STD data file pointer.")); return FALSE; } if (!(*(pPartSTDData.get()) == *(pPartSTDDataProj.get()))) { // the two particle std data dis-matched LogTrace(__FILE__, __LINE__, _T("AddASmplMsrResultMgr: the particle std data file of the newly added file is mis-matched with the other files in the report project file.")); return FALSE; } //if file name is same and path name is also same, not add CString strWorkingFolder = pSmplMsrResultFileMgrPtr->GetWorkingFolderStr(); // pathname CString strPathname = pSmplMsrResultFileMgrPtr->GetPathName(); auto itr = std::find_if(m_listSmplMgrs.begin(), m_listSmplMgrs.end(), [strWorkingFolder, strPathname](CSmplMsrResultFileMgrPtr p) { return ((p->GetPathName().CompareNoCase(strPathname) == 0) && (p->GetWorkingFolderStr().CompareNoCase(strWorkingFolder) == 0)); }); if (itr != m_listSmplMgrs.end()) { // the two particle std data dis-matched LogTrace(__FILE__, __LINE__, _T("AddASmplMsrResultMgr: the sample measure result file has been inserted into current report file.")); return FALSE; } } // add the file path name into file path names list CString strPathname = pSmplMsrResultFileMgrPtr->GetPathName(); std::vector listSmplMsrResultFilePathNames = m_pReportProjFile->GetSmplMsrResultFilePathNames(); listSmplMsrResultFilePathNames.push_back(strPathname); m_pReportProjFile->SetSmplMsrResultFilePathNames(listSmplMsrResultFilePathNames); // add the sample result file into sample measure result files list m_listSmplMgrs.push_back(pSmplMsrResultFileMgrPtr); // set modify flag to TRUE SetModify(); // set working sample m_nWorkingSampeIndex = (int)m_listSmplMgrs.size() - 1; // reset property parameters ResetPropertyParams(); // ok, return TRUE return TRUE; } void CReportProjFileMgr::SetSmplMsrResultMgrs(CSmplMsrResultFileMgrList a_listSmplMsrResultFileMgr) { for (auto pSmplMsrResultMgr : a_listSmplMsrResultFileMgr) { CString strWorkingFolder = pSmplMsrResultMgr->GetWorkingFolderStr(); CSmplMsrResultFileMgrPtr pSmplMsrResultMgrNew = CSmplMsrResultFileMgrPtr(new CSmplMsrResultFileMgr(strWorkingFolder)); CString strPathname = pSmplMsrResultMgr->GetPathName(); pSmplMsrResultMgrNew->SetPathName(strPathname); CSmplMsrResultFilePtr pSmplMsrResultFile = pSmplMsrResultMgr->GetSmplMsrResultFile(); CSmplMsrResultFilePtr pSmplMsrResultFileNew = CSmplMsrResultFilePtr(new CSmplMsrResultFile(pSmplMsrResultFile.get())); pSmplMsrResultMgrNew->SetSmplMsrResultFile(pSmplMsrResultFileNew); m_listSmplMgrs.push_back(pSmplMsrResultMgrNew); } } CSmplMsrResultFileMgrPtr CReportProjFileMgr::GetASmplMsrResultMgrById(int a_nIndex) { if (a_nIndex < 0 || a_nIndex >= (int)m_listSmplMgrs.size()) { return nullptr; } return m_listSmplMgrs[a_nIndex]; } CSmplMsrResultFileMgrPtr CReportProjFileMgr::GetASmplMsrResultMgrByPathName(CString a_strPathName) { a_strPathName.Trim(); if (a_strPathName.IsEmpty()) { return nullptr; } auto itr = std::find_if(m_listSmplMgrs.begin(), m_listSmplMgrs.end(), [a_strPathName](CSmplMsrResultFileMgrPtr p) { return p->GetPathName().CompareNoCase(a_strPathName) == 0; }); if (itr == m_listSmplMgrs.end()) { return nullptr; } return *itr; } CSmplMsrResultFileMgrPtr CReportProjFileMgr::GetASmplMsrResultMgrByFileName(CString a_strFileName) { a_strFileName.Trim(); if (a_strFileName.IsEmpty()) { return nullptr; } auto itr = std::find_if(m_listSmplMgrs.begin(), m_listSmplMgrs.end(), [a_strFileName](CSmplMsrResultFileMgrPtr p) { CString strDataSource = COTSHelper::GetFileName(p->GetPathName()); return strDataSource.CompareNoCase(a_strFileName) == 0; }); if (itr == m_listSmplMgrs.end()) { return nullptr; } return *itr; } BOOL CReportProjFileMgr::DeleteASmplMsrResultMgrById(int a_nIndex) { // check the index if (a_nIndex < 0 || a_nIndex >= (int)m_listSmplMgrs.size()) { // invalid input sample index LogErrorTrace(__FILE__, __LINE__, _T("DeleteSampleByIndex::input sample index")); return a_nIndex; } // delete path from project file; std::vector listSmplMsrResultFilePathNames = m_pReportProjFile->GetSmplMsrResultFilePathNames(); // check number of file path names if ((int)listSmplMsrResultFilePathNames.size() != (int)m_listSmplMgrs.size()) { LogErrorTrace(__FILE__, __LINE__, _T("DeleteASmplMsrResultMgrById: file path names list has different size with sample result file number.")); return FALSE; } // calculate new working sample index int nNewWorkingSampeIndex; if (a_nIndex < m_nWorkingSampeIndex) { nNewWorkingSampeIndex = m_nWorkingSampeIndex - 1; } else if (a_nIndex > m_nWorkingSampeIndex) { nNewWorkingSampeIndex = m_nWorkingSampeIndex; } else { // deleting working sample. if (a_nIndex == (int)m_listSmplMgrs.size() - 1) { // this is the last sample, select the above sample as working sample // if this is only sample in the list working sample index will be -1; nNewWorkingSampeIndex = m_nWorkingSampeIndex - 1; } else { // select next sample as working sample nNewWorkingSampeIndex = m_nWorkingSampeIndex; } } // delete the sample m_listSmplMgrs.erase(m_listSmplMgrs.begin() + a_nIndex); // the file is modified. SetModify(); // reset working sample index m_nWorkingSampeIndex = nNewWorkingSampeIndex; // delete the sample path name listSmplMsrResultFilePathNames.erase(listSmplMsrResultFilePathNames.begin() + a_nIndex); m_pReportProjFile->SetSmplMsrResultFilePathNames(listSmplMsrResultFilePathNames); // reset property parameters ResetPropertyParams(); // ok, return TRUE return TRUE; } BOOL CReportProjFileMgr::DeleteASmplMsrResultMgrByPathName(CString a_strPathName) { // check report project file pointer ASSERT(m_pReportProjFile); if (!m_pReportProjFile) { // invalid report project file pointer LogErrorTrace(__FILE__, __LINE__, _T("DeleteASmplMsrResultMgrByPathName: invalid report project file pointer.")); return FALSE; } a_strPathName.Trim(); if (a_strPathName.IsEmpty()) { return FALSE; } auto itrObj = std::find_if(m_listSmplMgrs.begin(), m_listSmplMgrs.end(), [a_strPathName](CSmplMsrResultFileMgrPtr p) { return p->GetPathName().CompareNoCase(a_strPathName) == 0; }); if (itrObj == m_listSmplMgrs.end()) { // failed to find sample measure result file LogErrorTrace(__FILE__, __LINE__, _T("DeleteASmplMsrResultMgrByPathName: failed to find sample measure result file.")); return FALSE; } std::vector listSmplMsrResultFilePathNames = m_pReportProjFile->GetSmplMsrResultFilePathNames(); auto itrPathName = std::find_if(listSmplMsrResultFilePathNames.begin(), listSmplMsrResultFilePathNames.end(), [a_strPathName](CString strPathName) { return strPathName.CompareNoCase(a_strPathName) == 0; }); if (itrPathName == listSmplMsrResultFilePathNames.end()) { // failed to find sample measure result file pathname LogErrorTrace(__FILE__, __LINE__, _T("DeleteASmplMsrResultMgrByPathName: failed to find sample measure result file pathname.")); return FALSE; } m_listSmplMgrs.erase(itrObj); // listSmplMsrResultFilePathNames.erase(itrPathName); m_pReportProjFile->GetSmplMsrResultFilePathNames().erase(itrPathName); // reset property parameters ResetPropertyParams(); // set modify flag to TRUE SetModify(); // ok, return TRUE return TRUE; } BOOL CReportProjFileMgr::EditASmplMsrResultMgrById(int a_nIndex, CSmplMsrResultFileMgrPtr a_pSmpFileMgr) { ASSERT(a_pSmpFileMgr); if (!a_pSmpFileMgr) { LogErrorTrace(__FILE__, __LINE__, _T("EditASmplMsrResultMgrById:invalid sample measure result manager pointer.")); return FALSE; } // check if the working sample index if (a_nIndex < 0 || a_nIndex >= (int)m_listSmplMgrs.size()) { LogErrorTrace(__FILE__, __LINE__, _T("EditASmplMsrResultMgrById: invalid sample measure result manager index.")); // invalid working sample index return FALSE; } m_listSmplMgrs.erase(m_listSmplMgrs.begin() + a_nIndex); m_listSmplMgrs.insert(m_listSmplMgrs.begin() + a_nIndex, a_pSmpFileMgr); return TRUE; } CSmplMsrResultFileMgrPtr CReportProjFileMgr::GetWorkingSmplMsrReslMgr() { // check if the working sample index if (m_nWorkingSampeIndex < 0 || m_nWorkingSampeIndex >= (int)m_listSmplMgrs.size()) { LogErrorTrace(__FILE__, __LINE__, _T("GetWorkingSmplMsrReslMgr: invalid working sample measure result manager index.")); // invalid working sample index return FALSE; } return GetASmplMsrResultMgrById(m_nWorkingSampeIndex); } CString CReportProjFileMgr::GetWorkingSampleName() { CString strRet = _T(""); CSmplMsrResultFileMgrPtr pSmplMsrResultFileMgr = GetWorkingSmplMsrReslMgr(); ASSERT(pSmplMsrResultFileMgr); if (!pSmplMsrResultFileMgr) { LogErrorTrace(__FILE__, __LINE__, _T("GetWorkingSampleName: invalid working sample measure result manager.")); return _T(""); } CSmplMsrResultFilePtr pSmplMsrResultFile = pSmplMsrResultFileMgr->GetSmplMsrResultFile(); ASSERT(pSmplMsrResultFile); if (!pSmplMsrResultFile) { LogErrorTrace(__FILE__, __LINE__, _T("GetWorkingSampleName: invalid working sample measure result file.")); return _T(""); } COTSSamplePtr pSample = pSmplMsrResultFile->GetSample(); ASSERT(pSample); if (!pSample) { LogErrorTrace(__FILE__, __LINE__, _T("GetWorkingSampleName: invalid working sample.")); return _T(""); } strRet = pSample->GetName(); return strRet; } BOOL CReportProjFileMgr::SetWorkingSmplMsrReslMgr(CSmplMsrResultFileMgrPtr a_pSmplMsrResultMgr) { ASSERT(a_pSmplMsrResultMgr); if (!a_pSmplMsrResultMgr) { LogErrorTrace(__FILE__, __LINE__, _T("SetWorkingSmplMsrReslMgr: invalid sample measure result manager pointer.")); return FALSE; } if (!EditASmplMsrResultMgrById(m_nWorkingSampeIndex, a_pSmplMsrResultMgr)) { LogErrorTrace(__FILE__, __LINE__, _T("SetWorkingSmplMsrReslMgr: can't edit working sample measure result file.")); return FALSE; } return TRUE; } CString CReportProjFileMgr::GetFileName() { // make a copy of file path name CString strPathName = m_strPathName; // is this a new file? strPathName.Trim(); if (strPathName.CompareNoCase(UNTITLED_NEW_FILE_NAME) == 0) { return strPathName; } // get file name CString strFileName = COTSHelper::GetFileNameWithoutExtension(strPathName); strFileName = COTSHelper::GetFileName(strFileName); // return file name return strFileName; } // grid computing CGridDatasList CReportProjFileMgr::GridDataTransfer() { CGridDatasList listGridData; listGridData.clear(); // calculate table type CPropParamPtr prop = m_CurrentPropParam; //COMPUTE_TABLE_TYPE nCalTableType = a_pGridIn->GetCalTableType(); BOOL bRet = FALSE; TrioCal trio(this); CGBCalculate GBCal(this); MeasureResultInfo Msr(this); switch (prop->GetType()) { case DISPLAY_PICTURE_TYPE::IMAGE: { IMAGE_DISPLAY_TYPE nImgDisType = prop->GetImageDisplayType(); switch (nImgDisType) { case IMAGE_DISPLAY_TYPE::GENERAL: listGridData = CompDistribution(); break; case IMAGE_DISPLAY_TYPE::IMAGE_GRID: { MEASURE_DATA_TYPE meaType = prop->GetMeasureDataType(); switch (meaType) { case MEASURE_DATA_TYPE::ALL_PARTICLE: listGridData = CompSortClass(); break; case MEASURE_DATA_TYPE::ANYLYSIS_PARTICLE: listGridData = CompSortKind(); break; case MEASURE_DATA_TYPE::PARTICALE_SIZE_DISTRIBUTION: listGridData = CompSortSize(); break; default: break; } break; } default: break; } break; } case DISPLAY_PICTURE_TYPE::TABLE: { CALCULATE_TABLE_TYPE nCalTableType = prop->GetCalTableType(); switch (nCalTableType) { case CALCULATE_TABLE_TYPE::MEASURE_INFO: listGridData = Msr.GetMeasureResultInfo(); break; case CALCULATE_TABLE_TYPE::PARTICALE_GENE_INFO://识别颗粒信息表 listGridData = CompParticleGenInfo(); break; case CALCULATE_TABLE_TYPE::PARTICALE_COMP://颗粒成分表,即颗粒识别出的物质名称 listGridData = CompParticleComponent(); break; case CALCULATE_TABLE_TYPE::ELEMENT_COMP://元素成分表,即物质的元素百分比 listGridData = CompElementComponent(); break; case CALCULATE_TABLE_TYPE::PARTICALE_SIZE_DISTRIBUTION://颗粒尺寸分布 listGridData = CompParticleSizeDistribution(); break; case CALCULATE_TABLE_TYPE::AVE_ELEMENT_COMP: listGridData = CompAveElemnetComponent();//元素平均重量百分比 break; case CALCULATE_TABLE_TYPE::GB_Method1: listGridData = GBCal.GetGBInclusion(); break; case CALCULATE_TABLE_TYPE::GB_Method2: listGridData = GBCal.GetGBInclusion(); break; case CALCULATE_TABLE_TYPE::ASTM: listGridData = GBCal.GetGBInclusion(); break; case CALCULATE_TABLE_TYPE::DIN: listGridData = GBCal.GetGBInclusion(); break; default: break; } break; } case DISPLAY_PICTURE_TYPE::CHART: { CALCULATE_CHART_TYPE nCalChartType = prop->GetCalChartType(); switch (nCalChartType) { case CALCULATE_CHART_TYPE::PARTICALE_COMP: listGridData = CompChartParticleComp(); break; case CALCULATE_CHART_TYPE::ELEMENT_COMP: listGridData = CompChartElementComp(); break; case CALCULATE_CHART_TYPE::PARTICALE_SIZE_DISTRIBUTION: listGridData = CompChartParticleSize(); break; case CALCULATE_CHART_TYPE::TRIO_CHART: listGridData = trio.CompParticleTrioInfo(); break; case CALCULATE_CHART_TYPE::COMMON_FIVE: listGridData = CompChartCommonFive(); break; default: break; } break; } } return listGridData; } // reclassify measure result BOOL CReportProjFileMgr::ReClassify() { ASSERT(m_pReportProjFile); if (!m_pReportProjFile) { LogErrorTrace(__FILE__, __LINE__, _T("ReClassify: empty report project file.")); return FALSE; } // particle STD data CPartSTDDataPtr pPartSTDData = m_pReportProjFile->GetPartSTDData(); ASSERT(pPartSTDData); if (!pPartSTDData) { LogErrorTrace(__FILE__, __LINE__, _T("ReClassify: empty STD file.")); return FALSE; } // sample measure result files for (auto pSmplMsrResultMgr : m_listSmplMgrs) { // particle list, need compute COTSParticleList listParticleOld = pSmplMsrResultMgr->GetParticleList(); // analysis x-ray list CPosXraysList listAnalysisXray = pSmplMsrResultMgr->GetAnalysisXray(); if (listParticleOld.empty() || listAnalysisXray.empty()) { // need to reload the result COTSFieldMgrList listFieldMgr = pSmplMsrResultMgr->GetOTSFldMgrListAndAnalysisXrayList(); if (listFieldMgr.empty()) { LogErrorTrace(__FILE__, __LINE__, _T("ReClassify: can't reload file.")); return FALSE; } if (!pSmplMsrResultMgr->ComputeParticleList()) { LogErrorTrace(__FILE__, __LINE__, _T("ReClassify: can't compute particle list.")); return FALSE; } listParticleOld = pSmplMsrResultMgr->GetParticleList(); listAnalysisXray = pSmplMsrResultMgr->GetAnalysisXray(); } COTSParticleList listAnalysisParticle; listAnalysisParticle.clear(); for (auto pParticle : listParticleOld) { int nType = pParticle->GetType(); //All particles that contain X-ray data if (nType > (int)OTS_PARTCLE_TYPE::NO_ANALYSIS_X_RAY) { COTSParticlePtr pParticleNew = COTSParticlePtr(new COTSParticle(*pParticle.get())); listAnalysisParticle.push_back(pParticleNew); } } // 1. Update particle message if (!ClassifyParticles(listAnalysisParticle, listAnalysisXray)) { LogErrorTrace(__FILE__, __LINE__, _T("ReClassify: can't classify particle list.")); return FALSE; } COTSParticleList listParticle; listParticle.clear(); for (auto pParticle : listParticleOld) { int nType = pParticle->GetType(); if (nType < (int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED) { COTSParticlePtr pParticleNew = COTSParticlePtr(new COTSParticle(*pParticle.get())); listParticle.push_back(pParticleNew); } } for (auto pParticle : listAnalysisParticle) { COTSParticlePtr pParticleNew = COTSParticlePtr(new COTSParticle(*pParticle.get())); listParticle.push_back(pParticleNew); } CSmplMsrResultFilePtr pSmplMsrResultFile = pSmplMsrResultMgr->GetSmplMsrResultFile(); ASSERT(pSmplMsrResultFile); if (!pSmplMsrResultFile) { LogErrorTrace(__FILE__, __LINE__, _T("ReClassify: can't get sample measure result file.")); return FALSE; } COTSFieldDataList listFieldData = pSmplMsrResultFile->GetFieldData(); for (auto pFieldData : listFieldData) { int nID = pFieldData->GetId(); COTSParticleList listFieldParticle; for (auto pParticle : listParticle) { int nFieldId = pParticle->GetFieldId(); if (nFieldId == nID) { COTSParticlePtr pParticleNew = COTSParticlePtr(new COTSParticle(*pParticle.get())); listFieldParticle.push_back(pParticleNew); } } pFieldData->SetParticleList(listFieldParticle); //update basedata add code 2019-6-18 CString strFieldFileFolder = pFieldData->GetFieldFileFolder(); CString strIncAFilename = strFieldFileFolder + SMPL_MSR_RESULT_INCLUSION_FILE; CIncAFileMgrPtr pIncAFileMgr = CIncAFileMgrPtr(new CIncAFileMgr(strIncAFilename)); pIncAFileMgr->SetParticleList(listFieldParticle, TRUE); if (!pIncAFileMgr->Update(strIncAFilename)) { LogErrorTrace(__FILE__, __LINE__, _T("SaveFieldFiles: save inclusion file failed.")); return FALSE; } } pSmplMsrResultFile->SetFieldData(listFieldData); // 2. Update measure result message. COTSSamplePtr pSample = pSmplMsrResultFile->GetSample(); ASSERT(pSample); if (!pSample) { LogErrorTrace(__FILE__, __LINE__, _T("ReClassify: can't get sample pointer.")); return FALSE; } CMsrResultsPtr poMsrResults = CMsrResultsPtr(new CMsrResults()); // go through the particles list for (auto pParticle : listParticle) { // create a measure result item CMsrResultItemPtr pMsrResultItem = CMsrResultItemPtr(new CMsrResultItem()); pMsrResultItem->SetTypeId(pParticle->GetType()); pMsrResultItem->SetArea((int)(pParticle->GetArea() + 0.5)); pMsrResultItem->SetNumber(1); // add the particle into to field data poMsrResults->CumulateMeasureResults(pMsrResultItem); } pSample->SetMsrResults(poMsrResults); // 3. Update sample STD CMsrParamsPtr poMsrParams = pSample->GetMsrParams(); ASSERT(poMsrParams); if (!poMsrParams) { LogErrorTrace(__FILE__, __LINE__, _T("ReClassify: can't get sample parameter pointer.")); return FALSE; } poMsrParams->SetPartSTDData(pPartSTDData); // 4. write sample measure result file. // sample measure result file CString strFilePathName = pSmplMsrResultMgr->GetPathName(); if (!pSmplMsrResultMgr->Save(strFilePathName)) { LogErrorTrace(__FILE__, __LINE__, _T("ReClassify: can't get sample pointer.")); return FALSE; } } return TRUE; } // get inclusion index double CReportProjFileMgr::GetInclusionIndex() { // get folder name from general parameter. ASSERT(m_pReportProjFile); if (!m_pReportProjFile) { LogErrorTrace(__FILE__, __LINE__, _T("GetInclusionIndex: Can't find the folder.")); return -1; } double dScale = m_pReportProjFile->GetScale(); double dTotalMeasuredArea = 0.0; double dInclusionArea = 0.0; CSmplMsrResultFileMgrList m_listSmplMsrResultMgrs; for (auto pSmplMsrResultMgr : m_listSmplMsrResultMgrs) { CSmplMsrResultFilePtr pSmplMsrResultFile = pSmplMsrResultMgr->GetSmplMsrResultFile(); ASSERT(pSmplMsrResultFile); if (!pSmplMsrResultFile) { LogErrorTrace(__FILE__, __LINE__, _T("GetInclusionIndex: invalid sample measure result file pointer.")); return -1; } COTSSamplePtr pSample = pSmplMsrResultFile->GetSample(); ASSERT(pSample); if (!pSample) { LogErrorTrace(__FILE__, __LINE__, _T("GetInclusionIndex: invalid sample pointer.")); return -1; } CMsrResultsPtr poMsrResults = pSample->GetMsrResults(); ASSERT(poMsrResults); if (!poMsrResults) { LogErrorTrace(__FILE__, __LINE__, _T("GetInclusionIndex: invalid sample measure result pointer.")); return -1; } dTotalMeasuredArea += poMsrResults->GetMeasuredArea(); CMsrResultItemsList listResultItems = poMsrResults->GetResultItems(); for (auto pItem : listResultItems) { int nType = pItem->GetTypeId(); if (nType > (int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED) { dInclusionArea += pItem->GetArea(); } } } return dInclusionArea / dTotalMeasuredArea * dScale; } // classify particles BOOL CReportProjFileMgr::ClassifyParticles(COTSParticleList& a_listAnalysisParticles, CPosXraysList& a_listAnalysisXRay) { // make sure the two lists are same size int nSize = (int)a_listAnalysisParticles.size(); if (nSize != (int)a_listAnalysisXRay.size()) { // particles list size is different with x-ray size LogErrorTrace(__FILE__, __LINE__, _T("ClassifyParticles: particles list size is different with x-ray size.")); return FALSE; } // go through all analysis particles for (int i = 0; i < nSize; ++i) { COTSParticlePtr pParticle = a_listAnalysisParticles[i]; int nAnalysisXrayId = pParticle->GetAnalysisId(); if (nAnalysisXrayId < 0 || nAnalysisXrayId >= nSize) { // particles list size is different with x-ray size LogErrorTrace(__FILE__, __LINE__, _T("ClassifyParticles: particles xray id is wrong.")); return FALSE; } int nFieldId = pParticle->GetFieldId(); //using on classify debug,trace fieldid and analysisxrayid if (nFieldId == 135 && nAnalysisXrayId == 38) { int a = 0; } auto itr = std::find_if(a_listAnalysisXRay.begin(), a_listAnalysisXRay.end(), [nAnalysisXrayId, nFieldId](CPosXrayPtr p) { return (p->GetScanFieldId() == nFieldId && p->GetIndex() == nAnalysisXrayId); }); if (itr == a_listAnalysisXRay.end()) { return FALSE; } CPosXrayPtr pXray = *itr; if (!ClassifyParticle(pParticle, pXray)) { // failed to call ClassifyParticle method LogErrorTrace(__FILE__, __LINE__, _T("ClassifyParticles: failed to call ClassifyParticle method.")); return FALSE; } } // ok, return TRUE return TRUE; } BOOL CReportProjFileMgr::ClassifyParticle(COTSParticlePtr a_pParticle, CPosXrayPtr a_pXRay) { // safety check ASSERT(m_pReportProjFile); if (!m_pReportProjFile) { // invalid sample pointer. LogErrorTrace(__FILE__, __LINE__, _T("ClassifyParticle: invalid sample pointer.")); return FALSE; } ASSERT(a_pParticle); if (!a_pParticle) { // invalid particle pointer. LogErrorTrace(__FILE__, __LINE__, _T("ClassifyParticle: invalid particle pointer.")); return FALSE; } ASSERT(a_pXRay); if (!a_pXRay) { // invalid x-ray pointer. LogErrorTrace(__FILE__, __LINE__, _T("ClassifyParticle: invalid x-ray pointer.")); return FALSE; } //2019.3.28 code changes //initial inclusion ID is NOT_IDENTIFIED int nIncId = (int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED; //get STDData from Reportprojfile CPartSTDDataPtr pPartSTDData = m_pReportProjFile->GetPartSTDData(); //get element chemistries list from xray CElementChemistriesList listElementChemistriesOld = a_pXRay->GetElementQuantifyData(); auto pSample = m_listSmplMgrs[m_nWorkingSampeIndex]->GetSmplMsrResultFile()->GetSample(); //get the parameter MsrParam object CMsrParamsPtr pMsrParam = pSample->GetMsrParams(); //get the steel technology parameter STEEL_TECHNOLOGY steelTech = pMsrParam->GetSteelTechnology(); //get standard database item which will be used when classify. //third setp.the particle are classified if (!COTSClassifyEng::ClassifyXray(pPartSTDData, steelTech, listElementChemistriesOld, nIncId)) {// invalid x-ray pointer. LogErrorTrace(__FILE__, __LINE__, _T("ClassifyParticle: can't identify the particle as any inclusion.")); return FALSE; } if (nIncId < 8) { nIncId = (int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED; } a_pParticle->SetType(nIncId); // ok, return TRUE return TRUE; } // protected // get data source name list std::vector CReportProjFileMgr::GetDataSourceNamesList() { std::vector listDataSourceNames; CString strComSourceName = _T(""); int nComNum = 0; for (auto pSmplMsrResultFileMgr : m_listSmplMgrs) { // sample measure result file CString strFilePathName = pSmplMsrResultFileMgr->GetPathName(); // get data source name CString strDataSource = COTSHelper::GetFileName(strFilePathName); // get compound source name CSmplMsrResultFilePtr pSmplMsrResultFile = pSmplMsrResultFileMgr->GetSmplMsrResultFile(); ASSERT(pSmplMsrResultFile); if (!pSmplMsrResultFile) { LogErrorTrace(__FILE__, __LINE__, _T("GetDataSourceNamesList: Can't get sample result file pointer.")); break; } BOOL bSwitch = pSmplMsrResultFile->GetSwitch(); if (bSwitch) { strComSourceName += strDataSource + _T("+"); nComNum++; } // add data source name into the list listDataSourceNames.push_back(strDataSource); } if (nComNum > 1) { //listDataSourceNames.push_back(strComSourceName); strComSourceName.TrimRight(_T("+"));//去掉最后的+号 listDataSourceNames.insert(listDataSourceNames.begin(), strComSourceName); } return listDataSourceNames; } std::vector CReportProjFileMgr::GetDataSourcePosList() { std::vector listDataSourcePos; if (!IsHaveMultiDataSource()) { return listDataSourcePos; } int nPos = -1; for (auto pSmplMsrResultFileMgr : m_listSmplMgrs) { nPos++; // get compound source name CSmplMsrResultFilePtr pSmplMsrResultFile = pSmplMsrResultFileMgr->GetSmplMsrResultFile(); ASSERT(pSmplMsrResultFile); if (!pSmplMsrResultFile) { LogErrorTrace(__FILE__, __LINE__, _T("GetDataSourceNamesList: Can't get sample result file pointer.")); break; } BOOL bSwitch = pSmplMsrResultFile->GetSwitch(); if (bSwitch) { listDataSourcePos.push_back(nPos); } } return listDataSourcePos; } // get property parameter // compute particle general information CGridDatasList CReportProjFileMgr::CompParticleGenInfo() { // use the dll resource AFX_MANAGE_STATE(AfxGetStaticModuleState()); CGridDatasList listGridData; listGridData.clear(); // depart compound source name std::vector listDataSource = m_CurrentPropParam->GetDataSourceList(); int nSelectedDataSourceIndex = m_CurrentPropParam->GetDataSourceId(); CString sDataSourceNames = listDataSource[nSelectedDataSourceIndex]; std::vector listSelectedDataSource = COTSHelper::SplitString(sDataSourceNames, _T("+")); std::vector listSelectedPos; if (IsHaveMultiDataSource() && (int)listSelectedDataSource.size() > 1) { listSelectedPos = GetDataSourcePosList(); if ((int)listSelectedPos.size() != (int)listSelectedDataSource.size()) { return listGridData; } } int nIndex = 0; for (auto strDataSourceName : listSelectedDataSource) { CGridDataPtr pGridData = CGridDataPtr(new CGridData()); //// data source id pGridData->SetDataSourceList(m_CurrentPropParam->GetDataSourceList()); int nDataSourceId = -1; if (IsHaveMultiDataSource()) { if (listSelectedDataSource.size() > 1) { nDataSourceId = listSelectedPos[nIndex]; } else { nDataSourceId = m_CurrentPropParam->GetDataSourceId() - 1; } } else { nDataSourceId = m_CurrentPropParam->GetDataSourceId(); } pGridData->SetDataSourceId(nDataSourceId); //------------select xray data add 2019-06-15----------------- COTSParticleList listParticleAll; listParticleAll.clear(); CPosXraysList listXrayOut; listXrayOut.clear(); CPosXraysList listXray; listXray.clear(); COTSParticleList selectedParts = m_CurrentPropParam->GetSelectParticle(); // add filter select particle COTSParticleList* pSelectedParts; listXrayOut = GetAnalysisXrayList(strDataSourceName); if (m_CurrentPropParam->GetDataSourceType() == DATA_SOURCE_TYPE::SELECTION) { listParticleAll = m_CurrentPropParam->GetSelectParticle(); pSelectedParts = &selectedParts; for (auto pParticle : listParticleAll) { int nIndex = pParticle->GetAnalysisId(); int nField = pParticle->GetFieldId(); auto itr = std::find_if(listXrayOut.begin(), listXrayOut.end(), [nIndex, nField](CPosXrayPtr p) { return (p->GetIndex() == nIndex && p->GetScanFieldId() == nField); }); if (itr == listXrayOut.end()) { continue; } else { CPosXrayPtr pXray = *itr; listXray.push_back(pXray); } } } else { listParticleAll = GetAnalysisParticleList(strDataSourceName); pSelectedParts = &listParticleAll; for (auto pXray : listXrayOut) { //CPosXrayPtr pXrayNew = CPosXrayPtr(new CPosXray(*pXray.get())); listXray.push_back(pXray); } } //----------------------------------------------------------- //get pixel size CSmplMsrResultFileMgrPtr pSmplMsrResultFileMgr = this->GetASmplMsrResultMgrByFileName(strDataSourceName); ASSERT(pSmplMsrResultFileMgr); if (!pSmplMsrResultFileMgr) { LogErrorTrace(__FILE__, __LINE__, _T("CompParticleGenInfo: can't get sample result file manager.")); return listGridData; } CSmplMsrResultFilePtr pSmplMsrResultFile = pSmplMsrResultFileMgr->GetSmplMsrResultFile(); ASSERT(pSmplMsrResultFile); if (!pSmplMsrResultFile) { LogErrorTrace(__FILE__, __LINE__, _T("CompParticleGenInfo: can't get sample result file.")); return listGridData; } COTSSamplePtr pSample = pSmplMsrResultFile->GetSample(); ASSERT(pSample); if (!pSample) { LogErrorTrace(__FILE__, __LINE__, _T("CompParticleGenInfo: can't get sample.")); return listGridData; } double dPixelSize = pSample->CalculatePixelSize(); if (!GetGenInfoFromParticleList(*pSelectedParts, listXray, dPixelSize, pGridData)) { LogErrorTrace(__FILE__, __LINE__, _T("CompParticleGenInfo: can't get general information.")); return listGridData; } listGridData.push_back(pGridData); nIndex++; } return listGridData; } COTSParticleList CReportProjFileMgr::GetAnalysisParticleList(CString a_DataSourceName) { COTSParticleList listParticleAll; // compound sample measure result files CSmplMsrResultFileMgrPtr pSmplMsrResultFileMgr = this->GetASmplMsrResultMgrByFileName(a_DataSourceName); if (!pSmplMsrResultFileMgr->ComputeParticleList()) { LogErrorTrace(__FILE__, __LINE__, _T("GetAnalysisParticleList: can't get particle list.")); return listParticleAll; } listParticleAll = pSmplMsrResultFileMgr->GetParticleList(); return listParticleAll; } CPosXraysList CReportProjFileMgr::GetAnalysisXrayList(CString a_DataSourceName) { CPosXraysList listAnalysisXray; CSmplMsrResultFileMgrPtr pSmplMsrResultFileMgr = this->GetASmplMsrResultMgrByFileName(a_DataSourceName); pSmplMsrResultFileMgr->GetOTSFldMgrListAndAnalysisXrayList(); // should first read x ray data from data base. listAnalysisXray = pSmplMsrResultFileMgr->GetAnalysisXray(); return listAnalysisXray; } CSTDItemPtr CReportProjFileMgr::GetParticleSTDItem(int STDItemId) { // std ASSERT(m_pReportProjFile); if (!m_pReportProjFile) { LogErrorTrace(__FILE__, __LINE__, _T("CompParticleGenInfo: empty project file.")); return nullptr; } CPartSTDDataPtr pPartSTDData = m_pReportProjFile->GetPartSTDData(); ASSERT(pPartSTDData); if (!pPartSTDData) { LogErrorTrace(__FILE__, __LINE__, _T("CompParticleGenInfo: invalid STD data.")); return nullptr; } CSTDItemsList listSTDItem = pPartSTDData->GetSTDItemsList(); if (listSTDItem.empty()) { LogErrorTrace(__FILE__, __LINE__, _T("CompParticleGenInfo: empty STD Item.")); return nullptr; } auto itr = std::find_if(listSTDItem.begin(), listSTDItem.end(), [STDItemId](CSTDItemPtr p) {return (p->GetSTDId() == STDItemId); }); if (itr == listSTDItem.end()) //没有找到,标明这是一个未识别颗粒,类型为7 { return nullptr; } CSTDItemPtr p = *itr; return p; } bool CReportProjFileMgr::GetSTDMapedParticleList(const COTSParticleList& a_listParticle, map* mapSameSTDPartList) { //把颗粒根据类型分组,类型 ID做key,颗粒列表做value map::iterator partListIter; //get the same type particle together for (auto pParticle : a_listParticle) { int nType = pParticle->GetType(); //只有"NOT_IDENTIFIED"以上的颗粒类型需要考虑 if (nType >= (int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED_SIC) { partListIter = mapSameSTDPartList->find(nType); if (partListIter == mapSameSTDPartList->end()) { COTSParticleList listParticle; listParticle.push_back(pParticle); mapSameSTDPartList->insert(pair(nType, listParticle)); } else { partListIter->second.push_back(pParticle); } } } return true; } // compute particle general information according to particle list BOOL CReportProjFileMgr::GetGenInfoFromParticleList(COTSParticleList a_listParticle, CPosXraysList a_listXray, double a_dPixelSize, CGridDataPtr a_pGridData) { ASSERT(a_pGridData); if (!a_pGridData) { LogErrorTrace(__FILE__, __LINE__, _T("GetGenInfoFromParticleList: invalid grid data pointer.")); return FALSE; } COTSParticleList listPartReport; map mapSameSTDItemPartList; this->GetSTDMapedParticleList(a_listParticle, &mapSameSTDItemPartList); COTSParticleList listNotIdentified; COTSParticleList listSiC; COTSParticleList listFeO; for (auto partListIter = mapSameSTDItemPartList.begin(); partListIter != mapSameSTDItemPartList.end(); partListIter++) { if (partListIter->first != (int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED) { listPartReport.insert(listPartReport.end(), partListIter->second.begin(), partListIter->second.end()); } else if (partListIter->first == (int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED_SIC) { listSiC = partListIter->second; } else if (partListIter->first == (int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED_FEO) { listFeO = partListIter->second; } else { listNotIdentified = partListIter->second; } } listPartReport.insert(listPartReport.end(), listSiC.begin(), listSiC.end()); listPartReport.insert(listPartReport.end(), listFeO.begin(), listFeO.end()); listPartReport.insert(listPartReport.end(), listNotIdentified.begin(), listNotIdentified.end()); int nColumnNum = ((int)(REPORT_PARTICLE_GEN_INFO_GRID_CLUMN::MAX) - (int)(REPORT_PARTICLE_GEN_INFO_GRID_CLUMN::MIN) + 1); std::vector listColumnName; LoadColumnString(listColumnName, IDS_PARTICLE_GEN_INFO_START, nColumnNum); if ((int)listColumnName.size() != nColumnNum) { LogErrorTrace(__FILE__, __LINE__, _T("CompParticleGenInfo: Can't get column name number.")); return FALSE; } //将元素进行分栏显示汇总集合 vector< CElementChemistriesList> vec_CElementChemistriesList; vec_CElementChemistriesList.clear(); CGridColumnsList listGridColumn; for (int i = 0; i < nColumnNum; i++) { CGridColumnPtr pColumn = CGridColumnPtr(new CGridColumn()); pColumn->SetName(listColumnName[i]); CGridRowsList listGridRows; listGridRows.clear(); int nType = 0; int nPos = 0; double a_dPartFTD; double a_dMinWidth; double a_dMaxLength; //double a_dRatio; switch (i) { case (int)REPORT_PARTICLE_GEN_INFO_GRID_CLUMN::NAME: listGridRows.clear(); for (auto pParticle : listPartReport) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING); nType = pParticle->GetType(); if (nType >= (int)OTS_PARTCLE_TYPE::IDENTIFIED) { std::string strName = pParticle->TypeName(); pGridRow->SetStringValue(strName.c_str()); } else { int nColumnNum = ((int)(REPORT_SORT_CLASS_GRID_CLUMN::MAX) - (int)(REPORT_SORT_CLASS_GRID_CLUMN::MIN) + 1); std::vector listColumnName; LoadColumnString(listColumnName, IDS_SORT_CLASS_START, nColumnNum); if (nType == (int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED) { pGridRow->SetStringValue(listColumnName[(int)REPORT_SORT_CLASS_GRID_CLUMN::NOT_IDENTIFIED]);//未知颗粒 } else if (nType == (int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED_SIC) { pGridRow->SetStringValue(listColumnName[(int)REPORT_SORT_CLASS_GRID_CLUMN::NOT_INCLUSION_SIC]);//SiC } else if (nType == (int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED_FEO) { pGridRow->SetStringValue(listColumnName[(int)REPORT_SORT_CLASS_GRID_CLUMN::NOT_INCLUSION_FEO]);//FeO } } listGridRows.push_back(pGridRow); //获取element数据 int XrayId = pParticle->GetAnalysisId(); int nFieldId = pParticle->GetFieldId(); auto itr = std::find_if(a_listXray.begin(), a_listXray.end(), [XrayId, nFieldId](CPosXrayPtr p) { return ((p->GetScanFieldId() == nFieldId) && (p->GetIndex() == XrayId)); }); CPosXrayPtr pXray = *itr; CElementChemistriesList listTpElement = pXray->GetElementQuantifyData(); //将获取到的元素先都添加到元素的List当中 vec_CElementChemistriesList.push_back(listTpElement); } break; case (int)REPORT_PARTICLE_GEN_INFO_GRID_CLUMN::IMAGE: listGridRows.clear(); for (auto pParticle : listPartReport) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::PARTICLE); //COTSParticlePtr pParticleNew = COTSParticlePtr(new COTSParticle(*pParticle.get())); pGridRow->SetParticle(pParticle); listGridRows.push_back(pGridRow); } break; case (int)REPORT_PARTICLE_GEN_INFO_GRID_CLUMN::MAXLENGTH://最长直径 listGridRows.clear(); for (auto pParticle : listPartReport) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); a_dMaxLength = pParticle->GetDMax(); pGridRow->SetDoubleValue(a_dMaxLength); listGridRows.push_back(pGridRow); } break; case (int)REPORT_PARTICLE_GEN_INFO_GRID_CLUMN::MINLENGTH://最短直径 listGridRows.clear(); for (auto pParticle : listPartReport) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); a_dMinWidth = pParticle->GetDMin(); pGridRow->SetDoubleValue(a_dMinWidth); listGridRows.push_back(pGridRow); } break; case (int)REPORT_PARTICLE_GEN_INFO_GRID_CLUMN::AXIALRATIO://长短直径比 listGridRows.clear(); for (auto pParticle : listPartReport) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); a_dMinWidth = pParticle->GetDMax(); a_dMaxLength = pParticle->GetDMin(); double d_axialratio = 0; if (a_dMinWidth != 0) { d_axialratio = a_dMaxLength / a_dMinWidth; } pGridRow->SetDoubleValue(d_axialratio); listGridRows.push_back(pGridRow); } break; case (int)REPORT_PARTICLE_GEN_INFO_GRID_CLUMN::EquivalentCircleDiameter://等效圆直径 listGridRows.clear(); //double Diameter; for (auto pParticle : listPartReport) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); double Diameter = pParticle->GetEqualCircleDiameter(); pGridRow->SetDoubleValue(Diameter); listGridRows.push_back(pGridRow); } break; case (int)REPORT_PARTICLE_GEN_INFO_GRID_CLUMN::FerretDiameter://费雷特直径 listGridRows.clear(); for (auto pParticle : listPartReport) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); a_dPartFTD = (pParticle->GetDMax() + pParticle->GetDMin()) / 2; //a_dPartFTD = pParticle->GetFeretDiameter(); pGridRow->SetDoubleValue(a_dPartFTD); listGridRows.push_back(pGridRow); } break; case (int)REPORT_PARTICLE_GEN_INFO_GRID_CLUMN::SIZE: listGridRows.clear(); for (auto pParticle : listPartReport) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); double dSize = pParticle->GetArea(); pGridRow->SetDoubleValue(dSize); listGridRows.push_back(pGridRow); //pParticle->GetFeretDiameter(); } break; //2020-4-11 add new calc type case (int)REPORT_PARTICLE_GEN_INFO_GRID_CLUMN::PERP: //正交直径 listGridRows.clear(); for (auto pParticle : listPartReport) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); double dPerp = pParticle->GetDPerp(); pGridRow->SetDoubleValue(dPerp); listGridRows.push_back(pGridRow); } break; case (int)REPORT_PARTICLE_GEN_INFO_GRID_CLUMN::PERI: //周长 listGridRows.clear(); for (auto pParticle : listPartReport) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); double dPeri = pParticle->GetPerimeter(); pGridRow->SetDoubleValue(dPeri); listGridRows.push_back(pGridRow); } break; case (int)REPORT_PARTICLE_GEN_INFO_GRID_CLUMN::INSCR: //内接圆直径 listGridRows.clear(); for (auto pParticle : listPartReport) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); double dInscr = pParticle->GetDInscr(); pGridRow->SetDoubleValue(dInscr); listGridRows.push_back(pGridRow); } break; case (int)REPORT_PARTICLE_GEN_INFO_GRID_CLUMN::MEAN: //内接圆平均直径 listGridRows.clear(); for (auto pParticle : listPartReport) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); double dMean = pParticle->GetDMean(); pGridRow->SetDoubleValue(dMean); listGridRows.push_back(pGridRow); } break; case (int)REPORT_PARTICLE_GEN_INFO_GRID_CLUMN::ELONG: //展开长度 listGridRows.clear(); for (auto pParticle : listPartReport) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); double dElong = pParticle->GetDElong(); pGridRow->SetDoubleValue(dElong); listGridRows.push_back(pGridRow); } break; case (int)REPORT_PARTICLE_GEN_INFO_GRID_CLUMN::ASPECT_ELONG: //展开长度比 listGridRows.clear(); for (auto pParticle : listPartReport) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); double dAspectElong = pParticle->GetAspectElong(); pGridRow->SetDoubleValue(dAspectElong); listGridRows.push_back(pGridRow); } break; case (int)REPORT_PARTICLE_GEN_INFO_GRID_CLUMN::ASPECT_MAX: //展开直径比 listGridRows.clear(); for (auto pParticle : listPartReport) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); double dAspectRatio = pParticle->GetAspectRatio(); pGridRow->SetDoubleValue(dAspectRatio); listGridRows.push_back(pGridRow); } break; case (int)REPORT_PARTICLE_GEN_INFO_GRID_CLUMN::Orientation: //朝向角度 listGridRows.clear(); for (auto pParticle : listPartReport) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); double dOrientation = pParticle->GetOrientation(); pGridRow->SetDoubleValue(dOrientation); listGridRows.push_back(pGridRow); } break; } pColumn->SetGridRowsList(listGridRows); listGridColumn.push_back(pColumn); } //定义一个不显示的元素字符列表 vector vec_NotDisplayed; vec_NotDisplayed.clear(); //上面获取完成vector CElementChemistriesList 后,再对该列表取出不同元素名的所有元素的总数 vector vec_CString; vec_CString.clear(); for (auto pListTpElement : vec_CElementChemistriesList) { for (auto pCElementChemistry : pListTpElement) { CString ls_CString = pCElementChemistry->GetName(); //判断是否已经添加完在字符列表中了 bool b_sfcz = false; for (int i = 0; i < vec_CString.size(); i++) { if (vec_CString[i] == ls_CString) { b_sfcz = true; break; } } //判断是否在不显示的元素列表中 for (int i = 0; i < vec_NotDisplayed.size(); i++) { if (vec_NotDisplayed[i] == ls_CString) { b_sfcz = true; break; } } //未添加进列表中,及不在不显示的元素列表中的话,对该元素进行添加 if (b_sfcz == false) { vec_CString.push_back(ls_CString); } } } ////获得了总数后,再添加Column, for (unsigned int i = 0; i < vec_CString.size(); i++) { CGridColumnPtr pColumn = CGridColumnPtr(new CGridColumn()); pColumn->SetName(vec_CString[i]); CGridRowsList listGridRows; listGridRows.clear(); for (auto pParticle : listPartReport) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); int XrayId = pParticle->GetAnalysisId(); int nFieldId = pParticle->GetFieldId(); auto itr = std::find_if(a_listXray.begin(), a_listXray.end(), [XrayId, nFieldId](CPosXrayPtr p) { return ((p->GetScanFieldId() == nFieldId) && (p->GetIndex() == XrayId)); }); if (itr == a_listXray.end()) { break; } else { //找到了的情况下,与之对应取出 CPosXrayPtr pXray = *itr; CElementChemistriesList listTpElement = pXray->GetElementQuantifyData(); for (int k = 0; k < (int)listTpElement.size(); k++) { if (listTpElement[k]->GetName() == vec_CString[i]) { //对应到了该列,将重量比添加到row中 pGridRow->SetDoubleValue(listTpElement[k]->GetPercentage()); } } //pGridRow->SetDoubleValue(listTpElement[0]->GetPercentage()); } //从该颗粒中,查找与vec_CString[i]对应的元素,找到的话,取出重量比 listGridRows.push_back(pGridRow); } pColumn->SetGridRowsList(listGridRows); listGridColumn.push_back(pColumn); } //reset load param file //过滤要显示的列 CGridColumnsList::iterator itr = listGridColumn.begin(); while (itr != listGridColumn.end()) { if (EstimateShowColumn((*itr)->GetName()) == false) { itr = listGridColumn.erase(itr); continue; } itr++; } a_pGridData->SetGridColumnList(listGridColumn); return TRUE; } //判断该列是否要显示 BOOL CReportProjFileMgr::EstimateShowColumn(CString a_strColName) { CString str_Area_Enum = "Area"; CString str_MaxDiameter_Enum = "MaxDiameter"; CString str_MinDiameter_Enum = "MinDiameter"; CString str_DiameterRatio_Enum = "DiameterRatio"; CString str_EquivalentCircleDiameter_Enum = "EquivalentCircleDiameter"; CString str_FerretDiameter_Enum = "FerretDiameter"; CString str_Area_CN = "颗粒面积"; CString str_MaxDiameter_CN = "最长直径"; CString str_MinDiameter_CN = "最短直径"; CString str_DiameterRatio_CN = "长短直径比"; CString str_EquivalentCircleDiameter_CN = "等效圆直径"; CString str_FerretDiameter_CN = "费雷特直径"; //最后再根据设置默认显示列名,对不需要显示的列进行屏蔽 CString s_DefaultComputedColName = m_rptparamfile->GetDefaultComputedColName(); if (a_strColName.Find(str_Area_CN, 0) > -1 || a_strColName.Find(str_MaxDiameter_CN, 0) > -1 || a_strColName.Find(str_MinDiameter_CN, 0) > -1 || a_strColName.Find(str_DiameterRatio_CN, 0) > -1 || a_strColName.Find(str_EquivalentCircleDiameter_CN, 0) > -1 || a_strColName.Find(str_FerretDiameter_CN, 0) > -1) { //面积 if (s_DefaultComputedColName.Find(str_Area_Enum) > -1 && a_strColName.Find(str_Area_CN, 0) > -1) { return true; } //最长直径 if (s_DefaultComputedColName.Find(str_MaxDiameter_Enum) > -1 && a_strColName.Find(str_MaxDiameter_CN, 0) > -1) { return true; } //最短直径 if (s_DefaultComputedColName.Find(str_MinDiameter_Enum) > -1 && a_strColName.Find(str_MinDiameter_CN, 0) > -1) { return true; } //长短直径比 if (s_DefaultComputedColName.Find(str_DiameterRatio_Enum) > -1 && a_strColName.Find(str_DiameterRatio_CN, 0) > -1) { return true; } //等效圆直径 if (s_DefaultComputedColName.Find(str_EquivalentCircleDiameter_Enum) > -1 && a_strColName.Find(str_EquivalentCircleDiameter_CN, 0) > -1) { return true; } //费雷特直径 if (s_DefaultComputedColName.Find(str_FerretDiameter_Enum) > -1 && a_strColName.Find(str_FerretDiameter_CN, 0) > -1) { return true; } return false; } return true; } // compute particle component CGridDatasList CReportProjFileMgr::CompParticleComponent() { // use the dll resource AFX_MANAGE_STATE(AfxGetStaticModuleState()); CGridDatasList listGridData; listGridData.clear(); std::vector listDataSource = m_CurrentPropParam->GetDataSourceList(); int nSelectedDataSourceIndex = m_CurrentPropParam->GetDataSourceId(); CString sDataSourceNames = listDataSource[nSelectedDataSourceIndex]; std::vector listSelectedDataSource = COTSHelper::SplitString(sDataSourceNames, _T("+")); //int nIndex = 0; for (auto strDataSourceName : listSelectedDataSource) { CGridDataPtr pGridData = CGridDataPtr(new CGridData()); // data source id pGridData->SetDataSourceList(m_CurrentPropParam->GetDataSourceList()); pGridData->SetDataSourceId(m_CurrentPropParam->GetDataSourceId()); COTSParticleList* pSelectidParts; COTSParticleList listParticleAll; COTSParticleList seleParticles; // add filter select particle if (m_CurrentPropParam->GetDataSourceType() == DATA_SOURCE_TYPE::SELECTION) { seleParticles = m_CurrentPropParam->GetSelectParticle(); pSelectidParts = &seleParticles; } else { listParticleAll = GetAnalysisParticleList(strDataSourceName); pSelectidParts = &listParticleAll; } //get pixel size CSmplMsrResultFileMgrPtr pSmplMsrResultFileMgr = this->GetASmplMsrResultMgrByFileName(strDataSourceName); ASSERT(pSmplMsrResultFileMgr); if (!pSmplMsrResultFileMgr) { LogErrorTrace(__FILE__, __LINE__, _T("CompParticleComponent: can't get sample result file manager.")); return listGridData; } CSmplMsrResultFilePtr pSmplMsrResultFile = pSmplMsrResultFileMgr->GetSmplMsrResultFile(); ASSERT(pSmplMsrResultFile); if (!pSmplMsrResultFile) { LogErrorTrace(__FILE__, __LINE__, _T("CompParticleComponent: can't get sample result file.")); return listGridData; } COTSSamplePtr pSample = pSmplMsrResultFile->GetSample(); ASSERT(pSample); if (!pSample) { LogErrorTrace(__FILE__, __LINE__, _T("CompParticleComponent: can't get sample.")); return listGridData; } double dPixelSize = pSample->CalculatePixelSize(); if (!GetComponentFromParticleList(*pSelectidParts, m_CurrentPropParam->GetSizeCalMethodType(), dPixelSize, pGridData)) { LogErrorTrace(__FILE__, __LINE__, _T("CompParticleComponent: can't get general information.")); return listGridData; } listGridData.push_back(pGridData); } return listGridData; } BOOL CReportProjFileMgr::GetComponentFromParticleList(COTSParticleList a_listParticle, OTSMODEL::SIZE_CAL_METHOD_TYPE a_nMethod, double a_dPixelSize, CGridDataPtr a_pGridData) { // use the dll resource AFX_MANAGE_STATE(AfxGetStaticModuleState()); ASSERT(a_pGridData); if (!a_pGridData) { LogErrorTrace(__FILE__, __LINE__, _T("GetComponentFromParticleList: invalid grid data pointer.")); return FALSE; } //// std //ASSERT(m_pReportProjFile); //if (!m_pReportProjFile) //{ // LogErrorTrace(__FILE__, __LINE__, _T("GetComponentFromParticleList: empty project file.")); // return FALSE; //} //CPartSTDDataPtr pPartSTDData = m_pReportProjFile->GetPartSTDData(); //ASSERT(pPartSTDData); //if (!pPartSTDData) //{ // LogErrorTrace(__FILE__, __LINE__, _T("GetComponentFromParticleList: invalid STD data.")); // return FALSE; //} //CSTDItemsList listSTDItem = pPartSTDData->GetSTDItemsList(); //if (listSTDItem.empty()) //{ // LogErrorTrace(__FILE__, __LINE__, _T("GetComponentFromParticleList: empty STD Item.")); // return FALSE; //} //get the same type particle together map mapSameSTDItemPartList; map::iterator partListIter; this->GetSTDMapedParticleList(a_listParticle, &mapSameSTDItemPartList); /*CSTDItemsList listHavePartSTDItem; for (auto STDItem : listSTDItem) { auto partListIter = mapSameSTDItemPartList.find(STDItem->GetSTDId()); if (partListIter != mapSameSTDItemPartList.end()) { listHavePartSTDItem.push_back(STDItem); } }*/ int nColumnNum = ((int)(REPORT_PARTICLE_COMPONENT_GRID_CLUMN::MAX) - (int)(REPORT_PARTICLE_COMPONENT_GRID_CLUMN::MIN) + 1); std::vector listColumnName; LoadColumnString(listColumnName, IDS_PARTICLE_COMPONENT_START, nColumnNum); if ((int)listColumnName.size() != nColumnNum) { LogErrorTrace(__FILE__, __LINE__, _T("GetComponentFromParticleList: Can't get column name number.")); return FALSE; } CGridColumnsList listGridColumn; COTSParticleList listPartReport; for (int i = 0; i < nColumnNum; i++) { CGridColumnPtr pColumn = CGridColumnPtr(new CGridColumn()); pColumn->SetName(listColumnName[i]); CGridRowsList listGridRows; listGridRows.clear(); switch (i) { case (int)REPORT_PARTICLE_COMPONENT_GRID_CLUMN::NAME: { // std item name listGridRows.clear(); for (auto STDPart : mapSameSTDItemPartList) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING); std::string name = STDPart.second[0]->TypeName(); //pGridRow->SetStringValue(STDPart->GetName ()); pGridRow->SetStringValue(name.c_str()); listGridRows.push_back(pGridRow); } auto itr = mapSameSTDItemPartList.find((int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED); if (itr != mapSameSTDItemPartList.end()) { CGridRowPtr pGridRowUndefined = CGridRowPtr(new CGridRow()); pGridRowUndefined->SetDataType(REPORT_GRID_DATA_TYPE::STRING); CString strUndefined; strUndefined = MultiLang::GetInstance().GetCStringByKey(IDS_UNDEFINED_PARTICLE); pGridRowUndefined->SetStringValue(strUndefined); listGridRows.push_back(pGridRowUndefined); } auto itrSiC = mapSameSTDItemPartList.find((int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED_SIC); if (itrSiC != mapSameSTDItemPartList.end()) { CGridRowPtr pGridRowSiC = CGridRowPtr(new CGridRow()); pGridRowSiC->SetDataType(REPORT_GRID_DATA_TYPE::STRING); CString strSiC; strSiC = MultiLang::GetInstance().GetCStringByKey(IDS_SIC); pGridRowSiC->SetStringValue(strSiC); listGridRows.push_back(pGridRowSiC); } auto itrFeO = mapSameSTDItemPartList.find((int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED_FEO); if (itrFeO != mapSameSTDItemPartList.end()) { CGridRowPtr pGridRowFeO = CGridRowPtr(new CGridRow()); pGridRowFeO->SetDataType(REPORT_GRID_DATA_TYPE::STRING); CString strFeO; strFeO = MultiLang::GetInstance().GetCStringByKey(IDS_FEO); pGridRowFeO->SetStringValue(strFeO); listGridRows.push_back(pGridRowFeO); } } break; case (int)REPORT_PARTICLE_COMPONENT_GRID_CLUMN::COLOUR: { // std item color listGridRows.clear(); for (auto STDPart : mapSameSTDItemPartList) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING); std::string color = STDPart.second[0]->TypeColor(); pGridRow->SetStringValue(color.c_str()); listGridRows.push_back(pGridRow); } auto itr = mapSameSTDItemPartList.find((int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED); if (itr != mapSameSTDItemPartList.end()) { CGridRowPtr pGridRowUndefined = CGridRowPtr(new CGridRow()); pGridRowUndefined->SetDataType(REPORT_GRID_DATA_TYPE::STRING); CString strUndefinedColour = _T(""); pGridRowUndefined->SetStringValue(strUndefinedColour); listGridRows.push_back(pGridRowUndefined); } auto itrSiC = mapSameSTDItemPartList.find((int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED_SIC); if (itrSiC != mapSameSTDItemPartList.end()) { CGridRowPtr pGridRowSiC = CGridRowPtr(new CGridRow()); pGridRowSiC->SetDataType(REPORT_GRID_DATA_TYPE::STRING); CString strSiCColour = _T(""); pGridRowSiC->SetStringValue(strSiCColour); listGridRows.push_back(pGridRowSiC); } auto itrFeO = mapSameSTDItemPartList.find((int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED_FEO); if (itrFeO != mapSameSTDItemPartList.end()) { CGridRowPtr pGridRowFeO = CGridRowPtr(new CGridRow()); pGridRowFeO->SetDataType(REPORT_GRID_DATA_TYPE::STRING); CString strFeOColour = _T(""); pGridRowFeO->SetStringValue(strFeOColour); listGridRows.push_back(pGridRowFeO); } } break; case (int)REPORT_PARTICLE_COMPONENT_GRID_CLUMN::PARTICLE_NUM: { // get each type particle num int nParticleUndefined = 0; int nParticleSiC = 0; int nParticleFeO = 0; for (auto pSTDItem : mapSameSTDItemPartList) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::INT); int nParticleNum = pSTDItem.second.size(); pGridRow->SetIntValue(nParticleNum); listGridRows.push_back(pGridRow); } CGridRowPtr pGridRowUndefined = CGridRowPtr(new CGridRow()); pGridRowUndefined->SetDataType(REPORT_GRID_DATA_TYPE::INT); auto itr = mapSameSTDItemPartList.find((int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED); if (itr != mapSameSTDItemPartList.end()) { nParticleUndefined = itr->second.size(); } else { nParticleUndefined = 0; } if (0 != nParticleUndefined) { pGridRowUndefined->SetIntValue(nParticleUndefined); listGridRows.push_back(pGridRowUndefined); } CGridRowPtr pGridRowSiC = CGridRowPtr(new CGridRow()); pGridRowSiC->SetDataType(REPORT_GRID_DATA_TYPE::INT); auto itrSiC = mapSameSTDItemPartList.find((int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED_SIC); if (itrSiC != mapSameSTDItemPartList.end()) { nParticleSiC = itrSiC->second.size(); } else { nParticleSiC = 0; } if (0 != nParticleSiC) { pGridRowSiC->SetIntValue(nParticleSiC); listGridRows.push_back(pGridRowSiC); } CGridRowPtr pGridRowFeO = CGridRowPtr(new CGridRow()); pGridRowFeO->SetDataType(REPORT_GRID_DATA_TYPE::INT); auto itrFeO = mapSameSTDItemPartList.find((int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED_FEO); if (itrFeO != mapSameSTDItemPartList.end()) { nParticleFeO = itrFeO->second.size(); } else { nParticleFeO = 0; } if (0 != nParticleFeO) { pGridRowFeO->SetIntValue(nParticleFeO); listGridRows.push_back(pGridRowFeO); } } break; case (int)REPORT_PARTICLE_COMPONENT_GRID_CLUMN::AVE_VALUE: { // get particle average area int nParticleUndefined = 0; double dAveValueUndefined = 0; int nParticleSiC = 0; double dAveValueSiC = 0; int nParticleFeO = 0; double dAveValueFeO = 0; for (auto pSTDPart : mapSameSTDItemPartList) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); int nParticleNum = 0; double dAveValue = 0; COTSParticleList listPartReport = pSTDPart.second; for (auto pParticle : listPartReport) { double dValue = GetValueAsMethod(pParticle, a_nMethod, a_dPixelSize); nParticleNum++; dAveValue += dValue; } if (nParticleNum != 0) { dAveValue = dAveValue / (double)nParticleNum; } pGridRow->SetDoubleValue(dAveValue); listGridRows.push_back(pGridRow); } CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); auto itr = mapSameSTDItemPartList.find((int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED); if (itr != mapSameSTDItemPartList.end()) { nParticleUndefined = itr->second.size(); listPartReport = itr->second; } else { nParticleUndefined = 0; } if (nParticleUndefined != 0) { for (auto pParticle : listPartReport) { double dValue = GetValueAsMethod(pParticle, a_nMethod, a_dPixelSize); dAveValueUndefined += dValue; } if (nParticleUndefined != 0) { dAveValueUndefined = dAveValueUndefined / (double)nParticleUndefined; } pGridRow->SetDoubleValue(dAveValueUndefined); listGridRows.push_back(pGridRow); } CGridRowPtr pGridRowSiC = CGridRowPtr(new CGridRow()); pGridRowSiC->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); auto itrSiC = mapSameSTDItemPartList.find((int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED_SIC); if (itrSiC != mapSameSTDItemPartList.end()) { nParticleSiC = itrSiC->second.size(); listPartReport = itrSiC->second; } else { nParticleSiC = 0; } if (nParticleSiC != 0) { for (auto pParticle : listPartReport) { double dValue = GetValueAsMethod(pParticle, a_nMethod, a_dPixelSize); dAveValueSiC += dValue; } if (nParticleSiC != 0) { dAveValueSiC = dAveValueSiC / (double)nParticleSiC; } pGridRowSiC->SetDoubleValue(dAveValueSiC); listGridRows.push_back(pGridRowSiC); } CGridRowPtr pGridRowFeO = CGridRowPtr(new CGridRow()); pGridRowFeO->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); auto itrFeO = mapSameSTDItemPartList.find((int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED_FEO); if (itrFeO != mapSameSTDItemPartList.end()) { nParticleFeO = itrFeO->second.size(); listPartReport = itrFeO->second; } else { nParticleFeO = 0; } if (nParticleFeO != 0) { for (auto pParticle : listPartReport) { double dValue = GetValueAsMethod(pParticle, a_nMethod, a_dPixelSize); dAveValueFeO += dValue; } if (nParticleFeO != 0) { dAveValueFeO = dAveValueFeO / (double)nParticleFeO; } pGridRowFeO->SetDoubleValue(dAveValueFeO); listGridRows.push_back(pGridRowFeO); } } break; case (int)REPORT_PARTICLE_COMPONENT_GRID_CLUMN::MAX_VALUE: { // get particle max area double dMaxValueUndefined = 0; double dMaxValueSiC = 0; double dMaxValueFeO = 0; double dMaxValue = 0; for (auto pSTDPart : mapSameSTDItemPartList) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); dMaxValue = 0; COTSParticleList listPartReport = pSTDPart.second; for (auto pParticle : listPartReport) { double dValue = GetValueAsMethod(pParticle, a_nMethod, a_dPixelSize); if (dValue > dMaxValue) { dMaxValue = dValue; } } pGridRow->SetDoubleValue(dMaxValue); listGridRows.push_back(pGridRow); } CGridRowPtr pGridRowUndefined = CGridRowPtr(new CGridRow()); pGridRowUndefined->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); auto itr = mapSameSTDItemPartList.find((int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED); listPartReport.clear(); if (itr != mapSameSTDItemPartList.end()) { listPartReport = itr->second; } for (auto pParticle : listPartReport) { double dValue = GetValueAsMethod(pParticle, a_nMethod, a_dPixelSize); if (dValue > dMaxValueUndefined) { dMaxValueUndefined = dValue; } } if (itr != mapSameSTDItemPartList.end()) { pGridRowUndefined->SetDoubleValue(dMaxValueUndefined); listGridRows.push_back(pGridRowUndefined); } CGridRowPtr pGridRowSiC = CGridRowPtr(new CGridRow()); pGridRowSiC->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); auto itrSiC = mapSameSTDItemPartList.find((int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED_SIC); listPartReport.clear(); if (itrSiC != mapSameSTDItemPartList.end()) { listPartReport = itrSiC->second; } for (auto pParticle : listPartReport) { double dValue = GetValueAsMethod(pParticle, a_nMethod, a_dPixelSize); if (dValue > dMaxValueSiC) { dMaxValueSiC = dValue; } } if (itrSiC != mapSameSTDItemPartList.end()) { pGridRowSiC->SetDoubleValue(dMaxValueSiC); listGridRows.push_back(pGridRowSiC); } CGridRowPtr pGridRowFeO = CGridRowPtr(new CGridRow()); pGridRowFeO->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); auto itrFeO = mapSameSTDItemPartList.find((int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED_FEO); listPartReport.clear(); if (itrFeO != mapSameSTDItemPartList.end()) { listPartReport = itrFeO->second; } for (auto pParticle : listPartReport) { double dValue = GetValueAsMethod(pParticle, a_nMethod, a_dPixelSize); if (dValue > dMaxValueFeO) { dMaxValueFeO = dValue; } } if (itrFeO != mapSameSTDItemPartList.end()) { pGridRowFeO->SetDoubleValue(dMaxValueFeO); listGridRows.push_back(pGridRowFeO); } } break; } pColumn->SetGridRowsList(listGridRows); listGridColumn.push_back(pColumn); } a_pGridData->SetGridColumnList(listGridColumn); return TRUE; } // compute element component CGridDatasList CReportProjFileMgr::CompElementComponent() { // use the dll resource AFX_MANAGE_STATE(AfxGetStaticModuleState()); CGridDatasList listGridData; listGridData.clear(); std::vector listDataSource = m_CurrentPropParam->GetDataSourceList(); int nSelectedDataSourceIndex = m_CurrentPropParam->GetDataSourceId(); CString sDataSourceNames = listDataSource[nSelectedDataSourceIndex]; std::vector listSelectedDataSource = COTSHelper::SplitString(sDataSourceNames, _T("+")); //int nIndex = 0; for (auto strDataSourceName : listSelectedDataSource) { CGridDataPtr pGridData = CGridDataPtr(new CGridData()); // data source id pGridData->SetDataSourceList(m_CurrentPropParam->GetDataSourceList()); pGridData->SetDataSourceId(m_CurrentPropParam->GetDataSourceId()); COTSParticleList listParticleAll; listParticleAll.clear(); CPosXraysList listXrayOut; listXrayOut.clear(); CPosXraysList listXray; listXray.clear(); listXrayOut = GetAnalysisXrayList(strDataSourceName); if (m_CurrentPropParam->GetDataSourceType() == DATA_SOURCE_TYPE::ALL) { listParticleAll = GetAnalysisParticleList(strDataSourceName); for (auto pXray : listXrayOut) { CPosXrayPtr pXrayNew = CPosXrayPtr(new CPosXray(*pXray.get())); listXray.push_back(pXrayNew); } } else if (m_CurrentPropParam->GetDataSourceType() == DATA_SOURCE_TYPE::SELECTION) { listParticleAll = m_CurrentPropParam->GetSelectParticle(); for (auto pParticle : listParticleAll) { int nIndex = pParticle->GetAnalysisId(); int nField = pParticle->GetFieldId(); auto itr = std::find_if(listXrayOut.begin(), listXrayOut.end(), [nIndex, nField](CPosXrayPtr p) { return (p->GetIndex() == nIndex && p->GetScanFieldId() == nField); }); if (itr == listXrayOut.end()) { continue; } else { CPosXrayPtr pXray = *itr; CPosXrayPtr pXrayNew = CPosXrayPtr(new CPosXray(*pXray.get())); listXray.push_back(pXrayNew); } } } if (!GetElementComponentFromParticleList(listParticleAll, listXray, pGridData)) { LogErrorTrace(__FILE__, __LINE__, _T("CompParticleComponent: can't get general information.")); return listGridData; } listGridData.push_back(pGridData); } return listGridData; } BOOL CReportProjFileMgr::GetElementComponentFromParticleList(COTSParticleList a_listParticleAll, CPosXraysList a_listXray, CGridDataPtr a_pGridData) { // use the dll resource AFX_MANAGE_STATE(AfxGetStaticModuleState()); ASSERT(a_pGridData); if (!a_pGridData) { LogErrorTrace(__FILE__, __LINE__, _T("GetElementComponentFromParticleList: invalid grid data pointer.")); return FALSE; } // std ASSERT(m_pReportProjFile); if (!m_pReportProjFile) { LogErrorTrace(__FILE__, __LINE__, _T("GetElementComponentFromParticleList: empty project file.")); return FALSE; } int nColumnNum = ((int)(REPORT_ELEMENT_COMPONENT_GRID_CLUMN::MAX) - (int)(REPORT_ELEMENT_COMPONENT_GRID_CLUMN::MIN) + 1); std::vector listColumnName; LoadColumnString(listColumnName, IDS_ELEMENT_COMPONENT_START, nColumnNum); if ((int)listColumnName.size() != nColumnNum) { LogErrorTrace(__FILE__, __LINE__, _T("GetElementComponentFromParticleList: Can't get column name number.")); return FALSE; } COTSParticleList listParticleAnalysis; listParticleAnalysis.clear(); for (auto pParticle : a_listParticleAll) { int nType = pParticle->GetType(); if (nType >= (int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED_SIC) { COTSParticlePtr pParticleNew = COTSParticlePtr(new COTSParticle(*pParticle.get())); listParticleAnalysis.push_back(pParticleNew); } } CElementChemistriesList listElementResult = GetUndefinedElementList(listParticleAnalysis, a_listXray); //Draw the grid CGridColumnsList listGridColumn; for (int i = 0; i < nColumnNum; i++) { CGridColumnPtr pColumn = CGridColumnPtr(new CGridColumn()); pColumn->SetName(listColumnName[i]); CGridRowsList listGridRows; listGridRows.clear(); switch (i) { case (int)REPORT_ELEMENT_COMPONENT_GRID_CLUMN::NAME: { // std item name listGridRows.clear(); for (auto pElement : listElementResult) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING); CString strElementName = pElement->GetName(); pGridRow->SetStringValue(strElementName); listGridRows.push_back(pGridRow); } } break; case (int)REPORT_ELEMENT_COMPONENT_GRID_CLUMN::NUM: { // std item name listGridRows.clear(); for (auto pElement : listElementResult) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING); CString strElementNum = _T(""); double dPercent = pElement->GetPercentage(); strElementNum.Format(_T("%f"), dPercent); strElementNum += "%"; pGridRow->SetStringValue(strElementNum); listGridRows.push_back(pGridRow); } } break; } pColumn->SetGridRowsList(listGridRows); listGridColumn.push_back(pColumn); } a_pGridData->SetGridColumnList(listGridColumn); return TRUE; } // compute particle size distribution CGridDatasList CReportProjFileMgr::CompParticleSizeDistribution() { // use the dll resource AFX_MANAGE_STATE(AfxGetStaticModuleState()); CGridDatasList listGridData; listGridData.clear(); // depart compound source name std::vector listDataSource = m_CurrentPropParam->GetDataSourceList(); int nSelectedDataSourceIndex = m_CurrentPropParam->GetDataSourceId(); CString sDataSourceNames = listDataSource[nSelectedDataSourceIndex]; std::vector listSelectedDataSource = COTSHelper::SplitString(sDataSourceNames, _T("+")); //int nIndex = 0; for (auto strDataSourceName : listSelectedDataSource) { CGridDataPtr pGridData = CGridDataPtr(new CGridData()); // data source id std::vector listDataSource; listDataSource.clear(); listDataSource = m_CurrentPropParam->GetDataSourceList(); pGridData->SetDataSourceList(listDataSource); int nDataSourceId = m_CurrentPropParam->GetDataSourceId(); pGridData->SetDataSourceId(nDataSourceId); COTSParticleList* pSelectidParts; COTSParticleList listParticleAll; COTSParticleList seleParticles; // add filter select particle if (m_CurrentPropParam->GetDataSourceType() == DATA_SOURCE_TYPE::SELECTION) { seleParticles = m_CurrentPropParam->GetSelectParticle(); pSelectidParts = &seleParticles; } else { listParticleAll = GetAnalysisParticleList(strDataSourceName); pSelectidParts = &listParticleAll; } //get pixel size CSmplMsrResultFileMgrPtr pSmplMsrResultFileMgr = this->GetASmplMsrResultMgrByFileName(strDataSourceName); ASSERT(pSmplMsrResultFileMgr); if (!pSmplMsrResultFileMgr) { LogErrorTrace(__FILE__, __LINE__, _T("CompParticleSizeDistribution: can't get sample result file manager.")); return listGridData; } CSmplMsrResultFilePtr pSmplMsrResultFile = pSmplMsrResultFileMgr->GetSmplMsrResultFile(); ASSERT(pSmplMsrResultFile); if (!pSmplMsrResultFile) { LogErrorTrace(__FILE__, __LINE__, _T("CompParticleSizeDistribution: can't get sample result file.")); return listGridData; } COTSSamplePtr pSample = pSmplMsrResultFile->GetSample(); if (!pSample) { LogErrorTrace(__FILE__, __LINE__, _T("CompParticleSizeDistribution: can't get sample.")); return listGridData; } double dPixelSize = pSample->CalculatePixelSize(); if (!GetSizeDistributionFromParticleList(*pSelectidParts, pGridData, dPixelSize)) { LogErrorTrace(__FILE__, __LINE__, _T("CompParticleSizeDistribution: can't get general information.")); return listGridData; } listGridData.push_back(pGridData); } return listGridData; } BOOL CReportProjFileMgr::IsHaveMultiDataSource() { int nMultiCount = 0; for (auto SmplMgr : m_listSmplMgrs) { CSmplMsrResultFilePtr pSmpl = SmplMgr->GetSmplMsrResultFile(); if (pSmpl->GetSwitch()) { nMultiCount++; } } if (nMultiCount > 1) { return TRUE; } return FALSE; } BOOL CReportProjFileMgr::GetSizeDistributionFromParticleList(COTSParticleList a_listParticle, CGridDataPtr a_pGridData, double a_dPixelSize) { // use the dll resource AFX_MANAGE_STATE(AfxGetStaticModuleState()); ASSERT(a_pGridData); if (!a_pGridData) { LogErrorTrace(__FILE__, __LINE__, _T("GetSizeDistributionFromParticleList: invalid grid data pointer.")); return FALSE; } //size CPartSizeFilePtr pPartSize = m_CurrentPropParam->GetWorkingSizeFile(); ASSERT(pPartSize); if (!pPartSize) { LogErrorTrace(__FILE__, __LINE__, _T("GetSizeDistributionFromParticleList: invalid pPartSize data.")); return FALSE; } CPartSizeItemList listPartSize = pPartSize->GetPartSizeList(); if (listPartSize.empty()) { LogErrorTrace(__FILE__, __LINE__, _T("GetSizeDistributionFromParticleList: empty pPartSize Item.")); return FALSE; } //get the same type particle together map mapSameSTDItemPartList; map::iterator partListIter; this->GetSTDMapedParticleList(a_listParticle, &mapSameSTDItemPartList); COTSParticleList listNotIdentified; for (auto partListIter = mapSameSTDItemPartList.begin(); partListIter != mapSameSTDItemPartList.end(); partListIter++) { if (partListIter->first == (int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED) { listNotIdentified = partListIter->second; } } COTSParticleList listSiC; for (auto partListIter = mapSameSTDItemPartList.begin(); partListIter != mapSameSTDItemPartList.end(); partListIter++) { if (partListIter->first == (int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED_SIC) { listSiC = partListIter->second; } } COTSParticleList listFeO; for (auto partListIter = mapSameSTDItemPartList.begin(); partListIter != mapSameSTDItemPartList.end(); partListIter++) { if (partListIter->first == (int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED_FEO) { listFeO = partListIter->second; } } int nColumnNum = ((int)(REPORT_SIZE_DISTRIBUTION_GRID_CLUMN::MAX) - (int)(REPORT_SIZE_DISTRIBUTION_GRID_CLUMN::MIN) + 1); std::vector listColumnName; LoadColumnString(listColumnName, IDS_PARTICLE_COMPONENT_START, nColumnNum); if ((int)listColumnName.size() != nColumnNum) { LogErrorTrace(__FILE__, __LINE__, _T("GetComponentFromParticleList: Can't get column name number.")); return FALSE; } CGridColumnsList listGridColumn; for (int i = 0; i < nColumnNum; i++) { CGridColumnPtr pColumn = CGridColumnPtr(new CGridColumn()); pColumn->SetName(listColumnName[i]); CGridRowsList listGridRows; listGridRows.clear(); switch (i) { case (int)REPORT_SIZE_DISTRIBUTION_GRID_CLUMN::NAME: { // std item name listGridRows.clear(); for (auto sItemName : mapSameSTDItemPartList) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING); pGridRow->SetStringValue(sItemName.second[0]->TypeName().c_str()); listGridRows.push_back(pGridRow); } if (!listNotIdentified.empty()) { CGridRowPtr pGridRowUndefined = CGridRowPtr(new CGridRow()); pGridRowUndefined->SetDataType(REPORT_GRID_DATA_TYPE::STRING); CString strUndefined; strUndefined = MultiLang::GetInstance().GetCStringByKey(IDS_UNDEFINED_PARTICLE);//“未识别颗粒” pGridRowUndefined->SetStringValue(strUndefined); listGridRows.push_back(pGridRowUndefined); } if (!listSiC.empty()) { CGridRowPtr pGridRowSiC = CGridRowPtr(new CGridRow()); pGridRowSiC->SetDataType(REPORT_GRID_DATA_TYPE::STRING); CString strSIC; strSIC = MultiLang::GetInstance().GetCStringByKey(IDS_SIC);//“未识别颗粒SiC” pGridRowSiC->SetStringValue(strSIC); listGridRows.push_back(pGridRowSiC); } if (!listFeO.empty()) { CGridRowPtr pGridRowFeO = CGridRowPtr(new CGridRow()); pGridRowFeO->SetDataType(REPORT_GRID_DATA_TYPE::STRING); CString strFeO; strFeO = MultiLang::GetInstance().GetCStringByKey(IDS_FEO);//“未识别颗粒” pGridRowFeO->SetStringValue(strFeO); listGridRows.push_back(pGridRowFeO); } //个数 CGridRowPtr pGridRowNum = CGridRowPtr(new CGridRow()); pGridRowNum->SetDataType(REPORT_GRID_DATA_TYPE::STRING); CString strNum; strNum = MultiLang::GetInstance().GetCStringByKey(IDS_NUM); pGridRowNum->SetStringValue(strNum); listGridRows.push_back(pGridRowNum); break; } case (int)REPORT_SIZE_DISTRIBUTION_GRID_CLUMN::COLOUR: { // std item colour listGridRows.clear(); for (auto parts : mapSameSTDItemPartList) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING); pGridRow->SetStringValue(parts.second[0]->TypeColor().c_str()); listGridRows.push_back(pGridRow); } if (!listNotIdentified.empty()) { CGridRowPtr pGridRowUndefined = CGridRowPtr(new CGridRow()); pGridRowUndefined->SetDataType(REPORT_GRID_DATA_TYPE::STRING); CString strUndefinedColour = _T(""); pGridRowUndefined->SetStringValue(strUndefinedColour); listGridRows.push_back(pGridRowUndefined); } if (!listSiC.empty()) { CGridRowPtr pGridRowSiC = CGridRowPtr(new CGridRow()); pGridRowSiC->SetDataType(REPORT_GRID_DATA_TYPE::STRING); CString strSiCColour = _T(""); pGridRowSiC->SetStringValue(strSiCColour); listGridRows.push_back(pGridRowSiC); } if (!listFeO.empty()) { CGridRowPtr pGridRowFeO = CGridRowPtr(new CGridRow()); pGridRowFeO->SetDataType(REPORT_GRID_DATA_TYPE::STRING); CString strFeOColour = _T(""); pGridRowFeO->SetStringValue(strFeOColour); listGridRows.push_back(pGridRowFeO); } //颜色行补齐行 CGridRowPtr pGridRowNum = CGridRowPtr(new CGridRow()); pGridRowNum->SetDataType(REPORT_GRID_DATA_TYPE::STRING); CString strColorNumber = _T(""); pGridRowNum->SetStringValue(strColorNumber); listGridRows.push_back(pGridRowNum); break; } } pColumn->SetGridRowsList(listGridRows); listGridColumn.push_back(pColumn); } //ParticleAmount double dParticleAmount = 0; for (unsigned int i = 0; i < a_listParticle.size(); i++) { if (a_listParticle[i]->GetAnalysisId() > -1) dParticleAmount++; } //add item for (auto partsizeItem : listPartSize) { CDoubleRangePtr level = partsizeItem->GetSizeLevel(); double dStart = level->GetStart(); double dEnd = level->GetEnd(); CString ColumnName = _T(""); //ColumnName = dStart + "-" + dEnd; ColumnName = partsizeItem->GetName(); CGridColumnPtr pColumn = CGridColumnPtr(new CGridColumn()); pColumn->SetName(ColumnName); double dColumnAmount = 0; CGridRowsList listGridRows; listGridRows.clear(); int nTypeId; double dParticleUndefined = (double)listNotIdentified.size(); double dParticleSiC = (double)listNotIdentified.size(); double dParticleFeO = (double)listNotIdentified.size(); for (auto pSTDPart : mapSameSTDItemPartList) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::INT); bool bAdd = true; double dParticleNum = 0; for (auto pParticle : pSTDPart.second) { SIZE_CAL_METHOD_TYPE Method = m_CurrentPropParam->GetSizeCalMethodType(); double dValue = GetValueAsMethod(pParticle, Method, a_dPixelSize); if (dValue >= dStart && dValue < dEnd) { dParticleNum++; } } pGridRow->SetIntValue((int)dParticleNum); listGridRows.push_back(pGridRow); dColumnAmount += dParticleNum; } if (!listNotIdentified.empty()) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::INT); double dParticleNumCount = 0; for (auto undefinedPart : listNotIdentified) { SIZE_CAL_METHOD_TYPE Method = m_CurrentPropParam->GetSizeCalMethodType(); double dValue = GetValueAsMethod(undefinedPart, Method, a_dPixelSize); if (dValue >= dStart && dValue < dEnd) { dParticleNumCount++; } } pGridRow->SetIntValue((int)dParticleNumCount); listGridRows.push_back(pGridRow); dColumnAmount += dParticleNumCount; } //percent if (!listSiC.empty()) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::INT); int dParticleNumCount = 0; for (auto undefinedPart : listSiC) { SIZE_CAL_METHOD_TYPE Method = m_CurrentPropParam->GetSizeCalMethodType(); double dValue = GetValueAsMethod(undefinedPart, Method, a_dPixelSize); if (dValue >= dStart && dValue < dEnd) { dParticleNumCount++; } } pGridRow->SetIntValue((int)dParticleNumCount); listGridRows.push_back(pGridRow); dColumnAmount += dParticleNumCount; } //percent if (!listFeO.empty()) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::INT); int dParticleNumCount = 0; for (auto undefinedPart : listFeO) { SIZE_CAL_METHOD_TYPE Method = m_CurrentPropParam->GetSizeCalMethodType(); double dValue = GetValueAsMethod(undefinedPart, Method, a_dPixelSize); if (dValue >= dStart && dValue < dEnd) { dParticleNumCount++; } } pGridRow->SetIntValue((int)dParticleNumCount); listGridRows.push_back(pGridRow); dColumnAmount += dParticleNumCount; } CGridRowPtr pGridRow2 = CGridRowPtr(new CGridRow()); pGridRow2->SetDataType(REPORT_GRID_DATA_TYPE::STRING); double dAPercent = dColumnAmount / dParticleAmount; char cColumnAmount[256]; sprintf(cColumnAmount, "%.0lf", dColumnAmount); char cRes[256]; sprintf(cRes, "%.2lf%%\n", dAPercent * 100); CString strResult = cRes; strResult = "" + (CString)cColumnAmount + "(" + strResult + ")"; pGridRow2->SetStringValue(strResult); listGridRows.push_back(pGridRow2); //addcolum pColumn->SetGridRowsList(listGridRows); listGridColumn.push_back(pColumn); } a_pGridData->SetGridColumnList(listGridColumn); return TRUE; } // compute average element component CGridDatasList CReportProjFileMgr::CompAveElemnetComponent() { // use the dll resource AFX_MANAGE_STATE(AfxGetStaticModuleState()); CGridDatasList listGridData; listGridData.clear(); // depart compound source name std::vector listDataSource = m_CurrentPropParam->GetDataSourceList(); int nSelectedDataSourceIndex = m_CurrentPropParam->GetDataSourceId(); CString sDataSourceNames = listDataSource[nSelectedDataSourceIndex]; std::vector listSelectedDataSource = COTSHelper::SplitString(sDataSourceNames, _T("+")); //int nIndex = 0; for (auto strDataSourceName : listSelectedDataSource) { CGridDataPtr pGridData = CGridDataPtr(new CGridData()); // data source id std::vector listDataSource; listDataSource.clear(); listDataSource = m_CurrentPropParam->GetDataSourceList(); pGridData->SetDataSourceList(listDataSource); int nDataSourceId = m_CurrentPropParam->GetDataSourceId(); pGridData->SetDataSourceId(nDataSourceId); COTSParticleList listParticleAll; listParticleAll.clear(); CPosXraysList listXrayOut; listXrayOut.clear(); CPosXraysList listXray; listXray.clear(); listXrayOut = GetAnalysisXrayList(strDataSourceName); if (m_CurrentPropParam->GetDataSourceType() == DATA_SOURCE_TYPE::ALL) { listParticleAll = GetAnalysisParticleList(strDataSourceName); for (auto pXray : listXrayOut) { CPosXrayPtr pXrayNew = CPosXrayPtr(new CPosXray(*pXray.get())); listXray.push_back(pXrayNew); } } else if (m_CurrentPropParam->GetDataSourceType() == DATA_SOURCE_TYPE::SELECTION) { listParticleAll = m_CurrentPropParam->GetSelectParticle(); for (auto pParticle : listParticleAll) { int nIndex = pParticle->GetAnalysisId(); int nField = pParticle->GetFieldId(); auto itr = std::find_if(listXrayOut.begin(), listXrayOut.end(), [nIndex, nField](CPosXrayPtr p) { return (p->GetIndex() == nIndex && p->GetScanFieldId() == nField); }); if (itr == listXrayOut.end()) { continue; } else { CPosXrayPtr pXray = *itr; CPosXrayPtr pXrayNew = CPosXrayPtr(new CPosXray(*pXray.get())); listXray.push_back(pXrayNew); } } } if (!GetAveElementFromParticleList(listParticleAll, listXray, pGridData)) { LogErrorTrace(__FILE__, __LINE__, _T("CompParticleComponent: can't get general information.")); return listGridData; } listGridData.push_back(pGridData); //nIndex++; } return listGridData; } BOOL CReportProjFileMgr::GetAveElementFromParticleList(COTSParticleList a_listParticleAll, CPosXraysList a_listXray, CGridDataPtr a_pGridData) { // use the dll resource AFX_MANAGE_STATE(AfxGetStaticModuleState()); ASSERT(a_pGridData); if (!a_pGridData) { LogErrorTrace(__FILE__, __LINE__, _T("GetAveElementFromParticleList: invalid grid data pointer.")); return FALSE; } // std ASSERT(m_pReportProjFile); if (!m_pReportProjFile) { LogErrorTrace(__FILE__, __LINE__, _T("GetAveElementFromParticleList: empty project file.")); return FALSE; } std::set allTypeIds; allTypeIds.clear(); COTSParticleList listNotIdentifiedParticle; listNotIdentifiedParticle.clear(); COTSParticleList listSiCParticle; listSiCParticle.clear(); COTSParticleList listFeOParticle; listFeOParticle.clear(); COTSParticleList listIdentifiedParticle; listIdentifiedParticle.clear(); std::vector listElementChemistriesList; listElementChemistriesList.clear(); for (auto pParticle : a_listParticleAll) { int nType = (int)pParticle->GetType(); // get undefined particle and analysis particle if (nType >= (int)OTS_PARTCLE_TYPE::NO_ANALYSIS_X_RAY) { COTSParticlePtr pParticleNew = COTSParticlePtr(new COTSParticle(*pParticle.get())); if (nType == (int)OTS_PARTCLE_TYPE::NO_ANALYSIS_X_RAY)//不与考虑 { //listNoAnalysisParticle.push_back(pParticleNew); } else if (nType == (int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED) { listNotIdentifiedParticle.push_back(pParticleNew); } else if (nType == (int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED_SIC) { listSiCParticle.push_back(pParticleNew); } else if (nType == (int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED_FEO) { listFeOParticle.push_back(pParticleNew); } else if (nType >= (int)OTS_PARTCLE_TYPE::USER_DEFINED_MIN)//类型ID号至少1000以上 { listIdentifiedParticle.push_back(pParticleNew); allTypeIds.insert(nType); } } } //CPartSTDDataPtr pPartSTDData = m_pReportProjFile->GetPartSTDData(); //ASSERT(pPartSTDData); //if (!pPartSTDData) //{ // LogErrorTrace(__FILE__, __LINE__, _T("GetSizeDistributionFromParticleList: invalid STD data.")); // return FALSE; //} //CSTDItemsList listSTDItem = pPartSTDData->GetSTDItemsList(); //if (listSTDItem.empty()) //{ // LogErrorTrace(__FILE__, __LINE__, _T("GetSizeDistributionFromParticleList: empty STD Item.")); // return FALSE; //} COTSParticleList listPartReport; //get the same type particle together map mapSameSTDItemPartList; map::iterator partListIter; this->GetSTDMapedParticleList(a_listParticleAll, &mapSameSTDItemPartList); // make the first two columns: particle type and area CGridColumnsList listGridColumn; CGridRowsList listParticleGridRows; listParticleGridRows.clear(); CGridRowsList listAreaGridRows; listAreaGridRows.clear(); COTSParticleList listParticleType; COTSParticleList particlesOfThisType; listParticleType.clear(); particlesOfThisType.clear(); double dAreaTotal = 0; for (auto typeId : allTypeIds) { auto iterParts = mapSameSTDItemPartList.find(typeId); if (iterParts == mapSameSTDItemPartList.end()) { continue; } else { particlesOfThisType = iterParts->second; } CGridRowPtr pParticleGridRow = CGridRowPtr(new CGridRow()); pParticleGridRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING); //CSTDItemPtr STDItem = GetParticleSTDItem(typeId); //CSTDItemPtr STDItem = particlesOfThisType[0]->TypeName(); CString strPartName = particlesOfThisType[0]->TypeName().c_str(); pParticleGridRow->SetStringValue(strPartName); listParticleGridRows.push_back(pParticleGridRow); CGridRowPtr pAreaGridRow = CGridRowPtr(new CGridRow()); pAreaGridRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); double dArea = 0; for (auto pPatTp : particlesOfThisType) { double dAreaC = pPatTp->GetArea(); dArea += dAreaC; } pAreaGridRow->SetDoubleValue(dArea); listAreaGridRows.push_back(pAreaGridRow); dAreaTotal += dArea; // compute Element COTSParticlePtr pParticle = particlesOfThisType[0]; COTSParticlePtr pParticleNew = COTSParticlePtr(new COTSParticle(*pParticle.get())); listParticleType.push_back(pParticleNew); int XrayId = pParticle->GetAnalysisId(); if (XrayId < 0 || XrayId >(int)a_listXray.size()) { continue; } int nFieldId = pParticle->GetFieldId(); auto itr = std::find_if(a_listXray.begin(), a_listXray.end(), [XrayId, nFieldId](CPosXrayPtr p) { return ((p->GetScanFieldId() == nFieldId) && (p->GetIndex() == XrayId)); }); if (itr == a_listXray.end()) { LogErrorTrace(__FILE__, __LINE__, _T("GetAveElementFromParticleList: can't find x-ray.")); return FALSE; } CPosXrayPtr pXray = *itr; CElementChemistriesList listTpElement = pXray->GetElementQuantifyData(); listElementChemistriesList.push_back(listTpElement); } //undefined particle area double dAreaNotIden = 0; for (auto pPUn : listNotIdentifiedParticle) { double dA = pPUn->GetArea(); dAreaNotIden += dA; } dAreaTotal += dAreaNotIden; double dAreaSiC = 0; for (auto pPUn : listSiCParticle) { double dA = pPUn->GetArea(); dAreaSiC += dA; } dAreaTotal += dAreaSiC; double dAreaFeO = 0; for (auto pPUn : listFeOParticle) { double dA = pPUn->GetArea(); dAreaFeO += dA; } dAreaTotal += dAreaFeO; // area row of undefined and total analysis if (!listNotIdentifiedParticle.empty()) { CGridRowPtr pAreaGridRow = CGridRowPtr(new CGridRow()); pAreaGridRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); pAreaGridRow->SetDoubleValue(dAreaNotIden); listAreaGridRows.push_back(pAreaGridRow); } if (!listSiCParticle.empty()) { CGridRowPtr pAreaSiCGridRow = CGridRowPtr(new CGridRow()); pAreaSiCGridRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); pAreaSiCGridRow->SetDoubleValue(dAreaSiC); listAreaGridRows.push_back(pAreaSiCGridRow); } if (!listFeOParticle.empty()) { CGridRowPtr pAreaFeOGridRow = CGridRowPtr(new CGridRow()); pAreaFeOGridRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); pAreaFeOGridRow->SetDoubleValue(dAreaFeO); listAreaGridRows.push_back(pAreaFeOGridRow); } CGridRowPtr pAreaToTalGridRow = CGridRowPtr(new CGridRow()); pAreaToTalGridRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); pAreaToTalGridRow->SetDoubleValue(dAreaTotal); listAreaGridRows.push_back(pAreaToTalGridRow); // particle type of undefined and analysis particle if (!listNotIdentifiedParticle.empty()) { CGridRowPtr pParticleGridRow = CGridRowPtr(new CGridRow()); pParticleGridRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING); CString strUndefineName = _T(""); strUndefineName = MultiLang::GetInstance().GetCStringByKey(IDS_PARTICL_UNDEFINED); pParticleGridRow->SetStringValue(strUndefineName); listParticleGridRows.push_back(pParticleGridRow); } if (!listSiCParticle.empty()) { CGridRowPtr pParticleSiCGridRow = CGridRowPtr(new CGridRow()); pParticleSiCGridRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING); CString strSiCName = _T(""); strSiCName = MultiLang::GetInstance().GetCStringByKey(IDS_SIC); pParticleSiCGridRow->SetStringValue(strSiCName); listParticleGridRows.push_back(pParticleSiCGridRow); } if (!listFeOParticle.empty()) { CGridRowPtr pParticleFeOGridRow = CGridRowPtr(new CGridRow()); pParticleFeOGridRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING); CString strFeOName = _T(""); strFeOName = MultiLang::GetInstance().GetCStringByKey(IDS_FEO); pParticleFeOGridRow->SetStringValue(strFeOName); listParticleGridRows.push_back(pParticleFeOGridRow); } CGridRowPtr pParticleAGridRow = CGridRowPtr(new CGridRow()); pParticleAGridRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING); CString strAnalysisdName = _T(""); strAnalysisdName = MultiLang::GetInstance().GetCStringByKey(IDS_PARTICL_ANALYSIS); pParticleAGridRow->SetStringValue(strAnalysisdName); listParticleGridRows.push_back(pParticleAGridRow); if (!((int)listParticleGridRows.size() == (int)listAreaGridRows.size())) { LogErrorTrace(__FILE__, __LINE__, _T("GetAveElementFromParticleList: particle num and area num are different.")); return FALSE; } // column name of particle type and area int nColumnNum = ((int)(REPORT_AVE_ELEMENT_GRID_CLUMN::MAX) - (int)(REPORT_AVE_ELEMENT_GRID_CLUMN::MIN) + 1); std::vector listColumnName; LoadColumnString(listColumnName, IDS_AVE_ELEMENT_START, nColumnNum); // particle type CGridColumnPtr pParticleColumn = CGridColumnPtr(new CGridColumn()); pParticleColumn->SetName(listColumnName[0]); pParticleColumn->SetGridRowsList(listParticleGridRows); // area CGridColumnPtr pAreaColumn = CGridColumnPtr(new CGridColumn()); pAreaColumn->SetName(listColumnName[1]); pAreaColumn->SetGridRowsList(listAreaGridRows); listGridColumn.push_back(pParticleColumn); listGridColumn.push_back(pAreaColumn); // get element area list from particle list CElementChemistriesList listUndefinedElement; if (!listNotIdentifiedParticle.empty()) { listUndefinedElement = GetUndefinedElementList(listNotIdentifiedParticle, a_listXray); listElementChemistriesList.push_back(listUndefinedElement); } // get element area list from particle list CElementChemistriesList listSiCElement; if (!listSiCParticle.empty()) { listSiCElement = GetUndefinedElementList(listSiCParticle, a_listXray); listElementChemistriesList.push_back(listSiCElement); } CElementChemistriesList listFeOElement; if (!listFeOParticle.empty()) { listFeOElement = GetUndefinedElementList(listFeOParticle, a_listXray); listElementChemistriesList.push_back(listFeOElement); } std::vector listElementName; listElementName.clear(); for (auto listElement : listElementChemistriesList) { for (auto pElement : listElement) { CString strElementName = pElement->GetName(); if (strElementName.Compare("Fe") == 0) { continue; } auto itr = std::find(listElementName.begin(), listElementName.end(), strElementName); if (itr == listElementName.end()) { listElementName.push_back(strElementName); } } } for (auto strName : listElementName) { //2020-2-17修改,c元素不再包含显示在元素列表中,并将显示的其它元素重新进行归一化。 if (strName == "C") continue; // particle type CGridColumnPtr pElementColumn = CGridColumnPtr(new CGridColumn()); pElementColumn->SetName(strName); CGridRowsList listElementGridRows; listElementGridRows.clear(); double dTotalArea = 0.0; int nRowNum = 0; // analysis particle for (auto pParticle : listParticleType) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); int XrayId = pParticle->GetAnalysisId(); if (XrayId < 0 || XrayId >(int)a_listXray.size()) { LogErrorTrace(__FILE__, __LINE__, _T("GetAveElementFromParticleList: can't get x ray.")); return FALSE; } int nFieldId = pParticle->GetFieldId(); auto itr = std::find_if(a_listXray.begin(), a_listXray.end(), [XrayId, nFieldId](CPosXrayPtr p) { return ((p->GetScanFieldId() == nFieldId) && (p->GetIndex() == XrayId)); }); if (itr == a_listXray.end()) { LogErrorTrace(__FILE__, __LINE__, _T("GetAveElementFromParticleList: can't find x-ray.")); return FALSE; } CPosXrayPtr pXray = *itr; CElementChemistriesList listTpElement = pXray->GetElementQuantifyData(); auto itrE = std::find_if(listTpElement.begin(), listTpElement.end(), [strName](CElementChemistryPtr p) { return p->GetName().CompareNoCase(strName) == 0; }); if (itrE == listTpElement.end()) { pGridRow->SetDoubleValue(0.0); } else { CElementChemistriesList listElementNoFe = CPosXray::RemoveFe(listTpElement); auto itr = std::find_if(listElementNoFe.begin(), listElementNoFe.end(), [strName](CElementChemistryPtr p) { return p->GetName().CompareNoCase(strName) == 0; }); if (itr == listElementNoFe.end()) { pGridRow->SetDoubleValue(0.0); } else { CElementChemistryPtr pElement = *itr; double dPercent = pElement->GetPercentage(); pGridRow->SetDoubleValue(dPercent); if (nRowNum < 0 || nRowNum >(int) listAreaGridRows.size()) { LogErrorTrace(__FILE__, __LINE__, _T("GetAveElementFromParticleList: can't get area.")); return FALSE; } dTotalArea += listAreaGridRows[nRowNum]->GetDoubleValue() * dPercent; } } nRowNum++; listElementGridRows.push_back(pGridRow); } // undefined particle if (!listNotIdentifiedParticle.empty()) { CGridRowPtr pUndefinedGridRow = CGridRowPtr(new CGridRow()); pUndefinedGridRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); // get element area list from particle list auto itr = std::find_if(listUndefinedElement.begin(), listUndefinedElement.end(), [strName](CElementChemistryPtr p) { return p->GetName().CompareNoCase(strName) == 0; }); if (itr == listUndefinedElement.end()) { pUndefinedGridRow->SetDoubleValue(0.0); } else { CElementChemistryPtr pElement = *itr; double dPercent = pElement->GetPercentage(); pUndefinedGridRow->SetDoubleValue(dPercent); dTotalArea += listAreaGridRows[nRowNum]->GetDoubleValue() * dPercent; } nRowNum++; listElementGridRows.push_back(pUndefinedGridRow); } if (!listSiCParticle.empty()) { CGridRowPtr pSiCGridRow = CGridRowPtr(new CGridRow()); pSiCGridRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); // get element area list from particle list auto itrSiC = std::find_if(listSiCElement.begin(), listSiCElement.end(), [strName](CElementChemistryPtr p) { return p->GetName().CompareNoCase(strName) == 0; }); if (itrSiC == listSiCElement.end()) { pSiCGridRow->SetDoubleValue(0.0); } else { CElementChemistryPtr pElement = *itrSiC; double dPercent = pElement->GetPercentage(); pSiCGridRow->SetDoubleValue(dPercent); dTotalArea += listAreaGridRows[nRowNum]->GetDoubleValue() * dPercent; } nRowNum++; listElementGridRows.push_back(pSiCGridRow); } if (!listFeOParticle.empty()) { CGridRowPtr pFeOGridRow = CGridRowPtr(new CGridRow()); pFeOGridRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); // get element area list from particle list auto itrFeO = std::find_if(listFeOElement.begin(), listFeOElement.end(), [strName](CElementChemistryPtr p) { return p->GetName().CompareNoCase(strName) == 0; }); if (itrFeO == listFeOElement.end()) { pFeOGridRow->SetDoubleValue(0.0); } else { CElementChemistryPtr pElement = *itrFeO; double dPercent = pElement->GetPercentage(); pFeOGridRow->SetDoubleValue(dPercent); dTotalArea += listAreaGridRows[nRowNum]->GetDoubleValue() * dPercent; } nRowNum++; listElementGridRows.push_back(pFeOGridRow); } int nAreaSize = (int)listAreaGridRows.size(); if (!((nRowNum + 1) == nAreaSize)) { LogErrorTrace(__FILE__, __LINE__, _T("GetAveElementFromParticleList: can't get area.")); return FALSE; } dTotalArea = dTotalArea / listAreaGridRows[nAreaSize - 1]->GetDoubleValue(); // total particle CGridRowPtr pTotalGridRow = CGridRowPtr(new CGridRow()); pTotalGridRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); pTotalGridRow->SetDoubleValue(dTotalArea); listElementGridRows.push_back(pTotalGridRow); pElementColumn->SetGridRowsList(listElementGridRows); listGridColumn.push_back(pElementColumn); } //2020-2-17 Modify and standardize double d_allelement_subtotal = 0; for (unsigned int i_row = 0; i_row < listGridColumn[0]->GetRowList().size(); i_row++) { //first,So let's take out all the sums d_allelement_subtotal = 0; for (unsigned int icolumn = 2; icolumn < listGridColumn.size(); icolumn++) { double ls_dd = listGridColumn[icolumn]->GetRowList()[i_row]->GetDoubleValue(); if (ls_dd < 0) continue; d_allelement_subtotal = d_allelement_subtotal + ls_dd; } //second,Then calculate the normalized values for (unsigned int icolumn = 2; icolumn < listGridColumn.size(); icolumn++) { double ls_dd = listGridColumn[icolumn]->GetRowList()[i_row]->GetDoubleValue(); if (ls_dd < 0) continue; listGridColumn[icolumn]->GetRowList()[i_row]->SetDoubleValue(ls_dd / d_allelement_subtotal * 100); } } a_pGridData->SetGridColumnList(listGridColumn); return TRUE; } // compute sort image class CGridDatasList CReportProjFileMgr::CompSortClass() { // use the dll resource AFX_MANAGE_STATE(AfxGetStaticModuleState()); CGridDatasList listGridData; listGridData.clear(); // depart compound source name std::vector listDataSource = m_CurrentPropParam->GetDataSourceList(); int nSelectedDataSourceIndex = m_CurrentPropParam->GetDataSourceId(); CString sDataSourceNames = listDataSource[nSelectedDataSourceIndex]; std::vector listSelectedDataSource = COTSHelper::SplitString(sDataSourceNames, _T("+")); //int nIndex = 0; for (auto strDataSourceName : listSelectedDataSource) { CGridDataPtr pGridData = CGridDataPtr(new CGridData()); // data source id std::vector listDataSource; listDataSource.clear(); listDataSource = m_CurrentPropParam->GetDataSourceList(); pGridData->SetDataSourceList(listDataSource); int nDataSourceId = m_CurrentPropParam->GetDataSourceId(); pGridData->SetDataSourceId(nDataSourceId); COTSParticleList listParticleAll = GetAnalysisParticleList(strDataSourceName); if (!GetSortClassFromParticleList(listParticleAll, pGridData)) { LogErrorTrace(__FILE__, __LINE__, _T("CompParticleComponent: can't get general information.")); return listGridData; } listGridData.push_back(pGridData); } return listGridData; } // get sort class from particle list BOOL CReportProjFileMgr::GetSortClassFromParticleList(COTSParticleList a_listParticleAll, CGridDataPtr a_pGridData) { ASSERT(a_pGridData); if (!a_pGridData) { LogErrorTrace(__FILE__, __LINE__, _T("GetSortClassFromParticleList: invalid grid data pointer.")); return FALSE; } // std ASSERT(m_pReportProjFile); if (!m_pReportProjFile) { LogErrorTrace(__FILE__, __LINE__, _T("GetSortClassFromParticleList: empty project file.")); return FALSE; } int nColumnNum = ((int)(REPORT_SORT_CLASS_GRID_CLUMN::MAX) - (int)(REPORT_SORT_CLASS_GRID_CLUMN::MIN) + 1); std::vector listColumnName; LoadColumnString(listColumnName, IDS_SORT_CLASS_START, nColumnNum); if ((int)listColumnName.size() != nColumnNum) { LogErrorTrace(__FILE__, __LINE__, _T("GetSortClassFromParticleList: Can't get column name number.")); return FALSE; } CGridColumnsList listGridColumn; for (int i = 0; i < nColumnNum; i++) { CGridColumnPtr pColumn = CGridColumnPtr(new CGridColumn()); pColumn->SetName(listColumnName[i]); CGridRowsList listGridRows; listGridRows.clear(); switch (i) { case (int)REPORT_SORT_CLASS_GRID_CLUMN::TOO_SMALL: { listGridRows.clear(); int nTypeId = (int)OTS_PARTCLE_TYPE::SMALL; for (auto pParticle : a_listParticleAll) { int nType = pParticle->GetType(); if (nType == nTypeId) { COTSParticlePtr pParticleNew = COTSParticlePtr(new COTSParticle(*pParticle.get())); CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::PARTICLE); pGridRow->SetParticle(pParticleNew); listGridRows.push_back(pGridRow); } } } break; case (int)REPORT_SORT_CLASS_GRID_CLUMN::OVER_SIZE: { listGridRows.clear(); int nTypeId = (int)OTS_PARTCLE_TYPE::OVERSIZE; for (auto pParticle : a_listParticleAll) { int nType = pParticle->GetType(); if (nType == nTypeId) { COTSParticlePtr pParticleNew = COTSParticlePtr(new COTSParticle(*pParticle.get())); CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::PARTICLE); pGridRow->SetParticle(pParticleNew); listGridRows.push_back(pGridRow); } } } break; case (int)REPORT_SORT_CLASS_GRID_CLUMN::GRAY_NO_INTERS: { listGridRows.clear(); int nTypeId = (int)OTS_PARTCLE_TYPE::AVE_GRAY_NOT_INRANRE; for (auto pParticle : a_listParticleAll) { int nType = pParticle->GetType(); if (nType == nTypeId) { COTSParticlePtr pParticleNew = COTSParticlePtr(new COTSParticle(*pParticle.get())); CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::PARTICLE); pGridRow->SetParticle(pParticleNew); listGridRows.push_back(pGridRow); } } } break; case (int)REPORT_SORT_CLASS_GRID_CLUMN::LOW_COUNT: { listGridRows.clear(); int nTypeId = (int)OTS_PARTCLE_TYPE::LOW_COUNT; for (auto pParticle : a_listParticleAll) { int nType = pParticle->GetType(); if (nType == nTypeId) { COTSParticlePtr pParticleNew = COTSParticlePtr(new COTSParticle(*pParticle.get())); CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::PARTICLE); pGridRow->SetParticle(pParticleNew); listGridRows.push_back(pGridRow); } } } break; case (int)REPORT_SORT_CLASS_GRID_CLUMN::NO_INTEREST_ELEMENTS: { listGridRows.clear(); int nTypeId = (int)OTS_PARTCLE_TYPE::NO_INTEREST_ELEMENTS; for (auto pParticle : a_listParticleAll) { int nType = pParticle->GetType(); if (nType == nTypeId) { COTSParticlePtr pParticleNew = COTSParticlePtr(new COTSParticle(*pParticle.get())); CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::PARTICLE); pGridRow->SetParticle(pParticleNew); listGridRows.push_back(pGridRow); } } } break; case (int)REPORT_SORT_CLASS_GRID_CLUMN::NOT_INCLUSION_SIC: { listGridRows.clear(); int nTypeId = (int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED_SIC; for (auto pParticle : a_listParticleAll) { int nType = pParticle->GetType(); if (nType == nTypeId) { COTSParticlePtr pParticleNew = COTSParticlePtr(new COTSParticle(*pParticle.get())); CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::PARTICLE); pGridRow->SetParticle(pParticleNew); listGridRows.push_back(pGridRow); } } } break; case (int)REPORT_SORT_CLASS_GRID_CLUMN::NOT_INCLUSION_FEO: { listGridRows.clear(); int nTypeId = (int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED_FEO; for (auto pParticle : a_listParticleAll) { int nType = pParticle->GetType(); if (nType == nTypeId) { COTSParticlePtr pParticleNew = COTSParticlePtr(new COTSParticle(*pParticle.get())); CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::PARTICLE); pGridRow->SetParticle(pParticleNew); listGridRows.push_back(pGridRow); } } } break; case (int)REPORT_SORT_CLASS_GRID_CLUMN::NOT_IDENTIFIED: { listGridRows.clear(); int nTypeId = (int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED; for (auto pParticle : a_listParticleAll) { int nType = pParticle->GetType(); if (nType == nTypeId) { COTSParticlePtr pParticleNew = COTSParticlePtr(new COTSParticle(*pParticle.get())); CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::PARTICLE); pGridRow->SetParticle(pParticleNew); listGridRows.push_back(pGridRow); } } } break; case (int)REPORT_SORT_CLASS_GRID_CLUMN::IDENTIFIED: { listGridRows.clear(); int nTypeId = (int)OTS_PARTCLE_TYPE::IDENTIFIED; for (auto pParticle : a_listParticleAll) { int nType = pParticle->GetType(); if (nType >= nTypeId) { COTSParticlePtr pParticleNew = COTSParticlePtr(new COTSParticle(*pParticle.get())); CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::PARTICLE); pGridRow->SetParticle(pParticleNew); listGridRows.push_back(pGridRow); } } } break; } pColumn->SetGridRowsList(listGridRows); listGridColumn.push_back(pColumn); } a_pGridData->SetGridColumnList(listGridColumn); return TRUE; } // compute sort image kind CGridDatasList CReportProjFileMgr::CompSortKind() { // use the dll resource AFX_MANAGE_STATE(AfxGetStaticModuleState()); CGridDatasList listGridData; listGridData.clear(); // depart compound source name std::vector listDataSource = m_CurrentPropParam->GetDataSourceList(); int nSelectedDataSourceIndex = m_CurrentPropParam->GetDataSourceId(); CString sDataSourceNames = listDataSource[nSelectedDataSourceIndex]; std::vector listSelectedDataSource = COTSHelper::SplitString(sDataSourceNames, _T("+")); //int nIndex = 0; for (auto strDataSourceName : listSelectedDataSource) { CGridDataPtr pGridData = CGridDataPtr(new CGridData()); // data source id std::vector listDataSource; listDataSource.clear(); listDataSource = m_CurrentPropParam->GetDataSourceList(); pGridData->SetDataSourceList(listDataSource); int nDataSourceId = m_CurrentPropParam->GetDataSourceId(); pGridData->SetDataSourceId(nDataSourceId); COTSParticleList listParticleAll = GetAnalysisParticleList(strDataSourceName); if (!GetSortKindFromParticleList(listParticleAll, pGridData)) { LogErrorTrace(__FILE__, __LINE__, _T("CompParticleComponent: can't get general information.")); return listGridData; } listGridData.push_back(pGridData); } return listGridData; } // compute sort king from particle list BOOL CReportProjFileMgr::GetSortKindFromParticleList(COTSParticleList a_listParticleAll, CGridDataPtr a_pGridData) { // use the dll resource AFX_MANAGE_STATE(AfxGetStaticModuleState()); ASSERT(a_pGridData); if (!a_pGridData) { LogErrorTrace(__FILE__, __LINE__, _T("GetSortClassFromParticleList: invalid grid data pointer.")); return FALSE; } int nColumnNum = ((int)(REPORT_SORT_KIND_GRID_CLUMN::MAX) - (int)(REPORT_SORT_KIND_GRID_CLUMN::MIN) + 1); std::vector listColumnName; LoadColumnString(listColumnName, IDS_SORT_KIND_START, nColumnNum); map mapSameSTDItemPartList; this->GetSTDMapedParticleList(a_listParticleAll, &mapSameSTDItemPartList); CGridColumnsList listGridColumn; nColumnNum = mapSameSTDItemPartList.size(); for (auto itr = mapSameSTDItemPartList.begin(); itr != mapSameSTDItemPartList.end(); itr++) { CGridColumnPtr pColumn = CGridColumnPtr(new CGridColumn()); std::string typeName = itr->second[0]->TypeName(); pColumn->SetName(typeName.c_str()); CGridRowsList listGridRows; listGridRows.clear(); COTSParticleList thisTypeParts = itr->second; for (auto pParticle : thisTypeParts) { COTSParticlePtr pParticleNew = COTSParticlePtr(new COTSParticle(*pParticle.get())); CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::PARTICLE); pGridRow->SetParticle(pParticleNew); listGridRows.push_back(pGridRow); } pColumn->SetGridRowsList(listGridRows); listGridColumn.push_back(pColumn); } a_pGridData->SetGridColumnList(listGridColumn); return TRUE; } // compute sort image size CGridDatasList CReportProjFileMgr::CompSortSize() { // use the dll resource AFX_MANAGE_STATE(AfxGetStaticModuleState()); CGridDatasList listGridData; listGridData.clear(); // depart compound source name std::vector listDataSource = m_CurrentPropParam->GetDataSourceList(); int nSelectedDataSourceIndex = m_CurrentPropParam->GetDataSourceId(); CString sDataSourceNames = listDataSource[nSelectedDataSourceIndex]; std::vector listSelectedDataSource = COTSHelper::SplitString(sDataSourceNames, _T("+")); //int nIndex = 0; for (auto strDataSourceName : listSelectedDataSource) { CGridDataPtr pGridData = CGridDataPtr(new CGridData()); // data source id std::vector listDataSource; listDataSource.clear(); listDataSource = m_CurrentPropParam->GetDataSourceList(); pGridData->SetDataSourceList(listDataSource); int nDataSourceId = m_CurrentPropParam->GetDataSourceId(); pGridData->SetDataSourceId(nDataSourceId); COTSParticleList listParticleAll = GetAnalysisParticleList(strDataSourceName); //get pixel size CSmplMsrResultFileMgrPtr pSmplMsrResultFileMgr = this->GetASmplMsrResultMgrByFileName(strDataSourceName); ASSERT(pSmplMsrResultFileMgr); if (!pSmplMsrResultFileMgr) { LogErrorTrace(__FILE__, __LINE__, _T("CompDistribution: can't get sample result file manager.")); return listGridData; } CSmplMsrResultFilePtr pSmplMsrResultFile = pSmplMsrResultFileMgr->GetSmplMsrResultFile(); ASSERT(pSmplMsrResultFile); if (!pSmplMsrResultFile) { LogErrorTrace(__FILE__, __LINE__, _T("CompDistribution: can't get sample result file.")); return listGridData; } COTSSamplePtr pSample = pSmplMsrResultFile->GetSample(); ASSERT(pSample); if (!pSample) { LogErrorTrace(__FILE__, __LINE__, _T("CompDistribution: can't get sample.")); return listGridData; } double dPixelSize = pSample->CalculatePixelSize(); if (!GetSortSizeFromParticleList(listParticleAll, dPixelSize, pGridData)) { LogErrorTrace(__FILE__, __LINE__, _T("CompParticleComponent: can't get general information.")); return listGridData; } listGridData.push_back(pGridData); //nIndex++; } return listGridData; } // compute sort size from particle list BOOL CReportProjFileMgr::GetSortSizeFromParticleList(COTSParticleList a_listParticleAll, double a_dPixelSize, CGridDataPtr a_pGridData) { // use the dll resource AFX_MANAGE_STATE(AfxGetStaticModuleState()); ASSERT(a_pGridData); if (!a_pGridData) { LogErrorTrace(__FILE__, __LINE__, _T("GetSortSizeFromParticleList: invalid grid data pointer.")); return FALSE; } // particle size file CPartSizeFilePtr pPartSize = m_CurrentPropParam->GetWorkingSizeFile(); ASSERT(pPartSize); if (!pPartSize) { LogErrorTrace(__FILE__, __LINE__, _T("GetSortSizeFromParticleList: invalid part size data.")); return FALSE; } int nColumnNum = ((int)(REPORT_SORT_SIZE_GRID_CLUMN::MAX) - (int)(REPORT_SORT_SIZE_GRID_CLUMN::MIN) + 1); std::vector listColumnName; LoadColumnString(listColumnName, IDS_SORT_SIZE_START, nColumnNum); CPartSizeItemList& listSizes = pPartSize->GetPartSizeList(); for (auto pSize : listSizes) { CString strSizeName = pSize->GetName(); listColumnName.push_back(strSizeName); nColumnNum++; } if ((int)listColumnName.size() != nColumnNum) { LogErrorTrace(__FILE__, __LINE__, _T("GetSortClassFromParticleList: Can't get column name number.")); return FALSE; } CGridColumnsList listGridColumn; for (int i = 0; i < nColumnNum; i++) { CGridColumnPtr pColumn = CGridColumnPtr(new CGridColumn()); pColumn->SetName(listColumnName[i]); CGridRowsList listGridRows; listGridRows.clear(); double dSizeMax = 0.0; double dSizeMin = 0.0; if (i == 0) { dSizeMin = m_CurrentPropParam->GetGrainSizeMin(); dSizeMax = m_CurrentPropParam->GetGrainSizeMax(); } else { dSizeMin = listSizes[i - 1]->GetSizeLevel()->GetStart(); dSizeMax = listSizes[i - 1]->GetSizeLevel()->GetEnd(); } for (auto pParticle : a_listParticleAll) { double dValue = GetValueAsMethod(pParticle, m_CurrentPropParam->GetSizeCalMethodType(), a_dPixelSize); if (dValue < dSizeMax && dValue > dSizeMin) { COTSParticlePtr pParticleNew = COTSParticlePtr(new COTSParticle(*pParticle.get())); CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::PARTICLE); pGridRow->SetParticle(pParticleNew); listGridRows.push_back(pGridRow); } } pColumn->SetGridRowsList(listGridRows); listGridColumn.push_back(pColumn); } //reverse funcation for size particle sort reverse(listGridColumn.begin(), listGridColumn.end()); a_pGridData->SetGridColumnList(listGridColumn); return TRUE; } // compute sort image size CGridDatasList CReportProjFileMgr::CompDistribution()//CGridInPtr a_pGridIn { // use the dll resource AFX_MANAGE_STATE(AfxGetStaticModuleState()); CGridDatasList listGridData; listGridData.clear(); // depart compound source name CPropParamPtr propParam = this->GetPropertyParamImage(); std::vector listDataSource = this->GetPropertyParamImage()->GetDataSourceList(); int nSelectedDataSourceIndex = propParam->GetDataSourceId(); CString sDataSourceNames = listDataSource[nSelectedDataSourceIndex]; std::vector listSelectedDataSource = COTSHelper::SplitString(sDataSourceNames, _T("+")); int nIndex = 0; for (auto strDataSourceName : listSelectedDataSource) { CGridDataPtr pGridData = CGridDataPtr(new CGridData()); // data source id std::vector listDataSource; listDataSource.clear(); listDataSource = propParam->GetDataSourceList(); pGridData->SetDataSourceList(listDataSource); int nDataSourceId = propParam->GetDataSourceId(); pGridData->SetDataSourceId(nDataSourceId); COTSParticleList listParticleAll = GetAnalysisParticleList(strDataSourceName); //get pixel size CSmplMsrResultFileMgrPtr pSmplMsrResultFileMgr = this->GetASmplMsrResultMgrByFileName(strDataSourceName); ASSERT(pSmplMsrResultFileMgr); if (!pSmplMsrResultFileMgr) { LogErrorTrace(__FILE__, __LINE__, _T("CompDistribution: can't get sample result file manager.")); return listGridData; } CSmplMsrResultFilePtr pSmplMsrResultFile = pSmplMsrResultFileMgr->GetSmplMsrResultFile(); ASSERT(pSmplMsrResultFile); if (!pSmplMsrResultFile) { LogErrorTrace(__FILE__, __LINE__, _T("CompDistribution: can't get sample result file.")); return listGridData; } COTSSamplePtr pSample = pSmplMsrResultFile->GetSample(); ASSERT(pSample); if (!pSample) { LogErrorTrace(__FILE__, __LINE__, _T("CompDistribution: can't get sample.")); return listGridData; } double dPixelSize = pSample->CalculatePixelSize(); if (!GetDistributionFromParticleList(propParam, dPixelSize, listParticleAll, pGridData)) { LogErrorTrace(__FILE__, __LINE__, _T("CompDistribution: can't get particle list.")); return listGridData; } listGridData.push_back(pGridData); nIndex++; } return listGridData; } BOOL CReportProjFileMgr::GetDistributionFromParticleList(CPropParamPtr propParam, double a_dPixelSize, COTSParticleList a_listParticleAll, CGridDataPtr a_pGridData) { // use the dll resource AFX_MANAGE_STATE(AfxGetStaticModuleState()); ASSERT(a_pGridData); if (!a_pGridData) { LogErrorTrace(__FILE__, __LINE__, _T("GetDistributionFromParticleList: invalid grid data pointer.")); return FALSE; } // std ASSERT(m_pReportProjFile); if (!m_pReportProjFile) { LogErrorTrace(__FILE__, __LINE__, _T("GetDistributionFromParticleList: empty project file.")); return FALSE; } // particle size file CPartSizeFilePtr pPartSize = m_CurrentPropParam->GetWorkingSizeFile(); ASSERT(pPartSize); if (!pPartSize) { LogErrorTrace(__FILE__, __LINE__, _T("GetDistributionFromParticleList: invalid part size data.")); return FALSE; } CPartSizeItemList& listSizes = pPartSize->GetPartSizeList(); std::vector listSizeClassTables; LoadColumnString(listSizeClassTables, (UINT)IDS_SIZE_CLASS_DEFUALT_FIRST, (int)(SIZE_CLASS_DEFUALT::MAX) - (int)(SIZE_CLASS_DEFUALT::MIN) + 1); if ((pPartSize.get() != nullptr)) { CPartSizeItemList listSizeItem = pPartSize->GetPartSizeList(); for (auto pItem : listSizeItem) { CString strValue = pItem->GetName(); listSizeClassTables.push_back(strValue); } } CGridColumnsList listGridColumn; CGridColumnPtr pColumn = CGridColumnPtr(new CGridColumn()); pColumn->SetName(_T("")); CGridRowsList listGridRows; listGridRows.clear(); PARTICLE_TYPE nSelectType = propParam->GetPartType(); int nSTDId = propParam->GetSTDId(); int nSizeClassType; double dSizeMax = 0; double dSizeMin = 0; dSizeMin = propParam->GetGrainSizeMin(); dSizeMax = propParam->GetGrainSizeMax(); //因GridIn参数中没有传递具体选择什么类型的粒级分类数据,因此用SizeLevel的两个限值来区分,都为0 时就认为是选择了全部,其他的就按选择具体的档级处理。 if (dSizeMax == 0 && dSizeMin == 0)//当DSizeMax==0 和 dSizeMin==0 时表明“粒级”栏选择的是 “全部”或“自定义”上下限填写的是0. { nSizeClassType = 0;//等于0表明选择“全部”也就是默认取全部粒级表的尺寸数据 } else { nSizeClassType = 1;//等于1表明选择的是单个某个粒级的数据档 如“3~5” } for (auto pParticle : a_listParticleAll) { int nTypeParticle = pParticle->GetType(); double dValue = GetValueAsMethod(pParticle, propParam->GetSizeCalMethodType(), a_dPixelSize); COTSParticlePtr pParticleNew = COTSParticlePtr(new COTSParticle(*pParticle.get())); switch ((int)nSelectType) { case (int)PARTICLE_TYPE::ALL: if (nSizeClassType == 0) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::PARTICLE); pGridRow->SetParticle(pParticleNew); listGridRows.push_back(pGridRow); } else { if (dValue > dSizeMin && dValue < dSizeMax) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::PARTICLE); pGridRow->SetParticle(pParticleNew); listGridRows.push_back(pGridRow); } } break; case (int)PARTICLE_TYPE::ANALYSISED: if (nSizeClassType == 0) { if (nSTDId == 0) //全部颗粒 { if (nSizeClassType == 0) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::PARTICLE); pGridRow->SetParticle(pParticleNew); listGridRows.push_back(pGridRow); } else { if (dValue > dSizeMin && dValue < dSizeMax) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::PARTICLE); pGridRow->SetParticle(pParticleNew); listGridRows.push_back(pGridRow); } } } else if (nSTDId == 1) // 未识别颗粒 { if (nTypeParticle == (int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::PARTICLE); pGridRow->SetParticle(pParticleNew); listGridRows.push_back(pGridRow); } } else { if (nTypeParticle == (nSTDId - 1)) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::PARTICLE); pGridRow->SetParticle(pParticleNew); listGridRows.push_back(pGridRow); } } } else { if (dValue > dSizeMin && dValue < dSizeMax) { CGridRowPtr pGridRow = CGridRowPtr(new CGridRow()); pGridRow->SetDataType(REPORT_GRID_DATA_TYPE::PARTICLE); pGridRow->SetParticle(pParticleNew); listGridRows.push_back(pGridRow); } } break; default: break; } } pColumn->SetGridRowsList(listGridRows); listGridColumn.push_back(pColumn); a_pGridData->SetGridColumnList(listGridColumn); return TRUE; } // load column name string void CReportProjFileMgr::LoadColumnString(std::vector& a_listStrings, UINT a_nFirstStringID, int a_nCount) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); for (int i = 0; i < a_nCount; ++i) { CString str; str = MultiLang::GetInstance().GetCStringByKey(a_nFirstStringID + i); a_listStrings.push_back(str); } } // get undefined element list from particle list CElementChemistriesList CReportProjFileMgr::GetUndefinedElementList(COTSParticleList a_listParticle, CPosXraysList a_listXray) { CElementChemistriesList listElementChemistry; // safety check to get xray data and element number int nXraySize = (int)a_listXray.size(); int nParticleSize = (int)a_listParticle.size(); if (nParticleSize > nXraySize) { LogErrorTrace(__FILE__, __LINE__, _T("GetUndefinedElementList: get xray number is not enough.")); return listElementChemistry; } CElementAreaList listElementArea; // get element area double dTotalArea = 0; for (auto pParticle : a_listParticle) { int nXrayId = pParticle->GetAnalysisId(); if (nXrayId < 0 || nXrayId >(int) a_listXray.size()) { LogErrorTrace(__FILE__, __LINE__, _T("GetUndefinedElementList: get wrong xray id.")); return listElementChemistry; } int nFieldId = pParticle->GetFieldId(); auto itr = std::find_if(a_listXray.begin(), a_listXray.end(), [nXrayId, nFieldId](CPosXrayPtr p) { return ((p->GetScanFieldId() == nFieldId) && (p->GetIndex() == nXrayId)); }); if (itr == a_listXray.end()) { LogErrorTrace(__FILE__, __LINE__, _T("GetUndefinedElementList: can't find x-ray.")); return listElementChemistry; } CPosXrayPtr pXray = *itr; // remove Fe CElementChemistriesList listElementChemistryCurrent = pXray->GetElementQuantifyData(); CElementChemistriesList listElementChemistryNew1 = CPosXray::RemoveFe(listElementChemistryCurrent); CElementChemistriesList listElementChemistryNew = CPosXray::RemoveC(listElementChemistryNew1); double t = 0; CElementChemistriesList listElementChemistryG1; for (auto pElementChemistry : listElementChemistryNew) { t += pElementChemistry->GetPercentage(); } if (t == 0) { continue; } for (auto pElementChemistry : listElementChemistryNew) { double dPecent = 100.0 *pElementChemistry->GetPercentage() / t; CElementChemistryPtr pElementNew = CElementChemistryPtr(new CElementChemistry(*pElementChemistry.get())); pElementNew->SetPercentage(dPecent); listElementChemistryG1.push_back(pElementNew); } CElementAreaPtr pElementArea = CElementAreaPtr(new CElementArea()); double dArea = pParticle->GetArea(); pElementArea->SetArea(dArea); pElementArea->SetElementList(listElementChemistryG1); listElementArea.push_back(pElementArea); dTotalArea += dArea; } for (auto pElementArea : listElementArea) { CElementChemistriesList listElementChemistryCurrent = pElementArea->GetElementList(); for (auto pElement : listElementChemistryCurrent) { CString strName = pElement->GetName(); double dPercentNorm = 1.0; auto itr = std::find_if(listElementChemistry.begin(), listElementChemistry.end(), [strName](CElementChemistryPtr p) { return p->GetName().CompareNoCase(strName) == 0; }); if (itr == listElementChemistry.end()) { double dArea = pElementArea->GetArea(); double dPercent = pElement->GetPercentage(); dPercentNorm = dArea * dPercent / dTotalArea; } else { CElementChemistryPtr pElementChemistry = *itr; double dAreaOld = pElementChemistry->GetPercentage() * dTotalArea * 0.01; double dArea = pElementArea->GetArea(); double dPercent = pElement->GetPercentage(); dPercentNorm = 100 * (0.01 * dArea * dPercent + dAreaOld) / dTotalArea; listElementChemistry.erase(itr); } CElementChemistryPtr pElement = CElementChemistryPtr(new CElementChemistry()); pElement->SetName(strName); pElement->SetPercentage(dPercentNorm); listElementChemistry.push_back(pElement); } } return listElementChemistry; } CGridDatasList CReportProjFileMgr::CompChartParticleComp() { // use the dll resource AFX_MANAGE_STATE(AfxGetStaticModuleState()); CGridDatasList listGridData; listGridData.clear(); // depart compound source name std::vector listDataSource = m_CurrentPropParam->GetDataSourceList(); int nSelectedDataSourceIndex = m_CurrentPropParam->GetDataSourceId(); CGridDatasList pGridList = CompParticleComponent(); for (CGridDataPtr pGrid : pGridList) { CGridDataPtr pGridData = CGridDataPtr(new CGridData()); // data source id std::vector listDataSource; listDataSource.clear(); listDataSource = m_CurrentPropParam->GetDataSourceList(); pGridData->SetDataSourceList(listDataSource); int nDataSourceId = m_CurrentPropParam->GetDataSourceId(); pGridData->SetDataSourceId(nDataSourceId); ASSERT(pGrid); if (!pGrid) { LogErrorTrace(__FILE__, __LINE__, _T("CompChartParticleComp: invalid grid in data pointer.")); return listGridData; } CGridColumnsList listGridColumn = pGrid->GetGridColumnList(); // particle column CGridColumnPtr pParticleCol = listGridColumn[(int)REPORT_PARTICLE_COMPONENT_GRID_CLUMN::NAME - (int)REPORT_PARTICLE_COMPONENT_GRID_CLUMN::MIN]; CGridRowsList listGridParticleRows = pParticleCol->GetRowList(); // particle num column CGridColumnPtr pParticleNumCol = listGridColumn[(int)REPORT_PARTICLE_COMPONENT_GRID_CLUMN::PARTICLE_NUM - (int)REPORT_PARTICLE_COMPONENT_GRID_CLUMN::MIN]; CGridRowsList listGridParticleNumRows = pParticleNumCol->GetRowList(); if (!((int)listGridParticleRows.size() == (int)listGridParticleNumRows.size())) { LogErrorTrace(__FILE__, __LINE__, _T("CompChartParticleComp: invalid name and num are different.")); return listGridData; } CGridColumnsList listCol; listCol.clear(); int nIndex = 0; for (auto pNameRow : listGridParticleRows) { CGridColumnPtr pColumn = CGridColumnPtr(new CGridColumn()); // name CString strName = pNameRow->GetStringValue(); pColumn->SetName(strName); // list of rows CGridRowsList listRows; CGridRowPtr pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT); CGridRowPtr pGridRow = listGridParticleNumRows[nIndex]; ASSERT(pGridRow); if (!pGridRow) { LogErrorTrace(__FILE__, __LINE__, _T("CompChartParticleComp: invalid name and num are different.")); return listGridData; } int nValue = pGridRow->GetIntValue(); pRow->SetIntValue(nValue); listRows.push_back(pRow); pColumn->SetGridRowsList(listRows); listCol.push_back(pColumn); nIndex++; } pGridData->SetGridColumnList(listCol); listGridData.push_back(pGridData); } return listGridData; } CGridDatasList CReportProjFileMgr::CompChartElementComp() { // use the dll resource AFX_MANAGE_STATE(AfxGetStaticModuleState()); CGridDatasList listGridData; listGridData.clear(); CGridDatasList listGridDataEEE = CompElementComponent(); for (CGridDataPtr pGrid : listGridDataEEE) { CGridDataPtr pGridData = CGridDataPtr(new CGridData()); // data source id std::vector listDataSource = m_CurrentPropParam->GetDataSourceList(); pGridData->SetDataSourceList(listDataSource); int nDataSourceId = m_CurrentPropParam->GetDataSourceId(); pGridData->SetDataSourceId(nDataSourceId); CGridColumnsList listGridColumn = pGrid->GetGridColumnList(); //获取第一列所有元素名称 CGridColumnPtr element = listGridColumn[0]; //获取第二列所有占比 CGridColumnPtr Comp = listGridColumn[1]; CGridRowsList listGridNameRows = element->GetRowList(); CGridColumnsList listGridValid; // first two column is particle name and area, they are invalid listGridValid.clear(); //循环第一列所有行,创建新表结构列 for (CGridRowPtr row : listGridNameRows) { CGridColumnPtr pColumn = CGridColumnPtr(new CGridColumn()); // name CString strName = row->GetStringValue(); pColumn->SetName(strName); listGridValid.push_back(pColumn); } //添加数据 CGridColumnsList listCol; listCol.clear(); for (int i = 0; i < listGridValid.size(); i++) { auto pGridColumn = listGridValid[i]; CGridColumnPtr pColumn = CGridColumnPtr(new CGridColumn()); // name CString strName = pGridColumn->GetName(); pColumn->SetName(strName); // list of rows CGridRowsList listRows; CGridRowPtr pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); CString sValue = Comp->GetRowList()[i]->GetStringValue(); sValue.Replace('%', '0'); double dValue; dValue = atof(sValue); pRow->SetDoubleValue(dValue); listRows.push_back(pRow); pColumn->SetGridRowsList(listRows); listCol.push_back(pColumn); } pGridData->SetGridColumnList(listCol); listGridData.push_back(pGridData); } // use the dll resource //AFX_MANAGE_STATE(AfxGetStaticModuleState()); //CGridDatasList listGridData; //listGridData.clear(); //// depart compound source name //std::vector listWorkIndex; //std::vector listPos; //std::vector listDataSource = m_CurrentPropParam->GetDataSourceList(); //int nSelectedDataSourceIndex = m_CurrentPropParam->GetDataSourceId(); // //int nIndex = 0; //CGridDatasList pGridList = CompAveElemnetComponent(); // //for (CGridDataPtr pGrid : pGridList) //{ // CGridDataPtr pGridData = CGridDataPtr(new CGridData()); // // data source id // std::vector listDataSource = m_CurrentPropParam->GetDataSourceList(); // pGridData->SetDataSourceList(listDataSource); // int nDataSourceId = m_CurrentPropParam->GetDataSourceId(); // pGridData->SetDataSourceId(nDataSourceId); // // // ASSERT(pGrid); // if (!pGrid) // { // LogErrorTrace(__FILE__, __LINE__, _T("CompChartElementComp: invalid grid in data pointer.")); // return listGridData; // } // CGridColumnsList listGridColumn = pGrid->GetGridColumnList(); // int nSTDId = m_CurrentPropParam->GetSTDId(); // CGridColumnPtr pParticleName = listGridColumn[(int)REPORT_ELEMENT_COMPONENT_GRID_CLUMN::NAME - (int)REPORT_ELEMENT_COMPONENT_GRID_CLUMN::MIN]; // CGridRowsList listGridNameRows = pParticleName->GetRowList(); // if (nSTDId < -1 || nSTDId >(int)listGridNameRows.size()) // { // LogErrorTrace(__FILE__, __LINE__, _T("CompChartElementComp: invalid STD id.")); // return listGridData; // } // if (nSTDId == 0)// all element // { // nSTDId = (int)listGridNameRows.size() - 1; // } // else if (nSTDId == 1) // undefined element // { // nSTDId = (int)listGridNameRows.size() - 2; // } // else // { // nSTDId = nSTDId - 1; // } // if ((int)listGridColumn.size() < 3) // { // LogErrorTrace(__FILE__, __LINE__, _T("CompChartElementComp: no element is checked out.")); // return listGridData; // } // CGridColumnsList listGridValid; // first two column is particle name and area, they are invalid // listGridValid.clear(); // for (int i = 2; i < (int)listGridColumn.size(); i++) // { // CGridColumnPtr pNewGridColumn = listGridColumn[i]; // ASSERT(pNewGridColumn); // if (!pNewGridColumn) // { // LogErrorTrace(__FILE__, __LINE__, _T("CompChartElementComp: invalid column.")); // return listGridData; // } // listGridValid.push_back(pNewGridColumn); // } // CGridColumnsList listCol; // listCol.clear(); // for (auto pGridColumn : listGridValid) // { // CGridColumnPtr pColumn = CGridColumnPtr(new CGridColumn()); // // name // CString strName = pGridColumn->GetName(); // pColumn->SetName(strName); // // list of rows // CGridRowsList listRows; // CGridRowPtr pRow = CGridRowPtr(new CGridRow()); // pRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); // CGridRowsList listGridRows = pGridColumn->GetRowList(); // if (!((int)listGridRows.size() == (int)listGridNameRows.size())) // { // LogErrorTrace(__FILE__, __LINE__, _T("CompChartElementComp: row lengths are different.")); // return listGridData; // } // CGridRowPtr pGridRow = listGridRows[nSTDId]; // ASSERT(pGridRow); // if (!pGridRow) // { // LogErrorTrace(__FILE__, __LINE__, _T("CompChartElementComp: invalid name and num are different.")); // return listGridData; // } // double dValue = pGridRow->GetDoubleValue(); // pRow->SetDoubleValue(dValue); // listRows.push_back(pRow); // pColumn->SetGridRowsList(listRows); // listCol.push_back(pColumn); // } // pGridData->SetGridColumnList(listCol); // listGridData.push_back(pGridData); //} return listGridData; } CGridDatasList CReportProjFileMgr::CompChartParticleSize() { // use the dll resource AFX_MANAGE_STATE(AfxGetStaticModuleState()); CGridDatasList listGridData; listGridData.clear(); // depart compound source name std::vector listWorkIndex; std::vector listPos; std::vector listDataSource = m_CurrentPropParam->GetDataSourceList(); int nSelectedDataSourceIndex = m_CurrentPropParam->GetDataSourceId(); CGridDatasList pGridList = CompParticleSizeDistribution(); for (CGridDataPtr pGrid : pGridList) { CGridDataPtr pGridData = CGridDataPtr(new CGridData()); // data source id std::vector listDataSource; listDataSource.clear(); listDataSource = m_CurrentPropParam->GetDataSourceList(); pGridData->SetDataSourceList(listDataSource); int nDataSourceId = m_CurrentPropParam->GetDataSourceId(); pGridData->SetDataSourceId(nDataSourceId); //CGridDataPtr pGrid = pGridList[0]; ASSERT(pGrid); if (!pGrid) { LogErrorTrace(__FILE__, __LINE__, _T("CompChartParticleSize: invalid grid in data pointer.")); return listGridData; } //amounts CGridColumnsList listGridColumn = pGrid->GetGridColumnList(); int nCols = (int)listGridColumn.size(); int nAmounts = 0; int nSTDId = m_CurrentPropParam->GetSTDId(); CGridColumnPtr pParticleName = listGridColumn[(int)REPORT_SIZE_DISTRIBUTION_GRID_CLUMN::NAME - (int)REPORT_SIZE_DISTRIBUTION_GRID_CLUMN::MIN]; CGridRowsList listGridNameRows = pParticleName->GetRowList(); if (nSTDId < -1 || nSTDId >(int)listGridNameRows.size()) { LogErrorTrace(__FILE__, __LINE__, _T("CompChartParticleSize: invalid STD id.")); return listGridData; } CGridColumnsList listCol; listCol.clear(); int nCIndex = 0; int nCAmount = 0; for (auto gridColumn : listGridColumn) { nCIndex++; if (nCIndex > (((int)REPORT_SIZE_DISTRIBUTION_GRID_CLUMN::MAX) + 1)) { CGridColumnPtr pColumn = CGridColumnPtr(new CGridColumn()); CString strName = gridColumn->GetName(); pColumn->SetName(strName); CGridRowsList listGridRows = gridColumn->GetRowList(); CGridRowsList listRows; int nRows = (int)listGridRows.size(); CGridRowPtr pGridRow = listGridRows[nRows - 1]; ASSERT(pGridRow); if (!pGridRow) { LogErrorTrace(__FILE__, __LINE__, _T("CompChartParticleSize: invalid name and num are different.")); return listGridData; } CString strValue = pGridRow->GetStringValue(); double dValue = atof(strValue); CGridRowPtr pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); pRow->SetDoubleValue(dValue); listRows.push_back(pRow); pColumn->SetGridRowsList(listRows); listCol.push_back(pColumn); } } //double dValue = nCAmount / nAmounts; pGridData->SetGridColumnList(listCol); listGridData.push_back(pGridData); } return listGridData; } // compute common five classification CGridDatasList CReportProjFileMgr::CompChartCommonFive() { // use the dll resource AFX_MANAGE_STATE(AfxGetStaticModuleState()); CGridDatasList listGridData; listGridData.clear(); std::vector listDataSource = m_CurrentPropParam->GetDataSourceList(); int nSelectedDataSourceIndex = m_CurrentPropParam->GetDataSourceId(); CString sDataSourceNames = listDataSource[nSelectedDataSourceIndex]; std::vector listSelectedDataSource = COTSHelper::SplitString(sDataSourceNames, _T("+")); //int nIndex = 0; for (auto strDataSourceName : listSelectedDataSource) { CGridDataPtr pGridData = CGridDataPtr(new CGridData()); // data source id pGridData->SetDataSourceList(m_CurrentPropParam->GetDataSourceList()); pGridData->SetDataSourceId(m_CurrentPropParam->GetDataSourceId()); COTSParticleList* pSelectidParts; COTSParticleList listParticleAll; COTSParticleList seleParticles; // add filter select particle if (m_CurrentPropParam->GetDataSourceType() == DATA_SOURCE_TYPE::SELECTION) { seleParticles = m_CurrentPropParam->GetSelectParticle(); pSelectidParts = &seleParticles; } else { listParticleAll = GetAnalysisParticleList(strDataSourceName); pSelectidParts = &listParticleAll; } if (!GetCommonFiveFromParticleList(*pSelectidParts, pGridData)) { LogErrorTrace(__FILE__, __LINE__, _T("CompParticleComponent: can't get general information.")); return listGridData; } listGridData.push_back(pGridData); } return listGridData; } BOOL CReportProjFileMgr::GetCommonClass( COTSParticlePtr a_pPart, INC_COMMON_CLASSIFY_TYPE& a_nType) { // safety check ASSERT(a_pPart); if (!a_pPart) { // something wrong LogErrorTrace(__FILE__, __LINE__, _T("GetCommonClass: invalid CParticlePtr.")); return FALSE; } int nType = a_pPart->GetType(); //CString sIncName = GetSTDItemNameById(a_listSTDItems, nType); //只有"NOT_IDENTIFIED"以上的颗粒类型需要考虑 if (nType >= (int)OTS_PARTCLE_TYPE::NOT_IDENTIFIED) { if ((nType >= (int)OTS_STD_ITEM_VALUE::SYS_SPIEL_OXICE_MIN && nType <= (int)OTS_STD_ITEM_VALUE::SYS_SPIEL_OXICE_MAX) || (nType >= (int)OTS_STD_ITEM_VALUE::SYS_SPINEL_OXIDE_NITRIDE_MIN && nType <= (int)OTS_STD_ITEM_VALUE::SYS_SPINEL_OXIDE_NITRIDE_MAX) || (nType >= (int)OTS_STD_ITEM_VALUE::SYS_SPINEL_OXIDE_SULFIDE_MIN && nType <= (int)OTS_STD_ITEM_VALUE::SYS_SIMPLE_OXIDE_SULFIDE_MAX)) { a_nType = INC_COMMON_CLASSIFY_TYPE::SPINEL; } else if (nType >= (int)OTS_STD_ITEM_VALUE::SYS_OXIDE_MIN && nType <= (int)(int)OTS_STD_ITEM_VALUE::SYS_OXIDE_MAX) { a_nType = INC_COMMON_CLASSIFY_TYPE::OXIDE; } else if ((nType >= (int)OTS_STD_ITEM_VALUE::SYS_SIMPLE_OXIDE_SULFIDE_MIN && nType <= (int)(int)OTS_STD_ITEM_VALUE::SYS_SIMPLE_OXIDE_SULFIDE_MAX) || (nType >= (int)OTS_STD_ITEM_VALUE::SYS_COMPLEX_OXIDE_SULFIDE_MIN && nType <= (int)(int)OTS_STD_ITEM_VALUE::SYS_COMPLEX_OXIDE_SULFIDE_MAX) || (nType >= (int)OTS_STD_ITEM_VALUE::SYS_OXIDE_SULFIDE_MIN && nType <= (int)(int)OTS_STD_ITEM_VALUE::SYS_OXIDE_SULFIDE_MAX)) { a_nType = INC_COMMON_CLASSIFY_TYPE::SULFIDE_OXIDE; } else if (nType > (int)OTS_STD_ITEM_VALUE::SYS_NITRIDE_MIN && nType <= (int)(int)OTS_STD_ITEM_VALUE::SYS_NITRIDE_MAX) { a_nType = INC_COMMON_CLASSIFY_TYPE::NITRIDE; } else if (nType > (int)OTS_STD_ITEM_VALUE::SYS_SUL_MIN && nType <= (int)(int)OTS_STD_ITEM_VALUE::SYS_SUL_MAX) { a_nType = INC_COMMON_CLASSIFY_TYPE::SULFIDE; } } else { LogErrorTrace(__FILE__, __LINE__, _T("GetCommonClass: this particle is not a common particle.")); return FALSE; } // ok, return TRUE return TRUE; } BOOL CReportProjFileMgr::GetCommonFiveFromParticleList(COTSParticleList a_listParticle, CGridDataPtr a_pGridData) { // use the dll resource AFX_MANAGE_STATE(AfxGetStaticModuleState()); ASSERT(a_pGridData); if (!a_pGridData) { LogErrorTrace(__FILE__, __LINE__, _T("GetCommonFiveFromParticleList: invalid grid data pointer.")); return FALSE; } //// std //ASSERT(m_pReportProjFile); //if (!m_pReportProjFile) //{ // LogErrorTrace(__FILE__, __LINE__, _T("GetCommonFiveFromParticleList: empty project file.")); // return FALSE; //} //CPartSTDDataPtr pPartSTDData = m_pReportProjFile->GetPartSTDData(); //ASSERT(pPartSTDData); //if (!pPartSTDData) //{ // LogErrorTrace(__FILE__, __LINE__, _T("GetComponentFromParticleList: invalid STD data.")); // return FALSE; //} //CSTDItemsList listSTDItem = pPartSTDData->GetSTDItemsList(); //if (listSTDItem.empty()) //{ // LogErrorTrace(__FILE__, __LINE__, _T("GetComponentFromParticleList: empty STD Item.")); // return FALSE; //} int nNumSulfideOxide = 0; int nNumOxide = 0; int nNumSulfide = 0; int nNumNitrides = 0; int nNumSpinel = 0; for (auto pPart : a_listParticle) { INC_COMMON_CLASSIFY_TYPE nCommonType = INC_COMMON_CLASSIFY_TYPE::INVALID; if (GetCommonClass(pPart, nCommonType)) { if ((int)nCommonType == (int)INC_COMMON_CLASSIFY_TYPE::SULFIDE_OXIDE) { nNumSulfideOxide++; } else if ((int)nCommonType == (int)INC_COMMON_CLASSIFY_TYPE::OXIDE) { nNumOxide++; } else if ((int)nCommonType == (int)INC_COMMON_CLASSIFY_TYPE::SULFIDE) { nNumSulfide++; } else if ((int)nCommonType == (int)INC_COMMON_CLASSIFY_TYPE::NITRIDE) { nNumNitrides++; } else if ((int)nCommonType == (int)INC_COMMON_CLASSIFY_TYPE::SPINEL) { nNumSpinel++; } } } int nColumnNum = ((int)(REPORT_COMMON_FIVE_GRID_CLUMN::MAX) - (int)(REPORT_COMMON_FIVE_GRID_CLUMN::MIN) + 1); std::vector listColumnName; LoadColumnString(listColumnName, IDS_COMMON_FIVE_START, nColumnNum); if ((int)listColumnName.size() != nColumnNum) { LogErrorTrace(__FILE__, __LINE__, _T("GetCommonFiveFromParticleList: Can't get column name number.")); return FALSE; } CGridColumnsList listGridColumn; COTSParticleList listPartReport; for (int i = 0; i < nColumnNum; i++) { CGridColumnPtr pColumn = CGridColumnPtr(new CGridColumn()); pColumn->SetName(listColumnName[i]); CGridRowsList listGridRows; listGridRows.clear(); switch (i) { case (int)REPORT_COMMON_FIVE_GRID_CLUMN::SULFIDE_OXIDE: { listGridRows.clear(); CGridRowPtr pGridRowNum = CGridRowPtr(new CGridRow()); pGridRowNum->SetDataType(REPORT_GRID_DATA_TYPE::INT); pGridRowNum->SetIntValue(nNumSulfideOxide); listGridRows.push_back(pGridRowNum); } break; case (int)REPORT_COMMON_FIVE_GRID_CLUMN::OXIDE: { listGridRows.clear(); CGridRowPtr pGridRowNum = CGridRowPtr(new CGridRow()); pGridRowNum->SetDataType(REPORT_GRID_DATA_TYPE::INT); pGridRowNum->SetIntValue(nNumOxide); listGridRows.push_back(pGridRowNum); } break; case (int)REPORT_COMMON_FIVE_GRID_CLUMN::SULFIDE: { listGridRows.clear(); CGridRowPtr pGridRowNum = CGridRowPtr(new CGridRow()); pGridRowNum->SetDataType(REPORT_GRID_DATA_TYPE::INT); pGridRowNum->SetIntValue(nNumSulfide); listGridRows.push_back(pGridRowNum); } break; case (int)REPORT_COMMON_FIVE_GRID_CLUMN::NITRIDES: { listGridRows.clear(); CGridRowPtr pGridRowNum = CGridRowPtr(new CGridRow()); pGridRowNum->SetDataType(REPORT_GRID_DATA_TYPE::INT); pGridRowNum->SetIntValue(nNumNitrides); listGridRows.push_back(pGridRowNum); } break; case (int)REPORT_COMMON_FIVE_GRID_CLUMN::SPINEL: { listGridRows.clear(); CGridRowPtr pGridRowNum = CGridRowPtr(new CGridRow()); pGridRowNum->SetDataType(REPORT_GRID_DATA_TYPE::INT); pGridRowNum->SetIntValue(nNumSpinel); listGridRows.push_back(pGridRowNum); } break; } pColumn->SetGridRowsList(listGridRows); listGridColumn.push_back(pColumn); } a_pGridData->SetGridColumnList(listGridColumn); return TRUE; } double CReportProjFileMgr::GetValueAsMethod(COTSParticlePtr a_pParticle, OTSMODEL::SIZE_CAL_METHOD_TYPE a_nMethod, double a_dPixelSize) { double dValue = 0; double dArea = a_pParticle->GetArea(); double dDiameter = 2 * sqrt(dArea / Pi); double dFltD; double dMinWidth; double dMaxLength; double dRatio; if (!OTSIMGPROC::CGBImgPropCal::GetParticleFTD(a_pParticle, a_dPixelSize, dFltD, dMinWidth, dMaxLength, dRatio)) { return dValue; } switch ((int)a_nMethod) { case (int)SIZE_CAL_METHOD_TYPE::CIRCLE: dValue = dDiameter; break; case (int)SIZE_CAL_METHOD_TYPE::AREA: dValue = dArea; break; case (int)SIZE_CAL_METHOD_TYPE::FLTD: dValue = dFltD; break; case (int)SIZE_CAL_METHOD_TYPE::LENGTH: dValue = dMaxLength; break; case (int)SIZE_CAL_METHOD_TYPE::WIDTH: dValue = dMinWidth; break; } return dValue; } void CReportProjFileMgr::SetSelectedPicture(RETORT_PROP_GRID_PARAM_TYPE a_nType) { if (m_listPropParams.size() == 0) { ResetPropertyParams(); } if (m_listPropParams.size() > 0) { switch (a_nType) { case RETORT_PROP_GRID_PARAM_TYPE::IMAGE: m_CurrentPropParam = m_listPropParams[0]; break; case RETORT_PROP_GRID_PARAM_TYPE::TABLE: m_CurrentPropParam = m_listPropParams[1]; break; case RETORT_PROP_GRID_PARAM_TYPE::CHART: m_CurrentPropParam = m_listPropParams[2]; break; default: break; } } } }