InterImageOpDialog.cs 37 KB

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