FocusingParameter.cs 17 KB

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