版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

685 lines
32 KiB

  1. using MaiMuAOI.SysCtrl;
  2. using MaiMuControl.Utils;
  3. using OpenCvSharp;
  4. using ProductionControl.UI;
  5. using ProductionControl.UIExtend;
  6. using System;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using System.ComponentModel;
  10. using System.Data;
  11. using System.Diagnostics;
  12. using System.Drawing;
  13. using System.Drawing.Imaging;
  14. using System.IO;
  15. using System.Linq;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. using System.Windows.Forms;
  19. using ToolKits.EnumTool;
  20. using ToolKits.mAPI;
  21. namespace MaiMuAOI.SysUI.ProductAndStep
  22. {
  23. public partial class ProductInfoFrm : Form
  24. {
  25. Service.ClassesService svcClasses = new Service.ClassesService();
  26. Service.ProductService service = new Service.ProductService();
  27. Models.Product model = new Models.Product();
  28. public ProductInfoFrm(Models.Product m = null)
  29. {
  30. InitializeComponent();
  31. UIStyle.SetUIStyle(this);
  32. this.uiTitel1.FatherForm = this;
  33. this.dgvBatchList.AutoGenerateColumns = false;
  34. this.Cursor = Cursors.WaitCursor;
  35. skinTabControl1.SelectedIndex = 0;
  36. //去除PT线宽等
  37. //tabControl1.TabPages.RemoveAt(2);
  38. //this.cbMarkType.SelectedIndex = -1;
  39. if (m != null)
  40. {
  41. model = m;
  42. this.Text += $" (ID:{m.Id})";
  43. this.txtCode.Text = m.Code;
  44. this.txtName.Text = m.Name;
  45. this.txtSpec.Text = m.Spec;
  46. this.cmbHoleCount.Text = m.HoleCount.ToString();
  47. this.txtBatchId.Text = m.BatchId;
  48. this.numTargetCount.Value = m.TargetCount;
  49. this.toolTip1.SetToolTip(this.numTargetCount, "已完成:" + m.CompleteCount);
  50. this.numTensionBaseValue.Value = (decimal)m.TensionBaseValue;
  51. this.numTensionUpFloatValue.Value = (decimal)m.TensionUpFloatValue;
  52. this.numTensionDownFloatValue.Value = (decimal)m.TensionDownFloatValue;
  53. this.numHeightBaseValue.Value = (decimal)m.HeightBaseValue;
  54. this.numHeightUpFloatValue.Value = (decimal)m.HeightUpFloatValue;
  55. this.numHeightDownFloatValue.Value = (decimal)m.HeightDownFloatValue;
  56. this.txtHeightBaseDec.Text = m.HeightBaseDec;
  57. this.numLineWidthBaseValue.Value = (decimal)m.LineWidthBaseValue;
  58. this.numLineWidthUpFloatValue.Value = (decimal)m.LineWidthUpFloatValue;
  59. this.numLineWidthDownFloatValue.Value = (decimal)m.LineWidthDownFloatValue;
  60. this.numPTBaseValue.Value = (decimal)m.PTBaseValue;
  61. this.numPTUpFloatValue.Value = (decimal)m.PTUpFloatValue;
  62. this.numPTDownFloatValue.Value = (decimal)m.PTDownFloatValue;
  63. this.numPTXBaseValue.Value = (decimal)m.PTXBaseValue;
  64. this.numPTXUpFloatValue.Value = (decimal)m.PTXUpFloatValue;
  65. this.numPTXDownFloatValue.Value = (decimal)m.PTXDownFloatValue;
  66. //新增判断2024-2-20
  67. this.numericUpDown3.Value = (decimal)m.FLineWidthBaseValue;
  68. this.numericUpDown2.Value = (decimal)m.FLineWidthUpFloatValue;
  69. this.numericUpDown1.Value = (decimal)m.FLineWidthDownFloatValue;
  70. this.numericUpDown6.Value = (decimal)m.MGridIntervalBaseValue;
  71. this.numericUpDown5.Value = (decimal)m.MGridIntervalUpFloatValue;
  72. this.numericUpDown4.Value = (decimal)m.MGridIntervalDownFloatValue;
  73. this.numericUpDown9.Value = (decimal)m.MGridWidthBaseValue;
  74. this.numericUpDown8.Value = (decimal)m.MGridWidthUpFloatValue;
  75. this.numericUpDown7.Value = (decimal)m.MGridWidthDownFloatValue ;
  76. this.numericUpDown12.Value = (decimal)m.MGridSpreadBaseValue;
  77. this.numericUpDown11.Value = (decimal)m.MGridSpreadUpFloatValue;
  78. this.numericUpDown10.Value = (decimal)m.MGridSpreadDownFloatValue;
  79. this.numericUpDown15.Value = (decimal)m.FGridSpreadBaseValue;
  80. this.numericUpDown14.Value = (decimal)m.FGridSpreadUpFloatValue;
  81. this.numericUpDown13.Value = (decimal)m.FGridSpreadDownFloatValue;
  82. this.numericUpDown18.Value = (decimal)m.BackPoleWidthBaseValue;
  83. this.numericUpDown17.Value = (decimal)m.BackPoleWidthUpFloatValue;
  84. this.numericUpDown16.Value = (decimal)m.BackPoleWidthDownFloatValue;
  85. this.numericUpDown21.Value = (decimal)m.MGridLengthBaseValue;
  86. this.numericUpDown20.Value = (decimal)m.MGridLengthUpFloatValue;
  87. this.numericUpDown19.Value = (decimal)m.MGridLengthDownFloatValue;
  88. this.numericUpDown24.Value = (decimal)m.MarkXDisBaseValue;
  89. this.numericUpDown23.Value = (decimal)m.MarkXDisUpFloatValue;
  90. this.numericUpDown22.Value = (decimal)m.MarkXDisDownFloatValue;
  91. this.numericUpDown27.Value = (decimal)m.MarkYDisBaseValue;
  92. this.numericUpDown26.Value = (decimal)m.MarkYDisUpFloatValue;
  93. this.numericUpDown25.Value = (decimal)m.MarkYDisDownFloatValue;
  94. this.numericUpDown30.Value = (decimal)m.ForkLengthBaseValue;
  95. this.numericUpDown29.Value = (decimal)m.ForkLengthUpFloatValue;
  96. this.numericUpDown28.Value = (decimal)m.ForkLengthDownFloatValue;
  97. this.numericUpDown33.Value = (decimal)m.ForkWidthBaseValue;
  98. this.numericUpDown32.Value = (decimal)m.ForkWidthUpFloatValue;
  99. this.numericUpDown31.Value = (decimal)m.ForkWidthDownFloatValue;
  100. this.numericUpDown36.Value = (decimal)m.ForkDisBaseValue;
  101. this.numericUpDown35.Value = (decimal)m.ForkDisUpFloatValue;
  102. this.numericUpDown34.Value = (decimal)m.ForkDisDownFloatValue;
  103. //if (m.Type > 0)
  104. //{
  105. // this.txtCode.Enabled = false;
  106. // this.txtName.Width = this.txtCode.Width;
  107. // this.txtSpec.Enabled = false;
  108. //}
  109. this.tsbtnAddFile.Enabled = true;
  110. this.tsbtnNewBatchId.Enabled = true;
  111. this.dgvBatchList.DataSource = new BindingSource(m.BatchHistoryList, null);
  112. //2023-11-2 mark
  113. this.cbMarkType.SelectedIndex = m.MarkType;
  114. this.numMarkSize.Value = (decimal)m.MarkSize;
  115. //2023-12-18 主栅
  116. this.cbMarkDisturb.Checked = (m.MarkDisturb == 1);
  117. this.cbMainGrid.Checked = (m.MainGrid == 1);
  118. //2024-1-24 pad
  119. this.cbHavePad.Checked = (m.HavePad == 1);
  120. Models.Attachment attachmentFile = model.AttachmentList.FirstOrDefault(x => x.Type == 0);
  121. if (attachmentFile != null)
  122. {
  123. this.btnOpenFile.Text = attachmentFile.Name;
  124. this.btnOpenFile.Visible = true;
  125. if ((this.groupBox5.Width - this.btnOpenFile.Width) > 0)
  126. {
  127. this.btnOpenFile.Left = (this.groupBox5.Width - this.btnOpenFile.Width) / 2;
  128. }
  129. else
  130. this.btnOpenFile.Left = 20;
  131. this.textBoxPath.Text = ConfMgr.Instance.ProjectDir+ $"\\{model.Id}\\" + attachmentFile.Name;
  132. }
  133. //是否显示上传功能
  134. if(ConfMgr.Instance.SysConfigParams.OpenPdtServer)
  135. tsbPdtPush.Visible = true;
  136. else
  137. tsbPdtPush.Visible = false;
  138. }
  139. else
  140. {
  141. cbMarkType.SelectedIndex = 2;
  142. numMarkSize.Value = (decimal)0.5;
  143. this.textBoxPath.Text = "";
  144. }
  145. InitDataView();
  146. this.Cursor = Cursors.Default;
  147. }
  148. ArrayList GetArrayList<T>()
  149. {
  150. ArrayList list = new ArrayList();
  151. Type type = typeof(T);
  152. //list.Add(new DictionaryEntry("start", "启动按钮"));
  153. foreach (int value in Enum.GetValues(type))
  154. {
  155. string strName = Enum.GetName(type, value);//获取名称
  156. list.Add(new DictionaryEntry(value, strName));
  157. }
  158. return list;
  159. }
  160. private void InitDataView()
  161. {
  162. try
  163. {
  164. //显示的数据
  165. this.cmbClasses.DisplayMember = "Name";
  166. this.cmbClasses.ValueMember = "Id";
  167. var list = svcClasses.GetListNav(0);
  168. this.cmbClasses.DataSource = list;
  169. if (model.ClassesId > 0)
  170. this.cmbClasses.SelectedValue = model.ClassesId;
  171. //缺陷项
  172. //ArrayList lstDefect = new ArrayList();
  173. //List<string> DefectNames = new List<string>();
  174. //foreach (var item in Enum.GetValues(typeof(DefectCodeEnum)))
  175. //{
  176. // DefectCountOfSizeControl userCon = new DefectCountOfSizeControl();
  177. // userCon.Code = item.ToString();
  178. // userCon.Title = EnumExtension.GetEnumDescription((DefectCodeEnum)item);
  179. // if (model != null && model.QualifiedCriterionList != null)
  180. // {
  181. // var qalifiedItem = model.QualifiedCriterionList.FirstOrDefault(m => m.DefectCode == userCon.Code);
  182. // if (qalifiedItem != null)
  183. // {
  184. // userCon.Checked = true;
  185. // userCon.SizeValue = (decimal)qalifiedItem.Size;
  186. // userCon.MaxDefectCount = qalifiedItem.MaxDefectCount;
  187. // }
  188. // }
  189. // this.flpQualifiedPannel.Controls.Add(userCon);
  190. //}
  191. var lstDefect = GetArrayList<DefectCodeEnum>();
  192. foreach (DictionaryEntry item in lstDefect)
  193. {
  194. DefectCountOfSizeControl userCon = new DefectCountOfSizeControl();
  195. userCon.Code = item.Value.ToString();
  196. userCon.Title = ((DefectNameEnum)(int)item.Key).ToString();
  197. if (model != null && model.QualifiedCriterionList != null)
  198. {
  199. var qalifiedItem = model.QualifiedCriterionList.FirstOrDefault(m => m.DefectCode == userCon.Code);
  200. if (qalifiedItem != null)
  201. {
  202. userCon.Checked = true;
  203. userCon.SizeValue = (decimal)qalifiedItem.Size;
  204. userCon.MaxDefectCount = qalifiedItem.MaxDefectCount;
  205. }
  206. }
  207. this.flpQualifiedPannel.Controls.Add(userCon);
  208. }
  209. //模型文件
  210. string strDefectModelFile = ConfMgr.Instance.SysConfigParams.AIModelPath;
  211. string[] onnxFiles = Directory.GetFiles(strDefectModelFile, "*.onnx");
  212. string onlyName;
  213. foreach (string onnxFile in onnxFiles)
  214. {
  215. onlyName = Path.GetFileName(onnxFile);
  216. cmbDefectModelFile.Items.Add(onlyName);
  217. if (!string.IsNullOrWhiteSpace(model.DefectModelFile) && onlyName.ToLower() == model.DefectModelFile.ToLower())
  218. this.cmbDefectModelFile.SelectedItem = model.DefectModelFile;
  219. }
  220. }
  221. catch(Exception e)
  222. {
  223. MessageBox.Show("数据&模型载入出错:"+ e.Message,"报警", MessageBoxButtons.OK,MessageBoxIcon.Error);
  224. }
  225. }
  226. private void ProductInfoFrm_Load(object sender, EventArgs e)
  227. {
  228. }
  229. private void tsbtnSave_Click(object sender, EventArgs e)
  230. {
  231. try
  232. {
  233. string szCode = this.txtCode.Text.Trim();
  234. string szName = this.txtName.Text.Trim();
  235. string szSpec = this.txtSpec.Text.Trim();
  236. string szHoleCount = this.cmbHoleCount.Text.Trim();
  237. string szBatchId = this.txtBatchId.Text.Trim();
  238. int liTargetCount = (int)this.numTargetCount.Value;
  239. string szHeightBaseDec = this.txtHeightBaseDec.Text.Trim().Trim(new char[] { ';', ',' });
  240. if (szCode == "" || szName == "")
  241. throw new Exception("请填写料号和名称!");
  242. if (this.cmbClasses.SelectedIndex < 0)
  243. throw new Exception("请选择产品类型!");
  244. if (szHoleCount == "" || !Util.IsNumber(szHoleCount))
  245. throw new Exception("请正确填写产品目数!");
  246. if (this.cmbDefectModelFile.SelectedIndex < 0)
  247. throw new Exception("请选择检测模型文件!");
  248. if (this.cbMarkType.SelectedIndex < 0)
  249. throw new Exception("请选择Mark!");
  250. //if (szBatchId == "")// || liTargetCount < 1
  251. // throw new Exception("请填写批次号");// 和批次目标数量!");
  252. if (szHeightBaseDec != "")
  253. {
  254. double num;
  255. string[] szs = szHeightBaseDec.Split(new char[] { ';', ',' });
  256. foreach (string s in szs)
  257. {
  258. if (!double.TryParse(s, out num))
  259. throw new Exception(s + " 非数值!");
  260. }
  261. }
  262. model.Code = szCode;
  263. model.Name = szName;
  264. model.Spec = szSpec;
  265. model.ClassesId = (int)this.cmbClasses.SelectedValue;
  266. model.HoleCount = Convert.ToInt32(szHoleCount);
  267. model.DefectModelFile = this.cmbDefectModelFile.Text.Trim();
  268. model.TensionBaseValue = (double)this.numTensionBaseValue.Value;
  269. model.TensionUpFloatValue = (double)this.numTensionUpFloatValue.Value;
  270. model.TensionDownFloatValue = (double)this.numTensionDownFloatValue.Value;
  271. model.HeightBaseValue = (double)this.numHeightBaseValue.Value;
  272. model.HeightUpFloatValue = (double)this.numHeightUpFloatValue.Value;
  273. model.HeightDownFloatValue = (double)this.numHeightDownFloatValue.Value;
  274. model.HeightBaseDec = szHeightBaseDec;
  275. model.LineWidthBaseValue = (double)this.numLineWidthBaseValue.Value;
  276. model.LineWidthUpFloatValue = (double)this.numLineWidthUpFloatValue.Value;
  277. model.LineWidthDownFloatValue = (double)this.numLineWidthDownFloatValue.Value;
  278. model.PTBaseValue = (double)this.numPTBaseValue.Value;
  279. model.PTUpFloatValue = (double)this.numPTUpFloatValue.Value;
  280. model.PTDownFloatValue = (double)this.numPTDownFloatValue.Value;
  281. model.PTXBaseValue = (double)this.numPTXBaseValue.Value;
  282. model.PTXUpFloatValue = (double)this.numPTXUpFloatValue.Value;
  283. model.PTXDownFloatValue = (double)this.numPTXDownFloatValue.Value;
  284. //新增判断2024-2-20
  285. model.FLineWidthBaseValue = (double)this.numericUpDown3.Value;
  286. model.FLineWidthUpFloatValue = (double)this.numericUpDown2.Value;
  287. model.FLineWidthDownFloatValue = (double)this.numericUpDown1.Value;
  288. model.MGridIntervalBaseValue = (double)this.numericUpDown6.Value;
  289. model.MGridIntervalUpFloatValue = (double)this.numericUpDown5.Value;
  290. model.MGridIntervalDownFloatValue = (double)this.numericUpDown4.Value;
  291. model.MGridWidthBaseValue = (double)this.numericUpDown9.Value;
  292. model.MGridWidthUpFloatValue = (double)this.numericUpDown8.Value;
  293. model.MGridWidthDownFloatValue = (double)this.numericUpDown7.Value;
  294. model.MGridSpreadBaseValue = (double)this.numericUpDown12.Value;
  295. model.MGridSpreadUpFloatValue = (double)this.numericUpDown11.Value;
  296. model.MGridSpreadDownFloatValue = (double)this.numericUpDown10.Value;
  297. model.FGridSpreadBaseValue = (double)this.numericUpDown15.Value;
  298. model.FGridSpreadUpFloatValue = (double)this.numericUpDown14.Value;
  299. model.FGridSpreadDownFloatValue = (double)this.numericUpDown13.Value;
  300. model.BackPoleWidthBaseValue = (double)this.numericUpDown18.Value;
  301. model.BackPoleWidthUpFloatValue = (double)this.numericUpDown17.Value;
  302. model.BackPoleWidthDownFloatValue = (double)this.numericUpDown16.Value;
  303. model.MGridLengthBaseValue = (double)this.numericUpDown21.Value;
  304. model.MGridLengthUpFloatValue = (double)this.numericUpDown20.Value;
  305. model.MGridLengthDownFloatValue = (double)this.numericUpDown19.Value;
  306. model.MarkXDisBaseValue = (double)this.numericUpDown24.Value;
  307. model.MarkXDisUpFloatValue = (double)this.numericUpDown23.Value;
  308. model.MarkXDisDownFloatValue = (double)this.numericUpDown22.Value;
  309. model.MarkYDisBaseValue = (double)this.numericUpDown27.Value;
  310. model.MarkYDisUpFloatValue = (double)this.numericUpDown26.Value;
  311. model.MarkYDisDownFloatValue = (double)this.numericUpDown25.Value;
  312. model.ForkLengthBaseValue = (double)this.numericUpDown30.Value;
  313. model.ForkLengthUpFloatValue = (double)this.numericUpDown29.Value;
  314. model.ForkLengthDownFloatValue = (double)this.numericUpDown28.Value;
  315. model.ForkWidthBaseValue = (double)this.numericUpDown33.Value;
  316. model.ForkWidthUpFloatValue = (double)this.numericUpDown32.Value;
  317. model.ForkWidthDownFloatValue = (double)this.numericUpDown31.Value;
  318. model.ForkDisBaseValue = (double)this.numericUpDown36.Value;
  319. model.ForkDisUpFloatValue = (double)this.numericUpDown35.Value;
  320. model.ForkDisDownFloatValue = (double)this.numericUpDown34.Value;
  321. if (model.QualifiedCriterionList == null)
  322. model.QualifiedCriterionList = new List<Models.QualifiedCriterion>();
  323. else
  324. model.QualifiedCriterionList.Clear();
  325. foreach (DefectCountOfSizeControl defectControl in this.flpQualifiedPannel.Controls)
  326. {
  327. if (defectControl.Checked)
  328. {
  329. model.QualifiedCriterionList.Add(
  330. new Models.QualifiedCriterion()
  331. {
  332. DefectCode = defectControl.Code,
  333. Size = (float)defectControl.SizeValue,
  334. MaxDefectCount = (int)defectControl.MaxDefectCount,
  335. ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code,
  336. CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code
  337. });
  338. }
  339. }
  340. model.ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code;
  341. //2023-11-2 mark
  342. model.MarkType = this.cbMarkType.SelectedIndex;
  343. model.MarkSize = (double)this.numMarkSize.Value;
  344. //2023-12-18 主栅
  345. model.MarkDisturb = this.cbMarkDisturb.Checked ? 1 : 0;
  346. model.MainGrid = this.cbMainGrid.Checked ? 1 : 0;
  347. //2024-1-24 是否存在pad
  348. model.HavePad = this.cbHavePad.Checked ? 1 : 0;
  349. bool result;
  350. if (model.Id == 0)
  351. {
  352. model.BatchId = szBatchId;
  353. model.TargetCount = liTargetCount;
  354. model.CompleteCount = 0;
  355. model.CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code;
  356. result = service.InsertNav(model);
  357. }
  358. else
  359. {
  360. if (model.BatchId != szBatchId && !string.IsNullOrWhiteSpace(model.BatchId))
  361. {
  362. if (model.CompleteCount < model.TargetCount
  363. && MessageBox.Show($"本批次完成数量未达到目标数量,确定更换批次号?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
  364. return;
  365. if (model.BatchHistoryList.FirstOrDefault(m => m.BatchId == szBatchId) != null)
  366. throw new Exception("当前批次号与历史中所用批次号重复,请重新填写!");
  367. model.BatchHistoryList.Add(new Models.BatchHistory()
  368. {
  369. BatchId = model.BatchId,
  370. TargetCount = model.TargetCount,
  371. CompleteCount = model.CompleteCount,
  372. CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code,
  373. ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code
  374. });
  375. model.CompleteCount = 0;
  376. }
  377. model.BatchId = szBatchId;
  378. model.TargetCount = liTargetCount;
  379. result = service.UpdateNav(model);
  380. }
  381. if (!result)
  382. throw new Exception("保存失败!");
  383. this.tsbtnAddFile.Enabled = true;
  384. this.tsbtnNewBatchId.Enabled = true;
  385. MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  386. this.DialogResult = DialogResult.OK;
  387. this.Close();
  388. }
  389. catch (Exception ex)
  390. {
  391. MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  392. }
  393. }
  394. private void tsbtnExit_Click(object sender, EventArgs e)
  395. {
  396. this.Close();
  397. }
  398. private void tsbtnNewBatchId_Click(object sender, EventArgs e)
  399. {
  400. }
  401. private void tsbtnAddFile_Click(object sender, EventArgs e)
  402. {
  403. this.Cursor = Cursors.WaitCursor;
  404. System.Windows.Forms.Application.DoEvents();
  405. try
  406. {
  407. if (this.cbMarkType.SelectedIndex < 0)
  408. throw new Exception("请选择Mark!");
  409. //.dwg /.dxf /.dws /.dwt
  410. string filePath = ConfMgr.SelectFile("gbx,gbr文件|*.gb?");
  411. if (string.IsNullOrWhiteSpace(filePath))
  412. return;
  413. string fileName = Path.GetFileName(filePath);
  414. string fileExtend = Path.GetExtension(filePath);
  415. string fileOnlyName = fileName.Substring(0, fileName.Length - fileExtend.Length);
  416. //
  417. string targFilePath = ConfMgr.Instance.ProjectDir + $"\\{model.Id}\\";
  418. if (!Directory.Exists(targFilePath))
  419. Directory.CreateDirectory(targFilePath);
  420. else//删除原文件
  421. ConfMgr.DelFilesInFolder(targFilePath);
  422. targFilePath += fileName;
  423. //File.Copy(res.file_path, defectFileName + ".bmp", true);
  424. bool result = API.CopyFile(filePath, targFilePath, false);//更快 //false-覆盖
  425. if (!result)
  426. throw new Exception("移动文件失败!");
  427. //后台线程转BMP与JPG
  428. string tempClass = this.cmbClasses.Text;
  429. int tempIndex = this.cbMarkType.SelectedIndex;
  430. double tempSize = (double)this.numMarkSize.Value;
  431. //2023-12-18
  432. int tMarkDistrub = this.cbMarkDisturb.Checked ? 1 : 0;
  433. int tMainGrid = this.cbMainGrid.Checked ? 1 : 0;
  434. //2024-1-24
  435. int tHavePad = this.cbHavePad.Checked ? 1 : 0;
  436. //Task.Run(() =>
  437. {
  438. Yolo5.Yolo_Class yolo = new Yolo5.Yolo_Class();
  439. string bmpPath = targFilePath.Substring(0, targFilePath.Length - 4) + ".bmp";
  440. //2023-11-3 mark
  441. //yolo.gerber2image(targFilePath, bmpPath);
  442. double[] markParam = new double[7];
  443. if (tempClass.Contains("乳剂"))
  444. markParam[0] = 2;
  445. else if (tempClass.Contains("PI"))
  446. markParam[0] = 1;
  447. else
  448. markParam[0] = 0;
  449. if (tempIndex == 0)
  450. {
  451. //默认情况 实心圆,0.5mm
  452. markParam[1] = 2;
  453. markParam[2] = 0.5;
  454. markParam[3] = 1;
  455. markParam[4] = 0;
  456. markParam[5] = 0;
  457. markParam[6] = 0;
  458. }
  459. else
  460. {
  461. markParam[1] = tempIndex - 1;
  462. markParam[2] = tempSize;
  463. markParam[3] = tempIndex == 1 ? 0 : 1;
  464. markParam[4] = tMarkDistrub;
  465. markParam[5] = tMainGrid;
  466. markParam[6] = tHavePad;
  467. }
  468. yolo.gerber2image(targFilePath, bmpPath, markParam);
  469. //换背景JPG
  470. Mat mat = Cv2.ImRead(bmpPath);
  471. Cv2.CvtColor(mat, mat, ColorConversionCodes.RGB2GRAY);//转灰度图
  472. for (int i = 0; i < mat.Height; i++)
  473. {
  474. for (int j = 0; j < mat.Width; j++)
  475. {
  476. if (mat.At<byte>(i, j) == 255)//白色
  477. mat.Set<byte>(i, j, 0);
  478. else
  479. mat.Set<byte>(i, j, 255);
  480. }
  481. }
  482. model.MapPath = bmpPath;
  483. //灰转彩
  484. //Cv2.CvtColor(mat, mat, ColorConversionCodes.GRAY2RGB);
  485. //for (int i = 0; i < mat.Height; i++)
  486. //{
  487. // for (int j = 0; j < mat.Width; j++)
  488. // {
  489. // if (mat.At<byte>(i, j) == 255)//白色
  490. // mat.Set<byte>(i, j, 0); //黄色
  491. // }
  492. //}
  493. bmpPath = targFilePath.Substring(0, targFilePath.Length - 4) + ".jpg";
  494. OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat).Save(bmpPath, ImageFormat.Jpeg);
  495. //});//不能加.Start();
  496. }
  497. Models.Attachment attachmentFile = model.AttachmentList.FirstOrDefault(m => m.Type == 0);
  498. if (attachmentFile != null)
  499. {
  500. attachmentFile.Type = 0;//图纸
  501. attachmentFile.NameTimestamp = $"{model.Id}\\{fileOnlyName}";
  502. attachmentFile.Name = fileName;
  503. attachmentFile.ExtendName = fileExtend;
  504. }
  505. else
  506. {
  507. model.AttachmentList.Add(new Models.Attachment()
  508. {
  509. TBName = "product",
  510. Type = 0,
  511. NameTimestamp = $"{model.Id}\\{fileOnlyName}",
  512. Name = fileName,
  513. ExtendName = fileExtend,
  514. CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code,
  515. ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code
  516. });
  517. }
  518. if (!service.UpdateNav(model))
  519. throw new Exception("保存文件失败!");
  520. model = service.GetModelNav(model.Code);
  521. this.btnOpenFile.Text = fileName;
  522. this.btnOpenFile.Visible = true;
  523. }
  524. catch (Exception ex)
  525. {
  526. MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  527. }
  528. finally
  529. {
  530. this.Cursor = Cursors.Default;
  531. }
  532. }
  533. private void btnOpenFile_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  534. {
  535. Models.Attachment attachmentFile = model.AttachmentList.FirstOrDefault(m => m.Type == 0);
  536. if (attachmentFile == null)
  537. MessageBox.Show("还未上传!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  538. string filePath = ConfMgr.Instance.ProjectDir + $"\\{model.Id}\\" + attachmentFile.Name;
  539. if (File.Exists(filePath))
  540. Process.Start(filePath);
  541. }
  542. private void tbtnGetPos_Click(object sender, EventArgs e)
  543. {
  544. if ((model.MapPath == null) || (string.IsNullOrEmpty(model.MapPath)))
  545. {
  546. MessageBox.Show("还未上传图纸!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  547. return;
  548. }
  549. List<double> dList = new List<double>();
  550. if (model.GetPointList != null)
  551. {
  552. var list = model.GetPointList.Split(',');
  553. dList = new List<double>();
  554. if (list.Length < 28)
  555. {
  556. for (int i = 0; i < 28; i++)
  557. {
  558. dList.Add(0);
  559. }
  560. }
  561. else
  562. {
  563. for (int i = 0; i < list.Length; i++)
  564. {
  565. dList.Add(double.Parse(list[i]));
  566. }
  567. }
  568. }
  569. FrmGetPosByPic frm = new FrmGetPosByPic(model, model.MapPath, dList.ToArray());
  570. frm.ShowDialog();
  571. model.GetPointList = string.Join(",", frm.GetPoints()); ;
  572. model.MapPath = frm.GetMapPath();
  573. if (!service.UpdateNav(model))
  574. throw new Exception("保存文件失败!");
  575. model = service.GetModelNav(model.Code);
  576. }
  577. private void textBoxPath_DoubleClick(object sender, EventArgs e)
  578. {
  579. if (File.Exists(this.textBoxPath.Text))
  580. {
  581. Models.Attachment attachmentFile = model.AttachmentList.FirstOrDefault(x => x.Type == 0);
  582. if (attachmentFile != null)
  583. {
  584. System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("Explorer.exe");
  585. psi.Arguments = "/e,/select," + ConfMgr.Instance.ProjectDir + $"\\{model.Id}\\";
  586. System.Diagnostics.Process.Start(psi);
  587. }
  588. }
  589. }
  590. #region 发送产品数据
  591. private void tsbPdtPush_Click(object sender, EventArgs e)
  592. {
  593. try
  594. {
  595. this.Cursor = Cursors.WaitCursor;
  596. System.Windows.Forms.Application.DoEvents();
  597. SysMgr.Instance.SendPdtData(model);
  598. this.Cursor = Cursors.Default;
  599. }
  600. catch (Exception ex)
  601. {
  602. ;
  603. }
  604. }
  605. #endregion
  606. }
  607. }