using System.Collections.Generic;
using XP.Hardware.MotionControl.Abstractions;
using XP.Hardware.MotionControl.Abstractions.Enums;
namespace XP.Hardware.MotionControl.Services
{
///
/// 运动控制业务服务接口 | Motion Control Business Service Interface
/// 封装所有运动控制业务规则,供 ViewModel 调用 | Encapsulates all motion control business rules for ViewModel
///
public interface IMotionControlService
{
#region 轮询控制 | Polling Control
///
/// 启动 PLC 状态轮询 | Start PLC status polling
/// 以配置的 PollingInterval 周期执行轮询 | Polls at configured PollingInterval
///
void StartPolling();
///
/// 停止 PLC 状态轮询 | Stop PLC status polling
///
void StopPolling();
#endregion
#region 单轴移动 | Single Axis Move
///
/// 移动直线轴到目标位置 | Move linear axis to target position
/// 包含边界检查和运动中防重入 | Includes boundary check and move-in-progress guard
///
/// 直线轴标识 | Linear axis identifier
/// 目标位置(mm)| Target position (mm)
/// 操作结果 | Operation result
MotionResult MoveToTarget(AxisId axisId, double target, double? speed = null);
///
/// 移动旋转轴到目标角度 | Move rotary axis to target angle
/// 包含边界检查和禁用轴检查 | Includes boundary check and disabled axis check
///
/// 旋转轴标识 | Rotary axis identifier
/// 目标角度(度)| Target angle (degrees)
/// 运动速度(可选,不传则不写入速度信号)| Speed (optional)
/// 操作结果 | Operation result
MotionResult MoveRotaryToTarget(RotaryAxisId axisId, double targetAngle, double? speed = null);
#endregion
#region 多轴联动 | Multi-Axis Coordinated Move
///
/// 多轴联动移动 | Multi-axis coordinated move
/// 对所有目标轴并行执行边界检查,任意轴越界则拒绝整个命令 | Atomic boundary check for all target axes
///
/// 轴标识与目标位置的字典 | Dictionary of axis IDs and target positions
/// 操作结果 | Operation result
MotionResult MoveAllToTarget(Dictionary targets);
///
/// 停止所有已启用轴 | Stop all enabled axes
///
/// 操作结果 | Operation result
MotionResult StopAll();
///
/// 所有已启用轴回零 | Home all enabled axes
///
/// 操作结果 | Operation result
MotionResult HomeAll();
#endregion
#region Jog 控制 | Jog Control
///
/// 直线轴 Jog 启动 | Start linear axis jog
/// Homing 状态下拒绝 Jog 命令 | Rejects jog when axis is homing
///
/// 直线轴标识 | Linear axis identifier
/// 正向为 true,反向为 false | True for positive, false for negative
/// 操作结果 | Operation result
MotionResult JogStart(AxisId axisId, bool positive);
///
/// 直线轴 Jog 停止 | Stop linear axis jog
///
/// 直线轴标识 | Linear axis identifier
/// 操作结果 | Operation result
MotionResult JogStop(AxisId axisId);
///
/// 旋转轴 Jog 启动 | Start rotary axis jog
/// Homing 状态下拒绝 Jog 命令 | Rejects jog when axis is homing
///
/// 旋转轴标识 | Rotary axis identifier
/// 正向为 true,反向为 false | True for positive, false for negative
/// 操作结果 | Operation result
MotionResult JogRotaryStart(RotaryAxisId axisId, bool positive);
///
/// 旋转轴 Jog 停止 | Stop rotary axis jog
///
/// 旋转轴标识 | Rotary axis identifier
/// 操作结果 | Operation result
MotionResult JogRotaryStop(RotaryAxisId axisId);
#endregion
#region 安全门控制 | Safety Door Control
///
/// 开门(含联锁检查)| Open door (with interlock check)
/// 联锁信号有效时拒绝开门 | Rejects when interlock is active
///
/// 操作结果 | Operation result
MotionResult OpenDoor();
///
/// 关门 | Close door
///
/// 操作结果 | Operation result
MotionResult CloseDoor();
///
/// 停止门运动 | Stop door movement
///
/// 操作结果 | Operation result
MotionResult StopDoor();
#endregion
#region 几何计算 | Geometry Calculation
///
/// 获取当前几何参数(正算)| Get current geometry parameters (forward calculation)
/// 根据当前轴位置计算 FOD、FDD 和放大倍率 | Calculates FOD, FDD and magnification from current axis positions
///
/// FOD(mm)、FDD(mm)、放大倍率 | FOD (mm), FDD (mm), Magnification
(double FOD, double FDD, double Magnification) GetCurrentGeometry();
///
/// 应用几何参数(反算,由 FOD 和 FDD)| Apply geometry (inverse, from FOD and FDD)
/// 计算并移动 SourceZ 和 DetectorZ 到目标位置 | Calculates and moves SourceZ and DetectorZ to target positions
///
/// 目标 FOD(mm)| Target FOD (mm)
/// 目标 FDD(mm)| Target FDD (mm)
/// 操作结果 | Operation result
MotionResult ApplyGeometry(double targetFOD, double targetFDD);
///
/// 几何反算(仅计算,不移动)| Geometry inverse calculation (calculate only, no move)
/// 返回 SourceZ 和 DetectorZ 的目标位置 | Returns target positions for SourceZ and DetectorZ
///
/// 目标 FOD(mm)| Target FOD (mm)
/// 目标 FDD(mm)| Target FDD (mm)
/// 成功时返回 (sourceZTarget, detectorZTarget, null),失败时返回 (0, 0, errorMessage) | On success returns targets, on failure returns error
(double SourceZTarget, double DetectorZTarget, string ErrorMessage) CalculateGeometryTargets(double targetFOD, double targetFDD);
///
/// 应用几何参数(反算,由 FOD 和放大倍率)| Apply geometry (inverse, from FOD and magnification)
/// 先计算 FDD = M × FOD,再移动轴 | Calculates FDD = M × FOD, then moves axes
///
/// 目标 FOD(mm)| Target FOD (mm)
/// 目标放大倍率 | Target magnification
/// 操作结果 | Operation result
MotionResult ApplyGeometryByMagnification(double targetFOD, double magnification);
#endregion
}
}