// DlgHoleRecipeSetting.cpp : ±¸Çö ÆÄÀÏÀÔ´Ï´Ù. // #include "stdafx.h" #include "ENRIT.h" #include "ViewHoleRecipeSetting.h" #include "afxdialogex.h" #include "Global_Define.h" const int HOLE_INSPECT_COLUMN_COUNT = 11; const char* HOLE_INSPECT_COLUMN_ITEM[HOLE_INSPECT_COLUMN_COUNT] = {"Idx", "Side", "Pos L/T", "Pos R/B", "Circle L/T", "Circle R/B", "Threshold", "Offset", "MinSize", "Rate(%)", "Image Path"}; const int HOLE_INSPECT_COLUMN_WIDHT[HOLE_INSPECT_COLUMN_COUNT] = {30, 50, 60, 60, 60, 60, 60, 50, 50, 50, 100}; #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 // CViewHoleRecipeSetting ´ëÈ­ »óÀÚÀÔ´Ï´Ù. IMPLEMENT_DYNAMIC(CViewHoleRecipeSetting, CDialog) CViewHoleRecipeSetting::CViewHoleRecipeSetting(CWnd* pParent /*=NULL*/) : CDialog(CViewHoleRecipeSetting::IDD, pParent) { m_pInterface = NULL; m_pDlgRecipe = NULL; m_vecSide.clear(); m_vecSide.push_back(_T("A Top")); m_vecSide.push_back(_T("B Top")); m_vecSide.push_back(_T("C Top")); m_vecSide.push_back(_T("D Top")); m_vecSide.push_back(_T("A Bot")); m_vecSide.push_back(_T("B Bot")); m_vecSide.push_back(_T("C Bot")); m_vecSide.push_back(_T("D Bot")); CreateDirectory(RECIPE_HOLE_TEMPLATE_PATH, NULL); } CViewHoleRecipeSetting::~CViewHoleRecipeSetting() { m_vecSide.clear(); } void CViewHoleRecipeSetting::DoDataExchange(CDataExchange* pDX) { DDX_Control(pDX, IDC_HOLE_SETTING_LIST, m_HoleList); CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CViewHoleRecipeSetting, CDialog) ON_NOTIFY(GVN_ENDLABELEDIT, IDC_HOLE_SETTING_LIST, OnHoleListEditEnd) ON_NOTIFY(NM_CLICK, IDC_HOLE_SETTING_LIST, &CViewHoleRecipeSetting::OnHoleListClick) END_MESSAGE_MAP() BEGIN_EVENTSINK_MAP(CViewHoleRecipeSetting, CDialog) ON_EVENT(CViewHoleRecipeSetting, IDC_INSPECT_PROCESS, DISPID_CLICK, CViewHoleRecipeSetting::ClickHoleInspectProcess, VTS_NONE) ON_EVENT(CViewHoleRecipeSetting, IDC_VIEW_MODE, DISPID_CLICK, CViewHoleRecipeSetting::ClickViewMode, VTS_NONE) ON_EVENT(CViewHoleRecipeSetting, IDC_BTN_ROI_UP, DISPID_CLICK, CViewHoleRecipeSetting::ClickROIUp, VTS_NONE) ON_EVENT(CViewHoleRecipeSetting, IDC_BTN_ROI_LEFT, DISPID_CLICK, CViewHoleRecipeSetting::ClickROILeft, VTS_NONE) ON_EVENT(CViewHoleRecipeSetting, IDC_BTN_ROI_RIGHT, DISPID_CLICK, CViewHoleRecipeSetting::ClickROIRight, VTS_NONE) ON_EVENT(CViewHoleRecipeSetting, IDC_BTN_ROI_DN, DISPID_CLICK, CViewHoleRecipeSetting::ClickROIDown, VTS_NONE) ON_EVENT(CViewHoleRecipeSetting, IDC_BTN_ROI_WIDTH_PLUS, DISPID_CLICK, CViewHoleRecipeSetting::ClickROIWidthUp, VTS_NONE) ON_EVENT(CViewHoleRecipeSetting, IDC_BTN_ROI_WIDTH_MINUS, DISPID_CLICK, CViewHoleRecipeSetting::ClickROIWidthDown, VTS_NONE) ON_EVENT(CViewHoleRecipeSetting, IDC_BTN_ROI_HEIGHT_PLUS, DISPID_CLICK, CViewHoleRecipeSetting::ClickROIHeightUp, VTS_NONE) ON_EVENT(CViewHoleRecipeSetting, IDC_BTN_ROI_HEIGHT_MINUS, DISPID_CLICK, CViewHoleRecipeSetting::ClickROIHeightDown, VTS_NONE) ON_EVENT(CViewHoleRecipeSetting, IDC_BTN_CIRCLE_UP, DISPID_CLICK, CViewHoleRecipeSetting::ClickCircleUp, VTS_NONE) ON_EVENT(CViewHoleRecipeSetting, IDC_BTN_CIRCLE_LEFT, DISPID_CLICK, CViewHoleRecipeSetting::ClickCircleLeft, VTS_NONE) ON_EVENT(CViewHoleRecipeSetting, IDC_BTN_CIRCLE_RIGHT, DISPID_CLICK, CViewHoleRecipeSetting::ClickCircleRight, VTS_NONE) ON_EVENT(CViewHoleRecipeSetting, IDC_BTN_CIRCLE_DN, DISPID_CLICK, CViewHoleRecipeSetting::ClickCircleDown, VTS_NONE) ON_EVENT(CViewHoleRecipeSetting, IDC_BTN_CIRCLE_WIDTH_PLUS, DISPID_CLICK, CViewHoleRecipeSetting::ClickCircleWidthUp, VTS_NONE) ON_EVENT(CViewHoleRecipeSetting, IDC_BTN_CIRCLE_WIDTH_MINUS, DISPID_CLICK, CViewHoleRecipeSetting::ClickCircleWidthDown, VTS_NONE) ON_EVENT(CViewHoleRecipeSetting, IDC_BTN_CIRCLE_HEIGHT_PLUS, DISPID_CLICK, CViewHoleRecipeSetting::ClickCircleHeightUp, VTS_NONE) ON_EVENT(CViewHoleRecipeSetting, IDC_BTN_CIRCLE_HEIGHT_MINUS, DISPID_CLICK, CViewHoleRecipeSetting::ClickCircleHeightDown, VTS_NONE) ON_EVENT(CViewHoleRecipeSetting, IDC_UPDATE, DISPID_CLICK, CViewHoleRecipeSetting::ClickUpdate, VTS_NONE) ON_EVENT(CViewHoleRecipeSetting, IDC_ADD_AREA, DISPID_CLICK, CViewHoleRecipeSetting::ClickAdd, VTS_NONE) ON_EVENT(CViewHoleRecipeSetting, IDC_DEL_AREA, DISPID_CLICK, CViewHoleRecipeSetting::ClickDelete, VTS_NONE) ON_EVENT(CViewHoleRecipeSetting, IDC_SAVE, DISPID_CLICK, CViewHoleRecipeSetting::ClickSave, VTS_NONE) ON_EVENT(CViewHoleRecipeSetting, IDC_EXIT, DISPID_CLICK, CViewHoleRecipeSetting::ClickExit, VTS_NONE) END_EVENTSINK_MAP() // CViewHoleRecipeSetting ¸Þ½ÃÁö 󸮱âÀÔ´Ï´Ù. BOOL CViewHoleRecipeSetting::OnInitDialog() { CDialog::OnInitDialog(); // TODO: ¿©±â¿¡ Ãß°¡ ÃʱâÈ­ ÀÛ¾÷À» Ãß°¡ÇÕ´Ï´Ù. InitHoleList(); CRect rect; GetDlgItem(IDC_STATIC_TEMPLATE_DISPLAY)->GetWindowRect(rect); ScreenToClient(rect); m_ImageView.Create(NULL, NULL, WS_CHILD | WS_VISIBLE | WM_NOTIFY , rect, this, 0); m_ImageView.ShowWindow(SW_SHOW); CString strControlStep = _T("20"); SetDlgItemText(IDC_EDIT_CONTROL_STEP, strControlStep); UpdateData(TRUE); return TRUE; } BOOL CViewHoleRecipeSetting::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 CDialog::PreTranslateMessage(pMsg); } void CViewHoleRecipeSetting::SaveTempleteImage(int nIdx) { if(m_pDlgRecipe == NULL) return; CHOLEINSPECT_PARM* pHoleParm = &m_pDlgRecipe->m_HoleInspectParm; if(nIdx < 0|| pHoleParm->m_vecHoleInsParam.size() <= nIdx) return; if(m_DisplayOrigin.GetImageExist() == FALSE) return; CString strRecipeName = m_pDlgRecipe->GetRecipeName(); strRecipeName = (strRecipeName.GetLength() == 0) ? _T("Test_Recipe") : strRecipeName; CString strDirPath; strDirPath.Format(_T("%s\\%s"), RECIPE_HOLE_TEMPLATE_PATH, strRecipeName); CreateDirectory(strDirPath, NULL); CString strFilePath; CTime currentTime = CTime::GetCurrentTime(); strFilePath.Format(_T("%s\\%04d%02d%02d_%02d%02d%02d.bmp"), strDirPath , currentTime.GetYear() , currentTime.GetMonth() , currentTime.GetDay() , currentTime.GetHour() , currentTime.GetMinute() , currentTime.GetSecond()); m_DisplayOrigin.SaveImage(strFilePath, 100); pHoleParm->m_vecHoleInsParam[nIdx].m_strTemplatePath = strFilePath; UpdateRecipeToHoleList(); } void CViewHoleRecipeSetting::ClickHoleInspectProcess() { if(m_pInterface == NULL) return; CCellID FocusedID = m_HoleList.GetFocusCell(); int nIdx = FocusedID.row-1; CHOLEINSPECT_PARM* pHoleParm = &m_pDlgRecipe->m_HoleInspectParm; if(nIdx < 0|| pHoleParm->m_vecHoleInsParam.size() <= nIdx) return; if(pHoleParm->m_vecHoleInsParam[nIdx].m_nSideIdx != m_pInterface->IHoleRecipe2RecipeView_GetCurrentSetSide()) { AfxMessageBox(_T("Please, Check Recipe Set Side..")); return; } IplImage* pViewImage = NULL; m_pInterface->IHoleRecipe2RecipeVIew_HoleInspectProcess(nIdx, &pViewImage); if(pViewImage != NULL) { m_ImageView.CopyImageFrom(pViewImage); m_ImageView.Invalidate(); cvReleaseImage(&pViewImage); } } void CViewHoleRecipeSetting::ClickViewMode() { if(m_ImageView.GetViewType() == ViewScale_Origin) m_ImageView.SetViewType(ViewScale_Fit); else m_ImageView.SetViewType(ViewScale_Origin); m_ImageView.Invalidate(); } void CViewHoleRecipeSetting::ClickROIUp() { if(m_pDlgRecipe == NULL || m_pInterface == NULL) return; CCellID FocusedID = m_HoleList.GetFocusCell(); int nIdx = FocusedID.row-1; CHOLEINSPECT_PARM* pHoleParm = &m_pDlgRecipe->m_HoleInspectParm; if(nIdx < 0|| pHoleParm->m_vecHoleInsParam.size() <= nIdx) return; if(pHoleParm->m_vecHoleInsParam[nIdx].m_nSideIdx != m_pInterface->IHoleRecipe2RecipeView_GetCurrentSetSide()) { AfxMessageBox(_T("Please, Check Recipe Set Side..")); return; } UpdateData(FALSE); CString strControlStep = _T("1"); GetDlgItemText(IDC_EDIT_CONTROL_STEP, strControlStep); int nStep = _wtoi(strControlStep); pHoleParm->m_vecHoleInsParam[nIdx].m_rtArea.OffsetRect(0, nStep * -1); if(m_pInterface != NULL) m_pInterface->IHoleRecipe2RecipeView_UpdateFrameView(); UpdateRecipeToHoleList(); } void CViewHoleRecipeSetting::ClickROILeft() { if(m_pDlgRecipe == NULL || m_pInterface == NULL) return; CCellID FocusedID = m_HoleList.GetFocusCell(); int nIdx = FocusedID.row-1; CHOLEINSPECT_PARM* pHoleParm = &m_pDlgRecipe->m_HoleInspectParm; if(nIdx < 0|| pHoleParm->m_vecHoleInsParam.size() <= nIdx) return; if(pHoleParm->m_vecHoleInsParam[nIdx].m_nSideIdx != m_pInterface->IHoleRecipe2RecipeView_GetCurrentSetSide()) { AfxMessageBox(_T("Please, Check Recipe Set Side..")); return; } UpdateData(FALSE); CString strControlStep = _T("1"); GetDlgItemText(IDC_EDIT_CONTROL_STEP, strControlStep); int nStep = _wtoi(strControlStep); pHoleParm->m_vecHoleInsParam[nIdx].m_rtArea.OffsetRect(nStep * -1, 0); if(m_pInterface != NULL) m_pInterface->IHoleRecipe2RecipeView_UpdateFrameView(); UpdateRecipeToHoleList(); } void CViewHoleRecipeSetting::ClickROIRight() { if(m_pDlgRecipe == NULL || m_pInterface == NULL) return; CCellID FocusedID = m_HoleList.GetFocusCell(); int nIdx = FocusedID.row-1; CHOLEINSPECT_PARM* pHoleParm = &m_pDlgRecipe->m_HoleInspectParm; if(nIdx < 0|| pHoleParm->m_vecHoleInsParam.size() <= nIdx) return; if(pHoleParm->m_vecHoleInsParam[nIdx].m_nSideIdx != m_pInterface->IHoleRecipe2RecipeView_GetCurrentSetSide()) { AfxMessageBox(_T("Please, Check Recipe Set Side..")); return; } UpdateData(FALSE); CString strControlStep = _T("1"); GetDlgItemText(IDC_EDIT_CONTROL_STEP, strControlStep); int nStep = _wtoi(strControlStep); pHoleParm->m_vecHoleInsParam[nIdx].m_rtArea.OffsetRect(nStep, 0); if(m_pInterface != NULL) m_pInterface->IHoleRecipe2RecipeView_UpdateFrameView(); UpdateRecipeToHoleList(); } void CViewHoleRecipeSetting::ClickROIDown() { if(m_pDlgRecipe == NULL || m_pInterface == NULL) return; CCellID FocusedID = m_HoleList.GetFocusCell(); int nIdx = FocusedID.row-1; CHOLEINSPECT_PARM* pHoleParm = &m_pDlgRecipe->m_HoleInspectParm; if(nIdx < 0|| pHoleParm->m_vecHoleInsParam.size() <= nIdx) return; if(pHoleParm->m_vecHoleInsParam[nIdx].m_nSideIdx != m_pInterface->IHoleRecipe2RecipeView_GetCurrentSetSide()) { AfxMessageBox(_T("Please, Check Recipe Set Side..")); return; } UpdateData(FALSE); CString strControlStep = _T("1"); GetDlgItemText(IDC_EDIT_CONTROL_STEP, strControlStep); int nStep = _wtoi(strControlStep); pHoleParm->m_vecHoleInsParam[nIdx].m_rtArea.OffsetRect(0, nStep); if(m_pInterface != NULL) m_pInterface->IHoleRecipe2RecipeView_UpdateFrameView(); UpdateRecipeToHoleList(); } void CViewHoleRecipeSetting::ClickROIWidthUp() { if(m_pDlgRecipe == NULL || m_pInterface == NULL) return; CCellID FocusedID = m_HoleList.GetFocusCell(); int nIdx = FocusedID.row-1; CHOLEINSPECT_PARM* pHoleParm = &m_pDlgRecipe->m_HoleInspectParm; if(nIdx < 0|| pHoleParm->m_vecHoleInsParam.size() <= nIdx) return; if(pHoleParm->m_vecHoleInsParam[nIdx].m_nSideIdx != m_pInterface->IHoleRecipe2RecipeView_GetCurrentSetSide()) { AfxMessageBox(_T("Please, Check Recipe Set Side..")); return; } UpdateData(FALSE); CString strControlStep = _T("1"); GetDlgItemText(IDC_EDIT_CONTROL_STEP, strControlStep); int nStep = _wtoi(strControlStep); pHoleParm->m_vecHoleInsParam[nIdx].m_rtArea.right += nStep; if(m_pInterface != NULL) m_pInterface->IHoleRecipe2RecipeView_UpdateFrameView(); UpdateRecipeToHoleList(); } void CViewHoleRecipeSetting::ClickROIWidthDown() { if(m_pDlgRecipe == NULL || m_pInterface == NULL) return; CCellID FocusedID = m_HoleList.GetFocusCell(); int nIdx = FocusedID.row-1; CHOLEINSPECT_PARM* pHoleParm = &m_pDlgRecipe->m_HoleInspectParm; if(nIdx < 0|| pHoleParm->m_vecHoleInsParam.size() <= nIdx) return; if(pHoleParm->m_vecHoleInsParam[nIdx].m_nSideIdx != m_pInterface->IHoleRecipe2RecipeView_GetCurrentSetSide()) { AfxMessageBox(_T("Please, Check Recipe Set Side..")); return; } UpdateData(FALSE); CString strControlStep = _T("1"); GetDlgItemText(IDC_EDIT_CONTROL_STEP, strControlStep); int nStep = _wtoi(strControlStep); if(pHoleParm->m_vecHoleInsParam[nIdx].m_rtArea.left < pHoleParm->m_vecHoleInsParam[nIdx].m_rtArea.right - nStep) pHoleParm->m_vecHoleInsParam[nIdx].m_rtArea.right -= nStep; if(m_pInterface != NULL) m_pInterface->IHoleRecipe2RecipeView_UpdateFrameView(); UpdateRecipeToHoleList(); } void CViewHoleRecipeSetting::ClickROIHeightUp() { if(m_pDlgRecipe == NULL || m_pInterface == NULL) return; CCellID FocusedID = m_HoleList.GetFocusCell(); int nIdx = FocusedID.row-1; CHOLEINSPECT_PARM* pHoleParm = &m_pDlgRecipe->m_HoleInspectParm; if(nIdx < 0|| pHoleParm->m_vecHoleInsParam.size() <= nIdx) return; if(pHoleParm->m_vecHoleInsParam[nIdx].m_nSideIdx != m_pInterface->IHoleRecipe2RecipeView_GetCurrentSetSide()) { AfxMessageBox(_T("Please, Check Recipe Set Side..")); return; } UpdateData(FALSE); CString strControlStep = _T("1"); GetDlgItemText(IDC_EDIT_CONTROL_STEP, strControlStep); int nStep = _wtoi(strControlStep); pHoleParm->m_vecHoleInsParam[nIdx].m_rtArea.bottom += nStep; if(m_pInterface != NULL) m_pInterface->IHoleRecipe2RecipeView_UpdateFrameView(); UpdateRecipeToHoleList(); } void CViewHoleRecipeSetting::ClickROIHeightDown() { if(m_pDlgRecipe == NULL || m_pInterface == NULL) return; CCellID FocusedID = m_HoleList.GetFocusCell(); int nIdx = FocusedID.row-1; CHOLEINSPECT_PARM* pHoleParm = &m_pDlgRecipe->m_HoleInspectParm; if(nIdx < 0|| pHoleParm->m_vecHoleInsParam.size() <= nIdx) return; if(pHoleParm->m_vecHoleInsParam[nIdx].m_nSideIdx != m_pInterface->IHoleRecipe2RecipeView_GetCurrentSetSide()) { AfxMessageBox(_T("Please, Check Recipe Set Side..")); return; } UpdateData(FALSE); CString strControlStep = _T("1"); GetDlgItemText(IDC_EDIT_CONTROL_STEP, strControlStep); int nStep = _wtoi(strControlStep); if(pHoleParm->m_vecHoleInsParam[nIdx].m_rtArea.top < pHoleParm->m_vecHoleInsParam[nIdx].m_rtArea.bottom - nStep) pHoleParm->m_vecHoleInsParam[nIdx].m_rtArea.bottom -= nStep; if(m_pInterface != NULL) m_pInterface->IHoleRecipe2RecipeView_UpdateFrameView(); UpdateRecipeToHoleList(); } void CViewHoleRecipeSetting::ClickCircleUp() { if(m_pDlgRecipe == NULL) return; CCellID FocusedID = m_HoleList.GetFocusCell(); int nIdx = FocusedID.row-1; CHOLEINSPECT_PARM* pHoleParm = &m_pDlgRecipe->m_HoleInspectParm; if(nIdx < 0|| pHoleParm->m_vecHoleInsParam.size() <= nIdx) return; UpdateData(FALSE); CString strControlStep = _T("1"); GetDlgItemText(IDC_EDIT_CONTROL_STEP, strControlStep); int nStep = _wtoi(strControlStep); pHoleParm->m_vecHoleInsParam[nIdx].m_rtHoleArea.OffsetRect(0, nStep * -1); UpdateRecipeToHoleList(); UpdateHoleImage(nIdx); } void CViewHoleRecipeSetting::ClickCircleLeft() { if(m_pDlgRecipe == NULL) return; CCellID FocusedID = m_HoleList.GetFocusCell(); int nIdx = FocusedID.row-1; CHOLEINSPECT_PARM* pHoleParm = &m_pDlgRecipe->m_HoleInspectParm; if(nIdx < 0|| pHoleParm->m_vecHoleInsParam.size() <= nIdx) return; UpdateData(FALSE); CString strControlStep = _T("1"); GetDlgItemText(IDC_EDIT_CONTROL_STEP, strControlStep); int nStep = _wtoi(strControlStep); pHoleParm->m_vecHoleInsParam[nIdx].m_rtHoleArea.OffsetRect(nStep * -1, 0); UpdateRecipeToHoleList(); UpdateHoleImage(nIdx); } void CViewHoleRecipeSetting::ClickCircleRight() { if(m_pDlgRecipe == NULL) return; CCellID FocusedID = m_HoleList.GetFocusCell(); int nIdx = FocusedID.row-1; CHOLEINSPECT_PARM* pHoleParm = &m_pDlgRecipe->m_HoleInspectParm; if(nIdx < 0|| pHoleParm->m_vecHoleInsParam.size() <= nIdx) return; UpdateData(FALSE); CString strControlStep = _T("1"); GetDlgItemText(IDC_EDIT_CONTROL_STEP, strControlStep); int nStep = _wtoi(strControlStep); pHoleParm->m_vecHoleInsParam[nIdx].m_rtHoleArea.OffsetRect(nStep, 0); UpdateRecipeToHoleList(); UpdateHoleImage(nIdx); } void CViewHoleRecipeSetting::ClickCircleDown() { if(m_pDlgRecipe == NULL) return; CCellID FocusedID = m_HoleList.GetFocusCell(); int nIdx = FocusedID.row-1; CHOLEINSPECT_PARM* pHoleParm = &m_pDlgRecipe->m_HoleInspectParm; if(nIdx < 0|| pHoleParm->m_vecHoleInsParam.size() <= nIdx) return; UpdateData(FALSE); CString strControlStep = _T("1"); GetDlgItemText(IDC_EDIT_CONTROL_STEP, strControlStep); int nStep = _wtoi(strControlStep); pHoleParm->m_vecHoleInsParam[nIdx].m_rtHoleArea.OffsetRect(0, nStep); UpdateRecipeToHoleList(); UpdateHoleImage(nIdx); } void CViewHoleRecipeSetting::ClickCircleWidthUp() { if(m_pDlgRecipe == NULL) return; CCellID FocusedID = m_HoleList.GetFocusCell(); int nIdx = FocusedID.row-1; CHOLEINSPECT_PARM* pHoleParm = &m_pDlgRecipe->m_HoleInspectParm; if(nIdx < 0|| pHoleParm->m_vecHoleInsParam.size() <= nIdx) return; UpdateData(FALSE); CString strControlStep = _T("1"); GetDlgItemText(IDC_EDIT_CONTROL_STEP, strControlStep); int nStep = _wtoi(strControlStep); pHoleParm->m_vecHoleInsParam[nIdx].m_rtHoleArea.right += nStep; UpdateRecipeToHoleList(); UpdateHoleImage(nIdx); } void CViewHoleRecipeSetting::ClickCircleWidthDown() { if(m_pDlgRecipe == NULL) return; CCellID FocusedID = m_HoleList.GetFocusCell(); int nIdx = FocusedID.row-1; CHOLEINSPECT_PARM* pHoleParm = &m_pDlgRecipe->m_HoleInspectParm; if(nIdx < 0|| pHoleParm->m_vecHoleInsParam.size() <= nIdx) return; UpdateData(FALSE); CString strControlStep = _T("1"); GetDlgItemText(IDC_EDIT_CONTROL_STEP, strControlStep); int nStep = _wtoi(strControlStep); if(pHoleParm->m_vecHoleInsParam[nIdx].m_rtHoleArea.left < pHoleParm->m_vecHoleInsParam[nIdx].m_rtHoleArea.right - nStep) pHoleParm->m_vecHoleInsParam[nIdx].m_rtHoleArea.right -= nStep; UpdateRecipeToHoleList(); UpdateHoleImage(nIdx); } void CViewHoleRecipeSetting::ClickCircleHeightUp() { if(m_pDlgRecipe == NULL) return; CCellID FocusedID = m_HoleList.GetFocusCell(); int nIdx = FocusedID.row-1; CHOLEINSPECT_PARM* pHoleParm = &m_pDlgRecipe->m_HoleInspectParm; if(nIdx < 0|| pHoleParm->m_vecHoleInsParam.size() <= nIdx) return; UpdateData(FALSE); CString strControlStep = _T("1"); GetDlgItemText(IDC_EDIT_CONTROL_STEP, strControlStep); int nStep = _wtoi(strControlStep); pHoleParm->m_vecHoleInsParam[nIdx].m_rtHoleArea.bottom += nStep; UpdateRecipeToHoleList(); UpdateHoleImage(nIdx); } void CViewHoleRecipeSetting::ClickCircleHeightDown() { if(m_pDlgRecipe == NULL) return; CCellID FocusedID = m_HoleList.GetFocusCell(); int nIdx = FocusedID.row-1; CHOLEINSPECT_PARM* pHoleParm = &m_pDlgRecipe->m_HoleInspectParm; if(nIdx < 0|| pHoleParm->m_vecHoleInsParam.size() <= nIdx) return; UpdateData(FALSE); CString strControlStep = _T("1"); GetDlgItemText(IDC_EDIT_CONTROL_STEP, strControlStep); int nStep = _wtoi(strControlStep); if(pHoleParm->m_vecHoleInsParam[nIdx].m_rtHoleArea.top < pHoleParm->m_vecHoleInsParam[nIdx].m_rtHoleArea.bottom - nStep) pHoleParm->m_vecHoleInsParam[nIdx].m_rtHoleArea.bottom -= nStep; UpdateRecipeToHoleList(); UpdateHoleImage(nIdx); } void CViewHoleRecipeSetting::ClickUpdate() { if(m_pInterface == NULL) return; CCellID FocusedID = m_HoleList.GetFocusCell(); int nIdx = FocusedID.row-1; CHOLEINSPECT_PARM* pHoleParm = &m_pDlgRecipe->m_HoleInspectParm; if(nIdx < 0 || pHoleParm->m_vecHoleInsParam.size() <= nIdx) return; if(pHoleParm->m_vecHoleInsParam[nIdx].m_strTemplatePath.GetLength() != 0) { if(IDYES != AfxMessageBox(_T("There is an registered image, Change Image?"), MB_YESNO | MB_ICONQUESTION)) return; DeleteFile(pHoleParm->m_vecHoleInsParam[nIdx].m_strTemplatePath); } IplImage* pImageBuffer = NULL; if(m_pInterface->IHoleRecipe2RecipeView_GetHoleAreaImage(nIdx, &pImageBuffer) == FALSE) return; pHoleParm->m_vecHoleInsParam[nIdx].m_rtHoleArea.left=0; pHoleParm->m_vecHoleInsParam[nIdx].m_rtHoleArea.top=0; pHoleParm->m_vecHoleInsParam[nIdx].m_rtHoleArea.right=pImageBuffer->width; pHoleParm->m_vecHoleInsParam[nIdx].m_rtHoleArea.bottom=pImageBuffer->height; m_DisplayOrigin.CopyImageFrom(pImageBuffer); // Regist TemplateImage SaveTempleteImage(nIdx); cvReleaseImage(&pImageBuffer); UpdateRecipeToHoleList(); UpdateHoleImage(nIdx); } void CViewHoleRecipeSetting::ClickAdd() { if(m_pInterface == NULL) return; int nSideIdx; CRect rtArea; BOOL bRet = m_pInterface->IHoleRecipe2RecipeView_AddHoleArea(nSideIdx, rtArea); if(bRet == FALSE) return; HOLE_INS_PARM newHoleParm; newHoleParm.m_nSideIdx = nSideIdx; newHoleParm.m_rtArea = newHoleParm.m_rtHoleArea = rtArea; newHoleParm.m_nThreshold = 30; newHoleParm.m_nOffset = 5; newHoleParm.m_nMinSize = 3; newHoleParm.m_dMatRate = 85.0; newHoleParm.m_strTemplatePath = _T(""); m_pDlgRecipe->m_HoleInspectParm.m_vecHoleInsParam.push_back(newHoleParm); m_pDlgRecipe->m_HoleInspectParm.m_nTotalHoleCount = (int)m_pDlgRecipe->m_HoleInspectParm.m_vecHoleInsParam.size(); UpdateRecipeToHoleList(); m_pInterface->IHoleRecipe2RecipeView_UpdateFrameView(); m_HoleList.SetFocusCell((int) m_pDlgRecipe->m_HoleInspectParm.m_vecHoleInsParam.size(), 0); } void CViewHoleRecipeSetting::ClickDelete() { if(m_pInterface == NULL) return; CCellID FocusedID = m_HoleList.GetFocusCell(); int nIdx = FocusedID.row-1; CHOLEINSPECT_PARM* pHoleParm = &m_pDlgRecipe->m_HoleInspectParm; if(nIdx < 0 || pHoleParm->m_vecHoleInsParam.size() <= nIdx) return; CString strTemp; strTemp.Format(_T("Delete Hole Inspect Area [%d]?"), nIdx+1); if(IDYES != AfxMessageBox(strTemp, MB_YESNO | MB_ICONQUESTION)) return; if(pHoleParm->m_vecHoleInsParam[nIdx].m_strTemplatePath.GetLength() != 0) DeleteFile(pHoleParm->m_vecHoleInsParam[nIdx].m_strTemplatePath); vector newVector; for(int i=0; i<(int) pHoleParm->m_vecHoleInsParam.size(); i++) { if(i == nIdx) continue; newVector.push_back(pHoleParm->m_vecHoleInsParam[i]); } pHoleParm->m_vecHoleInsParam.clear(); pHoleParm->m_vecHoleInsParam = newVector; pHoleParm->m_nTotalHoleCount = (int) pHoleParm->m_vecHoleInsParam.size(); newVector.clear(); UpdateRecipeToHoleList(); } void CViewHoleRecipeSetting::ClickSave() { UpdateHoleListToRecipe(); if(m_pInterface != NULL) m_pInterface->IHoleRecipe2RecipeView_SaveRecipe(); } void CViewHoleRecipeSetting::ClickExit() { ShowWindow(SW_HIDE); } void CViewHoleRecipeSetting::SetInterface(IHoleRecipeView2Parent* pInterface) { m_pInterface = pInterface; } void CViewHoleRecipeSetting::SetRecipe(CGlassRecipe* pRecipe) { if(pRecipe == NULL) return; m_pDlgRecipe = pRecipe; UpdateRecipeToHoleList(); UpdateHoleImage(-1); } void CViewHoleRecipeSetting::InitHoleList() { if(m_HoleList.GetSafeHwnd() == NULL) return; m_HoleList.GetDefaultCell(TRUE, FALSE)->SetBackClr(GRID_FIX_COLOR); m_HoleList.GetDefaultCell(FALSE, TRUE)->SetBackClr(GRID_FIX_COLOR); m_HoleList.GetDefaultCell(FALSE, FALSE)->SetBackClr(GRID_COLOR); m_HoleList.SetFixedBkColor(GRID_FIX_COLOR); m_HoleList.SetGridLines(GVL_BOTH); m_HoleList.SetColumnCount(HOLE_INSPECT_COLUMN_COUNT); m_HoleList.SetRowCount(1); m_HoleList.SetFixedRowCount(1); m_HoleList.SetFixedColumnCount(0); m_HoleList.ExpandColumnsToFit(); m_HoleList.SetSingleRowSelection(TRUE); m_HoleList.SetSingleColSelection(TRUE); CFont *pFont = m_HoleList.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_HoleList.GetDefaultCell(TRUE, FALSE)->SetFont(&lf); m_HoleList.GetDefaultCell(FALSE, TRUE)->SetFont(&lf); m_HoleList.GetDefaultCell(TRUE, TRUE)->SetFont(&lf); m_HoleList.SetEditable(TRUE); m_HoleList.EnableSelection(TRUE); CString str; GV_ITEM Item; int nCol = 0; int iLoop; Item.mask = GVIF_TEXT; Item.row = 0; for(iLoop=0;iLoopm_HoleInspectParm; m_HoleList.SetRowCount(pHoleParm->m_nTotalHoleCount + 1); CString strTemp; int nColIdx, nRowIdx; for(int i=0; im_nTotalHoleCount; i++) { if(pHoleParm->m_vecHoleInsParam.size() <= i) continue; nColIdx = 0; nRowIdx = i + 1; // 0. Index strTemp.Format(_T("%d"), nRowIdx); m_HoleList.SetItemText(nRowIdx, nColIdx++, strTemp); // 1. Side m_HoleList.SetItemText(nRowIdx, nColIdx++, m_vecSide[pHoleParm->m_vecHoleInsParam[i].m_nSideIdx]); // 2. ROI L/T strTemp.Format(_T("%d, %d"), (int) pHoleParm->m_vecHoleInsParam[i].m_rtArea.left, (int) pHoleParm->m_vecHoleInsParam[i].m_rtArea.top); m_HoleList.SetItemText(nRowIdx, nColIdx++, strTemp); // 3. ROI R/B strTemp.Format(_T("%d, %d"), (int) pHoleParm->m_vecHoleInsParam[i].m_rtArea.right, (int) pHoleParm->m_vecHoleInsParam[i].m_rtArea.bottom); m_HoleList.SetItemText(nRowIdx, nColIdx++, strTemp); // 4. Circle L/T strTemp.Format(_T("%d, %d"), (int) pHoleParm->m_vecHoleInsParam[i].m_rtHoleArea.left, (int) pHoleParm->m_vecHoleInsParam[i].m_rtHoleArea.top); m_HoleList.SetItemText(nRowIdx, nColIdx++, strTemp); // 5. Circle R/B strTemp.Format(_T("%d, %d"), (int) pHoleParm->m_vecHoleInsParam[i].m_rtHoleArea.right, (int) pHoleParm->m_vecHoleInsParam[i].m_rtHoleArea.bottom); m_HoleList.SetItemText(nRowIdx, nColIdx++, strTemp); // 6. Threshold strTemp.Format(_T("%d"), (int) pHoleParm->m_vecHoleInsParam[i].m_nThreshold); m_HoleList.SetItemText(nRowIdx, nColIdx++, strTemp); // 7. Offset strTemp.Format(_T("%d"), (int) pHoleParm->m_vecHoleInsParam[i].m_nOffset); m_HoleList.SetItemText(nRowIdx, nColIdx++, strTemp); // 8. MinSize strTemp.Format(_T("%d"), (int) pHoleParm->m_vecHoleInsParam[i].m_nMinSize); m_HoleList.SetItemText(nRowIdx, nColIdx++, strTemp); // 9. MatRate strTemp.Format(_T("%.2f"), pHoleParm->m_vecHoleInsParam[i].m_dMatRate); m_HoleList.SetItemText(nRowIdx, nColIdx++, strTemp); // 10. Image Path m_HoleList.SetItemText(nRowIdx, nColIdx++, pHoleParm->m_vecHoleInsParam[i].m_strTemplatePath); } m_HoleList.Invalidate(); } void CViewHoleRecipeSetting::UpdateHoleListToRecipe() { if(m_pDlgRecipe == NULL) return; CHOLEINSPECT_PARM* pHoleParm = &m_pDlgRecipe->m_HoleInspectParm; int nRowCount = m_HoleList.GetRowCount() - 1; int nColIdx = 0; CString strTemp; int nHoleIdx = 0; for(int i=0; im_vecHoleInsParam.size() <= i) continue; nColIdx = 6; // 6. Threshold strTemp = m_HoleList.GetItemText(i+1, nColIdx++); pHoleParm->m_vecHoleInsParam[nHoleIdx].m_nThreshold = _wtoi(strTemp); // 7. Offset strTemp = m_HoleList.GetItemText(i+1, nColIdx++); pHoleParm->m_vecHoleInsParam[nHoleIdx].m_nOffset = _wtoi(strTemp); // 8. MinSize strTemp = m_HoleList.GetItemText(i+1, nColIdx++); pHoleParm->m_vecHoleInsParam[nHoleIdx].m_nMinSize = _wtoi(strTemp); // 9. MatRate strTemp = m_HoleList.GetItemText(i+1, nColIdx++); pHoleParm->m_vecHoleInsParam[nHoleIdx].m_dMatRate = _wtof(strTemp); nHoleIdx++; } pHoleParm->m_nTotalHoleCount = (int) pHoleParm->m_vecHoleInsParam.size(); } void CViewHoleRecipeSetting::UpdateHoleImage(int nIdx) { if(nIdx == -1) { m_ImageView.ClearImage(0); m_ImageView.Invalidate(); return; } if(m_pInterface == NULL) return; CHOLEINSPECT_PARM* pHoleParm = &m_pDlgRecipe->m_HoleInspectParm; if(nIdx < 0|| pHoleParm->m_vecHoleInsParam.size() <= nIdx) return; if(m_DisplayOrigin.GetImageExist() == FALSE) return; IplImage* pViewImage = cvCreateImage(cvSize(m_DisplayOrigin.GetWidth(), m_DisplayOrigin.GetHeight()), 8, 3); cvCvtColor(m_DisplayOrigin.GetIplImage(), pViewImage, CV_GRAY2BGR); CRect* pRtHole = &pHoleParm->m_vecHoleInsParam[nIdx].m_rtHoleArea; int nOffset = pHoleParm->m_vecHoleInsParam[nIdx].m_nOffset; cvEllipse(pViewImage, cvPoint(pRtHole->CenterPoint().x, pRtHole->CenterPoint().y), cvSize(pRtHole->Width()/2, pRtHole->Height()/2), 0.0, 0.0, 360.0, cvScalar(255,255,0), 1); cvEllipse(pViewImage, cvPoint(pRtHole->CenterPoint().x, pRtHole->CenterPoint().y), cvSize((pRtHole->Width()/2)-nOffset, (pRtHole->Height()/2)-nOffset), 0, 0.0, 360.0, cvScalar(0,255,255), 1); m_ImageView.CopyImageFrom(pViewImage); cvReleaseImage(&pViewImage); m_ImageView.Invalidate(); } void CViewHoleRecipeSetting::OnHoleListEditEnd(NMHDR *pNotifyStruct, LRESULT* pResult) { UpdateHoleListToRecipe(); UpdateRecipeToHoleList(); CCellID FocusedID = m_HoleList.GetFocusCell(); int nIdx = FocusedID.row-1; CHOLEINSPECT_PARM* pHoleParm = &m_pDlgRecipe->m_HoleInspectParm; if(nIdx < 0|| pHoleParm->m_vecHoleInsParam.size() <= nIdx) return; UpdateHoleImage(nIdx); } void CViewHoleRecipeSetting::OnHoleListClick(NMHDR *pNotifyStruct, LRESULT* pResult) { if(m_pDlgRecipe == NULL) return; CCellID FocusedID = m_HoleList.GetFocusCell(); int nIdx = FocusedID.row - 1; CHOLEINSPECT_PARM* pHoleParm = &m_pDlgRecipe->m_HoleInspectParm; if(nIdx < 0|| pHoleParm->m_vecHoleInsParam.size() <= nIdx) return; m_DisplayOrigin.LoadImage(pHoleParm->m_vecHoleInsParam[nIdx].m_strTemplatePath); UpdateHoleImage(nIdx); }