#0039 全局数据结构设计

This commit is contained in:
zhengxuan.zhang
2026-03-18 20:14:08 +08:00
parent c6144fae89
commit 67898edc3f
19 changed files with 1490 additions and 16 deletions
+44
View File
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace XplorePlane.Models
{
/// <summary>检测配方中的单个步骤</summary>
public record RecipeStep(
int StepIndex,
MotionState MotionState,
RaySourceState RaySourceState,
DetectorState DetectorState,
PipelineModel Pipeline
);
/// <summary>检测配方(CNC 自动编程)</summary>
public record InspectionRecipe(
Guid Id,
string Name,
DateTime CreatedAt,
DateTime UpdatedAt,
IReadOnlyList<RecipeStep> Steps
)
{
/// <summary>追加步骤,返回新的 InspectionRecipe</summary>
public InspectionRecipe AddStep(RecipeStep step) =>
this with
{
Steps = Steps.Append(step).ToList().AsReadOnly(),
UpdatedAt = DateTime.UtcNow
};
}
/// <summary>配方执行状态(不可变)</summary>
public record RecipeExecutionState(
int CurrentStepIndex,
int TotalSteps,
RecipeExecutionStatus Status,
string CurrentRecipeName
)
{
public static readonly RecipeExecutionState Default = new(0, 0, RecipeExecutionStatus.Idle, string.Empty);
}
}
+120
View File
@@ -0,0 +1,120 @@
using System;
namespace XplorePlane.Models
{
// ── Enumerations ──────────────────────────────────────────────────
/// <summary>系统操作模式</summary>
public enum OperationMode
{
Idle, // 空闲
Scanning, // 扫描
CTAcquire, // CT 采集
RecipeRun // 配方执行中
}
/// <summary>配方执行状态</summary>
public enum RecipeExecutionStatus
{
Idle, // 空闲
Running, // 运行中
Paused, // 暂停
Completed, // 已完成
Error // 出错
}
// ── State Records ─────────────────────────────────────────────────
/// <summary>运动控制状态(不可变)</summary>
public record MotionState(
double XM, // X 轴位置 (μm)
double YM, // Y 轴位置 (μm)
double ZT, // Z 上轴位置 (μm)
double ZD, // Z 下轴位置 (μm)
double TiltD, // 倾斜角度 (m°)
double Dist, // 距离 (μm)
double XMSpeed, // X 轴速度 (μm/s)
double YMSpeed, // Y 轴速度 (μm/s)
double ZTSpeed, // Z 上轴速度 (μm/s)
double ZDSpeed, // Z 下轴速度 (μm/s)
double TiltDSpeed, // 倾斜速度 (m°/s)
double DistSpeed // 距离速度 (μm/s)
)
{
public static readonly MotionState Default = new(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
/// <summary>射线源状态(不可变)</summary>
public record RaySourceState(
bool IsOn, // 开关状态
double Voltage, // 电压 (kV)
double Power // 功率 (W)
)
{
public static readonly RaySourceState Default = new(false, 0, 0);
}
/// <summary>探测器状态(不可变)</summary>
public record DetectorState(
bool IsConnected, // 连接状态
bool IsAcquiring, // 是否正在采集
double FrameRate, // 当前帧率 (fps)
string Resolution // 分辨率描述,如 "2048x2048"
)
{
public static readonly DetectorState Default = new(false, false, 0, string.Empty);
}
/// <summary>系统级状态(不可变)</summary>
public record SystemState(
OperationMode OperationMode, // 当前操作模式
bool HasError, // 是否存在系统错误
string ErrorMessage // 错误描述
)
{
public static readonly SystemState Default = new(OperationMode.Idle, false, string.Empty);
}
/// <summary>摄像头视频流状态(不可变)</summary>
public record CameraState(
bool IsConnected, // 连接状态
bool IsStreaming, // 是否正在推流
object CurrentFrame, // 当前帧数据引用(BitmapSource 或 byte[]Frozen
int Width, // 分辨率宽
int Height, // 分辨率高
double FrameRate // 帧率 (fps)
)
{
public static readonly CameraState Default = new(false, false, null, 0, 0, 0);
}
/// <summary>物理坐标</summary>
public record PhysicalPosition(double X, double Y, double Z);
/// <summary>图像标定矩阵,像素坐标 → 物理坐标映射</summary>
public record CalibrationMatrix(
double M11, double M12, double M13, // 3x3 仿射变换矩阵
double M21, double M22, double M23,
double M31, double M32, double M33
)
{
/// <summary>将像素坐标转换为物理坐标</summary>
public (double X, double Y, double Z) Transform(double pixelX, double pixelY)
{
double x = M11 * pixelX + M12 * pixelY + M13;
double y = M21 * pixelX + M22 * pixelY + M23;
double z = M31 * pixelX + M32 * pixelY + M33;
return (x, y, z);
}
}
/// <summary>画面联动状态(不可变)</summary>
public record LinkedViewState(
PhysicalPosition TargetPosition, // 目标物理坐标
bool IsExecuting, // 联动是否正在执行
DateTime LastRequestTime // 最近一次联动请求时间
)
{
public static readonly LinkedViewState Default = new(new PhysicalPosition(0, 0, 0), false, DateTime.MinValue);
}
}