BatteryCrystalDialog.cs 92 KB

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