MetalsBoundaryEditingDialog.cs 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260
  1. using OpenCvSharp;
  2. using PaintDotNet.Adjust;
  3. using PaintDotNet.Base.Functionodel;
  4. using PaintDotNet.CustomControl;
  5. using PaintDotNet;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.ComponentModel;
  9. using System.Data;
  10. using System.Drawing;
  11. using System.Drawing.Drawing2D;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows.Forms;
  16. using Point = System.Drawing.Point;
  17. using PaintDotNet.Annotation;
  18. namespace PaintDotNet.DedicatedAnalysis.NonferrousMetals.IntegrationClass
  19. {
  20. internal class MetalsBoundaryEditingDialog : Form
  21. {
  22. /// <summary>
  23. /// 公共按钮
  24. /// </summary>
  25. private CommonControlButtons commonControlButtons;
  26. /// <summary>
  27. /// 主控件
  28. /// </summary>
  29. private AppWorkspace appWorkspace;
  30. private DocumentWorkspaceWindow documentWorkspace;
  31. /// <summary>
  32. /// 外接矩形,或者是计算的矩形
  33. /// </summary>
  34. protected RectangleF rectangle = new RectangleF();
  35. ///// <summary>
  36. ///// 用于get处理后的图像
  37. ///// </summary>
  38. //private Mat phaseMat;
  39. ///// <summary>
  40. ///// 辅助线集成
  41. ///// </summary>
  42. //private GrainSizeGuideClass guideClass;
  43. //public object SelectedItem;
  44. Color phaseColor;
  45. Mat phaseMatCopy = new Mat();
  46. /// <summary>
  47. /// 当前处理的程序
  48. /// </summary>
  49. private Data.Action.Action911 action = new Data.Action.Action911();
  50. /// <summary>
  51. /// 操作类型
  52. /// 0,没有操作 1,折线添加 2,直线添加
  53. /// 11,多边形删除 12,圆形删除 13,矩形删除 14,椭圆删除
  54. /// </summary>
  55. private int pointKtype = 0;
  56. /// <summary>
  57. /// 起始点
  58. /// </summary>
  59. private Point startPoint = new Point(-1, -1);
  60. /// <summary>
  61. /// 是否绘制了起始点
  62. /// </summary>
  63. private bool drawedStartPoint = false;
  64. /// <summary>
  65. /// 结束点
  66. /// </summary>
  67. private Point endPoint = new Point(-1, -1);
  68. /// <summary>
  69. /// 折线点的集合
  70. /// </summary>
  71. public List<Point> pointArray = new List<Point>();
  72. /// <summary>
  73. /// 是否显示视场
  74. /// </summary>
  75. Boolean ShowDrawClassView = true;
  76. private GroupBox groupBox1;
  77. private GroupBox groupBox2;
  78. private Button button2;
  79. private Button button1;
  80. private Button button3;
  81. private Button button4;
  82. private Button button8;
  83. private Button button7;
  84. private Button button6;
  85. private Button button5;
  86. private TriangleTrackBar trackBar2;
  87. private TextBox textBox1;
  88. private Label label1;
  89. private TrackBar trackBar1;
  90. private Button button9;
  91. private GroupBox groupBox7;
  92. List<System.Drawing.Point[]> analyzePoints;
  93. //public GrainSizeGuideClass GuideClass
  94. //{
  95. // set
  96. // {
  97. // this.guideClass = value;
  98. // }
  99. //}
  100. public MetalsBoundaryEditingDialog(AppWorkspace appWorkspace, int focusedItemIndex, Color phaseColor, List<System.Drawing.Point[]> analyzePoints/*Mat analyzeMat*/, Boolean ShowDrawClassView = true)
  101. {
  102. this.ShowDrawClassView = ShowDrawClassView;
  103. this.appWorkspace = appWorkspace;
  104. InitializeComponent();
  105. InitializeLanguageText();
  106. //
  107. //初始化图像控件
  108. //
  109. this.documentWorkspace = new DocumentWorkspaceWindow(appWorkspace);
  110. this.documentWorkspace.Dock = DockStyle.Fill;
  111. this.documentWorkspace.HookMouseEvents();
  112. this.documentWorkspace.AuxiliaryLineEnabled = false;
  113. this.documentWorkspace.Visible = false;
  114. this.documentWorkspace.panel.MouseDown += OnMouseDown;
  115. this.documentWorkspace.panel.Paint += Panel_Paint;
  116. this.documentWorkspace.panel.MouseMove += onMouseMove;
  117. this.documentWorkspace.panel.MouseUp += onMouseUp;
  118. this.documentWorkspace.panel.Click += new EventHandler(this.pictureBox1_Click);
  119. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.InclusionNoEffect;//禁止视场移动
  120. this.groupBox7.Controls.Add(documentWorkspace);
  121. //
  122. //初始化操作按钮
  123. //
  124. this.commonControlButtons = new CommonControlButtons();
  125. this.commonControlButtons.Dock = DockStyle.Top;
  126. this.commonControlButtons.Height = 30;
  127. this.commonControlButtons.HideZoomToWindowAndActualSize();
  128. this.groupBox7.Controls.Add(commonControlButtons);
  129. this.phaseColor = phaseColor;
  130. {
  131. //
  132. //初始化相
  133. //
  134. PhaseModel model = new PhaseModel();
  135. model.choise = true;
  136. model.mat = null;
  137. model.color = phaseColor.ToArgb();// Color.Green/*panel2.BackColor*/.ToArgb();
  138. model.position = this.documentWorkspace.PhaseModels.Count + 1;
  139. model.name = PdnResources.GetString("Menu.Binarization.text");
  140. this.documentWorkspace.PhaseModels.Add(model);
  141. }
  142. ///// <summary>
  143. ///// 选中图片的mat
  144. Mat imageMat = this.appWorkspace.DocumentWorkspaces[focusedItemIndex].CompositionSurface.CreatedAliasedMat();
  145. this.analyzePoints = analyzePoints;
  146. Document document = Document.FromImageMat(imageMat.Clone());
  147. this.documentWorkspace.Document = document;
  148. this.documentWorkspace.Visible = true;
  149. if (ShowDrawClassView)
  150. {
  151. this.documentWorkspace.GraphicsList = this.appWorkspace.DocumentWorkspaces[focusedItemIndex].GraphicsList;
  152. }
  153. else
  154. {
  155. GraphicsList itemGraphicsList = this.appWorkspace.DocumentWorkspaces[focusedItemIndex].GraphicsList;
  156. GraphicsList graphicsList = new GraphicsList();
  157. for (int j = 0; j < itemGraphicsList.Count; j++)
  158. {
  159. if (itemGraphicsList[j].objectType != Annotation.Enum.DrawClass.View)
  160. graphicsList.Add(itemGraphicsList[j]);
  161. }
  162. this.documentWorkspace.GraphicsList = graphicsList;
  163. }
  164. InitCommonButtonEvent();
  165. }
  166. #region 矩形拖动
  167. /// <summary>
  168. /// 鼠标按下
  169. /// </summary>
  170. /// <param name="drawArea"></param>
  171. /// <param name="e"></param>
  172. private void OnMouseDown(object sender, MouseEventArgs e)
  173. {
  174. // 换算后的点
  175. PointF point1 = documentWorkspace.GetScalePoint(e.Location);
  176. if (point1.X <= this.documentWorkspace.CompositionSurface.Width
  177. && point1.X >= 0
  178. && point1.Y >= 0
  179. && point1.Y <= this.documentWorkspace.CompositionSurface.Height)
  180. {
  181. if (e.Button == MouseButtons.Left/* && e.Clicks == 1*/&& this.pointKtype >= 1)
  182. {
  183. if (!drawedStartPoint)
  184. {
  185. drawedStartPoint = true;
  186. startPoint = new Point((int)point1.X, (int)point1.Y);
  187. return;
  188. }
  189. // 折线添加
  190. if (this.pointKtype == 1)
  191. {
  192. }
  193. // 直线添加
  194. else if (this.pointKtype == 2)
  195. {
  196. }
  197. // 多边形删除
  198. else if (this.pointKtype == 11)
  199. {
  200. }
  201. }
  202. }
  203. else if (this.pointKtype == 14 || this.pointKtype == 13 || this.pointKtype == 12)
  204. {
  205. if (!drawedStartPoint)
  206. {
  207. drawedStartPoint = true;
  208. startPoint = new Point((int)point1.X, (int)point1.Y);
  209. return;
  210. }
  211. }
  212. else
  213. return;
  214. // 右键完成操作
  215. if (e.Button == MouseButtons.Right)
  216. {
  217. }
  218. }
  219. /// <summary>
  220. /// 移动
  221. /// </summary>
  222. /// <param name="sender"></param>
  223. /// <param name="e"></param>
  224. private void onMouseMove(object sender, MouseEventArgs e)
  225. {
  226. // 换算后的点
  227. PointF point1 = documentWorkspace.GetScalePoint(e.Location);
  228. if (e.Button == MouseButtons.Left)
  229. {
  230. // 椭圆删除/圆形删除
  231. if ((this.pointKtype == 14 || this.pointKtype == 12) && drawedStartPoint)
  232. {
  233. endPoint = new Point((int)point1.X, (int)point1.Y);
  234. if (this.startPoint.X < this.endPoint.X)
  235. {
  236. this.rectangle.X = this.startPoint.X;
  237. this.rectangle.Width = this.endPoint.X - this.startPoint.X;
  238. }
  239. else
  240. {
  241. this.rectangle.X = this.endPoint.X;
  242. this.rectangle.Width = this.startPoint.X - this.endPoint.X;
  243. }
  244. if (this.startPoint.Y < this.endPoint.Y)
  245. {
  246. this.rectangle.Y = this.startPoint.Y;
  247. this.rectangle.Height = this.endPoint.Y - this.startPoint.Y;
  248. }
  249. else
  250. {
  251. this.rectangle.Y = this.endPoint.Y;
  252. this.rectangle.Height = this.startPoint.Y - this.endPoint.Y;
  253. }
  254. this.documentWorkspace.Refresh();
  255. }
  256. // 矩形删除
  257. if (this.pointKtype == 13 && drawedStartPoint)
  258. {
  259. endPoint = new Point((int)point1.X, (int)point1.Y);
  260. if (this.startPoint.X < this.endPoint.X)
  261. {
  262. this.rectangle.X = this.startPoint.X;
  263. this.rectangle.Width = this.endPoint.X - this.startPoint.X;
  264. }
  265. else
  266. {
  267. this.rectangle.X = this.endPoint.X;
  268. this.rectangle.Width = this.startPoint.X - this.endPoint.X;
  269. }
  270. if (this.startPoint.Y < this.endPoint.Y)
  271. {
  272. this.rectangle.Y = this.startPoint.Y;
  273. this.rectangle.Height = this.endPoint.Y - this.startPoint.Y;
  274. }
  275. else
  276. {
  277. this.rectangle.Y = this.endPoint.Y;
  278. this.rectangle.Height = this.startPoint.Y - this.endPoint.Y;
  279. }
  280. this.documentWorkspace.Refresh();
  281. }
  282. // 直线添加
  283. if (this.pointKtype == 2 && drawedStartPoint)
  284. {
  285. endPoint = new Point((int)point1.X, (int)point1.Y);
  286. this.documentWorkspace.Refresh();
  287. }
  288. }
  289. }
  290. /// <summary>
  291. /// 鼠标抬起
  292. /// </summary>
  293. /// <param name="sender"></param>
  294. /// <param name="e"></param>
  295. private void onMouseUp(object sender, MouseEventArgs e)
  296. {
  297. // 换算后的点
  298. PointF point1 = documentWorkspace.GetScalePoint(e.Location);
  299. if (point1.X <= this.documentWorkspace.CompositionSurface.Width
  300. && point1.X >= 0
  301. && point1.Y >= 0
  302. && point1.Y <= this.documentWorkspace.CompositionSurface.Height) { }
  303. else
  304. {
  305. if (this.pointKtype == 14 || this.pointKtype == 13 || this.pointKtype == 12)
  306. {
  307. //if (point1.X >= this.documentWorkspace.CompositionSurface.Width)
  308. // point1.X = this.documentWorkspace.CompositionSurface.Width - 1;
  309. //if (point1.X < 0)
  310. // point1.X = 0;
  311. //if (point1.Y >= this.documentWorkspace.CompositionSurface.Height)
  312. // point1.Y = this.documentWorkspace.CompositionSurface.Height - 1;
  313. //if (point1.Y < 0)
  314. // point1.Y = 0;
  315. }
  316. else
  317. return;
  318. }
  319. if (e.Button == MouseButtons.Right)
  320. {
  321. // 折线删除
  322. if (this.pointKtype == 11 && pointArray.Count > 1)
  323. {
  324. pointArray.Add(new Point((int)point1.X, (int)point1.Y));
  325. endPoint = new Point((int)point1.X, (int)point1.Y);
  326. List<PointF> pointFArray = new List<PointF>();
  327. foreach (var item in pointArray)
  328. {
  329. pointFArray.Add(new PointF(item.X, item.Y));
  330. }
  331. for (int i = this.analyzePoints.Count - 1; i >= 0; i--)
  332. {
  333. RectangleF analyzeF = new RectangleF(this.rectangle.X, this.rectangle.Y, Math.Min(this.rectangle.Width, this.rectangle.Height), Math.Min(this.rectangle.Width, this.rectangle.Height));
  334. List<Point> srcPoints = this.analyzePoints[i].ToList();
  335. this.analyzePoints.RemoveAt(i);//先移除
  336. List<Point> tempPoints = new List<Point>();
  337. foreach (var item in srcPoints)
  338. {
  339. if (!Adjust.BaseImage.BaseTools.isPointInPolygon(new System.Drawing.Point(item.X, item.Y), pointFArray))//判断如果不在折线删除的框选内
  340. tempPoints.Add(item);
  341. else
  342. {
  343. if (tempPoints.Count > 1)
  344. this.analyzePoints.Add(tempPoints.ToArray());//后添加
  345. tempPoints = new List<Point>();//添加后清空中间对象
  346. }
  347. }
  348. if (tempPoints.Count > 1)
  349. this.analyzePoints.Add(tempPoints.ToArray());//后添加
  350. }
  351. //this.documentWorkspace.PhaseModels[0].mat = PreActionIntent.PolygonDelete(this.documentWorkspace.PhaseModels[0].mat, pointFArray);
  352. //this.documentWorkspace.PhaseModels[0].mat.CopyTo(phaseMatCopy);
  353. //////保存处理后的图片
  354. ////Bitmap originalBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.documentWorkspace.PhaseModels[0].mat);
  355. ////Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  356. ////Graphics graphics = Graphics.FromImage(newBit);
  357. ////Draw(graphics);
  358. ////this.documentWorkspace.PhaseModels[0].mat/* = phaseMat*/ = PaintDotNet.Camera.Tools.ToMat(newBit);
  359. this.rectangle.X = -1;
  360. this.rectangle.Y = -1;
  361. this.rectangle.Width = 0;
  362. this.rectangle.Height = 0;
  363. pointArray.Clear();
  364. startPoint = new Point(-1, -1);
  365. drawedStartPoint = false;
  366. endPoint = new Point(-1, -1);
  367. this.pointKtype = 0;
  368. this.documentWorkspace.Refresh();
  369. }
  370. // 折线添加
  371. if (this.pointKtype == 1 && pointArray.Count > 1)
  372. {
  373. pointArray.Add(new Point((int)point1.X, (int)point1.Y));
  374. endPoint = new Point((int)point1.X, (int)point1.Y);
  375. List<Point> alPoints = this.findAllPoints(pointArray);
  376. if (alPoints.Count > 1)
  377. analyzePoints.Add(alPoints.ToArray());
  378. ////保存处理后的图片
  379. //Bitmap originalBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.documentWorkspace.PhaseModels[0].mat);
  380. //Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  381. //Graphics graphics = Graphics.FromImage(newBit);
  382. //Draw(graphics);
  383. //this.documentWorkspace.PhaseModels[0].mat/* = phaseMat*/ = PaintDotNet.Camera.Tools.ToMat(newBit);
  384. //this.documentWorkspace.PhaseModels[0].mat.CopyTo(phaseMatCopy);
  385. pointArray.Clear();
  386. startPoint = new Point(-1, -1);
  387. drawedStartPoint = false;
  388. endPoint = new Point(-1, -1);
  389. this.pointKtype = 0;
  390. this.documentWorkspace.Refresh();
  391. }
  392. }
  393. if (e.Button == MouseButtons.Left)
  394. {
  395. // 圆形删除/椭圆删除
  396. if ((this.pointKtype == 14 || this.pointKtype == 12) && drawedStartPoint)
  397. {
  398. endPoint = new Point((int)point1.X, (int)point1.Y);
  399. if (this.startPoint.X < this.endPoint.X)
  400. {
  401. this.rectangle.X = this.startPoint.X;
  402. this.rectangle.Width = this.endPoint.X - this.startPoint.X;
  403. }
  404. else
  405. {
  406. this.rectangle.X = this.endPoint.X;
  407. this.rectangle.Width = this.startPoint.X - this.endPoint.X;
  408. }
  409. if (this.startPoint.Y < this.endPoint.Y)
  410. {
  411. this.rectangle.Y = this.startPoint.Y;
  412. this.rectangle.Height = this.endPoint.Y - this.startPoint.Y;
  413. }
  414. else
  415. {
  416. this.rectangle.Y = this.endPoint.Y;
  417. this.rectangle.Height = this.startPoint.Y - this.endPoint.Y;
  418. }
  419. if (this.pointKtype == 14)
  420. {
  421. for (int i = this.analyzePoints.Count - 1; i >= 0; i--)
  422. {
  423. List<Point> srcPoints = this.analyzePoints[i].ToList();
  424. this.analyzePoints.RemoveAt(i);//先移除
  425. List<Point> tempPoints = new List<Point>();
  426. foreach (var item in srcPoints)
  427. {
  428. if (!Adjust.BaseImage.BaseTools.isPointInOval(new System.Drawing.Point(item.X, item.Y), new System.Drawing.PointF(rectangle.X + rectangle.Width / 2, rectangle.Y + rectangle.Height / 2),
  429. rectangle.Width / 2, rectangle.Height / 2 ))//判断如果不在椭圆删除的框选内
  430. tempPoints.Add(item);
  431. else
  432. {
  433. if (tempPoints.Count > 1)
  434. this.analyzePoints.Add(tempPoints.ToArray());//后添加
  435. tempPoints = new List<Point>();//添加后清空中间对象
  436. }
  437. }
  438. if (tempPoints.Count > 1)
  439. this.analyzePoints.Add(tempPoints.ToArray());//后添加
  440. }
  441. }
  442. else
  443. for (int i = this.analyzePoints.Count - 1; i >= 0; i--)
  444. {
  445. RectangleF analyzeF = new RectangleF(this.rectangle.X, this.rectangle.Y, Math.Min(this.rectangle.Width, this.rectangle.Height), Math.Min(this.rectangle.Width, this.rectangle.Height));
  446. List<Point> srcPoints = this.analyzePoints[i].ToList();
  447. this.analyzePoints.RemoveAt(i);//先移除
  448. List<Point> tempPoints = new List<Point>();
  449. foreach (var item in srcPoints)
  450. {
  451. if (!Adjust.BaseImage.BaseTools.isPointInOval(new System.Drawing.Point(item.X, item.Y), new System.Drawing.PointF(analyzeF.X + analyzeF.Width / 2, analyzeF.Y + analyzeF.Height / 2),
  452. analyzeF.Width / 2, analyzeF.Height / 2))//判断如果不在椭圆删除的框选内
  453. tempPoints.Add(item);
  454. else
  455. {
  456. if (tempPoints.Count > 1)
  457. this.analyzePoints.Add(tempPoints.ToArray());//后添加
  458. tempPoints = new List<Point>();//添加后清空中间对象
  459. }
  460. }
  461. if (tempPoints.Count > 1)
  462. this.analyzePoints.Add(tempPoints.ToArray());//后添加
  463. }
  464. this.rectangle.X = -1;
  465. this.rectangle.Y = -1;
  466. this.rectangle.Width = 0;
  467. this.rectangle.Height = 0;
  468. startPoint = new Point(-1, -1);
  469. drawedStartPoint = false;
  470. endPoint = new Point(-1, -1);
  471. this.pointKtype = 0;
  472. this.documentWorkspace.Refresh();
  473. }
  474. // 矩形删除
  475. if (this.pointKtype == 13 && drawedStartPoint)
  476. {
  477. endPoint = new Point((int)point1.X, (int)point1.Y);
  478. if (this.startPoint.X < this.endPoint.X)
  479. {
  480. this.rectangle.X = this.startPoint.X;
  481. this.rectangle.Width = this.endPoint.X - this.startPoint.X;
  482. }
  483. else
  484. {
  485. this.rectangle.X = this.endPoint.X;
  486. this.rectangle.Width = this.startPoint.X - this.endPoint.X;
  487. }
  488. if (this.startPoint.Y < this.endPoint.Y)
  489. {
  490. this.rectangle.Y = this.startPoint.Y;
  491. this.rectangle.Height = this.endPoint.Y - this.startPoint.Y;
  492. }
  493. else
  494. {
  495. this.rectangle.Y = this.endPoint.Y;
  496. this.rectangle.Height = this.startPoint.Y - this.endPoint.Y;
  497. }
  498. for (int i = this.analyzePoints.Count - 1; i >= 0; i--)
  499. {
  500. List<Point> srcPoints = this.analyzePoints[i].ToList();
  501. this.analyzePoints.RemoveAt(i);//先移除
  502. List<Point> tempPoints = new List<Point>();
  503. foreach (var item in srcPoints)
  504. {
  505. if (!rectangle.Contains(item.X, item.Y))//判断如果不在矩形删除的框选内
  506. tempPoints.Add(item);
  507. else
  508. {
  509. if (tempPoints.Count > 1)
  510. this.analyzePoints.Add(tempPoints.ToArray());//后添加
  511. tempPoints = new List<Point>();//添加后清空中间对象
  512. }
  513. }
  514. if (tempPoints.Count > 1)
  515. this.analyzePoints.Add(tempPoints.ToArray());//后添加
  516. }
  517. //this.documentWorkspace.PhaseModels[0].mat = PreActionIntent.RectangleDelete(this.documentWorkspace.PhaseModels[0].mat, this.rectangle);
  518. //this.documentWorkspace.PhaseModels[0].mat.CopyTo(phaseMatCopy);
  519. ////保存处理后的图片
  520. //Bitmap originalBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.documentWorkspace.PhaseModels[0].mat);
  521. //Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  522. //Graphics graphics = Graphics.FromImage(newBit);
  523. //Draw(graphics);
  524. //this.documentWorkspace.PhaseModels[0].mat/* = phaseMat*/ = PaintDotNet.Camera.Tools.ToMat(newBit);
  525. this.rectangle.X = -1;
  526. this.rectangle.Y = -1;
  527. this.rectangle.Width = 0;
  528. this.rectangle.Height = 0;
  529. startPoint = new Point(-1, -1);
  530. drawedStartPoint = false;
  531. endPoint = new Point(-1, -1);
  532. this.pointKtype = 0;
  533. this.documentWorkspace.Refresh();
  534. }
  535. // 折线添加/折线删除
  536. if (this.pointKtype == 1 || this.pointKtype == 11)
  537. {
  538. pointArray.Add(new Point((int)point1.X, (int)point1.Y));
  539. if (!drawedStartPoint)
  540. {
  541. drawedStartPoint = true;
  542. startPoint = new Point((int)point1.X, (int)point1.Y);
  543. }
  544. this.documentWorkspace.Refresh();
  545. }
  546. // 直线添加
  547. if (this.pointKtype == 2 && drawedStartPoint)
  548. {
  549. endPoint = new Point((int)point1.X, (int)point1.Y);
  550. if (drawedStartPoint && this.endPoint.X > -1 && this.endPoint.Y > -1)
  551. {
  552. List<Point> alPoints = this.findAllPoints(new List<Point>() { startPoint, endPoint });
  553. if (alPoints.Count > 1)
  554. analyzePoints.Add(alPoints.ToArray());
  555. }
  556. ////保存处理后的图片
  557. //Bitmap originalBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.documentWorkspace.PhaseModels[0].mat);
  558. //Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  559. //Graphics graphics = Graphics.FromImage(newBit);
  560. //Draw(graphics);
  561. //this.documentWorkspace.PhaseModels[0].mat/* = phaseMat*/ = PaintDotNet.Camera.Tools.ToMat(newBit);
  562. //this.documentWorkspace.PhaseModels[0].mat.CopyTo(phaseMatCopy);
  563. startPoint = new Point(-1, -1);
  564. drawedStartPoint = false;
  565. endPoint = new Point(-1, -1);
  566. this.pointKtype = 0;
  567. this.documentWorkspace.Refresh();
  568. }
  569. }
  570. }
  571. /// <summary>
  572. /// 根据关键点集合获取折线图上所有的点
  573. /// </summary>
  574. /// <param name="srcPoints">画折线或直线的点集合</param>
  575. /// <returns>按顺序返回折线或直线上面所有的点</returns>
  576. private List<Point> findAllPoints(List<Point> srcPoints)
  577. {
  578. List<Point> dstPoints = new List<Point>();
  579. for (int i = 0; i < srcPoints.Count - 1; i++)
  580. {
  581. Point startP = srcPoints[i];
  582. Point endP = srcPoints[i + 1];
  583. int disX = Math.Abs(startP.X - endP.X);
  584. int disY = Math.Abs(startP.Y - endP.Y);
  585. dstPoints.Add(startP);
  586. if (disX > disY)
  587. {
  588. int step = (endP.X - startP.X) / disX;
  589. // 计算斜率
  590. double k = ((double)(startP.Y - endP.Y)) / (startP.X - endP.X);
  591. //循环x坐标
  592. for (int stepI = 1; stepI < disX - 1; stepI++)
  593. {
  594. // 根据斜率,计算y坐标
  595. double y = k * stepI * step + startP.Y;
  596. // 简单判断一下y是不是整数
  597. double d = y - (int)y;
  598. //if (0.5 > d && d > -0.5)
  599. {
  600. dstPoints.Add(new Point(stepI * step + startP.X, (int)y));
  601. }
  602. }
  603. }
  604. else if (disY > 1)
  605. {
  606. int step = (endP.Y - startP.Y) / disY;
  607. // 计算斜率
  608. double k = ((double)(startP.X - endP.X)) / (startP.Y - endP.Y);
  609. //循环y坐标
  610. for (int stepI = 1; stepI < disY - 1; stepI++)
  611. {
  612. // 根据斜率,计算x坐标
  613. double x = k * stepI * step + startP.X;
  614. // 简单判断一下x是不是整数
  615. double d = x - (int)x;
  616. //if (0.5 > d && d > -0.5)
  617. {
  618. dstPoints.Add(new Point((int)x, stepI * step + startP.Y));
  619. }
  620. }
  621. }
  622. }
  623. dstPoints.Add(srcPoints[srcPoints.Count - 1]);
  624. return dstPoints;
  625. }
  626. #endregion
  627. /// <summary>
  628. /// surfaceBox双击事件
  629. /// 目前是参考AxioVision
  630. /// 应该是把每次选的点都取最高和最低的BGR
  631. /// </summary>
  632. /// <param name="sender"></param>
  633. /// <param name="e"></param>
  634. private unsafe void pictureBox1_Click(object sender, EventArgs e)
  635. {
  636. }
  637. /// <summary>
  638. /// 画布绘制
  639. /// </summary>
  640. /// <param name="sender"></param>
  641. /// <param name="e"></param>
  642. private void Panel_Paint(object sender, PaintEventArgs e)
  643. {
  644. if (this.documentWorkspace.CompositionSurface != null)
  645. {
  646. //
  647. // 以下是计算绘制图片的位置和大小并绘制图片
  648. //
  649. System.Drawing.Rectangle rc = this.documentWorkspace.panel.ClientRectangle;
  650. int width = (int)(this.documentWorkspace.CompositionSurface.Width * this.documentWorkspace.ScaleFactor.Ratio);
  651. int height = (int)(this.documentWorkspace.CompositionSurface.Height * this.documentWorkspace.ScaleFactor.Ratio);
  652. int x = (rc.Width < width) ? this.documentWorkspace.panel.AutoScrollPosition.X : (rc.Width - width) / 2;
  653. int y = (rc.Height < height) ? this.documentWorkspace.panel.AutoScrollPosition.Y : (rc.Height - height) / 2;
  654. //
  655. // 以下是绘制网格、标注、测量、视场等开始
  656. //
  657. e.Graphics.TranslateTransform(x, y);
  658. e.Graphics.ScaleTransform((float)this.documentWorkspace.ScaleFactor.Ratio, (float)this.documentWorkspace.ScaleFactor.Ratio);
  659. //if (this.checkBox4_0.Checked)//显示网格
  660. Draw(e.Graphics);
  661. e.Graphics.ScaleTransform(1 / (float)this.documentWorkspace.ScaleFactor.Ratio, 1 / (float)this.documentWorkspace.ScaleFactor.Ratio);
  662. e.Graphics.TranslateTransform(-x, -y);
  663. }
  664. }
  665. /// <summary>
  666. /// 绘制
  667. /// </summary>
  668. private void Draw(Graphics g)
  669. {
  670. // 抗锯齿
  671. g.SmoothingMode = SmoothingMode.AntiAlias;
  672. //圆形删除/椭圆删除
  673. if ((this.pointKtype == 14 || this.pointKtype == 12) && (this.rectangle.Width > 0 || this.rectangle.Height > 0))
  674. {
  675. Pen pen = new Pen(this.phaseColor, 1);
  676. pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
  677. if (this.pointKtype == 14)
  678. g.DrawEllipse(pen, this.rectangle);
  679. else
  680. 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)));
  681. pen.Dispose();
  682. }
  683. //矩形删除
  684. if (this.pointKtype == 13 && (this.rectangle.Width > 0 || this.rectangle.Height > 0))
  685. {
  686. Pen pen = new Pen(this.phaseColor, 1);
  687. pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
  688. g.DrawRectangle(pen, new Rectangle((int)this.rectangle.X, (int)this.rectangle.Y, (int)this.rectangle.Width, (int)this.rectangle.Height));
  689. pen.Dispose();
  690. }
  691. // 折线删除
  692. if (this.pointKtype == 11 && pointArray.Count >= 2)
  693. {
  694. Pen pen = new Pen(this.phaseColor, 1);
  695. pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
  696. g.DrawPolygon(pen, pointArray.ToArray());
  697. pen.Dispose();
  698. }
  699. //Mat analyzeMat = this.documentWorkspace.PhaseModels[0].mat;
  700. ////int matWidth = analyzeMat.Width;
  701. ////int matHeight = analyzeMat.Height;
  702. ////////System.Drawing.Point tempPoint;//<tempLine
  703. if (analyzePoints != null && analyzePoints.Count > 0)
  704. {
  705. Pen pen = new Pen(this.phaseColor, this.trackBar1.Value);
  706. bool findTempLineSuccess;
  707. //Mat erzhi = new Mat(new OpenCvSharp.Size(this.bitmap.Size.Width, this.bitmap.Size.Height), MatType.CV_8UC4, new Scalar(0, 0, 0, 0));
  708. //int Rows = this.bitmap.Height;// analyzeMat.Rows;
  709. //int Cols = this.bitmap.Width;// analyzeMat.Cols;
  710. //int[] point = new int[2];
  711. foreach (System.Drawing.Point[] tempLine1 in analyzePoints)
  712. {
  713. //for (int y = 0; y < tempLine1.Length - 1; y++)
  714. //{
  715. // System.Drawing.Point point11 = new System.Drawing.Point(tempLine1[y].X, tempLine1[y].Y);
  716. // System.Drawing.Point point12 = new System.Drawing.Point(tempLine1[y + 1].X, tempLine1[y + 1].Y);
  717. // g.DrawLine(pen, point11, point12);
  718. //}
  719. g.DrawLines(pen, tempLine1);
  720. }
  721. }
  722. // 直线添加
  723. if (this.pointKtype == 2 && drawedStartPoint && this.endPoint.X > -1 && this.endPoint.Y > -1)
  724. {
  725. Pen pen = new Pen(this.phaseColor, this.trackBar1.Value);
  726. //pen.DashStyle = DashStyle.Dash;
  727. g.DrawLine(pen, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y);
  728. pen.Dispose();
  729. }
  730. // 折线添加
  731. if (this.pointKtype == 1 && pointArray.Count >= 2)
  732. {
  733. Pen pen = new Pen(this.phaseColor, this.trackBar1.Value);
  734. g.DrawLines(pen, pointArray.ToArray());
  735. pen.Dispose();
  736. }
  737. //// 以下为绘制样式
  738. //Pen linePen = new Pen(Color.FromArgb(this.lineColor), this.lineWidth);
  739. //Pen pointPen1 = new Pen(Color.Yellow, this.pointWidth1);
  740. //Pen pointPen2 = new Pen(Color.FromArgb(this.pointColor2), this.pointWidth2);
  741. //Pen pointPen3 = new Pen(Color.FromArgb(this.pointColor3), this.pointWidth3);
  742. //SolidBrush brush1 = new SolidBrush(Color.FromArgb(this.pointColor1));
  743. //SolidBrush brush2 = new SolidBrush(Color.FromArgb(this.pointColor2));
  744. //SolidBrush brush3 = new SolidBrush(Color.FromArgb(this.pointColor3));
  745. //// 圆形
  746. //if (grainSizeGuideAreaMethodModel.circularGuideStyles != null)
  747. //{
  748. // foreach (var circularGuideStyle in grainSizeGuideAreaMethodModel.circularGuideStyles)
  749. // {
  750. // if (this.comboBox1.SelectedItem.Equals(circularGuideStyle.tag))
  751. // {
  752. // graphics.DrawEllipse(linePen, this.rectangleFLine.X, this.rectangleFLine.Y, this.rectangleFLine.Width, this.rectangleFLine.Height);
  753. // }
  754. // }
  755. //}
  756. //// 矩形
  757. //if (grainSizeGuideAreaMethodModel.rectangleGuideStyles != null)
  758. //{
  759. // foreach (var rectangleGuideStyle in grainSizeGuideAreaMethodModel.rectangleGuideStyles)
  760. // {
  761. // if (this.comboBox1.SelectedItem.Equals(rectangleGuideStyle.tag))
  762. // {
  763. // graphics.DrawRectangle(linePen, this.rectangleFLine.X, this.rectangleFLine.Y, this.rectangleFLine.Width, this.rectangleFLine.Height);
  764. // }
  765. // }
  766. //}
  767. //if (this.checkBox5_0.Checked && massLabelPoints.Count > 0)
  768. //{
  769. // int index = 0;
  770. // Font myFont = new Font("宋体", 12/*, FontStyle.Bold*/);
  771. // Brush bush = new SolidBrush(this.panel1.BackColor/*Color.Red*/);//填充的颜色
  772. // foreach (var item in massLabelPoints)
  773. // {
  774. // graphics.DrawString("" + (++index), myFont, bush, (float)item.X - 5, (float)item.Y - 5);
  775. // }
  776. //}
  777. }
  778. private void InitializeLanguageText()
  779. {
  780. this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
  781. this.button9.Text = PdnResources.GetString("CommonAction.Undo");
  782. this.button2.Text = PdnResources.GetString("Menu.File.Close.Text");
  783. this.button1.Text = PdnResources.GetString("Form.OkButton.Text");
  784. this.groupBox2.Text = PdnResources.GetString("Menu.BinaryAction.Text");
  785. this.button8.Text = PdnResources.GetString("Menu.Ellipsedelete.text");
  786. this.button7.Text = PdnResources.GetString("Menu.BinaryAction.RectangleDelete.Text");
  787. this.button6.Text = PdnResources.GetString("Menu.rounddelete.text");
  788. this.button5.Text = PdnResources.GetString("Menu.BinaryAction.PolygonleDelete.Text");
  789. this.label1.Text = PdnResources.GetString("Menu.Linewidth.text") + ":";
  790. this.button4.Text = PdnResources.GetString("Menu.Lineadd.text");
  791. this.button3.Text = PdnResources.GetString("Menu.Polylineadd.text");
  792. this.groupBox7.Text = PdnResources.GetString("Menu.Preview.text");
  793. this.Text = PdnResources.GetString("Menu.filter.text");
  794. }
  795. private void InitializeComponent()
  796. {
  797. this.groupBox1 = new System.Windows.Forms.GroupBox();
  798. this.button9 = new System.Windows.Forms.Button();
  799. this.button2 = new System.Windows.Forms.Button();
  800. this.button1 = new System.Windows.Forms.Button();
  801. this.groupBox2 = new System.Windows.Forms.GroupBox();
  802. this.button8 = new System.Windows.Forms.Button();
  803. this.trackBar1 = new System.Windows.Forms.TrackBar();
  804. this.button7 = new System.Windows.Forms.Button();
  805. this.trackBar2 = new PaintDotNet.CustomControl.TriangleTrackBar();
  806. this.button6 = new System.Windows.Forms.Button();
  807. this.textBox1 = new System.Windows.Forms.TextBox();
  808. this.button5 = new System.Windows.Forms.Button();
  809. this.label1 = new System.Windows.Forms.Label();
  810. this.button4 = new System.Windows.Forms.Button();
  811. this.button3 = new System.Windows.Forms.Button();
  812. this.groupBox7 = new System.Windows.Forms.GroupBox();
  813. this.groupBox1.SuspendLayout();
  814. this.groupBox2.SuspendLayout();
  815. ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit();
  816. this.SuspendLayout();
  817. //
  818. // groupBox1
  819. //
  820. this.groupBox1.Controls.Add(this.button9);
  821. this.groupBox1.Controls.Add(this.button2);
  822. this.groupBox1.Controls.Add(this.button1);
  823. this.groupBox1.Location = new System.Drawing.Point(12, 12);
  824. this.groupBox1.Name = "groupBox1";
  825. this.groupBox1.Size = new System.Drawing.Size(808, 45);
  826. this.groupBox1.TabIndex = 0;
  827. this.groupBox1.TabStop = false;
  828. //
  829. // button9
  830. //
  831. this.button9.Location = new System.Drawing.Point(468, 13);
  832. this.button9.Name = "button9";
  833. this.button9.Size = new System.Drawing.Size(91, 26);
  834. this.button9.TabIndex = 3;
  835. this.button9.UseVisualStyleBackColor = true;
  836. this.button9.Visible = false;
  837. //
  838. // button2
  839. //
  840. this.button2.Location = new System.Drawing.Point(694, 13);
  841. this.button2.Name = "button2";
  842. this.button2.Size = new System.Drawing.Size(91, 26);
  843. this.button2.TabIndex = 1;
  844. this.button2.UseVisualStyleBackColor = true;
  845. this.button2.Click += new System.EventHandler(this.button2_Click);
  846. //
  847. // button1
  848. //
  849. this.button1.Location = new System.Drawing.Point(582, 13);
  850. this.button1.Name = "button1";
  851. this.button1.Size = new System.Drawing.Size(91, 26);
  852. this.button1.TabIndex = 0;
  853. this.button1.UseVisualStyleBackColor = true;
  854. this.button1.Click += new System.EventHandler(this.button1_Click);
  855. //
  856. // groupBox2
  857. //
  858. this.groupBox2.Controls.Add(this.button8);
  859. this.groupBox2.Controls.Add(this.trackBar1);
  860. this.groupBox2.Controls.Add(this.button7);
  861. this.groupBox2.Controls.Add(this.trackBar2);
  862. this.groupBox2.Controls.Add(this.button6);
  863. this.groupBox2.Controls.Add(this.textBox1);
  864. this.groupBox2.Controls.Add(this.button5);
  865. this.groupBox2.Controls.Add(this.label1);
  866. this.groupBox2.Controls.Add(this.button4);
  867. this.groupBox2.Controls.Add(this.button3);
  868. this.groupBox2.Location = new System.Drawing.Point(12, 63);
  869. this.groupBox2.Name = "groupBox2";
  870. this.groupBox2.Size = new System.Drawing.Size(233, 199);
  871. this.groupBox2.TabIndex = 1;
  872. this.groupBox2.TabStop = false;
  873. //
  874. // button8
  875. //
  876. this.button8.Location = new System.Drawing.Point(134, 151);
  877. this.button8.Name = "button8";
  878. this.button8.Size = new System.Drawing.Size(73, 26);
  879. this.button8.TabIndex = 7;
  880. this.button8.UseVisualStyleBackColor = true;
  881. this.button8.Click += new System.EventHandler(this.button8_Click);
  882. //
  883. // trackBar1
  884. //
  885. this.trackBar1.AutoSize = false;
  886. this.trackBar1.Location = new System.Drawing.Point(107, 69);
  887. this.trackBar1.Maximum = 50;
  888. this.trackBar1.Minimum = 1;
  889. this.trackBar1.Name = "trackBar1";
  890. this.trackBar1.Size = new System.Drawing.Size(104, 31);
  891. this.trackBar1.TabIndex = 21;
  892. this.trackBar1.TickStyle = System.Windows.Forms.TickStyle.None;
  893. this.trackBar1.Value = 1;
  894. this.trackBar1.Scroll += new System.EventHandler(this.trackBar1_Scroll);
  895. //
  896. // button7
  897. //
  898. this.button7.Location = new System.Drawing.Point(27, 151);
  899. this.button7.Name = "button7";
  900. this.button7.Size = new System.Drawing.Size(73, 26);
  901. this.button7.TabIndex = 6;
  902. this.button7.UseVisualStyleBackColor = true;
  903. this.button7.Click += new System.EventHandler(this.button7_Click);
  904. //
  905. // trackBar2
  906. //
  907. this.trackBar2.Location = new System.Drawing.Point(108, 69);
  908. this.trackBar2.Maximum = 50;
  909. this.trackBar2.Minimum = 1;
  910. this.trackBar2.Name = "trackBar2";
  911. this.trackBar2.Size = new System.Drawing.Size(102, 24);
  912. this.trackBar2.TabIndex = 20;
  913. this.trackBar2.Value = 1;
  914. this.trackBar2.Visible = false;
  915. //
  916. // button6
  917. //
  918. this.button6.Location = new System.Drawing.Point(134, 107);
  919. this.button6.Name = "button6";
  920. this.button6.Size = new System.Drawing.Size(73, 26);
  921. this.button6.TabIndex = 5;
  922. this.button6.UseVisualStyleBackColor = true;
  923. this.button6.Click += new System.EventHandler(this.button6_Click);
  924. //
  925. // textBox1
  926. //
  927. this.textBox1.Location = new System.Drawing.Point(68, 69);
  928. this.textBox1.Name = "textBox1";
  929. this.textBox1.Size = new System.Drawing.Size(32, 21);
  930. this.textBox1.TabIndex = 19;
  931. this.textBox1.Text = "1";
  932. this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
  933. //
  934. // button5
  935. //
  936. this.button5.Location = new System.Drawing.Point(27, 107);
  937. this.button5.Name = "button5";
  938. this.button5.Size = new System.Drawing.Size(73, 26);
  939. this.button5.TabIndex = 4;
  940. this.button5.UseVisualStyleBackColor = true;
  941. this.button5.Click += new System.EventHandler(this.button5_Click);
  942. //
  943. // label1
  944. //
  945. this.label1.AutoSize = true;
  946. this.label1.Location = new System.Drawing.Point(28, 73);
  947. this.label1.Name = "label1";
  948. this.label1.Size = new System.Drawing.Size(0, 12);
  949. this.label1.TabIndex = 18;
  950. //
  951. // button4
  952. //
  953. this.button4.Location = new System.Drawing.Point(135, 31);
  954. this.button4.Name = "button4";
  955. this.button4.Size = new System.Drawing.Size(73, 26);
  956. this.button4.TabIndex = 3;
  957. this.button4.UseVisualStyleBackColor = true;
  958. this.button4.Click += new System.EventHandler(this.button4_Click);
  959. //
  960. // button3
  961. //
  962. this.button3.Location = new System.Drawing.Point(28, 31);
  963. this.button3.Name = "button3";
  964. this.button3.Size = new System.Drawing.Size(73, 26);
  965. this.button3.TabIndex = 2;
  966. this.button3.UseVisualStyleBackColor = true;
  967. this.button3.Click += new System.EventHandler(this.button3_Click);
  968. //
  969. // groupBox7
  970. //
  971. this.groupBox7.Location = new System.Drawing.Point(251, 63);
  972. this.groupBox7.Name = "groupBox7";
  973. this.groupBox7.Size = new System.Drawing.Size(569, 502);
  974. this.groupBox7.TabIndex = 1;
  975. this.groupBox7.TabStop = false;
  976. //
  977. // MetalsBoundaryEditingDialog
  978. //
  979. this.ClientSize = new System.Drawing.Size(832, 577);
  980. this.Controls.Add(this.groupBox2);
  981. this.Controls.Add(this.groupBox7);
  982. this.Controls.Add(this.groupBox1);
  983. this.MaximizeBox = false;
  984. this.MinimizeBox = false;
  985. this.Name = "MetalsBoundaryEditingDialog";
  986. this.groupBox1.ResumeLayout(false);
  987. this.groupBox2.ResumeLayout(false);
  988. this.groupBox2.PerformLayout();
  989. ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit();
  990. this.ResumeLayout(false);
  991. }
  992. /// <summary>
  993. /// 折线添加
  994. /// </summary>
  995. /// <param name="sender"></param>
  996. /// <param name="e"></param>
  997. private void button3_Click(object sender, EventArgs e)
  998. {
  999. pointArray.Clear();
  1000. startPoint = new Point(-1, -1);
  1001. drawedStartPoint = false;
  1002. endPoint = new Point(-1, -1);
  1003. pointKtype = 1;
  1004. this.documentWorkspace.Refresh();
  1005. }
  1006. /// <summary>
  1007. /// 直线添加
  1008. /// </summary>
  1009. /// <param name="sender"></param>
  1010. /// <param name="e"></param>
  1011. private void button4_Click(object sender, EventArgs e)
  1012. {
  1013. startPoint = new Point(-1, -1);
  1014. drawedStartPoint = false;
  1015. endPoint = new Point(-1, -1);
  1016. pointKtype = 2;
  1017. this.documentWorkspace.Refresh();
  1018. }
  1019. private void InitCommonButtonEvent()
  1020. {
  1021. this.commonControlButtons.zoomInButton.Click += new EventHandler(zoomInButton_Click);
  1022. this.commonControlButtons.zoomOutButton.Click += new EventHandler(zoomOutButton_Click);
  1023. this.commonControlButtons.zoomToWindowButton.Click += new EventHandler(zoomToWindowButton_Click);
  1024. this.commonControlButtons.actualSizeButton.Click += new EventHandler(actualSizeButton_Click);
  1025. this.commonControlButtons.pointerButton.Click += new EventHandler(pointerButton_Click);
  1026. this.commonControlButtons.mobileModeButton.Click += new EventHandler(mobileModeButton_Click);
  1027. }
  1028. private void zoomInButton_Click(object sender, EventArgs e)
  1029. {
  1030. this.documentWorkspace.ZoomIn();
  1031. }
  1032. private void zoomOutButton_Click(object sender, EventArgs e)
  1033. {
  1034. this.documentWorkspace.ZoomOut();
  1035. }
  1036. private void zoomToWindowButton_Click(object sender, EventArgs e)
  1037. {
  1038. this.documentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
  1039. }
  1040. private void actualSizeButton_Click(object sender, EventArgs e)
  1041. {
  1042. this.documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
  1043. this.documentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
  1044. }
  1045. private void pointerButton_Click(object sender, EventArgs e)
  1046. {
  1047. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.InclusionNoEffect;
  1048. this.documentWorkspace.Cursor = Cursors.Default;
  1049. }
  1050. private void mobileModeButton_Click(object sender, EventArgs e)
  1051. {
  1052. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode;
  1053. }
  1054. //确定按钮点击事件
  1055. private void button1_Click(object sender, EventArgs e)
  1056. {
  1057. this.phaseMatCopy = this.documentWorkspace.PhaseModels[0].mat;
  1058. this.DialogResult = DialogResult.OK;
  1059. this.Close();
  1060. }
  1061. /// <summary>
  1062. /// 用于get处理后的图像
  1063. /// </summary>
  1064. public List<Point[]> AnalyzePoints
  1065. {
  1066. get
  1067. {
  1068. return this.analyzePoints;
  1069. }
  1070. //set
  1071. //{
  1072. // this.analyzePoints = value;
  1073. //}
  1074. }
  1075. /// <summary>
  1076. /// 矩形删除
  1077. /// </summary>
  1078. /// <param name="sender"></param>
  1079. /// <param name="e"></param>
  1080. private void button7_Click(object sender, EventArgs e)
  1081. {
  1082. startPoint = new Point(-1, -1);
  1083. drawedStartPoint = false;
  1084. endPoint = new Point(-1, -1);
  1085. this.rectangle.X = -1;
  1086. this.rectangle.Y = -1;
  1087. this.rectangle.Width = 0;
  1088. this.rectangle.Height = 0;
  1089. this.pointKtype = 13;
  1090. this.documentWorkspace.Refresh();
  1091. }
  1092. /// <summary>
  1093. /// 椭圆删除
  1094. /// </summary>
  1095. /// <param name="sender"></param>
  1096. /// <param name="e"></param>
  1097. private void button8_Click(object sender, EventArgs e)
  1098. {
  1099. startPoint = new Point(-1, -1);
  1100. drawedStartPoint = false;
  1101. endPoint = new Point(-1, -1);
  1102. this.rectangle.X = -1;
  1103. this.rectangle.Y = -1;
  1104. this.rectangle.Width = 0;
  1105. this.rectangle.Height = 0;
  1106. this.pointKtype = 14;
  1107. this.documentWorkspace.Refresh();
  1108. }
  1109. /// <summary>
  1110. /// 圆形删除
  1111. /// </summary>
  1112. /// <param name="sender"></param>
  1113. /// <param name="e"></param>
  1114. private void button6_Click(object sender, EventArgs e)
  1115. {
  1116. startPoint = new Point(-1, -1);
  1117. drawedStartPoint = false;
  1118. endPoint = new Point(-1, -1);
  1119. this.rectangle.X = -1;
  1120. this.rectangle.Y = -1;
  1121. this.rectangle.Width = 0;
  1122. this.rectangle.Height = 0;
  1123. this.pointKtype = 12;
  1124. this.documentWorkspace.Refresh();
  1125. }
  1126. /// <summary>
  1127. /// 多边形删除
  1128. /// </summary>
  1129. /// <param name="sender"></param>
  1130. /// <param name="e"></param>
  1131. private void button5_Click(object sender, EventArgs e)
  1132. {
  1133. pointArray.Clear();
  1134. startPoint = new Point(-1, -1);
  1135. drawedStartPoint = false;
  1136. endPoint = new Point(-1, -1);
  1137. this.rectangle.X = -1;
  1138. this.rectangle.Y = -1;
  1139. this.rectangle.Width = 0;
  1140. this.rectangle.Height = 0;
  1141. this.pointKtype = 11;
  1142. this.documentWorkspace.Refresh();
  1143. }
  1144. private void button2_Click(object sender, EventArgs e)
  1145. {
  1146. this.Close();
  1147. }
  1148. /// <summary>
  1149. /// 线宽改变
  1150. /// </summary>
  1151. /// <param name="sender"></param>
  1152. /// <param name="e"></param>
  1153. private void textBox1_TextChanged(object sender, EventArgs e)
  1154. {
  1155. int valueT;
  1156. if (!int.TryParse(textBox1.Text, out valueT))
  1157. return;
  1158. if (this.trackBar1.Minimum > valueT)
  1159. valueT = this.trackBar1.Minimum;
  1160. if (this.trackBar1.Maximum < valueT)
  1161. valueT = this.trackBar1.Maximum;
  1162. this.trackBar1.Value = valueT;
  1163. //this.textBox1.Text = valueT + "";
  1164. this.documentWorkspace.Refresh();
  1165. }
  1166. private void trackBar1_Scroll(object sender, EventArgs e)
  1167. {
  1168. this.textBox1.Text = this.trackBar1.Value + "";
  1169. this.documentWorkspace.Refresh();
  1170. }
  1171. }
  1172. }