GrainBoundaryEditingDialog .cs 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  1. using OpenCvSharp;
  2. using PaintDotNet.Adjust;
  3. using PaintDotNet.Base.Functionodel;
  4. using PaintDotNet.CustomControl;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Drawing;
  8. using System.Drawing.Drawing2D;
  9. using System.Windows.Forms;
  10. using Point = System.Drawing.Point;
  11. namespace PaintDotNet.DedicatedAnalysis.GrainSize.GBT6394_2017
  12. {
  13. internal class GrainBoundaryEditingDialog : Form
  14. {
  15. /// <summary>
  16. /// 公共按钮
  17. /// </summary>
  18. private CommonControlButtons commonControlButtons;
  19. /// <summary>
  20. /// 主控件
  21. /// </summary>
  22. private AppWorkspace appWorkspace;
  23. private DocumentWorkspaceWindow documentWorkspace;
  24. /// <summary>
  25. /// 外接矩形,或者是计算的矩形
  26. /// </summary>
  27. protected RectangleF rectangle = new RectangleF();
  28. /// <summary>
  29. /// 存在视场标记
  30. /// </summary>
  31. private bool existViewFlag = false;
  32. /// <summary>
  33. /// 选中图片的bitmap
  34. /// </summary>
  35. private Bitmap bitmap;
  36. /// <summary>
  37. /// 当前选择的图片
  38. /// </summary>
  39. private Mat mat;
  40. /// <summary>
  41. /// 用于get处理后的图像
  42. /// </summary>
  43. private Mat phaseMat;
  44. Color phaseColor;
  45. /// <summary>
  46. /// 操作类型
  47. /// 0,没有操作 1,折线添加 2,直线添加
  48. /// 11,多边形删除 12,圆形删除 13,矩形删除 14,椭圆删除
  49. /// </summary>
  50. private int pointKtype = 0;
  51. /// <summary>
  52. /// 起始点
  53. /// </summary>
  54. private Point startPoint = new Point(-1, -1);
  55. /// <summary>
  56. /// 结束点
  57. /// </summary>
  58. private Point endPoint = new Point(-1, -1);
  59. /// <summary>
  60. /// 折线点的集合
  61. /// </summary>
  62. public List<Point> pointArray = new List<Point>();
  63. //1013###19326 晶粒度的晶界编辑页面,需要把辅助线带过去(客户编辑只处理辅助线位置的晶界)
  64. /// <summary>
  65. /// 辅助线集成
  66. /// </summary>
  67. private GrainSizeGuideClass guideClass;
  68. public object SelectedItem;
  69. private GroupBox groupBox1;
  70. private GroupBox groupBox2;
  71. private GroupBox groupBox3;
  72. private Button button2;
  73. private Button button1;
  74. private Button button3;
  75. private Button button4;
  76. private Button button8;
  77. private Button button7;
  78. private Button button6;
  79. private Button button5;
  80. private Button button9;
  81. private GroupBox groupBox7;
  82. public GrainSizeGuideClass GuideClass
  83. {
  84. set
  85. {
  86. this.guideClass = value;
  87. }
  88. }
  89. public GrainBoundaryEditingDialog(AppWorkspace appWorkspace, int focusedItemIndex, Color phaseColor, Mat phaseMat)
  90. {
  91. this.appWorkspace = appWorkspace;
  92. InitializeComponent();
  93. InitializeLanguageText();
  94. //
  95. //初始化图像控件
  96. //
  97. this.documentWorkspace = new DocumentWorkspaceWindow(appWorkspace);
  98. this.documentWorkspace.Dock = DockStyle.Fill;
  99. this.documentWorkspace.HookMouseEvents();
  100. this.documentWorkspace.AuxiliaryLineEnabled = false;
  101. this.documentWorkspace.Visible = false;
  102. this.documentWorkspace.panel.MouseDown += OnMouseDown;
  103. this.documentWorkspace.panel.Paint += Panel_Paint;
  104. this.documentWorkspace.panel.MouseMove += onMouseMove;
  105. this.documentWorkspace.panel.MouseUp += onMouseUp;
  106. this.documentWorkspace.panel.Click += new EventHandler(this.pictureBox1_Click);
  107. this.groupBox7.Controls.Add(documentWorkspace);
  108. //
  109. //初始化操作按钮
  110. //
  111. this.commonControlButtons = new CommonControlButtons();
  112. this.commonControlButtons.Dock = DockStyle.Top;
  113. this.commonControlButtons.Height = 30;
  114. this.commonControlButtons.HideZoomToWindowAndActualSize();
  115. this.groupBox7.Controls.Add(commonControlButtons);
  116. this.phaseColor = phaseColor;
  117. {
  118. //
  119. //初始化相
  120. //
  121. PhaseModel model = new PhaseModel();
  122. model.choise = true;
  123. model.mat = null;
  124. model.color = phaseColor.ToArgb();// Color.Green/*panel2.BackColor*/.ToArgb();
  125. model.position = this.documentWorkspace.PhaseModels.Count + 1;
  126. model.name = PdnResources.GetString("Menu.Grainboundarytoreproduce.text");
  127. this.documentWorkspace.PhaseModels.Add(model);
  128. }
  129. this.documentWorkspace.PhaseModels[0].mat = phaseMat;
  130. this.documentWorkspace.Refresh();
  131. existViewFlag = this.appWorkspace.DocumentWorkspaces[focusedItemIndex].GraphicsList.IsExsitView();
  132. this.bitmap = this.appWorkspace.DocumentWorkspaces[focusedItemIndex].CompositionSurface.CreateAliasedBitmap();
  133. if (!existViewFlag)
  134. {
  135. mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap);
  136. }
  137. else
  138. {
  139. mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(this.appWorkspace.DocumentWorkspaces[focusedItemIndex].GetFullSizeWithRegion());
  140. }
  141. Document document = Document.FromImage(bitmap);
  142. this.documentWorkspace.Document = document;
  143. this.documentWorkspace.Visible = true;
  144. this.documentWorkspace.GraphicsList = this.appWorkspace.DocumentWorkspaces[focusedItemIndex].GraphicsList;
  145. InitCommonButtonEvent();
  146. }
  147. #region 矩形拖动
  148. /// <summary>
  149. /// 鼠标按下
  150. /// </summary>
  151. /// <param name="drawArea"></param>
  152. /// <param name="e"></param>
  153. private void OnMouseDown(object sender, MouseEventArgs e)
  154. {
  155. // 换算后的点
  156. PointF point1 = documentWorkspace.GetScalePoint(e.Location);
  157. if (point1.X <= this.documentWorkspace.CompositionSurface.Width
  158. && point1.X >= 0
  159. && point1.Y >= 0
  160. && point1.Y <= this.documentWorkspace.CompositionSurface.Height)
  161. {
  162. if (e.Button == MouseButtons.Left && this.pointKtype >= 1
  163. && startPoint.X == -1 && startPoint.Y == -1)
  164. startPoint = new Point((int)point1.X, (int)point1.Y);
  165. }
  166. }
  167. /// <summary>
  168. /// 移动
  169. /// </summary>
  170. /// <param name="sender"></param>
  171. /// <param name="e"></param>
  172. private void onMouseMove(object sender, MouseEventArgs e)
  173. {
  174. // 换算后的点
  175. PointF point1 = documentWorkspace.GetScalePoint(e.Location);
  176. if (e.Button == MouseButtons.Left)
  177. {
  178. // 椭圆删除/圆形删除
  179. if ((this.pointKtype == 14 || this.pointKtype == 12) && this.startPoint.X > -1 && this.startPoint.Y > -1)
  180. {
  181. endPoint = new Point((int)point1.X, (int)point1.Y);
  182. if (this.startPoint.X < this.endPoint.X)
  183. {
  184. this.rectangle.X = this.startPoint.X;
  185. this.rectangle.Width = this.endPoint.X - this.startPoint.X;
  186. }
  187. else
  188. {
  189. this.rectangle.X = this.endPoint.X;
  190. this.rectangle.Width = this.startPoint.X - this.endPoint.X;
  191. }
  192. if (this.startPoint.Y < this.endPoint.Y)
  193. {
  194. this.rectangle.Y = this.startPoint.Y;
  195. this.rectangle.Height = this.endPoint.Y - this.startPoint.Y;
  196. }
  197. else
  198. {
  199. this.rectangle.Y = this.endPoint.Y;
  200. this.rectangle.Height = this.startPoint.Y - this.endPoint.Y;
  201. }
  202. this.documentWorkspace.Refresh();
  203. }
  204. // 矩形删除
  205. if (this.pointKtype == 13 && this.startPoint.X > -1 && this.startPoint.Y > -1)
  206. {
  207. endPoint = new Point((int)point1.X, (int)point1.Y);
  208. if (this.startPoint.X < this.endPoint.X)
  209. {
  210. this.rectangle.X = this.startPoint.X;
  211. this.rectangle.Width = this.endPoint.X - this.startPoint.X;
  212. }
  213. else
  214. {
  215. this.rectangle.X = this.endPoint.X;
  216. this.rectangle.Width = this.startPoint.X - this.endPoint.X;
  217. }
  218. if (this.startPoint.Y < this.endPoint.Y)
  219. {
  220. this.rectangle.Y = this.startPoint.Y;
  221. this.rectangle.Height = this.endPoint.Y - this.startPoint.Y;
  222. }
  223. else
  224. {
  225. this.rectangle.Y = this.endPoint.Y;
  226. this.rectangle.Height = this.startPoint.Y - this.endPoint.Y;
  227. }
  228. this.documentWorkspace.Refresh();
  229. }
  230. // 直线添加
  231. if (this.pointKtype == 2 && this.startPoint.X > -1 && this.startPoint.Y > -1)
  232. {
  233. endPoint = new Point((int)point1.X, (int)point1.Y);
  234. this.documentWorkspace.Refresh();
  235. }
  236. }
  237. }
  238. /// <summary>
  239. /// 鼠标抬起
  240. /// </summary>
  241. /// <param name="sender"></param>
  242. /// <param name="e"></param>
  243. private void onMouseUp(object sender, MouseEventArgs e)
  244. {
  245. // 换算后的点
  246. PointF point1 = documentWorkspace.GetScalePoint(e.Location);
  247. if (point1.X <= this.documentWorkspace.CompositionSurface.Width
  248. && point1.X >= 0
  249. && point1.Y >= 0
  250. && point1.Y <= this.documentWorkspace.CompositionSurface.Height) { }
  251. else
  252. return;
  253. if (e.Button == MouseButtons.Right)
  254. {
  255. // 折线删除
  256. if (this.pointKtype == 11 && pointArray.Count > 1)
  257. {
  258. pointArray.Add(new Point((int)point1.X, (int)point1.Y));
  259. endPoint = new Point((int)point1.X, (int)point1.Y);
  260. List<PointF> pointFArray = new List<PointF>();
  261. foreach (var item in pointArray)
  262. {
  263. pointFArray.Add(new PointF(item.X, item.Y));
  264. }
  265. this.documentWorkspace.PhaseModels[0].mat = PreActionIntent.PolygonDelete(this.documentWorkspace.PhaseModels[0].mat, pointFArray);
  266. ////保存处理后的图片
  267. //Bitmap originalBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.documentWorkspace.PhaseModels[0].mat);
  268. //Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  269. //Graphics graphics = Graphics.FromImage(newBit);
  270. //Draw(graphics);
  271. //this.documentWorkspace.PhaseModels[0].mat/* = phaseMat*/ = OpenCvSharp.Extensions.BitmapConverter.ToMat(newBit);
  272. this.rectangle.X = -1;
  273. this.rectangle.Y = -1;
  274. this.rectangle.Width = 0;
  275. this.rectangle.Height = 0;
  276. pointArray.Clear();
  277. startPoint = new Point(-1, -1);
  278. endPoint = new Point(-1, -1);
  279. this.pointKtype = 0;
  280. this.documentWorkspace.Refresh();
  281. }
  282. // 折线添加
  283. if (this.pointKtype == 1 && pointArray.Count > 1)
  284. {
  285. pointArray.Add(new Point((int)point1.X, (int)point1.Y));
  286. endPoint = new Point((int)point1.X, (int)point1.Y);
  287. //保存处理后的图片
  288. Bitmap originalBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.documentWorkspace.PhaseModels[0].mat);
  289. Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  290. Graphics graphics = Graphics.FromImage(newBit);
  291. Draw(graphics, false);
  292. this.documentWorkspace.PhaseModels[0].mat/* = phaseMat*/ = OpenCvSharp.Extensions.BitmapConverter.ToMat(newBit);
  293. pointArray.Clear();
  294. startPoint = new Point(-1, -1);
  295. endPoint = new Point(-1, -1);
  296. this.pointKtype = 0;
  297. this.documentWorkspace.Refresh();
  298. }
  299. }
  300. if (e.Button == MouseButtons.Left)
  301. {
  302. // 圆形删除/椭圆删除
  303. if ((this.pointKtype == 14 || this.pointKtype == 12) && this.startPoint.X > -1 && this.startPoint.Y > -1)
  304. {
  305. endPoint = new Point((int)point1.X, (int)point1.Y);
  306. if (this.startPoint.X < this.endPoint.X)
  307. {
  308. this.rectangle.X = this.startPoint.X;
  309. this.rectangle.Width = this.endPoint.X - this.startPoint.X;
  310. }
  311. else
  312. {
  313. this.rectangle.X = this.endPoint.X;
  314. this.rectangle.Width = this.startPoint.X - this.endPoint.X;
  315. }
  316. if (this.startPoint.Y < this.endPoint.Y)
  317. {
  318. this.rectangle.Y = this.startPoint.Y;
  319. this.rectangle.Height = this.endPoint.Y - this.startPoint.Y;
  320. }
  321. else
  322. {
  323. this.rectangle.Y = this.endPoint.Y;
  324. this.rectangle.Height = this.startPoint.Y - this.endPoint.Y;
  325. }
  326. if (this.pointKtype == 14)
  327. this.documentWorkspace.PhaseModels[0].mat = PreActionIntent.OvalDelete(this.documentWorkspace.PhaseModels[0].mat, this.rectangle);
  328. else
  329. this.documentWorkspace.PhaseModels[0].mat = PreActionIntent.OvalDelete(this.documentWorkspace.PhaseModels[0].mat
  330. , new RectangleF(this.rectangle.X, this.rectangle.Y, Math.Min(this.rectangle.Width, this.rectangle.Height), Math.Min(this.rectangle.Width, this.rectangle.Height)));
  331. this.rectangle.X = -1;
  332. this.rectangle.Y = -1;
  333. this.rectangle.Width = 0;
  334. this.rectangle.Height = 0;
  335. startPoint = new Point(-1, -1);
  336. endPoint = new Point(-1, -1);
  337. this.pointKtype = 0;
  338. this.documentWorkspace.Refresh();
  339. }
  340. // 矩形删除
  341. if (this.pointKtype == 13 && this.startPoint.X > -1 && this.startPoint.Y > -1)
  342. {
  343. endPoint = new Point((int)point1.X, (int)point1.Y);
  344. if (this.startPoint.X < this.endPoint.X)
  345. {
  346. this.rectangle.X = this.startPoint.X;
  347. this.rectangle.Width = this.endPoint.X - this.startPoint.X;
  348. }
  349. else
  350. {
  351. this.rectangle.X = this.endPoint.X;
  352. this.rectangle.Width = this.startPoint.X - this.endPoint.X;
  353. }
  354. if (this.startPoint.Y < this.endPoint.Y)
  355. {
  356. this.rectangle.Y = this.startPoint.Y;
  357. this.rectangle.Height = this.endPoint.Y - this.startPoint.Y;
  358. }
  359. else
  360. {
  361. this.rectangle.Y = this.endPoint.Y;
  362. this.rectangle.Height = this.startPoint.Y - this.endPoint.Y;
  363. }
  364. this.documentWorkspace.PhaseModels[0].mat = PreActionIntent.RectangleDelete(this.documentWorkspace.PhaseModels[0].mat, this.rectangle);
  365. //p.mat = PreActionIntent.RectangleDelete(p.mat, rect);
  366. ////保存处理后的图片
  367. //Bitmap originalBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.documentWorkspace.PhaseModels[0].mat);
  368. //Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  369. //Graphics graphics = Graphics.FromImage(newBit);
  370. //Draw(graphics);
  371. //this.documentWorkspace.PhaseModels[0].mat/* = phaseMat*/ = OpenCvSharp.Extensions.BitmapConverter.ToMat(newBit);
  372. this.rectangle.X = -1;
  373. this.rectangle.Y = -1;
  374. this.rectangle.Width = 0;
  375. this.rectangle.Height = 0;
  376. startPoint = new Point(-1, -1);
  377. endPoint = new Point(-1, -1);
  378. this.pointKtype = 0;
  379. this.documentWorkspace.Refresh();
  380. }
  381. // 折线添加/折线删除
  382. if (this.pointKtype == 1 || this.pointKtype == 11)
  383. {
  384. pointArray.Add(new Point((int)point1.X, (int)point1.Y));
  385. if (this.startPoint.X > -1 && this.startPoint.Y > -1)
  386. {
  387. }
  388. else
  389. startPoint = new Point((int)point1.X, (int)point1.Y);
  390. this.documentWorkspace.Refresh();
  391. }
  392. // 直线添加
  393. if (this.pointKtype == 2 && this.startPoint.X > -1 && this.startPoint.Y > -1)
  394. {
  395. endPoint = new Point((int)point1.X, (int)point1.Y);
  396. //保存处理后的图片
  397. Bitmap originalBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.documentWorkspace.PhaseModels[0].mat);
  398. Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  399. Graphics graphics = Graphics.FromImage(newBit);
  400. Draw(graphics, false);
  401. this.documentWorkspace.PhaseModels[0].mat/* = phaseMat*/ = OpenCvSharp.Extensions.BitmapConverter.ToMat(newBit);
  402. startPoint = new Point(-1, -1);
  403. endPoint = new Point(-1, -1);
  404. this.pointKtype = 0;
  405. this.documentWorkspace.Refresh();
  406. }
  407. }
  408. }
  409. #endregion
  410. /// <summary>
  411. /// surfaceBox双击事件
  412. /// 目前是参考AxioVision
  413. /// 应该是把每次选的点都取最高和最低的BGR
  414. /// </summary>
  415. /// <param name="sender"></param>
  416. /// <param name="e"></param>
  417. private unsafe void pictureBox1_Click(object sender, EventArgs e)
  418. {
  419. }
  420. /// <summary>
  421. /// 画布绘制
  422. /// </summary>
  423. /// <param name="sender"></param>
  424. /// <param name="e"></param>
  425. private void Panel_Paint(object sender, PaintEventArgs e)
  426. {
  427. if (this.documentWorkspace.CompositionSurface != null)
  428. {
  429. //
  430. // 以下是计算绘制图片的位置和大小并绘制图片
  431. //
  432. System.Drawing.Rectangle rc = this.documentWorkspace.panel.ClientRectangle;
  433. int width = (int)(this.documentWorkspace.CompositionSurface.Width * this.documentWorkspace.ScaleFactor.Ratio);
  434. int height = (int)(this.documentWorkspace.CompositionSurface.Height * this.documentWorkspace.ScaleFactor.Ratio);
  435. int x = (rc.Width < width) ? this.documentWorkspace.panel.AutoScrollPosition.X : (rc.Width - width) / 2;
  436. int y = (rc.Height < height) ? this.documentWorkspace.panel.AutoScrollPosition.Y : (rc.Height - height) / 2;
  437. //
  438. // 以下是绘制网格、标注、测量、视场等开始
  439. //
  440. e.Graphics.TranslateTransform(x, y);
  441. e.Graphics.ScaleTransform((float)this.documentWorkspace.ScaleFactor.Ratio, (float)this.documentWorkspace.ScaleFactor.Ratio);
  442. //if (this.checkBox4_0.Checked)//显示网格
  443. Draw(e.Graphics, true);
  444. e.Graphics.ScaleTransform(1 / (float)this.documentWorkspace.ScaleFactor.Ratio, 1 / (float)this.documentWorkspace.ScaleFactor.Ratio);
  445. e.Graphics.TranslateTransform(-x, -y);
  446. }
  447. }
  448. /// <summary>
  449. /// 绘制
  450. /// </summary>
  451. private void Draw(Graphics g, bool DrawGuideLines)
  452. {
  453. // 抗锯齿
  454. g.SmoothingMode = SmoothingMode.AntiAlias;
  455. if (DrawGuideLines)
  456. {
  457. if (guideClass != null && guideClass.GrainSizeGuideAreaMethodModel != null)
  458. guideClass.DrawAreaGuide(g, SelectedItem);
  459. else if (guideClass != null && guideClass.GrainSizeGuideStyleModel != null)
  460. guideClass.DrawGuideLines(g, SelectedItem);
  461. }
  462. //圆形删除/椭圆删除
  463. if ((this.pointKtype == 14 || this.pointKtype == 12) && (this.rectangle.Width > 0 || this.rectangle.Height > 0))
  464. {
  465. Pen pen = new Pen(this.phaseColor, 1);
  466. pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
  467. if (this.pointKtype == 14)
  468. g.DrawEllipse(pen, this.rectangle);
  469. else
  470. g.DrawEllipse(pen, new RectangleF(this.rectangle.X, this.rectangle.Y, Math.Min(this.rectangle.Width, this.rectangle.Height), Math.Min(this.rectangle.Width, this.rectangle.Height)));
  471. pen.Dispose();
  472. }
  473. //矩形删除
  474. if (this.pointKtype == 13 && (this.rectangle.Width > 0 || this.rectangle.Height > 0))
  475. {
  476. Pen pen = new Pen(this.phaseColor, 1);
  477. pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
  478. g.DrawRectangle(pen, new Rectangle((int)this.rectangle.X, (int)this.rectangle.Y, (int)this.rectangle.Width, (int)this.rectangle.Height));
  479. pen.Dispose();
  480. }
  481. // 折线删除
  482. if (this.pointKtype == 11 && pointArray.Count >= 2)
  483. {
  484. Pen pen = new Pen(this.phaseColor, 1);
  485. pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
  486. g.DrawPolygon(pen, pointArray.ToArray());
  487. pen.Dispose();
  488. }
  489. // 直线添加
  490. if (this.pointKtype == 2 && this.startPoint.X > -1 && this.startPoint.Y > -1 && this.endPoint.X > -1 && this.endPoint.Y > -1)
  491. {
  492. Pen pen = new Pen(this.phaseColor, 1);
  493. //pen.DashStyle = DashStyle.Dash;
  494. g.DrawLine(pen, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y);
  495. pen.Dispose();
  496. }
  497. // 折线添加
  498. if (this.pointKtype == 1 && pointArray.Count >= 2)
  499. {
  500. Pen pen = new Pen(this.phaseColor, 1);
  501. g.DrawLines(pen, pointArray.ToArray());
  502. pen.Dispose();
  503. }
  504. }
  505. private void InitializeLanguageText()
  506. {
  507. this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
  508. this.button9.Text = PdnResources.GetString("CommonAction.Undo");
  509. this.button2.Text = PdnResources.GetString("Menu.File.Close.Text");
  510. this.button1.Text = PdnResources.GetString("Form.OkButton.Text");
  511. this.groupBox2.Text = PdnResources.GetString("Menu.Addgrainboundaries.text");
  512. this.button4.Text = PdnResources.GetString("Menu.Lineadd.text");
  513. this.button3.Text = PdnResources.GetString("Menu.Polylineadd.text");
  514. this.groupBox3.Text = PdnResources.GetString("Menu.Deletegrainboundary.text");
  515. this.button8.Text = PdnResources.GetString("Menu.Ellipsedelete.text");
  516. this.button7.Text = PdnResources.GetString("Menu.BinaryAction.RectangleDelete.Text");
  517. this.button6.Text = PdnResources.GetString("Menu.rounddelete.text");
  518. this.button5.Text = PdnResources.GetString("Menu.BinaryAction.PolygonleDelete.Text");
  519. this.groupBox7.Text = PdnResources.GetString("Menu.Preview.text");
  520. this.Text = PdnResources.GetString("Menu.Grainboundaryedit.text");
  521. }
  522. private void InitializeComponent()
  523. {
  524. this.groupBox1 = new System.Windows.Forms.GroupBox();
  525. this.button9 = new System.Windows.Forms.Button();
  526. this.button2 = new System.Windows.Forms.Button();
  527. this.button1 = new System.Windows.Forms.Button();
  528. this.groupBox2 = new System.Windows.Forms.GroupBox();
  529. this.button4 = new System.Windows.Forms.Button();
  530. this.button3 = new System.Windows.Forms.Button();
  531. this.groupBox3 = new System.Windows.Forms.GroupBox();
  532. this.button8 = new System.Windows.Forms.Button();
  533. this.button7 = new System.Windows.Forms.Button();
  534. this.button6 = new System.Windows.Forms.Button();
  535. this.button5 = new System.Windows.Forms.Button();
  536. this.groupBox7 = new System.Windows.Forms.GroupBox();
  537. this.groupBox1.SuspendLayout();
  538. this.groupBox2.SuspendLayout();
  539. this.groupBox3.SuspendLayout();
  540. this.SuspendLayout();
  541. //
  542. // groupBox1
  543. //
  544. this.groupBox1.Controls.Add(this.button9);
  545. this.groupBox1.Controls.Add(this.button2);
  546. this.groupBox1.Controls.Add(this.button1);
  547. this.groupBox1.Location = new System.Drawing.Point(12, 12);
  548. this.groupBox1.Name = "groupBox1";
  549. this.groupBox1.Size = new System.Drawing.Size(808, 45);
  550. this.groupBox1.TabIndex = 0;
  551. this.groupBox1.TabStop = false;
  552. //
  553. // button9
  554. //
  555. this.button9.Location = new System.Drawing.Point(468, 13);
  556. this.button9.Name = "button9";
  557. this.button9.Size = new System.Drawing.Size(91, 26);
  558. this.button9.TabIndex = 2;
  559. this.button9.UseVisualStyleBackColor = true;
  560. this.button9.Visible = false;
  561. this.button9.Click += new System.EventHandler(this.button9_Click);
  562. //
  563. // button2
  564. //
  565. this.button2.Location = new System.Drawing.Point(694, 13);
  566. this.button2.Name = "button2";
  567. this.button2.Size = new System.Drawing.Size(91, 26);
  568. this.button2.TabIndex = 1;
  569. this.button2.UseVisualStyleBackColor = true;
  570. this.button2.Click += new System.EventHandler(this.button2_Click);
  571. //
  572. // button1
  573. //
  574. this.button1.Location = new System.Drawing.Point(582, 13);
  575. this.button1.Name = "button1";
  576. this.button1.Size = new System.Drawing.Size(91, 26);
  577. this.button1.TabIndex = 0;
  578. this.button1.UseVisualStyleBackColor = true;
  579. this.button1.Click += new System.EventHandler(this.button1_Click);
  580. //
  581. // groupBox2
  582. //
  583. this.groupBox2.Controls.Add(this.button4);
  584. this.groupBox2.Controls.Add(this.button3);
  585. this.groupBox2.Location = new System.Drawing.Point(12, 63);
  586. this.groupBox2.Name = "groupBox2";
  587. this.groupBox2.Size = new System.Drawing.Size(233, 106);
  588. this.groupBox2.TabIndex = 1;
  589. this.groupBox2.TabStop = false;
  590. //
  591. // button4
  592. //
  593. this.button4.Location = new System.Drawing.Point(135, 31);
  594. this.button4.Name = "button4";
  595. this.button4.Size = new System.Drawing.Size(73, 26);
  596. this.button4.TabIndex = 3;
  597. this.button4.UseVisualStyleBackColor = true;
  598. this.button4.Click += new System.EventHandler(this.button4_Click);
  599. //
  600. // button3
  601. //
  602. this.button3.Location = new System.Drawing.Point(28, 31);
  603. this.button3.Name = "button3";
  604. this.button3.Size = new System.Drawing.Size(73, 26);
  605. this.button3.TabIndex = 2;
  606. this.button3.UseVisualStyleBackColor = true;
  607. this.button3.Click += new System.EventHandler(this.button3_Click);
  608. //
  609. // groupBox3
  610. //
  611. this.groupBox3.Controls.Add(this.button8);
  612. this.groupBox3.Controls.Add(this.button7);
  613. this.groupBox3.Controls.Add(this.button6);
  614. this.groupBox3.Controls.Add(this.button5);
  615. this.groupBox3.Location = new System.Drawing.Point(12, 175);
  616. this.groupBox3.Name = "groupBox3";
  617. this.groupBox3.Size = new System.Drawing.Size(233, 106);
  618. this.groupBox3.TabIndex = 1;
  619. this.groupBox3.TabStop = false;
  620. //
  621. // button8
  622. //
  623. this.button8.Location = new System.Drawing.Point(135, 68);
  624. this.button8.Name = "button8";
  625. this.button8.Size = new System.Drawing.Size(73, 26);
  626. this.button8.TabIndex = 7;
  627. this.button8.UseVisualStyleBackColor = true;
  628. this.button8.Click += new System.EventHandler(this.button8_Click);
  629. //
  630. // button7
  631. //
  632. this.button7.Location = new System.Drawing.Point(28, 68);
  633. this.button7.Name = "button7";
  634. this.button7.Size = new System.Drawing.Size(73, 26);
  635. this.button7.TabIndex = 6;
  636. this.button7.UseVisualStyleBackColor = true;
  637. this.button7.Click += new System.EventHandler(this.button7_Click);
  638. //
  639. // button6
  640. //
  641. this.button6.Location = new System.Drawing.Point(135, 24);
  642. this.button6.Name = "button6";
  643. this.button6.Size = new System.Drawing.Size(73, 26);
  644. this.button6.TabIndex = 5;
  645. this.button6.UseVisualStyleBackColor = true;
  646. this.button6.Click += new System.EventHandler(this.button6_Click);
  647. //
  648. // button5
  649. //
  650. this.button5.Location = new System.Drawing.Point(28, 24);
  651. this.button5.Name = "button5";
  652. this.button5.Size = new System.Drawing.Size(73, 26);
  653. this.button5.TabIndex = 4;
  654. this.button5.UseVisualStyleBackColor = true;
  655. this.button5.Click += new System.EventHandler(this.button5_Click);
  656. //
  657. // groupBox7
  658. //
  659. this.groupBox7.Location = new System.Drawing.Point(251, 63);
  660. this.groupBox7.Name = "groupBox7";
  661. this.groupBox7.Size = new System.Drawing.Size(569, 502);
  662. this.groupBox7.TabIndex = 1;
  663. this.groupBox7.TabStop = false;
  664. //
  665. // GrainBoundaryEditingDialog
  666. //
  667. this.ClientSize = new System.Drawing.Size(832, 577);
  668. this.Controls.Add(this.groupBox2);
  669. this.Controls.Add(this.groupBox3);
  670. this.Controls.Add(this.groupBox7);
  671. this.Controls.Add(this.groupBox1);
  672. this.MaximizeBox = false;
  673. this.MinimizeBox = false;
  674. this.Name = "GrainBoundaryEditingDialog";
  675. this.groupBox1.ResumeLayout(false);
  676. this.groupBox2.ResumeLayout(false);
  677. this.groupBox3.ResumeLayout(false);
  678. this.ResumeLayout(false);
  679. }
  680. /// <summary>
  681. /// 折线添加
  682. /// </summary>
  683. /// <param name="sender"></param>
  684. /// <param name="e"></param>
  685. private void button3_Click(object sender, EventArgs e)
  686. {
  687. pointArray.Clear();
  688. startPoint = new Point(-1, -1);
  689. endPoint = new Point(-1, -1);
  690. pointKtype = 1;
  691. this.documentWorkspace.Refresh();
  692. }
  693. /// <summary>
  694. /// 直线添加
  695. /// </summary>
  696. /// <param name="sender"></param>
  697. /// <param name="e"></param>
  698. private void button4_Click(object sender, EventArgs e)
  699. {
  700. startPoint = new Point(-1, -1);
  701. endPoint = new Point(-1, -1);
  702. pointKtype = 2;
  703. this.documentWorkspace.Refresh();
  704. }
  705. private void InitCommonButtonEvent()
  706. {
  707. this.commonControlButtons.zoomInButton.Click += new EventHandler(zoomInButton_Click);
  708. this.commonControlButtons.zoomOutButton.Click += new EventHandler(zoomOutButton_Click);
  709. this.commonControlButtons.zoomToWindowButton.Click += new EventHandler(zoomToWindowButton_Click);
  710. this.commonControlButtons.actualSizeButton.Click += new EventHandler(actualSizeButton_Click);
  711. this.commonControlButtons.pointerButton.Click += new EventHandler(pointerButton_Click);
  712. this.commonControlButtons.mobileModeButton.Click += new EventHandler(mobileModeButton_Click);
  713. }
  714. private void zoomInButton_Click(object sender, EventArgs e)
  715. {
  716. this.documentWorkspace.ZoomIn();
  717. }
  718. private void zoomOutButton_Click(object sender, EventArgs e)
  719. {
  720. this.documentWorkspace.ZoomOut();
  721. }
  722. private void zoomToWindowButton_Click(object sender, EventArgs e)
  723. {
  724. this.documentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
  725. }
  726. private void actualSizeButton_Click(object sender, EventArgs e)
  727. {
  728. this.documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
  729. this.documentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
  730. }
  731. private void pointerButton_Click(object sender, EventArgs e)
  732. {
  733. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.Pointer;
  734. }
  735. private void mobileModeButton_Click(object sender, EventArgs e)
  736. {
  737. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode;
  738. }
  739. //确定按钮点击事件
  740. private void button1_Click(object sender, EventArgs e)
  741. {
  742. this.PhaseMat = this.documentWorkspace.PhaseModels[0].mat;
  743. this.DialogResult = DialogResult.OK;
  744. this.Close();
  745. }
  746. /// <summary>
  747. /// 用于get处理后的图像
  748. /// </summary>
  749. public Mat PhaseMat
  750. {
  751. get
  752. {
  753. return this.phaseMat;
  754. }
  755. set
  756. {
  757. this.phaseMat = value;
  758. }
  759. }
  760. /// <summary>
  761. /// 矩形删除
  762. /// </summary>
  763. /// <param name="sender"></param>
  764. /// <param name="e"></param>
  765. private void button7_Click(object sender, EventArgs e)
  766. {
  767. startPoint = new Point(-1, -1);
  768. endPoint = new Point(-1, -1);
  769. this.rectangle.X = -1;
  770. this.rectangle.Y = -1;
  771. this.rectangle.Width = 0;
  772. this.rectangle.Height = 0;
  773. this.pointKtype = 13;
  774. this.documentWorkspace.Refresh();
  775. }
  776. /// <summary>
  777. /// 椭圆删除
  778. /// </summary>
  779. /// <param name="sender"></param>
  780. /// <param name="e"></param>
  781. private void button8_Click(object sender, EventArgs e)
  782. {
  783. startPoint = new Point(-1, -1);
  784. endPoint = new Point(-1, -1);
  785. this.rectangle.X = -1;
  786. this.rectangle.Y = -1;
  787. this.rectangle.Width = 0;
  788. this.rectangle.Height = 0;
  789. this.pointKtype = 14;
  790. this.documentWorkspace.Refresh();
  791. }
  792. /// <summary>
  793. /// 圆形删除
  794. /// </summary>
  795. /// <param name="sender"></param>
  796. /// <param name="e"></param>
  797. private void button6_Click(object sender, EventArgs e)
  798. {
  799. startPoint = new Point(-1, -1);
  800. endPoint = new Point(-1, -1);
  801. this.rectangle.X = -1;
  802. this.rectangle.Y = -1;
  803. this.rectangle.Width = 0;
  804. this.rectangle.Height = 0;
  805. this.pointKtype = 12;
  806. this.documentWorkspace.Refresh();
  807. }
  808. /// <summary>
  809. /// 多边形删除
  810. /// </summary>
  811. /// <param name="sender"></param>
  812. /// <param name="e"></param>
  813. private void button5_Click(object sender, EventArgs e)
  814. {
  815. pointArray.Clear();
  816. startPoint = new Point(-1, -1);
  817. endPoint = new Point(-1, -1);
  818. this.rectangle.X = -1;
  819. this.rectangle.Y = -1;
  820. this.rectangle.Width = 0;
  821. this.rectangle.Height = 0;
  822. this.pointKtype = 11;
  823. this.documentWorkspace.Refresh();
  824. }
  825. private void button2_Click(object sender, EventArgs e)
  826. {
  827. this.Close();
  828. }
  829. /// <summary>
  830. /// 撤销按钮点击事件
  831. /// </summary>
  832. /// <param name="sender"></param>
  833. /// <param name="e"></param>
  834. private void button9_Click(object sender, EventArgs e)
  835. {
  836. }
  837. }
  838. }