85 lines
2.9 KiB
C++
85 lines
2.9 KiB
C++
|
|
#include "ConfigManager.h"
|
|||
|
|
#include "VrLog.h"
|
|||
|
|
#include "VrError.h"
|
|||
|
|
#include "PathManager.h"
|
|||
|
|
|
|||
|
|
// WorkpieceHole 应用的 ConfigManager 实现
|
|||
|
|
// 所有通用功能都在 BaseConfigManager 中实现
|
|||
|
|
// 这里只实现 WorkpieceHole 特定的功能
|
|||
|
|
|
|||
|
|
// 重写 Initialize 以禁用共享内存监控(WorkpieceHoleApp 不需要)
|
|||
|
|
bool ConfigManager::Initialize(const std::string& configFilePath)
|
|||
|
|
{
|
|||
|
|
LOG_INFO("ConfigManager initializing for WorkpieceHoleApp...\n");
|
|||
|
|
|
|||
|
|
// 保存配置文件路径
|
|||
|
|
if (configFilePath.empty()) {
|
|||
|
|
QString defaultPath = PathManager::GetInstance().GetConfigFilePath();
|
|||
|
|
m_configFilePath = defaultPath.toStdString();
|
|||
|
|
} else {
|
|||
|
|
m_configFilePath = configFilePath;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 创建VrConfig实例
|
|||
|
|
if (!IVrConfig::CreateInstance(&m_pVrConfig) || !m_pVrConfig) {
|
|||
|
|
LOG_ERROR("Failed to create VrConfig instance\n");
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 加载配置文件
|
|||
|
|
if (!LoadConfigFromFile(m_configFilePath)) {
|
|||
|
|
LOG_WARNING("Failed to load config file, using default config\n");
|
|||
|
|
_InitializeDefaultConfig();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// WorkpieceHoleApp 不需要共享内存监控,跳过 ConfigMonitor 启动
|
|||
|
|
LOG_INFO("ConfigManager initialized successfully for WorkpieceHoleApp (shared memory disabled)\n");
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 实现 LoadConfigFromFile 以适配 WorkpieceHole 的 IVrConfig API
|
|||
|
|
// WorkpieceHole 使用引用参数方式:int LoadConfig(const std::string& filePath, ConfigResult& configResult)
|
|||
|
|
bool ConfigManager::LoadConfigFromFile(const std::string& filePath)
|
|||
|
|
{
|
|||
|
|
if (!m_pVrConfig) {
|
|||
|
|
LOG_ERROR("VrConfig instance not available\n");
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
try {
|
|||
|
|
ConfigResult configResult;
|
|||
|
|
|
|||
|
|
// WorkpieceHole 使用引用参数方式
|
|||
|
|
int ret = m_pVrConfig->LoadConfig(filePath, configResult);
|
|||
|
|
if (ret != SUCCESS) {
|
|||
|
|
LOG_ERROR("Failed to load config from file: %s, error: %d\n", filePath.c_str(), ret);
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 使用基类的公共逻辑应用配置
|
|||
|
|
return _ApplyLoadedConfig(configResult, filePath);
|
|||
|
|
|
|||
|
|
} catch (const std::exception& e) {
|
|||
|
|
LOG_ERROR("Failed to load configuration from file %s: %s\n", filePath.c_str(), e.what());
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
bool ConfigManager::OnSwitchWorkPositionCommand(const SwitchWorkPositionParam& param)
|
|||
|
|
{
|
|||
|
|
LOG_INFO("WorkpieceHole: Received switch work position command: workPositionId=%s\n", param.workPositionId);
|
|||
|
|
|
|||
|
|
// WorkpieceHole 应用特有的工作点切换逻辑
|
|||
|
|
// 这里需要根据实际需求实现工作点切换
|
|||
|
|
// 可能需要:
|
|||
|
|
// 1. 重新加载不同的配置文件
|
|||
|
|
// 2. 更新算法参数
|
|||
|
|
// 3. 切换检测区域
|
|||
|
|
// 4. 更新标定矩阵
|
|||
|
|
// 5. 通知UI更新
|
|||
|
|
|
|||
|
|
// TODO: 实现具体的工作点切换逻辑
|
|||
|
|
|
|||
|
|
return true;
|
|||
|
|
}
|