ReportMgr.cpp 15 KB

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