190 lines
6.0 KiB
C
Raw Normal View History

2025-12-27 09:34:02 +08:00
#ifndef WHEELMEASUREPRESENTER_H
#define WHEELMEASUREPRESENTER_H
#include "BasePresenter.h"
#include "IVrWheelMeasureConfig.h"
#include "IWheelMeasureStatus.h"
#include "CommonDialogCameraLevel.h"
#include <QImage>
#include <QString>
#include <QStringList>
/**
* @brief Presenter
* BasePresenter
*/
class WheelMeasurePresenter : public BasePresenter,
public IVrWheelMeasureConfigChangeNotify,
public ICameraLevelCalculator,
public ICameraLevelResultSaver
{
Q_OBJECT
signals:
void configUpdated();
public:
explicit WheelMeasurePresenter(QObject* parent = nullptr);
~WheelMeasurePresenter();
// ============ 实现 BasePresenter 纯虚函数 ============
/**
* @brief
*/
int InitApp() override;
/**
* @brief
*/
int InitAlgoParams() override;
/**
* @brief
*/
int ProcessAlgoDetection(std::vector<std::pair<EVzResultDataType, SVzLaserLineData>>& detectionDataCache) override;
/**
* @brief
*/
EVzResultDataType GetDetectionDataType() override {
return keResultDataType_Position;
}
/**
* @brief
*/
void OnCameraStatusChanged(int cameraIndex, bool isConnected) override;
/**
* @brief
*/
void OnWorkStatusChanged(WorkStatus status) override;
/**
* @brief
*/
void OnCameraCountChanged(int count) override;
/**
* @brief
*/
void OnStatusUpdate(const std::string& statusMessage) override;
/**
* @brief Modbus写寄存器回调
*/
void OnModbusWriteCallback(uint16_t startAddress, const uint16_t* data, uint16_t count) override;
// ============ 实现 ICameraLevelCalculator 接口 ============
bool CalculatePlaneCalibration(
const std::vector<std::pair<EVzResultDataType, SVzLaserLineData>>& scanData,
double planeCalib[9],
double& planeHeight,
double invRMatrix[9]) override;
// ============ 实现 ICameraLevelResultSaver 接口 ============
bool SaveLevelingResults(double planeCalib[9], double planeHeight, double invRMatrix[9],
int cameraIndex, const QString& cameraName) override;
bool LoadLevelingResults(int cameraIndex, const QString& cameraName,
double planeCalib[9], double& planeHeight, double invRMatrix[9]) override;
// ============ IVrWheelMeasureConfigChangeNotify 接口实现 ============
void OnConfigChanged(const WheelMeasureConfigResult& configResult) override;
// ============ 公共接口 ============
/**
* @brief
*/
void setStatusUpdate(IWheelMeasureStatus* statusUpdate) { m_statusUpdate = statusUpdate; }
/**
* @brief
*/
IVrWheelMeasureConfig* GetConfig() const { return m_config; }
/**
* @brief
*/
WheelMeasureConfigResult* GetConfigResult() { return &m_configResult; }
/**
* @brief
*/
QStringList getCameraNames() const;
/**
* @brief
*/
void ResetDetect(int cameraIndex = 0);
/**
* @brief
*/
void StartAllDetection();
/**
* @brief
*/
void StopAllDetection();
/**
* @brief
*/
bool IsSequentialDetecting() const { return m_sequentialDetecting; }
/**
* @brief
*/
void SetDefaultCameraIndex(int cameraIndex) { m_currentCameraIndex = cameraIndex; }
/**
* @brief
*/
int GetDefaultCameraIndex() const { return m_currentCameraIndex; }
/**
* @brief
*/
static void _StaticCameraNotify(EVzDeviceWorkStatus eStatus, void* pExtData, unsigned int nDataLength, void* pInfoParam);
private:
// 初始化配置
bool initializeConfig(const QString& configPath);
// 初始化相机
bool initializeCameras();
// 处理扫描数据
void processScanData(std::vector<std::pair<EVzResultDataType, SVzLaserLineData>>& detectionDataCache);
// 根据相机索引获取调平参数
WheelCameraPlaneCalibParam* getPlaneCalibParam(int cameraIndex);
// 相机状态回调处理
void _CameraNotify(EVzDeviceWorkStatus eStatus, void* pExtData, unsigned int nDataLength, void* pInfoParam);
private:
IVrWheelMeasureConfig* m_config = nullptr;
WheelMeasureConfigResult m_configResult;
IWheelMeasureStatus* m_statusUpdate = nullptr;
int m_currentCameraIndex = 1; // 默认相机索引1-based
// 顺序检测相关
bool m_sequentialDetecting = false; // 是否正在顺序检测所有设备
bool m_stopSequentialRequested = false; // 是否请求停止顺序检测
int m_sequentialCurrentIndex = 0; // 当前顺序检测的设备索引0-based
int m_sequentialTotalCount = 0; // 需要顺序检测的设备总数
// 继续检测下一个设备
void continueSequentialDetection();
};
#endif // WHEELMEASUREPRESENTER_H