| | |
| | | #include "BondEq.h" |
| | | #include "afxdialogex.h" |
| | | #include "AxisSettingsDlg.h" |
| | | #include "ToolUnits.h" |
| | | |
| | | #define TIMER_INIT 1 |
| | | #define TIMER_READ_PLC_DATA 2 |
| | | |
| | | // CAxisSettingsDlg 对话框 |
| | | |
| | |
| | | { |
| | | m_nInitialWidth = 0; |
| | | m_nInitialHeight = 0; |
| | | m_pPLC = nullptr; |
| | | } |
| | | |
| | | CAxisSettingsDlg::~CAxisSettingsDlg() |
| | |
| | | m_mapFonts.clear(); |
| | | } |
| | | |
| | | void CAxisSettingsDlg::SetPLC(CPLC* pPLC) |
| | | { |
| | | ASSERT(pPLC); |
| | | m_pPLC = pPLC; |
| | | } |
| | | |
| | | void CAxisSettingsDlg::DoDataExchange(CDataExchange* pDX) |
| | | { |
| | | CDialogEx::DoDataExchange(pDX); |
| | | DDX_Control(pDX, IDC_STATIC_AXIS_TEST_FLS, m_staticFLS); |
| | | DDX_Control(pDX, IDC_STATIC_AXIS_TEST_DOG, m_staticDOG); |
| | | DDX_Control(pDX, IDC_STATIC_AXIS_TEST_RLS, m_staticRLS); |
| | | DDX_Control(pDX, IDC_STATIC_AXIS_TEST_READY, m_staticReady); |
| | | DDX_Control(pDX, IDC_STATIC_AXIS_TEST_BUSY, m_staticBusy); |
| | | DDX_Control(pDX, IDC_STATIC_AXIS_TEST_ERR, m_staticErr); |
| | | } |
| | | |
| | | CFont* CAxisSettingsDlg::GetOrCreateFont(int nFontSize) |
| | |
| | | // 根据控件高度动态调整字体大小 |
| | | int fontSize = nHeight / 2; |
| | | if (fontSize < 8) fontSize = 8; |
| | | if (fontSize > 24) fontSize = 24; // 最大字体大小 |
| | | |
| | | // 获取或创建字体 |
| | | CFont* pFont = GetOrCreateFont(fontSize); |
| | | |
| | | pWnd->SetFont(pFont); |
| | | pWnd->Invalidate(); // 刷新控件显示 |
| | | } |
| | | |
| | | void CAxisSettingsDlg::AdjustLabelFont(CBLLabel& label) |
| | | { |
| | | // 获取控件的矩形区域 |
| | | CRect rect; |
| | | label.GetClientRect(&rect); |
| | | |
| | | // 动态计算字体大小,基于控件的高度 |
| | | int fontSize = rect.Height() / 2; // 控件高度的一半作为字体大小 |
| | | if (fontSize < 8) fontSize = 8; // 最小字体大小 |
| | | if (fontSize > 30) fontSize = 30; // 最大字体大小 |
| | | |
| | | // 设置字体大小 |
| | | label.SetFontSize(fontSize); |
| | | |
| | | // 刷新控件显示 |
| | | label.Invalidate(); |
| | | label.UpdateWindow(); |
| | | } |
| | | |
| | | void CAxisSettingsDlg::SetStatusColor(CBLLabel& label, BOOL bStatus) |
| | | { |
| | | if (bStatus) { |
| | | label.SetBkColor(RGB(0, 255, 0)); // 绿色 |
| | | } |
| | | else { |
| | | label.SetBkColor(RGB(255, 0, 0)); // 红色 |
| | | } |
| | | |
| | | label.Invalidate(); // 标记区域无效 |
| | | label.UpdateWindow(); // 立即刷新 |
| | | } |
| | | |
| | | |
| | |
| | | ON_WM_SIZE() |
| | | ON_WM_CTLCOLOR() |
| | | ON_WM_SIZING() |
| | | ON_WM_TIMER() |
| | | END_MESSAGE_MAP() |
| | | |
| | | |
| | |
| | | CDialogEx::OnInitDialog(); |
| | | |
| | | // TODO: 在此添加额外的初始化 |
| | | SetWindowText(_T("Axis设定")); |
| | | |
| | | // 设置测试状态 |
| | | CBLLabel* pLabels[] = { &m_staticFLS, &m_staticDOG, &m_staticRLS, &m_staticReady, &m_staticBusy, &m_staticErr }; |
| | | for (auto pLabel : pLabels) { |
| | | SetStatusColor(*pLabel, FALSE); |
| | | pLabel->ModifyStyle(0, SS_NOTIFY); |
| | | pLabel->SetTextColor(RGB(255, 255, 255)); |
| | | pLabel->SetAlignment(AlignCenter); |
| | | pLabel->SetDynamicFont(TRUE); |
| | | } |
| | | |
| | | CRect screenRect, dlgRect, clientRect; |
| | | GetClientRect(&clientRect); |
| | | m_nInitialWidth = clientRect.Width(); |
| | |
| | | int centerX = screenRect.left + (screenRect.Width() - dlgWidth) / 2; |
| | | int centerY = screenRect.top + (screenRect.Height() - dlgHeight) / 2; |
| | | MoveWindow(centerX, centerY, dlgWidth, dlgHeight); |
| | | |
| | | SetTimer(TIMER_READ_PLC_DATA, 500, nullptr); |
| | | |
| | | return TRUE; // return TRUE unless you set the focus to a control |
| | | // 异常: OCX 属性页应返回 FALSE |
| | |
| | | CDialogEx::OnSize(nType, cx, cy); |
| | | |
| | | // TODO: 在此处添加消息处理程序代码 |
| | | CRect rect; |
| | | GetClientRect(&rect); |
| | | if (nType == SIZE_MINIMIZED || m_mapCtrlLayouts.empty()) { |
| | | return; |
| | | } |
| | | |
| | | float dScaleX = static_cast<float>(cx) / m_nInitialWidth; |
| | | float dScaleY = static_cast<float>(cy) / m_nInitialHeight; |
| | | |
| | | // 遍历对话框中的所有控件 |
| | | AdjustControls(rect.Width(), rect.Height()); |
| | | AdjustControls(dScaleX, dScaleY); |
| | | |
| | | // 动态调整各个 CBLLabel 的字体大小 |
| | | CBLLabel* pLabels[] = { &m_staticFLS, &m_staticDOG, &m_staticRLS, &m_staticReady, &m_staticBusy, &m_staticErr }; |
| | | for (auto pLabel : pLabels) { |
| | | AdjustLabelFont(*pLabel); |
| | | } |
| | | } |
| | | |
| | | void CAxisSettingsDlg::OnSizing(UINT fwSide, LPRECT pRect) |
| | |
| | | void CAxisSettingsDlg::OnBnClickedButtonAxisTestStop() |
| | | { |
| | | // TODO: 在此添加控件通知处理程序代码 |
| | | } |
| | | } |
| | | |
| | | void CAxisSettingsDlg::OnTimer(UINT_PTR nIDEvent) |
| | | { |
| | | if (TIMER_READ_PLC_DATA == nIDEvent) { |
| | | ASSERT(m_pPLC); |
| | | |
| | | int addr1, addr2, readSize; |
| | | addr1 = 5120; |
| | | addr2 = 5425; |
| | | readSize = (addr2 - addr1 + 1) * 2; |
| | | auto funOnReadData = [&, addr1, readSize](IMcChannel* pChannel, int addr, char* pData, unsigned int nDataSize, int flag) -> void { |
| | | if (nDataSize == readSize && flag == 0) { |
| | | double fCurPos = CToolUnits::toInt32(pData) * 0.001; |
| | | double fManualSpeed = CToolUnits::toInt32(&pData[(5422- addr1)*2]) * 0.001; |
| | | double fAutoSpeed = CToolUnits::toInt32(&pData[(5424 - addr1) * 2]) * 0.001; |
| | | double fPrm = CToolUnits::toInt32(&pData[(5150 - addr1) * 2]) * 0.1; |
| | | int nLoad = CToolUnits::toInt16(&pData[(5154 - addr1) * 2]); |
| | | int nErrCode = CToolUnits::toInt16(&pData[(5126 - addr1) * 2]); |
| | | int nAlarmCode = CToolUnits::toInt16(&pData[(5127 - addr1) * 2]); |
| | | CToolUnits::setDlgItemDouble(this, IDC_EDIT_AXIS_CURR_POS, fCurPos); |
| | | CToolUnits::setDlgItemDouble(this, IDC_EDIT_AXIS_CURR_MANUAL_SPEED, fManualSpeed); |
| | | CToolUnits::setDlgItemDouble(this, IDC_EDIT_AXIS_CURR_AUTO_SPEED, fAutoSpeed); |
| | | CToolUnits::setDlgItemDouble(this, IDC_EDIT_AXIS_CURR_ROTA_SPEED, fPrm); |
| | | SetDlgItemInt(IDC_EDIT_AXIS_CURR_LOAD, nLoad); |
| | | SetDlgItemInt(IDC_EDIT_AXIS_CURR_ERROR_NUMBER, nErrCode); |
| | | SetDlgItemInt(IDC_EDIT_AXIS_CURR_ALARM_NUMBER, nAlarmCode); |
| | | } |
| | | }; |
| | | m_pPLC->readData(MC::SOFT_COMPONENT::D, addr1, readSize, funOnReadData); |
| | | } |
| | | |
| | | CDialogEx::OnTimer(nIDEvent); |
| | | } |