ReportMgr.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. #pragma once
  2. #include "stdafx.h"
  3. #include "resource.h"
  4. #include "ReportMgr.h"
  5. #include "BSEImgFileMgr.h"
  6. #include "PosXrayFileMgr.h"
  7. #include "CGBCalculate.h"
  8. #include "GBFieldData.h"
  9. #include "OTSHelper.h"
  10. #include "OTSFileSys.h"
  11. #include "RptParamFileMgr.h"
  12. #include "GBImgPropCal.h"
  13. using namespace OTSGBCalculate;
  14. namespace OTSMODEL {
  15. using namespace std;
  16. // constructor
  17. CReportMgr::CReportMgr()
  18. {
  19. m_listPropParams.clear();
  20. m_mapSmplMgrs.clear();
  21. m_nWorkingSampeIndex = -1;
  22. //load param file
  23. CRptParamFileMgr paramFleMgr;
  24. paramFleMgr.Load(OTSMODEL::OTS_SOFT_PACKAGE_ID::OTSIncA);
  25. m_rptparamfile = paramFleMgr.GetRptParamFile();
  26. double dScale = m_rptparamfile->GetScale();
  27. }
  28. // destructor
  29. CReportMgr::~CReportMgr()
  30. {
  31. }
  32. CRptParamFilePtr CReportMgr::GetRptParamFilePtr()
  33. {
  34. return m_rptparamfile;
  35. }
  36. // class methods
  37. // public
  38. // property parameters
  39. CPropParamPtr CReportMgr::GetPropertyParamImage()
  40. {
  41. return m_listPropParams[(int)DISPLAY_PICTURE_TYPE::IMAGE];
  42. }
  43. CPropParamPtr CReportMgr::GetPropertyParamForGrid()
  44. {
  45. return m_listPropParams[(int)DISPLAY_PICTURE_TYPE::TABLE];
  46. }
  47. CPropParamPtr CReportMgr::GetPropertyParamChart()
  48. {
  49. return m_listPropParams[(int)DISPLAY_PICTURE_TYPE::CHART];
  50. }
  51. // reset property parameters
  52. BOOL CReportMgr::ResetPropertyParams(BOOL a_bClear /*= FALSE*/)
  53. {
  54. // clear property parameters list
  55. if (a_bClear)
  56. {
  57. m_listPropParams.clear();
  58. }
  59. // get data source names list
  60. std::vector<CString> listDataSourceNames = GetDataSourceNamesList();
  61. // data source names list can't be empty
  62. if (listDataSourceNames.empty())
  63. {
  64. LogErrorTrace(__FILE__, __LINE__, _T("ResetPropertyParams: empty data source name list."));
  65. return FALSE;
  66. }
  67. // add property parameters into the list
  68. if (m_listPropParams.empty())
  69. {
  70. //Image display picture's property
  71. CPropParamPtr pPropParam = CPropParamPtr(new CPropParamImage());
  72. pPropParam->SetDataSourceList(listDataSourceNames);
  73. pPropParam->SetDataSourceId(m_nWorkingSampeIndex);
  74. pPropParam->SetType(DISPLAY_PICTURE_TYPE::IMAGE);
  75. m_listPropParams.push_back(pPropParam);
  76. //grid table display picture's property
  77. pPropParam = CPropParamPtr(new CPropParamGrid());
  78. pPropParam->SetDataSourceList(listDataSourceNames);
  79. pPropParam->SetDataSourceId(m_nWorkingSampeIndex);
  80. pPropParam->SetType(DISPLAY_PICTURE_TYPE::TABLE);
  81. m_listPropParams.push_back(pPropParam);
  82. //chart display picture's property object
  83. pPropParam = CPropParamPtr(new CPropParamChart());
  84. pPropParam->SetDataSourceList(listDataSourceNames);
  85. pPropParam->SetDataSourceId(m_nWorkingSampeIndex);
  86. pPropParam->SetType(DISPLAY_PICTURE_TYPE::CHART);
  87. m_listPropParams.push_back(pPropParam);
  88. }
  89. else
  90. {
  91. for (auto pPropParam : m_listPropParams)
  92. {
  93. pPropParam->SetDataSourceList(listDataSourceNames);
  94. pPropParam->SetDataSourceId(m_nWorkingSampeIndex);
  95. }
  96. }
  97. // ok, return TRUE
  98. return TRUE;
  99. }
  100. // sample measure result files
  101. BOOL CReportMgr::AddASmplMsrResultMgr(CString a_strPathName /*= _T("")*/,CString anotherName)
  102. {
  103. /*int tmpFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
  104. tmpFlag |= _CRTDBG_LEAK_CHECK_DF;
  105. _CrtSetDbgFlag(tmpFlag);*/
  106. //_CrtSetBreakAlloc(351380);
  107. //if (m_mapSmplMgrs.find(anotherName) != m_mapSmplMgrs.end())//already exist;
  108. //{
  109. // //m_mapSmplMgrs[a_strPathName].
  110. // return true;
  111. //}
  112. CSmplMsrResultFileMgrPtr pSmplMsrResultFileMgrPtr = CSmplMsrResultFileMgrPtr(new CSmplMsrResultFileMgr(a_strPathName));
  113. if (!COTSFileSys::Exists(a_strPathName))
  114. {
  115. LogErrorTrace(__FILE__, __LINE__, "result file not exist!");
  116. return false;
  117. }
  118. // load sample result file
  119. if (!pSmplMsrResultFileMgrPtr->Load(a_strPathName))
  120. {
  121. return FALSE;
  122. }
  123. // add the file path name into file path names list
  124. // add the sample result file into sample measure result files list
  125. m_mapSmplMgrs[anotherName]=pSmplMsrResultFileMgrPtr;
  126. // set working sample
  127. m_nWorkingSampeIndex = m_mapSmplMgrs.size();
  128. // reset property parameters
  129. ResetPropertyParams();
  130. // ok, return TRUE
  131. return TRUE;
  132. }
  133. void CReportMgr::ClearSmplResults()
  134. {
  135. m_mapSmplMgrs.clear();
  136. }
  137. void CReportMgr::SetSmplMsrResultMgrs(CSmplMsrResultFileMgrList a_listSmplMsrResultFileMgr)
  138. {
  139. for (auto pSmplMsrResultMgr : a_listSmplMsrResultFileMgr)
  140. {
  141. CString strWorkingFolder = pSmplMsrResultMgr->GetWorkingFolderStr();
  142. CSmplMsrResultFileMgrPtr pSmplMsrResultMgrNew = CSmplMsrResultFileMgrPtr(new CSmplMsrResultFileMgr(strWorkingFolder));
  143. CString strPathname = pSmplMsrResultMgr->GetPathName();
  144. pSmplMsrResultMgrNew->SetPathName(strPathname);
  145. CSmplMsrResultFilePtr pSmplMsrResultFile = pSmplMsrResultMgr->GetSmplMsrResultFile();
  146. CSmplMsrResultFilePtr pSmplMsrResultFileNew = CSmplMsrResultFilePtr(new CSmplMsrResultFile(pSmplMsrResultFile.get()));
  147. pSmplMsrResultMgrNew->SetSmplMsrResultFile(pSmplMsrResultFileNew);
  148. m_mapSmplMgrs[strPathname]=pSmplMsrResultMgrNew;
  149. }
  150. }
  151. CSmplMsrResultFileMgrPtr CReportMgr::GetASmplMsrResultMgrByPathName(CString a_strPathName)
  152. {
  153. a_strPathName.Trim();
  154. if (a_strPathName.IsEmpty())
  155. {
  156. return nullptr;
  157. }
  158. auto itr = m_mapSmplMgrs.find(a_strPathName);
  159. if (itr == m_mapSmplMgrs.end())
  160. {
  161. return nullptr;
  162. }
  163. return itr->second;
  164. }
  165. CSmplMsrResultFileMgrPtr CReportMgr::GetASmplMsrResultMgrByFileName(CString a_strFileName)
  166. {
  167. a_strFileName.Trim();
  168. if (a_strFileName.IsEmpty())
  169. {
  170. return nullptr;
  171. }
  172. auto itr = std::find_if(m_mapSmplMgrs.begin(), m_mapSmplMgrs.end(), [a_strFileName](std::pair<CString, CSmplMsrResultFileMgrPtr> p)
  173. {
  174. // lambda predicate
  175. CString strDataSource = p.first;
  176. return strDataSource.CompareNoCase(a_strFileName) == 0;
  177. });
  178. if (itr == m_mapSmplMgrs.end())
  179. {
  180. return nullptr;
  181. }
  182. return itr->second;
  183. }
  184. // grid computing
  185. CGridDatasList CReportMgr::GridDataTransfer(CPropParamPtr thePropParam)
  186. {
  187. CGridDatasList listGridData;
  188. listGridData.clear();
  189. CGBCalculate GBCal(this);
  190. CALCULATE_TABLE_TYPE nCalTableType = thePropParam->GetCalTableType();
  191. listGridData = GBCal.GetGBInclusion(nCalTableType);
  192. /*switch (nCalTableType)
  193. {
  194. case CALCULATE_TABLE_TYPE::GB_Method1:
  195. listGridData = GBCal.GetGBInclusion();
  196. break;
  197. case CALCULATE_TABLE_TYPE::GB_Method2:
  198. listGridData = GBCal.GetGBInclusion();
  199. break;
  200. case CALCULATE_TABLE_TYPE::ASTM:
  201. listGridData = GBCal.GetGBInclusion();
  202. break;
  203. case CALCULATE_TABLE_TYPE::DIN:
  204. listGridData = GBCal.GetGBInclusion();
  205. break;
  206. default:
  207. break;
  208. }*/
  209. return listGridData;
  210. }
  211. // protected
  212. // get data source name list
  213. std::vector<CString> CReportMgr::GetDataSourceNamesList()
  214. {
  215. std::vector<CString> listDataSourceNames;
  216. CString strComSourceName = _T("");
  217. int nComNum = 0;
  218. for (auto pSmplMsrResultFileMgr : m_mapSmplMgrs)
  219. {
  220. // sample measure result file
  221. CString strFilePathName = pSmplMsrResultFileMgr.second->GetPathName();
  222. // get data source name
  223. CString strDataSource = COTSHelper::GetFileName(strFilePathName);
  224. // get compound source name
  225. CSmplMsrResultFilePtr pSmplMsrResultFile = pSmplMsrResultFileMgr.second->GetSmplMsrResultFile();
  226. ASSERT(pSmplMsrResultFile);
  227. if (!pSmplMsrResultFile)
  228. {
  229. LogErrorTrace(__FILE__, __LINE__, _T("GetDataSourceNamesList: Can't get sample result file pointer."));
  230. break;
  231. }
  232. BOOL bSwitch = pSmplMsrResultFile->GetSwitch();
  233. if (bSwitch)
  234. {
  235. strComSourceName += strDataSource + _T("+");
  236. nComNum++;
  237. }
  238. // add data source name into the list
  239. listDataSourceNames.push_back(strDataSource);
  240. }
  241. if (nComNum > 1)
  242. {
  243. //listDataSourceNames.push_back(strComSourceName);
  244. strComSourceName.TrimRight(_T("+"));//去掉最后的+号
  245. listDataSourceNames.insert(listDataSourceNames.begin(), strComSourceName);
  246. }
  247. return listDataSourceNames;
  248. }
  249. std::vector<int> CReportMgr::GetDataSourcePosList()
  250. {
  251. std::vector<int> listDataSourcePos;
  252. if (!IsHaveMultiDataSource())
  253. {
  254. return listDataSourcePos;
  255. }
  256. int nPos = -1;
  257. for (auto pSmplMsrResultFileMgr : m_mapSmplMgrs)
  258. {
  259. nPos++;
  260. // get compound source name
  261. CSmplMsrResultFilePtr pSmplMsrResultFile = pSmplMsrResultFileMgr.second->GetSmplMsrResultFile();
  262. ASSERT(pSmplMsrResultFile);
  263. if (!pSmplMsrResultFile)
  264. {
  265. LogErrorTrace(__FILE__, __LINE__, _T("GetDataSourceNamesList: Can't get sample result file pointer."));
  266. break;
  267. }
  268. BOOL bSwitch = pSmplMsrResultFile->GetSwitch();
  269. if (bSwitch)
  270. {
  271. listDataSourcePos.push_back(nPos);
  272. }
  273. }
  274. return listDataSourcePos;
  275. }
  276. // get property parameter
  277. COTSParticleList CReportMgr::GetAnalysisParticleList(CString a_DataSourceName)
  278. {
  279. COTSParticleList listParticleAll;
  280. // compound sample measure result files
  281. CSmplMsrResultFileMgrPtr pSmplMsrResultFileMgr = this->GetASmplMsrResultMgrByFileName(a_DataSourceName);
  282. if (!pSmplMsrResultFileMgr->ComputeParticleList())
  283. {
  284. LogErrorTrace(__FILE__, __LINE__, _T("GetAnalysisParticleList: can't get particle list."));
  285. return listParticleAll;
  286. }
  287. listParticleAll = pSmplMsrResultFileMgr->GetParticleList();
  288. return listParticleAll;
  289. }
  290. //判断该列是否要显示
  291. BOOL CReportMgr::EstimateShowColumn(CString a_strColName)
  292. {
  293. CString str_Area_Enum = "Area";
  294. CString str_MaxDiameter_Enum = "MaxDiameter";
  295. CString str_MinDiameter_Enum = "MinDiameter";
  296. CString str_DiameterRatio_Enum = "DiameterRatio";
  297. CString str_EquivalentCircleDiameter_Enum = "EquivalentCircleDiameter";
  298. CString str_FerretDiameter_Enum = "FerretDiameter";
  299. CString str_Area_CN = "颗粒面积";
  300. CString str_MaxDiameter_CN = "最长直径";
  301. CString str_MinDiameter_CN = "最短直径";
  302. CString str_DiameterRatio_CN = "长短直径比";
  303. CString str_EquivalentCircleDiameter_CN = "等效圆直径";
  304. CString str_FerretDiameter_CN = "费雷特直径";
  305. //最后再根据设置默认显示列名,对不需要显示的列进行屏蔽
  306. CString s_DefaultComputedColName = m_rptparamfile->GetDefaultComputedColName();
  307. if (a_strColName.Find(str_Area_CN, 0) > -1 || a_strColName.Find(str_MaxDiameter_CN, 0) > -1 ||
  308. a_strColName.Find(str_MinDiameter_CN, 0) > -1 || a_strColName.Find(str_DiameterRatio_CN, 0) > -1 ||
  309. a_strColName.Find(str_EquivalentCircleDiameter_CN, 0) > -1 || a_strColName.Find(str_FerretDiameter_CN, 0) > -1)
  310. {
  311. //面积
  312. if (s_DefaultComputedColName.Find(str_Area_Enum) > -1 && a_strColName.Find(str_Area_CN, 0) > -1)
  313. {
  314. return true;
  315. }
  316. //最长直径
  317. if (s_DefaultComputedColName.Find(str_MaxDiameter_Enum) > -1 && a_strColName.Find(str_MaxDiameter_CN, 0) > -1)
  318. {
  319. return true;
  320. }
  321. //最短直径
  322. if (s_DefaultComputedColName.Find(str_MinDiameter_Enum) > -1 && a_strColName.Find(str_MinDiameter_CN, 0) > -1)
  323. {
  324. return true;
  325. }
  326. //长短直径比
  327. if (s_DefaultComputedColName.Find(str_DiameterRatio_Enum) > -1 && a_strColName.Find(str_DiameterRatio_CN, 0) > -1)
  328. {
  329. return true;
  330. }
  331. //等效圆直径
  332. if (s_DefaultComputedColName.Find(str_EquivalentCircleDiameter_Enum) > -1 && a_strColName.Find(str_EquivalentCircleDiameter_CN, 0) > -1)
  333. {
  334. return true;
  335. }
  336. //费雷特直径
  337. if (s_DefaultComputedColName.Find(str_FerretDiameter_Enum) > -1 && a_strColName.Find(str_FerretDiameter_CN, 0) > -1)
  338. {
  339. return true;
  340. }
  341. return false;
  342. }
  343. return true;
  344. }
  345. BOOL CReportMgr::IsHaveMultiDataSource()
  346. {
  347. int nMultiCount = 0;
  348. for (auto SmplMgr : m_mapSmplMgrs)
  349. {
  350. CSmplMsrResultFilePtr pSmpl = SmplMgr.second->GetSmplMsrResultFile();
  351. if (pSmpl->GetSwitch())
  352. {
  353. nMultiCount++;
  354. }
  355. }
  356. if (nMultiCount > 1)
  357. {
  358. return TRUE;
  359. }
  360. return FALSE;
  361. }
  362. // get undefined element list from particle list
  363. CElementChemistriesList CReportMgr::GetUndefinedElementList(COTSParticleList a_listParticle, CPosXraysList a_listXray)
  364. {
  365. CElementChemistriesList listElementChemistry;
  366. // safety check to get xray data and element number
  367. int nXraySize = (int)a_listXray.size();
  368. int nParticleSize = (int)a_listParticle.size();
  369. if (nParticleSize > nXraySize)
  370. {
  371. LogErrorTrace(__FILE__, __LINE__, _T("GetUndefinedElementList: get xray number is not enough."));
  372. return listElementChemistry;
  373. }
  374. CElementAreaList listElementArea;
  375. // get element area
  376. double dTotalArea = 0;
  377. for (auto pParticle : a_listParticle)
  378. {
  379. int nXrayId = pParticle->GetAnalysisId();
  380. if (nXrayId < 0 || nXrayId >(int) a_listXray.size())
  381. {
  382. LogErrorTrace(__FILE__, __LINE__, _T("GetUndefinedElementList: get wrong xray id."));
  383. return listElementChemistry;
  384. }
  385. int nFieldId = pParticle->GetFieldId();
  386. auto itr = std::find_if(a_listXray.begin(), a_listXray.end(), [nXrayId, nFieldId](CPosXrayPtr p) { return ((p->GetScanFieldId() == nFieldId) && (p->GetIndex() == nXrayId)); });
  387. if (itr == a_listXray.end())
  388. {
  389. LogErrorTrace(__FILE__, __LINE__, _T("GetUndefinedElementList: can't find x-ray."));
  390. return listElementChemistry;
  391. }
  392. CPosXrayPtr pXray = *itr;
  393. // remove Fe
  394. CElementChemistriesList listElementChemistryCurrent = pXray->GetElementQuantifyData();
  395. CElementChemistriesList listElementChemistryNew1 = CPosXray::RemoveFe(listElementChemistryCurrent);
  396. CElementChemistriesList listElementChemistryNew = CPosXray::RemoveC(listElementChemistryNew1);
  397. double t = 0;
  398. CElementChemistriesList listElementChemistryG1;
  399. for (auto pElementChemistry : listElementChemistryNew)
  400. {
  401. t += pElementChemistry->GetPercentage();
  402. }
  403. if (t == 0)
  404. {
  405. continue;
  406. }
  407. for (auto pElementChemistry : listElementChemistryNew)
  408. {
  409. double dPecent = 100.0 *pElementChemistry->GetPercentage() / t;
  410. CElementChemistryPtr pElementNew = CElementChemistryPtr(new CElementChemistry(*pElementChemistry.get()));
  411. pElementNew->SetPercentage(dPecent);
  412. listElementChemistryG1.push_back(pElementNew);
  413. }
  414. CElementAreaPtr pElementArea = CElementAreaPtr(new CElementArea());
  415. double dArea = pParticle->GetActualArea();
  416. pElementArea->SetArea(dArea);
  417. pElementArea->SetElementList(listElementChemistryG1);
  418. listElementArea.push_back(pElementArea);
  419. dTotalArea += dArea;
  420. }
  421. for (auto pElementArea : listElementArea)
  422. {
  423. CElementChemistriesList listElementChemistryCurrent = pElementArea->GetElementList();
  424. for (auto pElement : listElementChemistryCurrent)
  425. {
  426. CString strName = pElement->GetName();
  427. double dPercentNorm = 1.0;
  428. auto itr = std::find_if(listElementChemistry.begin(), listElementChemistry.end(), [strName](CElementChemistryPtr p) { return p->GetName().CompareNoCase(strName) == 0; });
  429. if (itr == listElementChemistry.end())
  430. {
  431. double dArea = pElementArea->GetArea();
  432. double dPercent = pElement->GetPercentage();
  433. dPercentNorm = dArea * dPercent / dTotalArea;
  434. }
  435. else
  436. {
  437. CElementChemistryPtr pElementChemistry = *itr;
  438. double dAreaOld = pElementChemistry->GetPercentage() * dTotalArea * 0.01;
  439. double dArea = pElementArea->GetArea();
  440. double dPercent = pElement->GetPercentage();
  441. dPercentNorm = 100 * (0.01 * dArea * dPercent + dAreaOld) / dTotalArea;
  442. listElementChemistry.erase(itr);
  443. }
  444. CElementChemistryPtr pElement = CElementChemistryPtr(new CElementChemistry());
  445. pElement->SetName(strName);
  446. pElement->SetPercentage(dPercentNorm);
  447. listElementChemistry.push_back(pElement);
  448. }
  449. }
  450. return listElementChemistry;
  451. }
  452. }