Commit 4645d3ac LN

增加默认打开路径

1 个父辈 ae03e891
......@@ -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 "";
}
......
......@@ -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!