BatteryCrystalDialog.cs 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792
  1. using OpenCvSharp;
  2. using PaintDotNet.Annotation;
  3. using PaintDotNet.Annotation.Enum;
  4. using PaintDotNet.Base.CommTool;
  5. using PaintDotNet.Base.Functionodel;
  6. using PaintDotNet.Base.SettingModel;
  7. using PaintDotNet.CustomControl;
  8. using PaintDotNet.DbOpreate.DbBll;
  9. using PaintDotNet.DbOpreate.DbModel;
  10. using System;
  11. using System.Collections;
  12. using System.Collections.Generic;
  13. using System.ComponentModel;
  14. using System.Configuration;
  15. using System.Data;
  16. using System.Drawing;
  17. using System.Drawing.Drawing2D;
  18. using System.IO;
  19. using System.Linq;
  20. using System.Text;
  21. using System.Windows.Forms;
  22. namespace PaintDotNet.DedicatedAnalysis.Battery
  23. {
  24. internal partial class BatteryCrystalDialog : PdnBaseForm
  25. {
  26. #region 属性
  27. //二值化集成1
  28. BinaryClassForB binaryClass;
  29. private int menuId;
  30. /// <summary>
  31. /// 选中图片的bitmap
  32. /// </summary>
  33. private Bitmap bitmap;
  34. /// <summary>
  35. /// 存在视场标记
  36. /// </summary>
  37. private bool existViewFlag = false;
  38. private int changeCount;
  39. /// <summary>
  40. /// 主空间
  41. /// </summary>
  42. private AppWorkspace appWorkspace;
  43. /// <summary>
  44. /// 图像面板
  45. /// </summary>
  46. private DocumentWorkspaceWindow documentWorkspace;
  47. /// <summary>
  48. /// 公共控件
  49. /// </summary>
  50. private GeneralAnalysisCommonControlButtons commonControlButtons;
  51. /// <summary>
  52. /// 图片测量记录
  53. /// </summary>
  54. private List<DataTable> pictureDataTables = new List<DataTable>();
  55. /// <summary>
  56. /// 网格Xml
  57. /// </summary>
  58. private GrainSizePointCountingMethodModel grainSizePointCountingMethodModel;
  59. /// <summary>
  60. /// 数据变化
  61. /// </summary>
  62. private bool saveSuccess = false;
  63. private BinaryControlSmaller bc;
  64. #endregion 属性
  65. #region 数据属性
  66. /// <summary>
  67. /// 折线点的集合
  68. /// </summary>
  69. public List<System.Drawing.Point> pointArray = new List<System.Drawing.Point>();
  70. /// <summary>
  71. /// 存储所有轮廓线的点集合
  72. /// </summary>
  73. private List<PointF> pointList = new List<PointF>();
  74. /// <summary>
  75. /// 存储所有轮廓线集合
  76. /// </summary>
  77. private List<List<PointF>> lineList = new List<List<PointF>>();
  78. /// <summary>
  79. /// 存储所有增加颗粒的点集合
  80. /// </summary>
  81. private List<PointF> kongPointList = new List<PointF>();
  82. /// <summary>
  83. /// 存储所有孔隙线集合
  84. /// </summary>
  85. private List<List<PointF>> kongLineList = new List<List<PointF>>();
  86. /// <summary>
  87. /// 存储所有删除孔隙线的点集合
  88. /// </summary>
  89. private List<PointF> delPointList = new List<PointF>();
  90. /// <summary>
  91. /// 存储所有删除孔隙线集合
  92. /// </summary>
  93. private List<List<PointF>> delLineList = new List<List<PointF>>();
  94. //轮廓修改状态
  95. bool isLunKuo = false;
  96. //添加孔隙状态
  97. bool isAddKong = false;
  98. //删除孔隙状态
  99. bool isDelKong = false;
  100. /// <summary>
  101. /// 0:添加 1:选择 2:删除
  102. /// </summary>
  103. private int operationK = -1;
  104. /// <summary>
  105. /// 被选择的线
  106. /// </summary>
  107. private int selected = -1;
  108. /// <summary>
  109. /// 起止点
  110. /// </summary>
  111. private System.Drawing.PointF startPoint, endPoint;
  112. /// <summary>
  113. /// 存储所有线的点集合
  114. /// </summary>
  115. private List<PointF[]> pointList1 = new List<PointF[]>();
  116. /// <summary>
  117. /// 存储当前线的点集合
  118. /// </summary>
  119. private PointF[] nowLine;
  120. /// <summary>
  121. /// 辅助计算偏移量-移动线两端的点
  122. /// </summary>
  123. private PointF lastPoint = new PointF(0, 0);
  124. /// <summary>
  125. /// 辅助计算偏移量-移动线中间的点
  126. /// </summary>
  127. private PointF tempPoint = new PointF(0, 0);
  128. /// <summary>
  129. /// 判断图形是否可移动
  130. /// </summary>
  131. private bool canMove = false;
  132. /// <summary>
  133. /// 测量点
  134. /// </summary>
  135. public List<RectangleF> rectangleFList = new List<RectangleF>();
  136. /// <summary>
  137. /// 移动线上的哪一个点
  138. /// </summary>
  139. private int movePointIndex = -1;
  140. /// <summary>
  141. /// 线的总数
  142. /// </summary>
  143. private int lineCount = 0;
  144. /// <summary>
  145. /// 单位标尺
  146. /// </summary>
  147. private double unitLength = 1;
  148. #endregion
  149. System.Windows.Forms.DataVisualization.Charting.Chart chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart();
  150. /// <summary>
  151. ///
  152. /// </summary>
  153. /// <param name="appWorkspace"></param>
  154. public BatteryCrystalDialog(AppWorkspace appWorkspace, int menuId)
  155. {
  156. this.KeyPreview = true;
  157. this.KeyDown += OnKeyDown;
  158. this.menuId = menuId;
  159. binaryClass = new BinaryClassForB(menuId);
  160. InitializeComponent();
  161. InitializeLanguageText();
  162. ColumnHeader header0 = new ColumnHeader();
  163. header0.Text = "";
  164. header0.Width = 180;
  165. this.appWorkspace = appWorkspace;
  166. this.documentWorkspace = new DocumentWorkspaceWindow(appWorkspace);
  167. this.documentWorkspace.Dock = DockStyle.Fill;
  168. this.documentWorkspace.HookMouseEvents();
  169. this.documentWorkspace.AuxiliaryLineEnabled = false;
  170. this.documentWorkspace.Visible = false;
  171. this.documentWorkspace.panel.Paint += Panel_Paint;
  172. this.documentWorkspace.panel.MouseDown += OnMouseDown;
  173. this.documentWorkspace.panel.MouseUp += OnMouseUp;
  174. this.documentWorkspace.panel.Paint += Panel_Paint;
  175. this.documentWorkspace.panel.MouseMove += onMouseMove;
  176. this.documentWorkspace.activeTool = DrawToolType.Pointer;
  177. this.groupBox7.Controls.Add(this.documentWorkspace);
  178. this.commonControlButtons = new GeneralAnalysisCommonControlButtons();
  179. this.commonControlButtons.Dock = DockStyle.Top;
  180. this.commonControlButtons.Height = 30;
  181. this.commonControlButtons.HideZoomToWindowAndActualSize();
  182. this.commonControlButtons.trackLabel.Text = "单击开始画线,右键停止。";
  183. this.commonControlButtons.trackLabel.Visible = true;
  184. this.commonControlButtons.trackLabel.Width = 300;
  185. this.commonControlButtons.Visible = false;
  186. this.groupBox7.Controls.Add(commonControlButtons);
  187. //获取
  188. //Startup.instance.rules.TryGetValue(MeasurementUnit.Micron, out ruleValue);
  189. //double ruleValue = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetRuler(MeasurementUnit.Micron);
  190. ////double physical_area_length_Micron = getCurrentWorkspace().GetRuler(MeasurementUnit.Micron);
  191. chart1.Size = new System.Drawing.Size(1150, 180);
  192. chart1.Location = new System.Drawing.Point(5, 15);
  193. //二值化集成2
  194. bc.OriginCheckedChangedAction += new EventHandler(this.bcOriginCheckedChanged);//初始化原图勾选改变事件
  195. binaryClass.imageType = 2;
  196. binaryClass.createDocumentItemsSmaller(new string[] { "bp1" } , this.bc, this.appWorkspace, this.documentWorkspace, this.listView1);//初始化相的工作结构
  197. //binaryClass.BinaryImplFinishAction += new EventHandler(this.bClassBinaryImplFinishAction);//二值化后续处理事件(参数改变时,重新处理图像)
  198. binaryClass.parentSinglCrystal = this;
  199. this.ckChanged.CheckedChanged += new EventHandler(this.CheckedChanged);
  200. InitCommonButtonEvent();
  201. InitGridStyle();
  202. InitPicList();
  203. // SetAnalyzeModelFromXml(getModelName());
  204. }
  205. private void ShowImgEvent(object sender, EventArgs e)
  206. {
  207. if (this.listView1.Items.Count == 0)
  208. {
  209. return;
  210. }
  211. listView1.Focus();
  212. this.listView1.Items[0].Focused = true;
  213. this.listView1.Items[0].Selected = true;
  214. }
  215. #region 二值化相关方法
  216. private void InclusionsStandardDialog_FormClosing(object sender, FormClosingEventArgs e)
  217. {
  218. //binaryClass.saveParams();
  219. }
  220. private void ShownChoiseItemAndInitData(object sender, EventArgs e)
  221. {
  222. binaryClass.RefreshHistogramControl1Values();
  223. }
  224. /// <summary>
  225. /// 添加参数改变的监听
  226. /// </summary>
  227. /// <param name="sender"></param>
  228. /// <param name="e"></param>
  229. private void GrainSizePointCountingMethodDialog_Load(object sender, EventArgs e)
  230. {
  231. this.dataGridView1.SortCompare += DataGridView4_SortCompare;
  232. this.binaryClass.loadParams();
  233. }
  234. private bool bcBinaryChecked()
  235. {
  236. return bc != null && bc.BinaryChecked;
  237. }
  238. private bool bcOriginChecked()
  239. {
  240. return bc != null && bc.OriginChecked;
  241. }
  242. /// <summary>
  243. /// 显示原图/原图+二值图
  244. /// </summary>
  245. /// <param name="sender"></param>
  246. /// <param name="e"></param>
  247. private void bcOriginCheckedChanged(object sender, EventArgs e)
  248. {
  249. if (!bcOriginChecked())
  250. {
  251. if (bcBinaryChecked())
  252. this.documentWorkspace.PhaseModels[0].choise = true;
  253. }
  254. else
  255. this.documentWorkspace.PhaseModels[0].choise = false;
  256. this.documentWorkspace.Refresh();
  257. }
  258. /// <summary>
  259. /// 显示原图/原图+二值图
  260. /// </summary>
  261. /// <param name="sender"></param>
  262. /// <param name="e"></param>
  263. private void CheckedChanged(object sender, EventArgs e)
  264. {
  265. if (!ckChanged.Checked)
  266. {
  267. this.documentWorkspace.PhaseModels[0].choise = true;
  268. }
  269. else
  270. this.documentWorkspace.PhaseModels[0].choise = false;
  271. this.documentWorkspace.Refresh();
  272. }
  273. #endregion
  274. /// <summary>
  275. /// 初始化画面数据
  276. /// </summary>
  277. private void InitGridStyle()
  278. {
  279. grainSizePointCountingMethodModel = XmlSerializeHelper.DESerializer<GrainSizePointCountingMethodModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizePointCountingMethodModel.xml", FileMode.Open));
  280. if (grainSizePointCountingMethodModel.GridStyleList != null)
  281. {
  282. ArrayList arrayList = new ArrayList();
  283. foreach (var GridStyle in grainSizePointCountingMethodModel.GridStyleList)
  284. {
  285. arrayList.Add(GridStyle.gridName);
  286. }
  287. if (grainSizePointCountingMethodModel.GridStyleList.Count == 0)
  288. {
  289. }
  290. }
  291. }
  292. /// <summary>
  293. /// 初始化图片列表数据
  294. /// </summary>
  295. public void InitPicList()
  296. {
  297. //初始化图片列表
  298. for (int i = 0; i < this.appWorkspace.DocumentWorkspaces.Length; i++)
  299. {
  300. this.imageList1.Images.Add("img" + i, this.appWorkspace.DocumentWorkspaces[i].BinarizationThumbnail);
  301. this.listView1.Items.Add("", i);
  302. this.listView1.Items[i].ImageIndex = i;
  303. this.listView1.Items[i].Text = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName();
  304. this.listView1.Items[i].Name = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName();
  305. }
  306. this.Shown += ShowImgEvent;
  307. }
  308. #region 初始化
  309. private void InitializeLanguageText()
  310. {
  311. this.bc = new PaintDotNet.CustomControl.BinaryControlSmaller();
  312. //
  313. // bc
  314. //
  315. this.bc.BinaryBackColor = System.Drawing.Color.Red;
  316. this.bc.BinaryChecked = false;
  317. this.bc.BinaryStyle = 1;
  318. this.bc.Location = new System.Drawing.Point(152, 7);
  319. this.bc.Name = "bc";
  320. this.bc.OriginChecked = false;
  321. this.bc.scope1End = 170D;
  322. this.bc.scope1Start = 80D;
  323. this.bc.scope2End = 0D;
  324. this.bc.scope2Start = 0D;
  325. this.bc.scope3End = 0D;
  326. this.bc.scope3Start = 0D;
  327. this.bc.Size = new System.Drawing.Size(360, 247);
  328. this.bc.TabIndex = 3;
  329. // this.Controls.Add(this.bc);
  330. // this.Controls.SetChildIndex(this.bc, 0);
  331. //this.groupBox9.Controls.Add(chart1);
  332. this.groupBox8.Controls.Add(chart1);
  333. chart1.Visible = false;
  334. //this.label10.Visible = true;
  335. //this.label10.Text = "【" + tn.Name + "】图";
  336. chart1.Titles.Add("单晶尺寸分布图");
  337. }
  338. #endregion
  339. #region 公共按钮
  340. private void InitCommonButtonEvent()
  341. {
  342. this.commonControlButtons.zoomInButton.Click += new EventHandler(zoomInButton_Click);
  343. this.commonControlButtons.zoomOutButton.Click += new EventHandler(zoomOutButton_Click);
  344. this.commonControlButtons.zoomToWindowButton.Click += new EventHandler(zoomToWindowButton_Click);
  345. this.commonControlButtons.actualSizeButton.Click += new EventHandler(actualSizeButton_Click);
  346. this.commonControlButtons.pointerButton.Click += new EventHandler(pointerButton_Click);
  347. this.commonControlButtons.mobileModeButton.Click += new EventHandler(mobileModeButton_Click);
  348. }
  349. private void zoomInButton_Click(object sender, EventArgs e)
  350. {
  351. this.documentWorkspace.ZoomIn();
  352. }
  353. private void zoomOutButton_Click(object sender, EventArgs e)
  354. {
  355. this.documentWorkspace.ZoomOut();
  356. }
  357. private void zoomToWindowButton_Click(object sender, EventArgs e)
  358. {
  359. this.documentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
  360. }
  361. private void actualSizeButton_Click(object sender, EventArgs e)
  362. {
  363. this.documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
  364. this.documentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
  365. }
  366. private void pointerButton_Click(object sender, EventArgs e)
  367. {
  368. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.Pointer;
  369. }
  370. private void mobileModeButton_Click(object sender, EventArgs e)
  371. {
  372. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode;
  373. }
  374. #endregion
  375. private void listView1_MouseDown(object sender, MouseEventArgs e)
  376. {
  377. this.changeCount = 0;
  378. }
  379. private void DataGridView4_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
  380. {
  381. // 如果是数据的列,则按浮点数处理
  382. if (e.Column.Index > 1)//###20186
  383. {
  384. e.SortResult = (Convert.ToDouble(e.CellValue1) - Convert.ToDouble(e.CellValue2) > 0) ? 1 : (Convert.ToDouble(e.CellValue1) - Convert.ToDouble(e.CellValue2) < 0) ? -1 : 0;
  385. }
  386. //否则,按字符串比较
  387. else
  388. {
  389. e.SortResult = System.String.Compare(Convert.ToString(e.CellValue1), Convert.ToString(e.CellValue2));
  390. }
  391. e.Handled = true;//不能省掉,不然没效果
  392. }
  393. private void listView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
  394. {
  395. //bool change = false;
  396. //if (this.changeCount == 0)
  397. //{
  398. // if (this.dataGridView1.Rows.Count > 0)
  399. // {
  400. // if (this.saveSuccess)
  401. // {
  402. // DialogResult dt = MessageBox.Show(PdnResources.GetString("Menu.Whethertosavetherrentpicture.text") + "?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  403. // if (dt == DialogResult.Yes)
  404. // {
  405. // string imgName = this.appWorkspace.DocumentWorkspaces[e.ItemIndex].GetFriendlyName();
  406. // string tag = this.imageList1.Images.Keys[e.ItemIndex];
  407. // if (this.dataGridView1.Rows.Count == 0)
  408. // {
  409. // MessageBox.Show(PdnResources.GetString("Menu.Pleaseaddtype.text") + "!");
  410. // return;
  411. // }
  412. // }
  413. // }
  414. // }
  415. //}
  416. //else
  417. //{
  418. // if (change)
  419. // SelectedIndexChanged();
  420. //}
  421. if (unitLength == 1)
  422. unitLength = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetRuler(MeasurementUnit.Micron);
  423. this.changeCount++;
  424. }
  425. /// <summary>
  426. /// 切换图片
  427. /// </summary>
  428. /// <param name="sender"></param>
  429. /// <param name="e"></param>
  430. private void listView1_SelectedIndexChanged(object sender, EventArgs e)
  431. {
  432. SelectedIndexChanged();
  433. }
  434. List<PointF> list = new List<PointF>();
  435. /// <summary>
  436. /// 切换图片
  437. /// </summary>
  438. private void SelectedIndexChanged()
  439. {
  440. if (this.listView1.FocusedItem != null && this.listView1.FocusedItem.Selected)
  441. {
  442. existViewFlag = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GraphicsList.IsExsitView();
  443. this.bitmap = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap();
  444. lineList.Clear();
  445. pointList.Clear();
  446. kongLineList.Clear();
  447. kongPointList.Clear();
  448. delLineList.Clear();
  449. delPointList.Clear();
  450. isLunKuo = false;
  451. isAddKong = false;
  452. isDelKong = false;
  453. this.documentWorkspace.Refresh();
  454. this.dataGridView1.Rows.Clear();
  455. this.dataGridView2.Rows.Clear();
  456. chart1.Series.Clear();
  457. chart1.ChartAreas.Clear();
  458. chart1.Legends.Clear();
  459. Init();
  460. this.documentWorkspace.GridRectangleEnabled = false;
  461. //getimage();
  462. //getbian(bitmap);
  463. double minpoint = Convert.ToDouble(numericUpDown11.Value);
  464. if (!ckMin.Checked)
  465. minpoint = 0.01;
  466. binaryClass.pointsize = Convert.ToDouble(minpoint);
  467. int border = Convert.ToInt32(numericMax.Value);
  468. if (!ckMax.Checked)
  469. border = 0;
  470. binaryClass.border = border;
  471. double HW = Convert.ToDouble(numericHW.Value);
  472. if (!ckHW.Checked)
  473. HW = 100;
  474. binaryClass.HW = HW;
  475. double AreaRatio = Convert.ToDouble(numericArea.Value);
  476. if (!ckArea.Checked)
  477. AreaRatio = 0.01;
  478. binaryClass.AreaRatio = AreaRatio;
  479. //二值化集成4
  480. binaryClass.listView1_SelectedIndexChanged(this.bitmap);
  481. // binaryClass.bcDefault();
  482. this.documentWorkspace.Refresh();
  483. }
  484. }
  485. #region 原始事件
  486. private void Init()
  487. {
  488. this.commonControlButtons.Visible = true;
  489. this.dataGridView1.Rows.Clear();
  490. this.documentWorkspace.phaseModels.Clear();
  491. }
  492. /// <summary>
  493. /// 画布绘制
  494. /// </summary>
  495. /// <param name="sender"></param>
  496. /// <param name="e"></param>
  497. private void Panel_Paint(object sender, PaintEventArgs e)
  498. {
  499. if (this.documentWorkspace.CompositionSurface != null)
  500. {
  501. //
  502. // 以下是计算绘制图片的位置和大小并绘制图片
  503. //
  504. Rectangle rc = this.documentWorkspace.panel.ClientRectangle;
  505. int width = (int)(this.documentWorkspace.CompositionSurface.Width * this.documentWorkspace.ScaleFactor.Ratio);
  506. int height = (int)(this.documentWorkspace.CompositionSurface.Height * this.documentWorkspace.ScaleFactor.Ratio);
  507. int x = (rc.Width < width) ? this.documentWorkspace.panel.AutoScrollPosition.X : (rc.Width - width) / 2;
  508. int y = (rc.Height < height) ? this.documentWorkspace.panel.AutoScrollPosition.Y : (rc.Height - height) / 2;
  509. //if (pointArray.Count > 1)
  510. //{
  511. // e.Graphics.DrawLines(new Pen(Color.FromArgb(0, 0, 0), 2), pointArray.ToArray());
  512. //}
  513. //
  514. // 以下是绘制网格、标注、测量、视场等开始
  515. //
  516. e.Graphics.TranslateTransform(x, y);
  517. e.Graphics.ScaleTransform((float)this.documentWorkspace.ScaleFactor.Ratio, (float)this.documentWorkspace.ScaleFactor.Ratio);
  518. Draw(e.Graphics);
  519. //e.Graphics.DrawLines(new Pen(this.panel1.BackColor, Convert.ToInt32(this.txt_LeftLineWeight.Text)), list.ToArray());
  520. e.Graphics.ScaleTransform(1 / (float)this.documentWorkspace.ScaleFactor.Ratio, 1 / (float)this.documentWorkspace.ScaleFactor.Ratio);
  521. e.Graphics.TranslateTransform(-x, -y);
  522. }
  523. if (bc.isedit)
  524. {
  525. bc.isedit = false;
  526. List<List<int>> CircleDate = bc.data;
  527. bindGrid(CircleDate);
  528. }
  529. }
  530. // <summary>
  531. /// 存储字号与颜色字典
  532. /// </summary>
  533. public Dictionary<string, Color> colourFont = new Dictionary<string, Color>() { { "20", Color.White } };
  534. /// <summary>
  535. /// 绘制
  536. /// </summary>
  537. private void Draw(Graphics graphics)
  538. {
  539. //轮廓手动干预线
  540. if (lineList.Count > 0)
  541. {
  542. for (int i = 0; i < lineList.Count; i++)
  543. {
  544. graphics.DrawLines(new Pen(Color.FromArgb(255, 0, 255), 2), lineList[i].ToArray());
  545. }
  546. }
  547. if (pointList.Count > 1)
  548. {
  549. graphics.DrawLines(new Pen(Color.FromArgb(255, 0, 255), 2), pointList.ToArray());
  550. }
  551. //添加颗粒
  552. Color color = bc.BinaryBackColor;
  553. if (kongLineList.Count > 0)
  554. {
  555. for (int i = 0; i < kongLineList.Count; i++)
  556. {
  557. if (kongLineList[i].Count > 1)
  558. {
  559. graphics.DrawLines(new Pen(color, 2), kongLineList[i].ToArray());
  560. }
  561. }
  562. }
  563. graphics.SmoothingMode = SmoothingMode.AntiAlias;
  564. Pen standardPen = new Pen(Color.FromArgb(0, 255, 0), 4);//基准线画笔
  565. Pen surfacePen = new Pen(Color.FromArgb(255, 0, 0), 4);//钢样表面画笔
  566. Pen completePen = new Pen(Color.FromArgb(0, 0, 255), 4);//完全脱碳层画笔
  567. Pen validPen = new Pen(Color.FromArgb(255, 255, 255), 4);//有效脱碳层画笔
  568. Pen partPen = new Pen(Color.FromArgb(0, 0, 0), 2);//部分脱碳层画笔
  569. Pen borderPen = new Pen(Color.Black);//填充点外圈
  570. SolidBrush insideBrush = new SolidBrush(Color.White);//填充点内圈
  571. Pen rectPen = new Pen(Color.Black);
  572. rectPen.DashStyle = DashStyle.Custom;
  573. float[] dashArray = { 2.0f, 3.0f };
  574. rectPen.DashPattern = dashArray;
  575. if (pointList1.Count > 0)
  576. {
  577. foreach (PointF[] pointFs in pointList1)
  578. {
  579. PointF[] pf = pointFs;
  580. if (pointFs.Count() > 1 && pointFs[0] != pointFs[1])
  581. {
  582. float lineLength = 12;
  583. double angle = Math.Round(BasicCalculationHelper.AngleText(pointFs[0], pointFs[1], new PointF(pointFs[0].X + lineLength, pointFs[0].Y)), 10);
  584. //判断第二个点相对于第一个点的象限
  585. int x2 = (int)(pointFs[1].X - pointFs[0].X);
  586. if (x2 == 0)
  587. x2 = 1;
  588. int y2 = (int)(pointFs[1].Y - pointFs[0].Y);
  589. if (y2 == 0)
  590. y2 = 1;
  591. int i2 = 0;
  592. if (x2 > 0 && y2 > 0) //第4象限
  593. {
  594. i2 = 4;
  595. }
  596. else if (x2 > 0 && y2 < 0) //第1象限
  597. {
  598. i2 = 1;
  599. }
  600. else if (x2 < 0 && y2 < 0) //第2象限
  601. {
  602. i2 = 2;
  603. }
  604. else if (x2 < 0 && y2 > 0) //第3象限
  605. {
  606. i2 = 3;
  607. }
  608. double sAngle1;
  609. double eAngle1;
  610. double sAngle2;
  611. double eAngle2;
  612. if (i2 == 1 || i2 == 2)
  613. {
  614. sAngle1 = 360 - angle;
  615. eAngle1 = 180 - angle;
  616. sAngle2 = 270 - angle;
  617. eAngle2 = 90 - angle;
  618. }
  619. else
  620. {
  621. sAngle1 = angle;
  622. eAngle1 = 180 + angle;
  623. sAngle2 = 270 + angle;
  624. eAngle2 = 90 + angle;
  625. }
  626. graphics.DrawLine(standardPen, pointFs[0], pointFs[1]);
  627. if (!double.IsNaN(sAngle1) && !double.IsNaN(eAngle1) && !double.IsNaN(sAngle2) && !double.IsNaN(eAngle2))
  628. {
  629. PointF assistPoint1 = BasicCalculationHelper.GetAnglePoint(new PointF((pointFs[0].X + lineLength), pointFs[0].Y), pointFs[0], sAngle2);
  630. PointF assistPoint2 = BasicCalculationHelper.GetAnglePoint(new PointF((pointFs[0].X + lineLength), pointFs[0].Y), pointFs[0], eAngle2);
  631. PointF assistPoint3 = BasicCalculationHelper.GetAnglePoint(new PointF((pointFs[1].X + lineLength), pointFs[1].Y), pointFs[1], sAngle2);
  632. PointF assistPoint4 = BasicCalculationHelper.GetAnglePoint(new PointF((pointFs[1].X + lineLength), pointFs[1].Y), pointFs[1], eAngle2);
  633. graphics.DrawLine(surfacePen, assistPoint1, assistPoint2);
  634. graphics.DrawLine(partPen, assistPoint3, assistPoint4);
  635. //PointF[] pf = pointFs;
  636. if (i2 == 1 || i2 == 2)
  637. {
  638. graphics.DrawString(Math.Round((BasicCalculationHelper.GetDistance(pf[1], pf[0], 4) * unitLength),2).ToString(), new Font("宋体", float.Parse(colourFont.Keys.First()), System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))), new SolidBrush(colourFont.Values.First()), assistPoint4.X, assistPoint4.Y - 10);
  639. }
  640. else
  641. {
  642. graphics.DrawString(Math.Round((BasicCalculationHelper.GetDistance(pf[1], pf[0], 4) * unitLength), 2).ToString(), new Font("宋体", float.Parse(colourFont.Keys.First()), System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))), new SolidBrush(colourFont.Values.First()), assistPoint3.X, assistPoint3.Y - 10);
  643. }
  644. }
  645. }
  646. }
  647. if (selected > -1)
  648. {
  649. int tempLess = (int)(InvariantData.rectless * (this.documentWorkspace.ScaleFactor.Ratio < 1 ? 1 / this.documentWorkspace.ScaleFactor.Ratio : 1));
  650. int tempPlus = (int)(InvariantData.rectplus * (this.documentWorkspace.ScaleFactor.Ratio < 1 ? 1 / this.documentWorkspace.ScaleFactor.Ratio : 1));
  651. graphics.DrawRectangle(borderPen, new Rectangle((int)(pointList1[selected][0].X - tempLess), (int)(pointList1[selected][0].Y - tempLess), tempPlus, tempPlus));
  652. graphics.FillRectangle(insideBrush, new RectangleF(pointList1[selected][0].X - tempLess, pointList1[selected][0].Y - tempLess, tempPlus, tempPlus));
  653. graphics.DrawRectangle(borderPen, new Rectangle((int)(pointList1[selected][1].X - tempLess), (int)(pointList1[selected][1].Y - tempLess), tempPlus, tempPlus));
  654. graphics.FillRectangle(insideBrush, new RectangleF(pointList1[selected][1].X - tempLess, pointList1[selected][1].Y - tempLess, tempPlus, tempPlus));
  655. graphics.DrawRectangle(rectPen, rectangleFList[selected].X, rectangleFList[selected].Y, rectangleFList[selected].Width, rectangleFList[selected].Height);
  656. }
  657. }
  658. standardPen.Dispose();
  659. surfacePen.Dispose();
  660. completePen.Dispose();
  661. validPen.Dispose();
  662. partPen.Dispose();
  663. borderPen.Dispose();
  664. insideBrush.Dispose();
  665. rectPen.Dispose();
  666. }
  667. //最长直径
  668. double MaxM = 0;
  669. double MinM = 0;
  670. double MeanM = 0;
  671. private void bindGrid(List<List<int>> dataList)
  672. {
  673. if (dataList.Count < 1)
  674. {
  675. return;
  676. }
  677. chart1.Visible = true;
  678. List<int> CircleDate = dataList[0];
  679. //标尺 微米/像素
  680. double d = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetRuler(MeasurementUnit.Micron);
  681. dataGridView1.Rows.Clear();
  682. dataGridView2.Rows.Clear();
  683. chart1.Series.Clear();
  684. chart1.ChartAreas.Clear();
  685. List<Color> colorList = new List<Color>() { Color.FromArgb(255, 0, 0), Color.FromArgb(0, 255, 0), Color.FromArgb(139, 0, 0), Color.FromArgb(128, 0, 128), Color.FromArgb(122, 160, 255) };
  686. List<double> diameterPI = new List<double>() { };
  687. List<double> diameter = new List<double>(){ };
  688. List<double> diameterMax = new List<double>() { };
  689. List<double> diameterD = new List<double>() { };
  690. for (int i = 0; i < dataList.Count; i++)
  691. {
  692. int newPo = dataGridView1.Rows.Add();
  693. //序号
  694. dataGridView1.Rows[newPo].Cells[0].Value = (newPo + 1).ToString();
  695. //XY
  696. dataGridView1.Rows[newPo].Cells[1].Value ="X:"+ dataList[i][0].ToString()+",Y:"+ dataList[i][1].ToString();
  697. //直径
  698. double w = Convert.ToDouble(dataList[i][6]);
  699. double h = Convert.ToDouble(dataList[i][7]) ;
  700. double dd = (w + h)*0.5 * d;
  701. double area= Convert.ToDouble(dataList[i][4]) * d*d;
  702. double r = Math.Sqrt(area / Math.PI) * 2;
  703. diameterPI.Add(r);
  704. diameter.Add(dd);
  705. double maxD = w > h ? w : h;
  706. double minD = w < h ? w : h;
  707. diameterMax.Add(maxD * d);
  708. double circle= Convert.ToDouble(dataList[i][8])*0.001;
  709. dataGridView1.Rows[newPo].Cells[2].Value= Math.Round(dd, 2).ToString();
  710. dataGridView1.Rows[newPo].Cells[3].Value = dataList[i][5];
  711. dataGridView1.Rows[newPo].Cells[4].Value = Math.Round(maxD * d, 2).ToString();
  712. dataGridView1.Rows[newPo].Cells[5].Value = Math.Round(minD * d, 2).ToString();
  713. dataGridView1.Rows[newPo].Cells[6].Value = Math.Round(r, 2).ToString();
  714. double afe= Convert.ToDouble(dataList[i][8])*0.0001;
  715. dataGridView1.Rows[newPo].Cells[7].Value = Math.Round(afe, 3).ToString();
  716. diameterD.Add(Math.Round(afe, 3));
  717. }
  718. diameterMax.Sort();
  719. MinM = diameterMax[0];
  720. MaxM = diameterMax[diameterMax.Count - 1];
  721. foreach (var item in diameterMax)
  722. {
  723. MeanM += Math.Round(item, 1);
  724. }
  725. MeanM = MeanM / diameterMax.Count;
  726. DataTable dt = new DataTable();
  727. dt = CreatTable(diameter, diameterPI);
  728. CreatChart(dt);
  729. diameter.Sort();
  730. double total = 0;
  731. foreach (var item in diameter)
  732. {
  733. total += item;
  734. }
  735. total = total / diameter.Count;
  736. double advR = diameterPI.Average();
  737. int ind = 1;
  738. int newRow = dataGridView2.Rows.Add();
  739. dataGridView2.Rows[newRow].Cells[0].Value = (ind++).ToString();
  740. dataGridView2.Rows[newRow].Cells[1].Value = "平均值";
  741. dataGridView2.Rows[newRow].Cells[2].Value = Math.Round(total, 2).ToString();
  742. int newRow1 = dataGridView2.Rows.Add();
  743. dataGridView2.Rows[newRow1].Cells[0].Value = (ind++).ToString();
  744. dataGridView2.Rows[newRow1].Cells[1].Value = "最大值";
  745. dataGridView2.Rows[newRow1].Cells[2].Value = Math.Round(diameter[diameter.Count-1], 2).ToString();
  746. int newRow2 = dataGridView2.Rows.Add();
  747. dataGridView2.Rows[newRow2].Cells[0].Value = (ind++).ToString();
  748. dataGridView2.Rows[newRow2].Cells[1].Value = "最小值";
  749. dataGridView2.Rows[newRow2].Cells[2].Value = Math.Round(diameter[0], 2).ToString();
  750. int newRow7 = dataGridView2.Rows.Add();
  751. dataGridView2.Rows[newRow7].Cells[0].Value = (ind++).ToString();
  752. dataGridView2.Rows[newRow7].Cells[1].Value = "拟圆半径";
  753. dataGridView2.Rows[newRow7].Cells[2].Value = Math.Round(advR, 2).ToString();
  754. int newRow8 = dataGridView2.Rows.Add();
  755. dataGridView2.Rows[newRow8].Cells[0].Value = (ind++).ToString();
  756. dataGridView2.Rows[newRow8].Cells[1].Value = "平均圆度";
  757. dataGridView2.Rows[newRow8].Cells[2].Value = Math.Round(diameterD.Average(), 3).ToString();
  758. int count = diameter.Count;
  759. int d5 = Convert.ToInt32(count * 0.05);
  760. int d10 = Convert.ToInt32(count * 0.1);
  761. int d50 = Convert.ToInt32(count * 0.5);
  762. int d90 = Convert.ToInt32(count * 0.9);
  763. int d95 = Convert.ToInt32(count * 0.95);
  764. int newRow25 = dataGridView2.Rows.Add();
  765. dataGridView2.Rows[newRow25].Cells[0].Value = (ind++).ToString();
  766. dataGridView2.Rows[newRow25].Cells[1].Value = "D5";
  767. dataGridView2.Rows[newRow25].Cells[2].Value = Math.Round(diameter[d5], 2).ToString();
  768. int newRow3 = dataGridView2.Rows.Add();
  769. dataGridView2.Rows[newRow3].Cells[0].Value = (ind++).ToString();
  770. dataGridView2.Rows[newRow3].Cells[1].Value = "D10";
  771. dataGridView2.Rows[newRow3].Cells[2].Value = Math.Round(diameter[d10], 2).ToString();
  772. int newRow4 = dataGridView2.Rows.Add();
  773. dataGridView2.Rows[newRow4].Cells[0].Value = (ind++).ToString();
  774. dataGridView2.Rows[newRow4].Cells[1].Value = "D50";
  775. dataGridView2.Rows[newRow4].Cells[2].Value = Math.Round(diameter[d50], 2).ToString();
  776. int newRow5 = dataGridView2.Rows.Add();
  777. dataGridView2.Rows[newRow5].Cells[0].Value = (ind++).ToString();
  778. dataGridView2.Rows[newRow5].Cells[1].Value = "D90";
  779. dataGridView2.Rows[newRow5].Cells[2].Value = Math.Round(diameter[d90], 2).ToString();
  780. int newRow6 = dataGridView2.Rows.Add();
  781. dataGridView2.Rows[newRow6].Cells[0].Value = (ind++).ToString();
  782. dataGridView2.Rows[newRow6].Cells[1].Value = "D95";
  783. dataGridView2.Rows[newRow6].Cells[2].Value = Math.Round(diameter[d95], 2).ToString();
  784. }
  785. /// <summary>
  786. /// 准备用来处理单个颗粒的选中事件
  787. /// </summary>
  788. /// <param name="sender"></param>
  789. /// <param name="e"></param>
  790. private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
  791. {
  792. //当点击表头部的列时,e.RowIndex==-1
  793. if (e.RowIndex > -1)
  794. {
  795. string selectrow = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
  796. int x = Convert.ToInt32(selectrow);
  797. binaryClass.DrwCrystalSelected(x);
  798. this.documentWorkspace.Refresh();
  799. }
  800. }
  801. //外接矩形
  802. double MaxP = 0;
  803. double Minp = 0;
  804. double MeanP = 0;
  805. //拟圆直径
  806. double MaxP2 = 0;
  807. double Minp2 = 0;
  808. double MeanP2 = 0;
  809. private DataTable CreatTable(List<double> diameter, List<double> diameterPI)
  810. {
  811. diameter.Sort();
  812. double max = diameter[diameter.Count - 1];
  813. double total = max*2;
  814. double min = 0;
  815. Minp = diameter[0];
  816. MaxP= diameter[diameter.Count - 1];
  817. diameterPI.Sort();
  818. Minp2 = diameterPI[0];
  819. MaxP2 = diameterPI[diameterPI.Count - 1];
  820. foreach (var item in diameter)
  821. {
  822. MeanP += Math.Round(item, 2) ;
  823. }
  824. foreach (var item in diameterPI)
  825. {
  826. MeanP2 += Math.Round(item, 2);
  827. }
  828. MeanP = MeanP / diameter.Count;
  829. MeanP2 = MeanP2 / diameterPI.Count;
  830. //int eval =Convert.ToInt32( (max - min) / 20);
  831. //double eval =0.2;
  832. double eval = max / 15;
  833. List<double[]> vs = new List<double[]>();
  834. double rightmax = 0;
  835. for (int i = 0; eval * i < max; i++)
  836. {
  837. vs.Add(new double[] { eval*i, eval*(i+1) });
  838. rightmax = eval * (i + 1);
  839. }
  840. DataTable dt = new DataTable();
  841. dt.Columns.Add("diameter");
  842. dt.Columns.Add("sum");
  843. dt.Columns.Add("sum1");
  844. for (int i = 0; i < vs.Count; i++)
  845. {
  846. DataRow dr;
  847. dr = dt.NewRow();
  848. double low = Math.Round(eval * i, 2);
  849. double hight = Math.Round(eval * (i + 1), 2) ;
  850. dr["diameter"] =string.Format("{0}", hight) ;
  851. var emp = diameter.FindAll(e => e > low && e <= hight);
  852. dr["sum"] = emp.Count;
  853. var emp1 = diameterPI.FindAll(e => e > low && e <= hight);
  854. dr["sum1"] = emp1.Count;
  855. dt.Rows.Add(dr);
  856. }
  857. return dt;
  858. }
  859. private void CreatChart(DataTable dt)
  860. {
  861. if (dt == null || dt.Rows.Count == 0)
  862. {
  863. return;
  864. }
  865. chart1.Series.Clear();
  866. chart1.ChartAreas.Clear();
  867. chart1.Legends.Clear();
  868. //定义一个chart
  869. System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
  870. //定义一个绘图区域
  871. System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
  872. System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
  873. //定义一个绘图区域
  874. System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series();
  875. chartArea1.Name = "ChartArea1";
  876. chart1.Series.Add(series1);
  877. //chart1.Series.Add(series2);
  878. chart1.ChartAreas.Add(chartArea1);
  879. chart1.Legends.Add(legend1);
  880. series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline;
  881. chart1.Series[0].LegendText = "";
  882. chart1.Series[0].Label = "#VALY";
  883. chart1.Series[0].LabelBackColor = Color.Transparent;
  884. chart1.Series[0].ToolTip = "#VALY";
  885. chart1.Series[0]["PointWidth"] = "0.5";
  886. chart1.Series[0].XValueMember = "diameter";
  887. chart1.Series[0].YValueMembers = "sum";
  888. chart1.Series[0].LegendText = "卡规直径";
  889. //chart1.Series[1].LegendText = "";
  890. //chart1.Series[1].Label = "#VALY";
  891. //chart1.Series[1].LabelBackColor = Color.Transparent;
  892. //chart1.Series[1].ToolTip = "#VALY";
  893. //chart1.Series[1]["PointWidth"] = "0.5";
  894. //chart1.Series[1].XValueMember = "diameter";
  895. //chart1.Series[1].YValueMembers = "sum1";
  896. //chart1.Series[1].LegendText = "拟圆直径";
  897. chart1.ChartAreas[0].AxisX.Interval = 1;
  898. chart1.ChartAreas[0].AxisX.Title = "尺寸(μm)";
  899. chart1.ChartAreas[0].Axes[0].MajorGrid.Enabled = false; //X轴上网格
  900. chart1.ChartAreas[0].Axes[1].MajorGrid.Enabled = false; //y轴上网格
  901. series1.Color = Color.DarkSeaGreen;
  902. series2.Color = Color.PaleTurquoise;
  903. chart1.DataSource = dt;
  904. chart1.DataBind();
  905. }
  906. #region 手动干预
  907. /// <summary>
  908. /// 修改轮廓
  909. /// </summary>
  910. /// <param name="sender"></param>
  911. /// <param name="e"></param>
  912. private void btnLunkuo_Click(object sender, EventArgs e)
  913. {
  914. isLunKuo = true;
  915. isAddKong = false;
  916. isDelKong = false;
  917. operationK = -1;
  918. }
  919. /// <summary>
  920. /// 添加孔隙
  921. /// </summary>
  922. /// <param name="sender"></param>
  923. /// <param name="e"></param>
  924. private void btnAddKong_Click(object sender, EventArgs e)
  925. {
  926. isLunKuo = false;
  927. isAddKong = true;
  928. isDelKong = false;
  929. operationK = -1;
  930. }
  931. /// <summary>
  932. /// 删除孔隙
  933. /// </summary>
  934. /// <param name="sender"></param>
  935. /// <param name="e"></param>
  936. private void btnDelKong_Click(object sender, EventArgs e)
  937. {
  938. isLunKuo = false;
  939. isAddKong = false;
  940. isDelKong = true;
  941. operationK = -1;
  942. }
  943. /// <summary>
  944. /// 重新统计
  945. /// </summary>
  946. /// <param name="sender"></param>
  947. /// <param name="e"></param>
  948. private void btnReDrw_Click(object sender, EventArgs e)
  949. {
  950. double minpoint = Convert.ToDouble(numericUpDown11.Value);
  951. if (!ckMin.Checked)
  952. minpoint = 0.01;
  953. binaryClass.pointsize =minpoint;
  954. int border = Convert.ToInt32(numericMax.Value);
  955. if (!ckMax.Checked)
  956. border = 0;
  957. binaryClass.border = border;
  958. double HW = Convert.ToDouble(numericHW.Value);
  959. if (!ckHW.Checked)
  960. HW = 100;
  961. binaryClass.HW = HW;
  962. double AreaRatio = Convert.ToDouble(numericArea.Value);
  963. if (!ckArea.Checked)
  964. AreaRatio = 0.01;
  965. binaryClass.AreaRatio = AreaRatio;
  966. List<List<int>> CircleDate = binaryClass.ForgetCrystal(minpoint);
  967. bindGrid(CircleDate);
  968. }
  969. /// <summary>
  970. /// 计算外接矩形
  971. /// </summary>
  972. private RectangleF CalcOtherRectangle(PointF p1, PointF p2)
  973. {
  974. RectangleF rectangleF = new RectangleF();
  975. if (p1.X > p2.X)
  976. rectangleF.X = p2.X;
  977. else
  978. rectangleF.X = p1.X;
  979. if (p1.Y > p2.Y)
  980. rectangleF.Y = p2.Y;
  981. else
  982. rectangleF.Y = p1.Y;
  983. rectangleF.Width = Math.Abs(p2.X - p1.X);
  984. rectangleF.Height = Math.Abs(p2.Y - p1.Y);
  985. int tempLess = (int)(InvariantData.rectless * (this.documentWorkspace.ScaleFactor.Ratio < 1 ? 1 / this.documentWorkspace.ScaleFactor.Ratio : 1)) * 5;
  986. int tempPlus = (int)(InvariantData.rectplus * (this.documentWorkspace.ScaleFactor.Ratio < 1 ? 1 / this.documentWorkspace.ScaleFactor.Ratio : 1)) * 5;
  987. return new RectangleF(rectangleF.X - tempLess, rectangleF.Y - tempLess, rectangleF.Width + tempPlus, rectangleF.Height + tempPlus);
  988. }
  989. /// <summary>
  990. /// 移动
  991. /// </summary>
  992. /// <param name="sender"></param>
  993. /// <param name="e"></param>
  994. private void onMouseMove(object sender, MouseEventArgs e)
  995. {
  996. //if (e.Button == MouseButtons.Left)
  997. //{
  998. if (isLunKuo)
  999. {
  1000. int cou = pointList.Count;
  1001. if (cou > 0)
  1002. { // 换算后的点
  1003. PointF movePoint = this.documentWorkspace.GetScalePoint(e.Location);
  1004. pointList[cou - 1] = movePoint;
  1005. }
  1006. }
  1007. if (isAddKong && e.Button == MouseButtons.Left)
  1008. {
  1009. if (kongLineList.Count > 0)
  1010. { // 换算后的点
  1011. PointF movePoint = this.documentWorkspace.GetScalePoint(e.Location);
  1012. //kongPointList[kongPointList.Count - 1] = movePoint;
  1013. kongLineList[kongLineList.Count - 1].Add(movePoint);
  1014. }
  1015. }
  1016. if (isDelKong)
  1017. {
  1018. //if (delPointList.Count > 0)
  1019. //{ // 换算后的点
  1020. // PointF movePoint = this.documentWorkspace.GetScalePoint(e.Location);
  1021. // delPointList[delPointList.Count - 1] = movePoint;
  1022. //}
  1023. }
  1024. if (operationK >= 0 && e.Button == MouseButtons.Left)
  1025. {
  1026. PointF movePoint = this.documentWorkspace.GetScalePoint(e.Location);
  1027. if (operationK == 0)
  1028. {
  1029. this.endPoint = movePoint;
  1030. pointList1[lineCount][1] = endPoint;
  1031. }
  1032. else if (operationK == 1 && selected > -1 && canMove)
  1033. {
  1034. float dx = movePoint.X - lastPoint.X;
  1035. float dy = movePoint.Y - lastPoint.Y;
  1036. float dxTemp = movePoint.X - tempPoint.X;
  1037. float dyTemp = movePoint.Y - tempPoint.Y;
  1038. lastPoint.X = movePoint.X;
  1039. lastPoint.Y = movePoint.Y;
  1040. if (movePointIndex == -1)
  1041. {
  1042. RectangleF rectangleF = new RectangleF();
  1043. rectangleF = rectangleFList[selected];
  1044. if (rectangleF.Contains(movePoint))
  1045. this.documentWorkspace.panel.Cursor = Cursors.SizeAll;
  1046. rectangleF.X += dx;
  1047. rectangleF.Y += dy;
  1048. rectangleFList[selected] = rectangleF;
  1049. for (int i = 0; i < pointList1[selected].Count(); i++)
  1050. {
  1051. if (pointList1[selected][i] == PointF.Empty)
  1052. continue;
  1053. pointList1[selected][i].X += dx;
  1054. pointList1[selected][i].Y += dy;
  1055. }
  1056. }
  1057. else if (movePointIndex == 0)
  1058. {
  1059. pointList1[selected][0].X += dx;
  1060. pointList1[selected][0].Y += dy;
  1061. rectangleFList[selected] = CalcOtherRectangle(pointList1[selected][0], pointList1[selected][1]);
  1062. }
  1063. else if (movePointIndex == 1)
  1064. {
  1065. pointList1[selected][1].X += dx;
  1066. pointList1[selected][1].Y += dy;
  1067. rectangleFList[selected] = CalcOtherRectangle(pointList1[selected][0], pointList1[selected][1]);
  1068. }
  1069. }
  1070. this.documentWorkspace.Refresh();
  1071. }
  1072. this.documentWorkspace.Refresh();
  1073. // }
  1074. }
  1075. /// <summary>
  1076. /// 鼠标抬起
  1077. /// </summary>
  1078. /// <param name="sender"></param>
  1079. /// <param name="e"></param>
  1080. private void OnMouseUp(object sender, MouseEventArgs e)
  1081. {
  1082. if (e.Button == MouseButtons.Left)
  1083. {
  1084. if (operationK == 0)
  1085. {
  1086. if (startPoint != null && endPoint != null && startPoint != endPoint)
  1087. {
  1088. RectangleF rectangleF = CalcOtherRectangle(pointList1[lineCount][0], pointList1[lineCount][1]);
  1089. rectangleFList.Add(rectangleF);
  1090. lineCount++;
  1091. // AddContentToDataGridView();
  1092. }
  1093. else
  1094. {
  1095. if (pointList1.Count > 0)
  1096. {
  1097. pointList1.RemoveAt(pointList1.Count - 1);
  1098. this.documentWorkspace.Refresh();
  1099. return;
  1100. }
  1101. }
  1102. this.documentWorkspace.Refresh();
  1103. }
  1104. else if (operationK == 1)
  1105. {
  1106. canMove = false;
  1107. movePointIndex = -1;
  1108. // RefreshDataGridView1();
  1109. }
  1110. else if (isAddKong)
  1111. {
  1112. if (kongLineList[kongLineList.Count - 1].Count > 3)
  1113. {
  1114. isAddKong = false;
  1115. List<List<int>> CircleDate = binaryClass.DeleteCrystal(delPointList, kongLineList);
  1116. bindGrid(CircleDate);
  1117. }
  1118. else
  1119. {
  1120. kongLineList.RemoveAt(kongLineList.Count - 1);
  1121. }
  1122. }
  1123. }
  1124. if (operationK >= 0 && e.Button == MouseButtons.Left)
  1125. {
  1126. PointF downPoint = this.documentWorkspace.GetScalePoint(e.Location);
  1127. if (operationK == 0)
  1128. {
  1129. pointList1[lineCount - 1][1] = downPoint;
  1130. }
  1131. else if (operationK == 1)
  1132. {
  1133. lastPoint.X = downPoint.X;
  1134. lastPoint.Y = downPoint.Y;
  1135. tempPoint.X = downPoint.X;
  1136. tempPoint.Y = downPoint.Y;
  1137. for (int i = rectangleFList.Count - 1; i >= 0; i--)
  1138. {
  1139. if (rectangleFList[i].Contains(downPoint))
  1140. {
  1141. selected = i;
  1142. canMove = true;
  1143. }
  1144. }
  1145. if (selected > -1 && pointList1 != null && pointList1.Count > 0)
  1146. {
  1147. int tempLess = (int)(InvariantData.rectless * (this.documentWorkspace.ScaleFactor.Ratio < 1 ? 1 / this.documentWorkspace.ScaleFactor.Ratio : 1)) * 5;
  1148. int tempPlus = (int)(InvariantData.rectplus * (this.documentWorkspace.ScaleFactor.Ratio < 1 ? 1 / this.documentWorkspace.ScaleFactor.Ratio : 1)) * 5;
  1149. if (new RectangleF(pointList1[selected][0].X - tempLess, pointList1[selected][0].Y - tempLess, tempPlus, tempPlus).Contains(downPoint))
  1150. movePointIndex = 0;
  1151. else if (new RectangleF(pointList1[selected][1].X - tempLess, pointList1[selected][1].Y - tempLess, tempPlus, tempPlus).Contains(downPoint))
  1152. movePointIndex = 1;
  1153. else
  1154. movePointIndex = -1;
  1155. this.documentWorkspace.Refresh();
  1156. }
  1157. if (canMove)
  1158. return;
  1159. selected = -1;
  1160. }
  1161. }
  1162. }
  1163. /// <summary>
  1164. /// 鼠标按下
  1165. /// </summary>
  1166. /// <param name="drawArea"></param>
  1167. /// <param name="e"></param>
  1168. private void OnMouseDown(object sender, MouseEventArgs e)
  1169. {
  1170. PointF downPoint = this.documentWorkspace.GetScalePoint(e.Location);
  1171. if (operationK >= 0 && e.Button == MouseButtons.Left)
  1172. {
  1173. if (operationK == 0)
  1174. {
  1175. startPoint = endPoint = downPoint;
  1176. nowLine = new PointF[4];
  1177. nowLine[0] = startPoint;
  1178. nowLine[1] = endPoint;
  1179. pointList1.Add(nowLine);
  1180. }
  1181. else if (operationK == 1)
  1182. {
  1183. lastPoint.X = downPoint.X;
  1184. lastPoint.Y = downPoint.Y;
  1185. tempPoint.X = downPoint.X;
  1186. tempPoint.Y = downPoint.Y;
  1187. for (int i = rectangleFList.Count - 1; i >= 0; i--)
  1188. {
  1189. if (rectangleFList[i].Contains(downPoint))
  1190. {
  1191. selected = i;
  1192. canMove = true;
  1193. }
  1194. }
  1195. if (selected > -1 && pointList1 != null && pointList1.Count > 0)
  1196. {
  1197. int tempLess = (int)(InvariantData.rectless * (this.documentWorkspace.ScaleFactor.Ratio < 1 ? 1 / this.documentWorkspace.ScaleFactor.Ratio : 1)) * 5;
  1198. int tempPlus = (int)(InvariantData.rectplus * (this.documentWorkspace.ScaleFactor.Ratio < 1 ? 1 / this.documentWorkspace.ScaleFactor.Ratio : 1)) * 5;
  1199. if (new RectangleF(pointList1[selected][0].X - tempLess, pointList1[selected][0].Y - tempLess, tempPlus, tempPlus).Contains(downPoint))
  1200. movePointIndex = 0;
  1201. else if (new RectangleF(pointList1[selected][1].X - tempLess, pointList1[selected][1].Y - tempLess, tempPlus, tempPlus).Contains(downPoint))
  1202. movePointIndex = 1;
  1203. else
  1204. movePointIndex = -1;
  1205. this.documentWorkspace.Refresh();
  1206. }
  1207. if (canMove)
  1208. return;
  1209. selected = -1;
  1210. }
  1211. }
  1212. else if (e.Button == MouseButtons.Left)
  1213. {
  1214. if (isLunKuo)
  1215. {
  1216. if (pointList.Count == 0)
  1217. {
  1218. pointList.Add(downPoint);
  1219. pointList.Add(downPoint);
  1220. }
  1221. else
  1222. {
  1223. pointList.Add(downPoint);
  1224. }
  1225. }
  1226. if (isAddKong)
  1227. {
  1228. List<PointF> pl = new List<PointF>();
  1229. pl.Add(downPoint);
  1230. kongLineList.Add(pl);
  1231. //if (kongPointList.Count == 0)
  1232. //{
  1233. // kongPointList.Add(downPoint);
  1234. // kongPointList.Add(downPoint);
  1235. //}
  1236. //else
  1237. //{
  1238. // kongPointList.Add(downPoint);
  1239. //}
  1240. }
  1241. if (isDelKong)
  1242. {
  1243. delPointList.Add(downPoint);
  1244. List<List<int>> CircleDate = binaryClass.DeleteCrystal( delPointList, kongLineList);
  1245. bindGrid(CircleDate);
  1246. }
  1247. }
  1248. if (e.Button == MouseButtons.Right)
  1249. {
  1250. if (isLunKuo)
  1251. {
  1252. if (pointList.Count > 2)
  1253. {
  1254. pointList.RemoveAt(pointList.Count - 1);
  1255. List<PointF> pointFs = new List<PointF>(pointList.ToArray());
  1256. lineList.Add(pointFs);
  1257. }
  1258. pointList.Clear();
  1259. }
  1260. if (isAddKong)
  1261. {
  1262. if (kongPointList.Count > 2)
  1263. {
  1264. kongPointList.RemoveAt(kongPointList.Count - 1);
  1265. List<PointF> pointFs = new List<PointF>(kongPointList.ToArray());
  1266. kongLineList.Add(pointFs);
  1267. List<List<int>> CircleDate = binaryClass.DeleteCrystal(delPointList, kongLineList);
  1268. bindGrid(CircleDate);
  1269. }
  1270. kongPointList.Clear();
  1271. }
  1272. if (isDelKong)
  1273. {
  1274. //if (delPointList.Count > 2)
  1275. //{
  1276. // delPointList.RemoveAt(delPointList.Count - 1);
  1277. // List<PointF> pointFs = new List<PointF>(delPointList.ToArray());
  1278. // delLineList.Add(pointFs);
  1279. //}
  1280. //delPointList.Clear();
  1281. }
  1282. isLunKuo = false;
  1283. isAddKong = false;
  1284. isDelKong = false;
  1285. }
  1286. }
  1287. /// <summary>
  1288. /// Ctrl+z
  1289. /// </summary>
  1290. private void OnKeyDown(object sender, KeyEventArgs e)
  1291. {
  1292. if (e.Control && e.KeyCode == Keys.Z)
  1293. {
  1294. if (isLunKuo)
  1295. {
  1296. int cou = pointList.Count;
  1297. if (cou > 1)
  1298. {
  1299. if (cou == 2)
  1300. {
  1301. pointList.Clear();
  1302. }
  1303. else
  1304. {
  1305. pointList.RemoveAt(cou - 1);
  1306. }
  1307. }
  1308. else if (lineList.Count > 0)
  1309. {
  1310. pointList = lineList[lineList.Count - 1];
  1311. lineList.RemoveAt(lineList.Count - 1);
  1312. pointList.RemoveAt(pointList.Count - 1);
  1313. }
  1314. }
  1315. if (isAddKong)
  1316. {
  1317. if (kongLineList.Count > 0)
  1318. {
  1319. kongLineList.RemoveAt(kongLineList.Count - 1);
  1320. List<List<int>> CircleDate = binaryClass.DeleteCrystal(delPointList, kongLineList);
  1321. bindGrid(CircleDate);
  1322. }
  1323. }
  1324. if (isDelKong)
  1325. {
  1326. int cou = delPointList.Count;
  1327. if (cou > 0)
  1328. {
  1329. delPointList.RemoveAt(cou - 1);
  1330. List<List<int>> CircleDate = binaryClass.DeleteCrystal(delPointList, kongLineList);
  1331. bindGrid(CircleDate);
  1332. }
  1333. }
  1334. this.documentWorkspace.Refresh();
  1335. }
  1336. }
  1337. #endregion
  1338. /// <summary>
  1339. /// 导出孔隙信息
  1340. /// </summary>
  1341. /// <param name="sender"></param>
  1342. /// <param name="e"></param>
  1343. private void button14_Click(object sender, EventArgs e)
  1344. {
  1345. SaveFileDialog exe = new SaveFileDialog();
  1346. exe.Filter = "Image Files (*.jpg)|*.jpg";
  1347. exe.FilterIndex = 0;
  1348. exe.RestoreDirectory = true;
  1349. //exe.CreatePrompt = true;
  1350. exe.Title = "Image Files";
  1351. exe.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  1352. exe.FileName = DateTime.Now.ToString("yyyyMMddhhmmss") + "单晶";
  1353. DialogResult dr = exe.ShowDialog();
  1354. if (dr != DialogResult.OK)
  1355. {
  1356. return;
  1357. }
  1358. string GR_Path = exe.FileName + ".jpg";
  1359. chart1.SaveImage(GR_Path, System.Windows.Forms.DataVisualization.Charting.ChartImageFormat.Jpeg);
  1360. }
  1361. /// <summary>
  1362. /// 不可点击空白区域
  1363. /// </summary>
  1364. /// <param name="sender"></param>
  1365. /// <param name="e"></param>
  1366. private void listView1_MouseUp(object sender, MouseEventArgs e)
  1367. {
  1368. if (e.Button == MouseButtons.Left)
  1369. {
  1370. if (listView1.SelectedItems.Count > 0)
  1371. {
  1372. }
  1373. else if (listView1.SelectedItems.Count <= 0)//点击空白区
  1374. {
  1375. if (this.listView1.FocusedItem != null)
  1376. {
  1377. ListViewItem item = this.listView1.GetItemAt(e.X, e.Y);
  1378. if (item == null)
  1379. {
  1380. this.listView1.FocusedItem.Selected = true;
  1381. }
  1382. }
  1383. }
  1384. }
  1385. }
  1386. /// <summary>
  1387. /// 生成孔隙率
  1388. /// </summary>
  1389. /// <param name="sender"></param>
  1390. /// <param name="e"></param>
  1391. private void button13_Click(object sender, EventArgs e)
  1392. {
  1393. string name = this.listView1.FocusedItem.Name.Split('.')[0] + "-";
  1394. SaveFileDialog exe = new SaveFileDialog();
  1395. exe.Filter = "Execl files (*.xlsx)|*.xlsx";
  1396. exe.FilterIndex = 0;
  1397. exe.RestoreDirectory = true;
  1398. //exe.CreatePrompt = true;
  1399. exe.Title = "Export Excel File";
  1400. // exe.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  1401. exe.FileName = name;
  1402. String str = System.Configuration.ConfigurationManager.AppSettings["FolderSelectedPath"];
  1403. DialogResult dr = exe.ShowDialog();
  1404. if (dr != DialogResult.OK)
  1405. {
  1406. return;
  1407. }
  1408. DataTable dtb = new DataTable();
  1409. dtb.Columns.Add("序号");
  1410. dtb.Columns.Add("位置");
  1411. dtb.Columns.Add("卡规直径/微米");
  1412. dtb.Columns.Add("长径/微米");
  1413. dtb.Columns.Add("短径/微米");
  1414. dtb.Columns.Add("拟圆直径/微米");
  1415. dtb.Columns.Add("圆度");
  1416. for (int r = 0; r < this.dataGridView1.Rows.Count; r++)
  1417. {
  1418. DataRow dataRow = dtb.NewRow();
  1419. dataRow[0] = dataGridView1.Rows[r].Cells[0].Value.ToString();
  1420. dataRow[1] = dataGridView1.Rows[r].Cells[1].Value.ToString();
  1421. dataRow[2] = dataGridView1.Rows[r].Cells[2].Value.ToString();
  1422. dataRow[3] = dataGridView1.Rows[r].Cells[4].Value.ToString();
  1423. dataRow[4] = dataGridView1.Rows[r].Cells[5].Value.ToString();
  1424. dataRow[5] = dataGridView1.Rows[r].Cells[6].Value.ToString();
  1425. dataRow[6] = dataGridView1.Rows[r].Cells[7].Value.ToString();
  1426. dtb.Rows.Add(dataRow);
  1427. }
  1428. DataTable dtb1 = new DataTable();
  1429. dtb1.Columns.Add("序号");
  1430. dtb1.Columns.Add("名称");
  1431. dtb1.Columns.Add("值/微米");
  1432. for (int r = 0; r < this.dataGridView2.Rows.Count; r++)
  1433. {
  1434. DataRow dataRow = dtb1.NewRow();
  1435. dataRow[0] = dataGridView2.Rows[r].Cells[0].Value.ToString();
  1436. dataRow[1] = dataGridView2.Rows[r].Cells[1].Value.ToString();
  1437. dataRow[2] = dataGridView2.Rows[r].Cells[2].Value.ToString();
  1438. dtb1.Rows.Add(dataRow);
  1439. }
  1440. int index = exe.FileName.LastIndexOf('\\');
  1441. string GR_Path = exe.FileName.Remove(index)+"\\"+ name + ".jpg";
  1442. chart1.SaveImage(GR_Path, System.Windows.Forms.DataVisualization.Charting.ChartImageFormat.Jpeg);
  1443. //保存处理后的图片
  1444. double pantographRatio = (double)this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetRulerMultiple(MeasurementUnit.Micron);//标尺*放大倍数
  1445. List<Bitmap> tempBit = new List<Bitmap>();
  1446. Bitmap originalBit = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap();
  1447. originalBit.Tag = pantographRatio;
  1448. tempBit.Add(originalBit);
  1449. Bitmap processedBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.documentWorkspace.PhaseModels[0].mat);
  1450. Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  1451. Graphics graphics = Graphics.FromImage(newBit);
  1452. graphics.DrawImage(processedBit, new PointF(0, 0));
  1453. Draw(graphics);
  1454. newBit.Tag = pantographRatio;
  1455. tempBit.Add(newBit);
  1456. string GR_Path1 = exe.FileName.Remove(index) + "\\" + name + "1.jpg";
  1457. newBit.Save(GR_Path1);
  1458. List<DataTable> list = new List<DataTable>();
  1459. list.Add(dtb1);
  1460. list.Add(dtb);
  1461. List<string> pics = new List<string>() { GR_Path + ",400,200," + chart1.Width + "," + chart1.Height, GR_Path1 + ",400,420," + newBit.Width + "," + newBit.Height };
  1462. this.appWorkspace.ExportDataToExcelWithProgress(list, exe.FileName, true, false, true, null, null,pics);
  1463. }
  1464. #region 辅助测量
  1465. /// <summary>
  1466. /// 添加测量线
  1467. /// </summary>
  1468. /// <param name="sender"></param>
  1469. /// <param name="e"></param>
  1470. private void btnAddCeliang_Click(object sender, EventArgs e)
  1471. {
  1472. operationK = 0;
  1473. selected = -1;
  1474. this.documentWorkspace.Refresh();
  1475. }
  1476. /// <summary>
  1477. /// 选择测量线
  1478. /// </summary>
  1479. /// <param name="sender"></param>
  1480. /// <param name="e"></param>
  1481. private void btnSelCeliang_Click(object sender, EventArgs e)
  1482. {
  1483. operationK = 1;
  1484. }
  1485. /// <summary>
  1486. /// 删除测量线
  1487. /// </summary>
  1488. /// <param name="sender"></param>
  1489. /// <param name="e"></param>
  1490. private void btnDelCeliang_Click(object sender, EventArgs e)
  1491. {
  1492. if (selected > -1)
  1493. {
  1494. DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Areyousuretodmeasurementline.text") + "?", PdnResources.GetString("Menu.alert.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
  1495. if (dr == DialogResult.OK)
  1496. {
  1497. this.pointList1.Remove(this.pointList1[selected]);
  1498. this.rectangleFList.Remove(this.rectangleFList[selected]);
  1499. selected = -1;
  1500. lineCount--;
  1501. this.documentWorkspace.Refresh();
  1502. }
  1503. }
  1504. else
  1505. MessageBox.Show("请先选择测量线");
  1506. }
  1507. /// <summary>
  1508. /// 添加测量线按钮失去焦点
  1509. /// </summary>
  1510. /// <param name="sender"></param>
  1511. /// <param name="e"></param>
  1512. private void btnAddCeliang_LostFocus(object sender, EventArgs e)
  1513. {
  1514. operationK = -1;
  1515. selected = -1;
  1516. this.documentWorkspace.Refresh();
  1517. }
  1518. #endregion
  1519. #region 内部类
  1520. internal class LocalListViewItem
  1521. {
  1522. public DocumentWorkspace Value { get; }
  1523. public string Display { get; }
  1524. public LocalListViewItem(DocumentWorkspace Value, string Display)
  1525. {
  1526. this.Value = Value;
  1527. this.Display = Display;
  1528. }
  1529. }
  1530. internal class DocumentItem
  1531. {
  1532. public Bitmap bitmap;
  1533. public GraphicsList graphicsList;
  1534. public List<PhaseModel> phaseModels;
  1535. //public AnalysisResult analysisResult;
  1536. public DocumentItem(Bitmap bitmap, GraphicsList graphicsList, List<PhaseModel> phaseModels)
  1537. {
  1538. this.bitmap = bitmap;
  1539. this.graphicsList = graphicsList;
  1540. this.phaseModels = phaseModels;
  1541. }
  1542. }
  1543. #endregion
  1544. #endregion
  1545. }
  1546. }