Commit c941d69b LN

偏移角度可以配置小数。

1 个父辈 8e4e5914
...@@ -554,7 +554,7 @@ namespace TSA_V.DeviceLibrary ...@@ -554,7 +554,7 @@ namespace TSA_V.DeviceLibrary
{ {
public PcbOffsetInfo() { } public PcbOffsetInfo() { }
public PcbOffsetInfo(int x, int y, int a) public PcbOffsetInfo(int x, int y, double a)
{ {
this.X = x; this.X = x;
this.Y = y; this.Y = y;
...@@ -565,14 +565,13 @@ namespace TSA_V.DeviceLibrary ...@@ -565,14 +565,13 @@ namespace TSA_V.DeviceLibrary
public int Y { get; set; } public int Y { get; set; }
public int A { get; set; } public double A { get; set; }
} }
// 兼容旧版数据格式的转换器:支持字符串 "x, y"、数组 [x,y,(a)]、对象 {X:x,Y:y,A:a}
public class PcbOffsetInfoConverter : JsonConverter<PcbOffsetInfo> public class PcbOffsetInfoConverter : JsonConverter<PcbOffsetInfo>
{ {
// 序列化:将 A 保留一位小数输出
public override void WriteJson(JsonWriter writer, PcbOffsetInfo value, JsonSerializer serializer) public override void WriteJson(JsonWriter writer, PcbOffsetInfo value, JsonSerializer serializer)
{ {
if (value == null) if (value == null)
...@@ -586,10 +585,12 @@ namespace TSA_V.DeviceLibrary ...@@ -586,10 +585,12 @@ namespace TSA_V.DeviceLibrary
writer.WritePropertyName("Y"); writer.WritePropertyName("Y");
writer.WriteValue(value.Y); writer.WriteValue(value.Y);
writer.WritePropertyName("A"); writer.WritePropertyName("A");
writer.WriteValue(value.A); // 关键:保留一位小数(四舍五入)
writer.WriteValue(Math.Round(value.A, 1));
writer.WriteEndObject(); writer.WriteEndObject();
} }
// 反序列化:适配不同格式的 A(支持 int/string/float 转 double)
public override PcbOffsetInfo ReadJson(JsonReader reader, Type objectType, PcbOffsetInfo existingValue, bool hasExistingValue, JsonSerializer serializer) public override PcbOffsetInfo ReadJson(JsonReader reader, Type objectType, PcbOffsetInfo existingValue, bool hasExistingValue, JsonSerializer serializer)
{ {
if (reader.TokenType == JsonToken.Null) if (reader.TokenType == JsonToken.Null)
...@@ -601,57 +602,81 @@ namespace TSA_V.DeviceLibrary ...@@ -601,57 +602,81 @@ namespace TSA_V.DeviceLibrary
{ {
switch (reader.TokenType) switch (reader.TokenType)
{ {
// 1. 处理字符串格式(如 "x, y, a")
case JsonToken.String: case JsonToken.String:
{ {
string s = (reader.Value as string) ?? string.Empty; string s = (reader.Value as string) ?? string.Empty;
var parts = s.Split(new[] { ',', ';', ' ' }, StringSplitOptions.RemoveEmptyEntries) var parts = s.Split(new[] { ',', ';', ' ' }, StringSplitOptions.RemoveEmptyEntries)
.Select(p => p.Trim()).ToArray(); .Select(p => p.Trim()).ToArray();
// X/Y 仍按 int 解析
int x = parts.Length > 0 && int.TryParse(parts[0], out var xi) ? xi : 0; int x = parts.Length > 0 && int.TryParse(parts[0], out var xi) ? xi : 0;
int y = parts.Length > 1 && int.TryParse(parts[1], out var yi) ? yi : 0; int y = parts.Length > 1 && int.TryParse(parts[1], out var yi) ? yi : 0;
int a = parts.Length > 2 && int.TryParse(parts[2], out var ai) ? ai : 0; // 关键:A 改为 double 解析,保留一位小数
double a = parts.Length > 2 && double.TryParse(parts[2], out var ai)
? Math.Round(ai, 1)
: 0.0;
return new PcbOffsetInfo(x, y, a); return new PcbOffsetInfo(x, y, a);
} }
// 2. 处理数组格式(如 [x, y, a])
case JsonToken.StartArray: case JsonToken.StartArray:
{ {
var arr = JArray.Load(reader); var arr = JArray.Load(reader);
int x = arr.Count > 0 ? SafeInt(arr[0]) : 0; int x = arr.Count > 0 ? SafeInt(arr[0]) : 0;
int y = arr.Count > 1 ? SafeInt(arr[1]) : 0; int y = arr.Count > 1 ? SafeInt(arr[1]) : 0;
int a = arr.Count > 2 ? SafeInt(arr[2]) : 0; // 关键:A 用 SafeDouble 解析,保留一位小数
return new PcbOffsetInfo(x, y, a); double a = arr.Count > 2 ? SafeDouble(arr[2]) : 0.0;
return new PcbOffsetInfo(x, y, Math.Round(a, 1));
} }
// 3. 处理对象格式(如 {X:x, Y:y, A:a})
case JsonToken.StartObject: case JsonToken.StartObject:
{ {
var obj = JObject.Load(reader); var obj = JObject.Load(reader);
int x = SafeInt(obj["X"] ?? obj["x"]); int x = SafeInt(obj["X"] ?? obj["x"]);
int y = SafeInt(obj["Y"] ?? obj["y"]); int y = SafeInt(obj["Y"] ?? obj["y"]);
int a = SafeInt(obj["A"] ?? obj["a"]); // 关键:A 解析支持大小写键,保留一位小数
return new PcbOffsetInfo(x, y, a); double a = SafeDouble(obj["A"] ?? obj["a"]);
return new PcbOffsetInfo(x, y, Math.Round(a, 1));
} }
// 4. 处理单值格式(极少场景,视为 X,Y=0,A=0.0)
case JsonToken.Integer: case JsonToken.Integer:
case JsonToken.Float: case JsonToken.Float:
{ {
// 单值时,视为 X,Y/A = 0(极少出现,做兜底)
int x = Convert.ToInt32(reader.Value); int x = Convert.ToInt32(reader.Value);
return new PcbOffsetInfo(x, 0, 0); return new PcbOffsetInfo(x, 0, 0.0);
} }
default: default:
return new PcbOffsetInfo(0, 0, 0); return new PcbOffsetInfo(0, 0, 0.0);
} }
} }
catch catch
{ {
// 解析失败兜底,避免导入中断 // 解析失败兜底:A 设为 0.0
return new PcbOffsetInfo(0, 0, 0); return new PcbOffsetInfo(0, 0, 0.0);
} }
} }
// 原有:安全解析 int(不变)
private static int SafeInt(JToken t) private static int SafeInt(JToken t)
{ {
if (t == null) return 0; if (t == null) return 0;
if (t.Type == JTokenType.Integer) return (int)t; if (t.Type == JTokenType.Integer) return (int)t;
if (t.Type == JTokenType.Float) return (int)((double)t); if (t.Type == JTokenType.Float) return (int)Math.Round((double)t);
if (t.Type == JTokenType.String && int.TryParse((string)t, out var v)) return v; if (t.Type == JTokenType.String && int.TryParse((string)t, out var v)) return v;
return 0; return 0;
} }
// 新增:安全解析 double(适配 A 的 double 类型)
private static double SafeDouble(JToken t)
{
if (t == null) return 0.0;
if (t.Type == JTokenType.Integer) return (double)t; // int 转 double(如 5 → 5.0)
if (t.Type == JTokenType.Float) return (double)t; // 直接取 float/double 值(如 3.14 → 3.14)
if (t.Type == JTokenType.String && double.TryParse((string)t, out var v)) return v; // 字符串转 double(如 "2.5" → 2.5)
return 0.0;
}
} }
} }
...@@ -308,7 +308,7 @@ namespace TSA_V.DeviceLibrary ...@@ -308,7 +308,7 @@ namespace TSA_V.DeviceLibrary
// 默认按均匀间距计算 // 默认按均匀间距计算
int dx = (currC - 1) * pcbColValue; int dx = (currC - 1) * pcbColValue;
int dy = (currR - 1) * pcbRowValue; int dy = (currR - 1) * pcbRowValue;
int dA = 0;//默认角度都是0 double dA = 0;//默认角度都是0
// 若设置了某个PCB相对PCB1的偏移,则覆盖默认值 // 若设置了某个PCB相对PCB1的偏移,则覆盖默认值
try try
{ {
...@@ -449,7 +449,7 @@ namespace TSA_V.DeviceLibrary ...@@ -449,7 +449,7 @@ namespace TSA_V.DeviceLibrary
// 默认按均匀间距计算 // 默认按均匀间距计算
int dx = (currC - 1) * pcbColValue; int dx = (currC - 1) * pcbColValue;
int dy = (currR - 1) * pcbRowValue; int dy = (currR - 1) * pcbRowValue;
int dA = 0; double dA = 0;
// 若设置了某个PCB相对PCB1的偏移,则覆盖默认值 // 若设置了某个PCB相对PCB1的偏移,则覆盖默认值
try try
{ {
......
...@@ -307,6 +307,7 @@ namespace TSA_V ...@@ -307,6 +307,7 @@ namespace TSA_V
// 如果有单独设置,则使用已设置的值 // 如果有单独设置,则使用已设置的值
int showDx = defDx; int showDx = defDx;
int showDy = defDy; int showDy = defDy;
double showA = 0;
try try
{ {
if (currBoardInfo != null) if (currBoardInfo != null)
...@@ -315,10 +316,12 @@ namespace TSA_V ...@@ -315,10 +316,12 @@ namespace TSA_V
if (index == 1) if (index == 1)
{ {
showDx = 0; showDy = 0; // PCB1 固定为(0,0) showDx = 0; showDy = 0; // PCB1 固定为(0,0)
showA = 0;
} }
else if (p.X != 0 || p.Y != 0) else if (p.X != 0 || p.Y != 0)
{ {
showDx = p.X; showDy = p.Y; showDx = p.X; showDy = p.Y;
showA = p.A;
} }
} }
} }
...@@ -330,7 +333,7 @@ namespace TSA_V ...@@ -330,7 +333,7 @@ namespace TSA_V
lblPcbInfo.Margin = new Padding(6); lblPcbInfo.Margin = new Padding(6);
lblPcbInfo.AutoSize = false; lblPcbInfo.AutoSize = false;
lblPcbInfo.Font = new Font("微软雅黑", 12f, FontStyle.Bold); lblPcbInfo.Font = new Font("微软雅黑", 12f, FontStyle.Bold);
lblPcbInfo.Text = $"PCB{index}({showDx},{showDy})"; lblPcbInfo.Text = $"PCB{index}(X={showDx},Y={showDy},A={Math.Round(showA,1)})";
lblPcbInfo.Tag = index; lblPcbInfo.Tag = index;
lblPcbInfo.Cursor = Cursors.Hand; lblPcbInfo.Cursor = Cursors.Hand;
lblPcbInfo.Click += LabelPcb_Click; lblPcbInfo.Click += LabelPcb_Click;
...@@ -386,7 +389,7 @@ namespace TSA_V ...@@ -386,7 +389,7 @@ namespace TSA_V
int defDy = r0 * rowGap; int defDy = r0 * rowGap;
int currDx = defDx; int currDx = defDx;
int currDy = defDy; int currDy = defDy;
int currDA = 0; double currDA = 0;
try try
{ {
var p = currBoardInfo.GetPCBOffsetPoint(index); var p = currBoardInfo.GetPCBOffsetPoint(index);
...@@ -405,10 +408,10 @@ namespace TSA_V ...@@ -405,10 +408,10 @@ namespace TSA_V
{ {
int x = dlg.OffsetX; int x = dlg.OffsetX;
int y = dlg.OffsetY; int y = dlg.OffsetY;
int a = dlg.OffsetA; double a = dlg.OffsetA;
currBoardInfo.SetPCBOffset(index, new PcbOffsetInfo(x, y, a)); currBoardInfo.SetPCBOffset(index, new PcbOffsetInfo(x, y, a));
// 更新标签显示 // 更新标签显示
lbl.Text = $"PCB{index}(A={x},Y={y},A={a})"; lbl.Text = $"PCB{index}(X={x},Y={y},A={Math.Round(a,1)})";
try try
{ {
if (FrmProjectorScreen.instance != null) if (FrmProjectorScreen.instance != null)
......
...@@ -132,18 +132,19 @@ namespace TSA_V.frmBoard ...@@ -132,18 +132,19 @@ namespace TSA_V.frmBoard
// //
// numA // numA
// //
this.numA.DecimalPlaces = 1;
this.numA.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.numA.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.numA.Location = new System.Drawing.Point(158, 104); this.numA.Increment = new decimal(new int[] {
this.numA.Maximum = new decimal(new int[] { 5,
100000,
0, 0,
0, 0,
0}); 65536});
this.numA.Minimum = new decimal(new int[] { this.numA.Location = new System.Drawing.Point(158, 104);
100000, this.numA.Maximum = new decimal(new int[] {
36000,
0, 0,
0, 0,
-2147483648}); 131072});
this.numA.Name = "numA"; this.numA.Name = "numA";
this.numA.Size = new System.Drawing.Size(160, 23); this.numA.Size = new System.Drawing.Size(160, 23);
this.numA.TabIndex = 7; this.numA.TabIndex = 7;
......
...@@ -8,13 +8,13 @@ namespace TSA_V.frmBoard ...@@ -8,13 +8,13 @@ namespace TSA_V.frmBoard
public int OffsetX { get; private set; } public int OffsetX { get; private set; }
public int OffsetY { get; private set; } public int OffsetY { get; private set; }
public int OffsetA{get;private set; } //角度 public double OffsetA{get;private set; } //角度
private readonly int pcbIndex; private readonly int pcbIndex;
private readonly int defaultX; private readonly int defaultX;
private readonly int defaultY; private readonly int defaultY;
private readonly int defaultA; private readonly double defaultA;
public FrmPCbOffsetConfig(int pcbIndex, int defaultX, int defaultY,int defaultA) public FrmPCbOffsetConfig(int pcbIndex, int defaultX, int defaultY,double defaultA)
{ {
this.pcbIndex = pcbIndex; this.pcbIndex = pcbIndex;
this.defaultX = defaultX; this.defaultX = defaultX;
...@@ -27,7 +27,7 @@ namespace TSA_V.frmBoard ...@@ -27,7 +27,7 @@ namespace TSA_V.frmBoard
{ {
numX.Value = defaultX; numX.Value = defaultX;
numY.Value = defaultY; numY.Value = defaultY;
numA.Value = defaultA; numA.Value =(decimal) defaultA;
} }
catch { } catch { }
...@@ -37,7 +37,7 @@ namespace TSA_V.frmBoard ...@@ -37,7 +37,7 @@ namespace TSA_V.frmBoard
{ {
OffsetX = (int)numX.Value; OffsetX = (int)numX.Value;
OffsetY = (int)numY.Value; OffsetY = (int)numY.Value;
OffsetA = (int)numA.Value; OffsetA =Math.Round( (double)numA.Value,1);
this.DialogResult = DialogResult.OK; this.DialogResult = DialogResult.OK;
this.Close(); this.Close();
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!