Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
AccAOI
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 4645d3ac
由
LN
编写于
2019-08-02 15:56:16 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
增加默认打开路径
1 个父辈
ae03e891
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
48 行增加
和
22 行删除
AOI/AoiProject.cs
AccAOI/FrmAoiSetting.cs
AOI/AoiProject.cs
查看文件 @
4645d3a
...
...
@@ -102,27 +102,35 @@ namespace AOI
/// 加载项目
/// </summary>
/// <param name="filePath"></param>
public
void
Load
(
string
filePath
)
public
string
Load
(
string
filePath
)
{
Dictionary
<
string
,
string
>
projectMap
=
JsonUtil
.
DeserializeJsonToObjectFromFile
<
Dictionary
<
string
,
string
>>(
filePath
);
string
base64Img
=
projectMap
[
"base64Img"
];
this
.
standardImage
=
Base64Util
.
ToImage
(
base64Img
);
string
methodMapJson
=
projectMap
[
"methodMap"
];
var
jsonMap
=
JsonUtil
.
DeserializeJsonToObject
<
Dictionary
<
string
,
string
>>(
methodMapJson
);
foreach
(
var
item
in
jsonMap
)
try
{
JObject
obj
=
JObject
.
Parse
(
item
.
Value
);
string
fullTypeName
=
obj
.
Value
<
string
>(
"FullTypeName"
);
Type
t
=
Type
.
GetType
(
fullTypeName
);
JsonSerializer
serializer
=
new
JsonSerializer
();
StringReader
sr
=
new
StringReader
(
item
.
Value
);
object
o
=
serializer
.
Deserialize
(
new
JsonTextReader
(
sr
),
t
);
AoiMethod
aoiMethod
=
(
AoiMethod
)
o
;
string
PathDataStr
=
obj
.
Value
<
string
>(
"PathDataStr"
);
PathData
pathData
=
JsonUtil
.
DeserializeJsonToObject
<
PathData
>(
PathDataStr
);
aoiMethod
.
RoiPath
=
new
GraphicsPath
(
pathData
.
Points
,
pathData
.
Types
);
methodMap
.
Add
(
item
.
Key
,
aoiMethod
);
Dictionary
<
string
,
string
>
projectMap
=
JsonUtil
.
DeserializeJsonToObjectFromFile
<
Dictionary
<
string
,
string
>>(
filePath
);
string
base64Img
=
projectMap
[
"base64Img"
];
this
.
standardImage
=
Base64Util
.
ToImage
(
base64Img
);
string
methodMapJson
=
projectMap
[
"methodMap"
];
var
jsonMap
=
JsonUtil
.
DeserializeJsonToObject
<
Dictionary
<
string
,
string
>>(
methodMapJson
);
foreach
(
var
item
in
jsonMap
)
{
JObject
obj
=
JObject
.
Parse
(
item
.
Value
);
string
fullTypeName
=
obj
.
Value
<
string
>(
"FullTypeName"
);
Type
t
=
Type
.
GetType
(
fullTypeName
);
JsonSerializer
serializer
=
new
JsonSerializer
();
StringReader
sr
=
new
StringReader
(
item
.
Value
);
object
o
=
serializer
.
Deserialize
(
new
JsonTextReader
(
sr
),
t
);
AoiMethod
aoiMethod
=
(
AoiMethod
)
o
;
string
PathDataStr
=
obj
.
Value
<
string
>(
"PathDataStr"
);
PathData
pathData
=
JsonUtil
.
DeserializeJsonToObject
<
PathData
>(
PathDataStr
);
aoiMethod
.
RoiPath
=
new
GraphicsPath
(
pathData
.
Points
,
pathData
.
Types
);
methodMap
.
Add
(
item
.
Key
,
aoiMethod
);
return
""
;
}
}
catch
(
Exception
ex
)
{
return
ex
.
ToString
();
}
return
""
;
}
...
...
AccAOI/FrmAoiSetting.cs
查看文件 @
4645d3a
...
...
@@ -18,20 +18,26 @@ namespace AccAOI
public
static
Image
Img
=
null
;
private
AoiProject
Project
=
null
;
private
bool
CanSel
=
true
;
private
string
DefaultPath
=
""
;
public
FrmAoiSetting
()
{
InitializeComponent
();
this
.
WindowState
=
FormWindowState
.
Maximized
;
}
public
FrmAoiSetting
(
string
programPath
,
Image
image
=
null
)
public
FrmAoiSetting
(
string
programPath
,
Image
image
=
null
,
string
defaultPath
=
""
)
{
InitializeComponent
();
this
.
WindowState
=
FormWindowState
.
Maximized
;
if
(!
programPath
.
Equals
(
""
)
&&
(
image
!=
null
))
{
Project
=
new
AoiProject
(
image
);
Project
.
Load
(
programPath
);
string
result
=
Project
.
Load
(
programPath
);
if
(!
result
.
Equals
(
""
))
{
MessageBox
.
Show
(
"加载项目"
+
programPath
+
"失败:\r\n"
+
result
);
}
}
DefaultPath
=
defaultPath
;
ShowPorject
();
}
...
...
@@ -57,6 +63,7 @@ namespace AccAOI
openDialog
.
Title
=
"打开本地图片"
;
openDialog
.
Filter
=
"All Supported Images (*.bmp;*.dib;*.rle;*.gif;*.jpg;*.png)|*.bmp;*.dib;*.rle;*.gif;*.jpg;*.png|Bitmaps (*.bmp;*.dib;*.rle)|*.bmp;*.dib;*.rle|Graphics Interchange Format (*.gif)|*.gif|Joint Photographic Experts (*.jpg)|*.jpg|Portable Network Graphics (*.png)|*.png|All Files (*.*)|*.*"
;
openDialog
.
DefaultExt
=
"png"
;
//openDialog.DefaultExt = "png";
System
.
Windows
.
Forms
.
DialogResult
result
=
openDialog
.
ShowDialog
();
if
(
result
==
System
.
Windows
.
Forms
.
DialogResult
.
Cancel
)
...
...
@@ -85,6 +92,10 @@ namespace AccAOI
System
.
Windows
.
Forms
.
OpenFileDialog
openDialog
=
new
System
.
Windows
.
Forms
.
OpenFileDialog
();
openDialog
.
Title
=
"打开项目"
;
openDialog
.
Filter
=
"(*.data)|*.data|(*.*)|*.*"
;
if
(!
String
.
IsNullOrEmpty
(
DefaultPath
))
{
openDialog
.
InitialDirectory
=
DefaultPath
;
}
//openDialog.DefaultExt = "png";
System
.
Windows
.
Forms
.
DialogResult
result
=
openDialog
.
ShowDialog
();
if
(
result
==
System
.
Windows
.
Forms
.
DialogResult
.
Cancel
)
...
...
@@ -93,8 +104,11 @@ namespace AccAOI
}
string
fileName
=
openDialog
.
FileName
;
Project
=
new
AoiProject
(
Img
);
Project
.
Load
(
fileName
);
string
msg
=
Project
.
Load
(
fileName
);
if
(!
msg
.
Equals
(
""
))
{
MessageBox
.
Show
(
"加载项目"
+
fileName
+
"失败:\r\n"
+
msg
);
}
ShowPorject
();
}
...
...
@@ -109,6 +123,10 @@ namespace AccAOI
System
.
Windows
.
Forms
.
SaveFileDialog
saveFileDialog
=
new
System
.
Windows
.
Forms
.
SaveFileDialog
();
saveFileDialog
.
Title
=
"保存项目"
;
saveFileDialog
.
Filter
=
"(*.data)|*.data|(*.*)|*.*"
;
if
(!
String
.
IsNullOrEmpty
(
DefaultPath
))
{
saveFileDialog
.
InitialDirectory
=
DefaultPath
;
}
//openDialog.DefaultExt = "png";
System
.
Windows
.
Forms
.
DialogResult
result
=
saveFileDialog
.
ShowDialog
();
if
(
result
==
System
.
Windows
.
Forms
.
DialogResult
.
Cancel
)
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论