// ThresSetDlg.cpp : ʵÏÖÎļþ // #include "stdafx.h" #include "BlVisionPro.h" #include "ThresSetDlg.h" #include "afxdialogex.h" #include "VisionRecipe.h" #include "SoftVisionApp.h" // CThresSetDlg ¶Ô»°¿ò IMPLEMENT_DYNAMIC(CThresSetDlg, CDialogEx) CThresSetDlg::CThresSetDlg(CWnd* pParent /*=NULL*/) : CDialogEx(IDD_DIALOG_THRES_SET, pParent) { m_dot = NULL; m_eDir = DIMENSION_NONE; } CThresSetDlg::~CThresSetDlg() { } void CThresSetDlg::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); DDX_Control(pDX, IDC_PANEL_THRES_INFO, m_PanelThres); } BEGIN_MESSAGE_MAP(CThresSetDlg, CDialogEx) ON_WM_DESTROY() ON_BN_CLICKED(IDC_BUTTON_THRES_SAVE, &CThresSetDlg::OnBnClickedButtonThresSave) ON_BN_CLICKED(IDC_BUTTON_THRES_ROI_SET, &CThresSetDlg::OnBnClickedButtonThresRoiSet) ON_BN_CLICKED(IDC_BUTTON_THRES_PROCESS, &CThresSetDlg::OnBnClickedButtonThresProcess) END_MESSAGE_MAP() // CThresSetDlg ÏûÏ¢´¦Àí³ÌÐò BOOL CThresSetDlg::OnInitDialog() { CDialogEx::OnInitDialog(); // TODO: ÔÚ´ËÌí¼Ó¶îÍâµÄ³õʼ»¯ InitPanel(); return TRUE; // return TRUE unless you set the focus to a control // Òì³£: OCX ÊôÐÔÒ³Ó¦·µ»Ø FALSE } BOOL CThresSetDlg::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 CThresSetDlg::OnDestroy() { CDialogEx::OnDestroy(); // TODO: ÔÚ´Ë´¦Ìí¼ÓÏûÏ¢´¦Àí³ÌÐò´úÂë } int CThresSetDlg::setDimensionDir(DimensionDir eDir) { /* code */ ChangeVisionType(eDir); return 0; } void CThresSetDlg::InitPanel(void) { /* code */ m_vParams.clear(); CString strText; //1. ID strText = _T("ID."); m_vParams.push_back(strText); //2. Name strText = _T("Name"); m_vParams.push_back(strText); //3. use strText = _T("use"); m_vParams.push_back(strText); //4. use strText = _T("Pos type"); m_vParams.push_back(strText); //5. Min Thres strText = _T("Min Thres"); m_vParams.push_back(strText); //6. Max Thres strText = _T("Max Thres"); m_vParams.push_back(strText); //7. Max Thres strText = _T("Smooth"); m_vParams.push_back(strText); //8. Pos X strText = _T("X Size(um)"); m_vParams.push_back(strText); //9. Pos Y strText = _T("Y Size(um)"); m_vParams.push_back(strText); //10.Result strText = _T("Result"); m_vParams.push_back(strText); int nRows = 13; int nCols = (int)(m_vParams.size()); int nFixRows = 1; int nFixCols = 0; int nRowIdx = 0; int nColIdx = 0; m_PanelThres.DeleteAllItems(); m_PanelThres.SetVirtualMode(FALSE); m_PanelThres.GetDefaultCell(TRUE, FALSE)->SetBackClr(_gGridFixCellColor); m_PanelThres.GetDefaultCell(FALSE, TRUE)->SetBackClr(_gGridFixCellColor); m_PanelThres.GetDefaultCell(FALSE, FALSE)->SetBackClr(_gGridCellColor); m_PanelThres.SetFixedTextColor(_gGridFixFontColor); m_PanelThres.SetRowCount(nRows); m_PanelThres.SetColumnCount(nCols); m_PanelThres.SetFixedRowCount(nFixRows); m_PanelThres.SetFixedColumnCount(nFixCols); CFont *pFont = m_PanelThres.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_PanelThres.GetDefaultCell(FALSE, TRUE)->SetFont(&lf); m_PanelThres.GetDefaultCell(TRUE, FALSE)->SetFont(&lf); m_PanelThres.GetDefaultCell(FALSE, FALSE)->SetFont(&lf); m_PanelThres.GetDefaultCell(TRUE, TRUE)->SetFont(&lf); } // Col for (int i = 0; i < nCols; i++) { if (1 == i) { m_PanelThres.SetColumnWidth(nColIdx, 115); } else { m_PanelThres.SetColumnWidth(nColIdx, 75); } strText = m_vParams[i]; m_PanelThres.SetItemText(nRowIdx, nColIdx++, strText); } for (int i = 1; i < nRows; i++) { m_PanelThres.GetCell(i, 0)->SetState(GVIS_READONLY); } } void CThresSetDlg::ChangeVisionType(DimensionDir eDir) { /* code */ SaveThresParam(); m_eDir = eDir; m_dot = CVisionRecipe::getInstance()->getThresProcess(eDir); ShowThresParam(); } void CThresSetDlg::ShowThresParam(void) { /* code */ if (DIMENSION_NONE == m_eDir) return; if (NULL == m_dot) return; CString strText; for (int i = 0; i < 12; i++) { CThresDotProcess *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_PanelThres.SetItemText(idRow, idx, strText); idx += 1; //2. Name strText = dot->m_strName; m_PanelThres.SetItemText(idRow, idx, strText); idx += 1; //3. USE strText.Format(_T("%d"), dot->m_nUse); m_PanelThres.SetItemText(idRow, idx, strText); idx += 1; //4. pose type strText.Format(_T("%d"), dot->m_poseType); m_PanelThres.SetItemText(idRow, idx, strText); idx += 1; //5. Min Thres strText.Format(_T("%d"), dot->m_minThres); m_PanelThres.SetItemText(idRow, idx, strText); idx += 1; //6. Max Thres strText.Format(_T("%d"), dot->m_maxThres); m_PanelThres.SetItemText(idRow, idx, strText); idx += 1; //7. smooth strText.Format(_T("%d"), dot->m_nSmoothSize); m_PanelThres.SetItemText(idRow, idx, strText); idx += 1; //8. Min SizeX strText.Format(_T("%d"), dot->m_minSizeX); m_PanelThres.SetItemText(idRow, idx, strText); idx += 1; //9. Min SizeY strText.Format(_T("%d"), dot->m_minSizeY); m_PanelThres.SetItemText(idRow, idx, strText); idx += 1; //10. Result strText.Format(_T("%.1f"), (int)(dot->m_nNgInfo.size())); m_PanelThres.SetItemText(idRow, idx, strText); idx += 1; } UpdateData(FALSE); } void CThresSetDlg::SaveThresParam(void) { /* code */ if (DIMENSION_NONE == m_eDir) return; if (NULL == m_dot) return; CString strText; for (int i = 0; i < 12; i++) { CThresDotProcess *dot = m_dot->m_dots[i]; if (NULL == dot) continue; //1. ID int idRow = dot->getID(); int idx = 0; strText = m_PanelThres.GetItemText(idRow, idx); idx += 1; //2. Name strText = m_PanelThres.GetItemText(idRow, idx); dot->m_strName = strText; idx += 1; //3. Use strText = m_PanelThres.GetItemText(idRow, idx); dot->m_nUse = _wtoi(strText); idx += 1; //4. pose type strText = m_PanelThres.GetItemText(idRow, idx); dot->m_poseType = _wtoi(strText); idx += 1; //5.Min Thres strText = m_PanelThres.GetItemText(idRow, idx); dot->m_minThres = _wtoi(strText); idx += 1; //6. Max Thres strText = m_PanelThres.GetItemText(idRow, idx); dot->m_maxThres = _wtoi(strText); idx += 1; //7.smooth strText = m_PanelThres.GetItemText(idRow, idx); dot->m_nSmoothSize = _wtoi(strText); idx += 1; //8. Min SizeX strText = m_PanelThres.GetItemText(idRow, idx); dot->m_minSizeX = _wtoi(strText); idx += 1; //9. Max SizeX strText = m_PanelThres.GetItemText(idRow, idx); dot->m_minSizeY = _wtoi(strText); idx += 1; } } void CThresSetDlg::OnBnClickedButtonThresSave() { // TODO: ÔÚ´ËÌí¼Ó¿Ø¼þ֪ͨ´¦Àí³ÌÐò´úÂë SaveThresParam(); } void CThresSetDlg::OnBnClickedButtonThresRoiSet() { // TODO: ÔÚ´ËÌí¼Ó¿Ø¼þ֪ͨ´¦Àí³ÌÐò´úÂë if (NULL == m_dot) return; CCellID selCell = m_PanelThres.GetFocusCell(); int id = selCell.row; if (id < 1) return; CThresDotProcess *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; dot->setRegion(x1, y1, x2 - x1 + 1, y2 - y1 + 1); } void CThresSetDlg::OnBnClickedButtonThresProcess() { // TODO: ÔÚ´ËÌí¼Ó¿Ø¼þ֪ͨ´¦Àí³ÌÐò´úÂë CBlSideData *pSideData = CVisionRecipe::getInstance()->getSideData(m_eDir); if (nullptr != pSideData) { pSideData->m_vDispVisionResult.clear(); } SaveThresParam(); if (nullptr == m_dot) return; m_dot->execute(m_eDir); DispResult(); } void CThresSetDlg::DispResult(void) { /* code */ CSoftVisionApp::getInstance()->sendMessage(2, m_eDir); DispAllResult(); } void CThresSetDlg::DispAllResult(void) { /* code */ int nCount = 12; for (int i = 0; i < nCount; i++) { CThresDotProcess *dot = m_dot->m_dots[i]; if (NULL == dot) continue; bool isDo = true; if (1 != dot->m_nUse) isDo = false; if (!isDo) { int id = dot->getID(); m_PanelThres.SetItemText(id, 9, _T("NAN")); } else { //ÏÔʾ½á¹û CString strResult; strResult.Format(_T("%d"), (int)dot->m_nNgInfo.size()); int id = dot->getID(); m_PanelThres.SetItemText(id, 9, strResult); } } m_PanelThres.Invalidate(FALSE); }