#pragma once #include "stdafx.h" #include "CGBCalculate.h" #include "OTSFieldData.h" #include "GBImgPropCal.h" #include "OTSHelper.h" #include "OTSImageProcess.h" #include "CGBLevel.h" #include namespace OTSGBCalculate { using namespace OTSDATA; using namespace OTSIMGPROC; CGBCalculate::CGBCalculate(CReportMgr* rptMgrPtr) { m_rptMgrPtr = rptMgrPtr; } CGBCalculate::~CGBCalculate() { } // class methods // public CGridDatasList CGBCalculate::GetGBInclusion() { CGBFieldList listCGBField; COTSParticleList listOTSParticle; COTSParticlePtr pOTSParticle; CGBImgPropCal pGBImgPropCal; CGridDatasList listGridData; listGridData.clear(); CGridDatasList multGridList; multGridList.clear(); // depart compound source name CPropParamPtr currentProp = m_rptMgrPtr->GetPropertyParamForGrid(); std::vector listDataSource = currentProp->GetDataSourceList(); int nSelectedDataSourceIndex = currentProp->GetDataSourceId(); CString sDataSourceNames = listDataSource[nSelectedDataSourceIndex]; std::vector listSelectedDataSource = COTSHelper::SplitString(sDataSourceNames, _T("+")); for (auto strDataSourceName : listSelectedDataSource) { listCGBField.clear(); CGridDataPtr pGridData = CGridDataPtr(new CGridData()); // data source id std::vector listDataSource; listDataSource.clear(); listDataSource = currentProp->GetDataSourceList(); pGridData->SetDataSourceList(listDataSource); int nDataSourceId = currentProp->GetDataSourceId(); pGridData->SetDataSourceId(nDataSourceId); CSmplMsrResultFileMgrPtr rstFileMgrPrt = m_rptMgrPtr->GetASmplMsrResultMgrByFileName(strDataSourceName); CSmplMsrResultFilePtr pSmplMsrResultFile = rstFileMgrPrt->GetSmplMsrResultFile(); COTSSamplePtr pSample = pSmplMsrResultFile->GetSample(); CGBFieldList listRawGBFields=CalGBFields(rstFileMgrPrt); listCGBField = listRawGBFields; CALCULATE_TABLE_TYPE ty = m_rptMgrPtr->GetPropertyParamForGrid()->GetCalTableType(); if (ty == CALCULATE_TABLE_TYPE::DIN) { listGridData = this->GetGridDataListForOneDataSourceDIN(pSmplMsrResultFile->GetAllParticles(), ty); } else { listGridData = this->GetGridDataListForOneDataSource(listCGBField, ty); } multGridList.insert (multGridList.end (), listGridData.begin(), listGridData.end()); } return multGridList; } CGridDatasList CGBCalculate::GetGridDataListForOneDataSource(CGBFieldList listCGBField, CALCULATE_TABLE_TYPE tableType) { CGridDatasList listGridData; //Definition numbers //use the nXLevel array to memory how many fields in each level. CONST int LEVEL_LENGTH = 11; int nALevel[LEVEL_LENGTH]; //nALevelZero, nALevel_0_5, nALevel_1_0, nALevel_1_5, nALevel_2_0, nALevel_2_5, nALevel_3_0, nALevel_3_5, nALevel_4_0, nALevel_4_5, nALevel_5_0 ; int nALevel_w[LEVEL_LENGTH]; //nALevelZero_f, nALevel_0_5_f, nALevel_1_0_f, nALevel_1_5_f, nALevel_2_0_f, nALevel_2_5_f, nALevel_3_0_f, nALevel_3_5_f, nALevel_4_0_f, nALevel_4_5_f, nALevel_5_0_f; int nALevel_s[LEVEL_LENGTH]; int nBLevel[LEVEL_LENGTH]; //nBLevelZero, nBLevel_0_5, nBLevel_1_0, nBLevel_1_5, nBLevel_2_0, nBLevel_2_5, nBLevel_3_0, nBLevel_3_5, nBLevel_4_0, nBLevel_4_5, nBLevel_5_0; int nBLevel_w[LEVEL_LENGTH]; //nBLevelZero_f, nBLevel_0_5_f, nBLevel_1_0_f, nBLevel_1_5_f, nBLevel_2_0_f, nBLevel_2_5_f, nBLevel_3_0_f, nBLevel_3_5_f, nBLevel_4_0_f, nBLevel_4_5_f, nBLevel_5_0_f; int nBLevel_s[LEVEL_LENGTH]; int nCLevel[LEVEL_LENGTH]; //nCLevelZero, nCLevel_0_5, nCLevel_1_0, nCLevel_1_5, nCLevel_2_0, nCLevel_2_5, nCLevel_3_0, nCLevel_3_5, nCLevel_4_0, nCLevel_4_5, nCLevel_5_0; int nCLevel_w[LEVEL_LENGTH]; //nCLevelZero_f, nCLevel_0_5_f, nCLevel_1_0_f, nCLevel_1_5_f, nCLevel_2_0_f, nCLevel_2_5_f, nCLevel_3_0_f, nCLevel_3_5_f, nCLevel_4_0_f, nCLevel_4_5_f, nCLevel_5_0_f; int nCLevel_s[LEVEL_LENGTH]; int nDLevel[LEVEL_LENGTH];// nDLevelZero, nDLevel_0_5, nDLevel_1_0, nDLevel_1_5, nDLevel_2_0, nDLevel_2_5, nDLevel_3_0, nDLevel_3_5, nDLevel_4_0, nDLevel_4_5, nDLevel_5_0; int nDLevel_w[LEVEL_LENGTH]; //nDLevelZero_f, nDLevel_0_5_f, nDLevel_1_0_f, nDLevel_1_5_f, nDLevel_2_0_f, nDLevel_2_5_f, nDLevel_3_0_f, nDLevel_3_5_f, nDLevel_4_0_f, nDLevel_4_5_f, nDLevel_5_0_f; int nDLevel_s[LEVEL_LENGTH]; int nDSulfideLevel[LEVEL_LENGTH];// nDLevelZero, nDLevel_0_5, nDLevel_1_0, nDLevel_1_5, nDLevel_2_0, nDLevel_2_5, nDLevel_3_0, nDLevel_3_5, nDLevel_4_0, nDLevel_4_5, nDLevel_5_0; int nDSulfideLevel_w[LEVEL_LENGTH]; //nDLevelZero_f, nDLevel_0_5_f, nDLevel_1_0_f, nDLevel_1_5_f, nDLevel_2_0_f, nDLevel_2_5_f, nDLevel_3_0_f, nDLevel_3_5_f, nDLevel_4_0_f, nDLevel_4_5_f, nDLevel_5_0_f; int nDSulfideLevel_s[LEVEL_LENGTH]; CGBFieldList listDSFrame; //initlize for (int i = 0; i < LEVEL_LENGTH; i++) { nALevel[i]= 0; nALevel_w[i] = 0; nALevel_s[i] = 0; nBLevel[i]=0; nBLevel_w[i] = 0; nBLevel_s[i]=0; nCLevel[i]=0; nCLevel_w[i]=0; nCLevel_s[i]=0; nDLevel[i]=0; nDLevel_w[i]=0; nDLevel_s[i] = 0; nDSulfideLevel[i] = 0; nDSulfideLevel_w[i] = 0; nDSulfideLevel_s[i] = 0; } //loop CGBField list and cal the level numbers for (CGBFieldDataPtr GBFld : listCGBField) { //CalLevel mode switch (tableType) { case CALCULATE_TABLE_TYPE::GB_Method1: GBFld->CaculateLevelByMethod1(); break; case CALCULATE_TABLE_TYPE::GB_Method2: GBFld->CaculateLevelByMethod2(); break; case CALCULATE_TABLE_TYPE::ASTM: GBFld->CaculateLevelASTM(); break; default: break; } //update the A class grid data GB_GRADE_TYPE levelt = GBFld->GetALevel()->GetThinGrade(); GB_GRADE_TYPE levelw = GBFld->GetALevel()->GetWideGrade(); GB_GRADE_TYPE levels = GBFld->GetALevel()->GetSuperGrade(); SetFrameLevelNo(levelt, nALevel); SetFrameLevelNo(levelw, nALevel_w); SetFrameLevelNo(levels, nALevel_s); //update the B class grid data levelt = GBFld->GetBLevel()->GetThinGrade(); levelw = GBFld->GetBLevel()->GetWideGrade(); levels = GBFld->GetBLevel()->GetSuperGrade(); SetFrameLevelNo(levelt, nBLevel); SetFrameLevelNo(levelw, nBLevel_w); SetFrameLevelNo(levels, nBLevel_s); //update the C class grid data levelt = GBFld->GetCLevel()->GetThinGrade(); levelw = GBFld->GetCLevel()->GetWideGrade(); levels = GBFld->GetCLevel()->GetSuperGrade(); SetFrameLevelNo(levelt, nCLevel); SetFrameLevelNo(levelw, nCLevel_w); SetFrameLevelNo(levels, nCLevel_s); //update the D class grid data levelt = GBFld->GetDLevel()->GetThinGrade(); levelw = GBFld->GetDLevel()->GetWideGrade(); levels = GBFld->GetDLevel()->GetSuperGrade(); SetFrameLevelNo(levelt, nDLevel); SetFrameLevelNo(levelw, nDLevel_w); SetFrameLevelNo(levels, nDLevel_s); //update the Ds class grid data levelt = GBFld->GetDSulfideLevel()->GetThinGrade(); levelw = GBFld->GetDSulfideLevel()->GetWideGrade(); levels = GBFld->GetDSulfideLevel()->GetSuperGrade(); SetFrameLevelNo(levelt, nDSulfideLevel); SetFrameLevelNo(levelw, nDSulfideLevel_w); SetFrameLevelNo(levels, nDSulfideLevel_s); } //Get ListGrid for Level //CalLevel mode CGridDataPtr AGrid; CGridDataPtr BGrid; CGridDataPtr CGrid; CGridDataPtr DGrid; CGridDataPtr DSulfideGrid; CGridDataPtr DSGrid; CGridDataPtr GBFieldGrid; switch (tableType) { case CALCULATE_TABLE_TYPE::GB_Method1: AGrid = GetGridLevel("A", nALevel, nALevel_w, nALevel_s); BGrid = GetGridLevel("B", nBLevel, nBLevel_w, nBLevel_s); CGrid = GetGridLevel("C", nCLevel, nCLevel_w, nCLevel_s); DGrid = GetGridLevel("D", nDLevel, nDLevel_w, nDLevel_s); DSGrid = GetGridDSLevel(listCGBField); GBFieldGrid = GetGBFieldGrid(listCGBField); listGridData.push_back(AGrid); listGridData.push_back(BGrid); listGridData.push_back(CGrid); listGridData.push_back(DGrid); listGridData.push_back(DSGrid); listGridData.push_back(GBFieldGrid); //listGridData return listGridData; break; case CALCULATE_TABLE_TYPE::GB_Method2: AGrid = GetGridLevel("A", nALevel, nALevel_w, nALevel_s); BGrid = GetGridLevel("B", nBLevel, nBLevel_w, nBLevel_s); CGrid = GetGridLevel("C", nCLevel, nCLevel_w, nCLevel_s); DGrid = GetGridLevel("D", nDLevel, nDLevel_w, nDLevel_s); DSulfideGrid = GetGridLevel("DSulfide", nDSulfideLevel, nDSulfideLevel_w, nDSulfideLevel_s); DSGrid = GetGridDSLevel(listCGBField); GBFieldGrid = GetGBFieldGrid(listCGBField); listGridData.push_back(AGrid); listGridData.push_back(BGrid); listGridData.push_back(CGrid); listGridData.push_back(DGrid); listGridData.push_back(DSulfideGrid); listGridData.push_back(DSGrid); listGridData.push_back(GBFieldGrid); //listGridData return listGridData; break; case CALCULATE_TABLE_TYPE::ASTM: AGrid = GetGridLevel("A", nALevel, nALevel_w, nALevel_s); BGrid = GetGridLevel("B", nBLevel, nBLevel_w, nBLevel_s); CGrid = GetGridLevel("C", nCLevel, nCLevel_w, nCLevel_s); DGrid = GetGridLevel("D", nDLevel, nDLevel_w, nDLevel_s); DSGrid = GetGridDSLevel(listCGBField); GBFieldGrid = GetGBFieldGrid(listCGBField); listGridData.push_back(AGrid); listGridData.push_back(BGrid); listGridData.push_back(CGrid); listGridData.push_back(DGrid); listGridData.push_back(DSGrid); listGridData.push_back(GBFieldGrid); //listGridData return listGridData; break; default: return listGridData; break; } } CGridDatasList CGBCalculate::GetGridDataListForOneDataSourceDIN(COTSParticleList listParticle, CALCULATE_TABLE_TYPE tableType ) { CGridDatasList listGridData; COTSParticleList cotsparticlelistA; set cotsparticlelistB; COTSParticleList cotsparticlelistC; COTSParticleList cotsparticlelistD; //loop CGBField list and cal the level numbers CGBFieldDataPtr GBFld(new CGBFieldData()); GBFld->SetParticleList(listParticle, TRUE); GBFld->CaculateLevelDIN(listParticle); cotsparticlelistA = GBFld->listAThinParticles; cotsparticlelistB = GBFld->listBThinParticles; cotsparticlelistC = GBFld->listCThinParticles; cotsparticlelistD = GBFld->listDThinParticles; //Get ListGrid for Level //CalLevel mode CGridDataPtr AGrid; AGrid = GetGridDIN(cotsparticlelistA, cotsparticlelistB, cotsparticlelistC, cotsparticlelistD); listGridData.push_back(AGrid); //listGridData return listGridData; } //CGridDataPtr CGBFieldMgr::GetGBFieldGrid(CGBFieldList listCGBField, CGridInPtr a_pGridIn); CGridDataPtr CGBCalculate::GetGBFieldGrid(CGBFieldList listCGBField) { CGridDataPtr pGridData = CGridDataPtr(new CGridData()); std::vector listDataSource; listDataSource.clear(); listDataSource = m_rptMgrPtr->GetPropertyParamForGrid()->GetDataSourceList(); pGridData->SetDataSourceList(listDataSource); int nDataSourceId = m_rptMgrPtr->GetPropertyParamForGrid()->GetDataSourceId(); pGridData->SetDataSourceId(nDataSourceId); //amounts CGridColumnsList listCol; listCol.clear(); int columnNum = 11;//表格总列数 fieldpos 占2列,ABCDDS 占5列,particle占1列,particle 类别占1列,particle宽度占1列 CGridColumnPtr pColumn; for (int i = 0; i < columnNum; i++) { CString strName; CGridRowsList listRows; CGridRowPtr pRow; switch (i) { case 0: pColumn = CGridColumnPtr(new CGridColumn()); pColumn->SetName("FieldPosX"); for (auto GBF : listCGBField) { for (auto p : GBF->GetParticleList()) { pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT); pRow->SetIntValue(GBF->GetPosition().x); listRows.push_back(pRow); } } pColumn->SetGridRowsList(listRows); listCol.push_back(pColumn); break; case 1: pColumn = CGridColumnPtr(new CGridColumn()); pColumn->SetName("FieldPosY"); for (auto GBF : listCGBField) { for (auto p : GBF->GetParticleList()) { pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT); pRow->SetIntValue(GBF->GetPosition().y); listRows.push_back(pRow); } } pColumn->SetGridRowsList(listRows); listCol.push_back(pColumn); break; case 2: pColumn = CGridColumnPtr(new CGridColumn()); pColumn->SetName("ALevel"); for (auto GBF : listCGBField) { for (auto p : GBF->GetParticleList()) { pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING ); std::string Athin, Awide, Asuper; auto Alevel = GBF->GetALevel(); auto thin = Alevel->GetThinGrade(); Athin = GetLevelStr(thin); Awide = GetLevelStr(Alevel->GetWideGrade()); Asuper = GetLevelStr(Alevel->GetSuperGrade()); pRow->SetStringValue((Athin + "," + Awide + "," + Asuper).c_str()); listRows.push_back(pRow); } } pColumn->SetGridRowsList(listRows); listCol.push_back(pColumn); break; case 3: pColumn = CGridColumnPtr(new CGridColumn()); pColumn->SetName("BLevel"); for (auto GBF : listCGBField) { for (auto p : GBF->GetParticleList()) { pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING ); std::string thin, wide, super; auto level = GBF->GetBLevel(); thin = GetLevelStr(level->GetThinGrade()); wide = GetLevelStr(level->GetWideGrade()); super = GetLevelStr(level->GetSuperGrade()); pRow->SetStringValue((thin + "," + wide + "," + super).c_str()); listRows.push_back(pRow); } } pColumn->SetGridRowsList(listRows); listCol.push_back(pColumn); break; case 4: pColumn = CGridColumnPtr(new CGridColumn()); pColumn->SetName("CLevel"); for (auto GBF : listCGBField) { for (auto p : GBF->GetParticleList()) { pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING ); std::string thin, wide, super; auto level = GBF->GetCLevel(); thin = GetLevelStr(level->GetThinGrade()); wide = GetLevelStr(level->GetWideGrade()); super = GetLevelStr(level->GetSuperGrade()); pRow->SetStringValue((thin + "," + wide + "," + super).c_str()); listRows.push_back(pRow); } } pColumn->SetGridRowsList(listRows); listCol.push_back(pColumn); break; case 5: pColumn = CGridColumnPtr(new CGridColumn()); pColumn->SetName("DLevel"); for (auto GBF : listCGBField) { for (auto p : GBF->GetParticleList()) { pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING ); std::string thin, wide, super; auto level = GBF->GetDLevel(); thin = GetLevelStr(level->GetThinGrade()); wide = GetLevelStr(level->GetWideGrade()); super = GetLevelStr(level->GetSuperGrade()); pRow->SetStringValue((thin + "," + wide + "," + super).c_str()); listRows.push_back(pRow); } } pColumn->SetGridRowsList(listRows); listCol.push_back(pColumn); break; case 6: pColumn = CGridColumnPtr(new CGridColumn()); pColumn->SetName("DSLevel"); for (auto GBF : listCGBField) { for (auto p : GBF->GetParticleList()) { pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING ); std::string thin, wide, super; auto level = GBF->GetDSLevel(); thin = GetLevelStr(level->GetThinGrade()); wide = GetLevelStr(level->GetWideGrade()); super = GetLevelStr(level->GetSuperGrade()); pRow->SetStringValue((thin + "," + wide + "," + super).c_str()); listRows.push_back(pRow); } } pColumn->SetGridRowsList(listRows); listCol.push_back(pColumn); break; case 7: pColumn = CGridColumnPtr(new CGridColumn()); pColumn->SetName("DSulfideLevel"); for (auto GBF : listCGBField) { for (auto p : GBF->GetParticleList()) { pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING ); std::string thin, wide, super; auto level = GBF->GetDSulfideLevel(); thin = GetLevelStr(level->GetThinGrade()); wide = GetLevelStr(level->GetWideGrade()); super = GetLevelStr(level->GetSuperGrade()); pRow->SetStringValue((thin + "," + wide + "," + super).c_str()); listRows.push_back(pRow); } } pColumn->SetGridRowsList(listRows); listCol.push_back(pColumn); break; case 8: pColumn = CGridColumnPtr(new CGridColumn()); pColumn->SetName("Particle"); for (auto GBF : listCGBField) { for (auto p : GBF->GetParticleList()) { pRow = CGridRowPtr(new CGridRow()); pRow->SetParticle(p); listRows.push_back(pRow); } } pColumn->SetGridRowsList(listRows); listCol.push_back(pColumn); break; case 9: pColumn = CGridColumnPtr(new CGridColumn()); pColumn->SetName("ParticleGBClass"); for (auto GBF : listCGBField) { for (auto p : GBF->GetParticleList()) { int l = (int)GBF->mapAllParticles[p].myType; pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT); pRow->SetIntValue(l); listRows.push_back(pRow); } } pColumn->SetGridRowsList(listRows); listCol.push_back(pColumn); break; case 10: pColumn = CGridColumnPtr(new CGridColumn()); pColumn->SetName("ParticleGBWidthClass"); for (auto GBF : listCGBField) { for (auto p : GBF->GetParticleList()) { int w = (int)GBF->mapAllParticles[p].myWidth; pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT); pRow->SetIntValue(w); listRows.push_back(pRow); } } pColumn->SetGridRowsList(listRows); listCol.push_back(pColumn); break; default: break; } } pGridData->SetGridColumnList(listCol); return pGridData; } std::string CGBCalculate::GetLevelStr(GB_GRADE_TYPE l) { std::string s; switch (l) { case GB_GRADE_TYPE::POINT_0_0 : s = "0"; break; case GB_GRADE_TYPE::POINT_0_5: s = "0.5"; break; case GB_GRADE_TYPE::POINT_1_0: s = "1"; break; case GB_GRADE_TYPE::POINT_1_5: s = "1.5"; break; case GB_GRADE_TYPE::POINT_2_0: s = "2"; break; case GB_GRADE_TYPE::POINT_2_5: s = "2.5"; break; case GB_GRADE_TYPE::POINT_3_0: s = "3"; break; case GB_GRADE_TYPE::POINT_3_5: s = "3.5"; break; case GB_GRADE_TYPE::POINT_4_0: s = "4"; break; case GB_GRADE_TYPE::POINT_4_5: s = "4.5"; break; case GB_GRADE_TYPE::POINT_5_0: s = "5"; break; default: s = "0"; break; } return s; } //get grid with level ABCD CGridDataPtr CGBCalculate::GetGridLevel(CString GridType,int a_nLevel[], int a_nLevel_w[], int a_nLevel_s[]) { CGridDataPtr pGridData = CGridDataPtr(new CGridData()); std::vector listDataSource; listDataSource.clear(); listDataSource = m_rptMgrPtr->GetPropertyParamForGrid()->GetDataSourceList(); pGridData->SetDataSourceList(listDataSource); int nDataSourceId = m_rptMgrPtr->GetPropertyParamForGrid()->GetDataSourceId(); pGridData->SetDataSourceId(nDataSourceId); //amounts CGridColumnsList listCol; listCol.clear(); int columnNum = 11 + 1 + 1;//表格总列数 12个级别再加上前面的“分类”列和“宽度/um”列 CGridColumnPtr pColumn; for (int i=0;i< columnNum;i++) { CString strName; CGridRowsList listRows; CGridRowPtr pRow; CString strWidthName1, strWidthName2, strWidthName3; switch( i) { case 0: pColumn = CGridColumnPtr(new CGridColumn()); //strName = MultiLang::GetInstance ().GetCStringByKey (GBStr1); strName = "Class"; pColumn->SetName(strName); pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING); pRow->SetStringValue("Thin"); //MultiLang::GetInstance().GetCStringByKey(GBStr2) listRows.push_back(pRow); pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING); pRow->SetStringValue("Thick"); //MultiLang::GetInstance().GetCStringByKey(GBStr3) listRows.push_back(pRow); pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING); pRow->SetStringValue("OverSize"); //MultiLang::GetInstance().GetCStringByKey(GBStr4) listRows.push_back(pRow); pColumn->SetGridRowsList(listRows); listCol.push_back(pColumn); break; case 1: pColumn = CGridColumnPtr(new CGridColumn()); strName = "Width/um"; //MultiLang::GetInstance().GetCStringByKey(GBStr5); pColumn->SetName(strName); if (GridType == "A") { strWidthName1 = "2.0~4.0"; strWidthName2 = "4.0~12.0"; strWidthName3 = ">12.0"; } if (GridType == "B") { strWidthName1 = "2.0~9.0"; strWidthName2 = "9.0~15.0"; strWidthName3 = ">15.0"; } if (GridType == "C") { strWidthName1 = "2.0~5.0"; strWidthName2 = "5.0~12.0"; strWidthName3 = ">12.0"; } if (GridType == "D") { strWidthName1 = "2.0~8.0"; strWidthName2 = "8.0~13.0"; strWidthName3 = ">13.0"; } if (GridType == "DSulfide") { strWidthName1 = "2.0~8.0"; strWidthName2 = "8.0~13.0"; strWidthName3 = ">13.0"; } pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING); pRow->SetStringValue(strWidthName1); listRows.push_back(pRow); pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING); pRow->SetStringValue(strWidthName2); listRows.push_back(pRow); pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING); pRow->SetStringValue(strWidthName3); listRows.push_back(pRow); pColumn->SetGridRowsList(listRows); listCol.push_back(pColumn); break; default: pColumn = CGridColumnPtr(new CGridColumn()); CString name; name.Format(_T("%.1f"), (i - 2) / 2.0);//i=2 输出0 i=3 输出0.5 i=4 输出1 以此类推 pColumn->SetName(name); CGridRowsList listRows; pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT); pRow->SetIntValue(a_nLevel[i - 2]); listRows.push_back(pRow); pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT); pRow->SetIntValue(a_nLevel_w[i - 2]); listRows.push_back(pRow); pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT); pRow->SetIntValue(a_nLevel_s[i - 2]); listRows.push_back(pRow); pColumn->SetGridRowsList(listRows); listCol.push_back(pColumn); break; } } pGridData->SetGridColumnList(listCol); return pGridData; } CGridDataPtr CGBCalculate::GetGridDSLevel(CGBFieldList listCGBField) { CGridDataPtr pGridData = CGridDataPtr(new CGridData()); std::vector listDataSource; listDataSource.clear(); listDataSource = m_rptMgrPtr->GetPropertyParamForGrid()->GetDataSourceList(); pGridData->SetDataSourceList(listDataSource); int nDataSourceId = m_rptMgrPtr->GetPropertyParamForGrid()->GetDataSourceId(); pGridData->SetDataSourceId(nDataSourceId); //amounts CGridColumnsList listCol; listCol.clear(); int columnNum = 6; CGridColumnPtr pColumn; for (int i = 0; i < columnNum; i++) { CString strName; CGridRowsList listRows[6]; CGridRowPtr pRow; CString strWidthName1, strWidthName2, strWidthName3; switch (i) { case 0: pColumn = CGridColumnPtr(new CGridColumn()); strName = "No."; //MultiLang::GetInstance().GetCStringByKey(GBStr6); pColumn->SetName(strName); pColumn->SetGridRowsList(listRows[0]); listCol.push_back(pColumn); break; case 1: pColumn = CGridColumnPtr(new CGridColumn()); strName = "Area/um2"; //MultiLang::GetInstance().GetCStringByKey(GBStr7); pColumn->SetName(strName); pColumn->SetGridRowsList(listRows[1]); listCol.push_back(pColumn); break; case 2: pColumn = CGridColumnPtr(new CGridColumn()); strName = "MaxFeret/um";// MultiLang::GetInstance().GetCStringByKey(GBStr8); pColumn->SetName(strName); pColumn->SetGridRowsList(listRows[2]); listCol.push_back(pColumn); break; case 3: pColumn = CGridColumnPtr(new CGridColumn()); strName = "X/mm"; pColumn->SetName(strName); pColumn->SetGridRowsList(listRows[3]); listCol.push_back(pColumn); break; case 4: pColumn = CGridColumnPtr(new CGridColumn()); strName = "Y/mm"; pColumn->SetName(strName); pColumn->SetGridRowsList(listRows[4]); listCol.push_back(pColumn); break; case 5: pColumn = CGridColumnPtr(new CGridColumn()); strName = "Grade";// MultiLang::GetInstance().GetCStringByKey(GBStr9); pColumn->SetName(strName); pColumn->SetGridRowsList(listRows[5]); listCol.push_back(pColumn); break; } } for (CGBFieldDataPtr frame : listCGBField) { auto dsparticles = frame->listDSParticles; for (auto part : dsparticles) { for (int i = 0; i < columnNum; i++) { CString strName; CGridRowsList listRows; CGridRowPtr pRow; CString strWidthName1, strWidthName2, strWidthName3; CString idstr; int fldid; int partId; switch (i) { case 0: pColumn = listCol.at(0); pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING); fldid = part->GetFieldId(); partId = part->GetTagId(); idstr.Format("%d_%d", fldid,partId); pRow->SetStringValue(idstr); pColumn->AddGridRow(pRow); break; case 1: pColumn = listCol.at(1); pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT); pRow->SetIntValue(part->GetActualArea()); pColumn->AddGridRow(pRow); break; case 2: pColumn = listCol.at(2); pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); pRow->SetDoubleValue(part->GetFeretDiameter()); pColumn->AddGridRow(pRow); break; case 3: pColumn = listCol.at(3); pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT); pRow->SetIntValue(part->GetAbsolutPos().x); pColumn->AddGridRow(pRow); break; case 4: pColumn = listCol.at(4); pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT); pRow->SetIntValue(part->GetAbsolutPos().y); pColumn->AddGridRow(pRow); break; case 5: pColumn = listCol.at(5); pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT); pRow->SetIntValue((int)OTSGBCalculate::GetDSGrade(part->GetFeretDiameter())); pColumn->AddGridRow(pRow); break; } } } } pGridData->SetGridColumnList(listCol); return pGridData; } //get grid with level ABCD CGridDataPtr CGBCalculate::GetGridDIN(COTSParticleList cotsparticlelistA, set cotsparticlelistB, COTSParticleList cotsparticlelistC, COTSParticleList cotsparticlelistD) { CGridDataPtr pGridData = CGridDataPtr(new CGridData()); std::vector listDataSource; listDataSource.clear(); listDataSource = m_rptMgrPtr->GetPropertyParamForGrid()->GetDataSourceList(); pGridData->SetDataSourceList(listDataSource); int nDataSourceId = m_rptMgrPtr->GetPropertyParamForGrid()->GetDataSourceId(); pGridData->SetDataSourceId(nDataSourceId); //amounts CGridColumnsList listCol; listCol.clear(); int columnNum = 12;//表格总列数 11个级别再加上前面的“分类”列 CGridColumnPtr pColumn; int levA[9] = { 0,0,0,0,0,0,0,0,0 }; int levB[9] = { 0,0,0,0,0,0,0,0,0 }; int levC[9] = { 0,0,0,0,0,0,0,0,0 }; int levD[9] = { 0,0,0,0,0,0,0,0,0 }; double fg[9] = { 0.05,0.1,0.2,0.5,1,2,5,10,20 }; //指数 double ka = 0, kb = 0, kc = 0, kd = 0; //统计不同大小颗粒出现次数 for (auto pParticle : cotsparticlelistA) { double area = pParticle->GetActualArea(); for (int i = 0; i < 8; i++) { if (area >= fg[i] && area < fg[i + 1]) { levA[i] += 1; ka = ka + fg[i]; } } if (area >= fg[8]) { levA[8] += 1; ka = ka + fg[8]; } } for (auto pParticle : cotsparticlelistB) { double area = pParticle->GetActualArea(); for (int i = 0; i < 8; i++) { if (area >= fg[i] && area < fg[i + 1]) { levB[i] += 1; kb = kb + fg[i]; } } if (area >= fg[8]) { levB[8] += 1; kb = kb + fg[8]; } } for (auto pParticle : cotsparticlelistC) { double area = pParticle->GetActualArea(); for (int i = 0; i < 8; i++) { if (area >= fg[i] && area < fg[i + 1]) { levC[i] += 1; kc = kc + fg[i]; } } if (area >= fg[8]) { levC[8] += 1; kc = kc + fg[8]; } } for (auto pParticle : cotsparticlelistD) { double area = pParticle->GetActualArea(); for (int i = 0; i < 8; i++) { if (area >= fg[i] && area < fg[i + 1]) { levD[i] += 1; kd = kd + fg[i]; } } if (area >= fg[8]) { levD[8] += 1; kd = kd + fg[8]; } } double to = kb + kc + kd; for (int i = 0; i < columnNum; i++) { CString strName; CGridRowsList listRows; CGridRowPtr pRow; CString strWidthName1, strWidthName2, strWidthName3, strWidthName4; switch (i) { case 0: pColumn = CGridColumnPtr(new CGridColumn()); strName = "Class"; pColumn->SetName(strName); pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING); pRow->SetStringValue("SS"); listRows.push_back(pRow); pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING); pRow->SetStringValue("OA"); listRows.push_back(pRow); pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING); pRow->SetStringValue("OS"); listRows.push_back(pRow); pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::STRING); pRow->SetStringValue("OG"); listRows.push_back(pRow); pColumn->SetGridRowsList(listRows); listCol.push_back(pColumn); break; case 10: pColumn = CGridColumnPtr(new CGridColumn()); strName = "S"; pColumn->SetName(strName); strWidthName1.Format(_T("%lf"), ka); strWidthName2 = ""; strWidthName3 = ""; strWidthName4 = ""; pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); pRow->SetDoubleValue(ka); listRows.push_back(pRow); pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); pRow->SetDoubleValue(0); listRows.push_back(pRow); pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); pRow->SetDoubleValue(0); listRows.push_back(pRow); pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); pRow->SetDoubleValue(0); listRows.push_back(pRow); pColumn->SetGridRowsList(listRows); listCol.push_back(pColumn); break; case 11: pColumn = CGridColumnPtr(new CGridColumn()); strName = "O"; pColumn->SetName(strName); strWidthName1.Format(_T("%lf"), to); strWidthName2 = ""; strWidthName3 = ""; strWidthName4 = ""; pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); pRow->SetDoubleValue(0); listRows.push_back(pRow); pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); pRow->SetDoubleValue(kb); listRows.push_back(pRow); pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); pRow->SetDoubleValue(kc); listRows.push_back(pRow); pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::FLOAT); pRow->SetDoubleValue(kd); listRows.push_back(pRow); pColumn->SetGridRowsList(listRows); listCol.push_back(pColumn); break; default: pColumn = CGridColumnPtr(new CGridColumn()); strName.Format("%d", i - 1); pColumn->SetName(strName); CGridRowsList listRows; pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT); pRow->SetIntValue(levA[i - 1]); listRows.push_back(pRow); pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT); pRow->SetIntValue(levB[i - 1]); listRows.push_back(pRow); pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT); pRow->SetIntValue(levC[i - 1]); listRows.push_back(pRow); pRow = CGridRowPtr(new CGridRow()); pRow->SetDataType(REPORT_GRID_DATA_TYPE::INT); pRow->SetIntValue(levD[i - 1]); listRows.push_back(pRow); pColumn->SetGridRowsList(listRows); listCol.push_back(pColumn); break; } } pGridData->SetGridColumnList(listCol); return pGridData; } void CGBCalculate::SetFrameLevelNo(GB_GRADE_TYPE a_level, int a_nLevel[]) { a_nLevel[(int)a_level] += 1; } // calculate GB fields CGBFieldList CGBCalculate::CalGBFields(CSmplMsrResultFileMgrPtr pSmplMgr) { CGBFieldList m_listGBFields; m_listGBFields.clear(); ASSERT(pSmplMgr); CSmplMsrResultFilePtr pSmplMsrResultFile = pSmplMgr->GetSmplMsrResultFile(); ASSERT(pSmplMsrResultFile); COTSSamplePtr pOTSSample = pSmplMsrResultFile->GetSample(); ASSERT(pOTSSample); CSEMDataMsrPtr pEMDataMsrPtr = pOTSSample->GetSEMDataMsr(); ASSERT(pEMDataMsrPtr); // get field width int nOTSFieldWidth = pEMDataMsrPtr->GetScanFieldSize(); int nOTSFieldHeight = pEMDataMsrPtr->GetScanFieldHeight(); if (nOTSFieldWidth == 0 || nOTSFieldHeight==0) { LogErrorTrace(__FILE__, __LINE__, _T("CalGBFields: field width is zero .")); return m_listGBFields; } // scan parameters CMsrParamsPtr pMsrParam = pOTSSample->GetMsrParams(); //CMsrParamsPtr pMsrParam = pOTSSample->get COTSImageScanParamPtr pImgScanParam = pMsrParam->GetImageScanParam(); CSize sizePixelImage = pImgScanParam->GetImageResolution(); //use OTSField width cal the OTSField height //get OTSfilds list COTSFieldDataList allOTSFields; allOTSFields = pSmplMsrResultFile->GetFieldData(); // convert ots fields to gb fields if (!OTSFieldToGBField( allOTSFields, &m_listGBFields, sizePixelImage, nOTSFieldWidth, nOTSFieldHeight)) { LogErrorTrace(__FILE__, __LINE__, _T("CalGBFields: call OTSFieldToGBField failed.")); return m_listGBFields; } return m_listGBFields; } // Turn OTSField to GBField BOOL CGBCalculate::OTSFieldToGBField(COTSFieldDataList allOTSFields, CGBFieldList* m_listGBFields,CSize sizePixelImage,int nOTSFieldWidth,int nOTSFieldHeight) { if (allOTSFields.empty()) { LogTrace(__FILE__, __LINE__, _T("CalGBFields: listOTSFields is empty .")); return TRUE; } // get topleft point and bottomright point of the measurement convered area CPoint pointTopleft, pointBottomright; pointTopleft = pointBottomright = allOTSFields[0]->GetPosition(); //判断有效区域 for (unsigned int i = 0; i< allOTSFields.size(); i++) { //get current OTSField Position,the position is in the center of the field CPoint poiOTSFieldPosition = allOTSFields[i]->GetPosition(); pointTopleft.x = min(poiOTSFieldPosition.x, pointTopleft.x); pointTopleft.y = max(poiOTSFieldPosition.y, pointTopleft.y); pointBottomright.x = max(poiOTSFieldPosition.x, pointBottomright.x); pointBottomright.y = min(poiOTSFieldPosition.y, pointBottomright.y); } pointTopleft.x -= nOTSFieldWidth / 2; pointTopleft.y += nOTSFieldHeight / 2; pointBottomright.x+= nOTSFieldWidth / 2; pointBottomright.y-= nOTSFieldHeight / 2; double totalWidth = pointBottomright.x - pointTopleft.x; double totalHeight = pointTopleft.y - pointBottomright.y; int nPossibleGBFieldRowNum = totalHeight /GB_FIELD_WIDTH+0.5;//可能有的国标field行数 int nPossibleGBFieldColNum = totalWidth / GB_FIELD_WIDTH+0.5;//列数 //get possible OTSFields m_listGBFields->clear(); CPoint pointGBFieldPosition; for (int i = 0; i < nPossibleGBFieldRowNum; i++) { for (int j = 0; j < nPossibleGBFieldColNum; j++) { // cal GB field rectangle CPoint poiCurGBFieldTopLeft, poiCurGBFieldBottomRight; poiCurGBFieldTopLeft = pointTopleft; //获得左上角的坐标 poiCurGBFieldTopLeft.x += j * GB_FIELD_WIDTH; poiCurGBFieldTopLeft.y -= i * GB_FIELD_WIDTH; //获得右下角的坐标 poiCurGBFieldBottomRight.x = poiCurGBFieldTopLeft.x + GB_FIELD_WIDTH; poiCurGBFieldBottomRight.y = poiCurGBFieldTopLeft.y - GB_FIELD_WIDTH; COTSRect rectGBField(poiCurGBFieldTopLeft, poiCurGBFieldBottomRight); CGBFieldDataPtr pGBFieldData; pGBFieldData = GetOneGBField(rectGBField, allOTSFields, sizePixelImage, nOTSFieldWidth, nOTSFieldHeight); if (!pGBFieldData) { continue; } CPoint poiNewPosition=rectGBField.GetCenterPoint(); pGBFieldData->SetPosition(poiNewPosition); // add the GBField into the GBFields list m_listGBFields->push_back(pGBFieldData); } } // ok, return TRUE return TRUE; } // Custom collation rules BOOL comp(const COTSFieldDataPtr &a, const COTSFieldDataPtr &b) { if (a->GetPosition().y <= b->GetPosition().y) { if (a->GetPosition().y == b->GetPosition().y) { if (a->GetPosition().x < b->GetPosition().x) { return TRUE; } } else { return TRUE; } } return FALSE; } // get the GB field within a rectangle CGBFieldDataPtr CGBCalculate::GetOneGBField(COTSRect a_rectGBField, COTSFieldDataList& allOTSFields, CSize a_sizePixelImage, int nOTSFieldWidth, int nOTSFieldHeight) { // GB Field handle CGBFieldDataPtr pGBFieldData = nullptr; // get OTS fields within the rectangle COTSFieldDataList myOTSFields; myOTSFields.clear(); COTSFieldDataList::iterator itr = allOTSFields.begin(); while (itr != allOTSFields.end()) { // get an OTS field CPoint poiOTSField = (*itr)->GetPosition(); COTSRect fldRec = COTSRect(poiOTSField.x - nOTSFieldWidth / 2, poiOTSField.y + nOTSFieldHeight / 2, poiOTSField.x + nOTSFieldWidth / 2, poiOTSField.y - nOTSFieldHeight / 2); if (a_rectGBField.IntersectOtherRect( fldRec)) { (*itr)->SetRect(fldRec); myOTSFields.push_back(*itr); itr++; continue; } itr++; } pGBFieldData = NormalizeParticles(a_rectGBField, myOTSFields, a_sizePixelImage, nOTSFieldWidth, nOTSFieldHeight); pGBFieldData->myReleventOTSFlds = myOTSFields; return pGBFieldData; } // normalize particles for the GBFields CGBFieldDataPtr CGBCalculate::NormalizeParticles(COTSRect a_rectGBField, COTSFieldDataList myOTSFields, CSize a_sizePixelImage, int nFieldWidth,int nFieldHeight) { // inits CGBFieldDataPtr pGBFieldData(new CGBFieldData); pGBFieldData->SetMyRect(a_rectGBField); COTSParticleList listNormalizedParticles; CPoint pointGBFieldRectTopLeft = a_rectGBField.GetTopLeft(); COTSRect GBRect = a_rectGBField; int nBeforeCalNo = 0; int nAfterCalNo = 0; for (auto OTSField : myOTSFields) { for (auto part : OTSField->GetParticleList()) { CPoint fieldPos = OTSField->GetPosition(); //CPoint fieldTopLeft = CPoint(fieldPos.x - nFieldWidth / 2, fieldPos.y + nFieldHeight/2); CPoint fieldTopLeft = OTSField->GetRect().GetTopLeft(); double fwidth = nFieldWidth; double pixelsize = fwidth / a_sizePixelImage.cx; CPoint xrayPosInFieldByPixel= part->GetXRayPos(); CPoint partPos = CPoint(fieldTopLeft.x + xrayPosInFieldByPixel.x * pixelsize, fieldTopLeft.y - xrayPosInFieldByPixel.y * pixelsize); if (GBRect.PointInRect(partPos)) { CRect rectInSinglefld = part->GetParticleRect(); CPoint OTSLeftTop = CPoint(fieldTopLeft.x + rectInSinglefld.left * pixelsize, fieldTopLeft.y - rectInSinglefld.top * pixelsize); CPoint OTSRightBottom = CPoint(fieldTopLeft.x + rectInSinglefld.right * pixelsize, fieldTopLeft.y - rectInSinglefld.bottom * pixelsize); COTSRect recInOTSCord = COTSRect(OTSLeftTop, OTSRightBottom); part->SetOTSRect(recInOTSCord); pGBFieldData->IdentifyPartChemicalType(part); listNormalizedParticles.push_back(part); } } } // put new particle in the GB Field pGBFieldData->SetParticleList(listNormalizedParticles); return pGBFieldData; } void CGBCalculate::SetPixSize(double p) { PixSize = p; } }