| ¶Ô±ÈÐÂÎļþ |
| | |
| | | // CPageLinkSignal.cpp: å®ç°æä»¶ |
| | | // |
| | | |
| | | #include "stdafx.h" |
| | | #include "Servo.h" |
| | | #include "CPageLinkSignal.h" |
| | | #include "afxdialogex.h" |
| | | |
| | | |
| | | #define FACECOLOR_ON RGB(34, 177, 76) |
| | | #define FACECOLOR_OFF RGB(195, 195, 195) |
| | | |
| | | #define TIMER_ID_SIGNAL_UPDATE 1001 |
| | | #define TIMER_INTERVAL_MS 1000 // æ¯ 1 ç§æ´æ°ä¸æ¬¡ |
| | | |
| | | // CPageLinkSignal å¯¹è¯æ¡ |
| | | |
| | | IMPLEMENT_DYNAMIC(CPageLinkSignal, CHMPropertyPage) |
| | | |
| | | CPageLinkSignal::CPageLinkSignal(CWnd* pParent /*=nullptr*/) |
| | | : CHMPropertyPage(IDD_PAGE_LINK_SIGNAL, pParent) |
| | | { |
| | | m_pEquipment = nullptr; |
| | | } |
| | | |
| | | CPageLinkSignal::~CPageLinkSignal() |
| | | { |
| | | } |
| | | |
| | | void CPageLinkSignal::DoDataExchange(CDataExchange* pDX) |
| | | { |
| | | CHMPropertyPage::DoDataExchange(pDX); |
| | | } |
| | | |
| | | |
| | | BEGIN_MESSAGE_MAP(CPageLinkSignal, CHMPropertyPage) |
| | | ON_WM_CTLCOLOR() |
| | | ON_WM_DESTROY() |
| | | ON_WM_SIZE() |
| | | ON_WM_TIMER() |
| | | END_MESSAGE_MAP() |
| | | |
| | | |
| | | // CPageLinkSignal æ¶æ¯å¤çç¨åº |
| | | |
| | | void CPageLinkSignal::setEquipment(SERVO::CEquipment* pEquipment) |
| | | { |
| | | m_pEquipment = pEquipment; |
| | | } |
| | | |
| | | BOOL CPageLinkSignal::OnInitDialog() |
| | | { |
| | | CHMPropertyPage::OnInitDialog(); |
| | | CreateSignalButtons(); |
| | | |
| | | |
| | | KillTimer(TIMER_ID_SIGNAL_UPDATE); |
| | | SetTimer(TIMER_ID_SIGNAL_UPDATE, TIMER_INTERVAL_MS, nullptr); |
| | | |
| | | return TRUE; // return TRUE unless you set the focus to a control |
| | | // å¼å¸¸: OCX 屿§é¡µåºè¿å FALSE |
| | | } |
| | | |
| | | |
| | | HBRUSH CPageLinkSignal::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) |
| | | { |
| | | HBRUSH hbr = CHMPropertyPage::OnCtlColor(pDC, pWnd, nCtlColor); |
| | | |
| | | // TODO: 卿¤æ´æ¹ DC çä»»ä½ç¹æ§ |
| | | |
| | | // TODO: 妿é»è®¤ç䏿¯æéç»ç¬ï¼åè¿åå¦ä¸ä¸ªç»ç¬ |
| | | return hbr; |
| | | } |
| | | |
| | | |
| | | void CPageLinkSignal::OnDestroy() |
| | | { |
| | | CHMPropertyPage::OnDestroy(); |
| | | |
| | | // TODO: 卿¤å¤æ·»å æ¶æ¯å¤çç¨åºä»£ç |
| | | for (int i = 0; i < 8; i++) { |
| | | for (int j = 0; j < 8; j++) { |
| | | if (m_pBtn[i][j] != nullptr) { |
| | | m_pBtn[i][j]->DestroyWindow(); |
| | | delete m_pBtn[i][j]; |
| | | m_pBtn[i][j] = nullptr; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | void CPageLinkSignal::OnSize(UINT nType, int cx, int cy) |
| | | { |
| | | CHMPropertyPage::OnSize(nType, cx, cy); |
| | | |
| | | // TODO: 卿¤å¤æ·»å æ¶æ¯å¤çç¨åºä»£ç |
| | | } |
| | | |
| | | #define BTN_X 98 |
| | | #define BTN_Y 80 |
| | | #define BTN_WIDTH 36 |
| | | void CPageLinkSignal::CreateSignalButtons() |
| | | { |
| | | int x = 100; |
| | | int y = 100; |
| | | int marginx = 32; |
| | | int marginy = 12; |
| | | for (int row = 0; row < 8; row++) { |
| | | y = BTN_Y + (BTN_WIDTH + marginy) * row; |
| | | for (int col = 0; col < 8; col++) { |
| | | x = BTN_X + (BTN_WIDTH + marginx) * col; |
| | | m_pBtn[row][col] = new CBlButton(); |
| | | m_pBtn[row][col]->Create("", WS_VISIBLE, { x, y, x + 36, y + 36 }, this, 1000); |
| | | m_pBtn[row][col]->SetFaceColor(FACECOLOR_OFF); |
| | | m_pBtn[row][col]->SetFrameColor(RGB(28, 28, 28)); |
| | | m_pBtn[row][col]->SetTextColor(RGB(238, 238, 238)); |
| | | } |
| | | } |
| | | |
| | | CWnd* pItem; |
| | | CRect rcItem; |
| | | int idx[] = { IDC_LABEL_PATH1, IDC_LABEL_PATH2, IDC_LABEL_PATH3, IDC_LABEL_PATH4, IDC_LABEL_PATH5, |
| | | IDC_LABEL_PATH6, IDC_LABEL_PATH7, IDC_LABEL_PATH8}; |
| | | for (int i = 0; i < 8; i++) { |
| | | pItem = GetDlgItem(idx[i]); |
| | | pItem->GetWindowRect(&rcItem); |
| | | pItem->MoveWindow(BTN_X - rcItem.Width() - 18, |
| | | BTN_Y + (36 - rcItem.Height()) / 2 + (BTN_WIDTH + marginy) * i, |
| | | rcItem.Width(), rcItem.Height()); |
| | | } |
| | | |
| | | int idy[] = { IDC_LABEL_NAME1, IDC_LABEL_NAME2, IDC_LABEL_NAME3, IDC_LABEL_NAME4, IDC_LABEL_NAME5, |
| | | IDC_LABEL_NAME6, IDC_LABEL_NAME7, IDC_LABEL_NAME8 }; |
| | | for (int i = 0; i < 8; i++) { |
| | | pItem = GetDlgItem(idy[i]); |
| | | pItem->GetWindowRect(&rcItem); |
| | | pItem->MoveWindow(BTN_X + (BTN_WIDTH + marginx) * i, |
| | | BTN_Y - 36, |
| | | rcItem.Width(), rcItem.Height()); |
| | | } |
| | | } |
| | | |
| | | void CPageLinkSignal::OnTimer(UINT_PTR nIDEvent) |
| | | { |
| | | if (nIDEvent == TIMER_ID_SIGNAL_UPDATE) { |
| | | if (m_pEquipment) { |
| | | UpdateAllSignalStatesFromDevice(); |
| | | } |
| | | } |
| | | |
| | | CHMPropertyPage::OnTimer(nIDEvent); |
| | | } |
| | | |
| | | void CPageLinkSignal::UpdateAllSignalStatesFromDevice() |
| | | { |
| | | ASSERT(m_pEquipment); |
| | | |
| | | for (int nRow = 0; nRow < 8; ++nRow) { |
| | | for (int nCol = 0; nCol < 8; ++nCol) { |
| | | BOOL bCurrentState = m_pEquipment->isLinkSignalOn(nRow, nCol); |
| | | UpdateSignalState(nRow, nCol, bCurrentState); |
| | | } |
| | | } |
| | | } |
| | | |
| | | void CPageLinkSignal::UpdateSignalState(int nRow, int nCol, bool bNewState) |
| | | { |
| | | if (!::IsWindow(m_pBtn[nRow][nCol]->GetSafeHwnd())) { |
| | | return; |
| | | } |
| | | |
| | | bool bState = ::GetProp(m_pBtn[nRow][nCol]->GetSafeHwnd(), _T("State")) == (void*)1; |
| | | if (bState != bNewState) { |
| | | m_pBtn[nRow][nCol]->SetFaceColor(bNewState ? FACECOLOR_ON : FACECOLOR_OFF); |
| | | ::SetProp(m_pBtn[nRow][nCol]->GetSafeHwnd(), _T("State"), bNewState ? (void*)1 : (void*)0); |
| | | } |
| | | } |
| | | |
| | | |