// ViewDefect.cpp : ±¸Çö ÆÄÀÏÀÔ´Ï´Ù. // #include "stdafx.h" #include "ENRIT.h" #include "ViewDefect.h" #include "afxdialogex.h" #include "Global_Define.h" // CViewDefect ´ëÈ­ »óÀÚÀÔ´Ï´Ù. #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 const int DEFECT_COLUMN_COUNT = 13; const TCHAR *DEFECTLIST_COLUMN_ITEM[DEFECT_COLUMN_COUNT] = {_T("No"),_T("Side"),_T("Type"),_T("Index"),_T("W Size(um)"),_T("H Size(um)"),_T("RScale(um"),_T("Xpos(um)"),_T("Ypos(um)"),_T("Cam") ,_T("ScanIdx"),_T("StartLine"),_T("Defect Idx")}; const int DEFECT_COLUMN_WIDHT[DEFECT_COLUMN_COUNT] = {40,60,60,80,80,80,80,80,40,40,80,80,80}; IMPLEMENT_DYNAMIC(CViewDefect, CDialogEx) CViewDefect::CViewDefect(CWnd* pParent /*=NULL*/) : CDialogEx(CViewDefect::IDD, pParent) { m_pHardware = NULL; m_pGlassData = NULL; m_pMapDefect = NULL; m_bAsending = TRUE; m_pIV2M = NULL; m_pSelDefect = NULL; } CViewDefect::~CViewDefect() { } void CViewDefect::DoDataExchange(CDataExchange* pDX) { DDX_Control(pDX,IDC_GRD_DEFECT_LIST,m_GrdDefect); DDX_Control(pDX, IDC_SCROLLBAR_DEFECT_H, m_ctrlScrollH); CDialogEx::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CViewDefect, CDialogEx) ON_WM_HSCROLL() ON_NOTIFY(NM_CLICK, IDC_GRD_DEFECT_LIST, OnGridClick) ON_NOTIFY(NM_DBLCLK, IDC_GRD_DEFECT_LIST, OnGridDBClick) ON_MESSAGE(UM_CLK_ITEM_UPDATE , OnCImgListViewItemCLK) END_MESSAGE_MAP() BOOL CViewDefect::PreTranslateMessage(MSG* pMsg) { if( pMsg->message == WM_KEYDOWN ) { if(pMsg->wParam == VK_RETURN || pMsg->wParam == VK_ESCAPE ) { ::TranslateMessage(pMsg); ::DispatchMessage(pMsg); return TRUE; // DO NOT process further } } return CDialogEx::PreTranslateMessage(pMsg); } BOOL CViewDefect::OnInitDialog(void) { CDialogEx::OnInitDialog(); Init_DefectGrid(); GetDlgItem(IDC_STATIC_DEFECT_IMAGE)->GetWindowRect(&m_rcDefectImg); ScreenToClient(m_rcDefectImg); m_DefectImg.SetMeasureAble(TRUE); m_DefectImg.Create(m_rcDefectImg, this); InitScrollInfo(); CRect rc; m_pContextImgList.m_pNewViewClass = RUNTIME_CLASS(CImgListView); m_pImgList = (CImgListView*)((CFrameWnd*)this)->CreateView(&m_pContextImgList); ASSERT(m_pImgList); GetDlgItem(IDC_STATIC_IMG_LIST)->GetWindowRect(rc); ScreenToClient(rc); m_pImgList->ShowWindow(SW_NORMAL); m_pImgList->MoveWindow(rc); return TRUE; } // CViewDefect ¸Þ½ÃÁö 󸮱âÀÔ´Ï´Ù. void CViewDefect::SetRecipe(CHardwareSettings *pHW) { m_pHardware = pHW; } void CViewDefect::SetGlassData(CGlass_Data *pGlass) { m_pGlassData = pGlass; } void CViewDefect::OnGridClick(NMHDR *pNotifyStruct, LRESULT* /*pResult*/) { NM_GRIDVIEW* pItem = (NM_GRIDVIEW*) pNotifyStruct; if(pItem->iRow == 0) { SortListDefect(pItem->iColumn); FillDefectList(); } } void CViewDefect::SelectDefect( int nSelDefect ) { if(m_GrdDefect.GetRowCount() <= 1) return; int nListDefectIdx; int iRow,iCol=0; CString str; if(m_nSelectedRow > 0) { m_GrdDefect.SetItemState(m_nSelectedRow, m_nSelectedCol, m_GrdDefect.GetItemState(m_nSelectedRow, m_nSelectedCol) & ~GVIS_SELECTED & ~GVIS_FOCUSED); m_nSelectedRow = -1; m_nSelectedCol = -1; } for (iRow = 1; iRow < m_GrdDefect.GetRowCount() ; iRow++) { str = m_GrdDefect.GetItemText(iRow, 0); nListDefectIdx = _ttoi(str); if (nListDefectIdx == nSelDefect) { m_GrdDefect.SetItemState(iRow,iCol, LVIS_SELECTED|LVIS_FOCUSED); m_GrdDefect.EnsureVisible(iRow, 0); m_nSelectedRow = iRow; m_nSelectedCol = 0; break; } } m_GrdDefect.Invalidate(); } LRESULT CViewDefect::OnCImgListViewItemCLK(WPARAM wParam, LPARAM lParam) { CString strFileName = m_pImgList->GetSelectImgPath(); if((int)m_pSortDefect.size() <= 0) return 0; LISTDefectit it; CInspectDefect *pDefect; vector< pair > vec; CString strFullPath; int nIndex = 0; for(it = m_pSortDefect.begin(); it != m_pSortDefect.end(); ++it,nIndex++) { pDefect = *it; if(pDefect == NULL) continue; strFullPath = pDefect->m_strDefectPath; if(strFullPath.IsEmpty() == TRUE) continue; strFileName.MakeUpper(); strFullPath.MakeUpper(); if(strFileName == strFullPath) { SelectDefect(pDefect->m_nGlassDefectIdx); SetSelectDefectImg(nIndex+1); break; } } return 1; } void CViewDefect::SetSelectDefectImg(int iRow) { if(m_pIV2M != NULL) { int iDefect; iDefect = _ttoi(m_GrdDefect.GetItemText(iRow,0)); m_pSelDefect = FindDefectBuffer(iDefect); if(m_pSelDefect == NULL) return; if(m_pSelDefect->m_strDefectPath.IsEmpty() == TRUE) return; int nStageNo = g_pBase->m_nStageNo; if(nStageNo < 0 || nStageNo > 1) nStageNo = 0; CCameraSettings *pCamera = NULL; double dResH=5,dResV=5; if(m_pHardware != NULL) { pCamera = m_pHardware->GetCameraSettings(m_pSelDefect->m_nCameraID,m_pSelDefect->m_nScanIdx); dResH = pCamera->m_dConvResolution[nStageNo]; dResV = pCamera->m_dScanResolution[nStageNo]; } m_DefectImg.SetDefectImage(m_pSelDefect->m_nSideLoc,m_pSelDefect->m_strDefectPath,dResH, dResV); } InitScrollInfo(); } void CViewDefect::OnGridDBClick(NMHDR *pNotifyStruct, LRESULT* pResult) { NM_GRIDVIEW* pItem = (NM_GRIDVIEW*) pNotifyStruct; if (pItem->iRow < 0) return; m_nSelectedRow = pItem->iRow; m_nSelectedCol = pItem->iColumn; SetSelectDefectImg(m_nSelectedRow); } CInspectDefect *CViewDefect::FindDefectBuffer(int iGlassIdx) { if(m_pMapDefect == NULL) return NULL; MapDefectIt it; CInspectDefect *pDefect; for(it=m_pMapDefect->begin();it!=m_pMapDefect->end();it++) { pDefect = static_cast(it->second); if(pDefect == NULL) continue; if(pDefect->m_nGlassDefectIdx == iGlassIdx) { return pDefect; } } return NULL; } void CViewDefect::InitScrollInfo() { SCROLLINFO scrollInfoH; scrollInfoH.cbSize = sizeof(SCROLLINFO); scrollInfoH.fMask = SIF_ALL; scrollInfoH.nMin = 1; scrollInfoH.nPos = abs(m_DefectImg.m_ptOrg.x); scrollInfoH.nTrackPos = 64; scrollInfoH.nMax = m_DefectImg.GetImgWidth() - m_rcDefectImg.Width(); scrollInfoH.nPage = scrollInfoH.nMax - (m_DefectImg.GetImgWidth() - m_rcDefectImg.Width()); m_ctrlScrollH.SetScrollPos(abs(m_DefectImg.m_ptOrg.x)); m_ctrlScrollH.SetScrollInfo(&scrollInfoH); } void CViewDefect::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { // TODO: ¿©±â¿¡ ¸Þ½ÃÁö 󸮱â Äڵ带 Ãß°¡ ¹×/¶Ç´Â ±âº»°ªÀ» È£ÃâÇÕ´Ï´Ù. SCROLLINFO si; si.fMask = SIF_ALL; m_ctrlScrollH.GetScrollInfo(&si, SIF_ALL); switch (nSBCode) { case SB_LINEUP: si.nPos--; break; case SB_LINEDOWN: si.nPos++; break; case SB_PAGEUP: si.nPos-=si.nPage; break; case SB_PAGEDOWN: si.nPos+=si.nPage; break; case SB_THUMBTRACK: si.nPos=nPos; break; } if (si.nPos>(int)(si.nMax-si.nMin-si.nPage+1)) si.nPos=si.nMax-si.nMin-si.nPage+1; if (si.nPosDeleteItemAll(); m_pImgList->Invalidate(FALSE); } void CViewDefect::SortListDefect( int nCol ) { LISTDefectit it; CInspectDefect *pDefect; m_bAsending = !m_bAsending; vector< pair > vec; int nValue; for(it = m_pSortDefect.begin(); it != m_pSortDefect.end(); ++it) { pDefect = *it; switch(nCol) { case 0: nValue = pDefect->m_nGlassDefectIdx; break; case 1: nValue = pDefect->m_nSideLoc; break; case 2: nValue = pDefect->m_sDefectLoc; break; case 3: nValue = pDefect->m_nProfileIdx; break; case 4: nValue = pDefect->m_nUMSizeY; break; case 5: nValue = pDefect->m_nUMSizeX; break; case 6: nValue = pDefect->m_nDefectRScale; break; case 7: nValue = pDefect->m_nUMOriginX; break; case 8: nValue = pDefect->m_nUMOriginY; break; case 9: nValue = pDefect->m_nCameraID; break; case 10:nValue = pDefect->m_nScanIdx; break; case 11:nValue = pDefect->m_nPixelGlassStart; break; case 12:nValue = pDefect->m_nDefectIdx; break; default: continue; } vec.push_back(make_pair(nValue,pDefect)); } if(m_bAsending == TRUE) { std::sort(vec.begin(),vec.end(),greater< pair >()); } else { std::sort(vec.begin(),vec.end(),less< pair >()); } m_pSortDefect.clear(); vector< pair >::iterator itVec; for(itVec = vec.begin(); itVec != vec.end(); ++itVec) { m_pSortDefect.push_back(itVec->second); } vec.clear(); } void CViewDefect::SetDefectList(MapDefect* pMapDefect) { if(pMapDefect == NULL) { m_pMapDefect = NULL; } else { m_pMapDefect = pMapDefect; int nDefectSize = (int)m_pMapDefect->size(); MapDefectIt it; CInspectDefect *pInsDefect; for (MapDefectIt it = m_pMapDefect->begin(); it != m_pMapDefect->end(); it++) { pInsDefect = static_cast(it->second); if (!pInsDefect) continue; if(pInsDefect->m_bJudgeDefect == FALSE) continue; m_pOrgDefect.push_back(pInsDefect); m_pSortDefect.push_back(pInsDefect); } } SortListDefect(0); FillDefectList(); } void CViewDefect::SetDefectPath(CString strPath) { m_strDefectPath = strPath; m_pImgList->DeleteItemAll(); m_pImgList->Invalidate(FALSE); if((int)m_pSortDefect.size() > 0) { CString str = strPath + _T("\\"); m_pImgList->LoadImageFolder(str,g_pBase->m_strHPanelID); } } void CViewDefect::FillDefectList() { if(m_GrdDefect.GetSafeHwnd() == NULL) return; m_GrdDefect.SetRowCount((int)m_pSortDefect.size()+1); LISTDefectit it; CInspectDefect *pDefect; int iRow,iCol; CString str; iRow = 1; for(it = m_pSortDefect.begin(); it != m_pSortDefect.end(); ++it,iRow++) { pDefect = *it; if(pDefect == NULL) continue; iCol = 0; str.Format(_T("%d"),pDefect->m_nGlassDefectIdx); m_GrdDefect.SetItemText(iRow,iCol,str); iCol = 1; str.Format(_T("%s"),PANEL_SIDE[pDefect->m_nSideLoc]); m_GrdDefect.SetItemText(iRow,iCol,str); iCol = 2; str = _T("Unknown"); switch(pDefect->m_sDefectLoc) { case DefectLoc_Crack: str=_T("Crack"); break; case DefectLoc_Broken: str=_T("Broken"); break; case DefectLoc_Chip: { if(pDefect->m_sSplineLoc == Spline_None) str=_T("Chip"); else str=_T("R_Chip"); break; } case DefectLoc_Chamfer: str=_T("Chamfer"); break; case DefectLoc_Burr: str=_T("Burr"); break; case DefectLoc_Thin: str=_T("Thin"); break; case DefectLoc_Air: str=_T("Lifting"); break; case DefectLoc_Notch: str=_T("NCut"); break; case DefectLoc_Hole: str=_T("Hole"); break; case DefectLoc_Profile: str=_T("Profile"); break; case DefectLoc_KDist: str = _T("KDist"); break; case DefectLoc_RCUTChip: str = _T("RCUTChip"); break; } m_GrdDefect.SetItemText(iRow,iCol,str); iCol = 3; int nIndex = pDefect->m_nProfileIdx; if(pDefect->m_sDefectLoc == DefectLoc_Chamfer|| pDefect->m_sDefectLoc == DefectLoc_Profile) nIndex += 1; str.Format(_T("%d"),nIndex); m_GrdDefect.SetItemText(iRow,iCol,str); iCol = 4; str.Format(_T("%d"),pDefect->m_nUMSizeY); m_GrdDefect.SetItemText(iRow,iCol,str); iCol = 5; str.Format(_T("%d"),pDefect->m_nUMSizeX); m_GrdDefect.SetItemText(iRow,iCol,str); iCol = 6; str.Format(_T("%d"),pDefect->m_nDefectRScale); m_GrdDefect.SetItemText(iRow,iCol,str); iCol = 7; str.Format(_T("%d"),pDefect->m_nUMOriginX); m_GrdDefect.SetItemText(iRow,iCol,str); iCol = 8; str.Format(_T("%d"),pDefect->m_nUMOriginY); m_GrdDefect.SetItemText(iRow,iCol,str); iCol = 9; str.Format(_T("%d"),pDefect->m_nCameraID); m_GrdDefect.SetItemText(iRow,iCol,str); iCol = 10; str.Format(_T("%d"),pDefect->m_nScanIdx); m_GrdDefect.SetItemText(iRow,iCol,str); iCol = 11; str.Format(_T("%d"),pDefect->m_nPixelGlassStart); m_GrdDefect.SetItemText(iRow,iCol,str); iCol = 12; str.Format(_T("%d"),pDefect->m_nDefectIdx); m_GrdDefect.SetItemText(iRow,iCol,str); } m_GrdDefect.Invalidate(); } void CViewDefect::Init_DefectGrid() { if(m_GrdDefect.GetSafeHwnd() == NULL) return; // m_GrdDefect.GetDefaultCell(TRUE, FALSE)->SetBackClr(GRID_FIX_COLOR); // m_GrdDefect.GetDefaultCell(FALSE, TRUE)->SetBackClr(GRID_FIX_COLOR); // m_GrdDefect.GetDefaultCell(FALSE, FALSE)->SetBackClr(GRID_COLOR); // m_GrdDefect.SetFixedBkColor(GRID_FIX_COLOR); m_GrdDefect.SetGridLines(GVL_BOTH); m_GrdDefect.SetColumnCount(DEFECT_COLUMN_COUNT); m_GrdDefect.SetRowCount(1000); m_GrdDefect.SetFixedRowCount(1); m_GrdDefect.SetFixedColumnCount(0); CFont *pFont = m_GrdDefect.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_GrdDefect.GetDefaultCell(TRUE, FALSE)->SetFont(&lf); m_GrdDefect.GetDefaultCell(FALSE, TRUE)->SetFont(&lf); m_GrdDefect.GetDefaultCell(TRUE, TRUE)->SetFont(&lf); m_GrdDefect.SetEditable(FALSE); m_GrdDefect.EnableSelection(TRUE); m_GrdDefect.SetFixedRowSelection(TRUE); m_GrdDefect.SetSingleRowSelection(TRUE); m_GrdDefect.SetSingleColSelection(TRUE); Init_DefectGridHeader(); m_GrdDefect.Invalidate(); } void CViewDefect::Init_DefectGridHeader() { CString str; GV_ITEM Item; int nCol = 0; int iLoop; Item.mask = GVIF_TEXT; Item.row = 0; for(iLoop=0;iLoop