//#define _CRTDBG_MAP_ALLOC #include #include #include "stdafx.h" #include "OTSModelresource.h" #include "OTSDATAresource.h" #include "OTSProgMgr.h" #include "OTSFileSys.h" #include "MultiLang.h" namespace OTSMODEL { // parameter initialization value // auto name const CString AUTO_NAME = _T("Sample"); // sample name const CString SAMPLE_NAME = _T("Sample"); // measure switch const BOOL MEASURE_SWITCH = TRUE; // stop mode const OTS_MEASURE_STOP_MODE STOPT_MODE = OTS_MEASURE_STOP_MODE::CoverMode; // stop time const int MEASURE_TIME = 360; // stop field num const int FIELDS_NUM = 200; // stop part num const int PARTICL_NUM = 50000; // get image mode const OTS_GET_IMAGE_MODE FETCH_IMAGE_MODE = OTS_GET_IMAGE_MODE::FROM_CENTER; // scan speed const OTS_THREE_TIES_OPTIONS SCAN_SPEED = OTS_THREE_TIES_OPTIONS::TIE2; // image size const OTS_FIVE_TIES_OPTIONS IMAGE_WIDTH = OTS_FIVE_TIES_OPTIONS::TIE1; // particle area const CDoubleRange INCA_AREA = { 5, 100 }; // background gray const CIntRange BACK_GRAY = { 100, 255 }; // particle gray const CIntRange INCA_GRAY = { 5, 100 }; // XRay scan mode const OTS_X_RAY_SCAN_MODE SCAN_MODE = OTS_X_RAY_SCAN_MODE::PointMode; // XRay search speed const OTS_THREE_TIES_OPTIONS SEARCH_SPEED = OTS_THREE_TIES_OPTIONS::TIE2; // XRay search count const int SEARCH_COUNT = 5000; // XRay analysis speed const OTS_THREE_TIES_OPTIONS ANALYSIS_SPEED = OTS_THREE_TIES_OPTIONS::TIE2; // XRay analysis expect count const int ANALYSIS_EXPECT_COUNT = 10000; //stage data x start const long STAGE_DATA_X_AXIS_START = -100000; //stage data x end const long STAGE_DATA_X_AXIS_END = 100000; //stage data y start const long STAGE_DATA_Y_AXIS_START = -100000; //stage data y end const long STAGE_DATA_Y_AXIS_END = 100000; //stage data x direction const OTS_X_AXIS_DIRECTION STAGE_DATA_X_AXIS_DIRECTION = OTS_X_AXIS_DIRECTION::LEFT_TOWARD; //stage data y direction const OTS_Y_AXIS_DIRECTION STAGE_DATA_Y_AXIS_DIRECTION = OTS_Y_AXIS_DIRECTION::UP_TOWARD; //100 scan screen width const int SCREEN_WIDTH_MAG100 = 1142; COTSProgMgr::COTSProgMgr() { } COTSProgMgr::~COTSProgMgr() { } // // function: LoadInfoFromProgMgrFile // input: soft ware id, IncA is 0, ParA is 1 // action: normally, there is a program manager file in system data, this function is used to read the file // get information from it. Once there is no such file, this function can create a file. // return: program manager file containing parameter data, nullptr if failed COTSProgMgrParamFilePtr COTSProgMgr::LoadInfoFromProgMgrFile(OTS_SOFT_PACKAGE_ID a_nPackId) { /*int tmpFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); tmpFlag |= _CRTDBG_LEAK_CHECK_DF; _CrtSetDbgFlag(tmpFlag);*/ //_CrtSetBreakAlloc(1963); // create a program (preference) file manager pointer COTSProgMgrParamFilePtr pProgMgrParamFile = COTSProgMgrParamFilePtr(new COTSProgMgrParamFile()); // get software pack measure preference file pathname CString strProgMgrParamFilePathName = COTSFileSys::GetOTSPackMeasurePrefFilePathName(a_nPackId); if (strProgMgrParamFilePathName.IsEmpty()) { // shouldn't happen, software pack measure preference file pathname is empty, return nullptr LogErrorTrace(__FILE__, __LINE__, _T("LoadInfoFromProgMgrFile: failed to find program manager param file pathname.")); return nullptr; } // program manager param file exists? if (COTSFileSys::Exists(strProgMgrParamFilePathName)) { // tried to load it if (!pProgMgrParamFile->Load(strProgMgrParamFilePathName)) { // failed to load the license info file LogErrorTrace(__FILE__, __LINE__, _T("LoadLicenseInfoFile: failed to load license info file. pathname: %s"), strProgMgrParamFilePathName); return nullptr; } } else { // get app system file path CString strCompanySysDataPath = COTSFileSys::GetOTSPackSysDataPathName(a_nPackId); if (strCompanySysDataPath.IsEmpty()) { // shouldn't happen, program manager param file pathname is empty, return nullptr LogErrorTrace(__FILE__, __LINE__, _T("LoadInfoFromProgMgrFile: failed to company system data pathname.")); return nullptr; } // company system data path exists? if (!COTSFileSys::Exists(strCompanySysDataPath)) { // company system data path doesn't exists, create it if (!COTSFileSys::CreateFolder(strCompanySysDataPath)) { // failed to create company system data path, can't go any further, return nullptr LogErrorTrace(__FILE__, __LINE__, _T("LoadInfoFromProgMgrFile: failed to create system path.")); return nullptr; } } // SEM stage CSEMStageDataPtr pStageData = CSEMStageDataPtr(new CSEMStageData()); pStageData->SetScanFieldSize100(SCREEN_WIDTH_MAG100); CIntRangePtr pXAxis = CIntRangePtr(new CIntRange(STAGE_DATA_X_AXIS_START, STAGE_DATA_X_AXIS_END)); pStageData->SetXAxis(pXAxis); CIntRangePtr pYAxis = CIntRangePtr(new CIntRange(STAGE_DATA_Y_AXIS_START, STAGE_DATA_Y_AXIS_END)); pStageData->SetYAxis(pYAxis); pStageData->SetXAxisDir(STAGE_DATA_X_AXIS_DIRECTION); pStageData->SetYAxisDir(STAGE_DATA_Y_AXIS_DIRECTION); pStageData->SetMinMag(MAGNIFICATION_MIN); // general parameter COTSGeneralParametersPtr pGenParam = COTSGeneralParametersPtr(new COTSGeneralParameters()); pGenParam->SetSampleName(SAMPLE_NAME); pGenParam->SetMeasurementSwitch(MEASURE_SWITCH); // get software pack program data path CString strOTSProDataPathName = COTSFileSys::GetOTSPackProgDataPathName(a_nPackId); if (strOTSProDataPathName.IsEmpty()) { // shouldn't happen, software pack program data path is empty LogErrorTrace(__FILE__, __LINE__, _T("LoadInfoFromProgMgrFile: failed to get software pack program data path.")); return FALSE; } pGenParam->SetMsrParamFileFolderName(strOTSProDataPathName); pGenParam->SetPartSTDLibFolderName(strOTSProDataPathName); //image scan parameter COTSImageScanParamPtr pImageScanParam = COTSImageScanParamPtr(new COTSImageScanParam()); pImageScanParam->SetStopMode(STOPT_MODE); pImageScanParam->SetStopParamMeasTime(MEASURE_TIME); pImageScanParam->SetStopParamFields(FIELDS_NUM); pImageScanParam->SetStopParamParticles(PARTICL_NUM); pImageScanParam->SetStartImageMode(FETCH_IMAGE_MODE); pImageScanParam->SetScanImageSpeed(SCAN_SPEED); pImageScanParam->SetImagePixelSize(IMAGE_WIDTH); //image process parameter COTSImageProcessParamPtr pImageProcParam = COTSImageProcessParamPtr(new COTSImageProcessParam()); pImageProcParam->SetIncArea(INCA_AREA); pImageProcParam->SetBGGray(BACK_GRAY); pImageProcParam->SetParticleGray(INCA_GRAY); // X-Ray parameter COTSXRayParamPtr pXRayParam = COTSXRayParamPtr(new COTSXRayParam()); pXRayParam->SetScanMode(SCAN_MODE); pXRayParam->SetSearchSpeed(SEARCH_SPEED); pXRayParam->SetXRaySearchCount(SEARCH_COUNT); pXRayParam->SetAnalySpeed(ANALYSIS_SPEED); pXRayParam->SetAnalyExpCount(ANALYSIS_EXPECT_COUNT); // set the program (preference) file to default pProgMgrParamFile->SetStageData(pStageData); pProgMgrParamFile->SetGenParam(pGenParam); pProgMgrParamFile->SetImageScanParam(pImageScanParam); pProgMgrParamFile->SetImageProcParam(pImageProcParam); pProgMgrParamFile->SetXRayParam(pXRayParam); // create the program (preference) file if (!pProgMgrParamFile->Save(strProgMgrParamFilePathName)) { // failed to create LogErrorTrace(__FILE__, __LINE__, _T("LoadInfoFromProgMgrFile: create program manager file failed.")); return nullptr; } } // ok, return the program (preference) file return pProgMgrParamFile; } // safe parameters into program preference file BOOL COTSProgMgr::SaveInfoToProgMgrFile(OTS_SOFT_PACKAGE_ID a_nPackId, CSEMStageDataPtr a_pStageData, COTSGeneralParametersPtr a_pGenParam, COTSImageScanParamPtr a_pImageScanParam, COTSImageProcessParamPtr a_pImageProcParam, COTSXRayParamPtr a_pXRayParam) { // input validation ASSERT(a_pStageData); if (!a_pStageData) { LogErrorTrace(__FILE__, __LINE__, _T("SaveInfoToProgMgrFile: invalid stage pointer .")); return FALSE; } ASSERT(a_pGenParam); if (!a_pGenParam) { LogErrorTrace(__FILE__, __LINE__, _T("SaveInfoToProgMgrFile: invalid GenParam pointer .")); return FALSE; } ASSERT(a_pImageProcParam); if (!a_pImageProcParam) { LogErrorTrace(__FILE__, __LINE__, _T("SaveInfoToProgMgrFile: invalid ImageProcParam pointer .")); return FALSE; } ASSERT(a_pImageScanParam); if (!a_pImageScanParam) { LogErrorTrace(__FILE__, __LINE__, _T("SaveInfoToProgMgrFile: invalid ImageScanParam pointer .")); return FALSE; } ASSERT(a_pXRayParam); if (!a_pXRayParam) { LogErrorTrace(__FILE__, __LINE__, _T("SaveInfoToProgMgrFile: invalid XRayParam pointer .")); return FALSE; } // create a preference file COTSProgMgrParamFilePtr pProgMgrParamFile = COTSProgMgrParamFilePtr(new COTSProgMgrParamFile()); // set the new preference file pProgMgrParamFile->SetStageData(a_pStageData); pProgMgrParamFile->SetGenParam(a_pGenParam); pProgMgrParamFile->SetImageScanParam(a_pImageScanParam); pProgMgrParamFile->SetImageProcParam(a_pImageProcParam); pProgMgrParamFile->SetXRayParam(a_pXRayParam); // get software package system data path CString strSoftwareSysDataPath = COTSFileSys::GetOTSPackSysDataPathName(a_nPackId); if (strSoftwareSysDataPath.IsEmpty()) { // shouldn't happen, software package system data path string is empty LogErrorTrace(__FILE__, __LINE__, _T("SaveInfoToProgMgrFile: failed to software package system data path string.")); return FALSE; } // software package system data path exists? if (!COTSFileSys::Exists(strSoftwareSysDataPath)) { // software package system data path doesn't exists, create it if (!COTSFileSys::CreateFolder(strSoftwareSysDataPath)) { // failed to create software package system data path, return FALSE LogErrorTrace(__FILE__, __LINE__, _T("SaveInfoToProgMgrFile: failed to create software package system data path.")); return FALSE; } } // get software pack measure preference file pathname CString strProgMgrParamFilePathName = COTSFileSys::GetOTSPackMeasurePrefFilePathName(a_nPackId); if (strProgMgrParamFilePathName.IsEmpty()) { // shouldn't happen, software pack measure preference file pathname is empty, return nullptr LogErrorTrace(__FILE__, __LINE__, _T("SaveInfoToProgMgrFile: failed to find program manager param file pathname.")); return FALSE; } // save parameters into program preference file if (!pProgMgrParamFile->Save(strProgMgrParamFilePathName)) { // failed to save program preference file, return FALSE LogErrorTrace(__FILE__, __LINE__, _T("SaveInfoToProgMgrFile: failed to save program preference file.")); return FALSE; } // ok, return TRUE return TRUE; } CString COTSProgMgr::GetStopModeIdString(OTS_MEASURE_STOP_MODE a_nStopMode) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CString strStopModeId = _T(""); if (a_nStopMode >= OTS_MEASURE_STOP_MODE::MIN && a_nStopMode <= OTS_MEASURE_STOP_MODE::MAX) { strStopModeId=MultiLang::GetInstance ().GetCStringByKey (IDS_SCANSTOPMODE + (int)a_nStopMode); } return strStopModeId; } CString COTSProgMgr::GetScanSpeedString(OTS_THREE_TIES_OPTIONS a_nScanSpeed) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CString strScanSpeedId = _T(""); if (a_nScanSpeed >= OTS_THREE_TIES_OPTIONS::MIN && a_nScanSpeed <= OTS_THREE_TIES_OPTIONS::MAX) { strScanSpeedId=MultiLang::GetInstance ().GetCStringByKey (IDS_SCANSPEED + (int)a_nScanSpeed); } return strScanSpeedId; } CString COTSProgMgr::GetImageSizeIdString(OTS_FIVE_TIES_OPTIONS a_nImageSize) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CString strImageSizeId = _T(""); if (a_nImageSize >= OTS_FIVE_TIES_OPTIONS::MIN && a_nImageSize <= OTS_FIVE_TIES_OPTIONS::MAX) { strImageSizeId=MultiLang::GetInstance ().GetCStringByKey (IDS_SCANSIZE + (int)a_nImageSize); } return strImageSizeId; } CString COTSProgMgr::GetGetImageIdString(OTS_GET_IMAGE_MODE a_nGetImageMode) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CString strGetImageId = _T(""); if (a_nGetImageMode >= OTS_GET_IMAGE_MODE::MIN && a_nGetImageMode <= OTS_GET_IMAGE_MODE::MAX) { strGetImageId=MultiLang::GetInstance ().GetCStringByKey (IDS_FETCHIMAGEMODE + (int)a_nGetImageMode); } return strGetImageId; } CString COTSProgMgr::GetXRayAnalySpeedIdString(OTS_THREE_TIES_OPTIONS a_nXRayAnalySpeed) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CString strXRayAnalySpeedId = _T(""); if (a_nXRayAnalySpeed >= OTS_THREE_TIES_OPTIONS::MIN && a_nXRayAnalySpeed <= OTS_THREE_TIES_OPTIONS::MAX) { strXRayAnalySpeedId=MultiLang::GetInstance ().GetCStringByKey (IDS_ANALYSPEED + (int)a_nXRayAnalySpeed); } return strXRayAnalySpeedId; } CString COTSProgMgr::GetXRayScanModeIdString(OTS_X_RAY_SCAN_MODE a_nXRayScanMode) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CString strXRayScanModeId = _T(""); if (a_nXRayScanMode >= OTS_X_RAY_SCAN_MODE::MIN && a_nXRayScanMode <= OTS_X_RAY_SCAN_MODE::MAX) { strXRayScanModeId=MultiLang::GetInstance ().GetCStringByKey (IDS_XRAYSCANMODE + (int)a_nXRayScanMode); } return strXRayScanModeId; } CString COTSProgMgr::GetXRaySearchSpeedIdString(OTS_THREE_TIES_OPTIONS a_nXRaySearchSpeed) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CString strXRaySearchSpeedId = _T(""); if (a_nXRaySearchSpeed >= OTS_THREE_TIES_OPTIONS::MIN && a_nXRaySearchSpeed <= OTS_THREE_TIES_OPTIONS::MAX) { strXRaySearchSpeedId=MultiLang::GetInstance ().GetCStringByKey (IDS_SEARCHSPEED + (int)a_nXRaySearchSpeed); } return strXRaySearchSpeedId; } CString COTSProgMgr::GetYAxisDirectionIdString(OTS_Y_AXIS_DIRECTION a_nYAxisDirection) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CString strYAxisDirectionId = _T(""); if (a_nYAxisDirection >= OTS_Y_AXIS_DIRECTION::MIN && a_nYAxisDirection <= OTS_Y_AXIS_DIRECTION::MAX) { strYAxisDirectionId=MultiLang::GetInstance ().GetCStringByKey (IDS_YAXISDIRECTION + (int)a_nYAxisDirection); } return strYAxisDirectionId; } CString COTSProgMgr::GetSteelTechIdString(STEEL_TECHNOLOGY a_nSteelTech) { CString strId = _T(""); if (a_nSteelTech >= STEEL_TECHNOLOGY::MIN && a_nSteelTech <= STEEL_TECHNOLOGY::MAX) { strId = MultiLang::GetInstance().GetCStringByKey(IDS_STEEL_TECHNOLOGY + (int)a_nSteelTech); } return strId; } CString COTSProgMgr::GetXAxisDirectionIdString(OTS_X_AXIS_DIRECTION a_nXAxisDirection) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CString strXAxisDirectionId = _T(""); if (a_nXAxisDirection >= OTS_X_AXIS_DIRECTION::MIN && a_nXAxisDirection <= OTS_X_AXIS_DIRECTION::MAX) { strXAxisDirectionId=MultiLang::GetInstance ().GetCStringByKey (IDS_XAXISDIRECTION + (int)a_nXAxisDirection); } return strXAxisDirectionId; } // get measure area shape CString COTSProgMgr::GetAreaShapeString(DOMAIN_SHAPE a_nShape) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CString strShape = _T(""); if (a_nShape >= DOMAIN_SHAPE::MIN && a_nShape <= DOMAIN_SHAPE::MAX) { strShape = MultiLang::GetInstance().GetCStringByKey(IDS_MEASURE_SHAPE + (int)a_nShape); } return strShape; } }