chenluhua1980
7 天以前 238f41fd4edac2febc03d2e428bce7206f609e99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#pragma once
#include "afxdialogex.h"
#include "IOManager.h"
#include "BLLabel.h"
#include "PLC.h"
 
 
// CIOMonitoringDlg 对话框
 
class CIOMonitoringDlg : public CDialogEx
{
    DECLARE_DYNAMIC(CIOMonitoringDlg)
 
public:
    CIOMonitoringDlg(CWnd* pParent = nullptr);   // 标准构造函数
    virtual ~CIOMonitoringDlg();
 
// 对话框数据
#ifdef AFX_DESIGN_TIME
    enum { IDD = IDD_DIALOG_IO_MONITORING };
#endif
 
private:
    CFont* GetOrCreateFont(int nFontSize);                            // 获取或创建字体
    void SetDefaultFont();                                            // 设置默认字体
    void AdjustControls(float dScaleX, float dScaleY);                // 调整控件大小
    void AdjustControlFont(CWnd* pWnd, int nWidth, int nHeight);    // 调整控件字体大小
 
    void UpdatePageInfo();             // 更新分页信息
    void CreateDynamicControls();     // 动态创建控件
    CWnd* CreateStaticControl(UINT id, int x, int y, int width, int height, const CString& text, bool hasBorder = false, TextAlign alignment = AlignLeft, std::function<void()> clickCallback = nullptr); // 创建静态控件
    CWnd* GetStaticControl(UINT id); // 获取静态控件
    CString& GetStaticControlAddrText(UINT id, CString& strAddr); // 获取静态控件地址文本
    void DisplayCurrentPage();         // 显示当前页数据
    void ClearDynamicControls();     // 清除动态创建的控件
    bool ParsePLCAddress(const CString& address, MC::SOFT_COMPONENT& component, int& addr); // 解析 PLC 地址
    bool GeneratePLCAddress(MC::SOFT_COMPONENT component, int addr, CString& address, bool bHexFormat = false); // 生成 PLC 地址
    void ReadPLCData(MC::SOFT_COMPONENT softComponent, int startAddr, int endAddr, std::function<void(IMcChannel*, int, char*, unsigned int, int)> callback); // 读取 PLC 数据
    void ReadPLCStates();             // 定时器读PLC
    void UpdatePLCStatesToUI();         // 定时器更新状态的方法
 
private:
    CPLC* m_pPLC;
    int m_nInitialWidth;
    int m_nInitialHeight;
    int m_nCurrentPage; // 当前页
    int m_nTotalPages;    // 总页数
    int m_nRowsPerPage; // 每页显示的行数
    int m_nCols;        // 每行的控件组数
    std::map<int, CFont*> m_mapFonts;        // 字体映射
    std::map<int, CRect> m_mapCtrlLayouts;    // 控件布局映射
    std::vector<IOData> m_displayData;        // 当前显示的数据
    std::vector<BOOL> m_inputStates;        // 输入状态
    std::vector<BOOL> m_outputStates;        // 输出状态
    std::vector<CString> m_inputPLCAddresses;  // 存储 1 列 PLC 地址
    std::vector<CString> m_outputPLCAddresses; // 存储 4 列 PLC 地址
 
private:
    CStatic m_staticPageNum;
    std::vector<CBLLabel*> m_staticControls; // 动态创建的静态控件
 
protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持
 
    DECLARE_MESSAGE_MAP()
public:
    virtual BOOL OnInitDialog();
    afx_msg void OnSize(UINT nType, int cx, int cy);
    afx_msg void OnBnClickedButtonPrevPage();
    afx_msg void OnBnClickedButtonNextPage();
    afx_msg LRESULT OnIoClicked(WPARAM wParam, LPARAM lParam);
    afx_msg void OnTimer(UINT_PTR nIDEvent);
    afx_msg void OnClose();
};