| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588 | #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<CString> 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<CString, CSmplMsrResultFileMgrPtr> 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<CString> CReportMgr::GetDataSourceNamesList()	{		std::vector<CString> 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<int> CReportMgr::GetDataSourcePosList()	{		std::vector<int> 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;	}		}
 |