OTSSemBase.cpp 9.0 KB

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