ReportMgr.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  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::SetSmplMsrResultMgrs(CSmplMsrResultFileMgrList a_listSmplMsrResultFileMgr)
  134. {
  135. for (auto pSmplMsrResultMgr : a_listSmplMsrResultFileMgr)
  136. {
  137. CString strWorkingFolder = pSmplMsrResultMgr->GetWorkingFolderStr();
  138. CSmplMsrResultFileMgrPtr pSmplMsrResultMgrNew = CSmplMsrResultFileMgrPtr(new CSmplMsrResultFileMgr(strWorkingFolder));
  139. CString strPathname = pSmplMsrResultMgr->GetPathName();
  140. pSmplMsrResultMgrNew->SetPathName(strPathname);
  141. CSmplMsrResultFilePtr pSmplMsrResultFile = pSmplMsrResultMgr->GetSmplMsrResultFile();
  142. CSmplMsrResultFilePtr pSmplMsrResultFileNew = CSmplMsrResultFilePtr(new CSmplMsrResultFile(pSmplMsrResultFile.get()));
  143. pSmplMsrResultMgrNew->SetSmplMsrResultFile(pSmplMsrResultFileNew);
  144. m_mapSmplMgrs[strPathname]=pSmplMsrResultMgrNew;
  145. }
  146. }
  147. CSmplMsrResultFileMgrPtr CReportMgr::GetASmplMsrResultMgrByPathName(CString a_strPathName)
  148. {
  149. a_strPathName.Trim();
  150. if (a_strPathName.IsEmpty())
  151. {
  152. return nullptr;
  153. }
  154. auto itr = m_mapSmplMgrs.find(a_strPathName);
  155. if (itr == m_mapSmplMgrs.end())
  156. {
  157. return nullptr;
  158. }
  159. return itr->second;
  160. }
  161. CSmplMsrResultFileMgrPtr CReportMgr::GetASmplMsrResultMgrByFileName(CString a_strFileName)
  162. {
  163. a_strFileName.Trim();
  164. if (a_strFileName.IsEmpty())
  165. {
  166. return nullptr;
  167. }
  168. auto itr = std::find_if(m_mapSmplMgrs.begin(), m_mapSmplMgrs.end(), [a_strFileName](std::pair<CString, CSmplMsrResultFileMgrPtr> p)
  169. {
  170. // lambda predicate
  171. CString strDataSource = p.first;
  172. return strDataSource.CompareNoCase(a_strFileName) == 0;
  173. });
  174. if (itr == m_mapSmplMgrs.end())
  175. {
  176. return nullptr;
  177. }
  178. return itr->second;
  179. }
  180. // grid computing
  181. CGridDatasList CReportMgr::GridDataTransfer(CPropParamPtr thePropParam)
  182. {
  183. CGridDatasList listGridData;
  184. listGridData.clear();
  185. CGBCalculate GBCal(this);
  186. CALCULATE_TABLE_TYPE nCalTableType = thePropParam->GetCalTableType();
  187. switch (nCalTableType)
  188. {
  189. case CALCULATE_TABLE_TYPE::GB_Method1:
  190. listGridData = GBCal.GetGBInclusion();
  191. break;
  192. case CALCULATE_TABLE_TYPE::GB_Method2:
  193. listGridData = GBCal.GetGBInclusion();
  194. break;
  195. case CALCULATE_TABLE_TYPE::ASTM:
  196. listGridData = GBCal.GetGBInclusion();
  197. break;
  198. case CALCULATE_TABLE_TYPE::DIN:
  199. listGridData = GBCal.GetGBInclusion();
  200. break;
  201. default:
  202. break;
  203. }
  204. return listGridData;
  205. }
  206. // protected
  207. // get data source name list
  208. std::vector<CString> CReportMgr::GetDataSourceNamesList()
  209. {
  210. std::vector<CString> listDataSourceNames;
  211. CString strComSourceName = _T("");
  212. int nComNum = 0;
  213. for (auto pSmplMsrResultFileMgr : m_mapSmplMgrs)
  214. {
  215. // sample measure result file
  216. CString strFilePathName = pSmplMsrResultFileMgr.second->GetPathName();
  217. // get data source name
  218. CString strDataSource = COTSHelper::GetFileName(strFilePathName);
  219. // get compound source name
  220. CSmplMsrResultFilePtr pSmplMsrResultFile = pSmplMsrResultFileMgr.second->GetSmplMsrResultFile();
  221. ASSERT(pSmplMsrResultFile);
  222. if (!pSmplMsrResultFile)
  223. {
  224. LogErrorTrace(__FILE__, __LINE__, _T("GetDataSourceNamesList: Can't get sample result file pointer."));
  225. break;
  226. }
  227. BOOL bSwitch = pSmplMsrResultFile->GetSwitch();
  228. if (bSwitch)
  229. {
  230. strComSourceName += strDataSource + _T("+");
  231. nComNum++;
  232. }
  233. // add data source name into the list
  234. listDataSourceNames.push_back(strDataSource);
  235. }
  236. if (nComNum > 1)
  237. {
  238. //listDataSourceNames.push_back(strComSourceName);
  239. strComSourceName.TrimRight(_T("+"));//去掉最后的+号
  240. listDataSourceNames.insert(listDataSourceNames.begin(), strComSourceName);
  241. }
  242. return listDataSourceNames;
  243. }
  244. std::vector<int> CReportMgr::GetDataSourcePosList()
  245. {
  246. std::vector<int> listDataSourcePos;
  247. if (!IsHaveMultiDataSource())
  248. {
  249. return listDataSourcePos;
  250. }
  251. int nPos = -1;
  252. for (auto pSmplMsrResultFileMgr : m_mapSmplMgrs)
  253. {
  254. nPos++;
  255. // get compound source name
  256. CSmplMsrResultFilePtr pSmplMsrResultFile = pSmplMsrResultFileMgr.second->GetSmplMsrResultFile();
  257. ASSERT(pSmplMsrResultFile);
  258. if (!pSmplMsrResultFile)
  259. {
  260. LogErrorTrace(__FILE__, __LINE__, _T("GetDataSourceNamesList: Can't get sample result file pointer."));
  261. break;
  262. }
  263. BOOL bSwitch = pSmplMsrResultFile->GetSwitch();
  264. if (bSwitch)
  265. {
  266. listDataSourcePos.push_back(nPos);
  267. }
  268. }
  269. return listDataSourcePos;
  270. }
  271. // get property parameter
  272. COTSParticleList CReportMgr::GetAnalysisParticleList(CString a_DataSourceName)
  273. {
  274. COTSParticleList listParticleAll;
  275. // compound sample measure result files
  276. CSmplMsrResultFileMgrPtr pSmplMsrResultFileMgr = this->GetASmplMsrResultMgrByFileName(a_DataSourceName);
  277. if (!pSmplMsrResultFileMgr->ComputeParticleList())
  278. {
  279. LogErrorTrace(__FILE__, __LINE__, _T("GetAnalysisParticleList: can't get particle list."));
  280. return listParticleAll;
  281. }
  282. listParticleAll = pSmplMsrResultFileMgr->GetParticleList();
  283. return listParticleAll;
  284. }
  285. //判断该列是否要显示
  286. BOOL CReportMgr::EstimateShowColumn(CString a_strColName)
  287. {
  288. CString str_Area_Enum = "Area";
  289. CString str_MaxDiameter_Enum = "MaxDiameter";
  290. CString str_MinDiameter_Enum = "MinDiameter";
  291. CString str_DiameterRatio_Enum = "DiameterRatio";
  292. CString str_EquivalentCircleDiameter_Enum = "EquivalentCircleDiameter";
  293. CString str_FerretDiameter_Enum = "FerretDiameter";
  294. CString str_Area_CN = "颗粒面积";
  295. CString str_MaxDiameter_CN = "最长直径";
  296. CString str_MinDiameter_CN = "最短直径";
  297. CString str_DiameterRatio_CN = "长短直径比";
  298. CString str_EquivalentCircleDiameter_CN = "等效圆直径";
  299. CString str_FerretDiameter_CN = "费雷特直径";
  300. //最后再根据设置默认显示列名,对不需要显示的列进行屏蔽
  301. CString s_DefaultComputedColName = m_rptparamfile->GetDefaultComputedColName();
  302. if (a_strColName.Find(str_Area_CN, 0) > -1 || a_strColName.Find(str_MaxDiameter_CN, 0) > -1 ||
  303. a_strColName.Find(str_MinDiameter_CN, 0) > -1 || a_strColName.Find(str_DiameterRatio_CN, 0) > -1 ||
  304. a_strColName.Find(str_EquivalentCircleDiameter_CN, 0) > -1 || a_strColName.Find(str_FerretDiameter_CN, 0) > -1)
  305. {
  306. //面积
  307. if (s_DefaultComputedColName.Find(str_Area_Enum) > -1 && a_strColName.Find(str_Area_CN, 0) > -1)
  308. {
  309. return true;
  310. }
  311. //最长直径
  312. if (s_DefaultComputedColName.Find(str_MaxDiameter_Enum) > -1 && a_strColName.Find(str_MaxDiameter_CN, 0) > -1)
  313. {
  314. return true;
  315. }
  316. //最短直径
  317. if (s_DefaultComputedColName.Find(str_MinDiameter_Enum) > -1 && a_strColName.Find(str_MinDiameter_CN, 0) > -1)
  318. {
  319. return true;
  320. }
  321. //长短直径比
  322. if (s_DefaultComputedColName.Find(str_DiameterRatio_Enum) > -1 && a_strColName.Find(str_DiameterRatio_CN, 0) > -1)
  323. {
  324. return true;
  325. }
  326. //等效圆直径
  327. if (s_DefaultComputedColName.Find(str_EquivalentCircleDiameter_Enum) > -1 && a_strColName.Find(str_EquivalentCircleDiameter_CN, 0) > -1)
  328. {
  329. return true;
  330. }
  331. //费雷特直径
  332. if (s_DefaultComputedColName.Find(str_FerretDiameter_Enum) > -1 && a_strColName.Find(str_FerretDiameter_CN, 0) > -1)
  333. {
  334. return true;
  335. }
  336. return false;
  337. }
  338. return true;
  339. }
  340. BOOL CReportMgr::IsHaveMultiDataSource()
  341. {
  342. int nMultiCount = 0;
  343. for (auto SmplMgr : m_mapSmplMgrs)
  344. {
  345. CSmplMsrResultFilePtr pSmpl = SmplMgr.second->GetSmplMsrResultFile();
  346. if (pSmpl->GetSwitch())
  347. {
  348. nMultiCount++;
  349. }
  350. }
  351. if (nMultiCount > 1)
  352. {
  353. return TRUE;
  354. }
  355. return FALSE;
  356. }
  357. // get undefined element list from particle list
  358. CElementChemistriesList CReportMgr::GetUndefinedElementList(COTSParticleList a_listParticle, CPosXraysList a_listXray)
  359. {
  360. CElementChemistriesList listElementChemistry;
  361. // safety check to get xray data and element number
  362. int nXraySize = (int)a_listXray.size();
  363. int nParticleSize = (int)a_listParticle.size();
  364. if (nParticleSize > nXraySize)
  365. {
  366. LogErrorTrace(__FILE__, __LINE__, _T("GetUndefinedElementList: get xray number is not enough."));
  367. return listElementChemistry;
  368. }
  369. CElementAreaList listElementArea;
  370. // get element area
  371. double dTotalArea = 0;
  372. for (auto pParticle : a_listParticle)
  373. {
  374. int nXrayId = pParticle->GetAnalysisId();
  375. if (nXrayId < 0 || nXrayId >(int) a_listXray.size())
  376. {
  377. LogErrorTrace(__FILE__, __LINE__, _T("GetUndefinedElementList: get wrong xray id."));
  378. return listElementChemistry;
  379. }
  380. int nFieldId = pParticle->GetFieldId();
  381. auto itr = std::find_if(a_listXray.begin(), a_listXray.end(), [nXrayId, nFieldId](CPosXrayPtr p) { return ((p->GetScanFieldId() == nFieldId) && (p->GetIndex() == nXrayId)); });
  382. if (itr == a_listXray.end())
  383. {
  384. LogErrorTrace(__FILE__, __LINE__, _T("GetUndefinedElementList: can't find x-ray."));
  385. return listElementChemistry;
  386. }
  387. CPosXrayPtr pXray = *itr;
  388. // remove Fe
  389. CElementChemistriesList listElementChemistryCurrent = pXray->GetElementQuantifyData();
  390. CElementChemistriesList listElementChemistryNew1 = CPosXray::RemoveFe(listElementChemistryCurrent);
  391. CElementChemistriesList listElementChemistryNew = CPosXray::RemoveC(listElementChemistryNew1);
  392. double t = 0;
  393. CElementChemistriesList listElementChemistryG1;
  394. for (auto pElementChemistry : listElementChemistryNew)
  395. {
  396. t += pElementChemistry->GetPercentage();
  397. }
  398. if (t == 0)
  399. {
  400. continue;
  401. }
  402. for (auto pElementChemistry : listElementChemistryNew)
  403. {
  404. double dPecent = 100.0 *pElementChemistry->GetPercentage() / t;
  405. CElementChemistryPtr pElementNew = CElementChemistryPtr(new CElementChemistry(*pElementChemistry.get()));
  406. pElementNew->SetPercentage(dPecent);
  407. listElementChemistryG1.push_back(pElementNew);
  408. }
  409. CElementAreaPtr pElementArea = CElementAreaPtr(new CElementArea());
  410. double dArea = pParticle->GetActualArea();
  411. pElementArea->SetArea(dArea);
  412. pElementArea->SetElementList(listElementChemistryG1);
  413. listElementArea.push_back(pElementArea);
  414. dTotalArea += dArea;
  415. }
  416. for (auto pElementArea : listElementArea)
  417. {
  418. CElementChemistriesList listElementChemistryCurrent = pElementArea->GetElementList();
  419. for (auto pElement : listElementChemistryCurrent)
  420. {
  421. CString strName = pElement->GetName();
  422. double dPercentNorm = 1.0;
  423. auto itr = std::find_if(listElementChemistry.begin(), listElementChemistry.end(), [strName](CElementChemistryPtr p) { return p->GetName().CompareNoCase(strName) == 0; });
  424. if (itr == listElementChemistry.end())
  425. {
  426. double dArea = pElementArea->GetArea();
  427. double dPercent = pElement->GetPercentage();
  428. dPercentNorm = dArea * dPercent / dTotalArea;
  429. }
  430. else
  431. {
  432. CElementChemistryPtr pElementChemistry = *itr;
  433. double dAreaOld = pElementChemistry->GetPercentage() * dTotalArea * 0.01;
  434. double dArea = pElementArea->GetArea();
  435. double dPercent = pElement->GetPercentage();
  436. dPercentNorm = 100 * (0.01 * dArea * dPercent + dAreaOld) / dTotalArea;
  437. listElementChemistry.erase(itr);
  438. }
  439. CElementChemistryPtr pElement = CElementChemistryPtr(new CElementChemistry());
  440. pElement->SetName(strName);
  441. pElement->SetPercentage(dPercentNorm);
  442. listElementChemistry.push_back(pElement);
  443. }
  444. }
  445. return listElementChemistry;
  446. }
  447. }