综合平台编程器项目的远程存储
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

164 wiersze
5.6 KiB

  1. /**
  2. * @file project_workspace_controller.h
  3. * @brief 定义工程树和当前编辑对象控制器
  4. * @version 1.0.0
  5. * @author suyu
  6. * @date 2026-08-22
  7. */
  8. #pragma once
  9. #include "domain/hmi_model.h"
  10. #include "domain/runtime_state.h"
  11. #include <QString>
  12. #include <functional>
  13. #include <string>
  14. class HmiEditorService;
  15. class HmiEditorWidget;
  16. class HmiNavigationService;
  17. class LogicEditorService;
  18. class LogicEditorWidget;
  19. class ProjectService;
  20. class RuntimeModeService;
  21. class RuntimeMonitorWidget;
  22. class QWidget;
  23. class QAction;
  24. namespace Ui {
  25. class MainWindow;
  26. }
  27. /**
  28. * 组织工程树、当前页面/逻辑选择和工程对象的界面刷新
  29. *
  30. * 它不直接改 Project,所有增删改都转发给对应服务
  31. */
  32. class ProjectWorkspaceController final
  33. {
  34. public:
  35. /** 报告工程操作结果,参数依次为操作名、消息和是否成功 */
  36. using ResultReporter = std::function<void(
  37. const QString &action, const QString &message, bool succeeded)>;
  38. /** 向状态栏报告一条带超时的消息 */
  39. using StatusReporter = std::function<void(
  40. const QString &message, int timeout_ms)>;
  41. /** 通知主窗口编辑状态已经发生变化 */
  42. using EditStateChanged = std::function<void()>;
  43. /** 创建工程树控制器并绑定主窗口服务和编辑器 */
  44. ProjectWorkspaceController(
  45. QWidget &parent,
  46. Ui::MainWindow &ui,
  47. ProjectService &project_service,
  48. HmiEditorService &hmi_editor_service,
  49. LogicEditorService &logic_editor_service,
  50. RuntimeModeService &runtime_mode_service,
  51. HmiNavigationService &hmi_navigation_service,
  52. HmiEditorWidget &hmi_editor_widget,
  53. LogicEditorWidget &logic_editor_widget,
  54. RuntimeMonitorWidget &runtime_monitor_widget,
  55. std::string &current_hmi_page_id,
  56. std::string &current_logic_id,
  57. std::function<void(const std::string &)> show_control_properties,
  58. std::function<void(const std::string &)> show_logic_properties,
  59. ResultReporter result_reporter,
  60. StatusReporter status_reporter,
  61. EditStateChanged edit_state_changed);
  62. /** 连接工程树动作和选择变化信号 */
  63. void configure();
  64. /** 根据当前工程重新生成工程树和编辑器内容 */
  65. void refresh();
  66. /** 根据当前选中对象更新工程树动作的可用状态 */
  67. void updateActions();
  68. /** 新增一个 HMI 页面 */
  69. void addPage();
  70. /** 新增一个控制逻辑 */
  71. void addLogic();
  72. /** 重命名当前选中的工程树项目 */
  73. void renameSelectedItem();
  74. /** 删除当前选中的工程树项目 */
  75. void deleteSelectedItem();
  76. /** 按偏移量移动当前选中的工程树项目 */
  77. void moveSelectedItem(int offset);
  78. /** 把当前选中的 HMI 页面设为初始页面 */
  79. void setSelectedPageAsInitial();
  80. /** 启用或停用当前选中的控制逻辑 */
  81. void toggleSelectedLogicEnabled();
  82. /** 返回当前 HMI 页面标识 */
  83. const std::string &currentHmiPageId() const;
  84. /** 返回当前控制逻辑标识 */
  85. const std::string &currentLogicId() const;
  86. private:
  87. /** 工程树项目的三种业务类型 */
  88. enum class ItemKind
  89. {
  90. Root = 0, // 工程树根节点
  91. HmiPage = 1, // HMI 页面节点
  92. ControlLogic = 2 // 控制逻辑节点
  93. };
  94. /** 处理工程树选择变化并刷新当前编辑器 */
  95. void handleSelectionChanged();
  96. /** 统一报告工程操作失败 */
  97. void reportFailure(
  98. const QString &action, const std::string &message) const;
  99. /** 主窗口父对象,不由控制器拥有 */
  100. QWidget &parent_;
  101. /** 主窗口的 Designer 界面对象 */
  102. Ui::MainWindow &ui_;
  103. /** 工程服务,不由控制器拥有 */
  104. ProjectService &project_service_;
  105. /** HMI 编辑服务,不由控制器拥有 */
  106. HmiEditorService &hmi_editor_service_;
  107. /** 梯形图编辑服务,不由控制器拥有 */
  108. LogicEditorService &logic_editor_service_;
  109. /** 运行模式服务,不由控制器拥有 */
  110. RuntimeModeService &runtime_mode_service_;
  111. /** HMI 页面导航服务,不由控制器拥有 */
  112. HmiNavigationService &hmi_navigation_service_;
  113. /** 主窗口中的 HMI 编辑器 */
  114. HmiEditorWidget &hmi_editor_widget_;
  115. /** 主窗口中的梯形图编辑器 */
  116. LogicEditorWidget &logic_editor_widget_;
  117. /** 运行监控控件 */
  118. RuntimeMonitorWidget &runtime_monitor_widget_;
  119. /** 主窗口保存的当前 HMI 页面标识 */
  120. std::string &current_hmi_page_id_;
  121. /** 主窗口保存的当前控制逻辑标识 */
  122. std::string &current_logic_id_;
  123. /** 显示 HMI 控件属性的回调 */
  124. std::function<void(const std::string &)> show_control_properties_;
  125. /** 显示梯形图节点属性的回调 */
  126. std::function<void(const std::string &)> show_logic_properties_;
  127. /** 工程操作结果回调 */
  128. ResultReporter result_reporter_;
  129. /** 状态栏消息回调 */
  130. StatusReporter status_reporter_;
  131. /** 编辑状态变化回调 */
  132. EditStateChanged edit_state_changed_;
  133. /** 新增页面动作 */
  134. QAction *add_page_action_ = nullptr;
  135. /** 新增逻辑动作 */
  136. QAction *add_logic_action_ = nullptr;
  137. /** 重命名动作 */
  138. QAction *rename_item_action_ = nullptr;
  139. /** 删除工程树项目动作 */
  140. QAction *delete_item_action_ = nullptr;
  141. /** 上移工程树项目动作 */
  142. QAction *move_item_up_action_ = nullptr;
  143. /** 下移工程树项目动作 */
  144. QAction *move_item_down_action_ = nullptr;
  145. /** 设置初始页面动作 */
  146. QAction *set_initial_page_action_ = nullptr;
  147. /** 启停控制逻辑动作 */
  148. QAction *toggle_logic_enabled_action_ = nullptr;
  149. };