BatteryCrystalDialog.cs 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392
  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. string unString = "纳米";
  149. string unStringE = "nm";
  150. #endregion
  151. System.Windows.Forms.DataVisualization.Charting.Chart chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart();
  152. /// <summary>
  153. ///
  154. /// </summary>
  155. /// <param name="appWorkspace"></param>
  156. public BatteryCrystalDialog(AppWorkspace appWorkspace, int menuId)
  157. {
  158. this.KeyPreview = true;
  159. this.KeyDown += OnKeyDown;
  160. this.menuId = menuId;
  161. binaryClass = new BinaryClassForB(menuId);
  162. InitializeComponent();
  163. InitializeLanguageText();
  164. ColumnHeader header0 = new ColumnHeader();
  165. header0.Text = "";
  166. header0.Width = 180;
  167. this.appWorkspace = appWorkspace;
  168. this.documentWorkspace = new DocumentWorkspaceWindow(appWorkspace);
  169. this.documentWorkspace.Dock = DockStyle.Fill;
  170. this.documentWorkspace.HookMouseEvents();
  171. this.documentWorkspace.AuxiliaryLineEnabled = false;
  172. this.documentWorkspace.Visible = false;
  173. this.documentWorkspace.panel.Paint += Panel_Paint;
  174. this.documentWorkspace.panel.MouseDown += OnMouseDown;
  175. this.documentWorkspace.panel.MouseUp += OnMouseUp;
  176. this.documentWorkspace.panel.Paint += Panel_Paint;
  177. this.documentWorkspace.panel.MouseMove += onMouseMove;
  178. this.documentWorkspace.activeTool = DrawToolType.Pointer;
  179. this.groupBox7.Controls.Add(this.documentWorkspace);
  180. this.commonControlButtons = new GeneralAnalysisCommonControlButtons();
  181. this.commonControlButtons.Dock = DockStyle.Top;
  182. this.commonControlButtons.Height = 30;
  183. this.commonControlButtons.HideZoomToWindowAndActualSize();
  184. this.commonControlButtons.trackLabel.Text = "单击开始画线,右键停止。";
  185. this.commonControlButtons.trackLabel.Visible = true;
  186. this.commonControlButtons.trackLabel.Width = 300;
  187. this.commonControlButtons.Visible = false;
  188. this.groupBox7.Controls.Add(commonControlButtons);
  189. //获取
  190. //Startup.instance.rules.TryGetValue(MeasurementUnit.Micron, out ruleValue);
  191. //double ruleValue = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetRuler(MeasurementUnit.Micron);
  192. ////double physical_area_length_Micron = getCurrentWorkspace().GetRuler(MeasurementUnit.Micron);
  193. chart1.Size = new System.Drawing.Size(1150, 180);
  194. chart1.Location = new System.Drawing.Point(5, 15);
  195. //二值化集成2
  196. bc.OriginCheckedChangedAction += new EventHandler(this.bcOriginCheckedChanged);//初始化原图勾选改变事件
  197. binaryClass.imageType = 2;
  198. binaryClass.createDocumentItemsSmaller(new string[] { "bp1" } , this.bc, this.appWorkspace, this.documentWorkspace, this.listView1);//初始化相的工作结构
  199. //binaryClass.BinaryImplFinishAction += new EventHandler(this.bClassBinaryImplFinishAction);//二值化后续处理事件(参数改变时,重新处理图像)
  200. binaryClass.parentSinglCrystal = this;
  201. this.ckChanged.CheckedChanged += new EventHandler(this.CheckedChanged);
  202. this.ckDis.CheckedChanged += new EventHandler(this.IsDisChanged);
  203. this.ckJu.CheckedChanged += new EventHandler(this.IsDisChanged);
  204. numericUpDown11.Value=Convert.ToDecimal( binaryClass.pointsize);
  205. numericMax.Value = binaryClass.border;
  206. numericHW.Value = Convert.ToDecimal(binaryClass.HW);
  207. numericArea.Value = Convert.ToDecimal(binaryClass.AreaRatio);
  208. numericBottom.Value = binaryClass.borderBottom;
  209. numericNum.Value = binaryClass.numDecimals;
  210. string checkstate = binaryClass.CheckState.ToString();
  211. if (checkstate.Length == 5)
  212. {
  213. ckMin.Checked = checkstate.Substring(1, 1) == "1" ? true : false;
  214. ckMax.Checked = checkstate.Substring(2, 1) == "1" ? true : false;
  215. ckHW.Checked = checkstate.Substring(3, 1) == "1" ? true : false;
  216. ckArea.Checked = checkstate.Substring(4, 1) == "1" ? true : false;
  217. }
  218. else if (checkstate.Length == 7)
  219. {
  220. ckMin.Checked = checkstate.Substring(1, 1) == "1" ? true : false;
  221. ckMax.Checked = checkstate.Substring(2, 1) == "1" ? true : false;
  222. ckHW.Checked = checkstate.Substring(3, 1) == "1" ? true : false;
  223. ckArea.Checked = checkstate.Substring(4, 1) == "1" ? true : false;
  224. ckBottom.Checked = checkstate.Substring(5, 1) == "1" ? true : false;
  225. ckNum.Checked = checkstate.Substring(6, 1) == "1" ? true : false;
  226. }
  227. InitCommonButtonEvent();
  228. InitGridStyle();
  229. InitPicList();
  230. // SetAnalyzeModelFromXml(getModelName());
  231. }
  232. private void CkDis_CheckedChanged(object sender, EventArgs e)
  233. {
  234. throw new NotImplementedException();
  235. }
  236. private void ShowImgEvent(object sender, EventArgs e)
  237. {
  238. if (this.listView1.Items.Count == 0)
  239. {
  240. return;
  241. }
  242. listView1.Focus();
  243. this.listView1.Items[0].Focused = true;
  244. this.listView1.Items[0].Selected = true;
  245. }
  246. #region 二值化相关方法
  247. private void InclusionsStandardDialog_FormClosing(object sender, FormClosingEventArgs e)
  248. {
  249. int check = 1000000;
  250. double minpoint = Convert.ToDouble(numericUpDown11.Value);
  251. int minpointInt = ckMin.Checked ? 1 : 0;
  252. int border = Convert.ToInt32(numericMax.Value);
  253. int borderInt = ckMax.Checked ? 1 : 0;
  254. double HW = Convert.ToDouble(numericHW.Value);
  255. int HWInt = ckHW.Checked ? 1 : 0;
  256. double AreaRatio = Convert.ToDouble(numericArea.Value);
  257. int AreaRatioInt = ckArea.Checked ? 1 : 0;
  258. int bottom = Convert.ToInt32(numericBottom.Value);
  259. int bottomInt = ckBottom.Checked ? 1 : 0;
  260. int size = Convert.ToInt32(numericNum.Value);
  261. int sizeInt = ckNum.Checked ? 1 : 0;
  262. check = check + minpointInt * 100000 + borderInt * 10000 + HWInt * 1000 + AreaRatioInt * 100 + bottomInt * 10 + sizeInt;
  263. List<int> paramsList = new List<int>() {
  264. Convert.ToInt32(minpoint * 100)
  265. , Convert.ToInt32(border * 100)
  266. , Convert.ToInt32(HW * 100)
  267. , Convert.ToInt32(AreaRatio * 100)
  268. , Convert.ToInt32(bottom * 100)
  269. , Convert.ToInt32(size),check };
  270. binaryClass.saveParams(paramsList);
  271. }
  272. private void ShownChoiseItemAndInitData(object sender, EventArgs e)
  273. {
  274. binaryClass.RefreshHistogramControl1Values();
  275. }
  276. /// <summary>
  277. /// 添加参数改变的监听
  278. /// </summary>
  279. /// <param name="sender"></param>
  280. /// <param name="e"></param>
  281. private void GrainSizePointCountingMethodDialog_Load(object sender, EventArgs e)
  282. {
  283. this.dataGridView1.SortCompare += DataGridView4_SortCompare;
  284. this.binaryClass.loadParams();
  285. }
  286. private bool bcBinaryChecked()
  287. {
  288. return bc != null && bc.BinaryChecked;
  289. }
  290. private bool bcOriginChecked()
  291. {
  292. return bc != null && bc.OriginChecked;
  293. }
  294. /// <summary>
  295. /// 显示原图/原图+二值图
  296. /// </summary>
  297. /// <param name="sender"></param>
  298. /// <param name="e"></param>
  299. private void bcOriginCheckedChanged(object sender, EventArgs e)
  300. {
  301. if (!bcOriginChecked())
  302. {
  303. if (bcBinaryChecked())
  304. this.documentWorkspace.PhaseModels[0].choise = true;
  305. }
  306. else
  307. this.documentWorkspace.PhaseModels[0].choise = false;
  308. this.documentWorkspace.Refresh();
  309. }
  310. /// <summary>
  311. /// 显示原图/原图+二值图
  312. /// </summary>
  313. /// <param name="sender"></param>
  314. /// <param name="e"></param>
  315. private void CheckedChanged(object sender, EventArgs e)
  316. {
  317. if (!ckChanged.Checked)
  318. {
  319. this.documentWorkspace.PhaseModels[0].choise = true;
  320. }
  321. else
  322. this.documentWorkspace.PhaseModels[0].choise = false;
  323. this.documentWorkspace.Refresh();
  324. }
  325. #endregion
  326. /// <summary>
  327. /// 初始化画面数据
  328. /// </summary>
  329. private void InitGridStyle()
  330. {
  331. grainSizePointCountingMethodModel = XmlSerializeHelper.DESerializer<GrainSizePointCountingMethodModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizePointCountingMethodModel.xml", FileMode.Open));
  332. if (grainSizePointCountingMethodModel.GridStyleList != null)
  333. {
  334. ArrayList arrayList = new ArrayList();
  335. foreach (var GridStyle in grainSizePointCountingMethodModel.GridStyleList)
  336. {
  337. arrayList.Add(GridStyle.gridName);
  338. }
  339. if (grainSizePointCountingMethodModel.GridStyleList.Count == 0)
  340. {
  341. }
  342. }
  343. }
  344. /// <summary>
  345. /// 初始化图片列表数据
  346. /// </summary>
  347. public void InitPicList()
  348. {
  349. //初始化图片列表
  350. for (int i = 0; i < this.appWorkspace.DocumentWorkspaces.Length; i++)
  351. {
  352. this.imageList1.Images.Add("img" + i, this.appWorkspace.DocumentWorkspaces[i].BinarizationThumbnail);
  353. this.listView1.Items.Add("", i);
  354. this.listView1.Items[i].ImageIndex = i;
  355. this.listView1.Items[i].Text = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName();
  356. this.listView1.Items[i].Name = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName();
  357. }
  358. if (listView1.Items.Count > 0)
  359. {
  360. //标尺 微米/像素
  361. MeasurementUnit unit = this.appWorkspace.DocumentWorkspaces[0].GetMeasurementUnit();
  362. if (unit == MeasurementUnit.Micron)
  363. {
  364. unString = "微米";
  365. unStringE = "μm";
  366. ColumnVal.HeaderText = "值/微米";
  367. groupBox9.Text = "颗粒信息-单位:微米";
  368. groupBoxGrid2.Text = "统计结果-单位:微米";
  369. }
  370. //标尺 纳米/像素
  371. unitLength = this.appWorkspace.DocumentWorkspaces[0].GetRuler(unit);
  372. binaryClass.unitLength = unitLength;
  373. }
  374. this.Shown += ShowImgEvent;
  375. }
  376. #region 初始化
  377. private void InitializeLanguageText()
  378. {
  379. this.bc = new PaintDotNet.CustomControl.BinaryControlSmaller();
  380. //
  381. // bc
  382. //
  383. this.bc.BinaryBackColor = System.Drawing.Color.Red;
  384. this.bc.BinaryChecked = false;
  385. this.bc.BinaryStyle = 1;
  386. this.bc.Location = new System.Drawing.Point(152, 7);
  387. this.bc.Name = "bc";
  388. this.bc.OriginChecked = false;
  389. this.bc.scope1End = 170D;
  390. this.bc.scope1Start = 80D;
  391. this.bc.scope2End = 0D;
  392. this.bc.scope2Start = 0D;
  393. this.bc.scope3End = 0D;
  394. this.bc.scope3Start = 0D;
  395. this.bc.Size = new System.Drawing.Size(360, 247);
  396. this.bc.TabIndex = 3;
  397. // this.Controls.Add(this.bc);
  398. // this.Controls.SetChildIndex(this.bc, 0);
  399. //this.groupBox9.Controls.Add(chart1);
  400. this.groupBox8.Controls.Add(chart1);
  401. chart1.Visible = false;
  402. //this.label10.Visible = true;
  403. //this.label10.Text = "【" + tn.Name + "】图";
  404. chart1.Titles.Add("单晶尺寸分布图");
  405. }
  406. #endregion
  407. #region 公共按钮
  408. private void InitCommonButtonEvent()
  409. {
  410. this.commonControlButtons.zoomInButton.Click += new EventHandler(zoomInButton_Click);
  411. this.commonControlButtons.zoomOutButton.Click += new EventHandler(zoomOutButton_Click);
  412. this.commonControlButtons.zoomToWindowButton.Click += new EventHandler(zoomToWindowButton_Click);
  413. this.commonControlButtons.actualSizeButton.Click += new EventHandler(actualSizeButton_Click);
  414. this.commonControlButtons.pointerButton.Click += new EventHandler(pointerButton_Click);
  415. this.commonControlButtons.mobileModeButton.Click += new EventHandler(mobileModeButton_Click);
  416. }
  417. private void zoomInButton_Click(object sender, EventArgs e)
  418. {
  419. this.documentWorkspace.ZoomIn();
  420. }
  421. private void zoomOutButton_Click(object sender, EventArgs e)
  422. {
  423. this.documentWorkspace.ZoomOut();
  424. }
  425. private void zoomToWindowButton_Click(object sender, EventArgs e)
  426. {
  427. this.documentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
  428. }
  429. private void actualSizeButton_Click(object sender, EventArgs e)
  430. {
  431. this.documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
  432. this.documentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
  433. }
  434. private void pointerButton_Click(object sender, EventArgs e)
  435. {
  436. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.Pointer;
  437. }
  438. private void mobileModeButton_Click(object sender, EventArgs e)
  439. {
  440. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode;
  441. }
  442. #endregion
  443. private void listView1_MouseDown(object sender, MouseEventArgs e)
  444. {
  445. this.changeCount = 0;
  446. }
  447. private void DataGridView4_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
  448. {
  449. // 如果是数据的列,则按浮点数处理
  450. //if (e.Column.Index > 1)//###20186
  451. //{
  452. e.SortResult = (Convert.ToDouble(e.CellValue1) - Convert.ToDouble(e.CellValue2) > 0) ? 1 : (Convert.ToDouble(e.CellValue1) - Convert.ToDouble(e.CellValue2) < 0) ? -1 : 0;
  453. // }
  454. ////否则,按字符串比较
  455. //else
  456. //{
  457. // e.SortResult = System.String.Compare(Convert.ToString(e.CellValue1), Convert.ToString(e.CellValue2));
  458. //}
  459. e.Handled = true;//不能省掉,不然没效果
  460. }
  461. private void listView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
  462. {
  463. this.changeCount++;
  464. }
  465. /// <summary>
  466. /// 切换图片
  467. /// </summary>
  468. /// <param name="sender"></param>
  469. /// <param name="e"></param>
  470. private void listView1_SelectedIndexChanged(object sender, EventArgs e)
  471. {
  472. SelectedIndexChanged();
  473. }
  474. /// <summary>
  475. /// 显示矩形测距
  476. /// </summary>
  477. /// <param name="sender"></param>
  478. /// <param name="e"></param>
  479. private void IsDisChanged(object sender, EventArgs e)
  480. {
  481. binaryClass.isDis = ckDis.Checked;
  482. binaryClass.isJu = ckJu.Checked;
  483. btnReDrw_Click(null, null);
  484. // SelectedIndexChanged();
  485. }
  486. List<PointF> list = new List<PointF>();
  487. /// <summary>
  488. /// 切换图片
  489. /// </summary>
  490. private void SelectedIndexChanged()
  491. {
  492. if (this.listView1.FocusedItem != null && this.listView1.FocusedItem.Selected)
  493. {
  494. existViewFlag = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GraphicsList.IsExsitView();
  495. this.bitmap = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap();
  496. lineList.Clear();
  497. pointList.Clear();
  498. kongLineList.Clear();
  499. kongPointList.Clear();
  500. delLineList.Clear();
  501. delPointList.Clear();
  502. pointList1.Clear();
  503. isLunKuo = false;
  504. isAddKong = false;
  505. isDelKong = false;
  506. this.documentWorkspace.Refresh();
  507. this.dataGridView1.Rows.Clear();
  508. this.dataGridView2.Rows.Clear();
  509. chart1.Series.Clear();
  510. chart1.ChartAreas.Clear();
  511. chart1.Legends.Clear();
  512. Init();
  513. this.documentWorkspace.GridRectangleEnabled = false;
  514. //getimage();
  515. //getbian(bitmap);
  516. double minpoint = Convert.ToDouble(numericUpDown11.Value);
  517. if (!ckMin.Checked)
  518. minpoint = 0.01;
  519. binaryClass.pointsize = Convert.ToDouble(minpoint);
  520. int border = Convert.ToInt32(numericMax.Value);
  521. if (!ckMax.Checked)
  522. border = 0;
  523. binaryClass.border = border;
  524. double HW = Convert.ToDouble(numericHW.Value);
  525. if (!ckHW.Checked)
  526. HW = 100;
  527. binaryClass.HW = HW;
  528. double AreaRatio = Convert.ToDouble(numericArea.Value);
  529. if (!ckArea.Checked)
  530. AreaRatio = 0.01;
  531. binaryClass.AreaRatio = AreaRatio;
  532. int bottom = Convert.ToInt32(numericBottom.Value);
  533. if (!ckBottom.Checked)
  534. bottom = 0;
  535. binaryClass.borderBottom = bottom;
  536. //二值化集成4
  537. binaryClass.listView1_SelectedIndexChanged(this.bitmap);
  538. // binaryClass.bcDefault();
  539. this.documentWorkspace.Refresh();
  540. }
  541. }
  542. #region 原始事件
  543. private void Init()
  544. {
  545. this.commonControlButtons.Visible = true;
  546. this.dataGridView1.Rows.Clear();
  547. this.documentWorkspace.phaseModels.Clear();
  548. }
  549. /// <summary>
  550. /// 画布绘制
  551. /// </summary>
  552. /// <param name="sender"></param>
  553. /// <param name="e"></param>
  554. private void Panel_Paint(object sender, PaintEventArgs e)
  555. {
  556. if (this.documentWorkspace.CompositionSurface != null)
  557. {
  558. //
  559. // 以下是计算绘制图片的位置和大小并绘制图片
  560. //
  561. Rectangle rc = this.documentWorkspace.panel.ClientRectangle;
  562. int width = (int)(this.documentWorkspace.CompositionSurface.Width * this.documentWorkspace.ScaleFactor.Ratio);
  563. int height = (int)(this.documentWorkspace.CompositionSurface.Height * this.documentWorkspace.ScaleFactor.Ratio);
  564. int x = (rc.Width < width) ? this.documentWorkspace.panel.AutoScrollPosition.X : (rc.Width - width) / 2;
  565. int y = (rc.Height < height) ? this.documentWorkspace.panel.AutoScrollPosition.Y : (rc.Height - height) / 2;
  566. //if (pointArray.Count > 1)
  567. //{
  568. // e.Graphics.DrawLines(new Pen(Color.FromArgb(0, 0, 0), 2), pointArray.ToArray());
  569. //}
  570. //
  571. // 以下是绘制网格、标注、测量、视场等开始
  572. //
  573. e.Graphics.TranslateTransform(x, y);
  574. e.Graphics.ScaleTransform((float)this.documentWorkspace.ScaleFactor.Ratio, (float)this.documentWorkspace.ScaleFactor.Ratio);
  575. Draw(e.Graphics);
  576. //e.Graphics.DrawLines(new Pen(this.panel1.BackColor, Convert.ToInt32(this.txt_LeftLineWeight.Text)), list.ToArray());
  577. e.Graphics.ScaleTransform(1 / (float)this.documentWorkspace.ScaleFactor.Ratio, 1 / (float)this.documentWorkspace.ScaleFactor.Ratio);
  578. e.Graphics.TranslateTransform(-x, -y);
  579. }
  580. if (bc.isedit)
  581. {
  582. bc.isedit = false;
  583. List<List<int>> CircleDate = bc.data;
  584. bindGrid(CircleDate);
  585. }
  586. }
  587. // <summary>
  588. /// 存储字号与颜色字典
  589. /// </summary>
  590. public Dictionary<string, Color> colourFont = new Dictionary<string, Color>() { { "20", Color.White } };
  591. /// <summary>
  592. /// 绘制
  593. /// </summary>
  594. private void Draw(Graphics graphics)
  595. {
  596. //轮廓手动干预线
  597. if (lineList.Count > 0)
  598. {
  599. for (int i = 0; i < lineList.Count; i++)
  600. {
  601. graphics.DrawLines(new Pen(Color.FromArgb(255, 0, 255), 2), lineList[i].ToArray());
  602. }
  603. }
  604. if (pointList.Count > 1)
  605. {
  606. graphics.DrawLines(new Pen(Color.FromArgb(255, 0, 255), 2), pointList.ToArray());
  607. }
  608. //添加颗粒
  609. Color color = Color.FromArgb(255,0, 0,255);
  610. if (kongLineList.Count > 0)
  611. {
  612. for (int i = 0; i < kongLineList.Count; i++)
  613. {
  614. if (kongLineList[i].Count > 1)
  615. {
  616. graphics.DrawLines(new Pen(color, 2), kongLineList[i].ToArray());
  617. }
  618. }
  619. }
  620. graphics.SmoothingMode = SmoothingMode.AntiAlias;
  621. Pen standardPen = new Pen(Color.FromArgb(0, 255, 0), 4);//基准线画笔
  622. Pen surfacePen = new Pen(Color.FromArgb(255, 0, 0), 4);//钢样表面画笔
  623. Pen completePen = new Pen(Color.FromArgb(0, 0, 255), 4);//完全脱碳层画笔
  624. Pen validPen = new Pen(Color.FromArgb(255, 255, 255), 4);//有效脱碳层画笔
  625. Pen partPen = new Pen(Color.FromArgb(0, 0, 0), 2);//部分脱碳层画笔
  626. Pen borderPen = new Pen(Color.Black);//填充点外圈
  627. SolidBrush insideBrush = new SolidBrush(Color.White);//填充点内圈
  628. Pen rectPen = new Pen(Color.Black);
  629. rectPen.DashStyle = DashStyle.Custom;
  630. float[] dashArray = { 2.0f, 3.0f };
  631. rectPen.DashPattern = dashArray;
  632. if (pointList1.Count > 0)
  633. {
  634. foreach (PointF[] pointFs in pointList1)
  635. {
  636. PointF[] pf = pointFs;
  637. if (pointFs.Count() > 1 && pointFs[0] != pointFs[1])
  638. {
  639. float lineLength = 12;
  640. double angle = Math.Round(BasicCalculationHelper.AngleText(pointFs[0], pointFs[1], new PointF(pointFs[0].X + lineLength, pointFs[0].Y)), 10);
  641. //判断第二个点相对于第一个点的象限
  642. int x2 = (int)(pointFs[1].X - pointFs[0].X);
  643. if (x2 == 0)
  644. x2 = 1;
  645. int y2 = (int)(pointFs[1].Y - pointFs[0].Y);
  646. if (y2 == 0)
  647. y2 = 1;
  648. int i2 = 0;
  649. if (x2 > 0 && y2 > 0) //第4象限
  650. {
  651. i2 = 4;
  652. }
  653. else if (x2 > 0 && y2 < 0) //第1象限
  654. {
  655. i2 = 1;
  656. }
  657. else if (x2 < 0 && y2 < 0) //第2象限
  658. {
  659. i2 = 2;
  660. }
  661. else if (x2 < 0 && y2 > 0) //第3象限
  662. {
  663. i2 = 3;
  664. }
  665. double sAngle1;
  666. double eAngle1;
  667. double sAngle2;
  668. double eAngle2;
  669. if (i2 == 1 || i2 == 2)
  670. {
  671. sAngle1 = 360 - angle;
  672. eAngle1 = 180 - angle;
  673. sAngle2 = 270 - angle;
  674. eAngle2 = 90 - angle;
  675. }
  676. else
  677. {
  678. sAngle1 = angle;
  679. eAngle1 = 180 + angle;
  680. sAngle2 = 270 + angle;
  681. eAngle2 = 90 + angle;
  682. }
  683. graphics.DrawLine(standardPen, pointFs[0], pointFs[1]);
  684. if (!double.IsNaN(sAngle1) && !double.IsNaN(eAngle1) && !double.IsNaN(sAngle2) && !double.IsNaN(eAngle2))
  685. {
  686. PointF assistPoint1 = BasicCalculationHelper.GetAnglePoint(new PointF((pointFs[0].X + lineLength), pointFs[0].Y), pointFs[0], sAngle2);
  687. PointF assistPoint2 = BasicCalculationHelper.GetAnglePoint(new PointF((pointFs[0].X + lineLength), pointFs[0].Y), pointFs[0], eAngle2);
  688. PointF assistPoint3 = BasicCalculationHelper.GetAnglePoint(new PointF((pointFs[1].X + lineLength), pointFs[1].Y), pointFs[1], sAngle2);
  689. PointF assistPoint4 = BasicCalculationHelper.GetAnglePoint(new PointF((pointFs[1].X + lineLength), pointFs[1].Y), pointFs[1], eAngle2);
  690. graphics.DrawLine(surfacePen, assistPoint1, assistPoint2);
  691. graphics.DrawLine(partPen, assistPoint3, assistPoint4);
  692. //PointF[] pf = pointFs;
  693. if (i2 == 1 || i2 == 2)
  694. {
  695. 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);
  696. }
  697. else
  698. {
  699. 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);
  700. }
  701. }
  702. }
  703. }
  704. if (selected > -1)
  705. {
  706. int tempLess = (int)(InvariantData.rectless * (this.documentWorkspace.ScaleFactor.Ratio < 1 ? 1 / this.documentWorkspace.ScaleFactor.Ratio : 1));
  707. int tempPlus = (int)(InvariantData.rectplus * (this.documentWorkspace.ScaleFactor.Ratio < 1 ? 1 / this.documentWorkspace.ScaleFactor.Ratio : 1));
  708. graphics.DrawRectangle(borderPen, new Rectangle((int)(pointList1[selected][0].X - tempLess), (int)(pointList1[selected][0].Y - tempLess), tempPlus, tempPlus));
  709. graphics.FillRectangle(insideBrush, new RectangleF(pointList1[selected][0].X - tempLess, pointList1[selected][0].Y - tempLess, tempPlus, tempPlus));
  710. graphics.DrawRectangle(borderPen, new Rectangle((int)(pointList1[selected][1].X - tempLess), (int)(pointList1[selected][1].Y - tempLess), tempPlus, tempPlus));
  711. graphics.FillRectangle(insideBrush, new RectangleF(pointList1[selected][1].X - tempLess, pointList1[selected][1].Y - tempLess, tempPlus, tempPlus));
  712. graphics.DrawRectangle(rectPen, rectangleFList[selected].X, rectangleFList[selected].Y, rectangleFList[selected].Width, rectangleFList[selected].Height);
  713. }
  714. }
  715. standardPen.Dispose();
  716. surfacePen.Dispose();
  717. completePen.Dispose();
  718. validPen.Dispose();
  719. partPen.Dispose();
  720. borderPen.Dispose();
  721. insideBrush.Dispose();
  722. rectPen.Dispose();
  723. }
  724. //最长直径
  725. double MaxM = 0;
  726. double MinM = 0;
  727. double MeanM = 0;
  728. DataTable dtChart = new DataTable();
  729. private void bindGrid(List<List<int>> dataList)
  730. {
  731. if (dataList.Count < 1)
  732. {
  733. return;
  734. }
  735. chart1.Visible = true;
  736. List<int> CircleDate = dataList[0];
  737. dataGridView1.Rows.Clear();
  738. dataGridView2.Rows.Clear();
  739. chart1.Series.Clear();
  740. chart1.ChartAreas.Clear();
  741. 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) };
  742. List<double> diameterPI = new List<double>() { };
  743. List<double> diameter = new List<double>(){ };
  744. List<double> diameterMax = new List<double>() { };
  745. //保留小数位数
  746. int numDec =Convert.ToInt32( numericNum.Value);
  747. for (int i = 0; i < dataList.Count; i++)
  748. {
  749. int newPo = dataGridView1.Rows.Add();
  750. //序号
  751. dataGridView1.Rows[newPo].Cells[0].Value = (newPo + 1).ToString();
  752. //XY
  753. dataGridView1.Rows[newPo].Cells[1].Value ="X:"+ dataList[i][0].ToString()+",Y:"+ dataList[i][1].ToString();
  754. //直径
  755. double w = Convert.ToDouble(dataList[i][6]);
  756. double h = Convert.ToDouble(dataList[i][7]) ;
  757. double dd = (w + h)*0.5 * unitLength;
  758. double area= Convert.ToDouble(dataList[i][4]) * unitLength * unitLength;
  759. double r = Math.Sqrt(area / Math.PI) * 2;
  760. diameterPI.Add(r);
  761. diameter.Add(dd);
  762. double maxD = w > h ? w : h;
  763. double minD = w < h ? w : h;
  764. diameterMax.Add(maxD * unitLength);
  765. double circle= Convert.ToDouble(dataList[i][8])*0.001;
  766. dataGridView1.Rows[newPo].Cells[2].Value= Math.Round(dd, numDec).ToString();
  767. dataGridView1.Rows[newPo].Cells[3].Value = dataList[i][5];
  768. dataGridView1.Rows[newPo].Cells[4].Value = Math.Round(maxD * unitLength, numDec).ToString();
  769. dataGridView1.Rows[newPo].Cells[5].Value = Math.Round(minD * unitLength, numDec).ToString();
  770. dataGridView1.Rows[newPo].Cells[6].Value = Math.Round(r, numDec).ToString();
  771. }
  772. diameterMax.Sort();
  773. MinM = diameterMax[0];
  774. MaxM = diameterMax[diameterMax.Count - 1];
  775. foreach (var item in diameterMax)
  776. {
  777. MeanM += Math.Round(item, 1);
  778. }
  779. MeanM = MeanM / diameterMax.Count;
  780. dtChart = CreatTable(diameter, diameterPI);
  781. CreatChart(dtChart);
  782. diameter.Sort();
  783. double total = 0;
  784. foreach (var item in diameter)
  785. {
  786. total += item;
  787. }
  788. total = total / diameter.Count;
  789. double advR = diameterPI.Average();
  790. int ind = 1;
  791. int newRow = dataGridView2.Rows.Add();
  792. dataGridView2.Rows[newRow].Cells[0].Value = (ind++).ToString();
  793. dataGridView2.Rows[newRow].Cells[1].Value = "平均值";
  794. dataGridView2.Rows[newRow].Cells[2].Value = Math.Round(total, numDec).ToString();
  795. //int newRow1 = dataGridView2.Rows.Add();
  796. //dataGridView2.Rows[newRow1].Cells[0].Value = (ind++).ToString();
  797. //dataGridView2.Rows[newRow1].Cells[1].Value = "最大值";
  798. //dataGridView2.Rows[newRow1].Cells[2].Value = Math.Round(diameter[diameter.Count-1], 2).ToString();
  799. //int newRow2 = dataGridView2.Rows.Add();
  800. //dataGridView2.Rows[newRow2].Cells[0].Value = (ind++).ToString();
  801. //dataGridView2.Rows[newRow2].Cells[1].Value = "最小值";
  802. //dataGridView2.Rows[newRow2].Cells[2].Value = Math.Round(diameter[0], 2).ToString();
  803. int newRow2 = dataGridView2.Rows.Add();
  804. dataGridView2.Rows[newRow2].Cells[0].Value = (ind++).ToString();
  805. dataGridView2.Rows[newRow2].Cells[1].Value = "颗粒数量";
  806. dataGridView2.Rows[newRow2].Cells[2].Value = diameter.Count.ToString();
  807. int newRow7 = dataGridView2.Rows.Add();
  808. dataGridView2.Rows[newRow7].Cells[0].Value = (ind++).ToString();
  809. dataGridView2.Rows[newRow7].Cells[1].Value = "拟圆直径";
  810. dataGridView2.Rows[newRow7].Cells[2].Value = Math.Round(advR, numDec).ToString();
  811. int count = diameter.Count;
  812. int d1= Convert.ToInt32(count * 0.01);
  813. int d5 = Convert.ToInt32(count * 0.05);
  814. int d10 = Convert.ToInt32(count * 0.1);
  815. int d50 = Convert.ToInt32(count * 0.5);
  816. int d90 = Convert.ToInt32(count * 0.9);
  817. int d95 = Convert.ToInt32(count * 0.95);
  818. int d99 = Convert.ToInt32(count * 0.99);
  819. d1 = d1 >= count ? count - 1 : d1;
  820. d5 = d5 >= count ? count - 1 : d5;
  821. d10 = d10 >= count ? count - 1 : d10;
  822. d50 = d50 >= count ? count - 1 : d50;
  823. d90 = d90 >= count ? count - 1 : d90;
  824. d95 = d95 >= count ? count - 1 : d95;
  825. d99 = d99 >= count ? count - 1 : d99;
  826. int newRowMin = dataGridView2.Rows.Add();
  827. dataGridView2.Rows[newRowMin].Cells[0].Value = (ind++).ToString();
  828. dataGridView2.Rows[newRowMin].Cells[1].Value = "Dmin";
  829. dataGridView2.Rows[newRowMin].Cells[2].Value = Math.Round(diameter[0], numDec).ToString();
  830. int newRowd1 = dataGridView2.Rows.Add();
  831. dataGridView2.Rows[newRowd1].Cells[0].Value = (ind++).ToString();
  832. dataGridView2.Rows[newRowd1].Cells[1].Value = "D1";
  833. dataGridView2.Rows[newRowd1].Cells[2].Value = Math.Round(diameter[d1], numDec).ToString();
  834. int newRow25 = dataGridView2.Rows.Add();
  835. dataGridView2.Rows[newRow25].Cells[0].Value = (ind++).ToString();
  836. dataGridView2.Rows[newRow25].Cells[1].Value = "D5";
  837. dataGridView2.Rows[newRow25].Cells[2].Value = Math.Round(diameter[d5], numDec).ToString();
  838. int newRow3 = dataGridView2.Rows.Add();
  839. dataGridView2.Rows[newRow3].Cells[0].Value = (ind++).ToString();
  840. dataGridView2.Rows[newRow3].Cells[1].Value = "D10";
  841. dataGridView2.Rows[newRow3].Cells[2].Value = Math.Round(diameter[d10], numDec).ToString();
  842. int newRow4 = dataGridView2.Rows.Add();
  843. dataGridView2.Rows[newRow4].Cells[0].Value = (ind++).ToString();
  844. dataGridView2.Rows[newRow4].Cells[1].Value = "D50";
  845. dataGridView2.Rows[newRow4].Cells[2].Value = Math.Round(diameter[d50], numDec).ToString();
  846. int newRow5 = dataGridView2.Rows.Add();
  847. dataGridView2.Rows[newRow5].Cells[0].Value = (ind++).ToString();
  848. dataGridView2.Rows[newRow5].Cells[1].Value = "D90";
  849. dataGridView2.Rows[newRow5].Cells[2].Value = Math.Round(diameter[d90], numDec).ToString();
  850. int newRow6 = dataGridView2.Rows.Add();
  851. dataGridView2.Rows[newRow6].Cells[0].Value = (ind++).ToString();
  852. dataGridView2.Rows[newRow6].Cells[1].Value = "D95";
  853. dataGridView2.Rows[newRow6].Cells[2].Value = Math.Round(diameter[d95], numDec).ToString();
  854. int newRowd99 = dataGridView2.Rows.Add();
  855. dataGridView2.Rows[newRowd99].Cells[0].Value = (ind++).ToString();
  856. dataGridView2.Rows[newRowd99].Cells[1].Value = "D99";
  857. dataGridView2.Rows[newRowd99].Cells[2].Value = Math.Round(diameter[d99], numDec).ToString();
  858. int newRowMax = dataGridView2.Rows.Add();
  859. dataGridView2.Rows[newRowMax].Cells[0].Value = (ind++).ToString();
  860. dataGridView2.Rows[newRowMax].Cells[1].Value = "Dmax";
  861. dataGridView2.Rows[newRowMax].Cells[2].Value = Math.Round(diameter[diameter.Count - 1], numDec).ToString();
  862. }
  863. /// <summary>
  864. /// 准备用来处理单个颗粒的选中事件
  865. /// </summary>
  866. /// <param name="sender"></param>
  867. /// <param name="e"></param>
  868. private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
  869. {
  870. //当点击表头部的列时,e.RowIndex==-1
  871. if (e.RowIndex > -1)
  872. {
  873. string selectrow = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
  874. int x = Convert.ToInt32(selectrow);
  875. binaryClass.DrwCrystalSelected(x);
  876. this.documentWorkspace.Refresh();
  877. }
  878. }
  879. //外接矩形
  880. double MaxP = 0;
  881. double Minp = 0;
  882. double MeanP = 0;
  883. //拟圆直径
  884. double MaxP2 = 0;
  885. double Minp2 = 0;
  886. double MeanP2 = 0;
  887. private DataTable CreatTable(List<double> diameter, List<double> diameterPI)
  888. {
  889. diameter.Sort();
  890. double max = diameter[diameter.Count - 1];
  891. double total = max*2;
  892. double min = 0;
  893. Minp = diameter[0];
  894. MaxP= diameter[diameter.Count - 1];
  895. diameterPI.Sort();
  896. Minp2 = diameterPI[0];
  897. MaxP2 = diameterPI[diameterPI.Count - 1];
  898. foreach (var item in diameter)
  899. {
  900. MeanP += Math.Round(item, 2) ;
  901. }
  902. foreach (var item in diameterPI)
  903. {
  904. MeanP2 += Math.Round(item, 2);
  905. }
  906. MeanP = MeanP / diameter.Count;
  907. MeanP2 = MeanP2 / diameterPI.Count;
  908. //int eval =Convert.ToInt32( (max - min) / 20);
  909. double eval =0.3;
  910. // double eval = max / 15;
  911. List<double[]> vs = new List<double[]>();
  912. double rightmax = 5.7;
  913. for (int i = 0; eval * i < rightmax; i++)
  914. {
  915. vs.Add(new double[] { eval*i, eval*(i+1) });
  916. }
  917. DataTable dt = new DataTable();
  918. dt.Columns.Add("diameter");
  919. dt.Columns.Add("sum");
  920. dt.Columns.Add("sum1");
  921. for (int i = 0; i < vs.Count; i++)
  922. {
  923. DataRow dr;
  924. dr = dt.NewRow();
  925. double low = Math.Round(eval * i, 1);
  926. double hight = Math.Round(eval * (i + 1), 1) ;
  927. dr["diameter"] =string.Format("{0}", hight) ;
  928. var emp = diameter.FindAll(e => e > low && e <= hight);
  929. dr["sum"] = emp.Count;
  930. var emp1 = diameterPI.FindAll(e => e > low && e <= hight);
  931. dr["sum1"] = emp1.Count;
  932. dt.Rows.Add(dr);
  933. }
  934. DataRow drMax;
  935. drMax = dt.NewRow();
  936. double lowMax = Math.Round(5.7, 1);
  937. drMax["diameter"] =">5.7";
  938. var empMax = diameter.FindAll(e => e > lowMax);
  939. drMax["sum"] = empMax.Count;
  940. var emp1Max = diameterPI.FindAll(e => e > lowMax);
  941. drMax["sum1"] = emp1Max.Count;
  942. dt.Rows.Add(drMax);
  943. return dt;
  944. }
  945. private void CreatChart(DataTable dt)
  946. {
  947. if (dt == null || dt.Rows.Count == 0)
  948. {
  949. return;
  950. }
  951. chart1.Series.Clear();
  952. chart1.ChartAreas.Clear();
  953. chart1.Legends.Clear();
  954. //定义一个chart
  955. System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
  956. //定义一个绘图区域
  957. System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
  958. System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
  959. //定义一个绘图区域
  960. System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series();
  961. chartArea1.Name = "ChartArea1";
  962. chart1.Series.Add(series1);
  963. //chart1.Series.Add(series2);
  964. chart1.ChartAreas.Add(chartArea1);
  965. chart1.Legends.Add(legend1);
  966. series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline;
  967. chart1.Series[0].LegendText = "";
  968. chart1.Series[0].Label = "#VALY";
  969. chart1.Series[0].LabelBackColor = Color.Transparent;
  970. chart1.Series[0].ToolTip = "#VALY";
  971. chart1.Series[0]["PointWidth"] = "0.5";
  972. chart1.Series[0].XValueMember = "diameter";
  973. chart1.Series[0].YValueMembers = "sum";
  974. chart1.Series[0].LegendText = "卡规直径";
  975. //chart1.Series[1].LegendText = "";
  976. //chart1.Series[1].Label = "#VALY";
  977. //chart1.Series[1].LabelBackColor = Color.Transparent;
  978. //chart1.Series[1].ToolTip = "#VALY";
  979. //chart1.Series[1]["PointWidth"] = "0.5";
  980. //chart1.Series[1].XValueMember = "diameter";
  981. //chart1.Series[1].YValueMembers = "sum1";
  982. //chart1.Series[1].LegendText = "拟圆直径";
  983. chart1.ChartAreas[0].AxisX.Interval = 1;
  984. chart1.ChartAreas[0].AxisX.Title = "尺寸("+unStringE+")";
  985. chart1.ChartAreas[0].Axes[0].MajorGrid.Enabled = false; //X轴上网格
  986. chart1.ChartAreas[0].Axes[1].MajorGrid.Enabled = false; //y轴上网格
  987. series1.Color = Color.DarkSeaGreen;
  988. series2.Color = Color.PaleTurquoise;
  989. chart1.DataSource = dt;
  990. chart1.DataBind();
  991. }
  992. #region 手动干预
  993. /// <summary>
  994. /// 修改轮廓
  995. /// </summary>
  996. /// <param name="sender"></param>
  997. /// <param name="e"></param>
  998. private void btnLunkuo_Click(object sender, EventArgs e)
  999. {
  1000. isLunKuo = true;
  1001. isAddKong = false;
  1002. isDelKong = false;
  1003. operationK = -1;
  1004. }
  1005. /// <summary>
  1006. /// 添加孔隙
  1007. /// </summary>
  1008. /// <param name="sender"></param>
  1009. /// <param name="e"></param>
  1010. private void btnAddKong_Click(object sender, EventArgs e)
  1011. {
  1012. isLunKuo = false;
  1013. isAddKong = true;
  1014. isDelKong = false;
  1015. operationK = -1;
  1016. }
  1017. /// <summary>
  1018. /// 删除孔隙
  1019. /// </summary>
  1020. /// <param name="sender"></param>
  1021. /// <param name="e"></param>
  1022. private void btnDelKong_Click(object sender, EventArgs e)
  1023. {
  1024. isLunKuo = false;
  1025. isAddKong = false;
  1026. isDelKong = true;
  1027. operationK = -1;
  1028. }
  1029. /// <summary>
  1030. /// 重新统计
  1031. /// </summary>
  1032. /// <param name="sender"></param>
  1033. /// <param name="e"></param>
  1034. private void btnReDrw_Click(object sender, EventArgs e)
  1035. {
  1036. if (this.listView1.Items.Count == 0)
  1037. {
  1038. return;
  1039. }
  1040. double minpoint = Convert.ToDouble(numericUpDown11.Value);
  1041. if (!ckMin.Checked)
  1042. minpoint = 0.01;
  1043. binaryClass.pointsize =minpoint;
  1044. int border = Convert.ToInt32(numericMax.Value);
  1045. if (!ckMax.Checked)
  1046. border = 0;
  1047. binaryClass.border = border;
  1048. double HW = Convert.ToDouble(numericHW.Value);
  1049. if (!ckHW.Checked)
  1050. HW = 100;
  1051. binaryClass.HW = HW;
  1052. double AreaRatio = Convert.ToDouble(numericArea.Value);
  1053. if (!ckArea.Checked)
  1054. AreaRatio = 0.01;
  1055. binaryClass.AreaRatio = AreaRatio;
  1056. int bottom = Convert.ToInt32(numericBottom.Value);
  1057. if (!ckBottom.Checked)
  1058. bottom = 0;
  1059. binaryClass.borderBottom = bottom;
  1060. List<List<int>> CircleDate = binaryClass.ForgetCrystal(minpoint);
  1061. bindGrid(CircleDate);
  1062. }
  1063. /// <summary>
  1064. /// 计算外接矩形
  1065. /// </summary>
  1066. private RectangleF CalcOtherRectangle(PointF p1, PointF p2)
  1067. {
  1068. RectangleF rectangleF = new RectangleF();
  1069. if (p1.X > p2.X)
  1070. rectangleF.X = p2.X;
  1071. else
  1072. rectangleF.X = p1.X;
  1073. if (p1.Y > p2.Y)
  1074. rectangleF.Y = p2.Y;
  1075. else
  1076. rectangleF.Y = p1.Y;
  1077. rectangleF.Width = Math.Abs(p2.X - p1.X);
  1078. rectangleF.Height = Math.Abs(p2.Y - p1.Y);
  1079. int tempLess = (int)(InvariantData.rectless * (this.documentWorkspace.ScaleFactor.Ratio < 1 ? 1 / this.documentWorkspace.ScaleFactor.Ratio : 1)) * 5;
  1080. int tempPlus = (int)(InvariantData.rectplus * (this.documentWorkspace.ScaleFactor.Ratio < 1 ? 1 / this.documentWorkspace.ScaleFactor.Ratio : 1)) * 5;
  1081. return new RectangleF(rectangleF.X - tempLess, rectangleF.Y - tempLess, rectangleF.Width + tempPlus, rectangleF.Height + tempPlus);
  1082. }
  1083. /// <summary>
  1084. /// 移动
  1085. /// </summary>
  1086. /// <param name="sender"></param>
  1087. /// <param name="e"></param>
  1088. private void onMouseMove(object sender, MouseEventArgs e)
  1089. {
  1090. //if (e.Button == MouseButtons.Left)
  1091. //{
  1092. if (isLunKuo)
  1093. {
  1094. int cou = pointList.Count;
  1095. if (cou > 0)
  1096. { // 换算后的点
  1097. PointF movePoint = this.documentWorkspace.GetScalePoint(e.Location);
  1098. pointList[cou - 1] = movePoint;
  1099. }
  1100. }
  1101. if (isAddKong && e.Button == MouseButtons.Left)
  1102. {
  1103. if (kongLineList.Count > 0)
  1104. { // 换算后的点
  1105. PointF movePoint = this.documentWorkspace.GetScalePoint(e.Location);
  1106. //kongPointList[kongPointList.Count - 1] = movePoint;
  1107. kongLineList[kongLineList.Count - 1].Add(movePoint);
  1108. }
  1109. }
  1110. if (isDelKong)
  1111. {
  1112. //if (delPointList.Count > 0)
  1113. //{ // 换算后的点
  1114. // PointF movePoint = this.documentWorkspace.GetScalePoint(e.Location);
  1115. // delPointList[delPointList.Count - 1] = movePoint;
  1116. //}
  1117. }
  1118. if (operationK >= 0 && e.Button == MouseButtons.Left)
  1119. {
  1120. PointF movePoint = this.documentWorkspace.GetScalePoint(e.Location);
  1121. if (operationK == 0)
  1122. {
  1123. this.endPoint = movePoint;
  1124. pointList1[lineCount][1] = endPoint;
  1125. }
  1126. else if (operationK == 1 && selected > -1 && canMove)
  1127. {
  1128. float dx = movePoint.X - lastPoint.X;
  1129. float dy = movePoint.Y - lastPoint.Y;
  1130. float dxTemp = movePoint.X - tempPoint.X;
  1131. float dyTemp = movePoint.Y - tempPoint.Y;
  1132. lastPoint.X = movePoint.X;
  1133. lastPoint.Y = movePoint.Y;
  1134. if (movePointIndex == -1)
  1135. {
  1136. RectangleF rectangleF = new RectangleF();
  1137. rectangleF = rectangleFList[selected];
  1138. if (rectangleF.Contains(movePoint))
  1139. this.documentWorkspace.panel.Cursor = Cursors.SizeAll;
  1140. rectangleF.X += dx;
  1141. rectangleF.Y += dy;
  1142. rectangleFList[selected] = rectangleF;
  1143. for (int i = 0; i < pointList1[selected].Count(); i++)
  1144. {
  1145. if (pointList1[selected][i] == PointF.Empty)
  1146. continue;
  1147. pointList1[selected][i].X += dx;
  1148. pointList1[selected][i].Y += dy;
  1149. }
  1150. }
  1151. else if (movePointIndex == 0)
  1152. {
  1153. pointList1[selected][0].X += dx;
  1154. pointList1[selected][0].Y += dy;
  1155. rectangleFList[selected] = CalcOtherRectangle(pointList1[selected][0], pointList1[selected][1]);
  1156. }
  1157. else if (movePointIndex == 1)
  1158. {
  1159. pointList1[selected][1].X += dx;
  1160. pointList1[selected][1].Y += dy;
  1161. rectangleFList[selected] = CalcOtherRectangle(pointList1[selected][0], pointList1[selected][1]);
  1162. }
  1163. }
  1164. this.documentWorkspace.Refresh();
  1165. }
  1166. this.documentWorkspace.Refresh();
  1167. // }
  1168. }
  1169. /// <summary>
  1170. /// 鼠标抬起
  1171. /// </summary>
  1172. /// <param name="sender"></param>
  1173. /// <param name="e"></param>
  1174. private void OnMouseUp(object sender, MouseEventArgs e)
  1175. {
  1176. if (e.Button == MouseButtons.Left)
  1177. {
  1178. if (operationK == 0)
  1179. {
  1180. if (startPoint != null && endPoint != null && startPoint != endPoint)
  1181. {
  1182. RectangleF rectangleF = CalcOtherRectangle(pointList1[lineCount][0], pointList1[lineCount][1]);
  1183. rectangleFList.Add(rectangleF);
  1184. lineCount++;
  1185. // AddContentToDataGridView();
  1186. }
  1187. else
  1188. {
  1189. if (pointList1.Count > 0)
  1190. {
  1191. pointList1.RemoveAt(pointList1.Count - 1);
  1192. this.documentWorkspace.Refresh();
  1193. return;
  1194. }
  1195. }
  1196. this.documentWorkspace.Refresh();
  1197. }
  1198. else if (operationK == 1)
  1199. {
  1200. canMove = false;
  1201. movePointIndex = -1;
  1202. // RefreshDataGridView1();
  1203. }
  1204. else if (isAddKong)
  1205. {
  1206. if (kongLineList[kongLineList.Count - 1].Count > 3)
  1207. {
  1208. isAddKong = false;
  1209. List<List<int>> CircleDate = binaryClass.DeleteCrystal(delPointList, kongLineList);
  1210. bindGrid(CircleDate);
  1211. }
  1212. else
  1213. {
  1214. kongLineList.RemoveAt(kongLineList.Count - 1);
  1215. }
  1216. }
  1217. }
  1218. if (operationK >= 0 && e.Button == MouseButtons.Left)
  1219. {
  1220. PointF downPoint = this.documentWorkspace.GetScalePoint(e.Location);
  1221. if (operationK == 0)
  1222. {
  1223. pointList1[lineCount - 1][1] = downPoint;
  1224. }
  1225. else if (operationK == 1)
  1226. {
  1227. lastPoint.X = downPoint.X;
  1228. lastPoint.Y = downPoint.Y;
  1229. tempPoint.X = downPoint.X;
  1230. tempPoint.Y = downPoint.Y;
  1231. for (int i = rectangleFList.Count - 1; i >= 0; i--)
  1232. {
  1233. if (rectangleFList[i].Contains(downPoint))
  1234. {
  1235. selected = i;
  1236. canMove = true;
  1237. }
  1238. }
  1239. if (selected > -1 && pointList1 != null && pointList1.Count > 0)
  1240. {
  1241. int tempLess = (int)(InvariantData.rectless * (this.documentWorkspace.ScaleFactor.Ratio < 1 ? 1 / this.documentWorkspace.ScaleFactor.Ratio : 1)) * 5;
  1242. int tempPlus = (int)(InvariantData.rectplus * (this.documentWorkspace.ScaleFactor.Ratio < 1 ? 1 / this.documentWorkspace.ScaleFactor.Ratio : 1)) * 5;
  1243. if (new RectangleF(pointList1[selected][0].X - tempLess, pointList1[selected][0].Y - tempLess, tempPlus, tempPlus).Contains(downPoint))
  1244. movePointIndex = 0;
  1245. else if (new RectangleF(pointList1[selected][1].X - tempLess, pointList1[selected][1].Y - tempLess, tempPlus, tempPlus).Contains(downPoint))
  1246. movePointIndex = 1;
  1247. else
  1248. movePointIndex = -1;
  1249. this.documentWorkspace.Refresh();
  1250. }
  1251. if (canMove)
  1252. return;
  1253. selected = -1;
  1254. }
  1255. }
  1256. }
  1257. /// <summary>
  1258. /// 鼠标按下
  1259. /// </summary>
  1260. /// <param name="drawArea"></param>
  1261. /// <param name="e"></param>
  1262. private void OnMouseDown(object sender, MouseEventArgs e)
  1263. {
  1264. //禁止画黑色矩形
  1265. this.documentWorkspace.DrawRectangleFlag = false;
  1266. PointF downPoint = this.documentWorkspace.GetScalePoint(e.Location);
  1267. if (operationK >= 0 && e.Button == MouseButtons.Left)
  1268. {
  1269. if (operationK == 0)
  1270. {
  1271. startPoint = endPoint = downPoint;
  1272. nowLine = new PointF[4];
  1273. nowLine[0] = startPoint;
  1274. nowLine[1] = endPoint;
  1275. pointList1.Add(nowLine);
  1276. }
  1277. else if (operationK == 1)
  1278. {
  1279. lastPoint.X = downPoint.X;
  1280. lastPoint.Y = downPoint.Y;
  1281. tempPoint.X = downPoint.X;
  1282. tempPoint.Y = downPoint.Y;
  1283. for (int i = rectangleFList.Count - 1; i >= 0; i--)
  1284. {
  1285. if (rectangleFList[i].Contains(downPoint))
  1286. {
  1287. selected = i;
  1288. canMove = true;
  1289. }
  1290. }
  1291. if (selected > -1 && pointList1 != null && pointList1.Count > 0)
  1292. {
  1293. int tempLess = (int)(InvariantData.rectless * (this.documentWorkspace.ScaleFactor.Ratio < 1 ? 1 / this.documentWorkspace.ScaleFactor.Ratio : 1)) * 5;
  1294. int tempPlus = (int)(InvariantData.rectplus * (this.documentWorkspace.ScaleFactor.Ratio < 1 ? 1 / this.documentWorkspace.ScaleFactor.Ratio : 1)) * 5;
  1295. if (new RectangleF(pointList1[selected][0].X - tempLess, pointList1[selected][0].Y - tempLess, tempPlus, tempPlus).Contains(downPoint))
  1296. movePointIndex = 0;
  1297. else if (new RectangleF(pointList1[selected][1].X - tempLess, pointList1[selected][1].Y - tempLess, tempPlus, tempPlus).Contains(downPoint))
  1298. movePointIndex = 1;
  1299. else
  1300. movePointIndex = -1;
  1301. this.documentWorkspace.Refresh();
  1302. }
  1303. if (canMove)
  1304. return;
  1305. selected = -1;
  1306. }
  1307. }
  1308. else if (e.Button == MouseButtons.Left)
  1309. {
  1310. if (isLunKuo)
  1311. {
  1312. if (pointList.Count == 0)
  1313. {
  1314. pointList.Add(downPoint);
  1315. pointList.Add(downPoint);
  1316. }
  1317. else
  1318. {
  1319. pointList.Add(downPoint);
  1320. }
  1321. }
  1322. if (isAddKong)
  1323. {
  1324. List<PointF> pl = new List<PointF>();
  1325. pl.Add(downPoint);
  1326. kongLineList.Add(pl);
  1327. //if (kongPointList.Count == 0)
  1328. //{
  1329. // kongPointList.Add(downPoint);
  1330. // kongPointList.Add(downPoint);
  1331. //}
  1332. //else
  1333. //{
  1334. // kongPointList.Add(downPoint);
  1335. //}
  1336. }
  1337. if (isDelKong)
  1338. {
  1339. delPointList.Add(downPoint);
  1340. List<List<int>> CircleDate = binaryClass.DeleteCrystal( delPointList, kongLineList);
  1341. bindGrid(CircleDate);
  1342. }
  1343. }
  1344. if (e.Button == MouseButtons.Right)
  1345. {
  1346. if (isLunKuo)
  1347. {
  1348. if (pointList.Count > 2)
  1349. {
  1350. pointList.RemoveAt(pointList.Count - 1);
  1351. List<PointF> pointFs = new List<PointF>(pointList.ToArray());
  1352. lineList.Add(pointFs);
  1353. }
  1354. pointList.Clear();
  1355. }
  1356. if (isAddKong)
  1357. {
  1358. if (kongPointList.Count > 2)
  1359. {
  1360. kongPointList.RemoveAt(kongPointList.Count - 1);
  1361. List<PointF> pointFs = new List<PointF>(kongPointList.ToArray());
  1362. kongLineList.Add(pointFs);
  1363. List<List<int>> CircleDate = binaryClass.DeleteCrystal(delPointList, kongLineList);
  1364. bindGrid(CircleDate);
  1365. }
  1366. kongPointList.Clear();
  1367. }
  1368. if (isDelKong)
  1369. {
  1370. //if (delPointList.Count > 2)
  1371. //{
  1372. // delPointList.RemoveAt(delPointList.Count - 1);
  1373. // List<PointF> pointFs = new List<PointF>(delPointList.ToArray());
  1374. // delLineList.Add(pointFs);
  1375. //}
  1376. //delPointList.Clear();
  1377. }
  1378. isLunKuo = false;
  1379. isAddKong = false;
  1380. isDelKong = false;
  1381. }
  1382. }
  1383. /// <summary>
  1384. /// Ctrl+z
  1385. /// </summary>
  1386. private void OnKeyDown(object sender, KeyEventArgs e)
  1387. {
  1388. if (e.Control && e.KeyCode == Keys.Z)
  1389. {
  1390. if (isLunKuo)
  1391. {
  1392. int cou = pointList.Count;
  1393. if (cou > 1)
  1394. {
  1395. if (cou == 2)
  1396. {
  1397. pointList.Clear();
  1398. }
  1399. else
  1400. {
  1401. pointList.RemoveAt(cou - 1);
  1402. }
  1403. }
  1404. else if (lineList.Count > 0)
  1405. {
  1406. pointList = lineList[lineList.Count - 1];
  1407. lineList.RemoveAt(lineList.Count - 1);
  1408. pointList.RemoveAt(pointList.Count - 1);
  1409. }
  1410. }
  1411. if (isAddKong)
  1412. {
  1413. if (kongLineList.Count > 0)
  1414. {
  1415. kongLineList.RemoveAt(kongLineList.Count - 1);
  1416. List<List<int>> CircleDate = binaryClass.DeleteCrystal(delPointList, kongLineList);
  1417. bindGrid(CircleDate);
  1418. }
  1419. }
  1420. if (isDelKong)
  1421. {
  1422. int cou = delPointList.Count;
  1423. if (cou > 0)
  1424. {
  1425. delPointList.RemoveAt(cou - 1);
  1426. List<List<int>> CircleDate = binaryClass.DeleteCrystal(delPointList, kongLineList);
  1427. bindGrid(CircleDate);
  1428. }
  1429. }
  1430. this.documentWorkspace.Refresh();
  1431. }
  1432. }
  1433. #endregion
  1434. /// <summary>
  1435. /// 统计导出
  1436. /// </summary>
  1437. /// <param name="sender"></param>
  1438. /// <param name="e"></param>
  1439. private void button14_Click(object sender, EventArgs e)
  1440. {
  1441. if (this.listView1.Items.Count == 0)
  1442. {
  1443. return;
  1444. }
  1445. //保留小数位数
  1446. int numDec = Convert.ToInt32(numericNum.Value);
  1447. string name = this.listView1.FocusedItem.Name.Substring(0, this.listView1.FocusedItem.Name.LastIndexOf('.')) ;
  1448. SaveFileDialog exe = new SaveFileDialog();
  1449. exe.Filter = "Execl files (*.xlsx)|*.xlsx";
  1450. exe.FilterIndex = 0;
  1451. exe.RestoreDirectory = true;
  1452. //exe.CreatePrompt = true;
  1453. exe.Title = "Export Excel File";
  1454. // exe.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  1455. exe.FileName = name + "-";
  1456. String str = System.Configuration.ConfigurationManager.AppSettings["FolderSelectedPath"];
  1457. DialogResult dr = exe.ShowDialog();
  1458. if (dr != DialogResult.OK)
  1459. {
  1460. return;
  1461. }
  1462. DataTable dtb = new DataTable();
  1463. dtb.Columns.Add("序号");
  1464. dtb.Columns.Add("位置");
  1465. dtb.Columns.Add("卡规直径/"+ unString);
  1466. dtb.Columns.Add("长径/" + unString);
  1467. dtb.Columns.Add("短径/" + unString);
  1468. dtb.Columns.Add("拟圆直径/" + unString);
  1469. List<double> diameter = new List<double>() { };
  1470. List<double> diameterPi = new List<double>() { };
  1471. int inde = 1; int current = 1;
  1472. foreach (ListViewItem item in listView1.Items)
  1473. {
  1474. binaryClass.tipString = "正在处理" + (current++).ToString() + "/" + listView1.Items.Count.ToString() + "," + item.Name + "。";
  1475. listView1.FocusedItem = item;
  1476. this.listView1.FocusedItem.Selected = true;
  1477. for (int r = 0; r < this.dataGridView1.Rows.Count; r++)
  1478. {
  1479. DataRow dataRow = dtb.NewRow();
  1480. dataRow[0] = (inde++).ToString();
  1481. dataRow[1] = dataGridView1.Rows[r].Cells[1].Value.ToString();
  1482. dataRow[2] = dataGridView1.Rows[r].Cells[2].Value.ToString();
  1483. dataRow[3] = dataGridView1.Rows[r].Cells[4].Value.ToString();
  1484. dataRow[4] = dataGridView1.Rows[r].Cells[5].Value.ToString();
  1485. dataRow[5] = dataGridView1.Rows[r].Cells[6].Value.ToString();
  1486. dtb.Rows.Add(dataRow);
  1487. diameter.Add(Convert.ToDouble(dataRow[2]));
  1488. diameterPi.Add(Convert.ToDouble(dataRow[5]));
  1489. }
  1490. }
  1491. DataTable dt = new DataTable();
  1492. dt = CreatTable(diameter, diameter);
  1493. CreatChart(dt);
  1494. #region 统计表
  1495. int count = diameter.Count;
  1496. if (count == 0)
  1497. {
  1498. MessageBox.Show("数据为空,请设置好筛选条件!");
  1499. return;
  1500. }
  1501. diameter.Sort();
  1502. diameterPi.Sort();
  1503. List<double> valueList = new List<double>();
  1504. int d1 = Convert.ToInt32(count * 0.01);
  1505. int d5 = Convert.ToInt32(count * 0.05);
  1506. int d10 = Convert.ToInt32(count * 0.1);
  1507. int d50 = Convert.ToInt32(count * 0.5);
  1508. int d90 = Convert.ToInt32(count * 0.9);
  1509. int d95 = Convert.ToInt32(count * 0.95);
  1510. int d99 = Convert.ToInt32(count * 0.99);
  1511. d1 = d1 >= count ? count - 1 : d1;
  1512. d5 = d5 >= count ? count - 1 : d5;
  1513. d10 = d10 >= count ? count - 1 : d10;
  1514. d50 = d50 >= count ? count - 1 : d50;
  1515. d90 = d90 >= count ? count - 1 : d90;
  1516. d95 = d95 >= count ? count - 1 : d95;
  1517. d99 = d99 >= count ? count - 1 : d99;
  1518. double[] values = new double[] { diameter.Average(), diameter.Count, diameterPi.Average(), diameter.Min(), diameter[d1], diameter[d5], diameter[d10], diameter[d50], diameter[d90], diameter[d95], diameter[d99], diameter.Max() };
  1519. string[] names = new string[] { "卡规直径", "颗粒数量", "拟圆直径", "Dmin", "D1", "D5", "D10", "D50", "D90", "D95", "D99", "Dmax"};
  1520. #endregion
  1521. #region 前4行批号加统计
  1522. DataTable dtb0 = new DataTable();
  1523. dtb0.Columns.Add("批号");
  1524. dtb0.Columns.Add(name);
  1525. DataRow dataRuler = dtb0.NewRow();
  1526. dataRuler[0] = "标尺";
  1527. dataRuler[1] = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].xmlSaveModel.ruler_name;
  1528. dtb0.Rows.Add(dataRuler);
  1529. if (ckMin.Checked)
  1530. {
  1531. DataRow dataMin = dtb0.NewRow();
  1532. dataMin[0] = "最小尺寸";
  1533. dataMin[1] = numericUpDown11.Value.ToString() + unString;
  1534. dtb0.Rows.Add(dataMin);
  1535. }
  1536. if (ckMax.Checked)
  1537. {
  1538. DataRow dataBorder = dtb0.NewRow();
  1539. dataBorder[0] = "边界尺寸";
  1540. dataBorder[1] = numericMax.Value.ToString() + "像素";
  1541. dtb0.Rows.Add(dataBorder);
  1542. }
  1543. if (ckHW.Checked)
  1544. {
  1545. DataRow dataHw = dtb0.NewRow();
  1546. dataHw[0] = "长宽比例";
  1547. dataHw[1] = numericHW.Value.ToString();
  1548. dtb0.Rows.Add(dataHw);
  1549. }
  1550. if (ckArea.Checked)
  1551. {
  1552. DataRow dataArea = dtb0.NewRow();
  1553. dataArea[0] = "面积率";
  1554. dataArea[1] = numericArea.Value.ToString();
  1555. dtb0.Rows.Add(dataArea);
  1556. }
  1557. DataRow dataNone = dtb0.NewRow();
  1558. dataNone[0] = ""; dataNone[1] = "";
  1559. dtb0.Rows.Add(dataNone);
  1560. DataTable dtb1 = new DataTable();
  1561. dtb1.Columns.Add("序号");
  1562. for (int i = 1; i < 13; i++)
  1563. {
  1564. dtb1.Columns.Add(i.ToString());
  1565. }
  1566. DataRow dataRowName = dtb1.NewRow();
  1567. dataRowName[0] = "名称";
  1568. DataRow dataRowValue = dtb1.NewRow();
  1569. dataRowValue[0] = "值/"+ unString;
  1570. DataRow dataRowNone = dtb1.NewRow();
  1571. dataRowNone[0] = "";
  1572. for (int r = 0; r < this.dataGridView2.Rows.Count; r++)
  1573. {
  1574. dataRowName[r + 1] = names[r];
  1575. dataRowValue[r + 1] = Math.Round(values[r], numDec).ToString();
  1576. dataRowNone[r + 1] = "";
  1577. }
  1578. dtb1.Rows.Add(dataRowName);
  1579. dtb1.Rows.Add(dataRowValue);
  1580. dtb1.Rows.Add(dataRowNone);
  1581. #endregion
  1582. #region 分布统计
  1583. DataTable dtb2 = new DataTable();
  1584. dtb2.Columns.Add("序号");
  1585. dtb2.Columns.Add("颗粒尺寸x");
  1586. dtb2.Columns.Add("数量");
  1587. double eval = 0.3;
  1588. for (int i = 0; i < dt.Rows.Count; i++)
  1589. {
  1590. DataRow dtChartRow = dtb2.NewRow();
  1591. dtChartRow[0] = (i + 1).ToString();
  1592. double low = eval * i;
  1593. double high = eval * i + eval;
  1594. if (i == dt.Rows.Count - 1)
  1595. {
  1596. dtChartRow[1] = ("x>5.7");
  1597. }
  1598. else
  1599. {
  1600. dtChartRow[1] = string.Format("{0}<x≤{1}", low, high);
  1601. }
  1602. dtChartRow[2] = (dt.Rows[i]["sum"]).ToString();
  1603. dtb2.Rows.Add(dtChartRow);
  1604. }
  1605. #endregion
  1606. int index = exe.FileName.LastIndexOf('\\');
  1607. string GR_Path = exe.FileName.Remove(index) + "\\" + name + ".jpg";
  1608. chart1.SaveImage(GR_Path, System.Windows.Forms.DataVisualization.Charting.ChartImageFormat.Jpeg);
  1609. List<DataTable> list = new List<DataTable>();
  1610. list.Add(dtb0);
  1611. list.Add(dtb1);
  1612. list.Add(dtb2);
  1613. list.Add(dtb);
  1614. List<string> pics = new List<string>() { GR_Path + ",400,200," + chart1.Width + "," + chart1.Height };
  1615. this.appWorkspace.ExportDataToExcelWithProgress(list, exe.FileName, true, false, true, null, null, pics);
  1616. }
  1617. /// <summary>
  1618. /// 批量导出
  1619. /// </summary>
  1620. /// <param name="sender"></param>
  1621. /// <param name="e"></param>
  1622. private void btnAll_Click(object sender, EventArgs e)
  1623. {
  1624. if (this.listView1.Items.Count == 0)
  1625. {
  1626. return;
  1627. }
  1628. string name = this.listView1.FocusedItem.Name.Substring(0, this.listView1.FocusedItem.Name.LastIndexOf('.'));
  1629. SaveFileDialog exe = new SaveFileDialog();
  1630. exe.Filter = "Execl files (*.xlsx)|*.xlsx";
  1631. exe.FilterIndex = 0;
  1632. exe.RestoreDirectory = true;
  1633. //exe.CreatePrompt = true;
  1634. exe.Title = "Export Excel File";
  1635. // exe.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  1636. exe.FileName = name + "-";
  1637. String str = System.Configuration.ConfigurationManager.AppSettings["FolderSelectedPath"];
  1638. DialogResult dr = exe.ShowDialog();
  1639. if (dr != DialogResult.OK)
  1640. {
  1641. return;
  1642. }
  1643. DataTable totla = new DataTable();
  1644. totla.Columns.Add("序号");
  1645. for (int i = 1; i < 13; i++)
  1646. {
  1647. totla.Columns.Add(i.ToString());
  1648. }
  1649. DataRow totlaRowName = totla.NewRow();
  1650. totlaRowName[0] = "名称";
  1651. for (int r = 0; r < this.dataGridView2.Rows.Count; r++)
  1652. {
  1653. totlaRowName[r + 1] = dataGridView2.Rows[r].Cells[1].Value.ToString();
  1654. }
  1655. totla.Rows.Add(totlaRowName);
  1656. List<List<System.Data.DataTable>> datasMore = new List<List<DataTable>>();
  1657. List<List<string>> bitmapListMore = new List<List<string>>();
  1658. int current = 1;
  1659. foreach (ListViewItem item in listView1.Items)
  1660. {
  1661. binaryClass.tipString = "正在处理" + (current++).ToString() + "/" + listView1.Items.Count.ToString() + "," + item.Name + "。";
  1662. listView1.FocusedItem = item;
  1663. this.listView1.FocusedItem.Selected = true;
  1664. name = this.listView1.FocusedItem.Name.Substring(0, this.listView1.FocusedItem.Name.LastIndexOf('.'));
  1665. #region 颗粒信息
  1666. DataTable dtb = new DataTable();
  1667. dtb.Columns.Add("序号");
  1668. dtb.Columns.Add("位置");
  1669. dtb.Columns.Add("卡规直径/"+unString);
  1670. dtb.Columns.Add("长径/" + unString);
  1671. dtb.Columns.Add("短径/" + unString);
  1672. dtb.Columns.Add("拟圆直径/" + unString);
  1673. for (int r = 0; r < this.dataGridView1.Rows.Count; r++)
  1674. {
  1675. DataRow dataRow = dtb.NewRow();
  1676. dataRow[0] = dataGridView1.Rows[r].Cells[0].Value.ToString();
  1677. dataRow[1] = dataGridView1.Rows[r].Cells[1].Value.ToString();
  1678. dataRow[2] = dataGridView1.Rows[r].Cells[2].Value.ToString();
  1679. dataRow[3] = dataGridView1.Rows[r].Cells[4].Value.ToString();
  1680. dataRow[4] = dataGridView1.Rows[r].Cells[5].Value.ToString();
  1681. dataRow[5] = dataGridView1.Rows[r].Cells[6].Value.ToString();
  1682. dtb.Rows.Add(dataRow);
  1683. }
  1684. #endregion
  1685. #region 前4行批号加统计
  1686. DataRow totlaRowValue = totla.NewRow();//统计显示
  1687. DataTable dtb0 = new DataTable();
  1688. dtb0.Columns.Add("批号");
  1689. dtb0.Columns.Add(name);
  1690. DataRow dataRuler = dtb0.NewRow();
  1691. dataRuler[0] = "标尺";
  1692. dataRuler[1] = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].xmlSaveModel.ruler_name;
  1693. dtb0.Rows.Add(dataRuler);
  1694. if (ckMin.Checked)
  1695. {
  1696. DataRow dataMin = dtb0.NewRow();
  1697. dataMin[0] = "最小尺寸";
  1698. dataMin[1] = numericUpDown11.Value.ToString() + unString;
  1699. dtb0.Rows.Add(dataMin);
  1700. }
  1701. if (ckMax.Checked)
  1702. {
  1703. DataRow dataBorder = dtb0.NewRow();
  1704. dataBorder[0] = "边界尺寸";
  1705. dataBorder[1] = numericMax.Value.ToString() + "像素";
  1706. dtb0.Rows.Add(dataBorder);
  1707. }
  1708. if (ckHW.Checked)
  1709. {
  1710. DataRow dataHw = dtb0.NewRow();
  1711. dataHw[0] = "长宽比例";
  1712. dataHw[1] = numericHW.Value.ToString();
  1713. dtb0.Rows.Add(dataHw);
  1714. }
  1715. if (ckArea.Checked)
  1716. {
  1717. DataRow dataArea = dtb0.NewRow();
  1718. dataArea[0] = "面积率";
  1719. dataArea[1] = numericArea.Value.ToString();
  1720. dtb0.Rows.Add(dataArea);
  1721. }
  1722. DataRow dataNone = dtb0.NewRow();
  1723. dataNone[0] = ""; dataNone[1] = "";
  1724. dtb0.Rows.Add(dataNone);
  1725. totlaRowValue[0] = name;
  1726. DataTable dtb1 = new DataTable();
  1727. dtb1.Columns.Add("序号");
  1728. for (int i = 1; i < 13; i++)
  1729. {
  1730. dtb1.Columns.Add(i.ToString());
  1731. }
  1732. DataRow dataRowName = dtb1.NewRow();
  1733. dataRowName[0] = "名称";
  1734. DataRow dataRowValue = dtb1.NewRow();
  1735. dataRowValue[0] = "值/" + unString;
  1736. DataRow dataRowNone = dtb1.NewRow();
  1737. dataRowNone[0] = "";
  1738. for (int r = 0; r < this.dataGridView2.Rows.Count; r++)
  1739. {
  1740. dataRowName[r + 1] = dataGridView2.Rows[r].Cells[1].Value.ToString();
  1741. dataRowValue[r + 1] = dataGridView2.Rows[r].Cells[2].Value.ToString();
  1742. totlaRowValue[r + 1] = dataGridView2.Rows[r].Cells[2].Value.ToString();
  1743. dataRowNone[r + 1] = "";
  1744. }
  1745. dtb1.Rows.Add(dataRowName);
  1746. dtb1.Rows.Add(dataRowValue);
  1747. dtb1.Rows.Add(dataRowNone);
  1748. totla.Rows.Add(totlaRowValue);
  1749. #endregion
  1750. #region 分布统计
  1751. DataTable dtb2 = new DataTable();
  1752. dtb2.Columns.Add("序号");
  1753. dtb2.Columns.Add("颗粒尺寸x");
  1754. dtb2.Columns.Add("数量");
  1755. double eval = 0.3;
  1756. for (int i = 0; i < dtChart.Rows.Count; i++)
  1757. {
  1758. DataRow dtChartRow = dtb2.NewRow();
  1759. dtChartRow[0] = (i + 1).ToString();
  1760. double low = eval * i;
  1761. double high = eval * i + eval;
  1762. if (i == dtChart.Rows.Count - 1)
  1763. {
  1764. dtChartRow[1] = ("x>5.7");
  1765. }
  1766. else
  1767. {
  1768. dtChartRow[1] = string.Format("{0}<x≤{1}", low, high);
  1769. }
  1770. dtChartRow[2] = (dtChart.Rows[i]["sum"]).ToString();
  1771. dtb2.Rows.Add(dtChartRow);
  1772. }
  1773. #endregion
  1774. #region 图片导出
  1775. int index = exe.FileName.LastIndexOf('\\');
  1776. string GR_Path = exe.FileName.Remove(index) + "\\" + name + "-.jpg";
  1777. chart1.SaveImage(GR_Path, System.Windows.Forms.DataVisualization.Charting.ChartImageFormat.Jpeg);
  1778. //保存处理后的图片
  1779. double pantographRatio = (double)this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetRulerMultiple(MeasurementUnit.Micron);//标尺*放大倍数
  1780. List<Bitmap> tempBit = new List<Bitmap>();
  1781. Bitmap originalBit = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap();
  1782. originalBit.Tag = pantographRatio;
  1783. tempBit.Add(originalBit);
  1784. Bitmap processedBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.documentWorkspace.PhaseModels[0].mat);
  1785. Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  1786. Graphics graphics = Graphics.FromImage(newBit);
  1787. graphics.DrawImage(processedBit, new PointF(0, 0));
  1788. Draw(graphics);
  1789. newBit.Tag = pantographRatio;
  1790. tempBit.Add(newBit);
  1791. string GR_Path1 = exe.FileName.Remove(index) + "\\" + name + "-1.jpg";
  1792. newBit.Save(GR_Path1);
  1793. #endregion
  1794. List<DataTable> list = new List<DataTable>();
  1795. list.Add(dtb0);
  1796. list.Add(dtb1);
  1797. list.Add(dtb2);
  1798. list.Add(dtb);
  1799. List<string> pics = new List<string>() { GR_Path + ",150,150," + chart1.Width / 3 + "," + chart1.Height / 3, GR_Path1 + ",10,450," + newBit.Width / 3 + "," + newBit.Height / 3 };
  1800. datasMore.Add(list);
  1801. bitmapListMore.Add(pics);
  1802. }
  1803. List<DataTable> listmore = new List<DataTable>() { totla };
  1804. datasMore.Insert(0, listmore);
  1805. this.appWorkspace.ExportDataToExcelWithProgressForCrystal(datasMore, bitmapListMore, exe.FileName, null);
  1806. }
  1807. /// <summary>
  1808. /// 不可点击空白区域
  1809. /// </summary>
  1810. /// <param name="sender"></param>
  1811. /// <param name="e"></param>
  1812. private void listView1_MouseUp(object sender, MouseEventArgs e)
  1813. {
  1814. if (e.Button == MouseButtons.Left)
  1815. {
  1816. if (listView1.SelectedItems.Count > 0)
  1817. {
  1818. }
  1819. else if (listView1.SelectedItems.Count <= 0)//点击空白区
  1820. {
  1821. if (this.listView1.FocusedItem != null)
  1822. {
  1823. ListViewItem item = this.listView1.GetItemAt(e.X, e.Y);
  1824. if (item == null)
  1825. {
  1826. this.listView1.FocusedItem.Selected = true;
  1827. }
  1828. }
  1829. }
  1830. }
  1831. }
  1832. /// <summary>
  1833. /// 导出
  1834. /// </summary>
  1835. /// <param name="sender"></param>
  1836. /// <param name="e"></param>
  1837. private void button13_Click(object sender, EventArgs e)
  1838. {
  1839. if (this.listView1.Items.Count == 0)
  1840. {
  1841. return;
  1842. }
  1843. string name = this.listView1.FocusedItem.Name.Substring(0, this.listView1.FocusedItem.Name.LastIndexOf('.'));
  1844. SaveFileDialog exe = new SaveFileDialog();
  1845. exe.Filter = "Execl files (*.xlsx)|*.xlsx";
  1846. exe.FilterIndex = 0;
  1847. exe.RestoreDirectory = true;
  1848. //exe.CreatePrompt = true;
  1849. exe.Title = "Export Excel File";
  1850. // exe.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  1851. exe.FileName = name+"-";
  1852. String str = System.Configuration.ConfigurationManager.AppSettings["FolderSelectedPath"];
  1853. DialogResult dr = exe.ShowDialog();
  1854. if (dr != DialogResult.OK)
  1855. {
  1856. return;
  1857. }
  1858. #region 颗粒信息
  1859. DataTable dtb = new DataTable();
  1860. dtb.Columns.Add("序号");
  1861. dtb.Columns.Add("位置");
  1862. dtb.Columns.Add("卡规直径/" + unString);
  1863. dtb.Columns.Add("长径/" + unString);
  1864. dtb.Columns.Add("短径/" + unString);
  1865. dtb.Columns.Add("拟圆直径/" + unString);
  1866. for (int r = 0; r < this.dataGridView1.Rows.Count; r++)
  1867. {
  1868. DataRow dataRow = dtb.NewRow();
  1869. dataRow[0] = dataGridView1.Rows[r].Cells[0].Value.ToString();
  1870. dataRow[1] = dataGridView1.Rows[r].Cells[1].Value.ToString();
  1871. dataRow[2] = dataGridView1.Rows[r].Cells[2].Value.ToString();
  1872. dataRow[3] = dataGridView1.Rows[r].Cells[4].Value.ToString();
  1873. dataRow[4] = dataGridView1.Rows[r].Cells[5].Value.ToString();
  1874. dataRow[5] = dataGridView1.Rows[r].Cells[6].Value.ToString();
  1875. dtb.Rows.Add(dataRow);
  1876. }
  1877. #endregion
  1878. #region 前4行批号加统计
  1879. DataTable dtb0 = new DataTable();
  1880. dtb0.Columns.Add("批号");
  1881. dtb0.Columns.Add(name);
  1882. DataRow dataRuler = dtb0.NewRow();
  1883. dataRuler[0] = "标尺";
  1884. dataRuler[1] = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].xmlSaveModel.ruler_name;
  1885. dtb0.Rows.Add(dataRuler);
  1886. if (ckMin.Checked)
  1887. {
  1888. DataRow dataMin = dtb0.NewRow();
  1889. dataMin[0] = "最小尺寸";
  1890. dataMin[1] = numericUpDown11.Value.ToString() + unString;
  1891. dtb0.Rows.Add(dataMin);
  1892. }
  1893. if (ckMax.Checked)
  1894. {
  1895. DataRow dataBorder = dtb0.NewRow();
  1896. dataBorder[0] = "边界尺寸";
  1897. dataBorder[1] = numericMax.Value.ToString() + "像素";
  1898. dtb0.Rows.Add(dataBorder);
  1899. }
  1900. if (ckHW.Checked)
  1901. {
  1902. DataRow dataHw = dtb0.NewRow();
  1903. dataHw[0] = "长宽比例";
  1904. dataHw[1] = numericHW.Value.ToString();
  1905. dtb0.Rows.Add(dataHw);
  1906. }
  1907. if (ckArea.Checked)
  1908. {
  1909. DataRow dataArea = dtb0.NewRow();
  1910. dataArea[0] = "面积率";
  1911. dataArea[1] = numericArea.Value.ToString();
  1912. dtb0.Rows.Add(dataArea);
  1913. }
  1914. DataRow dataNone = dtb0.NewRow();
  1915. dataNone[0] = ""; dataNone[1] = "";
  1916. dtb0.Rows.Add(dataNone);
  1917. DataTable dtb1 = new DataTable();
  1918. dtb1.Columns.Add("序号");
  1919. for (int i = 1; i < 13; i++)
  1920. {
  1921. dtb1.Columns.Add(i.ToString());
  1922. }
  1923. DataRow dataRowName = dtb1.NewRow();
  1924. dataRowName[0] = "名称";
  1925. DataRow dataRowValue = dtb1.NewRow();
  1926. dataRowValue[0] = "值/" + unString;
  1927. DataRow dataRowNone = dtb1.NewRow();
  1928. dataRowNone[0] = "";
  1929. for (int r = 0; r < this.dataGridView2.Rows.Count; r++)
  1930. {
  1931. dataRowName[r+1]= dataGridView2.Rows[r].Cells[1].Value.ToString();
  1932. dataRowValue[r + 1] = dataGridView2.Rows[r].Cells[2].Value.ToString();
  1933. dataRowNone[r + 1] = "";
  1934. }
  1935. dtb1.Rows.Add(dataRowName);
  1936. dtb1.Rows.Add(dataRowValue);
  1937. dtb1.Rows.Add(dataRowNone);
  1938. #endregion
  1939. #region 分布统计
  1940. DataTable dtb2 = new DataTable();
  1941. dtb2.Columns.Add("序号");
  1942. dtb2.Columns.Add("颗粒尺寸x");
  1943. dtb2.Columns.Add("数量");
  1944. double eval = 0.3;
  1945. for (int i = 0; i < dtChart.Rows.Count; i++)
  1946. {
  1947. DataRow dtChartRow = dtb2.NewRow();
  1948. dtChartRow[0] = (i + 1).ToString();
  1949. double low = eval * i;
  1950. double high = eval * i + eval;
  1951. if (i == dtChart.Rows.Count - 1)
  1952. {
  1953. dtChartRow[1] = ("x>5.7");
  1954. }
  1955. else
  1956. {
  1957. dtChartRow[1] = string.Format("{0}<x≤{1}", low, high);
  1958. }
  1959. dtChartRow[2] = (dtChart.Rows[i]["sum"]).ToString();
  1960. dtb2.Rows.Add(dtChartRow);
  1961. }
  1962. #endregion
  1963. #region 图片导出
  1964. int index = exe.FileName.LastIndexOf('\\');
  1965. string GR_Path = exe.FileName.Remove(index)+"\\"+ name + "-.jpg";
  1966. chart1.SaveImage(GR_Path, System.Windows.Forms.DataVisualization.Charting.ChartImageFormat.Jpeg);
  1967. //保存处理后的图片
  1968. double pantographRatio = (double)this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetRulerMultiple(MeasurementUnit.Micron);//标尺*放大倍数
  1969. List<Bitmap> tempBit = new List<Bitmap>();
  1970. Bitmap originalBit = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap();
  1971. originalBit.Tag = pantographRatio;
  1972. tempBit.Add(originalBit);
  1973. Bitmap processedBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.documentWorkspace.PhaseModels[0].mat);
  1974. Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  1975. Graphics graphics = Graphics.FromImage(newBit);
  1976. graphics.DrawImage(processedBit, new PointF(0, 0));
  1977. Draw(graphics);
  1978. newBit.Tag = pantographRatio;
  1979. tempBit.Add(newBit);
  1980. string GR_Path1 = exe.FileName.Remove(index) + "\\" + name + "-1.jpg";
  1981. newBit.Save(GR_Path1);
  1982. #endregion
  1983. List<DataTable> list = new List<DataTable>();
  1984. list.Add(dtb0);
  1985. list.Add(dtb1);
  1986. list.Add(dtb2);
  1987. list.Add(dtb);
  1988. List<string> pics = new List<string>() { GR_Path + ",150,150," + chart1.Width/3 + "," + chart1.Height/3, GR_Path1 + ",10,450," + newBit.Width/3 + "," + newBit.Height/3 };
  1989. this.appWorkspace.ExportDataToExcelWithProgress(list, exe.FileName, true, false, true, null, null,pics);
  1990. }
  1991. #region 辅助测量
  1992. /// <summary>
  1993. /// 添加测量线
  1994. /// </summary>
  1995. /// <param name="sender"></param>
  1996. /// <param name="e"></param>
  1997. private void btnAddCeliang_Click(object sender, EventArgs e)
  1998. {
  1999. operationK = 0;
  2000. selected = -1;
  2001. this.documentWorkspace.Refresh();
  2002. }
  2003. /// <summary>
  2004. /// 选择测量线
  2005. /// </summary>
  2006. /// <param name="sender"></param>
  2007. /// <param name="e"></param>
  2008. private void btnSelCeliang_Click(object sender, EventArgs e)
  2009. {
  2010. operationK = 1;
  2011. }
  2012. /// <summary>
  2013. /// 删除测量线
  2014. /// </summary>
  2015. /// <param name="sender"></param>
  2016. /// <param name="e"></param>
  2017. private void btnDelCeliang_Click(object sender, EventArgs e)
  2018. {
  2019. if (selected > -1)
  2020. {
  2021. DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Areyousuretodmeasurementline.text") + "?", PdnResources.GetString("Menu.alert.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
  2022. if (dr == DialogResult.OK)
  2023. {
  2024. this.pointList1.Remove(this.pointList1[selected]);
  2025. this.rectangleFList.Remove(this.rectangleFList[selected]);
  2026. selected = -1;
  2027. lineCount--;
  2028. this.documentWorkspace.Refresh();
  2029. }
  2030. }
  2031. else
  2032. MessageBox.Show("请先选择测量线");
  2033. }
  2034. /// <summary>
  2035. /// 添加测量线按钮失去焦点
  2036. /// </summary>
  2037. /// <param name="sender"></param>
  2038. /// <param name="e"></param>
  2039. private void btnAddCeliang_LostFocus(object sender, EventArgs e)
  2040. {
  2041. operationK = -1;
  2042. selected = -1;
  2043. this.documentWorkspace.Refresh();
  2044. }
  2045. #endregion
  2046. #region 内部类
  2047. internal class LocalListViewItem
  2048. {
  2049. public DocumentWorkspace Value { get; }
  2050. public string Display { get; }
  2051. public LocalListViewItem(DocumentWorkspace Value, string Display)
  2052. {
  2053. this.Value = Value;
  2054. this.Display = Display;
  2055. }
  2056. }
  2057. internal class DocumentItem
  2058. {
  2059. public Bitmap bitmap;
  2060. public GraphicsList graphicsList;
  2061. public List<PhaseModel> phaseModels;
  2062. //public AnalysisResult analysisResult;
  2063. public DocumentItem(Bitmap bitmap, GraphicsList graphicsList, List<PhaseModel> phaseModels)
  2064. {
  2065. this.bitmap = bitmap;
  2066. this.graphicsList = graphicsList;
  2067. this.phaseModels = phaseModels;
  2068. }
  2069. }
  2070. #endregion
  2071. #endregion
  2072. }
  2073. }