// VisionSetDlg.cpp : ʵÏÖÎļþ // #include "stdafx.h" #include "BlVisionPro.h" #include "VisionSetDlg.h" #include "afxdialogex.h" #include "VisionBufferPro.h" #include "CornerDistSetDlg.h" #include "RcutSetDLg.h" #include "ScanSetDlg.h" #include "KeyVisionSetDlg.h" #include "LocSetDlg.h" #include "CutSetDlg.h" #include "KDistSetDlg.h" #include #include "GrindSetDlg.h" #include "LockSetDlg.h" #include "ChipInspectDlg.h" #include "ThresSetDlg.h" #include "HoleSetDlg.h" // CVisionSetDlg ¶Ô»°¿ò #define BUTTON_WIDTH 100 // °´Å¥µÄ¿í¶È #define BUTTON_HEIGHT 30 // °´Å¥µÄ¸ß¶È #define BUTTON_PADDING 1 // °´Å¥Ö®¼äµÄ¼ä¾à IMPLEMENT_DYNAMIC(CVisionSetDlg, CDialogEx) CVisionSetDlg::CVisionSetDlg(CWnd* pParent /*=NULL*/) : CDialogEx(IDD_DIALOG_VISION_SET, pParent) { m_pOpRoiDlg = NULL; m_drawOperator.isDrawing = false; } CVisionSetDlg::~CVisionSetDlg() { /* code */ int sz = (int)(m_pages.size()); for (int i = 0; i < sz; i++) { delete m_pages[i]; m_pages[i] = nullptr; } m_pages.clear(); if (m_pOpRoiDlg != NULL) { m_pOpRoiDlg->DestroyWindow(); delete m_pOpRoiDlg; m_pOpRoiDlg = NULL; } } void CVisionSetDlg::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CVisionSetDlg, CDialogEx) ON_WM_CLOSE() ON_WM_MOVE() ON_WM_CTLCOLOR() END_MESSAGE_MAP() // CVisionSetDlg ÏûÏ¢´¦Àí³ÌÐò void CVisionSetDlg::OnClose() { // TODO: ÔÚ´ËÌí¼ÓÏûÏ¢´¦Àí³ÌÐò´úÂëºÍ/»òµ÷ÓÃĬÈÏÖµ int sz = (int)(m_pages.size()); for (int i = 0; i < sz; i++) { m_pages[i]->ShowWindow(SW_HIDE); } CVisionRecipe::getInstance()->setVisionSetOpen(FALSE); CDialogEx::OnClose(); } void CVisionSetDlg::InitCreateWnd(void) { /* code */ CStatic *pMainPanel = (CStatic *)GetDlgItem(IDC_STATIC_UI_V); CVisionRecipe::getInstance()->SetMainDlg(this); //1. ´´½¨LOC { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CLocSetDlg *pDlg = new CLocSetDlg(); pDlg->Create(IDD_DIALOG_LOC_SET, pMainPanel); m_pages.push_back((CDialogEx*)(pDlg)); pDlg->ShowWindow(SW_HIDE); } //2. Grind { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CGrindSetDlg *pDlg = new CGrindSetDlg(); pDlg->Create(IDD_DIALOG_GRIND_SET, pMainPanel); m_pages.push_back((CDialogEx*)(pDlg)); pDlg->ShowWindow(SW_HIDE); } //3. KDist { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CKDistSetDlg *pDlg = new CKDistSetDlg(); pDlg->Create(IDD_DIALOG_DIST_SET, pMainPanel); m_pages.push_back((CDialogEx*)(pDlg)); pDlg->ShowWindow(SW_HIDE); } //4. CCUT { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CCutSetDlg *pDlg = new CCutSetDlg(); pDlg->Create(IDD_DIALOG_CUTLINE_SET, pMainPanel); m_pages.push_back((CDialogEx*)(pDlg)); pDlg->ShowWindow(SW_HIDE); } //5. RCUT { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CRcutSetDLg *pDlg = new CRcutSetDLg(); pDlg->Create(IDD_DIALOG_RCUT_SET, pMainPanel); m_pages.push_back((CDialogEx*)(pDlg)); pDlg->ShowWindow(SW_HIDE); } //6. ´´½¨ThresSet { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CThresSetDlg *pDlg = new CThresSetDlg(); pDlg->Create(IDD_DIALOG_THRES_SET, pMainPanel); m_pages.push_back((CDialogEx*)(pDlg)); pDlg->ShowWindow(SW_HIDE); } //7. ´´½¨Hole { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CHoleSetDlg* pDlg = new CHoleSetDlg(); pDlg->Create(IDD_DIALOG_HOLE_INSPECT, pMainPanel); m_pages.push_back((CDialogEx*)(pDlg)); pDlg->ShowWindow(SW_HIDE); } Resize(); } #define PAGE_MARGIN_LEFT 12 #define PAGE_MARGIN_TOP 0 #define PAGE_MARGIN_RIGHT 12 #define PAGE_MARGIN_BOTTOM 12 void CVisionSetDlg::Resize(void) { /* code */ CStatic *pMainPanel = (CStatic *)GetDlgItem(IDC_STATIC_UI_V); if (NULL == pMainPanel) return; CRect rcRect; pMainPanel->GetWindowRect(rcRect); for (auto item : m_pages) { if (NULL == item) continue; item->MoveWindow(rcRect.left + PAGE_MARGIN_LEFT, rcRect.top + PAGE_MARGIN_TOP, rcRect.Width() - PAGE_MARGIN_LEFT - PAGE_MARGIN_RIGHT, rcRect.Height() - PAGE_MARGIN_TOP - PAGE_MARGIN_BOTTOM); } } void CVisionSetDlg::SetButtonsSize(std::vector& buttons) { for (CButton* pButton : buttons) { if (pButton) { CRect rect; pButton->GetWindowRect(&rect); ScreenToClient(&rect); pButton->MoveWindow(rect.left, rect.top, BUTTON_WIDTH, BUTTON_HEIGHT); } } } void CVisionSetDlg::UpdateButtonsLayout(std::vector& buttons, const std::vector& states) { if (buttons.empty() || states.empty() || buttons.size() != states.size()) return; // È·±£°´Å¥Êý×é·Ç¿Õ // »ñÈ¡µÚÒ»¸ö°´Å¥µÄ³õʼλÖà CRect initialRect; buttons[0]->GetWindowRect(&initialRect); ScreenToClient(&initialRect); // ½«ÆÁÄ»×ø±êת»»Îª¿Í»§Çø×ø±ê int currentX = initialRect.left; // ÒÔµÚÒ»¸ö°´Å¥µÄXλÖÃΪÆðµã int currentY = initialRect.top; // ÒÔµÚÒ»¸ö°´Å¥µÄYλÖÃΪÆðµã // ±éÀú°´Å¥£¬¸ù¾Ý״̬ÏÔʾ»òÒþ²Ø for (size_t i = 0; i < buttons.size(); ++i) { CButton* pButton = buttons[i]; if (pButton) { if (states[i]) // Èç¹û״̬Ϊ true£¬ÏÔʾ°´Å¥ { // ÏÔʾ°´Å¥²¢µ÷ÕûËüµÄλÖà pButton->ShowWindow(SW_SHOW); pButton->MoveWindow(currentX, currentY, BUTTON_WIDTH, BUTTON_HEIGHT); // ¸üÐÂÏÂÒ»°´Å¥µÄλÖà currentX += BUTTON_WIDTH + BUTTON_PADDING; } else // Èç¹û״̬Ϊ false£¬Òþ²Ø°´Å¥ { pButton->ShowWindow(SW_HIDE); } } } } BOOL CVisionSetDlg::OnInitDialog() { CDialogEx::OnInitDialog(); // TODO: ÔÚ´ËÌí¼Ó¶îÍâµÄ³õʼ»¯ InitCreateWnd(); m_eDir = DIMENSION_NONE; m_eVisionType = VISION_NONE; ChangeVisionPro(DIMENSION_A, VISION_LOC); CButton* pMain = (CButton*)GetDlgItem(IDC_RDO_SIDE_A_TOP); if (pMain && pMain->GetSafeHwnd()) pMain->SetCheck(1); CButton* pVision = (CButton*)GetDlgItem(IDC_RDO_INSTYPE_LOC); if (pVision && pVision->GetSafeHwnd()) pVision->SetCheck(1); // Ìí¼Ó°´Å¥×é m_buttons.push_back((CButton*)GetDlgItem(IDC_RDO_INSTYPE_LOC)); m_buttons.push_back((CButton*)GetDlgItem(IDC_RDO_INSTYPE_GRIND)); m_buttons.push_back((CButton*)GetDlgItem(IDC_RDO_INSTYPE_KDIST)); m_buttons.push_back((CButton*)GetDlgItem(IDC_RDO_INSTYPE_CUT)); m_buttons.push_back((CButton*)GetDlgItem(IDC_RDO_INSTYPE_RCUT)); m_buttons.push_back((CButton*)GetDlgItem(IDC_RDO_INSTYPE_THRES)); m_buttons.push_back((CButton*)GetDlgItem(IDC_RDO_INSTYPE_HOLE)); m_buttons.push_back((CButton*)GetDlgItem(IDC_RDO_INSTYPE_IN_CHAMFER)); m_buttons.push_back((CButton*)GetDlgItem(IDC_RDO_INSTYPE_TOP_CORNER)); m_buttons.push_back((CButton*)GetDlgItem(IDC_RDO_INSTYPE_BOT_CORNER)); // ÉèÖÃÒ»×é°´Å¥µÄ´óС SetButtonsSize(m_buttons); ShowVisionType(); return TRUE; // return TRUE unless you set the focus to a control // Òì³£: OCX ÊôÐÔÒ³Ó¦·µ»Ø FALSE } void CVisionSetDlg::ShowVisionType(void) { /* code */ VisionDisplayInfo inf = CVisionRecipe::getInstance()->getVisionDisplay(); if (inf.isGrindDisplay) { GetDlgItem(IDC_RDO_INSTYPE_GRIND)->ShowWindow(SW_SHOW); } else { GetDlgItem(IDC_RDO_INSTYPE_GRIND)->ShowWindow(SW_HIDE); } if (inf.isDistDisplay) { GetDlgItem(IDC_RDO_INSTYPE_KDIST)->ShowWindow(SW_SHOW); } else { GetDlgItem(IDC_RDO_INSTYPE_KDIST)->ShowWindow(SW_HIDE); } if (inf.isCutDisplay) { GetDlgItem(IDC_RDO_INSTYPE_CUT)->ShowWindow(SW_SHOW); } else { GetDlgItem(IDC_RDO_INSTYPE_CUT)->ShowWindow(SW_HIDE); } if (inf.isRcutDisplay) { GetDlgItem(IDC_RDO_INSTYPE_RCUT)->ShowWindow(SW_SHOW); } else { GetDlgItem(IDC_RDO_INSTYPE_RCUT)->ShowWindow(SW_HIDE); } if (inf.isThresDisplay) { GetDlgItem(IDC_RDO_INSTYPE_THRES)->ShowWindow(SW_SHOW); } else { GetDlgItem(IDC_RDO_INSTYPE_THRES)->ShowWindow(SW_HIDE); } if (inf.isHoleDisplay) { GetDlgItem(IDC_RDO_INSTYPE_HOLE)->ShowWindow(SW_SHOW); } else { GetDlgItem(IDC_RDO_INSTYPE_HOLE)->ShowWindow(SW_HIDE); } /* m_buttons.push_back((CButton*)GetDlgItem(IDC_RDO_INSTYPE_IN_CHAMFER)); m_buttons.push_back((CButton*)GetDlgItem(IDC_RDO_INSTYPE_TOP_CORNER)); m_buttons.push_back((CButton*)GetDlgItem(IDC_RDO_INSTYPE_BOT_CORNER));*/ std::vector states; states.push_back(true); states.push_back(inf.isGrindDisplay); states.push_back(inf.isDistDisplay); states.push_back(inf.isCutDisplay); states.push_back(inf.isRcutDisplay); states.push_back(inf.isThresDisplay); states.push_back(inf.isHoleDisplay); states.push_back(false); states.push_back(false); states.push_back(false); UpdateButtonsLayout(m_buttons, states); } void CVisionSetDlg::OnMove(int x, int y) { CDialogEx::OnMove(x, y); // TODO: ÔÚ´Ë´¦Ìí¼ÓÏûÏ¢´¦Àí³ÌÐò´úÂë Resize(); } void CVisionSetDlg::ChangeDimension(DimensionDir eDir) { /* code */ ChangeVisionPro(eDir, m_eVisionType); } void CVisionSetDlg::ChangeVisionPro(DimensionDir eDir, VISION_TYPE eVision) { /* code */ ChangeImage(eDir); ChangeVisionType(eVision); } void CVisionSetDlg::ChangeImage(DimensionDir eDir) { /* code */ if (eDir == m_eDir) { return; } m_eDir = eDir; } void CVisionSetDlg::ChangeVisionType(VISION_TYPE eVision) { /* code */ int sz = (int)(m_pages.size()); if (sz < 1) return; for (int i = 0; i < sz; i++) { m_pages[i]->ShowWindow(SW_HIDE); } m_eVisionType = eVision; switch (eVision) { case VISION_LOC: { CLocSetDlg *pDlg = (CLocSetDlg *)(m_pages[0]); pDlg->setDimensionDir(m_eDir); pDlg->ShowWindow(SW_SHOW); break; } case VISION_GRIND: { CGrindSetDlg *pDlg = (CGrindSetDlg *)(m_pages[1]); pDlg->setDimensionDir(m_eDir); pDlg->ShowWindow(SW_SHOW); break; } case VISION_KDIST: { CKDistSetDlg *pDlg = (CKDistSetDlg *)(m_pages[2]); pDlg->setDimensionDir(m_eDir); pDlg->ShowWindow(SW_SHOW); break; } case VISION_CUT: { CCutSetDlg *pDlg = (CCutSetDlg *)(m_pages[3]); pDlg->setDimensionDir(m_eDir); pDlg->ShowWindow(SW_SHOW); break; } case VISION_RCUT: { CRcutSetDLg *pDlg = (CRcutSetDLg *)(m_pages[4]); pDlg->setDimensionDir(m_eDir); pDlg->ShowWindow(SW_SHOW); break; } case VISION_THRES: { CThresSetDlg* pDlg = (CThresSetDlg *)(m_pages[5]); pDlg->setDimensionDir(m_eDir); pDlg->ShowWindow(SW_SHOW); break; } case VISION_HOLE: { CHoleSetDlg* pDlg = (CHoleSetDlg *)(m_pages[6]); pDlg->setDimensionDir(m_eDir); pDlg->ShowWindow(SW_SHOW); break; } case VISION_NONE: break; default: break; } } HBRUSH CVisionSetDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor); // TODO: Ôڴ˸ü¸Ä DC µÄÈκÎÌØÐÔ // TODO: Èç¹ûĬÈϵIJ»ÊÇËùÐè»­±Ê£¬Ôò·µ»ØÁíÒ»¸ö»­±Ê return hbr; } BEGIN_EVENTSINK_MAP(CVisionSetDlg, CDialogEx) ON_EVENT(CVisionSetDlg, IDC_RDO_INSTYPE_LOC, DISPID_CLICK, CVisionSetDlg::ClickRdoInstypeLoc, VTS_NONE) ON_EVENT(CVisionSetDlg, IDC_RDO_INSTYPE_RCUT, DISPID_CLICK, CVisionSetDlg::ClickRdoInstypeRcut, VTS_NONE) ON_EVENT(CVisionSetDlg, IDC_BUTTON_VISION_SCAN_SET, DISPID_CLICK, CVisionSetDlg::ClickButtonVisionScanSet, VTS_NONE) ON_EVENT(CVisionSetDlg, IDC_BUTTON_VISION_KEY_SET, DISPID_CLICK, CVisionSetDlg::ClickButtonVisionKeySet, VTS_NONE) ON_EVENT(CVisionSetDlg, IDC_BUTTON_VISION_OP_ROI, DISPID_CLICK, CVisionSetDlg::ClickButtonVisionOpRoi, VTS_NONE) ON_EVENT(CVisionSetDlg, IDC_RDO_INSTYPE_CUT, DISPID_CLICK, CVisionSetDlg::ClickRdoInstypeCut, VTS_NONE) ON_EVENT(CVisionSetDlg, IDC_RDO_INSTYPE_KDIST, DISPID_CLICK, CVisionSetDlg::ClickRdoInstypeKdist, VTS_NONE) ON_EVENT(CVisionSetDlg, IDC_RDO_INSTYPE_GRIND, DISPID_CLICK, CVisionSetDlg::ClickRdoInstypeGrind, VTS_NONE) ON_EVENT(CVisionSetDlg, IDC_RDO_INSTYPE_THRES, DISPID_CLICK, CVisionSetDlg::ClickRdoInstypeThres, VTS_NONE) ON_EVENT(CVisionSetDlg, IDC_RDO_INSTYPE_HOLE, DISPID_CLICK, CVisionSetDlg::ClickRdoInstypeHole, VTS_NONE) END_EVENTSINK_MAP() void CVisionSetDlg::ClickRdoInstypeLoc() { // TODO: ÔÚ´Ë´¦Ìí¼ÓÏûÏ¢´¦Àí³ÌÐò´úÂë /* code */ ChangeVisionPro(m_eDir, VISION_LOC); } void CVisionSetDlg::ClickRdoInstypeRcut() { // TODO: ÔÚ´Ë´¦Ìí¼ÓÏûÏ¢´¦Àí³ÌÐò´úÂë ChangeVisionPro(m_eDir, VISION_RCUT); } void CVisionSetDlg::ClickButtonVisionScanSet() { // TODO: ÔÚ´Ë´¦Ìí¼ÓÏûÏ¢´¦Àí³ÌÐò´úÂë CScanSetDlg dlg; dlg.DoModal(); ShowVisionType(); } void CVisionSetDlg::ClickButtonVisionKeySet() { // TODO: ÔÚ´Ë´¦Ìí¼ÓÏûÏ¢´¦Àí³ÌÐò´úÂë CKeyVisionSetDlg dlg; dlg.DoModal(); ShowVisionType(); } void CVisionSetDlg::ClickButtonVisionOpRoi() { // TODO: ÔÚ´Ë´¦Ìí¼ÓÏûÏ¢´¦Àí³ÌÐò´úÂë //if (m_pOpRoiDlg == NULL) { // m_pOpRoiDlg = new COpRoiDlg(this); // m_pOpRoiDlg->Create(IDD_DIALOG_ROI_SET, this); // m_pOpRoiDlg->ShowWindow(SW_SHOW); //} //else { // m_pOpRoiDlg->ShowWindow(SW_SHOW); //} CLockSetDlg dlg; dlg.DoModal(); } void CVisionSetDlg::ClickRdoInstypeCut() { // TODO: ÔÚ´Ë´¦Ìí¼ÓÏûÏ¢´¦Àí³ÌÐò´úÂë ChangeVisionPro(m_eDir, VISION_CUT); } void CVisionSetDlg::ClickRdoInstypeKdist() { // TODO: ÔÚ´Ë´¦Ìí¼ÓÏûÏ¢´¦Àí³ÌÐò´úÂë ChangeVisionPro(m_eDir, VISION_KDIST); } void CVisionSetDlg::ClickRdoInstypeGrind() { // TODO: ÔÚ´Ë´¦Ìí¼ÓÏûÏ¢´¦Àí³ÌÐò´úÂë ChangeVisionPro(m_eDir, VISION_GRIND); } BOOL CVisionSetDlg::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 CVisionSetDlg::ClickRdoInstypeThres() { // TODO: ÔÚ´Ë´¦Ìí¼ÓÏûÏ¢´¦Àí³ÌÐò´úÂë ChangeVisionPro(m_eDir, VISION_THRES); } void CVisionSetDlg::ClickRdoInstypeHole() { // TODO: ÔÚ´Ë´¦Ìí¼ÓÏûÏ¢´¦Àí³ÌÐò´úÂë ChangeVisionPro(m_eDir, VISION_HOLE); }