OTSSemBase.cpp 9.5 KB

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