MethodKInclusionEditSec.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. using OpenCvSharp;
  2. using PaintDotNet;
  3. using PaintDotNet.Annotation.DedicatedAnalysis;
  4. using PaintDotNet.Annotation.Enum;
  5. using PaintDotNet.Base.DedicatedAnalysis.Inclusions.Model;
  6. using PaintDotNet.CustomControl;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.ComponentModel;
  10. using System.Data;
  11. using System.Drawing;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows.Annotations;
  16. using System.Windows.Forms;
  17. namespace Metis.DedicatedAnalysis.Inclusions.New_DIN50602_1985
  18. {
  19. internal partial class MethodKInclusionEditSec : Form
  20. {
  21. private GroupBox groupBox1;
  22. private GroupBox groupBox2;
  23. private GroupBox groupBox3;
  24. private GroupBox groupBox4;
  25. private Button button2;
  26. private Button button1;
  27. private Label label8;
  28. private Label label7;
  29. private Label label6;
  30. private Label label5;
  31. private Label label4;
  32. private Label label3;
  33. private Label label2;
  34. private Label label1;
  35. private Button button4;
  36. private Button button3;
  37. private System.ComponentModel.IContainer components = null;
  38. private InclusionEditModel inclusionEditModel;
  39. private InclusionEditModel oldInclusionEditModel;
  40. private CommonControlButtons commonControlButtons;
  41. private AppWorkspace appWorkspace;
  42. private Bitmap bitmap;
  43. private MethodKInclusionEditDialog methodKInclusionEdit;
  44. private System.Drawing.Point? selectedTypesOfInclusionsPoint = null;
  45. private List<Particle> selectedInclusion = new List<Particle>();
  46. private Mat thisOriginalImage;
  47. /// <summary>
  48. /// 图像面板
  49. /// </summary>
  50. private DocumentWorkspaceWindow documentWorkspace;
  51. public MethodKInclusionEditSec(InclusionEditModel inclusionEditModel, AppWorkspace appWorkspace, MethodKInclusionEditDialog methodKInclusionEdit,Mat OriginalImage)
  52. {
  53. this.inclusionEditModel = inclusionEditModel;
  54. this.appWorkspace = appWorkspace;
  55. this.methodKInclusionEdit = methodKInclusionEdit;
  56. this.oldInclusionEditModel = inclusionEditModel;
  57. InitializeComponent();
  58. #region [初始化夹杂物属性属性]
  59. this.label2.Text = this.inclusionEditModel.data.physicalLength.ToString();
  60. this.label4.Text = this.inclusionEditModel.data.physicalWidth.ToString();
  61. this.label6.Text = this.inclusionEditModel.data.areaK.ToString();
  62. this.label8.Text = this.inclusionEditModel.data.type.type.ToString();
  63. #endregion
  64. #region [图像面板相关]
  65. //
  66. //初始化图像控件
  67. //
  68. this.documentWorkspace = new DocumentWorkspaceWindow(this.appWorkspace);
  69. this.documentWorkspace.Cursor = Cursors.Default;
  70. this.documentWorkspace.Dock = DockStyle.Fill;
  71. this.documentWorkspace.HookMouseEvents();
  72. this.documentWorkspace.Visible = true;
  73. this.documentWorkspace.panel.MouseDown += new MouseEventHandler(this.OnMouseDown);
  74. this.documentWorkspace.panel.MouseMove += new MouseEventHandler(this.OnMouseMove);
  75. this.documentWorkspace.panel.MouseUp += new MouseEventHandler(this.documentWorkspace_panel_MouseUp);
  76. this.documentWorkspace.panel.Paint += new PaintEventHandler(DrawPaintEvent);
  77. //PdnBaseForm.RegisterFormHotKey(Keys.Delete, OnDeleteHotKeyPressed);
  78. this.groupBox4.Controls.Add(this.documentWorkspace);
  79. this.commonControlButtons = new CommonControlButtons();
  80. this.commonControlButtons.Dock = DockStyle.Top;
  81. this.commonControlButtons.Height = 30;
  82. this.commonControlButtons.HideZoomToWindowAndActualSize();
  83. this.groupBox4.Controls.Add(commonControlButtons);
  84. InitCommonButtonEvent();
  85. Mat mat = new Mat(OriginalImage, new Rect(this.inclusionEditModel.data.rectProfile.X, this.inclusionEditModel.data.rectProfile.Y, this.inclusionEditModel.data.rectProfile.Width, this.inclusionEditModel.data.rectProfile.Height));
  86. this.bitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat);
  87. Document document = Document.FromImage(this.bitmap);
  88. this.documentWorkspace.Document = document;
  89. this.documentWorkspace.Refresh();
  90. int x = this.oldInclusionEditModel.data.rectProfile.X;
  91. int y = this.oldInclusionEditModel.data.rectProfile.Y;
  92. for (int i = 0; i < this.inclusionEditModel.data.particles.Count; i++)
  93. {
  94. this.inclusionEditModel.data.particles[i].rectProfile = new System.Drawing.Rectangle(this.inclusionEditModel.data.particles[i].rectProfile.X - x, this.inclusionEditModel.data.particles[i].rectProfile.Y - y, this.oldInclusionEditModel.data.particles[i].rectProfile.Width, this.inclusionEditModel.data.particles[i].rectProfile.Height);
  95. for (int j = 0; j < this.inclusionEditModel.data.particles[i].points2.Length; j++)
  96. {
  97. this.inclusionEditModel.data.particles[i].points2[j].X -= x;
  98. this.inclusionEditModel.data.particles[i].points2[j].Y -= y;
  99. }
  100. }
  101. ToolInclusionSelect.CleanAndDrawInclusionAll(this.documentWorkspace, new List<Inclusion>() { this.inclusionEditModel.data }, false, false, 2,false);
  102. #endregion
  103. }
  104. #region [初始控件]
  105. private void InitCommonButtonEvent()
  106. {
  107. this.commonControlButtons.zoomInButton.Click += new EventHandler(zoomInButton_Click);
  108. this.commonControlButtons.zoomOutButton.Click += new EventHandler(zoomOutButton_Click);
  109. this.commonControlButtons.zoomToWindowButton.Click += new EventHandler(zoomToWindowButton_Click);
  110. this.commonControlButtons.actualSizeButton.Click += new EventHandler(actualSizeButton_Click);
  111. this.commonControlButtons.pointerButton.Click += new EventHandler(pointerButton_Click);
  112. this.commonControlButtons.mobileModeButton.Click += new EventHandler(mobileModeButton_Click);
  113. }
  114. private void zoomInButton_Click(object sender, EventArgs e)
  115. {
  116. if (this.bitmap != null)
  117. this.documentWorkspace.ZoomIn();
  118. }
  119. private void zoomOutButton_Click(object sender, EventArgs e)
  120. {
  121. if (this.bitmap != null)
  122. this.documentWorkspace.ZoomOut();
  123. }
  124. private void zoomToWindowButton_Click(object sender, EventArgs e)
  125. {
  126. this.documentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
  127. }
  128. private void actualSizeButton_Click(object sender, EventArgs e)
  129. {
  130. this.documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
  131. this.documentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
  132. }
  133. private void pointerButton_Click(object sender, EventArgs e)
  134. {
  135. this.documentWorkspace.ActiveTool = DrawToolType.Pointer;
  136. }
  137. private void mobileModeButton_Click(object sender, EventArgs e)
  138. {
  139. this.documentWorkspace.ActiveTool = DrawToolType.MoveMode;
  140. }
  141. #endregion
  142. #region Windows Form Designer geneAnnotation.Enum.rated code
  143. /// <summary>
  144. /// Required method for Designer support - do not modify
  145. /// the contents of this method with the code editor.
  146. /// </summary>
  147. private void InitializeComponent()
  148. {
  149. this.groupBox1 = new System.Windows.Forms.GroupBox();
  150. this.button2 = new System.Windows.Forms.Button();
  151. this.button1 = new System.Windows.Forms.Button();
  152. this.groupBox2 = new System.Windows.Forms.GroupBox();
  153. this.label8 = new System.Windows.Forms.Label();
  154. this.label7 = new System.Windows.Forms.Label();
  155. this.label6 = new System.Windows.Forms.Label();
  156. this.label5 = new System.Windows.Forms.Label();
  157. this.label4 = new System.Windows.Forms.Label();
  158. this.label3 = new System.Windows.Forms.Label();
  159. this.label2 = new System.Windows.Forms.Label();
  160. this.label1 = new System.Windows.Forms.Label();
  161. this.groupBox3 = new System.Windows.Forms.GroupBox();
  162. this.button4 = new System.Windows.Forms.Button();
  163. this.button3 = new System.Windows.Forms.Button();
  164. this.groupBox4 = new System.Windows.Forms.GroupBox();
  165. this.groupBox1.SuspendLayout();
  166. this.groupBox2.SuspendLayout();
  167. this.groupBox3.SuspendLayout();
  168. this.SuspendLayout();
  169. //
  170. // groupBox1
  171. //
  172. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  173. | System.Windows.Forms.AnchorStyles.Right)));
  174. this.groupBox1.Controls.Add(this.button2);
  175. this.groupBox1.Controls.Add(this.button1);
  176. this.groupBox1.Location = new System.Drawing.Point(18, 18);
  177. this.groupBox1.Margin = new System.Windows.Forms.Padding(4);
  178. this.groupBox1.Name = "groupBox1";
  179. this.groupBox1.Padding = new System.Windows.Forms.Padding(4);
  180. this.groupBox1.Size = new System.Drawing.Size(1164, 80);
  181. this.groupBox1.TabIndex = 14;
  182. this.groupBox1.TabStop = false;
  183. this.groupBox1.Text = "操作";
  184. //
  185. // button2
  186. //
  187. this.button2.Location = new System.Drawing.Point(1042, 26);
  188. this.button2.Margin = new System.Windows.Forms.Padding(4);
  189. this.button2.Name = "button2";
  190. this.button2.Size = new System.Drawing.Size(112, 34);
  191. this.button2.TabIndex = 1;
  192. this.button2.Text = "关闭";
  193. this.button2.UseVisualStyleBackColor = true;
  194. this.button2.Click += new System.EventHandler(this.button2_Click);
  195. //
  196. // button1
  197. //
  198. this.button1.Location = new System.Drawing.Point(921, 26);
  199. this.button1.Margin = new System.Windows.Forms.Padding(4);
  200. this.button1.Name = "button1";
  201. this.button1.Size = new System.Drawing.Size(112, 34);
  202. this.button1.TabIndex = 0;
  203. this.button1.Text = "确定";
  204. this.button1.UseVisualStyleBackColor = true;
  205. this.button1.Click += new System.EventHandler(this.button1_Click);
  206. //
  207. // groupBox2
  208. //
  209. this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  210. | System.Windows.Forms.AnchorStyles.Right)));
  211. this.groupBox2.Controls.Add(this.label8);
  212. this.groupBox2.Controls.Add(this.label7);
  213. this.groupBox2.Controls.Add(this.label6);
  214. this.groupBox2.Controls.Add(this.label5);
  215. this.groupBox2.Controls.Add(this.label4);
  216. this.groupBox2.Controls.Add(this.label3);
  217. this.groupBox2.Controls.Add(this.label2);
  218. this.groupBox2.Controls.Add(this.label1);
  219. this.groupBox2.Location = new System.Drawing.Point(18, 106);
  220. this.groupBox2.Margin = new System.Windows.Forms.Padding(4);
  221. this.groupBox2.Name = "groupBox2";
  222. this.groupBox2.Padding = new System.Windows.Forms.Padding(4);
  223. this.groupBox2.Size = new System.Drawing.Size(441, 274);
  224. this.groupBox2.TabIndex = 15;
  225. this.groupBox2.TabStop = false;
  226. this.groupBox2.Text = "夹杂物属性";
  227. //
  228. // label8
  229. //
  230. this.label8.AutoSize = true;
  231. this.label8.Location = new System.Drawing.Point(132, 224);
  232. this.label8.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
  233. this.label8.Name = "label8";
  234. this.label8.Size = new System.Drawing.Size(62, 18);
  235. this.label8.TabIndex = 7;
  236. this.label8.Text = "label8";
  237. //
  238. // label7
  239. //
  240. this.label7.AutoSize = true;
  241. this.label7.Location = new System.Drawing.Point(28, 224);
  242. this.label7.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
  243. this.label7.Name = "label7";
  244. this.label7.Size = new System.Drawing.Size(62, 18);
  245. this.label7.TabIndex = 6;
  246. this.label7.Text = "类型:";
  247. //
  248. // label6
  249. //
  250. this.label6.AutoSize = true;
  251. this.label6.Location = new System.Drawing.Point(132, 168);
  252. this.label6.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
  253. this.label6.Name = "label6";
  254. this.label6.Size = new System.Drawing.Size(62, 18);
  255. this.label6.TabIndex = 5;
  256. this.label6.Text = "label6";
  257. //
  258. // label5
  259. //
  260. this.label5.AutoSize = true;
  261. this.label5.Location = new System.Drawing.Point(28, 168);
  262. this.label5.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
  263. this.label5.Name = "label5";
  264. this.label5.Size = new System.Drawing.Size(62, 18);
  265. this.label5.TabIndex = 4;
  266. this.label5.Text = "面积:";
  267. //
  268. // label4
  269. //
  270. this.label4.AutoSize = true;
  271. this.label4.Location = new System.Drawing.Point(132, 108);
  272. this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
  273. this.label4.Name = "label4";
  274. this.label4.Size = new System.Drawing.Size(62, 18);
  275. this.label4.TabIndex = 3;
  276. this.label4.Text = "label4";
  277. //
  278. // label3
  279. //
  280. this.label3.AutoSize = true;
  281. this.label3.Location = new System.Drawing.Point(28, 108);
  282. this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
  283. this.label3.Name = "label3";
  284. this.label3.Size = new System.Drawing.Size(62, 18);
  285. this.label3.TabIndex = 2;
  286. this.label3.Text = "宽度:";
  287. //
  288. // label2
  289. //
  290. this.label2.AutoSize = true;
  291. this.label2.Location = new System.Drawing.Point(132, 54);
  292. this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
  293. this.label2.Name = "label2";
  294. this.label2.Size = new System.Drawing.Size(62, 18);
  295. this.label2.TabIndex = 1;
  296. this.label2.Text = "label2";
  297. //
  298. // label1
  299. //
  300. this.label1.AutoSize = true;
  301. this.label1.Location = new System.Drawing.Point(28, 54);
  302. this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
  303. this.label1.Name = "label1";
  304. this.label1.Size = new System.Drawing.Size(62, 18);
  305. this.label1.TabIndex = 0;
  306. this.label1.Text = "长度:";
  307. //
  308. // groupBox3
  309. //
  310. this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  311. | System.Windows.Forms.AnchorStyles.Right)));
  312. this.groupBox3.Controls.Add(this.button4);
  313. this.groupBox3.Controls.Add(this.button3);
  314. this.groupBox3.Location = new System.Drawing.Point(18, 382);
  315. this.groupBox3.Margin = new System.Windows.Forms.Padding(4);
  316. this.groupBox3.Name = "groupBox3";
  317. this.groupBox3.Padding = new System.Windows.Forms.Padding(4);
  318. this.groupBox3.Size = new System.Drawing.Size(441, 274);
  319. this.groupBox3.TabIndex = 16;
  320. this.groupBox3.TabStop = false;
  321. this.groupBox3.Text = "夹杂物操作";
  322. //
  323. // button4
  324. //
  325. this.button4.Location = new System.Drawing.Point(32, 93);
  326. this.button4.Margin = new System.Windows.Forms.Padding(4);
  327. this.button4.Name = "button4";
  328. this.button4.Size = new System.Drawing.Size(112, 34);
  329. this.button4.TabIndex = 1;
  330. this.button4.Text = "添加";
  331. this.button4.UseVisualStyleBackColor = true;
  332. this.button4.Click += new System.EventHandler(this.button4_Click);
  333. //
  334. // button3
  335. //
  336. this.button3.Location = new System.Drawing.Point(32, 30);
  337. this.button3.Margin = new System.Windows.Forms.Padding(4);
  338. this.button3.Name = "button3";
  339. this.button3.Size = new System.Drawing.Size(112, 34);
  340. this.button3.TabIndex = 0;
  341. this.button3.Text = "删除";
  342. this.button3.UseVisualStyleBackColor = true;
  343. this.button3.Click += new System.EventHandler(this.button3_Click);
  344. //
  345. // groupBox4
  346. //
  347. this.groupBox4.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  348. | System.Windows.Forms.AnchorStyles.Right)));
  349. this.groupBox4.Location = new System.Drawing.Point(468, 106);
  350. this.groupBox4.Margin = new System.Windows.Forms.Padding(4);
  351. this.groupBox4.Name = "groupBox4";
  352. this.groupBox4.Padding = new System.Windows.Forms.Padding(4);
  353. this.groupBox4.Size = new System.Drawing.Size(714, 550);
  354. this.groupBox4.TabIndex = 17;
  355. this.groupBox4.TabStop = false;
  356. //
  357. // MethodKInclusionEditSec
  358. //
  359. this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F);
  360. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  361. this.ClientSize = new System.Drawing.Size(1200, 675);
  362. this.Controls.Add(this.groupBox4);
  363. this.Controls.Add(this.groupBox3);
  364. this.Controls.Add(this.groupBox2);
  365. this.Controls.Add(this.groupBox1);
  366. this.Margin = new System.Windows.Forms.Padding(4);
  367. this.Name = "MethodKInclusionEditSec";
  368. this.Text = "夹杂物编辑";
  369. this.groupBox1.ResumeLayout(false);
  370. this.groupBox2.ResumeLayout(false);
  371. this.groupBox2.PerformLayout();
  372. this.groupBox3.ResumeLayout(false);
  373. this.ResumeLayout(false);
  374. }
  375. /// <summary>
  376. /// 面板绘制事件
  377. /// </summary>
  378. /// <param name="sender"></param>
  379. /// <param name="e"></param>
  380. private void DrawPaintEvent(object sender, PaintEventArgs e)
  381. {
  382. if (this.selectedInclusion.Count > 0)
  383. {
  384. Rectangle rc = this.documentWorkspace.panel.ClientRectangle;
  385. int wid = this.documentWorkspace.CompositionSurface == null ? this.documentWorkspace.Width : this.documentWorkspace.CompositionSurface.Width;
  386. int hei = this.documentWorkspace.CompositionSurface == null ? this.documentWorkspace.Height : this.documentWorkspace.CompositionSurface.Height;
  387. int width = (int)(wid * this.documentWorkspace.ScaleFactor.Ratio);
  388. int height = (int)(hei * this.documentWorkspace.ScaleFactor.Ratio);
  389. int x = (rc.Width < width) ? this.documentWorkspace.panel.AutoScrollPosition.X : (rc.Width - width) / 2;
  390. int y = (rc.Height < height) ? this.documentWorkspace.panel.AutoScrollPosition.Y : (rc.Height - height) / 2;
  391. e.Graphics.TranslateTransform(x, y);
  392. e.Graphics.ScaleTransform((float)this.documentWorkspace.ScaleFactor.Ratio, (float)this.documentWorkspace.ScaleFactor.Ratio);
  393. Pen pen = new Pen(Color.Blue,1);
  394. for (int i = 0; i < this.selectedInclusion.Count; i++)
  395. {
  396. Rectangle rectangle = new Rectangle(this.selectedInclusion[i].rectProfile.X, this.selectedInclusion[i].rectProfile.Y, this.selectedInclusion[i].rectProfile.Width == 0 ? 5 : this.selectedInclusion[i].rectProfile.Width, this.selectedInclusion[i].rectProfile.Height == 0 ? 5 : this.selectedInclusion[i].rectProfile.Height);
  397. e.Graphics.DrawRectangle(pen, rectangle);
  398. }
  399. e.Graphics.ScaleTransform(1 / (float)this.documentWorkspace.ScaleFactor.Ratio, 1 / (float)this.documentWorkspace.ScaleFactor.Ratio);
  400. e.Graphics.TranslateTransform(-x, -y);
  401. }
  402. }
  403. #region [滑动选中]
  404. /// <summary>
  405. /// Left mouse button is pressed
  406. /// </summary>
  407. /// <param name="drawArea"></param>
  408. /// <param name="e"></param>
  409. private void OnMouseDown(object sender, MouseEventArgs e)
  410. {
  411. if (e.Button == MouseButtons.Left)
  412. {
  413. this.selectedInclusion.Clear();
  414. this.selectedTypesOfInclusionsPoint = e.Location;
  415. }
  416. }
  417. /// <summary>
  418. /// Mouse is moved.
  419. /// None button is pressed, or left button is pressed.
  420. /// </summary>
  421. /// <param name="drawArea"></param>
  422. /// <param name="e"></param>
  423. private void OnMouseMove(object sender, MouseEventArgs e)
  424. {
  425. Pen pen = new Pen(Color.Black, 3);
  426. if (this.selectedTypesOfInclusionsPoint == null)
  427. {
  428. return;
  429. }
  430. this.documentWorkspace.Refresh();
  431. float x = Math.Min(this.selectedTypesOfInclusionsPoint.Value.X, e.Location.X);
  432. float y = Math.Min(this.selectedTypesOfInclusionsPoint.Value.Y, e.Location.Y);
  433. float width = Math.Abs(this.selectedTypesOfInclusionsPoint.Value.X - e.Location.X);
  434. float height = Math.Abs(this.selectedTypesOfInclusionsPoint.Value.Y - e.Location.Y);
  435. this.documentWorkspace.panel.CreateGraphics().DrawRectangles(pen, new RectangleF[] { new RectangleF(x, y, width, height) });
  436. }
  437. #endregion
  438. #endregion
  439. /// <summary>
  440. /// 删除
  441. /// </summary>
  442. /// <param name="sender"></param>
  443. /// <param name="e"></param>
  444. private void button3_Click(object sender, EventArgs e)
  445. {
  446. if (this.selectedInclusion.Count == 0)
  447. {
  448. return;
  449. }
  450. foreach (var item in this.selectedInclusion)
  451. {
  452. this.inclusionEditModel.data.removeParticles(item);
  453. }
  454. this.selectedInclusion.Clear();
  455. ToolInclusionSelect.CleanAndDrawInclusionAll(this.documentWorkspace, new List<Inclusion>() { this.inclusionEditModel.data }, false, false, 2, false);
  456. this.label2.Text = this.inclusionEditModel.data.physicalLength.ToString();
  457. this.label4.Text = this.inclusionEditModel.data.physicalWidth.ToString();
  458. this.label6.Text = this.inclusionEditModel.data.areaK.ToString();
  459. this.label8.Text = this.inclusionEditModel.data.type.type.ToString();
  460. }
  461. /// <summary>
  462. /// 添加
  463. /// </summary>
  464. /// <param name="sender"></param>
  465. /// <param name="e"></param>
  466. private void button4_Click(object sender, EventArgs e)
  467. {
  468. this.documentWorkspace.panel.MouseDown -= new MouseEventHandler(this.OnMouseDown);
  469. this.documentWorkspace.panel.MouseMove -= new MouseEventHandler(this.OnMouseMove);
  470. this.documentWorkspace.panel.MouseUp -= new MouseEventHandler(this.documentWorkspace_panel_MouseUp);
  471. this.documentWorkspace.panel.MouseUp += StopWrite;
  472. this.documentWorkspace.SetInclusion(this.inclusionEditModel.data);
  473. this.documentWorkspace.ActiveTool = DrawToolType.InclusionNewPolygon;
  474. }
  475. private void StopWrite(object sender, MouseEventArgs e)
  476. {
  477. this.label2.Text = this.inclusionEditModel.data.physicalLength.ToString();
  478. this.label4.Text = this.inclusionEditModel.data.physicalWidth.ToString();
  479. this.label6.Text = this.inclusionEditModel.data.areaK.ToString();
  480. this.label8.Text = this.inclusionEditModel.data.type.type.ToString();
  481. this.documentWorkspace.panel.MouseUp -= StopWrite;
  482. this.documentWorkspace.panel.MouseDown += OnMouseDown;
  483. this.documentWorkspace.panel.MouseUp += documentWorkspace_panel_MouseUp;
  484. this.documentWorkspace.panel.MouseMove += OnMouseMove;
  485. }
  486. /// <summary>
  487. /// 确定
  488. /// </summary>
  489. /// <param name="sender"></param>
  490. /// <param name="e"></param>
  491. private void button1_Click(object sender, EventArgs e)
  492. {
  493. this.Close();
  494. int x = this.oldInclusionEditModel.data.rectProfile.X;
  495. int y = this.oldInclusionEditModel.data.rectProfile.Y;
  496. for (int i = 0; i < this.inclusionEditModel.data.particles.Count; i++)
  497. {
  498. this.inclusionEditModel.data.particles[i].rectProfile = new System.Drawing.Rectangle(this.inclusionEditModel.data.particles[i].rectProfile.X + x, this.inclusionEditModel.data.particles[i].rectProfile.Y + y, this.oldInclusionEditModel.data.particles[i].rectProfile.Width, this.inclusionEditModel.data.particles[i].rectProfile.Height);
  499. for (int j = 0; j < this.inclusionEditModel.data.particles[i].points2.Length; j++)
  500. {
  501. this.inclusionEditModel.data.particles[i].points2[j].X += x;
  502. this.inclusionEditModel.data.particles[i].points2[j].Y += y;
  503. }
  504. }
  505. this.methodKInclusionEdit.rootEditCallBack(this.inclusionEditModel);
  506. }
  507. /// <summary>
  508. /// 关闭
  509. /// </summary>
  510. /// <param name="sender"></param>
  511. /// <param name="e"></param>
  512. private void button2_Click(object sender, EventArgs e)
  513. {
  514. this.Close();
  515. int x = this.oldInclusionEditModel.data.rectProfile.X;
  516. int y = this.oldInclusionEditModel.data.rectProfile.Y;
  517. for (int i = 0; i < this.inclusionEditModel.data.particles.Count; i++)
  518. {
  519. this.inclusionEditModel.data.particles[i].rectProfile = new System.Drawing.Rectangle(this.inclusionEditModel.data.particles[i].rectProfile.X + x, this.inclusionEditModel.data.particles[i].rectProfile.Y + y, this.oldInclusionEditModel.data.particles[i].rectProfile.Width, this.inclusionEditModel.data.particles[i].rectProfile.Height);
  520. for (int j = 0; j < this.inclusionEditModel.data.particles[i].points2.Length; j++)
  521. {
  522. this.inclusionEditModel.data.particles[i].points2[j].X += x;
  523. this.inclusionEditModel.data.particles[i].points2[j].Y += y;
  524. }
  525. }
  526. this.methodKInclusionEdit.rootEditCallBack(this.inclusionEditModel);
  527. }
  528. /// <summary>
  529. ///
  530. /// </summary>
  531. /// <param name="sender"></param>
  532. /// <param name="e"></param>
  533. private void documentWorkspace_panel_MouseUp(object sender, MouseEventArgs e)
  534. {
  535. if (e.Button == MouseButtons.Left)
  536. {
  537. this.selectedInclusion.Clear();
  538. if (this.selectedTypesOfInclusionsPoint == null)
  539. {
  540. return;
  541. }
  542. var startPoint = this.documentWorkspace.GetScalePoint(this.selectedTypesOfInclusionsPoint.Value);
  543. var lastPoint = this.documentWorkspace.GetScalePoint(e.Location);
  544. RectangleF rectangle = new RectangleF(Math.Min(lastPoint.X, startPoint.X), Math.Min(lastPoint.Y, startPoint.Y), Math.Abs(lastPoint.X - startPoint.X), Math.Abs(lastPoint.Y - startPoint.Y));
  545. for (int i = 0; i < this.documentWorkspace.GraphicsList.Count; i++)
  546. {
  547. if (!(this.documentWorkspace.GraphicsList[i] is InclusionDrawObject))
  548. {
  549. continue;
  550. }
  551. InclusionDrawObject drawObject = (InclusionDrawObject)this.documentWorkspace.GraphicsList[i];
  552. foreach (Particle particle in drawObject.inclusion.particles)
  553. {
  554. if (rectangle.Contains(particle.rectProfile) || rectangle.IntersectsWith(particle.rectProfile))
  555. {
  556. this.selectedInclusion.Add(particle);
  557. }
  558. }
  559. }
  560. this.selectedTypesOfInclusionsPoint = null;
  561. }
  562. this.documentWorkspace.Refresh();
  563. }
  564. }
  565. }