#include "stdafx.h" #include "OTSSemBase.h" #include "otsdataconst.h" namespace OTSController { COTSSemBase::COTSSemBase() : m_oScanField100(CSize(SCREEN_SIZE_DEFAULT_MAG100_X, SCREEN_SIZE_DEFAULT_MAG100_Y)) , m_bAllowRotation(FALSE) { } COTSSemBase::~COTSSemBase() { } // move SEM to the given point BOOL COTSSemBase::MoveSEMToPoint(const CPoint& a_poiPosition, const double& a_dRotation) { // connected? if (!IsConnected()) { // SEM is not connected LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::MoveSEMToPoint: SEM is not connected.")); return FALSE; } // attempt 1000 times until SEM in place //long nAttempTime = 2; double dSetPositionX = (double)a_poiPosition.x; double dSetPositionY = (double)a_poiPosition.y; double dSetPositionR = a_dRotation; double dOriginalPositionX = 0.0; double dOriginalPositionY = 0.0; double dGetPositionX = 0.0; double dGetPositionY = 0.0; double dGetPositionR = 0.0; BOOL bInPlace = FALSE; // allow rotation? if (!m_bAllowRotation) { // not allow to rotation // get SEM position if (!GetPositionXY(dOriginalPositionX, dOriginalPositionY, dGetPositionR)) { // failed to call GetPositionXY method LogErrorTrace(__FILE__, __LINE__, "COTSSemBase::MoveSEMToPoint: failed to call GetPositionXY method."); return FALSE; } // don't rotation at all dSetPositionR = dGetPositionR; } // Move SEM to position if (!SetPositionXY(dSetPositionX, dSetPositionY, dSetPositionR)) { LogErrorTrace(__FILE__, __LINE__, "COTSSemBase::MoveSEMToPoint: failed to call SetPositionXY method."); } //time out clock_t t0, dt; t0 = clock(); int ttt = 20; while (!bInPlace) { //³¬Ê±ÅÐ¶Ï dt = clock() - t0; if (dt >= ttt * CLOCKS_PER_SEC) { LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::MoveSEMToPoint: failed to call SetPositionXY time out > 20s")); return FALSE; } // get SEM position if (!GetPositionXY(dGetPositionX, dGetPositionY, dGetPositionR)) { // failed to call GetPositionXY method LogErrorTrace(__FILE__, __LINE__, "COTSSemBase::MoveSEMToPoint: failed to call GetPositionXY method."); continue; } // check if SEM has be in place if ((fabs(dSetPositionX - dGetPositionX) < POSITIONCRITERIA) && (fabs(dSetPositionY - dGetPositionY) < POSITIONCRITERIA)) { // x, y are in place // allow rotation? if (m_bAllowRotation) { // need to check if rotation is ok bInPlace = fabs(dSetPositionR - dGetPositionR) < POSITIONCRITERIA; } else { // don't need to check if rotation is ok bInPlace = TRUE; } } } // in placed? if (!bInPlace) { LogTrace(__FILE__, __LINE__, "COTSSemBase::MoveSEMToPoint: failed to move SEM to position(%f, %f, %f). current SEM position (%f, %f, %f).", dSetPositionX, dSetPositionY, dSetPositionR, dGetPositionX, dGetPositionY, dGetPositionR); return FALSE; } return TRUE; } // SEM data (measure) BOOL COTSSemBase::GetSEMDataMsr(CSEMDataMsrPtr a_pSEMDataMsr) { // input check ASSERT(a_pSEMDataMsr); if (!a_pSEMDataMsr) { // invalid SEM data pointer LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::GetSEMDataMsr: invalid SEM data pointer.")); return FALSE; } // connected? if (!IsConnected()) { // SEM is not connected LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::GetSEMDataMsr: SEM is not connected.")); return FALSE; } // get working distance double dFWD; if (!GetWorkingDistance(dFWD)) { // failed to get working distance LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::GetSEMDataMsr: failed to get working distance.")); return FALSE; } // get scan file size double dScanFieldSizeX, dScanFieldSizeY; if (!GetScanFieldSize( dScanFieldSizeX, dScanFieldSizeY)) { // failed to get scan field size LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::GetSEMDataMsr: failed to get scan field size.")); return FALSE; } // set SEM data (measure) a_pSEMDataMsr->SetWorkingDistance(dFWD); a_pSEMDataMsr->SetScanFieldSize((int)(dScanFieldSizeX + 0.5)); a_pSEMDataMsr->SetScanFieldSize100(m_oScanField100.cx); // ok, return TRUE return TRUE; } BOOL COTSSemBase::SetSEMDataMsr(CSEMDataMsrPtr a_pSEMDataMsr) { // input check ASSERT(a_pSEMDataMsr); if (!a_pSEMDataMsr) { // invalid SEM data pointer LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::GetSEMDataMsr: invalid SEM data pointer.")); return FALSE; } // connected? if (!IsConnected()) { // SEM is not connected LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::GetSEMDataMsr: SEM is not connected.")); return FALSE; } // set working distance if (!SetWorkingDistance(a_pSEMDataMsr->GetWorkingDistance())) { // failed to set working distance LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::GetSEMDataMsr: failed to set working distance.")); return FALSE; } // set scan field size if (!SetScanFieldSizeX(a_pSEMDataMsr->GetScanFieldSize())) { // failed to set scan field size LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::GetSEMDataMsr: failed to set scan field size.")); return FALSE; } // ok, return TRUE return TRUE; } // SEM data (general) BOOL COTSSemBase::GetSEMDataGnr(CSEMDataGnrPtr a_pSEMDataGnr) { // input check ASSERT(a_pSEMDataGnr); if (!a_pSEMDataGnr) { // invalid SEM data pointer LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::GetSEMDataGnr: invalid SEM data pointer.")); return FALSE; } // connected? if (!IsConnected()) { // SEM is not connected LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::GetSEMDataGnr: SEM is not connected.")); return FALSE; } // get KV double dKV; if (!GetHighTension(dKV)) { // failed to get KV LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::GetSEMDataMsr: failed to get kv.")); return FALSE; } // get brightness double dBrightness; if (!GetBrightness(dBrightness)) { // failed to get brightness LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::GetSEMDataMsr: failed to get brightness.")); return FALSE; } // get contrast double dContrast; if (!GetContrast(dContrast)) { // failed to get contrast LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::GetSEMDataMsr: failed to get contrast.")); return FALSE; } // set SEM data (general) a_pSEMDataGnr->SetKV(dKV); a_pSEMDataGnr->SetBrightness(dBrightness); a_pSEMDataGnr->SetContrast(dContrast); // ok, return TRUE return TRUE; } BOOL COTSSemBase::SetSEMDataGnr(CSEMDataGnrPtr a_pSEMDataGnr) { // input check ASSERT(a_pSEMDataGnr); if (!a_pSEMDataGnr) { // invalid SEM data pointer LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::SetSEMDataGnr: invalid SEM data pointer.")); return FALSE; } // connected? if (!IsConnected()) { // SEM is not connected LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::SetSEMDataGnr: SEM is not connected.")); return FALSE; } // set KV if (!SetHighTension(a_pSEMDataGnr->GetKV())) { // failed to set KV LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::SetSEMDataGnr: failed to set KV.")); return FALSE; } // set brightness if (!SetBrightness(a_pSEMDataGnr->GetBrightness())) { // failed to set brightness LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::SetSEMDataGnr: failed to set brightness.")); return FALSE; } // set contrast if (!SetContrast(a_pSEMDataGnr->GetContrast())) { // failed to set contrast LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::SetSEMDataGnr: failed to set contrast.")); return FALSE; } // ok, return TRUE return TRUE; } // convert scan field size to mag. BOOL COTSSemBase::ScanFieldSizeToMag ( double& a_dMagnification, double a_dScanFieldSizeX ) { // check input scan field value if (a_dScanFieldSizeX < SCANFIELDSIZE_MIN) { // failed to do scan field size mag convention. input scan field size is smaller than limited. LogErrorTrace(__FILE__, __LINE__, _T("COTSSemBase::ScanFieldSizeToMag: failed to do scan field size mag convention. input scan field size is smaller than limited.")); return FALSE; } // convert scan field size to magnification a_dMagnification = (double)(m_oScanField100.cx) * 100.0 / a_dScanFieldSizeX; // ok, return TRUE return TRUE; } // convert mag to scan field size. BOOL COTSSemBase::MagToScanFieldSize ( double a_dMagnification, double& a_dScanFieldSizeX, double& a_dScanFieldSizeY ) { // check mag value if (a_dMagnification < MAGNIFICATION_MIN) { // failed to do mag scan field size convention. input magnification is smaller than limited LogTrace(__FILE__, __LINE__, _T("COTSSemBase::MagToScanFieldSize: failed to do mag scan field size convention. input magnification is smaller than limited.")); return FALSE; } // calculation scan field size and set output values a_dScanFieldSizeX = 100.0 * m_oScanField100.cx / a_dMagnification; a_dScanFieldSizeY = 100.0 * m_oScanField100.cy / a_dMagnification; // ok, return TRUE return TRUE; } }