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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#pragma once
#include "BlButton.h"
#include "BLLabel.h"
#include "CBaseDlg.h"
#include "PLC.h"
#include "AxisManager.h"
 
// 每页定位点显示个数
#define AXIS_PAGE_SIZE    5
 
// Label控件
#define LABEL_MAX        6
#define LABEL_FLS        0
#define LABEL_DOG        1
#define LABEL_RLS        2
#define LABEL_READY        3
#define LABEL_BUSY        4
#define LABEL_ERR        5
 
// BUTTON控件
#define BTN_MAX            15
#define BTN_PAGE1        0
#define BTN_PAGE2        1
#define BTN_PAGE3        2
#define BTN_PAGE4        3
#define BTN_PAGE5        4
#define BTN_JOG_ADD        5
#define BTN_JOG_SUB        6
#define BTN_JOG_SEV        7
#define BTN_JOG_OPR        8
#define BTN_JOG_STOP    9
#define BTN_POINT1        10
#define BTN_POINT2        11
#define BTN_POINT3        12
#define BTN_POINT4        13
#define BTN_POINT5        14
 
// CAxisSettingsDlg 对话框
 
enum class AxisOperationType {
    OPR = 0,    // 回原点
    JOG_ADD,    // 正向点动
    JOG_SUB,    // 反向点动
    STOP,        // 停止操作
    SEV_ON,        // 使能
    POSITION_1, // 定位点1
    POSITION_2, // 定位点2
    POSITION_3, // 定位点3
    POSITION_4, // 定位点4
    POSITION_5  // 定位点5
};
 
class CAxisSettingsDlg : public CBaseDlg
{
    DECLARE_DYNAMIC(CAxisSettingsDlg)
 
public:
    CAxisSettingsDlg(CWnd* pParent = nullptr);   // 标准构造函数
    virtual ~CAxisSettingsDlg();
 
 
private:
    virtual BOOL PreAdjustControl(CWnd* pWnd);
 
 
// 对话框数据
#ifdef AFX_DESIGN_TIME
    enum { IDD = IDD_DIALOG_AXIS_SETTINGS };
#endif
 
private:
    UINT FindIDByName(const CString& strControlID);
    void AdjustLabelFont(CBLLabel& label);
    void SetLabelColor(CBLLabel& label, COLORREF color);
    void SetLabelColorBasedOnState(CBLLabel& label, BOOL bState, COLORREF colorTrue, COLORREF colorFalse);
    void UpdateLabels();
    void UpdatePageButtonStates();
    void HideEditCursor(int nCtrlID);
    int GetCurrentSelectedAxisID();
    void InitializeAxisIDCombo();
    void RefreshAxisDetails(int nAxisId);
    void RefreshPositionDetails(int nAxisId, int pageNumber);
    void UpdatePositionRange(PositionRange& position, int pageNumber, int pageSize, int currentIndex);
    void UpdateAxisSelection(int offset);
    void UpdateDataFromUI(int nAxisId);
    void SwitchToPage(int targetPage);
    bool ParsePLCAddress(const CString& address, MC::SOFT_COMPONENT& component, int& addr);
    void WriteAxisDataToPLC(int nAxisId);
    void HandleAxisOperation(AxisOperationType eOpType, bool bPressed);
    void ReadPLCDataToUI(int nAxisId);
    void ShowTipText(const char* pszText, float sec);
    void HideTip();
    bool IsFloatInRange(const std::string& strInput, double fLowerBound, double fUpperBound);
 
private:
    CPLC* m_pPLC;
    HBRUSH m_hbrTip;
    HFONT m_hTipFont;
    COLORREF m_crTipBack;
    COLORREF m_crTipText;
 
    // 当前选中的定位页面索引
    int m_currentPage;
 
    // 轴管理器
    AxisManager* m_pAxisManager;
 
    // 控件
    CBlButton* m_pBlBtns[BTN_MAX];
    CBLLabel* m_pBlLabels[LABEL_MAX];
    CComboBox m_comboAxisNO;
    CStatic m_staticAxisNO, m_staticAxisDescription, m_staticStartAddress;
 
    // 读到的数据
    BOOL m_bSEV;
    double m_fCurPos;
    double m_fManualSpeed;
    double m_fAutoSpeed;
    double m_fPrm;
    int m_nLoad;
    int m_nErrCode;
    int m_nAlarmCode;
    BOOL m_bFLS;
    BOOL m_bDOG;
    BOOL m_bRLS;
    BOOL m_bReady;
    BOOL m_bBusy;
    BOOL m_bErr;
    DWORD m_nBtnsFlashState6;
    DWORD m_nBtnsFlashState8;
 
protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持
    virtual BOOL OnInitDialog();
    virtual BOOL PreTranslateMessage(MSG* pMsg);
    afx_msg void OnSize(UINT nType, int cx, int cy);
    afx_msg void OnBnClickedButtonAxisLast();
    afx_msg void OnBnClickedButtonAxisNext();
    afx_msg void OnBnClickedButtonAxisAnchorPointGroup1();
    afx_msg void OnBnClickedButtonAxisAnchorPointGroup2();
    afx_msg void OnBnClickedButtonAxisAnchorPointGroup3();
    afx_msg void OnBnClickedButtonAxisAnchorPointGroup4();
    afx_msg void OnBnClickedButtonAxisAnchorPointGroup5();
    afx_msg void OnBnClickedButtonAxisAnchorPoint1();
    afx_msg void OnBnClickedButtonAxisAnchorPoint2();
    afx_msg void OnBnClickedButtonAxisAnchorPoint3();
    afx_msg void OnBnClickedButtonAxisAnchorPoint4();
    afx_msg void OnBnClickedButtonAxisAnchorPoint5();
    afx_msg void OnBnClickedButtonAxisTestOpr();
    afx_msg void OnBnClickedButtonAxisTestStop();
    afx_msg void OnBnClickedButtonAxisSev();
    afx_msg void OnSelchangeComboAxisName();
    afx_msg void OnBnClickedButtonAxisSave();
    afx_msg void OnBnClickedButtonAxisUpdateUi();
    afx_msg void OnBnClickedButtonAxisDetailSettings();
    afx_msg LRESULT OnUpdateDataToUI(WPARAM wParam, LPARAM lParam);
    afx_msg void OnKillfocusEditAxisModitfyManualSpeed();
    afx_msg void OnKillfocusEditAxisModitfyAutoSpeed();
    afx_msg void OnKillfocusEditAxisModitfyDeceTime();
    afx_msg void OnKillfocusEditAxisModitfyAcceTime();
    afx_msg void OnEnKillfocusEditAxisModitfyMicromentum();
    afx_msg void OnTimer(UINT_PTR nIDEvent);
    afx_msg void OnClose();
    afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
    DECLARE_MESSAGE_MAP()
};