InterImageOpDialog.cs 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  1. using Metis.ParameterSet;
  2. using PaintDotNet.Base;
  3. using PaintDotNet.Base.CommTool;
  4. using PaintDotNet.CustomControl;
  5. using PaintDotNet.Data.Param;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.ComponentModel;
  9. using System.Drawing;
  10. using System.Drawing.Imaging;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Windows.Forms;
  14. using static Metis.ParameterSet.ImageMenu;
  15. namespace PaintDotNet.Processing
  16. {
  17. /// <summary>
  18. /// 图像间操作
  19. /// </summary>
  20. internal class InterImageOpDialog : Form
  21. {
  22. #region 控件
  23. /// <summary>
  24. /// Required designer variable.
  25. /// </summary>
  26. private System.ComponentModel.IContainer components = null;
  27. /// <summary>
  28. /// Clean up any resources being used.
  29. /// </summary>
  30. /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  31. protected override void Dispose(bool disposing)
  32. {
  33. if (disposing && (components != null))
  34. {
  35. components.Dispose();
  36. }
  37. base.Dispose(disposing);
  38. }
  39. #region Windows Form Designer generated code
  40. /// <summary>
  41. /// Required method for Designer support - do not modify
  42. /// the contents of this method with the code editor.
  43. /// </summary>
  44. private void InitializeComponent()
  45. {
  46. this.components = new System.ComponentModel.Container();
  47. this.groupBoxParam = new System.Windows.Forms.GroupBox();
  48. this.listView1 = new System.Windows.Forms.ListView();
  49. this.imageList1 = new System.Windows.Forms.ImageList(this.components);
  50. this.labelFileName1 = new System.Windows.Forms.Label();
  51. this.label1 = new System.Windows.Forms.Label();
  52. this.button5 = new System.Windows.Forms.Button();
  53. this.informationControl = new PaintDotNet.CustomControl.InformationAdjustControl();
  54. this.parametersSettingControl = new PaintDotNet.CustomControl.ParametersSettingAdjustControl();
  55. this.groupBox1 = new System.Windows.Forms.GroupBox();
  56. this.groupBoxParam.SuspendLayout();
  57. this.SuspendLayout();
  58. //
  59. // groupBoxParam
  60. //
  61. this.groupBoxParam.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  62. | System.Windows.Forms.AnchorStyles.Left)));
  63. this.groupBoxParam.Controls.Add(this.listView1);
  64. this.groupBoxParam.Controls.Add(this.labelFileName1);
  65. this.groupBoxParam.Controls.Add(this.label1);
  66. this.groupBoxParam.Controls.Add(this.button5);
  67. this.groupBoxParam.Location = new System.Drawing.Point(12, 164);
  68. this.groupBoxParam.Name = "groupBoxParam";
  69. this.groupBoxParam.Size = new System.Drawing.Size(373, 574);
  70. this.groupBoxParam.TabIndex = 16;
  71. this.groupBoxParam.TabStop = false;
  72. //
  73. // listView1
  74. //
  75. this.listView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  76. | System.Windows.Forms.AnchorStyles.Left)
  77. | System.Windows.Forms.AnchorStyles.Right)));
  78. this.listView1.HideSelection = false;
  79. this.listView1.LargeImageList = this.imageList1;
  80. this.listView1.Location = new System.Drawing.Point(217, 152);
  81. this.listView1.Name = "listView1";
  82. this.listView1.Size = new System.Drawing.Size(113, 377);
  83. this.listView1.TabIndex = 7;
  84. this.listView1.UseCompatibleStateImageBehavior = false;
  85. this.listView1.Visible = false;
  86. this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged);
  87. this.listView1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.listView1_MouseClick);
  88. //
  89. // imageList1
  90. //
  91. this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
  92. this.imageList1.ImageSize = new System.Drawing.Size(64, 64);
  93. this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
  94. //
  95. // labelFileName1
  96. //
  97. this.labelFileName1.AutoSize = true;
  98. this.labelFileName1.Location = new System.Drawing.Point(88, 40);
  99. this.labelFileName1.Name = "labelFileName1";
  100. this.labelFileName1.Size = new System.Drawing.Size(221, 12);
  101. this.labelFileName1.TabIndex = 3;
  102. this.labelFileName1.Text = "label2label2label2label2label2label2";
  103. //
  104. // label1
  105. //
  106. this.label1.AutoSize = true;
  107. this.label1.Location = new System.Drawing.Point(11, 40);
  108. this.label1.Name = "label1";
  109. this.label1.Size = new System.Drawing.Size(0, 12);
  110. this.label1.TabIndex = 2;
  111. this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  112. //
  113. // button5
  114. //
  115. this.button5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
  116. this.button5.Location = new System.Drawing.Point(292, 545);
  117. this.button5.Name = "button5";
  118. this.button5.Size = new System.Drawing.Size(75, 23);
  119. this.button5.TabIndex = 1;
  120. this.button5.UseVisualStyleBackColor = true;
  121. this.button5.Click += new System.EventHandler(this.button5_Click);
  122. //
  123. // informationControl
  124. //
  125. this.informationControl.Location = new System.Drawing.Point(12, 76);
  126. this.informationControl.Name = "informationControl";
  127. this.informationControl.Size = new System.Drawing.Size(373, 82);
  128. this.informationControl.TabIndex = 15;
  129. //
  130. // parametersSettingControl
  131. //
  132. this.parametersSettingControl.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  133. | System.Windows.Forms.AnchorStyles.Right)));
  134. this.parametersSettingControl.Location = new System.Drawing.Point(12, 12);
  135. this.parametersSettingControl.Name = "parametersSettingControl";
  136. this.parametersSettingControl.Size = new System.Drawing.Size(776, 58);
  137. this.parametersSettingControl.TabIndex = 13;
  138. //
  139. // groupBox1
  140. //
  141. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  142. | System.Windows.Forms.AnchorStyles.Left)
  143. | System.Windows.Forms.AnchorStyles.Right)));
  144. this.groupBox1.Location = new System.Drawing.Point(392, 77);
  145. this.groupBox1.Name = "groupBox1";
  146. this.groupBox1.Size = new System.Drawing.Size(396, 661);
  147. this.groupBox1.TabIndex = 17;
  148. this.groupBox1.TabStop = false;
  149. this.groupBox1.Text = "预览";
  150. //
  151. // InterImageOpDialog
  152. //
  153. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  154. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  155. this.ClientSize = new System.Drawing.Size(800, 750);
  156. this.Controls.Add(this.groupBox1);
  157. this.Controls.Add(this.groupBoxParam);
  158. this.Controls.Add(this.informationControl);
  159. this.Controls.Add(this.parametersSettingControl);
  160. this.Name = "InterImageOpDialog";
  161. this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.InterImageOpDialog_FormClosing);
  162. this.Load += new System.EventHandler(this.InterImageOpDialog_Load);
  163. this.groupBoxParam.ResumeLayout(false);
  164. this.groupBoxParam.PerformLayout();
  165. this.ResumeLayout(false);
  166. }
  167. #endregion
  168. private System.Windows.Forms.GroupBox groupBoxParam;
  169. private System.Windows.Forms.Button button5;
  170. private CustomControl.InformationAdjustControl informationControl;
  171. private CustomControl.ParametersSettingAdjustControl parametersSettingControl;
  172. private System.Windows.Forms.Label label1;
  173. private System.Windows.Forms.Label labelFileName1;
  174. private System.Windows.Forms.ListView listView1;
  175. private ImageList imageList1;
  176. private GroupBox groupBox1;
  177. #endregion
  178. /// <summary>
  179. /// 步长 初始值1,依次增加
  180. /// </summary>
  181. string stepLength = "00" + Startup.instance.step_length;
  182. private AppWorkspace appWorkspace;
  183. /// <summary>
  184. /// 像素格式
  185. /// </summary>
  186. private PixelFormat pixelFormat;
  187. /// <summary>
  188. /// 处理程序
  189. /// </summary>
  190. private ParamObject action;
  191. /// <summary>
  192. /// 图像面板
  193. /// </summary>
  194. private DocumentWorkspaceWindow documentWorkspace;
  195. /// <summary>
  196. /// 公共按钮
  197. /// </summary>
  198. private CommonControlButtons commonControlButtons;
  199. // <summary>
  200. /// 如果有参数保存,将参数带入
  201. /// </summary>
  202. private Boolean initPamasValues = false;
  203. //图片选择窗口
  204. private InterImagePickerDialog imagePickerDialog;
  205. private PdnMenuItem MenuItem;
  206. [Browsable(false)]
  207. public AppWorkspace AppWorkspace
  208. {
  209. get
  210. {
  211. return this.appWorkspace;
  212. }
  213. set
  214. {
  215. this.appWorkspace = value;
  216. }
  217. }
  218. /// <summary>
  219. /// dialog
  220. /// </summary>
  221. /// <param name="appWorkspace"></param>
  222. /// <param name="menuId">对应菜单的id</param>
  223. public InterImageOpDialog(AppWorkspace appWorkspace, ActionType menuId, string dialogText, PdnMenuItem menuItem)
  224. {
  225. this.AppWorkspace = appWorkspace;
  226. InitializeComponent();
  227. this.MenuItem = menuItem;
  228. this.pixelFormat = this.AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.PixelFormat;
  229. this.Text = PdnResources.GetString("Menu.ImageProcessing.boundarydetection.Imageprodd.text");
  230. this.button5.Text = PdnResources.GetString("Menu.rebuild.Text");
  231. this.label1.Text = PdnResources.GetString("Menu.Inputimage1.text") + ":";
  232. this.groupBoxParam.Text = PdnResources.GetString("Menu.params.text");
  233. this.groupBox1.Text = PdnResources.GetString("Menu.Preview.text");
  234. //
  235. // 设置Dialog属性
  236. //
  237. this.StartPosition = FormStartPosition.CenterScreen;
  238. this.Icon = PdnInfo.AppIcon;
  239. this.Text = dialogText;
  240. //
  241. //初始化图像控件
  242. //
  243. this.documentWorkspace = new DocumentWorkspaceWindow(appWorkspace);
  244. this.documentWorkspace.Dock = DockStyle.Fill;
  245. this.documentWorkspace.HookMouseEvents();
  246. this.documentWorkspace.AuxiliaryLineEnabled = false;
  247. this.documentWorkspace.Visible = false;
  248. this.groupBox1.Controls.Add(documentWorkspace);
  249. //
  250. //初始化操作按钮
  251. //
  252. this.commonControlButtons = new CommonControlButtons();
  253. this.commonControlButtons.Dock = DockStyle.Top;
  254. this.commonControlButtons.Height = 30;
  255. this.commonControlButtons.HideZoomToWindowAndActualSize();
  256. this.groupBox1.Controls.Add(commonControlButtons);
  257. switch (menuId)
  258. {
  259. case ActionType.RealTimeStitching:
  260. action = new Data.Action.Action411();
  261. break;
  262. case ActionType.ActionImageAddition:
  263. action = new Data.Action.Action5050();
  264. break;
  265. case ActionType.ActionImageSubtraction:
  266. action = new Data.Action.Action5051();
  267. break;
  268. case ActionType.ActionImageMultiplication:
  269. action = new Data.Action.Action5052();
  270. break;
  271. case ActionType.ActionImageDivision:
  272. action = new Data.Action.Action5053();
  273. break;
  274. case ActionType.ActionImageAverage:
  275. action = new Data.Action.Action5054();
  276. break;
  277. case ActionType.ActionImageSquare:
  278. action = new Data.Action.Action5055();
  279. break;
  280. case ActionType.ActionImageSquareBoot:
  281. action = new Data.Action.Action5056();
  282. break;
  283. case ActionType.ActionImageLogarithm:
  284. action = new Data.Action.Action5057();
  285. break;
  286. case ActionType.ActionImageIndex:
  287. action = new Data.Action.Action5058();
  288. break;
  289. case ActionType.ActionImageMax:
  290. action = new Data.Action.Action5059();
  291. break;
  292. case ActionType.ActionImageMin:
  293. action = new Data.Action.Action5060();
  294. break;
  295. default:
  296. action = new Data.Action.Action5010();
  297. break;
  298. }
  299. if (action.Lists == null || action.Lists.Count < 1)
  300. {
  301. GetParameters(Startup.instance.imageMenuModel);
  302. //暂无参数
  303. }
  304. else
  305. {
  306. GetParameters(Startup.instance.imageMenuModel);
  307. int controlsTop = 45;
  308. //初始化手动控件
  309. for (int i = 0; i < action.Lists.Count; i++)
  310. {
  311. Args args = action.Lists[i];
  312. if (args is InputMatObject)
  313. {
  314. CustomControl.InputMatControl inputMat = new CustomControl.InputMatControl();
  315. inputMat.Left = 88;
  316. inputMat.Top = 35 + controlsTop;
  317. //设置参数范围
  318. inputMat.paramIndex = 100 + i;
  319. inputMat.selectButtonClick += new EventHandler(selectButtonImpl);//注册事件,在窗体中事件处理代码中预览图像处理效果
  320. groupBoxParam.Controls.Add(inputMat);
  321. groupBoxParam.Controls.SetChildIndex(inputMat, 100 + i);
  322. //inputMat.ValueChanged += new System.EventHandler(this.inputMat_ValueChanged); //111
  323. Label label = new Label();
  324. label.Left = 11;
  325. label.Top = 40 + controlsTop;
  326. label.Size = new Size(71, 12);
  327. label.TextAlign = ContentAlignment.MiddleRight;
  328. label.Text = args.name + ":";
  329. groupBoxParam.Controls.Add(label);
  330. controlsTop += 45;
  331. }
  332. else if (args is DecimalNumber)
  333. {
  334. CustomControl.NumberParamControl numberParam = new CustomControl.NumberParamControl();
  335. numberParam.Left = 88;
  336. numberParam.Top = 35 + controlsTop;
  337. //设置参数范围
  338. numberParam.paramIndex = 100 + i;
  339. numberParam.DecimalPlaces = ((DecimalNumber)args).DecimalPlaces;
  340. numberParam.Minimum = (double)((DecimalNumber)args).Min;
  341. numberParam.Maximum = (double)((DecimalNumber)args).Max;
  342. double fnum = 0;
  343. if (double.TryParse((initPamasValues ? args.value : args.initialValue).ToString(), out fnum))
  344. {
  345. numberParam.Value = fnum;
  346. }
  347. //numberParam.Value = /*(int)*/args.initialValue;
  348. groupBoxParam.Controls.Add(numberParam);
  349. groupBoxParam.Controls.SetChildIndex(numberParam, 100 + i);
  350. if (args is DecimalNumber)
  351. {
  352. numberParam.ValueChanged += new EventHandler(((DecimalNumber)args).numberParam_ValueChanged);
  353. }
  354. else
  355. {
  356. numberParam.ValueChanged += new EventHandler(((IntegerNumber)args).numberParam_ValueChanged);
  357. }
  358. Label label = new Label();
  359. label.Left = 11;
  360. label.Top = 40 + controlsTop;
  361. label.Size = new Size(71, 12);
  362. label.TextAlign = ContentAlignment.MiddleRight;
  363. label.Text = args.name + ":";
  364. groupBoxParam.Controls.Add(label);
  365. controlsTop += 45;
  366. }
  367. }
  368. }
  369. InitData();
  370. InitCommonButtonEvent();
  371. }
  372. /// <summary>
  373. /// 初始化数据
  374. /// </summary>
  375. public void InitData()
  376. {
  377. /// <summary>
  378. /// 当前活动的图像
  379. OpenCvSharp.Mat imageMat = this.AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreatedAliasedMat();
  380. //给picturebox赋值
  381. Document document = Document.FromImageMat(imageMat);//待测试
  382. this.documentWorkspace.Document = document;
  383. this.documentWorkspace.Visible = true;
  384. this.documentWorkspace.Refresh();
  385. //给输入图像1赋值
  386. labelFileName1.Text = AppWorkspace.ActiveDocumentWorkspace.GetFriendlyName();
  387. //初始化/重置参数
  388. resetNumber();
  389. //初始化图片列表
  390. for (int i = 0; i < AppWorkspace.DocumentWorkspaces.Length; i++)
  391. {
  392. this.imageList1.Images.Add("img" + i, AppWorkspace.DocumentWorkspaces[i].CompositionSurface.CreateAliasedBitmap());
  393. listView1.Items.Add("", i);
  394. listView1.Items[i].ImageIndex = i;
  395. listView1.Items[i].Name = "";
  396. }
  397. }
  398. private void InitCommonButtonEvent()
  399. {
  400. this.commonControlButtons.zoomInButton.Click += new EventHandler(zoomInButton_Click);
  401. this.commonControlButtons.zoomOutButton.Click += new EventHandler(zoomOutButton_Click);
  402. this.commonControlButtons.zoomToWindowButton.Click += new EventHandler(zoomToWindowButton_Click);
  403. this.commonControlButtons.actualSizeButton.Click += new EventHandler(actualSizeButton_Click);
  404. this.commonControlButtons.pointerButton.Click += new EventHandler(pointerButton_Click);
  405. this.commonControlButtons.mobileModeButton.Click += new EventHandler(mobileModeButton_Click);
  406. }
  407. private void zoomInButton_Click(object sender, EventArgs e)
  408. {
  409. this.documentWorkspace.ZoomIn();
  410. }
  411. private void zoomOutButton_Click(object sender, EventArgs e)
  412. {
  413. this.documentWorkspace.ZoomOut();
  414. }
  415. private void zoomToWindowButton_Click(object sender, EventArgs e)
  416. {
  417. this.documentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
  418. }
  419. private void actualSizeButton_Click(object sender, EventArgs e)
  420. {
  421. this.documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
  422. this.documentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
  423. }
  424. private void pointerButton_Click(object sender, EventArgs e)
  425. {
  426. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.Pointer;
  427. }
  428. private void mobileModeButton_Click(object sender, EventArgs e)
  429. {
  430. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode;
  431. }
  432. private void resetNumber()
  433. {
  434. foreach (Control control in groupBoxParam.Controls)//遍历参数面板上的所有控件
  435. {
  436. if (control is CustomControl.InputMatControl)
  437. {
  438. CustomControl.InputMatControl inputMat = (CustomControl.InputMatControl)control;
  439. inputMat.TextValue = AppWorkspace.ActiveDocumentWorkspace.GetFriendlyName();
  440. if (inputMat.paramIndex >= 100)
  441. {
  442. Args args = action.Lists[inputMat.paramIndex - 100];
  443. args.Value = AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreatedAliasedMat().Clone();
  444. }
  445. }
  446. else if (control is CustomControl.NumberParamControl && ((CustomControl.NumberParamControl)control).paramIndex >= 100)
  447. {
  448. CustomControl.NumberParamControl numberParam = (CustomControl.NumberParamControl)control;
  449. //List<Args> list1s = action.Lists[0];
  450. Args args = /*list1s*/action.Lists[numberParam.paramIndex - 100];
  451. double fnum = 0;
  452. if (double.TryParse((initPamasValues ? args.value : args.initialValue).ToString(), out fnum))
  453. {
  454. numberParam.Value = fnum;
  455. }
  456. //numberParam.Value = (int)args.initialValue;
  457. }
  458. }
  459. }
  460. private void InterImageOpDialog_Load(object sender, EventArgs e)
  461. {
  462. //图像名称输入框
  463. informationControl.fileNameTextBox1.Text = this.Text + "-" + stepLength;
  464. //picturePreviewControl1.isShown = true;
  465. parametersSettingControl.applyButtonClick += new EventHandler(applyButtonImpl);//注册事件,在窗体中事件处理代码中预览图像处理效果
  466. parametersSettingControl.sureButtonClick += new EventHandler(sureButtonImpl);//注册事件,在窗体中事件处理代码中预览图像处理效果
  467. }
  468. //应用
  469. private void applyButtonImpl(object sender, EventArgs e)
  470. {
  471. OpenCvSharp.Mat mat = action.PerformProcess(AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreatedAliasedMat().Clone());
  472. Document document = Document.FromMat(mat);
  473. this.documentWorkspace.Document = document;
  474. this.documentWorkspace.Refresh();
  475. //picturePreviewControl1.pictureBox1.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat);
  476. if (action.MenuId == ActionType.RealTimeStitching)
  477. {
  478. Document doc = Document.FromMat(mat.Clone());
  479. AppWorkspace.ActiveDocumentWorkspace.Document = doc;
  480. AppWorkspace.ActiveDocumentWorkspace.Refresh();
  481. }
  482. }
  483. //确定
  484. internal void sureButtonImpl(object sender, EventArgs e)
  485. {
  486. OpenCvSharp.Mat mat = action.PerformProcess(AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreatedAliasedMat().Clone());
  487. if (this.pixelFormat == PixelFormat.Format8bppIndexed && mat.Type() != OpenCvSharp.MatType.CV_8UC1)
  488. {
  489. mat = mat.CvtColor(OpenCvSharp.ColorConversionCodes.BGR2GRAY);
  490. }
  491. //生成新图-是
  492. if (informationControl.radioButton1.Checked)
  493. {
  494. this.OpenFileImpl(mat);
  495. }
  496. else
  497. {
  498. AppWorkspace.ActiveDocumentWorkspace.Document = Document.FromMat(mat);
  499. AppWorkspace.ActiveDocumentWorkspace.Refresh();
  500. //AppWorkspace.ActiveDocumentWorkspace.CompositionSurface = Surface.CopyFromBitmap(OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat));
  501. }
  502. this.Close();
  503. }
  504. //生成新图
  505. private void OpenFileImpl(OpenCvSharp.Mat mat)
  506. {
  507. DocumentWorkspace dw = AppWorkspace.AddNewDocumentWorkspace();
  508. Document document = Document.FromImageMat(mat);
  509. dw.Document = document;
  510. dw.fileText = informationControl.fileNameTextBox1.Text;
  511. dw.xmlSaveModel = this.AppWorkspace.ActiveDocumentWorkspace.xmlSaveModel;
  512. dw.rules = this.AppWorkspace.ActiveDocumentWorkspace.rules;
  513. AppWorkspace.ActiveDocumentWorkspace = dw;
  514. Startup.instance.step_length += 1;
  515. }
  516. //参数-重设
  517. private void button5_Click(object sender, EventArgs e)
  518. {
  519. //初始化/重置参数
  520. resetNumber();
  521. documentWorkspace.Document = AppWorkspace.ActiveDocumentWorkspace.Document;
  522. documentWorkspace.Refresh();
  523. }
  524. private void listView1_SelectedIndexChanged(object sender, EventArgs e)
  525. {
  526. foreach (Control control in groupBoxParam.Controls)//遍历参数面板上的所有控件
  527. {
  528. if (control is CustomControl.InputMatControl)
  529. {
  530. CustomControl.InputMatControl inputMat = (CustomControl.InputMatControl)control;
  531. inputMat.TextValue = AppWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetFriendlyName();
  532. if (inputMat.paramIndex >= 100)
  533. {
  534. Args args = action.Lists[inputMat.paramIndex - 100];
  535. args.Value = AppWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreatedAliasedMat().Clone();
  536. ((InputMatObject)args).FriendlyName = AppWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetFriendlyName();
  537. ((InputMatObject)args).FilePath = AppWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].FilePath;
  538. }
  539. }
  540. }
  541. listView1.Visible = false;
  542. }
  543. /// <summary>
  544. /// 选择图像按钮点击事件
  545. /// </summary>
  546. /// <param name="sender"></param>
  547. /// <param name="e"></param>
  548. private void selectButtonImpl(object sender, EventArgs e)
  549. {
  550. //listView1.Visible = true;
  551. if (imagePickerDialog == null)
  552. {
  553. imagePickerDialog = new InterImagePickerDialog(AppWorkspace);
  554. //imagePickerDialog.StartPosition = FormStartPosition.CenterScreen;
  555. imagePickerDialog.StartPosition = FormStartPosition.Manual;
  556. //Point pt = MousePosition;//获取鼠标的屏幕坐标// PointToScreen(((CustomControl.InputMatControl)sender).Location).Y + ((CustomControl.InputMatControl)sender).Height;//
  557. imagePickerDialog.Left = ((CustomControl.InputMatControl)sender).Left + 12 + this.Left + groupBoxParam.Left;// pt.X;
  558. imagePickerDialog.Top = ((CustomControl.InputMatControl)sender).Bottom + 36 + this.Top + groupBoxParam.Top;// pt.Y;
  559. imagePickerDialog.ValueChanged += new System.EventHandler(this.inputMat_ValueChanged);
  560. imagePickerDialog.Show();
  561. }
  562. else
  563. {
  564. if (!imagePickerDialog.IsDisposed)
  565. {
  566. imagePickerDialog.WindowState = FormWindowState.Normal;
  567. }
  568. else
  569. {
  570. imagePickerDialog = new InterImagePickerDialog(AppWorkspace);
  571. //imagePickerDialog.StartPosition = FormStartPosition.CenterScreen;
  572. imagePickerDialog.StartPosition = FormStartPosition.Manual;
  573. //Point pt = MousePosition;//获取鼠标的屏幕坐标
  574. imagePickerDialog.Left = ((CustomControl.InputMatControl)sender).Left + 12 + this.Left + groupBoxParam.Left;// pt.X;
  575. imagePickerDialog.Top = ((CustomControl.InputMatControl)sender).Bottom + 36 + this.Top + groupBoxParam.Top;// pt.Y;
  576. imagePickerDialog.ValueChanged += new System.EventHandler(this.inputMat_ValueChanged);
  577. imagePickerDialog.Show();
  578. }
  579. }
  580. }
  581. private void inputMat_ValueChanged(object sender, EventArgs e) //111
  582. {
  583. //DocumentWorkspace workspace = AppWorkspace.DocumentWorkspaces[this.dataGridView1.CurrentRow.Index];
  584. if (sender is DocumentWorkspace)
  585. {
  586. foreach (Control control in groupBoxParam.Controls)//遍历参数面板上的所有控件
  587. {
  588. if (control is CustomControl.InputMatControl)
  589. {
  590. CustomControl.InputMatControl inputMat = (CustomControl.InputMatControl)control;
  591. inputMat.TextValue = ((DocumentWorkspace)sender).GetFriendlyName();
  592. if (inputMat.paramIndex >= 100)
  593. {
  594. Args args = action.Lists[inputMat.paramIndex - 100];
  595. args.Value = ((DocumentWorkspace)sender).CompositionSurface.CreatedAliasedMat().Clone();
  596. ((InputMatObject)args).FriendlyName = ((DocumentWorkspace)sender).GetFriendlyName();
  597. ((InputMatObject)args).FilePath = ((DocumentWorkspace)sender).FilePath;
  598. }
  599. }
  600. }
  601. }
  602. //Bitmap map = workspace.SurfaceBox.Surface.CreateAliasedBitmap();
  603. //OpenCvSharp.Mat mat = PaintDotNet.Camera.Tools.ToMat(map);
  604. ////改变Args的值
  605. //Args args = action.Lists[((OpenCvSharp.Mat)sender).paramIndex - 100];
  606. ////args.Value = ((CustomControl.InputMatControl)sender).Value;
  607. }
  608. private void listView1_MouseClick(object sender, MouseEventArgs e)
  609. {
  610. foreach (Control control in groupBoxParam.Controls)//遍历参数面板上的所有控件
  611. {
  612. if (control is CustomControl.InputMatControl)
  613. {
  614. CustomControl.InputMatControl inputMat = (CustomControl.InputMatControl)control;
  615. inputMat.TextValue = AppWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetFriendlyName();
  616. if (inputMat.paramIndex >= 100)
  617. {
  618. Args args = action.Lists[inputMat.paramIndex - 100];
  619. args.Value = AppWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreatedAliasedMat().Clone();
  620. ((InputMatObject)args).FriendlyName = AppWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetFriendlyName();
  621. ((InputMatObject)args).FilePath = AppWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].FilePath;
  622. }
  623. //inputMat.
  624. }
  625. }
  626. listView1.Visible = false;
  627. }
  628. private void InterImageOpDialog_FormClosing(object sender, FormClosingEventArgs e)
  629. {
  630. #region [开启脚本录制]
  631. if (appWorkspace.startScriptRecording)
  632. {
  633. getScriptRecording();
  634. }
  635. #endregion
  636. string newpic = 1 + "";
  637. ImageMenu imageMenu;
  638. if (Startup.instance.imageMenuModel != null)
  639. {
  640. imageMenu = Startup.instance.imageMenuModel;
  641. }
  642. else
  643. {
  644. imageMenu = new ImageMenu();
  645. imageMenu.ListParam = new List<ImageParam>();
  646. }
  647. if (informationControl.radioButton1.Checked)
  648. newpic = 1 + "";
  649. else
  650. newpic = 0 + "";
  651. List<ImageParam> list = imageMenu.ListParam.Where(x => x.menuId == (int)action.MenuId).ToList();
  652. if (list.Count == 0)
  653. {
  654. ImageParam param = new ImageParam();
  655. param.menuId = (int)action.MenuId;
  656. param.param_key = "param_newpic";
  657. param.param_type = -1;
  658. param.param_value = newpic;
  659. imageMenu.ListParam.Add(param);
  660. }
  661. //imageMenu.ListParam = new List<mic_script_step_param>();
  662. if (action.lists.Count > 0)
  663. {
  664. for (int i = 0; i < action.lists.Count; i++)
  665. {
  666. if (list.Count > 0)
  667. {
  668. for (int j = 0; j < imageMenu.ListParam.Count; j++)
  669. {
  670. if (imageMenu.ListParam[j].menuId == (int)action.MenuId && imageMenu.ListParam[j].param_key == action.lists[i].key)
  671. {
  672. imageMenu.ListParam[j].param_type = (int)action.lists[i].Type;
  673. imageMenu.ListParam[j].param_value = action.lists[i].value.ToString();
  674. //imageMenu.ListParam[j].param_newpic = informationControl.radioButton1.Checked;
  675. }
  676. else if (imageMenu.ListParam[j].menuId == (int)action.MenuId && imageMenu.ListParam[j].param_key == "param_newpic")
  677. {
  678. //imageMenu.ListParam[j].param_type = (int)action.lists[i].Type;
  679. imageMenu.ListParam[j].param_value = newpic;
  680. //imageMenu.ListParam[j].param_newpic = informationControl.radioButton1.Checked;
  681. }
  682. }
  683. }
  684. else
  685. {
  686. ImageParam param = new ImageParam();
  687. param.menuId = (int)action.MenuId;
  688. param.param_key = action.lists[i].key;
  689. param.param_type = (int)action.lists[i].Type;
  690. param.param_value = action.lists[i].value.ToString();
  691. imageMenu.ListParam.Add(param);
  692. }
  693. }
  694. }
  695. else
  696. {
  697. if (list.Count > 0)
  698. {
  699. for (int j = 0; j < imageMenu.ListParam.Count; j++)
  700. {
  701. if (imageMenu.ListParam[j].menuId == (int)action.MenuId && imageMenu.ListParam[j].param_key == "param_newpic")
  702. {
  703. imageMenu.ListParam[j].param_value = newpic;
  704. }
  705. }
  706. }
  707. }
  708. Startup.instance.imageMenuModel = imageMenu;
  709. //按路径和名称保存xml文件
  710. string userInfoXml = XmlSerializeHelper.XmlSerialize<ImageMenu>(imageMenu);
  711. //xml保存路径
  712. string filePath = Application.StartupPath + "\\Config\\" + "Default\\ParameterSaving\\ParameterSaving.xml";
  713. //保存xml
  714. FileOperationHelper.WriteStringToFile(userInfoXml, filePath, FileMode.Create);
  715. }
  716. public void GetParameters(ImageMenu imageMenu)
  717. {
  718. List<ImageParam> list = new List<ImageParam>();
  719. if (imageMenu.ListParam.Count > 0)
  720. list = imageMenu.ListParam.Where(x => x.menuId == (int)action.MenuId).ToList();
  721. if (list.Count > 0)
  722. {
  723. initPamasValues = true;
  724. for (int i = 0; i < action.Lists.Count; i++)
  725. {
  726. for (int j = 0; j < list.Count; j++)
  727. {
  728. if (list[j].param_key.Equals(action.Lists[i].key))
  729. {
  730. action.Lists[i].Type = (Dtryt)list[j].param_type;
  731. action.Lists[i].value = list[j].param_value;
  732. break;
  733. }
  734. }
  735. }
  736. for (int j = 0; j < list.Count; j++)
  737. {
  738. if ("param_newpic".Equals(list[j].param_key))
  739. {
  740. if (list[j].param_value == "1")
  741. {
  742. informationControl.radioButton1.Checked = true;
  743. informationControl.radioButton2.Checked = false;
  744. }
  745. else
  746. {
  747. informationControl.radioButton1.Checked = false;
  748. informationControl.radioButton2.Checked = true;
  749. }
  750. }
  751. }
  752. }
  753. }
  754. #region [脚本录制]
  755. private void getScriptRecording()
  756. {
  757. List<Args> args = action.Lists;
  758. appWorkspace.SetScriptStartRecording(MenuItem.MenuId, MenuItem.Text, args);
  759. }
  760. #endregion
  761. }
  762. }