Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
李娜
/
Line-Smart-Workstation
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 8e4e5914
由
LN
编写于
2025-11-05 21:19:51 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
PcbOffsetInfo增加json处理
1 个父辈
fdc8b6d2
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
90 行增加
和
1 行删除
DeviceLibrary/bean/BoardInfo.cs
DeviceLibrary/manager/XYConvertManager.cs
DeviceLibrary/bean/BoardInfo.cs
查看文件 @
8e4e591
...
@@ -9,6 +9,8 @@ using System.Threading.Tasks;
...
@@ -9,6 +9,8 @@ using System.Threading.Tasks;
using
System.Windows.Forms
;
using
System.Windows.Forms
;
using
TSA_V.LoadCSVLibrary
;
using
TSA_V.LoadCSVLibrary
;
using
System.Reflection
;
using
System.Reflection
;
using
Newtonsoft.Json
;
using
Newtonsoft.Json.Linq
;
namespace
TSA_V.DeviceLibrary
namespace
TSA_V.DeviceLibrary
{
{
...
@@ -98,6 +100,7 @@ namespace TSA_V.DeviceLibrary
...
@@ -98,6 +100,7 @@ namespace TSA_V.DeviceLibrary
public
void
SetPCBOffset
(
int
pcbIndex
,
PcbOffsetInfo
value
)
public
void
SetPCBOffset
(
int
pcbIndex
,
PcbOffsetInfo
value
)
{
{
mPCbOffsetMap
[
pcbIndex
]
=
value
;
mPCbOffsetMap
[
pcbIndex
]
=
value
;
LogUtil
.
info
(
"boardName="
+
boardName
+
", SetPCBOffset: pcbIndex="
+
pcbIndex
+
", value="
+
value
.
ToString
());
}
}
public
int
PointColor
=
Color
.
White
.
ToArgb
();
public
int
PointColor
=
Color
.
White
.
ToArgb
();
...
@@ -546,6 +549,7 @@ namespace TSA_V.DeviceLibrary
...
@@ -546,6 +549,7 @@ namespace TSA_V.DeviceLibrary
public
long
uTime
;
public
long
uTime
;
}
}
[
JsonConverter
(
typeof
(
PcbOffsetInfoConverter
))]
public
class
PcbOffsetInfo
public
class
PcbOffsetInfo
{
{
...
@@ -565,4 +569,89 @@ namespace TSA_V.DeviceLibrary
...
@@ -565,4 +569,89 @@ namespace TSA_V.DeviceLibrary
}
}
// 兼容旧版数据格式的转换器:支持字符串 "x, y"、数组 [x,y,(a)]、对象 {X:x,Y:y,A:a}
public
class
PcbOffsetInfoConverter
:
JsonConverter
<
PcbOffsetInfo
>
{
public
override
void
WriteJson
(
JsonWriter
writer
,
PcbOffsetInfo
value
,
JsonSerializer
serializer
)
{
if
(
value
==
null
)
{
writer
.
WriteNull
();
return
;
}
writer
.
WriteStartObject
();
writer
.
WritePropertyName
(
"X"
);
writer
.
WriteValue
(
value
.
X
);
writer
.
WritePropertyName
(
"Y"
);
writer
.
WriteValue
(
value
.
Y
);
writer
.
WritePropertyName
(
"A"
);
writer
.
WriteValue
(
value
.
A
);
writer
.
WriteEndObject
();
}
public
override
PcbOffsetInfo
ReadJson
(
JsonReader
reader
,
Type
objectType
,
PcbOffsetInfo
existingValue
,
bool
hasExistingValue
,
JsonSerializer
serializer
)
{
if
(
reader
.
TokenType
==
JsonToken
.
Null
)
{
return
null
;
}
try
{
switch
(
reader
.
TokenType
)
{
case
JsonToken
.
String
:
{
string
s
=
(
reader
.
Value
as
string
)
??
string
.
Empty
;
var
parts
=
s
.
Split
(
new
[]
{
','
,
';'
,
' '
},
StringSplitOptions
.
RemoveEmptyEntries
)
.
Select
(
p
=>
p
.
Trim
()).
ToArray
();
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
a
=
parts
.
Length
>
2
&&
int
.
TryParse
(
parts
[
2
],
out
var
ai
)
?
ai
:
0
;
return
new
PcbOffsetInfo
(
x
,
y
,
a
);
}
case
JsonToken
.
StartArray
:
{
var
arr
=
JArray
.
Load
(
reader
);
int
x
=
arr
.
Count
>
0
?
SafeInt
(
arr
[
0
])
:
0
;
int
y
=
arr
.
Count
>
1
?
SafeInt
(
arr
[
1
])
:
0
;
int
a
=
arr
.
Count
>
2
?
SafeInt
(
arr
[
2
])
:
0
;
return
new
PcbOffsetInfo
(
x
,
y
,
a
);
}
case
JsonToken
.
StartObject
:
{
var
obj
=
JObject
.
Load
(
reader
);
int
x
=
SafeInt
(
obj
[
"X"
]
??
obj
[
"x"
]);
int
y
=
SafeInt
(
obj
[
"Y"
]
??
obj
[
"y"
]);
int
a
=
SafeInt
(
obj
[
"A"
]
??
obj
[
"a"
]);
return
new
PcbOffsetInfo
(
x
,
y
,
a
);
}
case
JsonToken
.
Integer
:
case
JsonToken
.
Float
:
{
// 单值时,视为 X,Y/A = 0(极少出现,做兜底)
int
x
=
Convert
.
ToInt32
(
reader
.
Value
);
return
new
PcbOffsetInfo
(
x
,
0
,
0
);
}
default
:
return
new
PcbOffsetInfo
(
0
,
0
,
0
);
}
}
catch
{
// 解析失败兜底,避免导入中断
return
new
PcbOffsetInfo
(
0
,
0
,
0
);
}
}
private
static
int
SafeInt
(
JToken
t
)
{
if
(
t
==
null
)
return
0
;
if
(
t
.
Type
==
JTokenType
.
Integer
)
return
(
int
)
t
;
if
(
t
.
Type
==
JTokenType
.
Float
)
return
(
int
)((
double
)
t
);
if
(
t
.
Type
==
JTokenType
.
String
&&
int
.
TryParse
((
string
)
t
,
out
var
v
))
return
v
;
return
0
;
}
}
}
}
DeviceLibrary/manager/XYConvertManager.cs
查看文件 @
8e4e591
...
@@ -139,7 +139,7 @@ namespace TSA_V.DeviceLibrary
...
@@ -139,7 +139,7 @@ namespace TSA_V.DeviceLibrary
//smtPoint.PointSize = 4;
//smtPoint.PointSize = 4;
//smtPoint.NodePositionX = BPoint.NodePositionX - (BPoint.NodePositionX - APoint.NodePositionX) * (BPoint.PositionX - smtPoint.PositionX) / (BPoint.PositionX - APoint.PositionX);
//smtPoint.NodePositionX = BPoint.NodePositionX - (BPoint.NodePositionX - APoint.NodePositionX) * (BPoint.PositionX - smtPoint.PositionX) / (BPoint.PositionX - APoint.PositionX);
//smtPoint.NodePositionY = BPoint.NodePositionY - (BPoint.NodePositionY - APoint.NodePositionY) * (BPoint.PositionY - smtPoint.PositionY) / (BPoint.PositionY - APoint.PositionY);
//smtPoint.NodePositionY = BPoint.NodePositionY - (BPoint.NodePositionY - APoint.NodePositionY) * (BPoint.PositionY - smtPoint.PositionY) / (BPoint.PositionY - APoint.PositionY);
LogUtil
.
info
(
$
" 【{smtPoint.PN}】图片坐标【{smtPoint.PositionX},{smtPoint.PositionY}】旧坐标【{oldX},{oldY}】新坐标【{smtPoint.NodePositionX},{smtPoint.NodePositionY}】"
+
LogUtil
.
debug
(
$
" 【{smtPoint.PN}】图片坐标【{smtPoint.PositionX},{smtPoint.PositionY}】旧坐标【{oldX},{oldY}】新坐标【{smtPoint.NodePositionX},{smtPoint.NodePositionY}】"
+
$
"点尺寸({smtPoint.PointSizeX},{smtPoint.PointSizeY}),画笔宽{smtPoint.PenWidth}"
);
$
"点尺寸({smtPoint.PointSizeX},{smtPoint.PointSizeY}),画笔宽{smtPoint.PenWidth}"
);
return
smtPoint
;
return
smtPoint
;
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论