|
- /**
- * @file runtime_monitor_widget.h
- * @brief 定义工程师运行监控主控件
- * @version 1.0.0
- * @author suyu
- * @date 2026-08-22
- */
-
- #pragma once
-
- #include "domain/runtime_state.h"
- #include "services/plc_communication_gateway.h"
- #include "services/software_logic_executor.h"
-
- #include <QWidget>
-
- #include <memory>
- #include <string>
-
- namespace Ui {
- class RuntimeMonitorWidget;
- }
-
- class FreeMonitorWidget;
- class HmiEditorService;
- class HmiEditorWidget;
- class HmiRuntimeService;
- class AlarmService;
- class HmiNavigationService;
- class LogicEditorService;
- class LogicEditorWidget;
- class RegisterMonitorService;
- class ProjectService;
-
- /** 运行监控投影,普通模式组合 HMI/梯形图/自由监控,运行版仅保留 HMI */
- class RuntimeMonitorWidget final : public QWidget
- {
- Q_OBJECT
-
- public:
- /** 创建组合 HMI、梯形图和自由监控的运行投影 */
- RuntimeMonitorWidget(
- HmiEditorService &hmi_editor_service,
- HmiRuntimeService &hmi_runtime_service,
- LogicEditorService &logic_editor_service,
- ProjectService &project_service,
- HmiNavigationService &hmi_navigation_service,
- AlarmService &alarm_service,
- RegisterMonitorService ®ister_monitor_service,
- QWidget *parent = nullptr);
- /** 释放组合的运行监控子控件 */
- ~RuntimeMonitorWidget() override;
-
- /** 将当前页面和控制逻辑绑定到运行监控界面 */
- void setProjectObjects(const std::string &page_id, const std::string &logic_id);
- /** 切换运行监控中显示的 HMI 页面 */
- void setRuntimePage(const std::string &page_id);
- /** 根据模式决定是否显示本地逻辑轨迹以及是否允许写入 */
- void setMode(ApplicationMode mode, PlcConnectionState plc_state);
- /** 切换 HMI 专用用户运行版的界面模式 */
- void setHmiOnlyRuntime(bool enabled);
- /** 从寄存器仓库刷新 HMI 和自由监控中的当前值 */
- void refreshValues(ApplicationMode mode, PlcConnectionState plc_state);
- /** 设置 HMI 控件是否允许写入运行值 */
- void setHmiWriteEnabled(bool enabled);
- /** 设置自由监控是否允许写入寄存器 */
- void setFreeMonitorWriteEnabled(bool enabled);
- /** 接收离线轨迹或基于 PLC 缓存计算的真机本地推算轨迹 */
- void setLogicTrace(const LogicTraceSnapshot &trace, const std::string &fault_node_id = {});
- /** 返回自由监控子控件,供上层刷新或连接信号 */
- FreeMonitorWidget *freeMonitorWidget() const;
- /** 返回当前选中的控制逻辑标识 */
- std::string selectedLogicId() const;
-
- signals:
- /** 页面跳转失败时发出可直接显示的错误信息 */
- void navigationFailed(const QString &message);
- /** 用户请求退出运行态 */
- void exitRequested();
- /** 用户在专用运行版中请求切换模式 */
- void modeChangeRequested(int mode);
-
- private:
- /** 显示指定的运行监控页面 */
- void showRuntimePage(const std::string &page_id);
- /** 选中指定控制逻辑并刷新梯形图投影 */
- void selectRuntimeLogic(const std::string &logic_id);
-
- /** Qt Designer 生成的界面对象 */
- std::unique_ptr<Ui::RuntimeMonitorWidget> ui_;
- /** 工程服务,不由控件拥有 */
- ProjectService &project_service_;
- /** HMI 页面导航服务,不由控件拥有 */
- HmiNavigationService &hmi_navigation_service_;
- /** 运行监控中的 HMI 视图 */
- HmiEditorWidget *hmi_view_ = nullptr;
- /** 运行监控中的梯形图视图 */
- LogicEditorWidget *logic_view_ = nullptr;
- /** 运行监控中的自由监控控件 */
- FreeMonitorWidget *free_monitor_widget_ = nullptr;
- /** 当前选中的控制逻辑标识 */
- std::string selected_logic_id_;
- /** 最近一次收到的本地逻辑执行轨迹 */
- LogicTraceSnapshot latest_trace_;
- /** 最近一次本地执行故障节点标识 */
- std::string latest_fault_node_id_;
- /** 是否已经收到过可显示的逻辑轨迹 */
- bool has_logic_trace_ = false;
- /** 是否只显示 HMI 页面并隐藏所有诊断区域 */
- bool hmi_only_mode_ = false;
- };
|