ReportMgr.cpp 15 KB

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