Membranes.cs 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398
  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.IO;
  18. using System.Linq;
  19. using System.Text;
  20. using System.Windows.Forms;
  21. namespace PaintDotNet.DedicatedAnalysis.Battery
  22. {
  23. internal partial class Membranes : PdnBaseForm
  24. {
  25. #region 属性
  26. //二值化集成1
  27. BinaryClassForB binaryClass;
  28. private int menuId;
  29. /// <summary>
  30. /// 选中图片的bitmap
  31. /// </summary>
  32. private Bitmap bitmap;
  33. /// <summary>
  34. /// 存在视场标记
  35. /// </summary>
  36. private bool existViewFlag = false;
  37. private int changeCount;
  38. /// <summary>
  39. /// 主空间
  40. /// </summary>
  41. private AppWorkspace appWorkspace;
  42. /// <summary>
  43. /// 图像面板
  44. /// </summary>
  45. private DocumentWorkspaceWindow documentWorkspace;
  46. /// <summary>
  47. /// 公共控件
  48. /// </summary>
  49. private GeneralAnalysisCommonControlButtons commonControlButtons;
  50. /// <summary>
  51. /// 图片测量记录
  52. /// </summary>
  53. private List<DataTable> pictureDataTables = new List<DataTable>();
  54. /// <summary>
  55. /// 网格Xml
  56. /// </summary>
  57. private GrainSizePointCountingMethodModel grainSizePointCountingMethodModel;
  58. /// <summary>
  59. /// 数据变化
  60. /// </summary>
  61. private bool saveSuccess = false;
  62. private BinaryControlSmaller bc;
  63. #endregion 属性
  64. #region 数据属性
  65. /// <summary>
  66. /// 折线点的集合
  67. /// </summary>
  68. public List<System.Drawing.Point> pointArray = new List<System.Drawing.Point>();
  69. /// <summary>
  70. /// 存储所有轮廓线的点集合
  71. /// </summary>
  72. private List<PointF> pointList = new List<PointF>();
  73. /// <summary>
  74. /// 存储所有轮廓线集合
  75. /// </summary>
  76. private List<List<PointF>> lineList = new List<List<PointF>>();
  77. /// <summary>
  78. /// 存储所有孔隙线的点集合
  79. /// </summary>
  80. private List<PointF> kongPointList = new List<PointF>();
  81. /// <summary>
  82. /// 存储所有孔隙线集合
  83. /// </summary>
  84. private List<List<PointF>> kongLineList = new List<List<PointF>>();
  85. /// <summary>
  86. /// 存储所有删除孔隙线的点集合
  87. /// </summary>
  88. private List<PointF> delPointList = new List<PointF>();
  89. /// <summary>
  90. /// 存储所有删除孔隙线集合
  91. /// </summary>
  92. private List<List<PointF>> delLineList = new List<List<PointF>>();
  93. //轮廓修改状态
  94. bool isLunKuo = false;
  95. //添加孔隙状态
  96. bool isAddKong = false;
  97. //删除孔隙状态
  98. bool isDelKong = false;
  99. //绘制轮廓
  100. bool isDrwKuo = false;
  101. //绘制轮廓结束
  102. bool DrwDone = false;
  103. #endregion
  104. /// <summary>
  105. ///
  106. /// </summary>
  107. /// <param name="appWorkspace"></param>
  108. public Membranes(AppWorkspace appWorkspace, int menuId)
  109. {
  110. this.KeyPreview = true;
  111. this.KeyDown += OnKeyDown;
  112. this.menuId = menuId;
  113. binaryClass = new BinaryClassForB(menuId);
  114. InitializeComponent();
  115. InitializeLanguageText();
  116. ColumnHeader header0 = new ColumnHeader();
  117. header0.Text = "";
  118. header0.Width = 180;
  119. this.appWorkspace = appWorkspace;
  120. this.documentWorkspace = new DocumentWorkspaceWindow(appWorkspace);
  121. this.documentWorkspace.Dock = DockStyle.Fill;
  122. this.documentWorkspace.HookMouseEvents();
  123. this.documentWorkspace.AuxiliaryLineEnabled = false;
  124. this.documentWorkspace.Visible = false;
  125. this.documentWorkspace.panel.Paint += Panel_Paint;
  126. this.documentWorkspace.panel.MouseDown += OnMouseDown;
  127. this.documentWorkspace.panel.MouseUp += OnMouseUp;
  128. this.documentWorkspace.panel.Paint += Panel_Paint;
  129. this.documentWorkspace.panel.MouseMove += onMouseMove;
  130. this.documentWorkspace.activeTool = DrawToolType.Pointer;
  131. this.groupBox7.Controls.Add(this.documentWorkspace);
  132. this.commonControlButtons = new GeneralAnalysisCommonControlButtons();
  133. this.commonControlButtons.Dock = DockStyle.Top;
  134. this.commonControlButtons.Height = 30;
  135. this.commonControlButtons.HideZoomToWindowAndActualSize();
  136. this.commonControlButtons.trackLabel.Text = "单击开始画线,右键停止。";
  137. this.commonControlButtons.trackLabel.Visible = true;
  138. this.commonControlButtons.trackLabel.Width = 300;
  139. this.commonControlButtons.Visible = false;
  140. this.groupBox7.Controls.Add(commonControlButtons);
  141. //获取
  142. //Startup.instance.rules.TryGetValue(MeasurementUnit.Micron, out ruleValue);
  143. //double ruleValue = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetRuler(MeasurementUnit.Micron);
  144. ////double physical_area_length_Micron = getCurrentWorkspace().GetRuler(MeasurementUnit.Micron);
  145. //二值化集成2
  146. bc.OriginCheckedChangedAction += new EventHandler(this.bcOriginCheckedChanged);//初始化原图勾选改变事件
  147. binaryClass.imageType = 5;
  148. binaryClass.createDocumentItemsSmaller(new string[] { "bp1" }, this.bc, this.appWorkspace, this.documentWorkspace, this.listView1);//初始化相的工作结构
  149. binaryClass.CilCount = Convert.ToInt32(txt_RightLineWeight.Text);
  150. InitCommonButtonEvent();
  151. InitGridStyle();
  152. InitPicList();
  153. // SetAnalyzeModelFromXml(getModelName());
  154. }
  155. private void ShowImgEvent(object sender, EventArgs e)
  156. {
  157. if (this.listView1.Items.Count == 0)
  158. {
  159. return;
  160. }
  161. listView1.Focus();
  162. this.listView1.Items[0].Focused = true;
  163. this.listView1.Items[0].Selected = true;
  164. }
  165. #region 二值化相关方法
  166. private void InclusionsStandardDialog_FormClosing(object sender, FormClosingEventArgs e)
  167. {
  168. binaryClass.saveParams();
  169. }
  170. private void ShownChoiseItemAndInitData(object sender, EventArgs e)
  171. {
  172. binaryClass.RefreshHistogramControl1Values();
  173. }
  174. /// <summary>
  175. /// 添加参数改变的监听
  176. /// </summary>
  177. /// <param name="sender"></param>
  178. /// <param name="e"></param>
  179. private void GrainSizePointCountingMethodDialog_Load(object sender, EventArgs e)
  180. {
  181. for (int i = 0; i < this.dataGridView1.Columns.Count; i++)
  182. {
  183. this.dataGridView1.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
  184. }
  185. this.dataGridView4.SortCompare += DataGridView4_SortCompare;
  186. this.binaryClass.loadParams();
  187. }
  188. private bool bcBinaryChecked()
  189. {
  190. return bc != null && bc.BinaryChecked;
  191. }
  192. private bool bcOriginChecked()
  193. {
  194. return bc != null && bc.OriginChecked;
  195. }
  196. /// <summary>
  197. /// 显示原图/原图+二值图
  198. /// </summary>
  199. /// <param name="sender"></param>
  200. /// <param name="e"></param>
  201. private void bcOriginCheckedChanged(object sender, EventArgs e)
  202. {
  203. if (!bcOriginChecked())
  204. {
  205. if (bcBinaryChecked())
  206. this.documentWorkspace.PhaseModels[0].choise = true;
  207. }
  208. else
  209. this.documentWorkspace.PhaseModels[0].choise = false;
  210. this.documentWorkspace.Refresh();
  211. }
  212. #endregion
  213. /// <summary>
  214. /// 初始化画面数据
  215. /// </summary>
  216. private void InitGridStyle()
  217. {
  218. grainSizePointCountingMethodModel = XmlSerializeHelper.DESerializer<GrainSizePointCountingMethodModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizePointCountingMethodModel.xml", FileMode.Open));
  219. if (grainSizePointCountingMethodModel.GridStyleList != null)
  220. {
  221. ArrayList arrayList = new ArrayList();
  222. foreach (var GridStyle in grainSizePointCountingMethodModel.GridStyleList)
  223. {
  224. arrayList.Add(GridStyle.gridName);
  225. }
  226. if (grainSizePointCountingMethodModel.GridStyleList.Count == 0)
  227. {
  228. }
  229. }
  230. }
  231. /// <summary>
  232. /// 初始化图片列表数据
  233. /// </summary>
  234. public void InitPicList()
  235. {
  236. //初始化图片列表
  237. for (int i = 0; i < this.appWorkspace.DocumentWorkspaces.Length; i++)
  238. {
  239. this.imageList1.Images.Add("img" + i, this.appWorkspace.DocumentWorkspaces[i].BinarizationThumbnail);
  240. this.listView1.Items.Add("", i);
  241. this.listView1.Items[i].ImageIndex = i;
  242. this.listView1.Items[i].Text = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName();
  243. this.listView1.Items[i].Name = this.appWorkspace.DocumentWorkspaces[i].GetFriendlyName();
  244. }
  245. this.Shown += ShowImgEvent;
  246. }
  247. #region 初始化
  248. private void InitializeLanguageText()
  249. {
  250. this.bc = new PaintDotNet.CustomControl.BinaryControlSmaller();
  251. //
  252. // bc
  253. //
  254. this.bc.BinaryBackColor = System.Drawing.Color.Red;
  255. this.bc.BinaryChecked = false;
  256. this.bc.BinaryStyle = 1;
  257. this.bc.Location = new System.Drawing.Point(152, 7);
  258. this.bc.Name = "bc";
  259. this.bc.OriginChecked = false;
  260. this.bc.scope1End = 0D;
  261. this.bc.scope1Start = 0D;
  262. this.bc.scope2End = 0D;
  263. this.bc.scope2Start = 0D;
  264. this.bc.scope3End = 0D;
  265. this.bc.scope3Start = 0D;
  266. this.bc.Size = new System.Drawing.Size(360, 247);
  267. this.bc.TabIndex = 3;
  268. this.Controls.Add(this.bc);
  269. this.Controls.SetChildIndex(this.bc, 0);
  270. }
  271. #endregion
  272. #region 公共按钮
  273. private void InitCommonButtonEvent()
  274. {
  275. this.commonControlButtons.zoomInButton.Click += new EventHandler(zoomInButton_Click);
  276. this.commonControlButtons.zoomOutButton.Click += new EventHandler(zoomOutButton_Click);
  277. this.commonControlButtons.zoomToWindowButton.Click += new EventHandler(zoomToWindowButton_Click);
  278. this.commonControlButtons.actualSizeButton.Click += new EventHandler(actualSizeButton_Click);
  279. this.commonControlButtons.pointerButton.Click += new EventHandler(pointerButton_Click);
  280. this.commonControlButtons.mobileModeButton.Click += new EventHandler(mobileModeButton_Click);
  281. }
  282. private void zoomInButton_Click(object sender, EventArgs e)
  283. {
  284. this.documentWorkspace.ZoomIn();
  285. }
  286. private void zoomOutButton_Click(object sender, EventArgs e)
  287. {
  288. this.documentWorkspace.ZoomOut();
  289. }
  290. private void zoomToWindowButton_Click(object sender, EventArgs e)
  291. {
  292. this.documentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
  293. }
  294. private void actualSizeButton_Click(object sender, EventArgs e)
  295. {
  296. this.documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
  297. this.documentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
  298. }
  299. private void pointerButton_Click(object sender, EventArgs e)
  300. {
  301. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.Pointer;
  302. }
  303. private void mobileModeButton_Click(object sender, EventArgs e)
  304. {
  305. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode;
  306. }
  307. #endregion
  308. private void listView1_MouseDown(object sender, MouseEventArgs e)
  309. {
  310. this.changeCount = 0;
  311. }
  312. private void DataGridView4_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
  313. {
  314. // 如果是数据的列,则按浮点数处理
  315. if (e.Column.Index > 1)//###20186
  316. {
  317. e.SortResult = (Convert.ToDouble(e.CellValue1) - Convert.ToDouble(e.CellValue2) > 0) ? 1 : (Convert.ToDouble(e.CellValue1) - Convert.ToDouble(e.CellValue2) < 0) ? -1 : 0;
  318. }
  319. //否则,按字符串比较
  320. else
  321. {
  322. e.SortResult = System.String.Compare(Convert.ToString(e.CellValue1), Convert.ToString(e.CellValue2));
  323. }
  324. e.Handled = true;//不能省掉,不然没效果
  325. }
  326. private void listView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
  327. {
  328. bool change = false;
  329. if (this.changeCount == 0)
  330. {
  331. if (this.dataGridView1.Rows.Count > 0)
  332. {
  333. if (this.saveSuccess)
  334. {
  335. DialogResult dt = MessageBox.Show(PdnResources.GetString("Menu.Whethertosavetherrentpicture.text") + "?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  336. if (dt == DialogResult.Yes)
  337. {
  338. string imgName = this.appWorkspace.DocumentWorkspaces[e.ItemIndex].GetFriendlyName();
  339. string tag = this.imageList1.Images.Keys[e.ItemIndex];
  340. if (this.dataGridView1.Rows.Count == 0)
  341. {
  342. MessageBox.Show(PdnResources.GetString("Menu.Pleaseaddtype.text") + "!");
  343. return;
  344. }
  345. }
  346. }
  347. }
  348. }
  349. else
  350. {
  351. if (change)
  352. SelectedIndexChanged();
  353. }
  354. this.changeCount++;
  355. }
  356. /// <summary>
  357. /// 切换图片
  358. /// </summary>
  359. /// <param name="sender"></param>
  360. /// <param name="e"></param>
  361. private void listView1_SelectedIndexChanged(object sender, EventArgs e)
  362. {
  363. SelectedIndexChanged();
  364. }
  365. List<PointF> list = new List<PointF>();
  366. /// <summary>
  367. /// 切换图片
  368. /// </summary>
  369. private void SelectedIndexChanged()
  370. {
  371. if (this.listView1.FocusedItem != null && this.listView1.FocusedItem.Selected)
  372. {
  373. existViewFlag = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GraphicsList.IsExsitView();
  374. this.bitmap = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap();
  375. lineList.Clear();
  376. pointList.Clear();
  377. kongLineList.Clear();
  378. kongPointList.Clear();
  379. delLineList.Clear();
  380. delPointList.Clear();
  381. isLunKuo = false;
  382. isAddKong = false;
  383. isDelKong = false;
  384. isDrwKuo = false;
  385. DrwDone = false;
  386. this.documentWorkspace.Refresh();
  387. this.dataGridView1.Rows.Clear();
  388. this.dataGridView4.Rows.Clear();
  389. Init();
  390. this.documentWorkspace.GridRectangleEnabled = false;
  391. //getimage();
  392. //getbian(bitmap);
  393. binaryClass.CilCount = Convert.ToInt32(txt_RightLineWeight.Text);
  394. //二值化集成4
  395. binaryClass.listView1_SelectedIndexChanged(this.bitmap);
  396. binaryClass.bcDefault();
  397. // btnCircleDrawing_Click(null, null);
  398. this.documentWorkspace.Refresh();
  399. }
  400. }
  401. #region 原始事件
  402. private void Init()
  403. {
  404. this.commonControlButtons.Visible = true;
  405. this.dataGridView1.Rows.Clear();
  406. this.dataGridView4.Rows.Clear();
  407. this.documentWorkspace.phaseModels.Clear();
  408. }
  409. /// <summary>
  410. /// 画布绘制
  411. /// </summary>
  412. /// <param name="sender"></param>
  413. /// <param name="e"></param>
  414. private void Panel_Paint(object sender, PaintEventArgs e)
  415. {
  416. if (this.documentWorkspace.CompositionSurface != null)
  417. {
  418. //
  419. // 以下是计算绘制图片的位置和大小并绘制图片
  420. //
  421. Rectangle rc = this.documentWorkspace.panel.ClientRectangle;
  422. int width = (int)(this.documentWorkspace.CompositionSurface.Width * this.documentWorkspace.ScaleFactor.Ratio);
  423. int height = (int)(this.documentWorkspace.CompositionSurface.Height * this.documentWorkspace.ScaleFactor.Ratio);
  424. int x = (rc.Width < width) ? this.documentWorkspace.panel.AutoScrollPosition.X : (rc.Width - width) / 2;
  425. int y = (rc.Height < height) ? this.documentWorkspace.panel.AutoScrollPosition.Y : (rc.Height - height) / 2;
  426. //if (pointArray.Count > 1)
  427. //{
  428. // e.Graphics.DrawLines(new Pen(Color.FromArgb(0, 0, 0), 2), pointArray.ToArray());
  429. //}
  430. //
  431. // 以下是绘制网格、标注、测量、视场等开始
  432. //
  433. e.Graphics.TranslateTransform(x, y);
  434. e.Graphics.ScaleTransform((float)this.documentWorkspace.ScaleFactor.Ratio, (float)this.documentWorkspace.ScaleFactor.Ratio);
  435. Draw(e.Graphics);
  436. //e.Graphics.DrawLines(new Pen(this.panel1.BackColor, Convert.ToInt32(this.txt_LeftLineWeight.Text)), list.ToArray());
  437. e.Graphics.ScaleTransform(1 / (float)this.documentWorkspace.ScaleFactor.Ratio, 1 / (float)this.documentWorkspace.ScaleFactor.Ratio);
  438. e.Graphics.TranslateTransform(-x, -y);
  439. }
  440. if (bc.isedit)
  441. {
  442. bc.isedit = false;
  443. List<List<int>> CircleDate = bc.data;
  444. bindGrid(CircleDate);
  445. }
  446. }
  447. /// <summary>
  448. /// 绘制
  449. /// </summary>
  450. private void Draw(Graphics graphics)
  451. {
  452. //轮廓手动干预线
  453. if (lineList.Count > 0)
  454. {
  455. for (int i = 0; i < lineList.Count; i++)
  456. {
  457. graphics.DrawLines(new Pen(Color.FromArgb(255, 0, 255), 2), lineList[i].ToArray());
  458. }
  459. }
  460. if (pointList.Count > 1)
  461. {
  462. graphics.DrawLines(new Pen(Color.FromArgb(255, 0, 255), 2), pointList.ToArray());
  463. }
  464. //孔隙手动干预线
  465. Color color = bc.BinaryBackColor;
  466. if (kongLineList.Count > 0)
  467. {
  468. for (int i = 0; i < kongLineList.Count; i++)
  469. {
  470. graphics.DrawLines(new Pen(color, 2), kongLineList[i].ToArray());
  471. }
  472. }
  473. if (kongPointList.Count > 1)
  474. {
  475. graphics.DrawLines(new Pen(color, 2), kongPointList.ToArray());
  476. }
  477. //删除孔隙
  478. //if (delLineList.Count > 0)
  479. //{
  480. // for (int i = 0; i < delLineList.Count; i++)
  481. // {
  482. // graphics.DrawLines(new Pen(Color.FromArgb(255, 0, 0), 2), delLineList[i].ToArray());
  483. // }
  484. //}
  485. //if (delPointList.Count > 1)
  486. //{
  487. // graphics.DrawLines(new Pen(Color.FromArgb(255, 0, 0), 2), delPointList.ToArray());
  488. //}
  489. }
  490. /// <summary>
  491. /// 画同心圆
  492. /// </summary>
  493. /// <param name="sender"></param>
  494. /// <param name="e"></param>
  495. private void btnCircleDrawing_Click(object sender, EventArgs e)
  496. {
  497. if (this.listView1.Items.Count == 0)
  498. {
  499. return;
  500. }
  501. if (rb_RightCircle.Checked)
  502. {
  503. List<List<int>> CircleDate = binaryClass.getCircleDate(Convert.ToInt32(txt_RightLineWeight.Text));
  504. bindGrid(CircleDate);
  505. }
  506. else
  507. {
  508. List<List<int>> CircleDate = binaryClass.getCircleDate(0);
  509. bindGrid(CircleDate);
  510. }
  511. }
  512. private void bindGrid(List<List<int>> dataList)
  513. {
  514. if (dataList == null)
  515. {
  516. return;
  517. }
  518. if (dataList.Count < 1)
  519. {
  520. return;
  521. }
  522. //标尺 微米/像素
  523. double d = binaryClass.GetRuler();
  524. // double d = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetRuler(MeasurementUnit.Micron);
  525. //图像自动识别标尺x微米/像素
  526. //double q= binaryClass.GetRuler();
  527. //孔隙率信息列表
  528. dataGridView1.Rows.Clear();
  529. Mat mat = this.documentWorkspace.PhaseModels[0].mat;
  530. double maxArea = mat.Rows* (mat.Cols-70);
  531. double totalArea = 0;
  532. //孔隙信息列表
  533. dataGridView4.Rows.Clear();
  534. for (int i = 1; i < dataList.Count - 1; i++)
  535. {
  536. if (dataList[i].Count < 6)
  537. { continue; }
  538. int newPo = dataGridView4.Rows.Add();
  539. //序号
  540. dataGridView4.Rows[newPo].Cells[0].Value = (newPo + 1).ToString();
  541. //X
  542. dataGridView4.Rows[newPo].Cells[1].Value = dataList[i][0];
  543. //Y
  544. dataGridView4.Rows[newPo].Cells[2].Value = dataList[i][1];
  545. //长
  546. dataGridView4.Rows[newPo].Cells[3].Value = Math.Round(Convert.ToDouble(dataList[i][2]) * d, 4).ToString();
  547. //宽
  548. dataGridView4.Rows[newPo].Cells[4].Value = Math.Round(Convert.ToDouble(dataList[i][3]) * d, 4).ToString();
  549. //面积
  550. dataGridView4.Rows[newPo].Cells[5].Value = Math.Round(Convert.ToDouble(dataList[i][4]) * d * d, 4).ToString();
  551. //标识
  552. dataGridView4.Rows[newPo].Cells[6].Value = dataList[i][5];
  553. totalArea = totalArea + Math.Round(Convert.ToDouble(dataList[i][4]) * d * d, 4);
  554. }
  555. int newrow = dataGridView1.Rows.Add();
  556. dataGridView1.Rows[newrow].Cells[0].Value = Math.Round(maxArea * d * d, 4).ToString();
  557. dataGridView1.Rows[newrow].Cells[1].Value = Math.Round(totalArea, 4).ToString();
  558. dataGridView1.Rows[newrow].Cells[2].Value = Math.Round((100*totalArea)/ (maxArea * d * d), 4).ToString() + "%";
  559. }
  560. #region 手动干预
  561. /// <summary>
  562. /// 修改轮廓
  563. /// </summary>
  564. /// <param name="sender"></param>
  565. /// <param name="e"></param>
  566. private void btnLunkuo_Click(object sender, EventArgs e)
  567. {
  568. isLunKuo = true;
  569. isAddKong = false;
  570. isDelKong = false;
  571. isDrwKuo = false;
  572. //DrwDone = false;
  573. }
  574. /// <summary>
  575. /// 添加孔隙
  576. /// </summary>
  577. /// <param name="sender"></param>
  578. /// <param name="e"></param>
  579. private void btnAddKong_Click(object sender, EventArgs e)
  580. {
  581. isLunKuo = false;
  582. isAddKong = true;
  583. isDelKong = false;
  584. isDrwKuo = false;
  585. //DrwDone = false;
  586. }
  587. /// <summary>
  588. /// 删除孔隙
  589. /// </summary>
  590. /// <param name="sender"></param>
  591. /// <param name="e"></param>
  592. private void btnDelKong_Click(object sender, EventArgs e)
  593. {
  594. isLunKuo = false;
  595. isAddKong = false;
  596. isDelKong = true;
  597. isDrwKuo = false;
  598. //DrwDone = false;
  599. }
  600. /// <summary>
  601. /// 绘制轮廓
  602. /// </summary>
  603. /// <param name="sender"></param>
  604. /// <param name="e"></param>
  605. private void btnDrwKuo_Click(object sender, EventArgs e)
  606. {
  607. isLunKuo = false;
  608. isAddKong = false;
  609. isDelKong = false;
  610. isDrwKuo = true;
  611. DrwDone = true;
  612. }
  613. /// <summary>
  614. /// 重新统计
  615. /// </summary>
  616. /// <param name="sender"></param>
  617. /// <param name="e"></param>
  618. private void btnReDrw_Click(object sender, EventArgs e)
  619. {
  620. if (pointList.Count > 1)
  621. {
  622. List<PointF> pointFs = new List<PointF>(pointList.ToArray());
  623. lineList.Add(pointFs);
  624. pointList.Clear();
  625. }
  626. if (kongPointList.Count > 1)
  627. {
  628. List<PointF> pointFs = new List<PointF>(kongPointList.ToArray());
  629. kongLineList.Add(pointFs);
  630. kongPointList.Clear();
  631. }
  632. if (delPointList.Count > 1)
  633. {
  634. }
  635. List<List<int>> CircleDate = new List<List<int>>();
  636. if (DrwDone)
  637. {
  638. CircleDate = binaryClass.DrwLunKuoNew(lineList, kongLineList, delPointList);
  639. }
  640. else
  641. {
  642. CircleDate = binaryClass.DrwLunKuo(lineList, kongLineList, delPointList);
  643. }
  644. bindGrid(CircleDate);
  645. isLunKuo = false;
  646. isAddKong = false;
  647. isDelKong = false;
  648. isDrwKuo = false;
  649. // DrwDone = false;
  650. }
  651. /// <summary>
  652. /// 移动
  653. /// </summary>
  654. /// <param name="sender"></param>
  655. /// <param name="e"></param>
  656. private void onMouseMove(object sender, MouseEventArgs e)
  657. {
  658. //if (e.Button == MouseButtons.Left)
  659. //{
  660. if (isLunKuo)
  661. {
  662. int cou = pointList.Count;
  663. if (cou > 0)
  664. { // 换算后的点
  665. PointF movePoint = this.documentWorkspace.GetScalePoint(e.Location);
  666. pointList[cou - 1] = movePoint;
  667. }
  668. }
  669. if (isAddKong)
  670. {
  671. if (kongPointList.Count > 0)
  672. { // 换算后的点
  673. PointF movePoint = this.documentWorkspace.GetScalePoint(e.Location);
  674. kongPointList[kongPointList.Count - 1] = movePoint;
  675. }
  676. }
  677. if (isDelKong)
  678. {
  679. //if (delPointList.Count > 0)
  680. //{ // 换算后的点
  681. // PointF movePoint = this.documentWorkspace.GetScalePoint(e.Location);
  682. // delPointList[delPointList.Count - 1] = movePoint;
  683. //}
  684. }
  685. if (isDrwKuo)
  686. {
  687. int cou = pointList.Count;
  688. if (cou > 0)
  689. { // 换算后的点
  690. PointF movePoint = this.documentWorkspace.GetScalePoint(e.Location);
  691. pointList[cou - 1] = movePoint;
  692. }
  693. }
  694. this.documentWorkspace.Refresh();
  695. // }
  696. }
  697. /// <summary>
  698. /// 鼠标抬起
  699. /// </summary>
  700. /// <param name="sender"></param>
  701. /// <param name="e"></param>
  702. private void OnMouseUp(object sender, MouseEventArgs e)
  703. {
  704. }
  705. /// <summary>
  706. /// 鼠标按下
  707. /// </summary>
  708. /// <param name="drawArea"></param>
  709. /// <param name="e"></param>
  710. private void OnMouseDown(object sender, MouseEventArgs e)
  711. {
  712. PointF downPoint = this.documentWorkspace.GetScalePoint(e.Location);
  713. if (e.Button == MouseButtons.Left)
  714. {
  715. if (isLunKuo)
  716. {
  717. if (pointList.Count == 0)
  718. {
  719. pointList.Add(downPoint);
  720. pointList.Add(downPoint);
  721. }
  722. else
  723. {
  724. pointList.Add(downPoint);
  725. }
  726. }
  727. if (isAddKong)
  728. {
  729. if (kongPointList.Count == 0)
  730. {
  731. kongPointList.Add(downPoint);
  732. kongPointList.Add(downPoint);
  733. }
  734. else
  735. {
  736. kongPointList.Add(downPoint);
  737. }
  738. }
  739. if (isDelKong)
  740. {
  741. //if (delPointList.Count == 0)
  742. //{
  743. // delPointList.Add(downPoint);
  744. // delPointList.Add(downPoint);
  745. //}
  746. //else
  747. //{
  748. // delPointList.Add(downPoint);
  749. //}
  750. delPointList.Add(downPoint);
  751. List<List<int>> CircleDate = new List<List<int>>();
  752. if (DrwDone)
  753. {
  754. CircleDate = binaryClass.DrwLunKuoNew(lineList, kongLineList, delPointList);
  755. }
  756. else
  757. {
  758. binaryClass.DrwLunKuo(lineList, kongLineList, delPointList);
  759. }
  760. bindGrid(CircleDate);
  761. }
  762. if (isDrwKuo)
  763. {
  764. if (pointList.Count == 0)
  765. {
  766. pointList.Add(downPoint);
  767. pointList.Add(downPoint);
  768. }
  769. else
  770. {
  771. pointList.Add(downPoint);
  772. }
  773. }
  774. }
  775. if (e.Button == MouseButtons.Right)
  776. {
  777. if (isLunKuo)
  778. {
  779. if (pointList.Count > 2)
  780. {
  781. pointList.RemoveAt(pointList.Count - 1);
  782. List<PointF> pointFs = new List<PointF>(pointList.ToArray());
  783. lineList.Add(pointFs);
  784. }
  785. pointList.Clear();
  786. }
  787. if (isAddKong)
  788. {
  789. if (kongPointList.Count > 2)
  790. {
  791. kongPointList.RemoveAt(kongPointList.Count - 1);
  792. List<PointF> pointFs = new List<PointF>(kongPointList.ToArray());
  793. kongLineList.Add(pointFs);
  794. }
  795. kongPointList.Clear();
  796. }
  797. if (isDelKong)
  798. {
  799. //if (delPointList.Count > 2)
  800. //{
  801. // delPointList.RemoveAt(delPointList.Count - 1);
  802. // List<PointF> pointFs = new List<PointF>(delPointList.ToArray());
  803. // delLineList.Add(pointFs);
  804. //}
  805. //delPointList.Clear();
  806. }
  807. if (isDrwKuo)
  808. {
  809. if (pointList.Count > 2)
  810. {
  811. pointList.RemoveAt(pointList.Count - 1);
  812. List<PointF> pointFs = new List<PointF>(pointList.ToArray());
  813. lineList.Add(pointFs);
  814. }
  815. pointList.Clear();
  816. }
  817. isLunKuo = false;
  818. isAddKong = false;
  819. isDelKong = false;
  820. isDrwKuo = false;
  821. }
  822. }
  823. /// <summary>
  824. /// Ctrl+z
  825. /// </summary>
  826. private void OnKeyDown(object sender, KeyEventArgs e)
  827. {
  828. if (e.Control && e.KeyCode == Keys.Z)
  829. {
  830. if (isLunKuo)
  831. {
  832. int cou = pointList.Count;
  833. if (cou > 1)
  834. {
  835. if (cou == 2)
  836. {
  837. pointList.Clear();
  838. }
  839. else
  840. {
  841. pointList.RemoveAt(cou - 1);
  842. }
  843. }
  844. else if (lineList.Count > 0)
  845. {
  846. pointList = lineList[lineList.Count - 1];
  847. lineList.RemoveAt(lineList.Count - 1);
  848. pointList.RemoveAt(pointList.Count - 1);
  849. }
  850. }
  851. if (isAddKong)
  852. {
  853. int cou = kongPointList.Count;
  854. if (cou > 1)
  855. {
  856. if (cou == 2)
  857. {
  858. kongPointList.Clear();
  859. }
  860. else
  861. {
  862. kongPointList.RemoveAt(cou - 1);
  863. }
  864. }
  865. else if (kongLineList.Count > 0)
  866. {
  867. kongPointList = kongLineList[kongLineList.Count - 1];
  868. kongLineList.RemoveAt(kongLineList.Count - 1);
  869. kongPointList.RemoveAt(kongPointList.Count - 1);
  870. }
  871. }
  872. if (isDelKong)
  873. {
  874. int cou = delPointList.Count;
  875. if (cou > 0)
  876. {
  877. delPointList.RemoveAt(cou - 1);
  878. }
  879. List<List<int>> CircleDate = new List<List<int>>();
  880. if (DrwDone)
  881. {
  882. CircleDate = binaryClass.DrwLunKuoNew(lineList, kongLineList, delPointList);
  883. }
  884. else
  885. {
  886. binaryClass.DrwLunKuo(lineList, kongLineList, delPointList);
  887. }
  888. bindGrid(CircleDate);
  889. //if (cou > 1)
  890. //{
  891. // if (cou == 2)
  892. // {
  893. // delPointList.Clear();
  894. // }
  895. // else
  896. // {
  897. // delPointList.RemoveAt(cou - 1);
  898. // }
  899. //}
  900. //else if (delLineList.Count > 0)
  901. //{
  902. // delPointList = delLineList[delLineList.Count - 1];
  903. // delLineList.RemoveAt(delLineList.Count - 1);
  904. // delPointList.RemoveAt(delPointList.Count - 1);
  905. //}
  906. }
  907. this.documentWorkspace.Refresh();
  908. }
  909. }
  910. #endregion
  911. /// <summary>
  912. /// 导出孔隙信息
  913. /// </summary>
  914. /// <param name="sender"></param>
  915. /// <param name="e"></param>
  916. private void button14_Click(object sender, EventArgs e)
  917. {
  918. SaveFileDialog exe = new SaveFileDialog();
  919. exe.Filter = "Execl files (*.xlsx)|*.xlsx";
  920. exe.FilterIndex = 0;
  921. exe.RestoreDirectory = true;
  922. //exe.CreatePrompt = true;
  923. exe.Title = "Export Excel File";
  924. exe.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  925. exe.FileName = DateTime.Now.ToString("yyyyMMddhhmmss") + "孔隙信息";
  926. DialogResult dr = exe.ShowDialog();
  927. if (dr != DialogResult.OK)
  928. {
  929. return;
  930. }
  931. DataTable dtb = new DataTable();
  932. foreach (DataGridViewColumn c in this.dataGridView4.Columns)
  933. {
  934. dtb.Columns.Add(c.HeaderText);
  935. }
  936. for (int r = 0; r < this.dataGridView4.Rows.Count; r++)
  937. {
  938. DataRow dataRow = dtb.NewRow();
  939. for (int c = 0; c < this.dataGridView4.Rows[r].Cells.Count; c++)
  940. {
  941. dataRow[this.dataGridView4.Columns[c].HeaderText] = (string)this.dataGridView4.Rows[r].Cells[c].Value.ToString();
  942. }
  943. dtb.Rows.Add(dataRow);
  944. //this.dataGridView4.Rows[r].Cells[1].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
  945. }
  946. List<DataTable> list = new List<DataTable>();
  947. list.Add(dtb);
  948. this.appWorkspace.ExportDataToExcelWithProgress(list, exe.FileName, true, false, true);
  949. }
  950. /// <summary>
  951. /// 不可点击空白区域
  952. /// </summary>
  953. /// <param name="sender"></param>
  954. /// <param name="e"></param>
  955. private void listView1_MouseUp(object sender, MouseEventArgs e)
  956. {
  957. if (e.Button == MouseButtons.Left)
  958. {
  959. if (listView1.SelectedItems.Count > 0)
  960. {
  961. }
  962. else if (listView1.SelectedItems.Count <= 0)//点击空白区
  963. {
  964. if (this.listView1.FocusedItem != null)
  965. {
  966. ListViewItem item = this.listView1.GetItemAt(e.X, e.Y);
  967. if (item == null)
  968. {
  969. this.listView1.FocusedItem.Selected = true;
  970. }
  971. }
  972. }
  973. }
  974. }
  975. /// <summary>
  976. /// 生成孔隙率
  977. /// </summary>
  978. /// <param name="sender"></param>
  979. /// <param name="e"></param>
  980. private void button13_Click(object sender, EventArgs e)
  981. {
  982. //string path = string.Empty;
  983. //System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog();
  984. //fbd.Description = "请选择文件夹";
  985. //String str = System.Configuration.ConfigurationManager.AppSettings["FolderSelectedPath"];
  986. //if (!string.IsNullOrEmpty(str))
  987. //{
  988. // fbd.SelectedPath = str;
  989. //}
  990. //if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  991. //{
  992. // path = fbd.SelectedPath;
  993. // PrintReport(path);
  994. // Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  995. // cfa.AppSettings.Settings["FolderSelectedPath"].Value = path;
  996. // cfa.Save();
  997. // System.Configuration.ConfigurationManager.RefreshSection("appSettings");
  998. //}
  999. string name = this.listView1.FocusedItem.Name.Split('.')[0] + "-";
  1000. SaveFileDialog exe = new SaveFileDialog();
  1001. exe.Filter = "Execl files (*.xlsx)|*.xlsx";
  1002. exe.FilterIndex = 0;
  1003. exe.RestoreDirectory = true;
  1004. //exe.CreatePrompt = true;
  1005. exe.Title = "Export Excel File";
  1006. // exe.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  1007. exe.FileName = name;
  1008. //String str = System.Configuration.ConfigurationManager.AppSettings["FolderSelectedPath"];
  1009. DialogResult dr = exe.ShowDialog();
  1010. if (dr != DialogResult.OK)
  1011. {
  1012. return;
  1013. }
  1014. DataTable dtb = new DataTable();
  1015. foreach (DataGridViewColumn c in this.dataGridView1.Columns)
  1016. {
  1017. dtb.Columns.Add(c.HeaderText);
  1018. }
  1019. for (int r = 0; r < this.dataGridView1.Rows.Count; r++)
  1020. {
  1021. DataRow dataRow = dtb.NewRow();
  1022. for (int c = 0; c < this.dataGridView1.Rows[r].Cells.Count; c++)
  1023. {
  1024. dataRow[this.dataGridView1.Columns[c].HeaderText] = (string)this.dataGridView1.Rows[r].Cells[c].Value.ToString();
  1025. }
  1026. dtb.Rows.Add(dataRow);
  1027. //this.dataGridView4.Rows[r].Cells[1].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
  1028. }
  1029. int index = exe.FileName.LastIndexOf('\\');
  1030. List<DataTable> list = new List<DataTable>();
  1031. list.Add(dtb);
  1032. DataTable dtb1 = new DataTable();
  1033. foreach (DataGridViewColumn c in this.dataGridView4.Columns)
  1034. {
  1035. dtb1.Columns.Add(c.HeaderText);
  1036. }
  1037. for (int r = 0; r < this.dataGridView4.Rows.Count; r++)
  1038. {
  1039. DataRow dataRow = dtb1.NewRow();
  1040. for (int c = 0; c < this.dataGridView4.Rows[r].Cells.Count; c++)
  1041. {
  1042. dataRow[this.dataGridView4.Columns[c].HeaderText] = (string)this.dataGridView4.Rows[r].Cells[c].Value.ToString();
  1043. }
  1044. dtb1.Rows.Add(dataRow);
  1045. //this.dataGridView4.Rows[r].Cells[1].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
  1046. }
  1047. list.Add(dtb1);
  1048. //保存处理后的图片
  1049. double pantographRatio = (double)this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetRulerMultiple(MeasurementUnit.Micron);//标尺*放大倍数
  1050. List<Bitmap> tempBit = new List<Bitmap>();
  1051. Bitmap originalBit = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap();
  1052. originalBit.Tag = pantographRatio;
  1053. tempBit.Add(originalBit);
  1054. Bitmap processedBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.documentWorkspace.PhaseModels[0].mat);
  1055. Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  1056. Graphics graphics = Graphics.FromImage(newBit);
  1057. graphics.DrawImage(processedBit, new PointF(0, 0));
  1058. Draw(graphics);
  1059. newBit.Tag = pantographRatio;
  1060. tempBit.Add(newBit);
  1061. string GR_Path = exe.FileName.Remove(index) + "\\" + name + ".jpg";
  1062. newBit.Save(GR_Path);
  1063. this.appWorkspace.ExportDataToExcelWithProgress(list, exe.FileName, true, false, true);
  1064. }
  1065. /// <summary>
  1066. /// 导出报告
  1067. /// </summary>
  1068. private void PrintReport(string savePath)
  1069. {
  1070. List<List<string>> analysisContent = new List<List<string>>();
  1071. for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
  1072. {
  1073. List<string> content1 = new List<string>();
  1074. if (i == 0)
  1075. {
  1076. content1.Add(this.dataGridView1.Columns[0].HeaderText);
  1077. content1.Add(this.dataGridView1.Columns[1].HeaderText);
  1078. content1.Add(this.dataGridView1.Columns[2].HeaderText);
  1079. analysisContent.Add(content1);
  1080. }
  1081. content1 = new List<string>();
  1082. content1.Add(this.dataGridView1.Rows[i].Cells[0].Value.ToString());
  1083. content1.Add(this.dataGridView1.Rows[i].Cells[1].Value.ToString());
  1084. content1.Add(this.dataGridView1.Rows[i].Cells[2].Value.ToString());
  1085. analysisContent.Add(content1);
  1086. }
  1087. List<string> content2 = new List<string>();
  1088. analysisContent.Add(content2);
  1089. for (int i = 0; i < this.dataGridView4.Rows.Count; i++)
  1090. {
  1091. List<string> content1 = new List<string>();
  1092. if (i == 0)
  1093. {
  1094. content1.Add(this.dataGridView4.Columns[0].HeaderText);
  1095. content1.Add(this.dataGridView4.Columns[1].HeaderText);
  1096. content1.Add(this.dataGridView4.Columns[2].HeaderText);
  1097. content1.Add(this.dataGridView4.Columns[3].HeaderText);
  1098. content1.Add(this.dataGridView4.Columns[4].HeaderText);
  1099. content1.Add(this.dataGridView4.Columns[5].HeaderText);
  1100. content1.Add(this.dataGridView4.Columns[6].HeaderText);
  1101. analysisContent.Add(content1);
  1102. }
  1103. content1 = new List<string>();
  1104. content1.Add(this.dataGridView4.Rows[i].Cells[0].Value.ToString());
  1105. content1.Add(this.dataGridView4.Rows[i].Cells[1].Value.ToString());
  1106. content1.Add(this.dataGridView4.Rows[i].Cells[2].Value.ToString());
  1107. content1.Add(this.dataGridView4.Rows[i].Cells[3].Value.ToString());
  1108. content1.Add(this.dataGridView4.Rows[i].Cells[4].Value.ToString());
  1109. content1.Add(this.dataGridView4.Rows[i].Cells[5].Value.ToString());
  1110. content1.Add(this.dataGridView4.Rows[i].Cells[6].Value.ToString());
  1111. analysisContent.Add(content1);
  1112. }
  1113. //保存处理后的图片
  1114. double pantographRatio = (double)this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].GetRulerMultiple(MeasurementUnit.Micron);//标尺*放大倍数
  1115. List<Bitmap> tempBit = new List<Bitmap>();
  1116. Bitmap originalBit = this.appWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index].CompositionSurface.CreateAliasedBitmap();
  1117. originalBit.Tag = pantographRatio;
  1118. tempBit.Add(originalBit);
  1119. Bitmap processedBit = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(this.documentWorkspace.PhaseModels[0].mat);
  1120. Bitmap newBit = originalBit.Clone(new Rectangle(0, 0, originalBit.Width, originalBit.Height), originalBit.PixelFormat);
  1121. Graphics graphics = Graphics.FromImage(newBit);
  1122. graphics.DrawImage(processedBit, new PointF(0, 0));
  1123. Draw(graphics);
  1124. newBit.Tag = pantographRatio;
  1125. tempBit.Add(newBit);
  1126. List<Bitmap> bitList = new List<Bitmap>();
  1127. bitList.Add(tempBit[0]);
  1128. bitList.Add(tempBit[1]);
  1129. Dictionary<string, string> tagInfos = new Dictionary<string, string>();
  1130. // this.analyzeSettingModel.analyzeClassify
  1131. AnalyzeSettingModel model = new AnalyzeSettingModel();
  1132. string filePath = Application.StartupPath + "\\ModuleManage\\Dedicated\\MicrostructureBand_ASTME1268\\截面孔隙.docx";//获取文档路径
  1133. string filePath2 = "E:\\图形处理\\Metisvision20210204\\RBDC\\Metisvision\\bin\\Debug\\ModuleManage\\Dedicated\\MicrostructureBand_ASTME1268\\截面孔隙.docx";
  1134. model.modulePath = filePath;
  1135. model.savePath = savePath;
  1136. //model.itemNumber = this.textBox2.Text;
  1137. //model.ratingDate = this.dateTimePicker1.Value;
  1138. //model.inspectionPerson = this.textBox4.Text;
  1139. model.contact = "";
  1140. //model.inspectionDepartment = this.textBox5.Text;
  1141. //model.inspectionDate = this.dateTimePicker2.Value;
  1142. string name = this.listView1.FocusedItem.Name.Split('.')[0];
  1143. model.analyzeClassify = name;
  1144. this.analyzeSettingModel = new AnalyzeSettingModel();
  1145. //this.analyzeSettingModel.modelItems = new List<AnalyzeSavedModel.ModelItem>();
  1146. //this.analyzeSettingModel = new AnalyzeSavedModel.ModelItem();
  1147. //this.analyzeSettingModel.languageName = this.languageName;
  1148. this.analyzeSettingModel = model;
  1149. //this.analyzeSettingModel.modelItems.Add(analyzeModel);
  1150. this.appWorkspace.CreateAnalysisReport(this.analyzeSettingModel, analysisContent, bitList, tagInfos);
  1151. }
  1152. /// 导出图片
  1153. /// </summary>
  1154. /// <param name="sender"></param>
  1155. /// <param name="e"></param>
  1156. private void btnImageOut_Click(object sender, EventArgs e)
  1157. {
  1158. SaveFileDialog exe = new SaveFileDialog();
  1159. exe.Filter = "Image Files (*.jpg)|*.jpg";
  1160. exe.FilterIndex = 0;
  1161. exe.RestoreDirectory = true;
  1162. //exe.CreatePrompt = true;
  1163. exe.Title = "Image Files";
  1164. exe.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  1165. exe.FileName = DateTime.Now.ToString("yyyyMMddhhmmss") + "孔隙率";
  1166. DialogResult dr = exe.ShowDialog();
  1167. if (dr != DialogResult.OK)
  1168. {
  1169. return;
  1170. }
  1171. Mat mat = binaryClass.MargMat();
  1172. if (Cv2.ImWrite(exe.FileName, mat))
  1173. {
  1174. MessageBox.Show("保存成功!");
  1175. }
  1176. //List<DataTable> list = new List<DataTable>();
  1177. //list.Add(dtb);
  1178. //this.appWorkspace.ExportDataToExcelWithProgress(list, exe.FileName, true, false, true);
  1179. }
  1180. /// <summary>
  1181. /// 准备用来处理单个颗粒的选中事件
  1182. /// </summary>
  1183. /// <param name="sender"></param>
  1184. /// <param name="e"></param>
  1185. private void dataGridView4_CellClick(object sender, DataGridViewCellEventArgs e)
  1186. {
  1187. //当点击表头部的列时,e.RowIndex==-1
  1188. if (e.RowIndex > -1)
  1189. {
  1190. int index = Convert.ToInt32(dataGridView4.Rows[e.RowIndex].Cells[6].Value);
  1191. int x = Convert.ToInt32(dataGridView4.Rows[e.RowIndex].Cells[0].Value);
  1192. int y = Convert.ToInt32(dataGridView4.Rows[e.RowIndex].Cells[1].Value);
  1193. PointF select = new PointF() { X = x, Y = y };
  1194. binaryClass.MembranesSel(index);
  1195. // binaryClass.DrwLunKuoLie1Selected(select);
  1196. this.documentWorkspace.Refresh();
  1197. }
  1198. }
  1199. #region 内部类
  1200. internal class LocalListViewItem
  1201. {
  1202. public DocumentWorkspace Value { get; }
  1203. public string Display { get; }
  1204. public LocalListViewItem(DocumentWorkspace Value, string Display)
  1205. {
  1206. this.Value = Value;
  1207. this.Display = Display;
  1208. }
  1209. }
  1210. internal class DocumentItem
  1211. {
  1212. public Bitmap bitmap;
  1213. public GraphicsList graphicsList;
  1214. public List<PhaseModel> phaseModels;
  1215. //public AnalysisResult analysisResult;
  1216. public DocumentItem(Bitmap bitmap, GraphicsList graphicsList, List<PhaseModel> phaseModels)
  1217. {
  1218. this.bitmap = bitmap;
  1219. this.graphicsList = graphicsList;
  1220. this.phaseModels = phaseModels;
  1221. }
  1222. }
  1223. #endregion
  1224. #endregion
  1225. }
  1226. }