OTSScanSim.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. #include "stdafx.h"
  2. #include "OTSScanSim.h"
  3. #include "otsdataconst.h"
  4. namespace OTSController {
  5. //private method
  6. namespace
  7. {
  8. // get system common data folder pathname
  9. // return "" if failed
  10. CString GetOSCommonDataPathName()
  11. {
  12. CString strPathName = _T(".\\");
  13. return strPathName;
  14. }
  15. // get company system data path
  16. CString GetCompanySysDataPathName()
  17. {
  18. // get common data pathname string
  19. CString strCommonDataPathName = GetOSCommonDataPathName();
  20. if (strCommonDataPathName.IsEmpty())
  21. {
  22. // failed to get common data pathname string
  23. LogErrorTrace(__FILE__, __LINE__, _T("GetOTSPackSysDataPathName: failed to common data pathname string."));
  24. return _T("");
  25. }
  26. // company system data pathname
  27. CString strCmpSysDataPath = strCommonDataPathName + STR_COMPANYNAME + _T("\\");
  28. // return company system data pathname
  29. return strCmpSysDataPath;
  30. }
  31. // check if the file exists or not
  32. BOOL Exists(LPCTSTR a_sPath)
  33. {
  34. return ::PathFileExists(a_sPath) == TRUE;
  35. }
  36. }
  37. const CString SIMULATION_IMAGE_FILEPATH = _T("Simulate");
  38. const CString SIMULATION_IMAGE_FILENAME = _T("SimImage.bmp");
  39. COTSScanSim::COTSScanSim()
  40. {
  41. }
  42. COTSScanSim::~COTSScanSim()
  43. {
  44. }
  45. // initialization
  46. BOOL COTSScanSim::Init()
  47. {
  48. // ok, return TRUE
  49. return TRUE;
  50. }
  51. // get the size of matrix.
  52. //CSize COTSScanSim::GetMatrixSize(int /*a_nMatrixIndex*/)
  53. //{
  54. // return CSize(0);
  55. //}
  56. // acquire BSE image
  57. CBSEImgPtr COTSScanSim::AcquireBSEImage()
  58. {
  59. // BSE image
  60. CBSEImgPtr poBSEImgPtr = nullptr;
  61. // load simulation image
  62. poBSEImgPtr = AcquireBSEImageFromBitmapFile();
  63. // check simulation image
  64. ASSERT(poBSEImgPtr);
  65. if (!poBSEImgPtr)
  66. {
  67. // failed to load simulation image
  68. LogErrorTrace(__FILE__, __LINE__, _T("COTSScanSim::AcquireBSEImage: failed to load simulation image"));
  69. }
  70. Sleep(1000);//simulate the real sem time delay.
  71. // return simulation image, nullptr if load simulation image failed
  72. return poBSEImgPtr;
  73. }
  74. // get image from a file
  75. CBSEImgPtr COTSScanSim::AcquireBSEImageFromBitmapFile()
  76. {
  77. // prepare file
  78. CFile file;
  79. CFileException fe;
  80. BYTE* m_pPixel;
  81. BYTE* m_pBmInfo;
  82. BITMAPFILEHEADER* m_pBmfh;
  83. m_pBmfh = new BITMAPFILEHEADER;
  84. CBSEImgPtr bseImage;
  85. // get simulation image file name
  86. CString strOTSSysDataPath = GetCompanySysDataPathName();
  87. CString strBitmapFilePathName = strOTSSysDataPath + SIMULATION_IMAGE_FILEPATH + _T("\\") + SIMULATION_IMAGE_FILENAME;
  88. // check if the file exist
  89. if (Exists(strBitmapFilePathName))
  90. {
  91. if (!file.Open(strBitmapFilePathName, CFile::modeRead, &fe))
  92. {
  93. LogInfoTrace(__FILE__, __LINE__, _T("COTSEDSBase::AcquireBSEImageFromBitmapFile: failed to open simulation image file %s."), strBitmapFilePathName);
  94. return nullptr;
  95. }
  96. // read file header
  97. file.Read(m_pBmfh, sizeof(BITMAPFILEHEADER));
  98. m_pBmInfo = new BYTE[m_pBmfh->bfOffBits - 14];
  99. file.Read(m_pBmInfo, m_pBmfh->bfOffBits - 14);
  100. BITMAPINFOHEADER bmih;
  101. memcpy(&bmih, m_pBmInfo, sizeof(BITMAPINFOHEADER));
  102. long width = bmih.biWidth;//获取宽度
  103. int bitCount = bmih.biBitCount;//获取位数
  104. long height = bmih.biHeight;//获取高度
  105. long LineBytes = (width * bitCount + 31) / 32 * 4;//计算每行像素所占的字节数
  106. m_pPixel = new BYTE[height * LineBytes];
  107. file.Read(m_pPixel, height * LineBytes);
  108. file.Close();
  109. CRect imageRect(0, 0, width, height);
  110. bseImage = CBSEImgPtr(new CBSEImg(imageRect));
  111. /*bseImage->SetImageRect(imageRect);*/
  112. bseImage->InitImageData(width, height);
  113. BYTE* pImageData = bseImage->GetImageDataPointer();
  114. long nActImageSize = width * height;
  115. for (int i = 0; i < height; i++)
  116. {
  117. memcpy(pImageData + i * width, m_pPixel + (height - i) * width, width);
  118. }
  119. delete[]m_pPixel;
  120. delete[]m_pBmInfo;
  121. delete m_pBmfh;
  122. }
  123. else
  124. {
  125. LogInfoTrace(__FILE__, __LINE__, _T("COTSEDSBase::AcquireBSEImageFromBitmapFile: failed to open simulation image file %s."), strBitmapFilePathName);
  126. return nullptr;
  127. }
  128. return bseImage;
  129. }
  130. // move beam to point
  131. BOOL COTSScanSim::MoveBeamTo(CPoint& a_beamPos)
  132. {
  133. return FALSE;
  134. }
  135. // start scan table
  136. //BOOL COTSScanSim::StartScanTable(int /*a_nMatrixIndex*/, unsigned int /*nP*/, int* /*px*/, int* /*py*/)
  137. //{
  138. // return TRUE;
  139. //}
  140. // set image size
  141. BOOL COTSScanSim::SetImageSize(long a_nImageSizeX,long nHeight)
  142. {
  143. return TRUE;
  144. }
  145. // set dwell time
  146. BOOL COTSScanSim::SetDwellTime(long a_nDwellTime)
  147. {
  148. return TRUE;
  149. }
  150. // get dwell time by index
  151. //long COTSScanSim::GetDwellTimeByIndex(const long a_nIndex)
  152. //{
  153. // // check index
  154. // if (a_nIndex < DWELLTIME_BRUKER_ID_MIN || a_nIndex > DWELLTIME_BRUKER_ID_MAX)
  155. // {
  156. // // invalid index
  157. // ASSERT(FALSE);
  158. // LogInfoTrace(__FILE__, __LINE__, _T("COTSScanSim::GetDwellTimeByIndex: invalid index"));
  159. // return -1;
  160. // }
  161. // // get dwell time by index
  162. // long nDwellTime = DWELLTIME_BRUKER_VALUES[a_nIndex];
  163. // return nDwellTime;
  164. //}
  165. // set dwell time by index
  166. //BOOL COTSScanSim::SetDwellTimeByIndex(const long a_nIndex)
  167. //{
  168. // // check index
  169. // if (a_nIndex < DWELLTIME_BRUKER_ID_MIN || a_nIndex > DWELLTIME_BRUKER_ID_MIN)
  170. // {
  171. // // invalid index
  172. // ASSERT(FALSE);
  173. // LogInfoTrace(__FILE__, __LINE__, _T("COTSScanSim::SetDwellTimeByIndex: invalid index"));
  174. // return FALSE;
  175. // }
  176. // // get dwell time
  177. // long nDwellTime = DWELLTIME_BRUKER_VALUES[a_nIndex];
  178. // if (!SetDwellTime(nDwellTime))
  179. // {
  180. // // failed to call SetDwellTime method
  181. // LogErrorTrace(__FILE__, __LINE__, _T("COTSScanSim::SetDwellTimeByIndex: failed to call SetDwellTime method."));
  182. // return FALSE;
  183. // }
  184. // // ok, return TRUE
  185. // return TRUE;
  186. //}
  187. // scan field size
  188. /*BOOL COTSScanSim::SetScanFieldSize(const int a_nWidth, const int a_nHeight)
  189. {
  190. m_nScanFieldSizeX = a_nWidth;
  191. m_nScanFieldSizeY = a_nHeight;
  192. return TRUE;
  193. }*/
  194. // set the SEM position
  195. /*BOOL COTSScanSim::SetEMPosition(const int a_nPosX, const int a_nPosY)
  196. {
  197. m_nCurrentBSEPositionX = a_nPosX;
  198. m_nCurrentBSEPositionY = a_nPosY;
  199. return TRUE;
  200. }*/
  201. }