using LiteDB; namespace HardwareControl.Core.Scanning { /// 一次扫描的整体状态。 public enum ScanStatus { Running = 0, Completed = 1, Aborted = 2, Failed = 3, } /// 扫描流程当前所处阶段。 public enum ScanPhase { Idle = 0, Homing = 1, Moving = 2, Focusing = 3, Acquiring = 4, Returning = 5, Analyzing = 6, Writing = 7, Completed = 8, Aborted = 9, Failed = 10, } /// 实时进度快照,通过 SignalR 推送给前端。 public sealed record ScanProgress( string ScanId, ScanPhase Phase, int PointIndex, int TotalPoints, int CompletedPoints, int Percent, string Message, int StageX, int StageY, bool StageMoving, DateTimeOffset UpdatedAt); /// 启动扫描的返回结果。 public sealed record ScanStartResult(string ScanId, int TotalPoints); /// 位移台实时位置。 public sealed record StagePosition( int X, int Y, int Z, bool Moving, DateTimeOffset UpdatedAt); /// 扫描结束事件。 public sealed record ScanRunSummary(string ScanId, ScanStatus Status, string? Error); /// 单个采样点采集完成事件(携带拼接光谱,用于实时绘图)。 public sealed record ScanPointAcquired( string ScanId, int PointIndex, int TotalPoints, float[] Wavelengths, float[] Spectrum, IReadOnlyList Segments, DateTimeOffset AcquiredAt); /// 扫描运行的持久化记录。 public sealed class ScanRunRecord { [BsonId] public string ScanId { get; set; } = string.Empty; public DateTimeOffset StartedAt { get; set; } public DateTimeOffset? FinishedAt { get; set; } public ScanStatus Status { get; set; } public string? Error { get; set; } public int TotalPoints { get; set; } public int CompletedPoints { get; set; } /// 传给光谱仪的曝光时间(微秒)。 public int ExposureUs { get; set; } public int Averaging { get; set; } public int DelayUs { get; set; } public int WaitTimeoutMs { get; set; } public int MoveSpeed { get; set; } public int MoveAccel { get; set; } /// 比例尺(像素/毫米)。 public double CameraScale { get; set; } public double CameraOffsetX { get; set; } public double CameraOffsetY { get; set; } public int ImageWidth { get; set; } public int ImageHeight { get; set; } /// 带采样点标注的靶面图。 public byte[]? ImageData { get; set; } public string? ImageMimeType { get; set; } } /// 单个采样点的持久化记录。 public sealed class ScanPointRecord { [BsonId] public int Id { get; set; } public string ScanId { get; set; } = string.Empty; /// 从 0 开始的点序号。 public int Index { get; set; } public int PixelX { get; set; } public int PixelY { get; set; } public int StageX { get; set; } public int StageY { get; set; } public bool Succeeded { get; set; } public string? Error { get; set; } public float[] Wavelengths { get; set; } = Array.Empty(); public float[] Spectrum { get; set; } = Array.Empty(); public ScanSegmentRecord[] Segments { get; set; } = Array.Empty(); public List Elements { get; set; } = new(); public double Temperature { get; set; } public double ElectronDensity { get; set; } public DateTimeOffset AcquiredAt { get; set; } } /// 拼接光谱的段信息。 public sealed class ScanSegmentRecord { public int DeviceIndex { get; set; } public string SerialNumber { get; set; } = string.Empty; public double WavelengthStart { get; set; } public double WavelengthEnd { get; set; } public int PointCount { get; set; } } /// 单个元素的定性/定量结果。 public sealed class ScanElementRecord { public string Symbol { get; set; } = string.Empty; public string Name { get; set; } = string.Empty; /// 高 / 中 / 低。 public string IntensityLevel { get; set; } = string.Empty; public double Abundance { get; set; } public double RawAbundance { get; set; } /// 检出 / 痕量。 public string Verdict { get; set; } = string.Empty; /// 该元素匹配谱线中的最大强度。 public double MaxIntensity { get; set; } /// 最强匹配谱线在原始光谱中的峰位(nm)。 public double MatchedWavelength { get; set; } public int MatchedLines { get; set; } } }