chenluhua1980
2026-01-24 8fc148424accf484b4f331c7d5fb11eb7383cf89
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
#pragma once
#include "ServoGraph.h"
#include "ServoCommo.h"
 
enum DeviceStatus {
    ONLINE,       // 在线
    OFFLINE,      // 离线
    OCCUPIED      // 有片(占用)
};
 
struct RobotPositionMapping {
    SERVO::ROBOT_POSITION position;
    float percentage;
    float angle;
    int arm; // 0 表示 ARM1,1 表示 ARM2
};
 
// CPageGraph1 对话框
 
class CPageGraph1 : public CDialogEx
{
    DECLARE_DYNAMIC(CPageGraph1)
 
public:
    CPageGraph1(CWnd* pParent = nullptr);   // 标准构造函数
    virtual ~CPageGraph1();
 
 
public:
    std::string GetConfigPath();
    void InitRxWindows();
    void UpdateDeviceStatus(int id, DeviceStatus status);
    void UpdateRobotPosition(float percentage);
    void RotateRobot(float angleInDegrees);
    void BindEquipmentToGraph();
    void MoveRobotToPosition(SERVO::ROBOT_POSITION position);
    void StartRobotMoveToPosition(SERVO::ROBOT_POSITION position);
    POINT LoadArmOffset(const std::string& armName);
    void SaveArmOffset(const std::string& armName, const POINT& pt);
 
private:
    IObserver* m_pObserver;
    CServoGraph* m_pGraph;
    BOOL m_bIsRobotMoving;
    COLORREF m_crBkgnd;
    HBRUSH m_hbrBkgnd;
 
    // ===== 机器人动画相关成员变量 =====
 
    // 动画目标位置(机器人目标位置枚举)
    SERVO::ROBOT_POSITION m_targetRobotPosition;
 
    // 动画起始和目标 X 坐标(水平位移)
    int m_nRobotMoveStartX;
    int m_nRobotMoveEndX;
 
    // 动画步数控制(总步数 & 当前步)
    int m_nRobotMoveSteps;          // 动画总步数(控制动画速度)
    int m_nRobotMoveCurrentStep;    // 当前动画步数进度
 
    // 动画起始和目标角度(旋转角度,单位:度)
    float m_nRobotMoveStartAngle;   // 起始角度
    float m_nRobotMoveEndAngle;     // 目标角度(旋转角度)
 
    // ===== 机器人状态相关成员变量 =====
 
    // 上一次已完成的位置(用于判断是否需要移动)
    SERVO::ROBOT_POSITION m_lastRobotPosition;
 
    // 上一次已更新的机器人 ARM 占用状态(两个机械臂)
    BOOL m_lastArmState[2];
 
    // 两个机械臂相对于机器人中心的偏移(像素坐标)
    POINT m_arm1Offset;
    POINT m_arm2Offset;
 
 
// 对话框数据
#ifdef AFX_DESIGN_TIME
    enum { IDD = IDD_PAGE_GRAPH1 };
#endif
 
protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持
 
    DECLARE_MESSAGE_MAP()
public:
    virtual BOOL OnInitDialog();
    afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
    afx_msg void OnDestroy();
    afx_msg void OnSize(UINT nType, int cx, int cy);
    afx_msg void OnGraphItemClicked(NMHDR* pNMHDR, LRESULT* pResult);
    afx_msg BOOL OnEraseBkgnd(CDC* pDC);
    afx_msg void OnTimer(UINT_PTR nIDEvent);
};