综合平台编程器项目的远程存储
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

159 line
5.4 KiB

  1. /**
  2. * @file main_window.h
  3. * @brief 定义综合平台编程器主窗口及运行模式界面协调逻辑
  4. * @version 0.2.0
  5. * @author suyu
  6. * @date 2026-08-08
  7. */
  8. #pragma once
  9. #include "domain/hmi_model.h"
  10. #include "domain/control_logic_model.h"
  11. #include "domain/runtime_state.h"
  12. #include "services/plc_communication_gateway.h"
  13. #include <QMainWindow>
  14. #include <memory>
  15. QT_BEGIN_NAMESPACE
  16. class QActionGroup;
  17. class QLabel;
  18. class QTimer;
  19. namespace Ui {
  20. class MainWindow;
  21. }
  22. QT_END_NAMESPACE
  23. class RuntimeModeService;
  24. class ProjectService;
  25. class HmiEditorService;
  26. class HmiRuntimeService;
  27. class HmiEditorWidget;
  28. class LogicEditorService;
  29. class LogicEditorWidget;
  30. /**
  31. * @brief 组织主界面区域并将用户操作转交给服务层
  32. *
  33. * 主窗口不直接访问寄存器、工程文件或 PLC 通信实现
  34. */
  35. class MainWindow final : public QMainWindow
  36. {
  37. Q_OBJECT
  38. public:
  39. /**
  40. * @brief 创建主窗口并注入 UI 所需的应用服务
  41. * @param runtime_mode_service 运行模式服务,调用方必须保证其生命周期覆盖窗口
  42. * @param project_service 工程管理服务,调用方必须保证其生命周期覆盖窗口
  43. * @param hmi_editor_service HMI 编辑服务,调用方必须保证其生命周期覆盖窗口
  44. * @param hmi_runtime_service HMI 运行服务,调用方必须保证其生命周期覆盖窗口
  45. * @param parent Qt 父对象
  46. */
  47. explicit MainWindow(
  48. RuntimeModeService &runtime_mode_service,
  49. ProjectService &project_service,
  50. HmiEditorService &hmi_editor_service,
  51. LogicEditorService &logic_editor_service,
  52. HmiRuntimeService &hmi_runtime_service,
  53. QWidget *parent = nullptr);
  54. ~MainWindow() override;
  55. private:
  56. // 配置菜单和工具栏动作
  57. void configureActions();
  58. // 配置主窗口外观和状态栏
  59. void configureAppearance();
  60. // 创建并连接 HMI 编辑画布
  61. void configureHmiEditor();
  62. // 创建并连接控制逻辑编辑画布
  63. void configureLogicEditor();
  64. // 创建并连接控件属性编辑表单
  65. void configurePropertyEditor();
  66. void configurePlcConnection();
  67. // 刷新工程树和当前 HMI 页面信息
  68. void refreshProjectUi();
  69. // 显示指定 HMI 控件的可编辑属性
  70. void showControlProperties(const std::string &control_id);
  71. // 显示指定控制逻辑节点的可编辑属性
  72. void showLogicNodeProperties(const std::string &node_id);
  73. // 向当前页面添加指定类型的 HMI 控件
  74. void addHmiControl(HmiControlType type);
  75. // 删除当前选中的 HMI 控件
  76. void deleteSelectedControl();
  77. // 将属性表单内容应用到当前选中控件
  78. void applySelectedControlProperties();
  79. // 在当前光标节点后添加串联条件,没有选择时追加到网络末尾
  80. void addLogicCondition(const LogicNodeConfig &config);
  81. // 为当前选中的连续逻辑范围建立并联支路
  82. void addLogicParallelBranch(const LogicNodeConfig &config);
  83. // 设置当前网络右侧的输出线圈
  84. void setLogicOutput(const LogicNodeConfig &config);
  85. // 新增一个梯形图网络
  86. void addLogicRung();
  87. // 删除当前选中的逻辑节点或网络
  88. void deleteSelectedLogicObject();
  89. // 将逻辑属性表单内容应用到当前选中节点
  90. void applySelectedLogicNodeProperties();
  91. void connectPlc();
  92. void disconnectPlc();
  93. // 创建新的工程并刷新编辑界面
  94. void createNewProject();
  95. // 保存当前工程到已关联的路径
  96. void saveProject();
  97. // 将当前工程保存到用户指定的路径
  98. void saveProjectAs();
  99. // 从用户指定的路径加载工程
  100. void loadProject();
  101. // 在状态栏和输出面板显示工程操作结果
  102. void showProjectResult(const QString &action, const QString &message, bool succeeded);
  103. /**
  104. * @brief 请求服务层切换模式并同步界面状态
  105. * @param requested_mode 目标应用模式
  106. *
  107. * 失败时恢复与服务层当前状态一致的工具栏选项
  108. */
  109. void requestMode(ApplicationMode requested_mode);
  110. /**
  111. * @brief 根据服务层模式策略更新编辑权限和状态反馈
  112. * @param message 要显示在状态栏和输出区的模式结果消息
  113. */
  114. void updateModeUi(const QString &message);
  115. // 根据仿真服务实际状态刷新执行器反馈和 HMI 写权限
  116. void updateSimulationUi(bool report_fault);
  117. /**
  118. * @brief 将互斥模式动作同步到服务层当前状态
  119. */
  120. void restoreCurrentModeAction();
  121. std::unique_ptr<Ui::MainWindow> ui_;
  122. /**
  123. * @brief 非拥有的运行模式服务依赖,由应用入口保证生命周期
  124. */
  125. RuntimeModeService &runtime_mode_service_;
  126. /**
  127. * @brief 非拥有的工程和 HMI 服务依赖,由应用入口保证生命周期
  128. */
  129. ProjectService &project_service_;
  130. HmiEditorService &hmi_editor_service_;
  131. LogicEditorService &logic_editor_service_;
  132. HmiRuntimeService &hmi_runtime_service_;
  133. QActionGroup *mode_action_group_ = nullptr;
  134. HmiEditorWidget *hmi_editor_widget_ = nullptr;
  135. LogicEditorWidget *logic_editor_widget_ = nullptr;
  136. QTimer *runtime_refresh_timer_ = nullptr;
  137. QLabel *mode_status_label_ = nullptr;
  138. QLabel *register_status_label_ = nullptr;
  139. QLabel *executor_status_label_ = nullptr;
  140. PlcSerialConfiguration plc_configuration_;
  141. std::string selected_control_id_;
  142. std::string selected_logic_node_id_;
  143. };