OTSSemBase.cpp 8.9 KB

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