133 lines
4.0 KiB
C++
133 lines
4.0 KiB
C++
#ifndef HOLEDETECTIONPRESENTER_H
|
||
#define HOLEDETECTIONPRESENTER_H
|
||
|
||
#include <condition_variable>
|
||
#include <thread>
|
||
#include <map>
|
||
#include <mutex>
|
||
#include <memory>
|
||
|
||
#include "BasePresenter.h"
|
||
#include "IVrEyeDevice.h"
|
||
#include "ConfigManager.h"
|
||
#include "TCPServerProtocol.h"
|
||
#include "IYHoleDetectionStatus.h"
|
||
#include "VrConvert.h"
|
||
#include "LaserDataLoader.h"
|
||
#include "CoordinateTransform.h"
|
||
#if 0 // PLC Modbus 功能已禁用
|
||
#include "PLCModbusClient.h"
|
||
#endif
|
||
#include <QImage>
|
||
#include <QPainter>
|
||
#include <QColor>
|
||
#include <QObject>
|
||
#include <QTimer>
|
||
#include <memory>
|
||
|
||
// Forward declarations
|
||
class DetectPresenter;
|
||
class HoleDetectionPresenter;
|
||
|
||
// 配置变化监听器代理类
|
||
class ConfigChangeListenerProxy : public IConfigChangeListener
|
||
{
|
||
public:
|
||
explicit ConfigChangeListenerProxy(HoleDetectionPresenter* presenter) : m_presenter(presenter) {}
|
||
|
||
void OnSystemConfigChanged(const SystemConfig& config) override;
|
||
void OnCameraParamChanged(int cameraIndex, const CameraUIParam& cameraParam) override {}
|
||
void OnAlgorithmParamChanged(const VrAlgorithmParams& algorithmParams) override {}
|
||
|
||
private:
|
||
HoleDetectionPresenter* m_presenter;
|
||
};
|
||
|
||
class HoleDetectionPresenter : public BasePresenter, public IVrConfigChangeNotify
|
||
{
|
||
Q_OBJECT
|
||
|
||
// 声明友元类,允许访问 protected 成员
|
||
friend class ConfigChangeListenerProxy;
|
||
|
||
public:
|
||
explicit HoleDetectionPresenter(QObject *parent = nullptr);
|
||
~HoleDetectionPresenter();
|
||
|
||
// 初始化
|
||
int InitApp() override;
|
||
|
||
// 获取配置管理器
|
||
ConfigManager* GetConfigManager() { return m_pConfigManager; }
|
||
|
||
// 手眼标定矩阵管理
|
||
CalibMatrix GetClibMatrix(int index) const;
|
||
|
||
// 实现IVrConfigChangeNotify接口
|
||
virtual void OnConfigChanged(const ConfigResult& configResult) override;
|
||
|
||
protected:
|
||
// ============ 实现 BasePresenter 纯虚函数 ============
|
||
|
||
int InitAlgoParams() override;
|
||
|
||
int ProcessAlgoDetection(std::vector<std::pair<EVzResultDataType, SVzLaserLineData>>& detectionDataCache) override;
|
||
|
||
EVzResultDataType GetDetectionDataType() override {
|
||
return keResultDataType_Position;
|
||
}
|
||
|
||
void OnCameraStatusChanged(int cameraIndex, bool isConnected) override;
|
||
void OnWorkStatusChanged(WorkStatus status) override;
|
||
void OnCameraCountChanged(int count) override;
|
||
void OnStatusUpdate(const std::string& statusMessage) override;
|
||
|
||
// HoleDetection 不需要 ModbusTCP 服务器(使用 TCPServerProtocol 通信)
|
||
bool ShouldStartModbusServer() const override { return false; }
|
||
|
||
private:
|
||
// TCP服务器相关方法
|
||
int InitTCPServer();
|
||
void OnTCPConnectionChanged(bool connected);
|
||
bool OnTCPDetectionTrigger(int cameraIndex, const RobotFlangePose& robotPose);
|
||
void _SendDetectionResultToTCP(const HoleDetectionResult& detectionResult, int cameraIndex);
|
||
|
||
// 连接状态检查和更新
|
||
void CheckAndUpdateWorkStatus();
|
||
|
||
// PLC Modbus 相关方法(已禁用)
|
||
#if 0
|
||
int InitPLCModbus();
|
||
void OnPLCPhotoRequested(int cameraIndex);
|
||
void SendCoordinateDataToPLC(const HoleDetectionResult& result);
|
||
#endif
|
||
|
||
private:
|
||
ConfigManager* m_pConfigManager = nullptr;
|
||
|
||
// TCP服务器相关
|
||
TCPServerProtocol* m_pTCPServer = nullptr;
|
||
bool m_bTCPConnected = false;
|
||
|
||
// 检测处理器
|
||
DetectPresenter* m_pDetectPresenter = nullptr;
|
||
|
||
// 手眼标定矩阵列表
|
||
std::vector<CalibMatrix> m_clibMatrixList;
|
||
|
||
// 当前机器人法兰位姿(从TCP触发信号中获取)
|
||
RobotFlangePose m_currentRobotPose;
|
||
|
||
// 配置变化监听器代理
|
||
std::shared_ptr<ConfigChangeListenerProxy> m_pConfigListener;
|
||
|
||
// PLC Modbus 客户端(已禁用)
|
||
#if 0
|
||
PLCModbusClient* m_pPLCModbusClient = nullptr;
|
||
bool m_bPLCConnected = false;
|
||
bool m_bRobotConnected = false;
|
||
#endif
|
||
};
|
||
|
||
#endif // HOLEDETECTIONPRESENTER_H
|