// HoleSetDlg.cpp : ʵÏÖÎļþ // #include "stdafx.h" #include "BlVisionPro.h" #include "HoleSetDlg.h" #include "afxdialogex.h" #include "VisionRecipe.h" #include "VisionSetDlg.h" #include "VisionBufferPro.h" #include "SoftVisionApp.h" // CHoleSetDlg ¶Ô»°¿ò IMPLEMENT_DYNAMIC(CHoleSetDlg, CDialogEx) CHoleSetDlg::CHoleSetDlg(CWnd* pParent /*=NULL*/) : CDialogEx(IDD_DIALOG_HOLE_INSPECT, pParent) { m_dot = NULL; m_eDir = DIMENSION_NONE; m_display = NULL; } CHoleSetDlg::~CHoleSetDlg() { } void CHoleSetDlg::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); DDX_Control(pDX, IDC_PANEL_HOLE_INFO, m_PanelHole); } BEGIN_MESSAGE_MAP(CHoleSetDlg, CDialogEx) ON_WM_DESTROY() ON_BN_CLICKED(IDC_BUTTON_HOLE_PROCESS, &CHoleSetDlg::OnBnClickedButtonHoleProcess) ON_BN_CLICKED(IDC_BUTTON_HOLE_SAVE, &CHoleSetDlg::OnBnClickedButtonHoleSave) ON_BN_CLICKED(IDC_BUTTON_HOLE_UP_IMAGE, &CHoleSetDlg::OnBnClickedButtonHoleUpImage) ON_BN_CLICKED(IDC_BUTTON_HOLE_CHANGE_SHOW, &CHoleSetDlg::OnBnClickedButtonHoleChangeShow) ON_BN_CLICKED(IDC_BUTTON_HOLE_DEL_IMAGE, &CHoleSetDlg::OnBnClickedButtonHoleDelImage) END_MESSAGE_MAP() // CHoleSetDlg ÏûÏ¢´¦Àí³ÌÐò void CHoleSetDlg::OnDestroy() { CDialogEx::OnDestroy(); // TODO: ÔÚ´Ë´¦Ìí¼ÓÏûÏ¢´¦Àí³ÌÐò´úÂë if (nullptr != m_display) { m_display->CloseWindow(); ClsDisplay_Free(m_display); m_display = nullptr; } } BOOL CHoleSetDlg::OnInitDialog() { CDialogEx::OnInitDialog(); // TODO: ÔÚ´ËÌí¼Ó¶îÍâµÄ³õʼ»¯ InitPanel(); InitDisplay(); return TRUE; // return TRUE unless you set the focus to a control // Òì³£: OCX ÊôÐÔÒ³Ó¦·µ»Ø FALSE } BOOL CHoleSetDlg::PreTranslateMessage(MSG* pMsg) { // TODO: ÔÚ´ËÌí¼ÓרÓôúÂëºÍ/»òµ÷ÓûùÀà if (pMsg->message == WM_KEYDOWN) { if ((pMsg->wParam == VK_RETURN) || (pMsg->wParam == VK_ESCAPE)) { return TRUE; } } return CDialogEx::PreTranslateMessage(pMsg); } void CHoleSetDlg::InitDisplay(void) { /* code */ m_display = ClsDisplay_Create(); if (nullptr != m_display) { CRect rect; CWnd* pDispWnd = GetDlgItem(IDC_STATIC_HOLE_IMG); pDispWnd->GetWindowRect(rect); m_display->OpenWindow((__int64)pDispWnd->m_hWnd, rect.Width(), rect.Height()); m_display->SetOperFlag(DEFAULT_OPER_FLAG); m_display->SetDraw("fill", DISP_OBJECT); m_display->SetColor("red", DISP_OBJECT); m_display->SetDraw("margin", DISP_REGION); std::string color = ClsVision::Rgb2Color(0, 255, 0); m_display->SetColor(color, DISP_REGION); m_display->SetDraw("margin", DISP_CROSS); color = ClsVision::Rgb2Color(255, 0, 0); m_display->SetColor(color, DISP_CROSS); m_display->SetDraw("fill", DISP_SELECT); m_display->SetColor("yellow", DISP_SELECT); color = ClsVision::Rgb2Color(0, 0, 100); m_display->SetBackgroundColor(color); } } int CHoleSetDlg::setDimensionDir(DimensionDir eDir) { /* code */ ChangeVisionType(eDir); return 0; } void CHoleSetDlg::ChangeVisionType(DimensionDir eDir) { /* code */ SaveHoleParam(); m_eDir = eDir; m_dot = CVisionRecipe::getInstance()->getHoleProcess(m_eDir); ShowHoleParam(); } void CHoleSetDlg::ShowHoleParam(void) { /* code */ if (DIMENSION_NONE == m_eDir) return; if (NULL == m_dot) return; CString strText; for (int i = 0; i < 4; i++) { CHoleDotProcess* dot = m_dot->m_dots[i]; if (NULL == dot) continue; //1. ID int idRow = dot->GetID(); int idx = 0; strText.Format(_T("%d"), dot->GetID()); m_PanelHole.SetItemText(idRow, idx, strText); idx += 1; //2. Name strText = dot->m_strName; m_PanelHole.SetItemText(idRow, idx, strText); idx += 1; //3. USE strText.Format(_T("%d"), dot->m_nUse); m_PanelHole.SetItemText(idRow, idx, strText); idx += 1; //4. Pos Type strText.Format(_T("%d"), dot->m_nPoseType); m_PanelHole.SetItemText(idRow, idx, strText); idx += 1; //5. Shape Type strText.Format(_T("%d"), dot->m_nShapeType); m_PanelHole.SetItemText(idRow, idx, strText); idx += 1; //6. Bright Type strText.Format(_T("%d"), dot->m_nBrightType); m_PanelHole.SetItemText(idRow, idx, strText); idx += 1; //7. Thres strText.Format(_T("%d"), dot->m_nThres); m_PanelHole.SetItemText(idRow, idx, strText); idx += 1; //8. Smooth Size strText.Format(_T("%d"), dot->m_nSmoothSize); m_PanelHole.SetItemText(idRow, idx, strText); idx += 1; //9. Defect Size strText.Format(_T("%d"), dot->m_nDefectSize); m_PanelHole.SetItemText(idRow, idx, strText); idx += 1; //10. Result int ngNum = (int)(dot->m_nNgInfo.size()); strText.Format(_T("%d"), ngNum); m_PanelHole.SetItemText(idRow, idx, strText); idx += 1; } UpdateData(FALSE); ShowHoleImage(); } void CHoleSetDlg::SaveHoleParam(void) { /* code */ if (DIMENSION_NONE == m_eDir) return; if (NULL == m_dot) return; UpdateData(TRUE); CString strText; for (int i = 0; i < 4; i++) { CHoleDotProcess* dot = m_dot->m_dots[i]; if (NULL == dot) continue; //1. ID int idRow = dot->GetID(); int idx = 0; strText = m_PanelHole.GetItemText(idRow, idx); idx += 1; //2. Name strText = m_PanelHole.GetItemText(idRow, idx); dot->m_strName = strText; idx += 1; //3. Use strText = m_PanelHole.GetItemText(idRow, idx); dot->m_nUse = _wtoi(strText); idx += 1; //4.Pos Type strText = m_PanelHole.GetItemText(idRow, idx); dot->m_nPoseType = _wtoi(strText); idx += 1; //5. Shape Type strText = m_PanelHole.GetItemText(idRow, idx); dot->m_nShapeType = _wtoi(strText); idx += 1; //6. Bright Type strText = m_PanelHole.GetItemText(idRow, idx); dot->m_nBrightType = _wtoi(strText); idx += 1; //7. Thres strText = m_PanelHole.GetItemText(idRow, idx); dot->m_nThres = _wtoi(strText); idx += 1; //8. Smooth Size strText = m_PanelHole.GetItemText(idRow, idx); dot->m_nSmoothSize = _wtoi(strText); idx += 1; //9. Defect Size strText = m_PanelHole.GetItemText(idRow, idx); dot->m_nDefectSize = _wtoi(strText); idx += 1; } } void CHoleSetDlg::OnBnClickedButtonHoleProcess() { // TODO: ÔÚ´ËÌí¼Ó¿Ø¼þ֪ͨ´¦Àí³ÌÐò´úÂë if (nullptr == m_dot) return; m_dot->Execute(m_eDir); } void CHoleSetDlg::InitPanel(void) { /* code */ m_vParams.clear(); CString strText; //1. ID strText = _T("ID."); m_vParams.push_back(strText); //2. useName strText = _T("Name"); m_vParams.push_back(strText); //3. useName strText = _T("use"); m_vParams.push_back(strText); //4. Pos Type strText = _T("Pos Type"); m_vParams.push_back(strText); //5. Shape Type strText = _T("Shape Type"); m_vParams.push_back(strText); //6. Bright Type strText = _T("Bright Type"); m_vParams.push_back(strText); //7. Thres strText = _T("Thres"); m_vParams.push_back(strText); //8. Smooth strText = _T("Smooth Size"); m_vParams.push_back(strText); // 9. Defect Size strText = _T("Defect Size"); m_vParams.push_back(strText); // 10.Result strText = _T("Result"); m_vParams.push_back(strText); int nRows = 5; int nCols = (int)(m_vParams.size()); int nFixRows = 1; int nFixCols = 0; int nRowIdx = 0; int nColIdx = 0; m_PanelHole.DeleteAllItems(); m_PanelHole.SetVirtualMode(FALSE); m_PanelHole.GetDefaultCell(TRUE, FALSE)->SetBackClr(_gGridFixCellColor); m_PanelHole.GetDefaultCell(FALSE, TRUE)->SetBackClr(_gGridFixCellColor); m_PanelHole.GetDefaultCell(FALSE, FALSE)->SetBackClr(_gGridCellColor); m_PanelHole.SetFixedTextColor(_gGridFixFontColor); m_PanelHole.SetRowCount(nRows); m_PanelHole.SetColumnCount(nCols); m_PanelHole.SetFixedRowCount(nFixRows); m_PanelHole.SetFixedColumnCount(nFixCols); CFont* pFont = m_PanelHole.GetFont(); if (pFont) { LOGFONT lf; pFont->GetLogFont(&lf); lf.lfItalic = 0; lf.lfHeight = 14; lf.lfWeight = FW_BOLD; _tcscpy_s(lf.lfFaceName, _T("Malgun Gothic")); m_PanelHole.GetDefaultCell(FALSE, TRUE)->SetFont(&lf); m_PanelHole.GetDefaultCell(TRUE, FALSE)->SetFont(&lf); m_PanelHole.GetDefaultCell(FALSE, FALSE)->SetFont(&lf); m_PanelHole.GetDefaultCell(TRUE, TRUE)->SetFont(&lf); } // Col for (int i = 0; i < nCols; i++) { if (1 == i) { m_PanelHole.SetColumnWidth(nColIdx, 115); } else if (0 == i) { m_PanelHole.SetColumnWidth(nColIdx, 50); } else { m_PanelHole.SetColumnWidth(nColIdx, 75); } strText = m_vParams[i]; m_PanelHole.SetItemText(nRowIdx, nColIdx++, strText); } for (int i = 1; i < nRows; i++) { m_PanelHole.GetCell(i, 0)->SetState(GVIS_READONLY); } } void CHoleSetDlg::OnBnClickedButtonHoleSave() { // TODO: ÔÚ´ËÌí¼Ó¿Ø¼þ֪ͨ´¦Àí³ÌÐò´úÂë SaveHoleParam(); ShowHoleImage(); } void CHoleSetDlg::OnBnClickedButtonHoleUpImage() { // TODO: ÔÚ´ËÌí¼Ó¿Ø¼þ֪ͨ´¦Àí³ÌÐò´úÂë CCellID selCell = m_PanelHole.GetFocusCell(); int id = 1; if (selCell.IsValid()) { id = selCell.row; } if (id < 1 || id > 4) return; CHoleDotProcess * dot = m_dot->m_dots[id - 1]; if (nullptr == dot) return; //1. ·¢ËÍÐÅÏ¢ CSoftVisionApp::getInstance()->sendMessage(1, m_eDir); //2. »ñȡλÖÃÐÅÏ¢ int x1 = 0; int y1 = 0; int x2 = 0; int y2 = 0; if (!CVisionRecipe::getInstance()->getFrame(x1, y1, x2, y2)) return; //½ØÍ¼ HalconCpp::HObject hImage; if (!CVisionBufferPro::getImageROI(m_eDir, hImage, x1, y1, x2, y2)) return; int width = 0; int height = 0; ClsVision::GetImageSize(hImage, width, height); if (width < 1 || height < 1) return; Point2I ptCenter; ptCenter.x = (int)(1.0f * (x1 + x2) / 2 + 0.5f); ptCenter.y = (int)(1.0f * (y1 + y2) / 2 + 0.5f); Point2I ptStd, ptTop, ptBot; if (!CSoftVisionApp::getInstance()->transformToStandard(m_eDir, ptCenter, ptStd, ptTop, ptBot)) return; dot->SetPose(ptStd.x, ptStd.y); dot->SetImage(hImage); ShowHoleImage(); } void CHoleSetDlg::ShowHoleImage(void) { /* code */ if (nullptr == m_dot) return; CCellID selCell = m_PanelHole.GetFocusCell(); int id = 1; if (selCell.IsValid()) { id = selCell.row; } if (id < 1 || id > 4) return; CHoleDotProcess* dot = m_dot->m_dots[id - 1]; if (nullptr == dot) return; HalconCpp::HObject& hImage = dot->GetImage(); int width = 0; int height = 0; ClsVision::GetImageSize(hImage, width, height); if (width < 1 || height < 1) { HalconCpp::GenEmptyObj(&m_display->GetImage()); HalconCpp::GenEmptyObj(&m_display->GetRegion()); HalconCpp::GenEmptyObj(&m_display->GetCross()); m_display->ClearWindow(); m_display->DispImage(); return; } HalconCpp::HObject hRegion, hRoiRegion; int offset = dot->m_nSmoothSize; HalconCpp::GenEllipse(&hRegion, 0.5 * (height-1), 0.5 * (width-1), 0, 0.5 * width, 0.5 * height); HalconCpp::GenEllipse(&hRoiRegion, 0.5 * (height - 1), 0.5 * (width - 1), 0, 0.5 * width - offset, 0.5 * height - offset); m_display->SetRegion(hRoiRegion); m_display->SetCross(hRegion); m_display->AutoWindowSize(width, height); m_display->SetImage(hImage); m_display->DispImage(); m_display->DispCross(); m_display->DispRegion(); } void CHoleSetDlg::OnBnClickedButtonHoleChangeShow() { // TODO: ÔÚ´ËÌí¼Ó¿Ø¼þ֪ͨ´¦Àí³ÌÐò´úÂë ShowHoleImage(); } void CHoleSetDlg::OnBnClickedButtonHoleDelImage() { // TODO: ÔÚ´ËÌí¼Ó¿Ø¼þ֪ͨ´¦Àí³ÌÐò´úÂë if (nullptr == m_dot) return; CCellID selCell = m_PanelHole.GetFocusCell(); if (!selCell.IsValid()) return; int id = selCell.row; if (id < 1 || id > 4) return; CHoleDotProcess* dot = m_dot->m_dots[id - 1]; if (nullptr == dot) return; HalconCpp::HObject& hImage = dot->GetImage(); int width = 0; int height = 0; ClsVision::GetImageSize(hImage, width, height); if (width < 1 || height < 1) return; HalconCpp::HObject hNilImage; HalconCpp::GenEmptyObj(&hNilImage); dot->SetImage(hNilImage); ShowHoleImage(); }