FocusingParameter.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. using PaintDotNet.Base.CommTool;
  2. using PaintDotNet.Base.SettingModel;
  3. using PaintDotNet.DbOpreate.DbModel;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14. using static PaintDotNet.Base.SettingModel.RuleFocusModel;
  15. namespace PaintDotNet.Setting
  16. {
  17. /// <summary>
  18. /// 聚焦参数
  19. /// </summary>
  20. internal class FocusingParameter : PdnBaseForm
  21. {
  22. private GroupBox groupBox1;
  23. private Button button2;
  24. private Button button1;
  25. private Label label3;
  26. private NumericUpDown numericUpDown2;
  27. private NumericUpDown numericUpDown1;
  28. private Label label2;
  29. private Label label1;
  30. private GroupBox groupBox2;
  31. private GroupBox groupBox_img;
  32. private ListView listView_rule;
  33. private RuleFocusModel ruleFocusModel;
  34. private IContainer components;
  35. private ImageList newImageList;
  36. static string filePath = Application.StartupPath + "\\RuleFouces\\RuleFoucesConfiguration.xml";
  37. public FocusingParameter()
  38. {
  39. InitializeComponent();
  40. InitializeLanguageText();
  41. InitData();
  42. }
  43. private void InitializeLanguageText()
  44. {
  45. this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
  46. // modify by shayg 20220718 start
  47. //this.button2.Text = PdnResources.GetString("Menu.File.Save.Text");
  48. //this.button1.Text = PdnResources.GetString("Menu.cancel.text");
  49. this.button2.Text = PdnResources.GetString("Menu.cancel.text");
  50. this.button1.Text = PdnResources.GetString("Menu.File.Save.Text");
  51. // modify by shayg 20220718 end
  52. this.groupBox2.Text = PdnResources.GetString("Menu.Setting.FocusSetting.Text");
  53. this.label3.Text = PdnResources.GetString("Menu.millisecond.text");
  54. this.label2.Text = PdnResources.GetString("Menu.step-size.text") + ":";
  55. this.label1.Text = PdnResources.GetString("Menu.timeinterval.text") + ":";
  56. this.Text = PdnResources.GetString("Menu.Setting.FocusSetting.Text");
  57. }
  58. private void InitializeComponent()
  59. {
  60. this.components = new System.ComponentModel.Container();
  61. this.groupBox1 = new System.Windows.Forms.GroupBox();
  62. this.button2 = new System.Windows.Forms.Button();
  63. this.button1 = new System.Windows.Forms.Button();
  64. this.groupBox2 = new System.Windows.Forms.GroupBox();
  65. this.label3 = new System.Windows.Forms.Label();
  66. this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
  67. this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
  68. this.label2 = new System.Windows.Forms.Label();
  69. this.label1 = new System.Windows.Forms.Label();
  70. this.groupBox_img = new System.Windows.Forms.GroupBox();
  71. this.listView_rule = new System.Windows.Forms.ListView();
  72. this.newImageList = new System.Windows.Forms.ImageList(this.components);
  73. this.groupBox1.SuspendLayout();
  74. this.groupBox2.SuspendLayout();
  75. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
  76. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
  77. this.groupBox_img.SuspendLayout();
  78. this.SuspendLayout();
  79. //
  80. // groupBox1
  81. //
  82. this.groupBox1.Controls.Add(this.button2);
  83. this.groupBox1.Controls.Add(this.button1);
  84. this.groupBox1.Location = new System.Drawing.Point(123, 12);
  85. this.groupBox1.Name = "groupBox1";
  86. this.groupBox1.Size = new System.Drawing.Size(415, 55);
  87. this.groupBox1.TabIndex = 1;
  88. this.groupBox1.TabStop = false;
  89. this.groupBox1.Text = "操作";
  90. //
  91. // button2
  92. //
  93. this.button2.Location = new System.Drawing.Point(334, 20);
  94. this.button2.Name = "button2";
  95. this.button2.Size = new System.Drawing.Size(75, 23);
  96. this.button2.TabIndex = 1;
  97. this.button2.Text = "取消";
  98. this.button2.UseVisualStyleBackColor = true;
  99. this.button2.Click += new System.EventHandler(this.button2_Click);
  100. //
  101. // button1
  102. //
  103. this.button1.Location = new System.Drawing.Point(253, 20);
  104. this.button1.Name = "button1";
  105. this.button1.Size = new System.Drawing.Size(75, 23);
  106. this.button1.TabIndex = 0;
  107. this.button1.Text = "确定";
  108. this.button1.UseVisualStyleBackColor = true;
  109. this.button1.Click += new System.EventHandler(this.button1_Click);
  110. //
  111. // groupBox2
  112. //
  113. this.groupBox2.Controls.Add(this.label3);
  114. this.groupBox2.Controls.Add(this.numericUpDown2);
  115. this.groupBox2.Controls.Add(this.numericUpDown1);
  116. this.groupBox2.Controls.Add(this.label2);
  117. this.groupBox2.Controls.Add(this.label1);
  118. this.groupBox2.Location = new System.Drawing.Point(123, 73);
  119. this.groupBox2.Name = "groupBox2";
  120. this.groupBox2.Size = new System.Drawing.Size(425, 419);
  121. this.groupBox2.TabIndex = 2;
  122. this.groupBox2.TabStop = false;
  123. this.groupBox2.Text = "聚焦参数";
  124. //
  125. // label3
  126. //
  127. this.label3.AutoSize = true;
  128. this.label3.Location = new System.Drawing.Point(232, 43);
  129. this.label3.Name = "label3";
  130. this.label3.Size = new System.Drawing.Size(29, 12);
  131. this.label3.TabIndex = 4;
  132. this.label3.Text = "毫秒";
  133. //
  134. // numericUpDown2
  135. //
  136. this.numericUpDown2.Location = new System.Drawing.Point(126, 81);
  137. this.numericUpDown2.Maximum = new decimal(new int[] {
  138. 10000,
  139. 0,
  140. 0,
  141. 0});
  142. this.numericUpDown2.Name = "numericUpDown2";
  143. this.numericUpDown2.Size = new System.Drawing.Size(100, 21);
  144. this.numericUpDown2.TabIndex = 3;
  145. this.numericUpDown2.Value = new decimal(new int[] {
  146. 100,
  147. 0,
  148. 0,
  149. 0});
  150. //
  151. // numericUpDown1
  152. //
  153. this.numericUpDown1.Increment = new decimal(new int[] {
  154. 10,
  155. 0,
  156. 0,
  157. 0});
  158. this.numericUpDown1.Location = new System.Drawing.Point(126, 40);
  159. this.numericUpDown1.Maximum = new decimal(new int[] {
  160. 1000,
  161. 0,
  162. 0,
  163. 0});
  164. this.numericUpDown1.Name = "numericUpDown1";
  165. this.numericUpDown1.Size = new System.Drawing.Size(100, 21);
  166. this.numericUpDown1.TabIndex = 2;
  167. this.numericUpDown1.Value = new decimal(new int[] {
  168. 100,
  169. 0,
  170. 0,
  171. 0});
  172. //
  173. // label2
  174. //
  175. this.label2.AutoSize = true;
  176. this.label2.Location = new System.Drawing.Point(35, 84);
  177. this.label2.Name = "label2";
  178. this.label2.Size = new System.Drawing.Size(41, 12);
  179. this.label2.TabIndex = 1;
  180. this.label2.Text = "步长:";
  181. //
  182. // label1
  183. //
  184. this.label1.AutoSize = true;
  185. this.label1.Location = new System.Drawing.Point(35, 43);
  186. this.label1.Name = "label1";
  187. this.label1.Size = new System.Drawing.Size(65, 12);
  188. this.label1.TabIndex = 0;
  189. this.label1.Text = "采图时间:";
  190. //
  191. // groupBox_img
  192. //
  193. this.groupBox_img.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  194. | System.Windows.Forms.AnchorStyles.Left)));
  195. this.groupBox_img.Controls.Add(this.listView_rule);
  196. this.groupBox_img.Location = new System.Drawing.Point(13, 13);
  197. this.groupBox_img.Margin = new System.Windows.Forms.Padding(4);
  198. this.groupBox_img.Name = "groupBox_img";
  199. this.groupBox_img.Padding = new System.Windows.Forms.Padding(4);
  200. this.groupBox_img.Size = new System.Drawing.Size(103, 479);
  201. this.groupBox_img.TabIndex = 14;
  202. this.groupBox_img.TabStop = false;
  203. this.groupBox_img.Text = "标尺名称";
  204. //
  205. // listView_rule
  206. //
  207. this.listView_rule.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)));
  208. this.listView_rule.FullRowSelect = true;
  209. this.listView_rule.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
  210. this.listView_rule.HideSelection = false;
  211. this.listView_rule.Location = new System.Drawing.Point(9, 19);
  212. this.listView_rule.Margin = new System.Windows.Forms.Padding(4);
  213. this.listView_rule.MultiSelect = false;
  214. this.listView_rule.Name = "listView_rule";
  215. this.listView_rule.Size = new System.Drawing.Size(86, 452);
  216. this.listView_rule.TabIndex = 0;
  217. this.listView_rule.UseCompatibleStateImageBehavior = false;
  218. this.listView_rule.SelectedIndexChanged += new System.EventHandler(this.listView_rule_SelectedIndexChanged);
  219. //
  220. // newImageList
  221. //
  222. this.newImageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
  223. this.newImageList.ImageSize = new System.Drawing.Size(16, 16);
  224. this.newImageList.TransparentColor = System.Drawing.Color.Transparent;
  225. //
  226. // FocusingParameter
  227. //
  228. this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
  229. this.ClientSize = new System.Drawing.Size(550, 504);
  230. this.Controls.Add(this.groupBox_img);
  231. this.Controls.Add(this.groupBox2);
  232. this.Controls.Add(this.groupBox1);
  233. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  234. this.MaximizeBox = false;
  235. this.MinimizeBox = false;
  236. this.Name = "FocusingParameter";
  237. this.Text = "聚焦参数";
  238. this.Controls.SetChildIndex(this.groupBox1, 0);
  239. this.Controls.SetChildIndex(this.groupBox2, 0);
  240. this.Controls.SetChildIndex(this.groupBox_img, 0);
  241. this.groupBox1.ResumeLayout(false);
  242. this.groupBox2.ResumeLayout(false);
  243. this.groupBox2.PerformLayout();
  244. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
  245. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
  246. this.groupBox_img.ResumeLayout(false);
  247. this.ResumeLayout(false);
  248. }
  249. /// <summary>
  250. /// 初始化数据
  251. /// </summary>
  252. private void InitData()
  253. {
  254. //初始化头
  255. this.listView_rule.View = View.Details;
  256. ColumnHeader header0 = new ColumnHeader();
  257. header0.Text = "";
  258. header0.Width = 180;
  259. this.listView_rule.Columns.Add(header0);
  260. #region [获取标尺]
  261. List<mic_rulers> list = Startup.instance.mic_rulersAll.Where(m => m.id >= 0).ToList();
  262. if (!System.IO.File.Exists(filePath))
  263. {
  264. ruleFocusModel = new RuleFocusModel();
  265. if (list != null && list.Count > 0)
  266. {
  267. if (ruleFocusModel.ModelList == null)
  268. {
  269. ruleFocusModel.ModelList = new List<RuleFocusDetailsModel>();
  270. }
  271. for (int i = 0; i < list.Count; i++)
  272. {
  273. mic_rulers rule = list[i];
  274. RuleFocusDetailsModel model = new RuleFocusDetailsModel();
  275. model.RuleId = rule.id;
  276. model.RuleName = rule.ruler_name;
  277. ruleFocusModel.ModelList.Add(model);
  278. }
  279. }
  280. Directory.CreateDirectory(Application.StartupPath + "\\RuleFouces\\");
  281. XmlSerializeHelper.Save(ruleFocusModel, filePath);
  282. }
  283. else
  284. {
  285. ruleFocusModel = XmlSerializeHelper.Load<RuleFocusModel>(filePath);
  286. foreach (var s in list)
  287. {
  288. var mod = ruleFocusModel.ModelList.Where(m => m.RuleId == s.id).FirstOrDefault();
  289. if (mod != null)
  290. {
  291. continue;
  292. }
  293. var model = new RuleFocusDetailsModel();
  294. model.RuleId = s.id;
  295. model.RuleName = s.ruler_name;
  296. ruleFocusModel.ModelList.Add(model);
  297. }
  298. XmlSerializeHelper.Save(ruleFocusModel, filePath);
  299. }
  300. //listView_rule.AutoResizeColumn(0, ColumnHeaderAutoResizeStyle.ColumnContent);
  301. foreach (var s in ruleFocusModel.ModelList)
  302. {
  303. ListViewItem item = new ListViewItem();
  304. item.Tag = s;
  305. item.Text = s.RuleName;
  306. this.listView_rule.Items.Add(item);
  307. }
  308. #endregion
  309. }
  310. /// <summary>
  311. /// 取消按钮
  312. /// </summary>
  313. /// <param name="sender"></param>
  314. /// <param name="e"></param>
  315. private void button2_Click(object sender, EventArgs e)
  316. {
  317. this.Close();
  318. }
  319. /// <summary>
  320. /// 确定按钮
  321. /// </summary>
  322. /// <param name="sender"></param>
  323. /// <param name="e"></param>
  324. private void button1_Click(object sender, EventArgs e)
  325. {
  326. if (this.listView_rule.FocusedItem != null && this.listView_rule.FocusedItem.Selected)
  327. {
  328. RuleFocusDetailsModel model = (RuleFocusDetailsModel)this.listView_rule.FocusedItem.Tag;
  329. var changeModel = this.ruleFocusModel.ModelList.Where(m => m.RuleId == model.RuleId).FirstOrDefault();
  330. if (changeModel != null)
  331. {
  332. changeModel.TimeLag = (int)this.numericUpDown1.Value;
  333. changeModel.StepLength = (int)this.numericUpDown2.Value;
  334. XmlSerializeHelper.Save(ruleFocusModel, filePath);
  335. }
  336. }
  337. }
  338. /// <summary>
  339. /// 选中标尺
  340. /// </summary>
  341. /// <param name="sender"></param>
  342. /// <param name="e"></param>
  343. private void listView_rule_SelectedIndexChanged(object sender, EventArgs e)
  344. {
  345. if (this.listView_rule.FocusedItem != null && this.listView_rule.FocusedItem.Selected)
  346. {
  347. RuleFocusDetailsModel model = (RuleFocusDetailsModel)this.listView_rule.FocusedItem.Tag;
  348. this.numericUpDown1.Value = model.TimeLag;
  349. this.numericUpDown2.Value = (decimal)model.StepLength;
  350. }
  351. }
  352. #region [获取当前系统激活的标尺]
  353. public static RuleFocusDetailsModel getRuleFocus()
  354. {
  355. #region [获取标尺]
  356. List<mic_rulers> list = Startup.instance.mic_rulersAll.Where(m => m.id >= 0).ToList();
  357. RuleFocusModel modelList = new RuleFocusModel();
  358. if (!System.IO.File.Exists(filePath))
  359. {
  360. Directory.CreateDirectory(Application.StartupPath + "\\RuleFouces\\");
  361. if (list != null && list.Count > 0)
  362. {
  363. modelList.ModelList = new List<RuleFocusDetailsModel>();
  364. for (int i = 0; i < list.Count; i++)
  365. {
  366. var rule = list[i];
  367. modelList.ModelList.Add(new RuleFocusDetailsModel(rule.id, rule.ruler_name));
  368. }
  369. }
  370. XmlSerializeHelper.Save(modelList, filePath);
  371. }
  372. else
  373. {
  374. modelList = XmlSerializeHelper.Load<RuleFocusModel>(filePath);
  375. foreach (var s in list)
  376. {
  377. if (!modelList.ModelList.Any(m => m.RuleId == s.id))
  378. {
  379. modelList.ModelList.Add(new RuleFocusDetailsModel(s.id, s.ruler_name));
  380. }
  381. }
  382. XmlSerializeHelper.Save(modelList, filePath);
  383. }
  384. var activationRules = Startup.instance.ruleDB;
  385. if (activationRules != null)
  386. {
  387. var thisNum = modelList.ModelList.Where(m => m.RuleId == activationRules.id).FirstOrDefault();
  388. if (thisNum != null)
  389. {
  390. return thisNum;
  391. }
  392. }
  393. return new RuleFocusDetailsModel();
  394. #endregion
  395. }
  396. #endregion
  397. }
  398. }