#pragma once #include "stdafx.h" #include "resource.h" #include "ReportMgr.h" #include "BSEImgFileMgr.h" #include "PosXrayFileMgr.h" #include "CGBCalculate.h" #include "GBFieldData.h" #include "OTSHelper.h" #include "OTSFileSys.h" #include "RptParamFileMgr.h" #include "GBImgPropCal.h" using namespace OTSGBCalculate; namespace OTSMODEL { using namespace std; // constructor CReportMgr::CReportMgr() { m_listPropParams.clear(); m_mapSmplMgrs.clear(); m_nWorkingSampeIndex = -1; //load param file CRptParamFileMgr paramFleMgr; paramFleMgr.Load(OTSMODEL::OTS_SOFT_PACKAGE_ID::OTSIncA); m_rptparamfile = paramFleMgr.GetRptParamFile(); double dScale = m_rptparamfile->GetScale(); } // destructor CReportMgr::~CReportMgr() { } CRptParamFilePtr CReportMgr::GetRptParamFilePtr() { return m_rptparamfile; } // class methods // public // property parameters CPropParamPtr CReportMgr::GetPropertyParamImage() { return m_listPropParams[(int)DISPLAY_PICTURE_TYPE::IMAGE]; } CPropParamPtr CReportMgr::GetPropertyParamForGrid() { return m_listPropParams[(int)DISPLAY_PICTURE_TYPE::TABLE]; } CPropParamPtr CReportMgr::GetPropertyParamChart() { return m_listPropParams[(int)DISPLAY_PICTURE_TYPE::CHART]; } // reset property parameters BOOL CReportMgr::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; } // 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->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->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->SetType(DISPLAY_PICTURE_TYPE::CHART); m_listPropParams.push_back(pPropParam); } else { for (auto pPropParam : m_listPropParams) { pPropParam->SetDataSourceList(listDataSourceNames); pPropParam->SetDataSourceId(m_nWorkingSampeIndex); } } // ok, return TRUE return TRUE; } // sample measure result files BOOL CReportMgr::AddASmplMsrResultMgr(CString a_strPathName /*= _T("")*/,CString anotherName) { CSmplMsrResultFileMgrPtr pSmplMsrResultFileMgrPtr = CSmplMsrResultFileMgrPtr(new CSmplMsrResultFileMgr(a_strPathName)); if (!COTSFileSys::Exists(a_strPathName)) { LogErrorTrace(__FILE__, __LINE__, "result file not exist!"); return false; } // load sample result file if (!pSmplMsrResultFileMgrPtr->Load(a_strPathName)) { return FALSE; } // add the file path name into file path names list // add the sample result file into sample measure result files list m_mapSmplMgrs[anotherName]=pSmplMsrResultFileMgrPtr; // set working sample m_nWorkingSampeIndex = m_mapSmplMgrs.size(); // reset property parameters ResetPropertyParams(); listGBFields.clear(); return TRUE; } void CReportMgr::ClearSmplResults() { m_mapSmplMgrs.clear(); } void CReportMgr::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_mapSmplMgrs[strPathname]=pSmplMsrResultMgrNew; } } CSmplMsrResultFileMgrPtr CReportMgr::GetASmplMsrResultMgrByPathName(CString a_strPathName) { a_strPathName.Trim(); if (a_strPathName.IsEmpty()) { return nullptr; } auto itr = m_mapSmplMgrs.find(a_strPathName); if (itr == m_mapSmplMgrs.end()) { return nullptr; } return itr->second; } CSmplMsrResultFileMgrPtr CReportMgr::GetASmplMsrResultMgrByFileName(CString a_strFileName) { a_strFileName.Trim(); if (a_strFileName.IsEmpty()) { return nullptr; } auto itr = std::find_if(m_mapSmplMgrs.begin(), m_mapSmplMgrs.end(), [a_strFileName](std::pair p) { // lambda predicate CString strDataSource = p.first; return strDataSource.CompareNoCase(a_strFileName) == 0; }); if (itr == m_mapSmplMgrs.end()) { return nullptr; } return itr->second; } // grid computing CGridDatasList CReportMgr::GridDataTransfer(CPropParamPtr thePropParam) { CGridDatasList listGridData; listGridData.clear(); CGBCalculate GBCal(this); CALCULATE_TABLE_TYPE nCalTableType = thePropParam->GetCalTableType(); listGridData = GBCal.GetGBInclusion(nCalTableType); return listGridData; } CGBFieldList CReportMgr::GetAllGBFields(CPropParamPtr thePropParam) { if (listGBFields.size() == 0) { CGBCalculate GBCal(this); CALCULATE_TABLE_TYPE nCalTableType = thePropParam->GetCalTableType(); listGBFields = GBCal.GetAllGBFields(nCalTableType); } return listGBFields; } // protected // get data source name list std::vector CReportMgr::GetDataSourceNamesList() { std::vector listDataSourceNames; CString strComSourceName = _T(""); int nComNum = 0; for (auto pSmplMsrResultFileMgr : m_mapSmplMgrs) { // sample measure result file CString strFilePathName = pSmplMsrResultFileMgr.second->GetPathName(); // get data source name CString strDataSource = COTSHelper::GetFileName(strFilePathName); // get compound source name CSmplMsrResultFilePtr pSmplMsrResultFile = pSmplMsrResultFileMgr.second->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 CReportMgr::GetDataSourcePosList() { std::vector listDataSourcePos; if (!IsHaveMultiDataSource()) { return listDataSourcePos; } int nPos = -1; for (auto pSmplMsrResultFileMgr : m_mapSmplMgrs) { nPos++; // get compound source name CSmplMsrResultFilePtr pSmplMsrResultFile = pSmplMsrResultFileMgr.second->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 COTSParticleList CReportMgr::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; } //判断该列是否要显示 BOOL CReportMgr::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; } BOOL CReportMgr::IsHaveMultiDataSource() { int nMultiCount = 0; for (auto SmplMgr : m_mapSmplMgrs) { CSmplMsrResultFilePtr pSmpl = SmplMgr.second->GetSmplMsrResultFile(); if (pSmpl->GetSwitch()) { nMultiCount++; } } if (nMultiCount > 1) { return TRUE; } return FALSE; } // get undefined element list from particle list CElementChemistriesList CReportMgr::GetUndefinedElementList(COTSParticleList a_listParticle, CPosXrayList 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->GetActualArea(); 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; } }