OTSSemBase.cpp 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. #include "stdafx.h"
  2. #include "OTSSemBase.h"
  3. #include "otsdataconst.h"
  4. namespace OTSController {
  5. COTSSemBase::COTSSemBase()
  6. : m_oScanField100(CSize(SCREEN_SIZE_DEFAULT_MAG100_X, SCREEN_SIZE_DEFAULT_MAG100_Y))
  7. , m_bAllowRotation(FALSE)
  8. {
  9. }
  10. COTSSemBase::~COTSSemBase()
  11. {
  12. }
  13. // move SEM to the given point
  14. BOOL COTSSemBase::MoveSEMToPoint(const CPoint& a_poiPosition, const double& a_dRotation)
  15. {
  16. // connected?
  17. if (!IsConnected())
  18. {
  19. // SEM is not connected
  20. LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::MoveSEMToPoint: SEM is not connected."));
  21. return FALSE;
  22. }
  23. // attempt 1000 times until SEM in place
  24. long nAttempTime = 10;
  25. double dSetPositionX = (double)a_poiPosition.x;
  26. double dSetPositionY = (double)a_poiPosition.y;
  27. double dSetPositionR = a_dRotation;
  28. double dOriginalPositionX = 0.0;
  29. double dOriginalPositionY = 0.0;
  30. double dGetPositionX = 0.0;
  31. double dGetPositionY = 0.0;
  32. double dGetPositionR = 0.0;
  33. BOOL bInPlace = FALSE;
  34. // allow rotation?
  35. if (!m_bAllowRotation)
  36. {
  37. // not allow to rotation
  38. // get SEM position
  39. if (!GetPositionXY(dOriginalPositionX, dOriginalPositionY, dGetPositionR))
  40. {
  41. // failed to call GetPositionXY method
  42. LogErrorTrace(__FILE__, __LINE__, "COTSSemBase::MoveSEMToPoint: failed to call GetPositionXY method.");
  43. return FALSE;
  44. }
  45. Sleep(1000);
  46. // don't rotation at all
  47. dSetPositionR = dGetPositionR;
  48. }
  49. // Move SEM to position
  50. if (!SetPositionXY(dSetPositionX, dSetPositionY, dSetPositionR))
  51. {
  52. LogErrorTrace(__FILE__, __LINE__, "COTSSemBase::MoveSEMToPoint: failed to call SetPositionXY method.");
  53. }
  54. Sleep(2000);
  55. while (nAttempTime > 0 && !bInPlace)
  56. {
  57. // get SEM position
  58. if (!GetPositionXY(dGetPositionX, dGetPositionY, dGetPositionR))
  59. {
  60. // failed to call GetPositionXY method
  61. LogErrorTrace(__FILE__, __LINE__, "COTSSemBase::MoveSEMToPoint: failed to call GetPositionXY method.");
  62. --nAttempTime;
  63. continue;
  64. }
  65. LogTrace(__FILE__, __LINE__, _T("COTSSemBase::MoveSEMToPoint: call GetPositionXY method%0.3f, %0.3f, %0.3f"), dGetPositionX, dGetPositionY, dGetPositionR);
  66. if (dGetPositionX == dOriginalPositionX && dGetPositionY == dOriginalPositionY)
  67. {
  68. // Move SEM to position
  69. if (!SetPositionXY(dSetPositionX, dSetPositionY, dSetPositionR))
  70. {
  71. LogErrorTrace(__FILE__, __LINE__, "COTSSemBase::MoveSEMToPoint: failed to call SetPositionXY method.");
  72. }
  73. Sleep(2000);
  74. }
  75. // check if SEM has be in place
  76. if ((fabs(dSetPositionX - dGetPositionX) < POSITIONCRITERIA)
  77. && (fabs(dSetPositionY - dGetPositionY) < POSITIONCRITERIA))
  78. {
  79. // x, y are in place
  80. // allow rotation?
  81. if (m_bAllowRotation)
  82. {
  83. // need to check if rotation is ok
  84. bInPlace = fabs(dSetPositionR - dGetPositionR) < POSITIONCRITERIA;
  85. }
  86. else
  87. {
  88. // don't need to check if rotation is ok
  89. bInPlace = TRUE;
  90. }
  91. }
  92. if (!bInPlace)
  93. {
  94. Sleep(1000);//ÑÓʱ100ºÁÃë
  95. }
  96. // tried once
  97. --nAttempTime;
  98. }
  99. // in placed?
  100. if (!bInPlace)
  101. {
  102. return FALSE;
  103. }
  104. else
  105. {
  106. Sleep(1000);//still wait another 500ms to let SEM move.then stage will be stable when we acquire BSE.
  107. }
  108. // ok, return TRUE
  109. return TRUE;
  110. }
  111. // SEM data (measure)
  112. BOOL COTSSemBase::GetSEMDataMsr(CSEMDataMsrPtr a_pSEMDataMsr)
  113. {
  114. // input check
  115. ASSERT(a_pSEMDataMsr);
  116. if (!a_pSEMDataMsr)
  117. {
  118. // invalid SEM data pointer
  119. LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::GetSEMDataMsr: invalid SEM data pointer."));
  120. return FALSE;
  121. }
  122. // connected?
  123. if (!IsConnected())
  124. {
  125. // SEM is not connected
  126. LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::GetSEMDataMsr: SEM is not connected."));
  127. return FALSE;
  128. }
  129. // get working distance
  130. double dFWD;
  131. if (!GetWorkingDistance(dFWD))
  132. {
  133. // failed to get working distance
  134. LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::GetSEMDataMsr: failed to get working distance."));
  135. return FALSE;
  136. }
  137. // get scan file size
  138. double dScanFieldSizeX, dScanFieldSizeY;
  139. if (!GetScanFieldSize( dScanFieldSizeX, dScanFieldSizeY))
  140. {
  141. // failed to get scan field size
  142. LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::GetSEMDataMsr: failed to get scan field size."));
  143. return FALSE;
  144. }
  145. // set SEM data (measure)
  146. a_pSEMDataMsr->SetWorkingDistance(dFWD);
  147. a_pSEMDataMsr->SetScanFieldSize((int)(dScanFieldSizeX + 0.5));
  148. a_pSEMDataMsr->SetScanFieldSize100(m_oScanField100.cx);
  149. // ok, return TRUE
  150. return TRUE;
  151. }
  152. BOOL COTSSemBase::SetSEMDataMsr(CSEMDataMsrPtr a_pSEMDataMsr)
  153. {
  154. // input check
  155. ASSERT(a_pSEMDataMsr);
  156. if (!a_pSEMDataMsr)
  157. {
  158. // invalid SEM data pointer
  159. LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::GetSEMDataMsr: invalid SEM data pointer."));
  160. return FALSE;
  161. }
  162. // connected?
  163. if (!IsConnected())
  164. {
  165. // SEM is not connected
  166. LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::GetSEMDataMsr: SEM is not connected."));
  167. return FALSE;
  168. }
  169. // set working distance
  170. if (!SetWorkingDistance(a_pSEMDataMsr->GetWorkingDistance()))
  171. {
  172. // failed to set working distance
  173. LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::GetSEMDataMsr: failed to set working distance."));
  174. return FALSE;
  175. }
  176. // set scan field size
  177. if (!SetScanFieldSizeX(a_pSEMDataMsr->GetScanFieldSize()))
  178. {
  179. // failed to set scan field size
  180. LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::GetSEMDataMsr: failed to set scan field size."));
  181. return FALSE;
  182. }
  183. // ok, return TRUE
  184. return TRUE;
  185. }
  186. // SEM data (general)
  187. BOOL COTSSemBase::GetSEMDataGnr(CSEMDataGnrPtr a_pSEMDataGnr)
  188. {
  189. // input check
  190. ASSERT(a_pSEMDataGnr);
  191. if (!a_pSEMDataGnr)
  192. {
  193. // invalid SEM data pointer
  194. LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::GetSEMDataGnr: invalid SEM data pointer."));
  195. return FALSE;
  196. }
  197. // connected?
  198. if (!IsConnected())
  199. {
  200. // SEM is not connected
  201. LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::GetSEMDataGnr: SEM is not connected."));
  202. return FALSE;
  203. }
  204. // get KV
  205. double dKV;
  206. if (!GetHighTension(dKV))
  207. {
  208. // failed to get KV
  209. LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::GetSEMDataMsr: failed to get kv."));
  210. return FALSE;
  211. }
  212. // get brightness
  213. double dBrightness;
  214. if (!GetBrightness(dBrightness))
  215. {
  216. // failed to get brightness
  217. LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::GetSEMDataMsr: failed to get brightness."));
  218. return FALSE;
  219. }
  220. // get contrast
  221. double dContrast;
  222. if (!GetContrast(dContrast))
  223. {
  224. // failed to get contrast
  225. LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::GetSEMDataMsr: failed to get contrast."));
  226. return FALSE;
  227. }
  228. // set SEM data (general)
  229. a_pSEMDataGnr->SetKV(dKV);
  230. a_pSEMDataGnr->SetBrightness(dBrightness);
  231. a_pSEMDataGnr->SetContrast(dContrast);
  232. // ok, return TRUE
  233. return TRUE;
  234. }
  235. BOOL COTSSemBase::SetSEMDataGnr(CSEMDataGnrPtr a_pSEMDataGnr)
  236. {
  237. // input check
  238. ASSERT(a_pSEMDataGnr);
  239. if (!a_pSEMDataGnr)
  240. {
  241. // invalid SEM data pointer
  242. LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::SetSEMDataGnr: invalid SEM data pointer."));
  243. return FALSE;
  244. }
  245. // connected?
  246. if (!IsConnected())
  247. {
  248. // SEM is not connected
  249. LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::SetSEMDataGnr: SEM is not connected."));
  250. return FALSE;
  251. }
  252. // set KV
  253. if (!SetHighTension(a_pSEMDataGnr->GetKV()))
  254. {
  255. // failed to set KV
  256. LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::SetSEMDataGnr: failed to set KV."));
  257. return FALSE;
  258. }
  259. // set brightness
  260. if (!SetBrightness(a_pSEMDataGnr->GetBrightness()))
  261. {
  262. // failed to set brightness
  263. LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::SetSEMDataGnr: failed to set brightness."));
  264. return FALSE;
  265. }
  266. // set contrast
  267. if (!SetContrast(a_pSEMDataGnr->GetContrast()))
  268. {
  269. // failed to set contrast
  270. LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::SetSEMDataGnr: failed to set contrast."));
  271. return FALSE;
  272. }
  273. // ok, return TRUE
  274. return TRUE;
  275. }
  276. // convert scan field size to mag.
  277. BOOL COTSSemBase::ScanFieldSizeToMag
  278. (
  279. double& a_dMagnification,
  280. double a_dScanFieldSizeX
  281. )
  282. {
  283. // check input scan field value
  284. if (a_dScanFieldSizeX < SCANFIELDSIZE_MIN)
  285. {
  286. // failed to do scan field size mag convention. input scan field size is smaller than limited.
  287. LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::ScanFieldSizeToMag: failed to do scan field size mag convention. input scan field size is smaller than limited."));
  288. return FALSE;
  289. }
  290. // convert scan field size to magnification
  291. a_dMagnification = (double)(m_oScanField100.cx) * 100.0 / a_dScanFieldSizeX;
  292. // ok, return TRUE
  293. return TRUE;
  294. }
  295. // convert mag to scan field size.
  296. BOOL COTSSemBase::MagToScanFieldSize
  297. (
  298. double a_dMagnification,
  299. double& a_dScanFieldSizeX,
  300. double& a_dScanFieldSizeY
  301. )
  302. {
  303. // check mag value
  304. if (a_dMagnification < MAGNIFICATION_MIN)
  305. {
  306. // failed to do mag scan field size convention. input magnification is smaller than limited
  307. LogTrace(__FILE__, __LINE__, _T("COTSSemBase::MagToScanFieldSize: failed to do mag scan field size convention. input magnification is smaller than limited."));
  308. return FALSE;
  309. }
  310. // calculation scan field size and set output values
  311. a_dScanFieldSizeX = 100.0 * m_oScanField100.cx / a_dMagnification;
  312. a_dScanFieldSizeY = 100.0 * m_oScanField100.cy / a_dMagnification;
  313. // ok, return TRUE
  314. return TRUE;
  315. }
  316. }