// ReviewProcessor.cpp : 구현 파일입니다. // #include "stdafx.h" #include "ReviewProcessor.h" #include "CHCommonClasses/ProcessTimer.h" #include "CHImageControls/CHImageProcess.h" #include "CHReviewRecipe/RsRcpReviewInfo.h" #include "CHReviewRecipe/RcpLightInfo.h" #include "CHReviewRecipe/RsRcpDefectFindInfo.h" #include "CameraControlReview.h" #include "CHSignalControls/SignalControl.h" #include "CHWsiControls/WsiControl.h" #include "CHEdgeTriangle/RecipeManager.h" #include "CHEdgeTriangle/EdgeTriangle.h" using namespace CHReviewResult; using namespace CHImageControls; // CReviewProcessor CReviewProcessor::CReviewProcessor(int nThreadCount) : CWorkThreadPools(nThreadCount) { // gdiplus startup if (gpGdiplusToken==NULL) { GdiplusStartupInput gdiplusStartupInput; GdiplusStartup(&gpGdiplusToken, &gdiplusStartupInput, NULL); gpGdiplusTokenCount++; } InitializeCriticalSection(&m_csUseThreadIndex); m_pView = NULL; m_pRP2P = NULL; m_pReviewDefectFinder = new CReviewDefectFinder[nThreadCount]; m_pEdgeTriangle = new CEdgeTriangle[nThreadCount]; m_pUseThreadIndex = new bool [nThreadCount]; for (int i=0; i-1 && nIndex100 || nStep<1 || nStep>10) return FALSE; m_nReviewResizeWidth = nWidth; m_nReviewResizeHeight = nHeight; m_nReviewImageSize = nSize; //byte m_nReviewImageQuality = nQuality; m_nReviewImageStep = nStep; m_dReviewImageScale = dScale; return TRUE; } BOOL CReviewProcessor::SetReviewImageInfo(int nWidth, int nHeight, int nSize, int nQuality, int nStep, double dScale, BOOL bOriginImg, int nImageRotate, int nImageFlip) { if (nQuality>100 || nStep<1 || nStep>10) return FALSE; if (nImageRotate == 1 || nImageRotate == 3) { m_nReviewResizeWidth = nHeight; m_nReviewResizeHeight = nWidth; } else { m_nReviewResizeWidth = nWidth; m_nReviewResizeHeight = nHeight; } m_nReviewImageSize = nSize; //byte m_nReviewImageQuality = nQuality; m_nReviewImageStep = nStep; m_dReviewImageScale = dScale; m_bReviewOriginalImage = bOriginImg; m_nImageRotate = nImageRotate; m_nimageFlip = nImageFlip; return TRUE; } void CReviewProcessor::SetUploadImagePath(const CString& strImagePath) { m_strSaveImageUploadPath = strImagePath; } void CReviewProcessor::GetSaveImageBasePath( CString& strPath ) { strPath = m_strSaveImageBasePath; } CString CReviewProcessor::GetUploadImagePath() { return m_strSaveImageUploadPath; } void CReviewProcessor::SetRTMSUploadImagePath(const CString& strImagePath) { m_strRTMSImagePath = strImagePath; } CString CReviewProcessor::GetRTMSUploadImagePath() { return m_strRTMSImagePath; } void CReviewProcessor::SetDefectFindInfo(const CRsRcpDefectFindInfo* pDefectFindInfo) { if (pDefectFindInfo==NULL) return; m_bDefectFindProcess = pDefectFindInfo->m_bDefectFind; m_ReviewDefectFindParam.nDirection = pDefectFindInfo->m_nDirection; m_ReviewDefectFindParam.dPitchX = pDefectFindInfo->m_nDFPitchX; m_ReviewDefectFindParam.dPitchY = pDefectFindInfo->m_nDFPitchY; m_ReviewDefectFindParam.nAutoPitchRange = pDefectFindInfo->m_nDFAutoPitchRange; m_ReviewDefectFindParam.nThreshold = pDefectFindInfo->m_nDFThreshold; } UINT64 CReviewProcessor::SaveReviewImage(CCHImageData* pImageData, const CString& strFilename, UINT64 nMaxSize, int nQuality, int nStep) { if (pImageData==NULL) return 0; UINT64 nSize = 0; BOOL bFind = FALSE; CFileFind finder; do { if (pImageData->SaveImage(strFilename, nQuality)==FALSE) { return 0; } bFind = finder.FindFile(strFilename); if (bFind==FALSE) return 0; bFind = finder.FindNextFile(); nSize = finder.GetLength(); nQuality -= nStep; if (nQuality<1 || nQuality>100) { return 0; } } while (nSize > nMaxSize); return nSize; } BOOL CReviewProcessor::SaveReviewImage(CCHImageData* pImageData, const CString& strFilename) { if (pImageData==NULL) return 0; BOOL bFind = FALSE; CFileFind finder; if (pImageData->SaveImage(strFilename)==FALSE) { return 0; } bFind = finder.FindFile(strFilename); return bFind; } void CReviewProcessor::DrawText(CDC *pDC, int nStartX, int nStartY, const VectorPoint& vectorPoint, const VectorString& vectorString) { if (pDC==NULL) return; pDC->SelectStockObject(WHITE_PEN); CFont font; VERIFY(font.CreateFont( 17, // nHeight 9, // nWidth 0, // nEscapement 0, // nOrientation FW_NORMAL, // nWeight FALSE, // bItalic FALSE, // bUnderline 0, // cStrikeOut ANSI_CHARSET, // nCharSet OUT_DEFAULT_PRECIS, // nOutPrecision CLIP_DEFAULT_PRECIS, // nClipPrecision DEFAULT_QUALITY, // nQuality DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily _T("Arial"))); // lpszFacename // Do something with the font just created... CFont* def_font = pDC->SelectObject(&font); // pDC->SetTextColor(RGB(255,255,255)); // pDC->SetBkMode(TRANSPARENT); pDC->SetTextColor(RGB(255,255,0)); pDC->SetBkColor(RGB(0, 0, 0)); pDC->SetBkMode(OPAQUE); // text out for (int i=0; i<(int)vectorPoint.size(); i++) { pDC->TextOut(vectorPoint[i].x + nStartX, vectorPoint[i].y + nStartY, vectorString[i]); } } void CReviewProcessor::DrawRuler(CDC *pDC, int nWidth, int nHeight, double dResolution, double dRulerGab) { if (pDC==NULL || dRulerGab==0.0 || dResolution==0.0) return; if (nWidth==0 || nHeight==0) return; pDC->SelectStockObject(WHITE_PEN); CFont font; VERIFY(font.CreateFont( 10, // nHeight 5, // nWidth 0, // nEscapement 0, // nOrientation FW_NORMAL, // nWeight FALSE, // bItalic FALSE, // bUnderline 0, // cStrikeOut ANSI_CHARSET, // nCharSet OUT_DEFAULT_PRECIS, // nOutPrecision CLIP_DEFAULT_PRECIS, // nClipPrecision DEFAULT_QUALITY, // nQuality DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily _T("Arial"))); // lpszFacename // Do something with the font just created... CFont* def_font = pDC->SelectObject(&font); pDC->SetTextColor(RGB(255,255,255)); pDC->SetBkMode(TRANSPARENT); // ruler double dResX = dResolution; double dResY = dResolution; double dGabX = dRulerGab / dResX; // um double dGabY = dRulerGab / dResY; // um if (dGabX<=0.0 || dGabY<=0.0) return; double dWidth = nWidth; double dHeight = nHeight; double dCenterX = dWidth/2.0; double dCenterY = dHeight/2.0; // x direction CString strValue = _T(""); strValue.Format(_T("%.1lf um"), dRulerGab); pDC->TextOut(5, nHeight/2+5, strValue); for (double dPos=dCenterX; dPos>=0.0; dPos-=dGabX) { pDC->MoveTo((int)(dPos+0.5), 0); pDC->LineTo((int)(dPos+0.5), 6); } for (double dPos=dCenterX+dGabX; dPosMoveTo((int)(dPos+0.5), 0); pDC->LineTo((int)(dPos+0.5), 6); } // y direction strValue.Format(_T("%.1lf um"), dRulerGab); pDC->TextOut(nWidth/2+5, 5, strValue); for (double dPos=dCenterY; dPos>0.0; dPos-=dGabY) { pDC->MoveTo(0, (int)(dPos+0.5)); pDC->LineTo(6, (int)(dPos+0.5)); } for (double dPos=dCenterY+dGabY; dPosMoveTo(0, (int)(dPos+0.5)); pDC->LineTo(6, (int)(dPos+0.5)); } } void CReviewProcessor::DrawDefectPosCursor(CDC* pDC, int nDefectPosX, int nDefectPosY) { if (pDC==NULL) return; POINT ptTemp; CPen pen, *pOldPen; pen.CreatePen(PS_SOLID, 2, RGB(0,255,0)); pOldPen = (CPen*) pDC->SelectObject(&pen); ptTemp.x = nDefectPosX; ptTemp.y = nDefectPosY; pDC->MoveTo(ptTemp.x, ptTemp.y); ptTemp.x = ptTemp.x + 14; pDC->LineTo(ptTemp.x, ptTemp.y); pDC->MoveTo(ptTemp.x, ptTemp.y); ptTemp.x = ptTemp.x - 4; ptTemp.y = ptTemp.y - 4; pDC->LineTo(ptTemp.x, ptTemp.y); pDC->MoveTo(ptTemp.x, ptTemp.y); ptTemp.x = ptTemp.x + 10; ptTemp.y = ptTemp.y - 10; pDC->LineTo(ptTemp.x, ptTemp.y); pDC->MoveTo(ptTemp.x, ptTemp.y); ptTemp.x = ptTemp.x - 6; ptTemp.y = ptTemp.y - 6; pDC->LineTo(ptTemp.x, ptTemp.y); pDC->MoveTo(ptTemp.x, ptTemp.y); ptTemp.x = ptTemp.x - 10; ptTemp.y = ptTemp.y + 10; pDC->LineTo(ptTemp.x, ptTemp.y); pDC->MoveTo(ptTemp.x, ptTemp.y); ptTemp.x = ptTemp.x - 4; ptTemp.y = ptTemp.y - 4; pDC->LineTo(ptTemp.x, ptTemp.y); pDC->MoveTo(ptTemp.x, ptTemp.y); ptTemp.y = ptTemp.y + 14; pDC->LineTo(ptTemp.x, ptTemp.y); pDC->SelectObject(pOldPen); } void CReviewProcessor::DrawDefectRect(CDC* pDC, const CRect& rtRect) { if (pDC==NULL) return; CPen pen, *pOldPen; pen.CreatePen(PS_SOLID, 2, RGB(0,255,0)); pOldPen = (CPen*) pDC->SelectObject(&pen); pDC->SelectStockObject(NULL_BRUSH); pDC->Rectangle(rtRect); /* ptTemp.x = nDefectPosX; ptTemp.y = nDefectPosY; pDC->MoveTo(ptTemp.x, ptTemp.y); ptTemp.x = ptTemp.x + 14; pDC->LineTo(ptTemp.x, ptTemp.y); pDC->MoveTo(ptTemp.x, ptTemp.y); ptTemp.x = ptTemp.x - 4; ptTemp.y = ptTemp.y - 4; pDC->LineTo(ptTemp.x, ptTemp.y); pDC->MoveTo(ptTemp.x, ptTemp.y); ptTemp.x = ptTemp.x + 10; ptTemp.y = ptTemp.y - 10; pDC->LineTo(ptTemp.x, ptTemp.y); pDC->MoveTo(ptTemp.x, ptTemp.y); ptTemp.x = ptTemp.x - 6; ptTemp.y = ptTemp.y - 6; pDC->LineTo(ptTemp.x, ptTemp.y); pDC->MoveTo(ptTemp.x, ptTemp.y); ptTemp.x = ptTemp.x - 10; ptTemp.y = ptTemp.y + 10; pDC->LineTo(ptTemp.x, ptTemp.y); pDC->MoveTo(ptTemp.x, ptTemp.y); ptTemp.x = ptTemp.x - 4; ptTemp.y = ptTemp.y - 4; pDC->LineTo(ptTemp.x, ptTemp.y); pDC->MoveTo(ptTemp.x, ptTemp.y); ptTemp.y = ptTemp.y + 14; pDC->LineTo(ptTemp.x, ptTemp.y); */ pDC->SelectObject(pOldPen); } // PCControl Control command BOOL CReviewProcessor::Signal_SendSignal(int nSignalIndex) { CSignalControl *pSignalControl = m_pRP2P->IRP2P_GetSignalControl(); if (pSignalControl==NULL) return FALSE; int nAddrIdx = 0; if (pSignalControl->Write_SendSignal(nAddrIdx, nSignalIndex, 1, 2000)) { m_pRP2P->IRP2P_DisplayMessage(_T("[PCControl_Send] Send Fail! ")); return FALSE; } return TRUE; } // Review Camera Control Command void CReviewProcessor::ReviewCamera_CameraControl(int nControlCmd) { int nModuleCount = Module_GetModuleStatusCount(); for (int nModuleIdx=0; nModuleIdxnCameraControl != nControlCmd) { pReviewCameraControl->Camera_Control(nControlCmd); pCameraControl->nCameraControl = nControlCmd; m_pRP2P->IRP2P_UpdateCameraControl(nModuleIdx, pCameraControl, NULL); } } } BOOL CReviewProcessor::ReviewCamera_CameraControl(int nModuleIndex, int nControlCmd) { SCameraControl *pCameraControl = Module_GetCameraControl(nModuleIndex); CCameraControlReview *pReviewCameraControl = ReviewCamera_GetReviewCameraControl(nModuleIndex); if (pCameraControl==NULL || pReviewCameraControl==NULL) { return FALSE; } if (nControlCmd!=CameraControlStop) { pReviewCameraControl->Camera_Control(CameraControlStop); } if(pReviewCameraControl->Camera_Control(nControlCmd)) { pCameraControl->nCameraControl = nControlCmd; m_pRP2P->IRP2P_UpdateCameraControl(nModuleIndex, pCameraControl, NULL); return TRUE; } return FALSE; } int CReviewProcessor::ReviewCamera_GetReviewCameraControlCount() const { return m_pRP2P->IRP2P_GetReviewCameraControlCount(); } CCameraControlReview* CReviewProcessor::ReviewCamera_GetReviewCameraControl(int nModuleIndex) { return m_pRP2P->IRP2P_GetReviewCameraControl(nModuleIndex); } // getter module status int CReviewProcessor::Module_GetModuleStatusCount(int nModuleType) const { return m_pRP2P->IRP2P_GetModuleStatusCount(nModuleType); } CModuleStatus* CReviewProcessor::Module_GetModuleStatus(int nModuleIdx) { return m_pRP2P->IRP2P_GetModuleStatus(nModuleIdx); } SCameraControl* CReviewProcessor::Module_GetCameraControl(int nModuleIdx) { CModuleStatus *pModuleStatus = Module_GetModuleStatus(nModuleIdx); if (pModuleStatus==NULL) return NULL; return pModuleStatus->GetCameraControl(); } SMotorPosition* CReviewProcessor::Module_GetMotorPosition(int nModuleIdx) { CModuleStatus *pModuleStatus = Module_GetModuleStatus(nModuleIdx); if (pModuleStatus==NULL) return NULL; return pModuleStatus->GetMotorPosition(); } SMotorStatus* CReviewProcessor::Module_GetMotorStatus(int nModuleIdx) { CModuleStatus *pModuleStatus = Module_GetModuleStatus(nModuleIdx); if (pModuleStatus==NULL) return NULL; return pModuleStatus->GetMotorStatus(); } SAxisIndex* CReviewProcessor::Module_GetAxisIndex(int nModuleIdx) { CModuleStatus *pModuleStatus = Module_GetModuleStatus(nModuleIdx); if (pModuleStatus==NULL) return NULL; return pModuleStatus->GetAxisIndex(); } SCoordInfo* CReviewProcessor::Module_GetCoordInfo(int nModuleIdx) { CModuleStatus *pModuleStatus = Module_GetModuleStatus(nModuleIdx); if (pModuleStatus==NULL) return NULL; return pModuleStatus->GetCoordInfo(); } SCameraInfo* CReviewProcessor::Module_GetCurrentCameraInfo(int nModuleIdx) { CModuleStatus *pModuleStatus = Module_GetModuleStatus(nModuleIdx); if (pModuleStatus==NULL) return NULL; return pModuleStatus->GetCurrentCameraInfo(); } SCameraInfo* CReviewProcessor::Module_GetCameraInfo(int nModuleIdx, int nZoomIdx) { CModuleStatus *pModuleStatus = Module_GetModuleStatus(nModuleIdx); if (pModuleStatus==NULL) return NULL; return pModuleStatus->GetCameraInfo(nZoomIdx); } BOOL CReviewProcessor::WSI_SetWSIEnd() { BOOL bReturn = TRUE; for (int i=0; i=Module_GetModuleStatusCount()) { return FALSE; } CWsiControl *pWSIControl = m_pRP2P->IRP2P_GetWSIControl(nModuleIndex); if (pWSIControl==NULL) return FALSE; return pWSIControl->SetWsiEnd(); } BOOL CReviewProcessor::WSI_SetWSITimeOver(int nModuleIndex) { if (nModuleIndex<0 || nModuleIndex>=Module_GetModuleStatusCount()) { return FALSE; } CWsiControl *pWSIControl = m_pRP2P->IRP2P_GetWSIControl(nModuleIndex); if (pWSIControl==NULL) return FALSE; return pWSIControl->SetWsiTimeOver(); } void CReviewProcessor::SetCellData(CGlassResult* pGlassResult) { m_vecCellId.clear(); m_vecCellIndex.clear(); int nVectorCellCount = pGlassResult->GetCellResultCount(); VectorCellResult* pVectorCellResult = pGlassResult->GetVectorCellResult(); for(int nVectorCellIdx = 0; nVectorCellIdx < nVectorCellCount; nVectorCellIdx++) { m_vecCellId.push_back(pVectorCellResult->at(nVectorCellIdx).strCellID); m_vecCellIndex.push_back(0); } } int CReviewProcessor::GetCellIdIdx(const CString& strCellID) { int nCellIDCount = (int)m_vecCellId.size(); for(int nCellIDIdx = 0; nCellIDIdx < nCellIDCount; nCellIDIdx++) { if(!strCellID.Compare(m_vecCellId.at(nCellIDIdx))) { return nCellIDIdx; } } return -1; } void CReviewProcessor::DrawCenterLine( CDC *pDC, int nWidth, int nHeight ) { if (pDC==NULL) return; if (nWidth==0 || nHeight==0) return; CPen CenterPen(PS_SOLID, 2, RGB(255,255,255)); pDC->SelectObject(&CenterPen); double dWidth = nWidth; double dHeight = nHeight; double dCenterX = dWidth/2.0; double dCenterY = dHeight/2.0; // horizontal line pDC->MoveTo(0, nHeight/2); pDC->LineTo(nWidth, nHeight/2); // vertical line pDC->MoveTo(nWidth/2, 0); pDC->LineTo(nWidth/2, nHeight); } void CReviewProcessor::DrawCenterRect( CDC *pDC, int nWidth, int nHeight, int nDrawWidth, int nDrawHeight, double dResolution ) { if (pDC==NULL) return; if (nWidth==0 || nHeight==0 || nDrawWidth==0 || nDrawHeight==0) return; CPen CenterPen(PS_SOLID, 3, RGB(255,0,0)); pDC->SelectObject(&CenterPen); int nPixelWidth = int(nDrawWidth/dResolution); int nPixelHeight = int(nDrawHeight/dResolution); int nCenterPixelX = nWidth/2; int nCenterPixelY = nHeight/2; // top line pDC->MoveTo(nCenterPixelX-nPixelWidth/2, nCenterPixelY-nPixelHeight/2); pDC->LineTo(nCenterPixelX+nPixelWidth/2, nCenterPixelY-nPixelHeight/2); // left line pDC->MoveTo(nCenterPixelX-nPixelWidth/2, nCenterPixelY-nPixelHeight/2); pDC->LineTo(nCenterPixelX-nPixelWidth/2, nCenterPixelY+nPixelHeight/2); // right line pDC->MoveTo(nCenterPixelX+nPixelWidth/2, nCenterPixelY-nPixelHeight/2); pDC->LineTo(nCenterPixelX+nPixelWidth/2, nCenterPixelY+nPixelHeight/2); // bottom line pDC->MoveTo(nCenterPixelX-nPixelWidth/2, nCenterPixelY+nPixelHeight/2); pDC->LineTo(nCenterPixelX+nPixelWidth/2, nCenterPixelY+nPixelHeight/2); } void IReviewProcessor2Parent::IRP2P_UpdateWSISelfDiagnosisResult() { }