OTSSemBase.cpp 9.3 KB

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