using Flyshot.Core.Config; using Flyshot.Core.Domain; namespace Flyshot.ControllerClientCompat; /// /// 根据旧版 ControllerClient 的机器人名称,解析当前 replacement 仓库支持的真实模型文件。 /// public sealed class ControllerClientCompatRobotCatalog { /// /// 保存当前现场支持的机器人名称到运行目录模型文件名映射。 /// private static readonly IReadOnlyDictionary SupportedRobotModelFileMap = new Dictionary(StringComparer.Ordinal) { ["FANUC_LR_Mate_200iD"] = "LR_Mate_200iD_7L.robot", ["FANUC_LR_Mate_200iD_7L"] = "LR_Mate_200iD_7L.robot" }; private readonly ControllerClientCompatOptions _options; private readonly RobotModelLoader _robotModelLoader; /// /// 初始化机器人兼容目录解析器。 /// /// 兼容层基础配置。 /// .robot 文件加载器。 public ControllerClientCompatRobotCatalog( ControllerClientCompatOptions options, RobotModelLoader robotModelLoader) { _options = options ?? throw new ArgumentNullException(nameof(options)); _robotModelLoader = robotModelLoader ?? throw new ArgumentNullException(nameof(robotModelLoader)); } /// /// 根据旧客户端的机器人名称加载对应模型。 /// /// 旧客户端传入的机器人名称。 /// RobotConfig.json 中的加速度倍率。 /// RobotConfig.json 中的 jerk 倍率。 /// 兼容层加载出的机器人模型。 public RobotProfile LoadProfile(string robotName, double accLimitScale = 1.0, double jerkLimitScale = 1.0) { if (string.IsNullOrWhiteSpace(robotName)) { throw new ArgumentException("机器人名称不能为空。", nameof(robotName)); } if (!SupportedRobotModelFileMap.TryGetValue(robotName, out var modelFileName)) { throw new InvalidOperationException($"Unsupported robot name: {robotName}"); } var modelPath = ResolveModelPath(modelFileName); return _robotModelLoader.LoadProfile(modelPath, accLimitScale, jerkLimitScale); } /// /// 解析机器人模型路径,运行目录 Config/Models 优先,旧父工作区只作为显式兼容入口。 /// /// 运行目录 Models 下的机器人模型文件名。 /// 可传给 .robot 加载器的模型文件绝对路径。 private string ResolveModelPath(string modelFileName) { var configModelPath = Path.Combine(_options.ResolveConfigRoot(), "Models", modelFileName); if (File.Exists(configModelPath)) { return configModelPath; } var legacyWorkspaceRoot = _options.ResolveLegacyWorkspaceRoot(); if (legacyWorkspaceRoot is not null) { return Path.Combine(legacyWorkspaceRoot, "FlyingShot", "FlyingShot", "Models", modelFileName); } return configModelPath; } }