OTSScanSim.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. #include "stdafx.h"
  2. #include "OTSScanSim.h"
  3. #include "otsdataconst.h"
  4. namespace OTSController {
  5. namespace
  6. {
  7. CString GetOSCommonDataPathName()
  8. {
  9. CString strPathName = _T(".\\");
  10. return strPathName;
  11. }
  12. CString GetCompanySysDataPathName()
  13. {
  14. CString strCommonDataPathName = GetOSCommonDataPathName();
  15. if (strCommonDataPathName.IsEmpty())
  16. {
  17. LogErrorTrace(__FILE__, __LINE__, _T("GetOTSPackSysDataPathName: failed to common data pathname string."));
  18. return _T("");
  19. }
  20. CString strCmpSysDataPath = strCommonDataPathName + STR_COMPANYNAME + _T("\\");
  21. return strCmpSysDataPath;
  22. }
  23. // check if the file exists or not
  24. BOOL Exists(LPCTSTR a_sPath)
  25. {
  26. return ::PathFileExists(a_sPath) == TRUE;
  27. }
  28. }
  29. const CString SIMULATION_IMAGE_FILEPATH = _T("Simulate");
  30. const CString SIMULATION_IMAGE_FILENAME = _T("SimImage.bmp");
  31. COTSScanSim::COTSScanSim()
  32. {
  33. }
  34. COTSScanSim::~COTSScanSim()
  35. {
  36. }
  37. BOOL COTSScanSim::Init()
  38. {
  39. return TRUE;
  40. }
  41. // acquire BSE image
  42. CBSEImgPtr COTSScanSim::AcquireBSEImage()
  43. {
  44. CBSEImgPtr poBSEImgPtr = nullptr;
  45. poBSEImgPtr = AcquireBSEImageFromBitmapFile();
  46. ASSERT(poBSEImgPtr);
  47. if (!poBSEImgPtr)
  48. {
  49. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanSim::AcquireBSEImage: failed to load simulation image"));
  50. }
  51. Sleep(1000);//simulate the real sem time delay.
  52. return poBSEImgPtr;
  53. }
  54. // get image from a file
  55. CBSEImgPtr COTSScanSim::AcquireBSEImageFromBitmapFile()
  56. {
  57. // prepare file
  58. CFile file;
  59. CFileException fe;
  60. BYTE* m_pPixel;
  61. BYTE* m_pBmInfo;
  62. BITMAPFILEHEADER* m_pBmfh;
  63. m_pBmfh = new BITMAPFILEHEADER;
  64. CBSEImgPtr bseImage;
  65. // get simulation image file name
  66. CString strOTSSysDataPath = GetCompanySysDataPathName();
  67. CString strBitmapFilePathName = strOTSSysDataPath + SIMULATION_IMAGE_FILEPATH + _T("\\") + SIMULATION_IMAGE_FILENAME;
  68. // check if the file exist
  69. if (Exists(strBitmapFilePathName))
  70. {
  71. if (!file.Open(strBitmapFilePathName, CFile::modeRead, &fe))
  72. {
  73. LogInfoTrace(__FILE__, __LINE__, _T("COTSEDSBase::AcquireBSEImageFromBitmapFile: failed to open simulation image file %s."), strBitmapFilePathName);
  74. return nullptr;
  75. }
  76. // read file header
  77. file.Read(m_pBmfh, sizeof(BITMAPFILEHEADER));
  78. m_pBmInfo = new BYTE[m_pBmfh->bfOffBits - 14];
  79. file.Read(m_pBmInfo, m_pBmfh->bfOffBits - 14);
  80. BITMAPINFOHEADER bmih;
  81. memcpy(&bmih, m_pBmInfo, sizeof(BITMAPINFOHEADER));
  82. long width = bmih.biWidth;
  83. int bitCount = bmih.biBitCount;
  84. long height = bmih.biHeight;
  85. long LineBytes = (width * bitCount + 31) / 32 * 4;//calculate the bytes of each line
  86. m_pPixel = new BYTE[height * LineBytes];
  87. file.Read(m_pPixel, height * LineBytes);
  88. file.Close();
  89. CRect imageRect(0, 0, width, height);
  90. bseImage = CBSEImgPtr(new CBSEImg(imageRect));
  91. bseImage->InitImageData(width, height);
  92. BYTE* pImageData = bseImage->GetImageDataPointer();
  93. long nActImageSize = width * height;
  94. for (int i = 0; i < height; i++)
  95. {
  96. memcpy(pImageData + i * width, m_pPixel + (height - i-1) * width, width);
  97. }
  98. delete[]m_pPixel;
  99. delete[]m_pBmInfo;
  100. delete m_pBmfh;
  101. }
  102. else
  103. {
  104. LogInfoTrace(__FILE__, __LINE__, _T("COTSEDSBase::AcquireBSEImageFromBitmapFile: failed to open simulation image file %s."), strBitmapFilePathName);
  105. return nullptr;
  106. }
  107. return bseImage;
  108. }
  109. // move beam to point
  110. BOOL COTSScanSim::MoveBeamTo(CPoint& a_beamPos)
  111. {
  112. return FALSE;
  113. }
  114. // set image size
  115. BOOL COTSScanSim::SetImageSize(long a_nImageSizeX,long nHeight)
  116. {
  117. return TRUE;
  118. }
  119. // set dwell time
  120. BOOL COTSScanSim::SetDwellTime(long a_nDwellTime)
  121. {
  122. return TRUE;
  123. }
  124. }