119 lines
3.5 KiB
C++
119 lines
3.5 KiB
C++
#ifndef HOLEPITPOSITIONPRESENTER_H
|
||
#define HOLEPITPOSITIONPRESENTER_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 "IYHolePitPositionStatus.h"
|
||
#include "VrConvert.h"
|
||
#include "LaserDataLoader.h"
|
||
#include "CoordinateTransform.h"
|
||
#include <QImage>
|
||
#include <QPainter>
|
||
#include <QColor>
|
||
#include <QObject>
|
||
#include <QTimer>
|
||
#include <memory>
|
||
|
||
// 前向声明
|
||
class DetectPresenter;
|
||
class HolePitPositionPresenter;
|
||
|
||
// 配置变化监听器代理类
|
||
class ConfigChangeListenerProxy : public IConfigChangeListener
|
||
{
|
||
public:
|
||
explicit ConfigChangeListenerProxy(HolePitPositionPresenter* 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:
|
||
HolePitPositionPresenter* m_presenter;
|
||
};
|
||
|
||
class HolePitPositionPresenter : public BasePresenter, public IVrConfigChangeNotify
|
||
{
|
||
Q_OBJECT
|
||
|
||
// 声明友元类,允许访问 protected 成员
|
||
friend class ConfigChangeListenerProxy;
|
||
|
||
public:
|
||
explicit HolePitPositionPresenter(QObject *parent = nullptr);
|
||
~HolePitPositionPresenter();
|
||
|
||
// 初始化
|
||
int InitApp() override;
|
||
|
||
// 获取配置管理器
|
||
ConfigManager* GetConfigManager() { return m_pConfigManager; }
|
||
|
||
// 手眼标定矩阵管理
|
||
CalibMatrix GetClibMatrix(int index) const;
|
||
|
||
// 获取算法版本号
|
||
std::string GetAlgoVersion() 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;
|
||
|
||
// HolePitPosition 不需要 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();
|
||
|
||
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;
|
||
};
|
||
|
||
#endif // HOLEPITPOSITIONPRESENTER_H
|