OTSSemBase.cpp 8.8 KB

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