MetalsBoundaryEditingDialog.cs 56 KB

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