// Dlg_Exception.cpp : implementation file // #include "stdafx.h" #include "ViewException.h" #include "afxdialogex.h" #include #include "Glass_Data.h" const int EXPAREA_COLUMN_COUNT = 8; const char* EXPAREA_COLUMN_ITEM[EXPAREA_COLUMN_COUNT] = {"No","Px","Py","Width","Height","Error X","Error Y","Apply Defect"}; const int EXPAREA_COLUMN_WIDHT[EXPAREA_COLUMN_COUNT] = {50,80,80,80,80,80,80,350}; #define GRID_FIX_COLOR RGB(144,200,246) #define GRID_COLOR RGB(242,242,242) #define GRID_TEXT_COLOR RGB(255,255,255) #define GRID_LINE_COLOR GRID_FIX_COLOR // CViewException dialog IMPLEMENT_DYNAMIC(CViewException, CDialogEx) CViewException::CViewException(CWnd* pParent /*=NULL*/) : CDialogEx(CViewException::IDD, pParent) { m_nExceptionType = 0; m_index = 0; m_ptOrg = CPoint (0,0); m_nSelectRow = 0; m_dEditPX = 0; m_dEditPY = 0; m_dEditROIWidth = 0; m_dEditROIHeight = 0; m_nErrorDx = 0; m_nErrorDy = 0; m_pHardwareSetting = NULL; m_pGlassRecipe = NULL; m_pGlassData = NULL; m_pExpArea = NULL; } CViewException::~CViewException() { } void CViewException::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); DDX_Text(pDX, IDC_EDIT_PX , m_dEditPX); DDX_Text(pDX, IDC_EDIT_PY , m_dEditPY); DDX_Text(pDX, IDC_EDIT_ROI_W , m_dEditROIWidth); DDX_Text(pDX, IDC_EDIT_ROI_H , m_dEditROIHeight); DDX_Text(pDX, IDC_EDIT_ERR_DX , m_nErrorDx); DDX_Text(pDX, IDC_EDIT_ERR_DY , m_nErrorDy); DDX_Control(pDX, IDC_CHK_TFT_CHIPPING , m_chk_AppDefect[0]); DDX_Control(pDX, IDC_CHK_TFT_BUR , m_chk_AppDefect[1]); DDX_Control(pDX, IDC_CHK_TFT_BROKEN , m_chk_AppDefect[2]); DDX_Control(pDX, IDC_CHK_CRACK , m_chk_AppDefect[3]); DDX_Control(pDX, IDC_CF_CHIPPING , m_chk_AppDefect[4]); DDX_Control(pDX, IDC_CF_BUR , m_chk_AppDefect[5]); DDX_Control(pDX, IDC_CHK_DETECT_LIMITED_AREA, m_chk_AppDefect[6]); DDX_Control(pDX, IDC_EXPAREA_LIST,m_GrdExpList); } BEGIN_MESSAGE_MAP(CViewException, CDialogEx) ON_BN_CLICKED(IDC_BTN_ADD , &CViewException::OnBnClickedBtnAdd) ON_BN_CLICKED(IDC_BTN_MODIFY , &CViewException::OnBnClickedBtnModify) ON_BN_CLICKED(IDC_BTN_DELETE , &CViewException::OnBnClickedBtnDelete) ON_BN_CLICKED(IDC_BTN_DELETE_ALL , &CViewException::OnBnClickedBtnDeleteAll) ON_BN_CLICKED(IDC_BTN_CLOSE, &CViewException::OnBnClickedBtnClose) ON_WM_PAINT() ON_NOTIFY(NM_DBLCLK, IDC_EXPAREA_LIST, OnGridDBClick) ON_WM_SHOWWINDOW() END_MESSAGE_MAP() // CViewException message handlers BOOL CViewException::OnInitDialog() { CDialogEx::OnInitDialog(); Init_ExpAreaGrid(); for(int i = 0 ; i < 7 ; i++) { m_chk_AppDefect[i].m_nFlatStyle = CMFCButton::BUTTONSTYLE_FLAT; m_chk_AppDefect[i].SetImage(IDB_CHECKNO32 ); m_chk_AppDefect[i].SetCheckedImage(IDB_CHECK32 ); } return TRUE; // return TRUE unless you set the focus to a control } void CViewException::OnShowWindow(BOOL bShow, UINT nStatus) { if(bShow == TRUE) { FillExpAreaGrid(); SetControlData(); UpdateData(FALSE); } } void CViewException::SetRecipe(CHardwareSettings *pHard,CGlassRecipe *pRecipe) { m_pHardwareSetting = pHard; m_pGlassRecipe = pRecipe; } void CViewException::SetIndex(int index) { m_index = index; } void CViewException::Init_ExpAreaGrid() { if(m_GrdExpList.GetSafeHwnd() == NULL) return; m_GrdExpList.GetDefaultCell(TRUE, FALSE)->SetBackClr(GRID_FIX_COLOR); m_GrdExpList.GetDefaultCell(FALSE, TRUE)->SetBackClr(GRID_FIX_COLOR); m_GrdExpList.GetDefaultCell(FALSE, FALSE)->SetBackClr(GRID_COLOR); m_GrdExpList.SetFixedBkColor(GRID_FIX_COLOR); m_GrdExpList.SetGridLines(GVL_BOTH); m_GrdExpList.SetColumnCount(EXPAREA_COLUMN_COUNT); m_GrdExpList.SetRowCount(10); m_GrdExpList.SetFixedRowCount(1); m_GrdExpList.SetFixedColumnCount(0); m_GrdExpList.ExpandColumnsToFit(); CFont *pFont = m_GrdExpList.GetFont(); if (!pFont) return; LOGFONT lf; pFont->GetLogFont(&lf); lf.lfItalic = 0; lf.lfHeight = 14; lf.lfWeight = FW_BOLD; _tcscpy(lf.lfFaceName, _T("Arial")); m_GrdExpList.GetDefaultCell(TRUE, FALSE)->SetFont(&lf); m_GrdExpList.GetDefaultCell(FALSE, TRUE)->SetFont(&lf); m_GrdExpList.GetDefaultCell(TRUE, TRUE)->SetFont(&lf); m_GrdExpList.SetEditable(FALSE); m_GrdExpList.EnableSelection(TRUE); m_GrdExpList.SetSingleRowSelection(TRUE); Init_ExpAreaGridHeader(); } void CViewException::Init_ExpAreaGridHeader() { CString str; GV_ITEM Item; int nCol = 0; int iLoop; Item.mask = GVIF_TEXT; Item.row = 0; for(iLoop=0;iLoopGetExpAreaList((DimensionDir)m_index); EXECPTION_AREA *pExp; int iCam = m_pHardwareSetting->GetCameraIndexToDimension((DimensionDir)m_index); int iScan = m_pHardwareSetting->GetScanToDimension((DimensionDir)m_index); CCameraSettings *pCamera = m_pHardwareSetting->GetCameraSettings(iCam,iScan); if(pCamera == NULL) return; int nStageNo = g_pBase->m_nStageNo; if(nStageNo < 0 || nStageNo > 1) nStageNo = 0; double dResV = pCamera->m_dScanResolution[nStageNo]; double dResH = pCamera->m_dConvResolution[nStageNo]; if(dResV <= 0) dResV = 1; if(dResH <= 0) dResH = 1; m_GrdExpList.SetRowCount((int)pList->size()+1); iRow = 1; for(it=pList->begin();it!=pList->end();it++) { iCol = 0; pExp = *it; str.Format(_T("%d"),iRow); m_GrdExpList.SetItemText(iRow,iCol,str); iCol++; str.Format(_T("%.2f"), (double)(pExp->rc.left * dResH)/1000.0); m_GrdExpList.SetItemText(iRow,iCol,str); iCol++; str.Format(_T("%.2f"), (double)(pExp->rc.top * dResV)/1000.0); m_GrdExpList.SetItemText(iRow,iCol,str); iCol++; str.Format(_T("%.2f"), (double)(pExp->rc.Width() * dResH)/1000.0); m_GrdExpList.SetItemText(iRow,iCol,str); iCol++; str.Format(_T("%.2f"), (double)(pExp->rc.Height() * dResV)/1000.0); m_GrdExpList.SetItemText(iRow,iCol,str); iCol++; str.Format(_T("%d"),pExp->szErrSize.cx); m_GrdExpList.SetItemText(iRow,iCol,str); iCol++; str.Format(_T("%d"),pExp->szErrSize.cy); m_GrdExpList.SetItemText(iRow,iCol,str); iCol++; bitset<16> bit(pExp->nAppDefect); str =""; if(bit[0]) str.AppendFormat(_T("[TFT_CH]")); if(bit[1]) str.AppendFormat(_T("[TFT_RE]")); if(bit[2]) str.AppendFormat(_T("[BROKEN]")); if(bit[3]) str.AppendFormat(_T("[CRACK]")); if(bit[4]) str.AppendFormat(_T("[CF_CH]")); if(bit[5]) str.AppendFormat(_T("[CF_RE]")); if(bit[6]) str.AppendFormat(_T("[TR_KEY]")); if(bit[7]) str.AppendFormat(_T("[DET_LIM_AR]")); m_GrdExpList.SetItemText(iRow,iCol,str); iRow++; } m_GrdExpList.Invalidate(); } void CViewException::OnBnClickedBtnAdd() { if(m_pGlassData == NULL || m_pIE2P == NULL || m_pGlassRecipe == NULL || m_pHardwareSetting == NULL) return; INS_EDGE_RESULT_INFO *pResInfo = m_pGlassData->GetEdgeResultInfo((DimensionDir)m_index); if(pResInfo == NULL) return; // if(pResInfo->ptMark[0].x < 1 || pResInfo->ptMark[0].y < 1) // { // AfxMessageBox(_T("Not Measure Image... This Function use after Measure"),MB_YESNO | MB_ICONQUESTION); // return; // } CINSPECT_JUDGEMENT_PARM *pJudgePrm = m_pGlassRecipe->GetJudgePrm(); int iCam = m_pHardwareSetting->GetCameraIndexToDimension((DimensionDir)m_index); int iScan = m_pHardwareSetting->GetScanToDimension((DimensionDir)m_index); CCameraSettings *pCamera = m_pHardwareSetting->GetCameraSettings(iCam,iScan); if(pCamera == NULL) return; int nStageNo = g_pBase->m_nStageNo; if(nStageNo < 0 || nStageNo > 1) nStageNo = 0; double dResV = pCamera->m_dScanResolution[nStageNo]; double dResH = pCamera->m_dConvResolution[nStageNo]; if(dResV <= 0) dResV = 1; if(dResH <= 0) dResH = 1; m_ptOrg = m_pIE2P->IE2P_GetFrameViewBasepoint(); int nPixelY; nPixelY = (int)(m_ptOrg.y + 100 - pResInfo->ptMark[0].y); //Ãʱâ ÁÂÇ¥¸¦ ³Ö´Â´Ù. m_dEditPX = pJudgePrm->cutting[m_index/4][m_index%4].nRefernce * 0.001 * (-1); m_dEditPY = (double)nPixelY * dResV * 0.001; m_dEditROIWidth = 1.7; m_dEditROIHeight = 1.6; m_nErrorDx = 500; m_nErrorDy = 500; m_pExpArea = new EXECPTION_AREA(); m_pExpArea->Init(); // Pixel ÁÂÇ¥·Î º¯È¯ÇÑ´Ù. m_pExpArea->nAreaType = m_nExceptionType; m_pExpArea->rc.left = int((m_dEditPX * 1000/dResH));// - nPixelY * g_InsData[m_nSide].dOffsetX); m_pExpArea->rc.top = int( m_dEditPY * 1000 /dResV); m_pExpArea->rc.right = int(m_pExpArea->rc.left + m_dEditROIWidth * 1000 / dResH); m_pExpArea->rc.bottom = int(m_pExpArea->rc.top + m_dEditROIHeight * 1000 / dResV); m_pExpArea->nAppDefect = 0x1f; m_pExpArea->szErrSize.cx = m_nErrorDx; m_pExpArea->szErrSize.cy = m_nErrorDy; // Filter ¿µ¿ª¿¡ Ãß°¡ EXCEPTION_AREA_LIST *pList = m_pGlassRecipe->GetExpAreaList((DimensionDir)m_index); pList->push_back(m_pExpArea); m_pIE2P->IE2P_SetExpArea(m_index); FillExpAreaGrid(); } void CViewException::OnBnClickedBtnModify() { if(m_pGlassData == NULL || m_pIE2P == NULL || m_pGlassRecipe == NULL || m_pHardwareSetting == NULL) return; if(m_pExpArea == NULL) return; UpdateData(TRUE); double dResV,dResH; GetResolution(dResH,dResV); m_pExpArea->nAreaType = m_nExceptionType; m_pExpArea->rc.top = int(m_dEditPY / dResV * 1000); m_pExpArea->rc.left = int(m_dEditPX / dResH * 1000); m_pExpArea->rc.bottom = int(m_pExpArea->rc.top + (m_dEditROIHeight/ dResV) * 1000); m_pExpArea->rc.right = int(m_pExpArea->rc.left + (m_dEditROIWidth/ dResH) * 1000); m_pExpArea->szErrSize.cx = m_nErrorDx; m_pExpArea->szErrSize.cy = m_nErrorDy; bitset<16> bit; ((CButton*)GetDlgItem(IDC_CHK_TFT_CHIPPING))->GetCheck()? bit.set(0) : bit.reset(0); ((CButton*)GetDlgItem(IDC_CHK_TFT_BUR))->GetCheck() ? bit.set(1) : bit.reset(1); ((CButton*)GetDlgItem(IDC_CHK_TFT_BROKEN))->GetCheck() ? bit.set(2) : bit.reset(2); ((CButton*)GetDlgItem(IDC_CHK_CRACK))->GetCheck() ? bit.set(3) : bit.reset(3); ((CButton*)GetDlgItem(IDC_CF_CHIPPING))->GetCheck() ? bit.set(4) : bit.reset(4); ((CButton*)GetDlgItem(IDC_CF_BUR))->GetCheck() ? bit.set(5) : bit.reset(5); ((CButton*)GetDlgItem(IDC_CHK_DETECT_LIMITED_AREA))->GetCheck() ? bit.set(6) : bit.reset(6); // ((CButton*)GetDlgItem(IDC_CHK_TRIMER_KEY))->GetCheck() ? bit.set(6) : bit.reset(6); m_pExpArea->nAppDefect = bit.to_ulong(); FillExpAreaGrid(); m_pIE2P->IU2P_DrawRefresh(); } void CViewException::OnBnClickedBtnDelete() { if(m_pGlassData == NULL || m_pIE2P == NULL || m_pGlassRecipe == NULL || m_pHardwareSetting == NULL) return; m_pIE2P->IE2P_SetExpAreaTrackerReset(); EXCEPTION_AREA_LIST *pList = m_pGlassRecipe->GetExpAreaList((DimensionDir)m_index); if(pList == NULL) return; for(itEXCEPTION_AREA_LIST it = pList->begin(); it != pList->end() ; it++) { if(m_pExpArea == (*it)) { delete m_pExpArea; pList->erase(it); m_pExpArea = NULL; m_nSelectRow = -1; break; } } FillExpAreaGrid(); SetControlData(); m_pIE2P->IU2P_DrawRefresh(); Invalidate(FALSE); } void CViewException::OnBnClickedBtnDeleteAll() { if(m_pGlassData == NULL || m_pIE2P == NULL || m_pGlassRecipe == NULL || m_pHardwareSetting == NULL) return; m_pIE2P->IE2P_SetExpAreaTrackerReset(); itEXCEPTION_AREA_LIST it; EXCEPTION_AREA_LIST *pList = m_pGlassRecipe->GetExpAreaList((DimensionDir)m_index); if(pList == NULL) return; if(!pList->empty()) { for(it = pList->begin(); it != pList->end() ; it++) { delete (*it); } } pList->clear(); m_nSelectRow = -1; FillExpAreaGrid(); SetControlData(); m_pIE2P->IU2P_DrawRefresh(); Invalidate(FALSE); } void CViewException::OnGridDBClick(NMHDR *pNotifyStruct, LRESULT* pResult) { NM_GRIDVIEW* pItem = (NM_GRIDVIEW*) pNotifyStruct; if (pItem->iRow < 0) return; m_nSelectRow = pItem->iRow; if(m_pGlassRecipe == NULL) return; EXCEPTION_AREA_LIST *pList = m_pGlassRecipe->GetExpAreaList((DimensionDir)m_index); if(pList == NULL) return; if((int)pList->size() < m_nSelectRow) return; itEXCEPTION_AREA_LIST it = pList->begin(); std::advance(it, m_nSelectRow-1); m_pExpArea = *it; if(m_pIE2P != NULL) m_pIE2P->IE2P_SetExpArea(m_index); SetControlData(); UpdateData(FALSE); } void CViewException::SetControlData() { if(m_nSelectRow >= 1 && m_GrdExpList.GetRowCount() > 1) { m_dEditPX = _ttof(m_GrdExpList.GetItemText(m_nSelectRow,1)); m_dEditPY = _ttof(m_GrdExpList.GetItemText(m_nSelectRow,2)); m_dEditROIWidth = _ttof(m_GrdExpList.GetItemText(m_nSelectRow,3)); m_dEditROIHeight = _ttof(m_GrdExpList.GetItemText(m_nSelectRow,4)); m_nErrorDx = _ttoi(m_GrdExpList.GetItemText(m_nSelectRow,5)); m_nErrorDy = _ttoi(m_GrdExpList.GetItemText(m_nSelectRow,6)); } else { m_dEditPX = 0; m_dEditPY = 0; m_dEditROIWidth = 0; m_dEditROIHeight = 0; m_nErrorDx = 0; m_nErrorDy = 0; } bitset<16> bit(0); if(m_pExpArea != NULL) bit = m_pExpArea->nAppDefect; ((CButton*)GetDlgItem(IDC_CHK_TFT_CHIPPING))->SetCheck(bit[0]); ((CButton*)GetDlgItem(IDC_CHK_TFT_BUR))->SetCheck(bit[1]); ((CButton*)GetDlgItem(IDC_CHK_TFT_BROKEN))->SetCheck(bit[2]); ((CButton*)GetDlgItem(IDC_CHK_CRACK))->SetCheck(bit[3]); ((CButton*)GetDlgItem(IDC_CF_CHIPPING))->SetCheck(bit[4]); ((CButton*)GetDlgItem(IDC_CF_BUR))->SetCheck(bit[5]); ((CButton*)GetDlgItem(IDC_CHK_DETECT_LIMITED_AREA))->SetCheck(bit[6]); } void CViewException::GetResolution(double &dH,double &dV) { if(m_pHardwareSetting == NULL) return; int iCam = m_pHardwareSetting->GetCameraIndexToDimension((DimensionDir)m_index); int iScan = m_pHardwareSetting->GetScanToDimension((DimensionDir)m_index); CCameraSettings *pCamera = m_pHardwareSetting->GetCameraSettings(iCam,iScan); if(pCamera == NULL) return; int nStageNo = g_pBase->m_nStageNo; if(nStageNo < 0 || nStageNo > 1) nStageNo = 0; dV = pCamera->m_dScanResolution[nStageNo]; dH = pCamera->m_dConvResolution[nStageNo]; if(dV <= 0) dV = 1; if(dH <= 0) dH = 1; } void CViewException::SetAreaChange(EXECPTION_AREA *pExp) { m_pExpArea = pExp; } void CViewException::SetAreaModify(EXECPTION_AREA *pExp) { if(m_pExpArea == NULL) return; double dResH,dResV; GetResolution(dResH,dResV); CString strTmp; strTmp.Format(_T("%4.3f"),(m_pExpArea->rc.left * dResH)/1000); GetDlgItem(IDC_EDIT_PX)->SetWindowText(strTmp); strTmp.Format(_T("%4.3f"),(m_pExpArea->rc.top * dResV)/1000); GetDlgItem(IDC_EDIT_PY)->SetWindowText(strTmp); strTmp.Format(_T("%4.3f"),(m_pExpArea->rc.Width() * dResH)/1000); GetDlgItem(IDC_EDIT_ROI_W)->SetWindowText(strTmp); strTmp.Format(_T("%4.3f"),(m_pExpArea->rc.Height() *dResV)/1000); GetDlgItem(IDC_EDIT_ROI_H)->SetWindowText(strTmp); FillExpAreaGrid(); } void CViewException::OnBnClickedBtnClose() { if(m_pIE2P != NULL) { m_pIE2P->IE2P_SetExpAreaTrackerReset(); m_pIE2P->IE2P_SetExpAreaDlgClose(); } if(m_pGlassRecipe != NULL) m_pGlassRecipe->SaveExpAreaList(); OnOK(); } void CViewException::OnPaint() { CPaintDC dc(this); // device context for painting }