OTSMeasureStatusWindow.cs 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005
  1. using OTS.WinFormsUI.Docking;
  2. using OTSCLRINTERFACE;
  3. using OTSDataType;
  4. using OTSIncAGraph.Controls;
  5. using OTSMeasureApp._0_OTSModel.OTSDataType;
  6. using OTSModelSharp;
  7. using OTSModelSharp.ServiceCenter;
  8. using OTSPeriodicTable;
  9. using System;
  10. using System.Collections;
  11. using System.Collections.Generic;
  12. using System.Data;
  13. using System.Drawing;
  14. using System.IO;
  15. using System.Reflection;
  16. using System.Windows.Forms;
  17. //using OTSMeasureApp._0_OTSModel.Measure.ParamData;
  18. namespace OTSMeasureApp
  19. {
  20. public enum idLine
  21. {
  22. //曲线
  23. GrayLine = 0,
  24. //灰度图
  25. GrayImage = 1
  26. }
  27. public enum MeasureStateMenuType
  28. {
  29. //获取BSE图
  30. ReadBSEPic = 0,
  31. //设置可视化灰度
  32. SetVisualGray = 1,
  33. //显示BSE灰度曲线图
  34. SetVisualGrayForSpecialGray = 2,
  35. grayToolStripMenuItem = 3,
  36. //切换至BSE图
  37. ChangeDiffImageShow = 4,
  38. //BSE去背景图
  39. DelBSEBG = 5,
  40. ColoredBSENoBG = 6,
  41. //显示BSE去背景灰度曲线图
  42. SampleHoleBSEImage = 7,
  43. //线扫描曲线
  44. MenuItemLineScam = 8,
  45. //单点采集Xray与元素信息
  46. PointScanElementMenuItem = 9,
  47. //导出采集信息报告
  48. ExportReport = 10
  49. }
  50. public partial class OTSMeasureStatusWindow : DockContent
  51. {
  52. #region 全部变量
  53. public OTSIncAMeasureAppForm m_MeasureAppForm;
  54. static int m_iWidth = 0;
  55. static int m_iHeight = 0;
  56. //获取BSE图时最初的位置
  57. Point m_GetBSEImageInitPoint = new Point();
  58. // 调试图图片数据
  59. public byte[] originalBseData;
  60. //去背景图
  61. private byte[] removeBGBseData;
  62. private Bitmap coloredParticleImage;
  63. //灰度图数据
  64. public double[] dGrayLevelData;
  65. //灰度峰值
  66. private double dGrayLevelMax;
  67. //去背景灰度图数据
  68. private double[] dGrayAbandonLevelData;
  69. //去背景灰度峰值
  70. private double dGrayAbandonLevelMax;
  71. public string FileName;
  72. //原图Y轴
  73. int YSize = 0;
  74. //int drawflag = 0;
  75. private int height = 0;
  76. private int width = 0;
  77. //画布大小
  78. private Bitmap bitmap;
  79. //要画曲线的点y坐标值,x值为10s采集一次数据
  80. private float[] curvebuf = new float[] { 20.0f, 30.0f, 40.0f, 35.4f, 21.6f, 32.8f, 5.2f, 9.9f, 30f, 35.3f, 25.3f, 21.2f, 30.2f, 22.8f, 40.5f, 5.6f, 20.6f };
  81. //记录鼠标在BSE移动时 图像的位置
  82. double m_MouseMoveImageX = -1;
  83. double m_MouseMoveImageY = -1;
  84. //绘制采集点对象
  85. public static List<CRectangleGDIObject> m_ElementPointGDIObjects;
  86. Point m_mouseCurrentPoint = new Point();
  87. //鼠标缩放倍数
  88. float m_CurrentMultiple = 0;
  89. float m_Multiple = 0.2f;
  90. int m_MaxMultipleRange = 4;
  91. //单击采集的鼠标位置
  92. double dMouseImgX = 0;
  93. double dMouseImgY = 0;
  94. NLog.Logger log;
  95. //国际化
  96. OTSCommon.Language lan;
  97. Hashtable table;
  98. #endregion
  99. #region 在右下角状态栏中显示鼠标当前位置所需要的参数
  100. double dPositionX = 0;
  101. double dPositionY = 0;
  102. int FieldWitdh = 0;
  103. double FieldHeight = 0;
  104. #endregion
  105. public enum ImageType
  106. {
  107. //BSE图
  108. BSEImage = 0,
  109. //去背景图
  110. RemoveBGImage = 1,
  111. //显示灰度曲线图
  112. GrayLevelChart = 2,
  113. //线扫描曲线
  114. GrayLevelLineScan = 3,
  115. //显示去背景BSE图灰度曲线
  116. GrayAbandonLevelChart = 4,
  117. //
  118. ColorParticleImage = 5
  119. }
  120. //图bfResult
  121. public static bool bfResult = false;
  122. //当前是否显示线扫描
  123. //public static bool IsShowGrayLevelLine = false;
  124. //当前默认值
  125. ImageType m_imagetype = ImageType.BSEImage;
  126. //ImageType m_IsShowImageType = ImageType.BSEImage;
  127. public OTSMeasureStatusWindow(OTSIncAMeasureAppForm MeasureApp)
  128. {
  129. InitializeComponent();
  130. m_MeasureAppForm = MeasureApp;
  131. m_ElementPointGDIObjects = new List<CRectangleGDIObject>();
  132. //进入时首先对XRayTable进行隐藏
  133. panelXray.Visible = false;
  134. //国际化
  135. lan = new OTSCommon.Language(this);
  136. table = lan.GetNameTable(this.Name);
  137. if (OTSCommon.Language.ReadDefaultLanguage() == "ZH")
  138. {
  139. contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Text = "切换显示至BSE图";
  140. }
  141. else
  142. {
  143. contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Text = "SwitchDisplayToBSEDiagram";
  144. }
  145. }
  146. /// <summary>
  147. /// 在控件中显示BSE图像
  148. /// </summary>
  149. /// <param name="m_iWidth"></param>
  150. /// <param name="m_iHeigh"></param>
  151. /// <param name="bBseData"></param>
  152. public void ShowImage(int iWidth, int iHeight, byte[] bBseData)
  153. {
  154. try
  155. {
  156. Bitmap bitmap = CImageHandler.ToGrayBitmap(bBseData, iWidth, iHeight);
  157. ShowBitmapInPicbox1(bitmap);
  158. }
  159. catch (Exception e)
  160. {
  161. NLog.LogManager.GetCurrentClassLogger().Error(e.Message);
  162. }
  163. }
  164. public void ShowBitmapInPicbox1(Bitmap bmpImage)
  165. {
  166. picBox.Image = bmpImage;
  167. //设置Pictrue显示位置
  168. picBox.Height = this.RestoreBounds.Height;
  169. picBox.Width = this.RestoreBounds.Height * 4 / 3;
  170. //获取黄线坐标位置
  171. Rectangle rectangle = GetPictureBoxZoomSize(picBox);
  172. m_GetBSEImageInitPoint = rectangle.Location;
  173. pointStart.X = rectangle.X;
  174. pointEnd.X = rectangle.X + rectangle.Width;
  175. pointStart.Y = rectangle.Y + (rectangle.Height) / 2;
  176. pointEnd.Y = rectangle.Y + (rectangle.Height) / 2;
  177. picBox.Left = 0;
  178. picBox.Top = 0;
  179. picBox.Show();
  180. pictureBox2.Visible = false;
  181. }
  182. public void ShowDoubleImage(Bitmap image1, Bitmap image2)
  183. {
  184. if (image1 != null)
  185. {
  186. picBox.Image = image1;
  187. }
  188. //设置Pictrue显示位置
  189. picBox.Height = this.RestoreBounds.Height;
  190. picBox.Width = this.RestoreBounds.Height * 2 / 3;
  191. //获取黄线坐标位置
  192. Rectangle rectangle = GetPictureBoxZoomSize(picBox);
  193. m_GetBSEImageInitPoint = rectangle.Location;
  194. pointStart.X = rectangle.X;
  195. pointEnd.X = rectangle.X + rectangle.Width;
  196. pointStart.Y = rectangle.Y + (rectangle.Height) / 2;
  197. pointEnd.Y = rectangle.Y + (rectangle.Height) / 2;
  198. picBox.Left = 0;
  199. picBox.Top = 0;
  200. picBox.Show();
  201. if (image2 != null)
  202. {
  203. pictureBox2.Image = image2;
  204. }
  205. pictureBox2.Height = this.RestoreBounds.Height;
  206. pictureBox2.Width = this.RestoreBounds.Height * 2 / 3;
  207. pictureBox2.Left = this.RestoreBounds.Width / 2;
  208. pictureBox2.Top = 0;
  209. pictureBox2.Show();
  210. }
  211. /// <summary>
  212. /// 在控件中显示图像
  213. /// </summary>
  214. /// <param name="m_iWidth"></param>
  215. /// <param name="m_iHeigh"></param>
  216. /// <param name="bBseData"></param>
  217. public Image ShowImageStatus(int m_iWidth, int m_iHeigh, byte[] bBseData)
  218. {
  219. return CImageHandler.ToGrayBitmap(bBseData, m_iWidth, m_iHeigh);
  220. }
  221. //显示扫描曲线图方法
  222. #region 显示扫描曲线图方法
  223. private void DrawCurve(byte[] buf, PaintEventArgs e)
  224. {
  225. //创建位图
  226. Rectangle rectangle = GetPictureBoxZoomSize(picBox);
  227. double rate = (double)rectangle.Height / (double)picBox.Image.Height;
  228. width = rectangle.Width;
  229. height = rectangle.Height;
  230. bitmap = new Bitmap(width, height);
  231. Pen mypenYellow = new Pen(Color.Yellow, 0.001f);//点颜色
  232. int len = buf.Length;
  233. PointF[] CurvePointF = new PointF[len];//坐标点
  234. float pointX = 0;
  235. float pointY = 0;
  236. for (int i = 0; i < buf.Length; i++)
  237. {
  238. pointX = (picBox.Width - rectangle.Width) / 2 + Convert.ToSingle(i * rate);
  239. float imagei = (int)GrayLevel.Max - Convert.ToInt32(buf[i]);
  240. float imagerate = (Convert.ToSingle(Convert.ToDouble(rectangle.Height) / 510));
  241. pointY = imagei * imagerate + (rectangle.Height) / 4 + rectangle.Top;
  242. if (pointY > ((rectangle.Height) * 3 / 4))
  243. {
  244. float ii = pointY;
  245. }
  246. CurvePointF[i] = new PointF(pointX, pointY);
  247. }
  248. float Tension = 0.001f;
  249. e.Graphics.DrawCurve(mypenYellow, CurvePointF, Tension);//画曲线
  250. }
  251. #endregion
  252. //处理获取调试图菜单事件
  253. #region 处理获取调试图菜单事件
  254. private void AcquireBSEImage_Click(object sender, EventArgs e)
  255. {
  256. if (m_ElementPointGDIObjects != null)
  257. {
  258. m_ElementPointGDIObjects.Clear();
  259. }
  260. //设置右键菜单中的项 是否可编辑
  261. SetContextMenuEnabled(true);
  262. bool rst = AcquireBSEImage();
  263. //取图不成功就返回
  264. if (rst)
  265. {
  266. bfResult = true;
  267. }
  268. if (!rst)
  269. {
  270. if (contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Enabled == true)
  271. {
  272. contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Enabled = false;
  273. }
  274. //显示单点扫描元素信息菜单
  275. contextMenuStrip1.Items[(int)MeasureStateMenuType.PointScanElementMenuItem].Enabled = false;
  276. picBox.Hide();
  277. return;
  278. }
  279. else
  280. {
  281. //显示单点扫描元素信息菜单
  282. contextMenuStrip1.Items[(int)MeasureStateMenuType.PointScanElementMenuItem].Enabled = true;
  283. }
  284. //m_IsShowImageType = ImageType.BSEImage;
  285. m_imagetype = ImageType.BSEImage;
  286. Bitmap bitmap = CImageHandler.ToGrayBitmap(originalBseData, m_iWidth, m_iHeight);
  287. ShowBitmapInPicbox1(bitmap);
  288. myChart.Visible = false;
  289. //图像加载后的显示位置
  290. m_CurrentMultiple = 0;
  291. picBox.Height = this.RestoreBounds.Height;
  292. picBox.Left = 0;
  293. picBox.Top = 0;
  294. DelElementPointGDIObjects();
  295. panelXray.Visible = false;
  296. m_CurrentMultiple = 0;
  297. }
  298. /// <summary>
  299. /// 获取BSE图方法
  300. /// </summary>
  301. private bool AcquireBSEImage()
  302. {
  303. //获取电镜中图像大小
  304. string str = m_MeasureAppForm.m_ProjParam.GetBSEImageResolutionStr();// 举例:1024X768
  305. string[] sArray = str.Split('X');
  306. if (sArray[0] != "" && sArray[1] != "")
  307. {
  308. m_iWidth = Convert.ToInt32(sArray[0]);
  309. m_iHeight = Convert.ToInt32(sArray[1]);
  310. }
  311. //建立图像数据
  312. originalBseData = new byte[m_iWidth * m_iHeight];
  313. //获取图像数据
  314. int nDwellTime = 4;
  315. try
  316. {
  317. int level = (int)m_MeasureAppForm.m_ProjParam.GetResultData().GetWorkingSample().GetMsrParams().GetImageScanParam().GetScanImageSpeed();
  318. switch (level)
  319. {
  320. case 0:
  321. nDwellTime = 2;
  322. break;
  323. case 1:
  324. nDwellTime = 4;
  325. break;
  326. case 2:
  327. nDwellTime = 8;
  328. break;
  329. }
  330. }
  331. catch (Exception)
  332. {
  333. nDwellTime = 8;
  334. }
  335. bool rst = GetScanImage(m_iWidth, m_iHeight, nDwellTime, ref originalBseData);
  336. return rst;
  337. }
  338. private void UpdateImageAndLineScanChart()
  339. {
  340. Bitmap bitmap = CImageHandler.ToGrayBitmap(originalBseData, m_iWidth, m_iHeight);
  341. ShowBitmapInPicbox1(bitmap);
  342. //获取灰度图数据
  343. dGrayLevelData = new double[(int)GrayLevel.Max];
  344. dGrayLevelData = GetGaryData(originalBseData, dGrayLevelData);
  345. //计算灰度最大值
  346. dGrayLevelMax = dGrayLevelData[0];
  347. for (int i = 1; i < (int)GrayLevel.Max; i++)
  348. {
  349. dGrayLevelMax = Math.Max(dGrayLevelMax, dGrayLevelData[i]);
  350. }
  351. int[] XData = new int[(int)GrayLevel.Max];
  352. for (int i = 0; i < (int)GrayLevel.Max; i++)
  353. {
  354. XData[i] = i + 1;
  355. }
  356. int[] YData = new int[dGrayLevelData.Length];
  357. for (int i = 0; i < dGrayLevelData.Length; i++)
  358. {
  359. YData[i] = (int)dGrayLevelData[i];
  360. }
  361. DisChartData(XData, YData, ImageType.GrayLevelLineScan);
  362. picBox.Refresh();
  363. }
  364. public double[] GetGaryData(byte[] Imagedata, double[] GrayLevelData)
  365. {
  366. //获得下标每一点的灰度值,并在数组里加一
  367. for (int i = 0; i < Imagedata.Length; i++)
  368. {
  369. byte graylevel = Imagedata[i];
  370. if (graylevel > 0 && graylevel < 255)
  371. {
  372. GrayLevelData[graylevel] += 1;
  373. }
  374. }
  375. return GrayLevelData;
  376. }
  377. public bool GetScanImage(int iWidth, int iHeight, int iDwellTime, ref byte[] bImageData)
  378. {
  379. //电镜设置对象
  380. IScanController cfun = ScanController.GetScanController();
  381. ISemController sem = SemController.GetSEMController();
  382. try
  383. {
  384. //连接电镜
  385. bool IsConnec = cfun.Init();
  386. if (!IsConnec)
  387. {
  388. string strErrorInfo = "(OTSBSEImageFun.GetScanImage) cfun.ConncetSem() = false Failed";
  389. log.Error(strErrorInfo);
  390. return false;
  391. }
  392. cfun.SetImageSize(iWidth, iHeight);
  393. cfun.SetDwellTime(iDwellTime);
  394. var bse = cfun.AcquireBSEImage();
  395. bImageData = bse.GetImageDataPtr();
  396. sem.SetScanExternal(false);
  397. }
  398. catch (Exception ex)
  399. {
  400. log.Error(ex.Message.ToString());
  401. return false;
  402. }
  403. return true;
  404. }
  405. #endregion
  406. //显示去背景图 = AUTO
  407. #region 显示去背景图
  408. private void ShowRemoveBGImage_Click(object sender, EventArgs e)
  409. {
  410. //设置右键菜单中的项 是否可编辑
  411. SetContextMenuEnabled(true);
  412. m_imagetype = ImageType.RemoveBGImage;
  413. ShowRemoveBGImage();
  414. m_CurrentMultiple = 0;
  415. panelXray.Visible = false;
  416. }
  417. protected void ShowRemoveBGImage()
  418. {
  419. //获取电镜中图像大小
  420. string str = m_MeasureAppForm.m_ProjParam.GetBSEImageResolutionStr();
  421. string[] sArray = str.Split('X');
  422. if (sArray[0] != "" && sArray[1] != "")
  423. {
  424. m_iWidth = Convert.ToInt32(sArray[0]);
  425. m_iHeight = Convert.ToInt32(sArray[1]);
  426. }
  427. //获取图像数据
  428. COTSSample WSample = m_MeasureAppForm.m_ProjRstData.GetWorkingSample();
  429. double pixelSize = WSample.CalculatePixelSize();
  430. var imageProcessParam = WSample.GetMsrParams().GetImageProcessParam();
  431. var imageHandle = new CImageHandler();
  432. bfResult = imageHandle.GetBSEImage(imageProcessParam, pixelSize, originalBseData, m_iWidth, m_iHeight, ref removeBGBseData);
  433. //取图不成功就返回
  434. if (!bfResult) { return; }
  435. Bitmap bitmap = CImageHandler.ToGrayBitmap(removeBGBseData, m_iWidth, m_iHeight);
  436. ShowDoubleImage((Bitmap)picBox.Image, bitmap);
  437. myChart.Visible = false;
  438. //切换显示至BSE图
  439. contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Enabled = true;
  440. }
  441. protected void ShowColoredRemoveBGImage()
  442. {
  443. //获取电镜中图像大小
  444. string str = m_MeasureAppForm.m_ProjParam.GetBSEImageResolutionStr();
  445. string[] sArray = str.Split('X');
  446. if (sArray[0] != "" && sArray[1] != "")
  447. {
  448. m_iWidth = Convert.ToInt32(sArray[0]);
  449. m_iHeight = Convert.ToInt32(sArray[1]);
  450. }
  451. //获取图像数据
  452. COTSSample WSample = m_MeasureAppForm.m_ProjRstData.GetWorkingSample();
  453. double pixelSize = WSample.CalculatePixelSize();
  454. var imageProcessParam = WSample.GetMsrParams().GetImageProcessParam();
  455. var imageHandle = new CImageHandler();
  456. coloredParticleImage = new Bitmap(m_iWidth, m_iHeight);
  457. CBSEImgClr pImgNoBG = new CBSEImgClr(new Rectangle(0, 0, m_iWidth, m_iHeight));
  458. bfResult = imageHandle.GetColoredImage(imageProcessParam, pixelSize, originalBseData, m_iWidth, m_iHeight, ref pImgNoBG, ref coloredParticleImage);
  459. removeBGBseData = pImgNoBG.GetImageDataPtr();
  460. //获取去背景灰度图数据
  461. dGrayAbandonLevelData = new double[(int)GrayLevel.Max];
  462. dGrayAbandonLevelData = GetGrayAbandonData(removeBGBseData, dGrayAbandonLevelData);
  463. //计算灰度去背景最大值
  464. dGrayAbandonLevelMax = dGrayAbandonLevelData[0];
  465. for (int i = 1; i < (int)GrayLevel.Max; i++)
  466. {
  467. dGrayAbandonLevelMax = Math.Max(dGrayAbandonLevelMax, dGrayAbandonLevelData[i]);
  468. }
  469. //取图不成功就返回
  470. if (!bfResult) { return; }
  471. ShowDoubleImage((Bitmap)picBox.Image, coloredParticleImage);
  472. myChart.Visible = false;
  473. picBox.Show();
  474. //切换显示至BSE图
  475. contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Enabled = true;
  476. }
  477. #endregion
  478. //显示灰度曲线
  479. #region 显示灰度曲线
  480. private void ShowGrayLevelImage_Click(object sender, EventArgs e)
  481. {
  482. //设置右键菜单中的项 是否可编辑
  483. SetContextMenuEnabled(false);
  484. ShowGrayLevelImage();
  485. }
  486. protected void ShowGrayLevelImage()
  487. {
  488. //切换显示至BSE图
  489. contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Enabled = true;
  490. contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Enabled = true;
  491. //获取灰度图数据
  492. dGrayLevelData = new double[(int)GrayLevel.Max];
  493. dGrayLevelData = GetGaryData(originalBseData, dGrayLevelData);
  494. int[] XData = new int[(int)GrayLevel.Max];
  495. for (int i = 0; i < (int)GrayLevel.Max; i++)
  496. {
  497. XData[i] = i + 1;
  498. }
  499. int[] YData = new int[dGrayLevelData.Length];
  500. for (int i = 0; i < dGrayLevelData.Length; i++)
  501. {
  502. YData[i] = (int)dGrayLevelData[i];
  503. }
  504. DisChartData(XData, YData, ImageType.GrayLevelChart);
  505. }
  506. #endregion
  507. //显示线扫描曲线
  508. #region 显示线扫描曲线
  509. private void ShowLineScanChart_Click(object sender, EventArgs e)
  510. {
  511. ShowBitmapInPicbox1((Bitmap)picBox.Image);
  512. if (MenuItemLineScan.Checked)
  513. {
  514. m_imagetype = ImageType.GrayLevelLineScan;
  515. timer1.Enabled = true;
  516. }
  517. else
  518. {
  519. m_imagetype = ImageType.BSEImage;
  520. timer1.Enabled = false;
  521. }
  522. }
  523. #endregion
  524. #region 扫描线轴X
  525. public Rectangle GetPictureBoxZoomSize(PictureBox p_PictureBox)
  526. {
  527. if (p_PictureBox != null)
  528. {
  529. PropertyInfo _ImageRectanglePropert = p_PictureBox.GetType().GetProperty("ImageRectangle", BindingFlags.Instance | BindingFlags.NonPublic);
  530. return (Rectangle)_ImageRectanglePropert.GetValue(p_PictureBox, null);
  531. }
  532. return new Rectangle(0, 0, 0, 0);
  533. }
  534. #endregion
  535. private void OTSMeasureStatusWindow_Load(object sender, EventArgs e)
  536. {
  537. System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(OTSMeasureStatusWindow));
  538. this.control_XRayTable1 = new Control_XRayTable();
  539. this.control_XRayTable1.BackColor = System.Drawing.Color.FromArgb(180, 255, 255);
  540. this.control_XRayTable1.Dock = System.Windows.Forms.DockStyle.Fill;
  541. this.control_XRayTable1.GBInfoStr = "";
  542. this.control_XRayTable1.GoodChineseName = "";
  543. this.control_XRayTable1.GoodName = "";
  544. this.control_XRayTable1.List_ShowElementInfo = ((System.Collections.Generic.List<OTSIncAGraph.Controls.ShowElementInfo>)(resources.GetObject("control_XRayTable1.List_ShowElementInfo")));
  545. this.control_XRayTable1.Location = new System.Drawing.Point(0, 0);
  546. this.control_XRayTable1.Margin = new System.Windows.Forms.Padding(2);
  547. this.control_XRayTable1.Name = "control_XRayTable1";
  548. this.control_XRayTable1.ShowAnalysisXray = true;
  549. this.control_XRayTable1.ShowSearchXray = false;
  550. this.control_XRayTable1.Size = new System.Drawing.Size(781, 200);
  551. this.control_XRayTable1.STDName = "";
  552. this.control_XRayTable1.TabIndex = 0;
  553. this.control_XRayTable1 = new OTSIncAGraph.Controls.Control_XRayTable();
  554. this.panelXray.Controls.Add(this.control_XRayTable1);
  555. //添加鼠标点击事件
  556. myChart.MouseClick += new MouseEventHandler(this.LZMeasureStatusWindow_MouseClick);
  557. picBox.MouseClick += new MouseEventHandler(HiddenXrayTablePanel_MouseClick);
  558. //
  559. // pbBSEImage添加鼠标操作
  560. //
  561. this.picBox.MouseUp += new MouseEventHandler(this.pbBSEImage_MouseUp);
  562. this.picBox.MouseDown += new MouseEventHandler(this.pbBSEImage_MouseDown);
  563. this.MouseUp += new MouseEventHandler(this.pbBSEImage_MouseUp);
  564. this.MouseDown += new MouseEventHandler(this.pbBSEImage_MouseDown);
  565. this.MouseWheel += new MouseEventHandler(this.pbBSEImage_MouseWheel);
  566. log = NLog.LogManager.GetCurrentClassLogger();
  567. }
  568. private void HiddenXrayTablePanel_MouseClick(object sender, MouseEventArgs e)
  569. {
  570. if (e.Button != MouseButtons.Right)
  571. {
  572. if (m_imagetype != ImageType.GrayLevelLineScan)
  573. {
  574. if (m_ElementPointGDIObjects != null)
  575. {
  576. if (m_ElementPointGDIObjects.Count > 0)
  577. {
  578. foreach (var item in m_ElementPointGDIObjects)
  579. {
  580. if (Math.Abs(e.Y - item.GetOrigionalDrawRegionF().Y) < 5 && Math.Abs(e.X - item.GetOrigionalDrawRegionF().X) < 5)
  581. {
  582. //显示Xray图像
  583. panelXray.Visible = true;
  584. }
  585. else
  586. {
  587. panelXray.Visible = false;
  588. }
  589. }
  590. }
  591. }
  592. }
  593. }
  594. }
  595. private void LZMeasureStatusWindow_MouseClick(object sender, MouseEventArgs e)
  596. {
  597. if (e.Button == MouseButtons.Right && e.Clicks == 1)
  598. {
  599. contextMenuStrip1.Show(PointToScreen(e.Location));
  600. SetContentMenu();
  601. }
  602. }
  603. #region 设置右键菜单中的项 是否可编辑
  604. protected void SetContextMenuEnabled(bool isEnabled)
  605. {
  606. //隐藏右键菜单中的项
  607. //MenuItemLineScan.Checked = false;
  608. MenuItemLineScan.Enabled = true;
  609. PointScanElementMenuItem.Enabled = isEnabled;
  610. bool showExprot = m_ElementPointGDIObjects.Count > 0 ? true : false;
  611. ExportScanInfoMenuItem.Enabled = showExprot;
  612. //IsShowGrayLevelLine = false;
  613. VisualAdjustingMenu.Enabled = isEnabled;
  614. toolStripMenuItem1.Enabled = true;
  615. this.Cursor = Cursors.Default;
  616. this.Validate();
  617. }
  618. #endregion
  619. #region 获取行数据
  620. private void GetLineImage(int iHeight, int iWidth, ref byte[] bdata)
  621. {
  622. Stream stream = null;
  623. //if (m_imagetype == ImageType.BSEImage)
  624. //{
  625. stream = new MemoryStream(originalBseData);
  626. //}
  627. //else if (m_imagetype == ImageType.RemoveBGImage)
  628. //{
  629. // stream = new MemoryStream(removeBGBseData);
  630. //}
  631. if (iHeight >= 0)
  632. {
  633. stream.Seek(iHeight * iWidth, SeekOrigin.Begin);
  634. }
  635. stream.Read(bdata, 0, iWidth);
  636. }
  637. #endregion
  638. private void panel1_Click(object sender, EventArgs e)
  639. {
  640. picBox.Show();
  641. }
  642. private void contextMenuStrip1_Opened(object sender, EventArgs e)
  643. {
  644. if (bfResult)
  645. {
  646. SampleParaLock.Enabled = true;
  647. ToolStripMenuItem.Enabled = true;
  648. grayToolStripMenuItem.Enabled = true;
  649. AbandonGrayStripMenuItem.Enabled = true;
  650. toolStripMenuItem2.Enabled = true;
  651. ChangeDiffImageShow.Enabled = true;
  652. if (0 <= m_MouseMoveImageX && m_MouseMoveImageX <= 1024)
  653. {
  654. PointScanElementMenuItem.Enabled = true;
  655. }
  656. else
  657. {
  658. PointScanElementMenuItem.Enabled = false;
  659. }
  660. if (!MenuItemLineScan.Checked)
  661. {
  662. PointScanElementMenuItem.Enabled = true;
  663. bool showExprot = m_ElementPointGDIObjects.Count > 0 ? true : false;
  664. if (showExprot)
  665. {
  666. ExportScanInfoMenuItem.Enabled = true;
  667. }
  668. }
  669. else
  670. {
  671. PointScanElementMenuItem.Enabled = false;
  672. ExportScanInfoMenuItem.Enabled = false;
  673. return;
  674. }
  675. if (myChart.Visible)
  676. {
  677. //MenuItemLineScan.Enabled = false;
  678. PointScanElementMenuItem.Enabled = false;
  679. ExportScanInfoMenuItem.Enabled = false;
  680. }
  681. else
  682. {
  683. //MenuItemLineScan.Enabled = true;
  684. PointScanElementMenuItem.Enabled = true;
  685. bool showExprot = m_ElementPointGDIObjects.Count > 0 ? true : false;
  686. if (showExprot)
  687. {
  688. ExportScanInfoMenuItem.Enabled = true;
  689. }
  690. }
  691. //根据去背景方式 设置可视化使用状态
  692. COTSSample WSample = m_MeasureAppForm.m_ProjRstData.GetWorkingSample();
  693. COTSImageProcParam ImgProcPrm = WSample.GetMsrParams().GetImageProcessParam();
  694. if (ImgProcPrm.GetBGRemoveType() == otsdataconst.OTS_BGREMOVE_TYPE.MANUAL)
  695. {
  696. VisualAdjustingMenu.Enabled = true;
  697. }
  698. else
  699. {
  700. VisualAdjustingMenu.Enabled = false;
  701. }
  702. }
  703. else
  704. {
  705. ToolStripMenuItem.Enabled = false;
  706. grayToolStripMenuItem.Enabled = false;
  707. MenuItemLineScan.Enabled = false;
  708. AbandonGrayStripMenuItem.Enabled = false;
  709. }
  710. }
  711. //拖动灰度线
  712. #region 拖动灰度线
  713. int LineX = 0;
  714. int LineXEnd = 0;
  715. public Point pointStart = new Point(100, 100);
  716. public Point pointEnd = new Point(400, 100);
  717. private bool m_bMouseDown = false;
  718. private void pictureBox1_Paint(object sender, PaintEventArgs e)
  719. {
  720. if (!bfResult)
  721. {
  722. return;
  723. }
  724. if (m_imagetype == ImageType.GrayLevelLineScan)
  725. {
  726. Rectangle rectangle = GetPictureBoxZoomSize(picBox);
  727. if (pointStart.Equals(pointEnd))
  728. {
  729. return;
  730. }
  731. Point start = new Point(100, pointStart.Y);
  732. Point end = new Point(500, pointEnd.Y);
  733. double rate = (double)picBox.Image.Height / (double)rectangle.Height;
  734. int YSize = Convert.ToInt32((rate * (double)pointStart.Y));
  735. //显示线扫描 黄色线的曲线数据
  736. var Imagedata = new byte[m_iWidth];
  737. YSize = Convert.ToInt32((rate * (double)pointStart.Y));
  738. GetLineImage(YSize, m_iWidth, ref Imagedata);
  739. DrawCurve(Imagedata, e);
  740. e.Graphics.DrawLine(new Pen(Color.Red), new Point(rectangle.X, rectangle.Y + (rectangle.Height) / 4), new Point(rectangle.X + rectangle.Width, rectangle.Y + (rectangle.Height) / 4));
  741. e.Graphics.DrawLine(new Pen(Color.Red), new Point(rectangle.X, rectangle.Y + rectangle.Height * 3 / 4), new Point(rectangle.X + rectangle.Width, rectangle.Y + rectangle.Height * 3 / 4));
  742. e.Graphics.DrawLine(new Pen(Color.Blue), new Point(rectangle.X, pointStart.Y), new Point(rectangle.X + rectangle.Width, pointEnd.Y));
  743. #region 绘制刻度条
  744. float offHeight = (rectangle.Y + (rectangle.Height) / 4) - (rectangle.Y + rectangle.Height * 3 / 4);
  745. float grayValue = Math.Abs(offHeight / 255);
  746. //设置文字对齐方式
  747. StringFormat sf = new StringFormat();
  748. sf.Alignment = StringAlignment.Center;
  749. sf.LineAlignment = StringAlignment.Center;
  750. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(100, Color.Red));
  751. //字体大小 根据样品孔Rectangle大小
  752. float fontSize = 15;
  753. Font font = new Font("黑体", fontSize, FontStyle.Bold);
  754. Pen pen = new Pen(Color.Red, 1);
  755. pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;
  756. pen.DashPattern = new float[] { 5, 5 };
  757. int fontOffWidth = 50;
  758. int fontOffHeight = 10;
  759. int scaleLine = 0;
  760. for (int i = 25; i <= 225; i += 25)
  761. {
  762. scaleLine = (int)(grayValue * i);
  763. e.Graphics.DrawLine(pen, new Point(rectangle.X, (rectangle.Y + rectangle.Height * 3 / 4) - scaleLine), new Point(rectangle.X + fontOffWidth, (rectangle.Y + rectangle.Height * 3 / 4) - scaleLine));
  764. e.Graphics.DrawString(i.ToString(), font, solidBrush, rectangle.X + 20, (rectangle.Y + rectangle.Height * 3 / 4) - scaleLine - fontOffHeight, sf);
  765. }
  766. #endregion
  767. }
  768. else
  769. {
  770. if (m_ElementPointGDIObjects != null)
  771. {
  772. if (m_ElementPointGDIObjects.Count > 0)
  773. {
  774. //绘制采集点标记
  775. foreach (CRectangleGDIObject item in m_ElementPointGDIObjects)
  776. {
  777. if (item != null)
  778. {
  779. item.OnPaint(e);
  780. }
  781. }
  782. }
  783. }
  784. }
  785. }
  786. private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
  787. {
  788. //如果pictureBox1中没有图像 则return退出
  789. if (picBox.Image == null)
  790. {
  791. return;
  792. }
  793. Control lCtrl = (sender as Control);
  794. Rectangle rectangle = GetPictureBoxZoomSize(picBox);
  795. int startimageX = 0;
  796. int startimageY = 0;
  797. //处理灰度值
  798. int grayValue = 0;
  799. // 生成鼠标的位置
  800. int MouseLine = e.X;
  801. //当前鼠标所在图片中的位置
  802. int imageX = 0;
  803. int imageY = 0;
  804. //当前pictrueBox与实际图片的X、Y比例
  805. double rateX = 0;
  806. double rateY = 0;
  807. if (originalBseData != null)
  808. {
  809. if ((picBox.Width - rectangle.Width) / 2 < e.X && e.X < (picBox.Width - rectangle.Width) / 2 + rectangle.Width)
  810. {
  811. imageX = e.X - (picBox.Width - rectangle.Width) / 2;
  812. rateX = (double)m_iWidth / (double)rectangle.Width;
  813. startimageX = Convert.ToInt32(imageX * rateX);
  814. m_MouseMoveImageX = startimageX;
  815. if (MoveFlag)
  816. {
  817. picBox.Left += Convert.ToInt32(e.X - xPos);//设置x坐标.
  818. picBox.Top += Convert.ToInt32(e.Y - yPos);//设置y坐标.
  819. }
  820. }
  821. else
  822. {
  823. startimageX = 0;
  824. m_MouseMoveImageX = -1;
  825. }
  826. if ((picBox.Height - rectangle.Height) / 2 < e.Y && e.Y < (picBox.Height - rectangle.Height) / 2 + rectangle.Height)
  827. {
  828. imageY = e.Y - (picBox.Height - rectangle.Height) / 2;
  829. rateY = (double)m_iHeight / (double)rectangle.Height;
  830. startimageY = Convert.ToInt32(imageY * rateY);
  831. m_MouseMoveImageY = startimageY;
  832. }
  833. //如果当前鼠标在图像Y轴中
  834. if (imageX > 0 && imageY > 0)
  835. {
  836. if (imageY > 1)
  837. {
  838. startimageX = startimageX + (startimageY * m_iWidth);
  839. grayValue = originalBseData[startimageX];
  840. }
  841. else if (startimageY == 1)
  842. {
  843. grayValue = originalBseData[startimageX];
  844. }
  845. }
  846. else
  847. {
  848. grayValue = 0;
  849. }
  850. }
  851. LineX = rectangle.X + 1;
  852. LineXEnd = rectangle.X + rectangle.Width;
  853. if (LineX < MouseLine && MouseLine < LineXEnd)
  854. {
  855. if (MenuItemLineScan.Checked)
  856. {
  857. if (Math.Abs(e.Y - pointStart.Y) < 2)
  858. {
  859. this.Cursor = Cursors.SizeNS;
  860. }
  861. else
  862. {
  863. this.Cursor = Cursors.Default;
  864. }
  865. }
  866. }
  867. //Y值
  868. double rate = (double)picBox.Image.Height / (double)rectangle.Height;
  869. int YSize = Convert.ToInt32((rate * (double)e.Y));
  870. string strGrayValue = grayValue.ToString();
  871. switch (strGrayValue.ToString().Length)
  872. {
  873. case 1:
  874. strGrayValue = " " + grayValue.ToString();
  875. break;
  876. case 2:
  877. strGrayValue = " " + grayValue.ToString();
  878. break;
  879. }
  880. //此处调接口显示灰度值
  881. m_MeasureAppForm.ShowGrayVal(strGrayValue.ToString());
  882. if (m_imagetype != ImageType.GrayLevelLineScan)
  883. {
  884. if (m_ElementPointGDIObjects != null)
  885. {
  886. if (m_ElementPointGDIObjects.Count > 0)
  887. {
  888. foreach (var item in m_ElementPointGDIObjects)
  889. {
  890. Rectangle rect = new Rectangle(e.Location, new Size(1, 1));
  891. if (Math.Abs(e.Y - item.GetOrigionalDrawRegionF().Y) < 5 && Math.Abs(e.X - item.GetOrigionalDrawRegionF().X) < 5)
  892. {
  893. //设置鼠标样式
  894. this.Cursor = Cursors.Hand;
  895. }
  896. else
  897. {
  898. this.Cursor = Cursors.Default;
  899. }
  900. }
  901. }
  902. }
  903. }
  904. if (e.Button != MouseButtons.Left)
  905. {
  906. return;
  907. }
  908. pointStart = new Point(pointStart.X, e.Y);
  909. pointEnd = new Point(pointEnd.X, e.Y);
  910. picBox.Refresh();
  911. }
  912. private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
  913. {
  914. m_mouseCurrentPoint = e.Location;
  915. if (e.Button != MouseButtons.Left)
  916. {
  917. return;
  918. }
  919. m_bMouseDown = !m_bMouseDown;
  920. }
  921. #endregion
  922. //显示去背景BSE图得灰度曲线值
  923. #region 显示去背景BSE图得灰度曲线值
  924. private void ShowAbandonGrayLevelImage_Click(object sender, EventArgs e)
  925. {
  926. //设置右键菜单中的项 是否可编辑
  927. SetContextMenuEnabled(false);
  928. ShowAbandonGrayLevelImage();
  929. }
  930. private double[] GetGrayAbandonData(byte[] Imagedata, double[] GrayAbandonLevelData)
  931. {
  932. //获得下标每一点的灰度值,并在数组里加一
  933. for (int i = 0; i < Imagedata.Length; i++)
  934. {
  935. byte graylevel = Imagedata[i];
  936. if (graylevel > 0 && graylevel < 255)
  937. {
  938. GrayAbandonLevelData[graylevel] += 1;
  939. }
  940. }
  941. return GrayAbandonLevelData;
  942. }
  943. protected void ShowAbandonGrayLevelImage()
  944. {
  945. m_imagetype = ImageType.GrayAbandonLevelChart;
  946. COTSSample WSample = m_MeasureAppForm.m_ProjRstData.GetWorkingSample();
  947. var pixelSize = WSample.CalculatePixelSize();
  948. var imageHandle = new CImageHandler();
  949. if (removeBGBseData == null)
  950. {
  951. bfResult = imageHandle.GetBSEImage(WSample.GetMsrParams().GetImageProcessParam(), pixelSize, originalBseData, m_iWidth, m_iHeight, ref removeBGBseData);
  952. }
  953. if (bfResult)
  954. {
  955. dGrayAbandonLevelData = new double[(int)GrayLevel.Max];
  956. GetGrayAbandonData(removeBGBseData, dGrayAbandonLevelData);
  957. //计算灰度去背景最大值
  958. dGrayAbandonLevelMax = dGrayAbandonLevelData[0];
  959. for (int i = 0; i < (int)GrayLevel.Max; i++)
  960. {
  961. dGrayAbandonLevelMax = Math.Max(dGrayAbandonLevelMax, dGrayAbandonLevelData[i]);
  962. }
  963. }
  964. //picBox.Hide();
  965. int[] XData = new int[(int)GrayLevel.Max];
  966. for (int i = 0; i < (int)GrayLevel.Max; i++)
  967. {
  968. XData[i] = i + 1;
  969. }
  970. int[] YData = new int[dGrayAbandonLevelData.Length];
  971. for (int i = 0; i < dGrayAbandonLevelData.Length; i++)
  972. {
  973. YData[i] = (int)dGrayAbandonLevelData[i];
  974. }
  975. DisChartData(XData, YData, ImageType.GrayAbandonLevelChart);
  976. }
  977. #endregion
  978. private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
  979. {
  980. if (e.Button == MouseButtons.Right && e.Clicks == 1)
  981. {
  982. int XMenu = picBox.Left + e.Location.X;
  983. int YMenu = picBox.Top + e.Location.Y;
  984. Point mousePoint = new Point(XMenu, YMenu);
  985. contextMenuStrip1.Show(PointToScreen(mousePoint));
  986. //电镜位置信息
  987. Point semLocatin = new Point((int)dPositionX, (int)dPositionY);
  988. //Rectangle semRect = new Rectangle();
  989. if (IsSEMLocationOnTheSampleStage(semLocatin))
  990. {
  991. SetContentMenu();
  992. }
  993. }
  994. }
  995. private void ChangeDiffImageShow_Click(object sender, EventArgs e)
  996. {
  997. SetContextMenuEnabled(true);
  998. //显示BSE图
  999. if (originalBseData != null)
  1000. {
  1001. //用于线扫描曲线
  1002. m_imagetype = ImageType.BSEImage;
  1003. //在控件中显示图像
  1004. Bitmap bitmap = CImageHandler.ToGrayBitmap(originalBseData, m_iWidth, m_iHeight);
  1005. ShowBitmapInPicbox1(bitmap);
  1006. }
  1007. m_CurrentMultiple = 0;
  1008. panelXray.Visible = false;
  1009. }
  1010. #region 显示鼠标位置
  1011. /// <summary>
  1012. /// 显示鼠标位置
  1013. /// </summary>
  1014. /// <param name="eMouseLocation">当前处理后的鼠标路径 减去边缘</param>
  1015. /// <param name="imageRect">Pictrue中的图像尺寸与位置</param>
  1016. public void ShowMouseSEMCurrentLocation(Point eMouseLocation, Rectangle imageRect, Rectangle semRect)
  1017. {
  1018. //真实图像中心点
  1019. Point imgRealCenterPoint = new Point();
  1020. //显示图像中心点
  1021. Point imgCenterPoint = new Point();
  1022. int imgWidth = 0;
  1023. int imgHeight = 0;
  1024. //获取真实图片的分辨率
  1025. m_MeasureAppForm.m_ProjParam.GetBSEImageSize(ref imgWidth, ref imgHeight);
  1026. //根据真实图像的像素 获取真实图像中心点
  1027. imgRealCenterPoint.X = imgWidth / 2;
  1028. imgRealCenterPoint.Y = imgHeight / 2;
  1029. //图像与真是图像的宽高的比例
  1030. double witdhRote = 0;
  1031. double heightRote = 0;
  1032. //获取显示图像与真是图像的宽高的比例
  1033. witdhRote = (double)imageRect.Width / imgWidth;
  1034. heightRote = (double)imageRect.Height / imgHeight;
  1035. //获取每个单位中包含多少像素 根据帧图的长度 与 真实图像的长度计算
  1036. double lenghtInPixWidth = (double)FieldWitdh / imgWidth / witdhRote;
  1037. double lenghtInPixHeight = (double)FieldHeight / imgHeight / heightRote;
  1038. //通过鼠标当前位置 获取位置 原点为控件的左上角起始点
  1039. double MouseWidth = (double)eMouseLocation.X * lenghtInPixWidth;
  1040. double MouseHeight = (double)eMouseLocation.Y * lenghtInPixHeight;
  1041. //根据显示图像的像素 获取真实图像中心点
  1042. imgCenterPoint.X = imageRect.Width / 2;
  1043. imgCenterPoint.Y = imageRect.Height / 2;
  1044. //通过鼠标当前位置 获取位置 原点为控件的左上角起始点
  1045. double imgCenterWidth = (double)imgCenterPoint.X * lenghtInPixWidth;
  1046. double imgCenterHeight = (double)imgCenterPoint.Y * lenghtInPixHeight;
  1047. //获取当前鼠标坐标与SEM当前坐标的距离 单位毫米
  1048. double apartCenterPointWidth = MouseWidth - imgCenterWidth;
  1049. double apartCenterPointHeight = MouseHeight - imgCenterHeight;
  1050. //将微米转换为毫米
  1051. float mousePointX = Convert.ToSingle((apartCenterPointWidth / 1000).ToString("F3"));
  1052. float mousePointY = Convert.ToSingle((apartCenterPointHeight / 1000).ToString("F3"));
  1053. //根据Sem电镜当前位置 计算与SEM坐标起始点相差的距离
  1054. //1.获取电镜当前位置
  1055. double semX = dPositionX;
  1056. double semY = dPositionY;
  1057. //2.获取当前电镜位置与SEM原点位置的距离
  1058. string apartToSEMWidth = Convert.ToSingle(semX + mousePointX).ToString("F3");
  1059. string apartToSEMHeight = Convert.ToSingle(semY - mousePointY).ToString("F3");
  1060. //编辑显示内容
  1061. string STSemCoordinate = "X:" + apartToSEMWidth + "|Y:" + apartToSEMHeight + "";
  1062. }
  1063. #endregion
  1064. #region 设置测量状态初始化
  1065. /// <summary>
  1066. /// 设置测量状态初始化
  1067. /// </summary>
  1068. public void SetMeasureStatusInit()
  1069. {
  1070. picBox.Hide();
  1071. foreach (ToolStripItem item in contextMenuStrip1.Items)
  1072. {
  1073. if (item != contextMenuStrip1.Items[(int)MeasureStateMenuType.ReadBSEPic])
  1074. {
  1075. item.Enabled = false;
  1076. }
  1077. }
  1078. }
  1079. #endregion
  1080. #region 鼠标是否在图像上移动
  1081. /// <summary>
  1082. /// 鼠标是否在图像上移动
  1083. /// </summary>
  1084. /// <param name="mouseCurrentLocation"></param>
  1085. /// <param name="picBox"></param>
  1086. /// <returns></returns>
  1087. public bool IsOnTheImage(Point mouseCurrentLocation, PictureBox picBox, ref Point mouseLocation, ref Rectangle imageRect)
  1088. {
  1089. //通过Pictrue获取图像尺寸位置
  1090. Rectangle rectangle = GetPictureBoxZoomSize(picBox);
  1091. imageRect = rectangle;
  1092. //当前鼠标坐标是否包含在图像中
  1093. bool result = imageRect.Contains(mouseCurrentLocation);
  1094. if (result)
  1095. {
  1096. //获取与边框的间隔
  1097. mouseLocation.X = mouseCurrentLocation.X - rectangle.X;
  1098. mouseLocation.Y = mouseCurrentLocation.Y;
  1099. return true;
  1100. }
  1101. return false;
  1102. }
  1103. #endregion
  1104. #region 判断当前电镜位置是否在样品台内部
  1105. /// <summary>
  1106. /// 判断当前电镜位置是否在样品台内部
  1107. /// </summary>
  1108. /// <param name="semLocation">电镜当前位置</param>
  1109. /// <param name="SampleStage">样品台尺寸与位置</param>
  1110. /// <returns></returns>
  1111. public bool IsSEMLocationOnTheSampleStage(Point semLocation)
  1112. {
  1113. return m_MeasureAppForm.m_SamplepaceWindow.m_visualStage.IfMouseInStage(semLocation);
  1114. }
  1115. #endregion
  1116. #region 设置右键菜单项是否可用
  1117. /// <summary>
  1118. /// 设置右键菜单项是否可用
  1119. /// </summary>
  1120. public void SetContentMenu()
  1121. {
  1122. int sampleCount = m_MeasureAppForm.m_ProjParam.GetSampleCount();
  1123. if (sampleCount == 0)
  1124. {
  1125. foreach (ToolStripItem item in contextMenuStrip1.Items)
  1126. {
  1127. item.Enabled = false;
  1128. }
  1129. }
  1130. else
  1131. {
  1132. if (m_MeasureAppForm.MeasureThreadRunFlag)
  1133. {
  1134. if (m_MeasureAppForm.m_MsrThreadWrapper.BgWorkIsPaused())
  1135. {
  1136. foreach (ToolStripItem item in contextMenuStrip1.Items)
  1137. {
  1138. item.Enabled = true;
  1139. }
  1140. }
  1141. else
  1142. {
  1143. foreach (ToolStripItem item in contextMenuStrip1.Items)
  1144. {
  1145. item.Enabled = false;
  1146. }
  1147. }
  1148. }
  1149. double iWDistance = 0;
  1150. double dMagni = 0;
  1151. m_MeasureAppForm.m_ProjParam.GetWorkingSampleSEMData(ref iWDistance, ref dMagni);
  1152. if (iWDistance != 0 && dMagni != 0)
  1153. {
  1154. contextMenuStrip1.Items[(int)MeasureStateMenuType.ReadBSEPic].Enabled = true;
  1155. }
  1156. }
  1157. }
  1158. #endregion
  1159. public void DisChartData(int[] XData, int[] YData, ImageType imgtype)
  1160. {
  1161. m_imagetype = imgtype;
  1162. //添加数据
  1163. myChart.Series[0].Points.DataBindXY(XData, YData);
  1164. myChart.Series[0].Label = "";
  1165. myChart.Series[0].LegendText = "";
  1166. myChart.Series[0].Name = "Graph";
  1167. myChart.Series[0].IsVisibleInLegend = false;
  1168. switch (imgtype)
  1169. {
  1170. case ImageType.GrayLevelChart:
  1171. myChart.Titles[0].Text = "B-GrayCurve";
  1172. picBox.Hide();
  1173. pictureBox2.Hide();
  1174. myChart.Visible = true;
  1175. break;
  1176. case ImageType.GrayAbandonLevelChart:
  1177. myChart.Titles[0].Text = "Remove Background Gray-scaleCurve";
  1178. picBox.Hide();
  1179. pictureBox2.Hide();
  1180. myChart.Visible = true;
  1181. break;
  1182. case ImageType.GrayLevelLineScan:
  1183. pictureBox2.Hide();
  1184. myChart.Visible = true;
  1185. break;
  1186. default:
  1187. myChart.Titles[0].Text = "";
  1188. break;
  1189. }
  1190. panelXray.Visible = false;
  1191. }
  1192. private void PointScanElementMenuItem_Click(object sender, EventArgs e)
  1193. {
  1194. MenuItemLineScan.Checked = false;
  1195. //电镜设置对象
  1196. //控制类对象初始化
  1197. var expC = m_MeasureAppForm.m_ProjRstData.GetWorkingSample().GetMsrParams().GetXRayParam().GetAnalyExpCount();
  1198. IEDSController m_EDSHardwareMgr = EDSController.GetEDSController(m_iWidth, m_iHeight, expC);
  1199. //1.连接电镜
  1200. if (m_EDSHardwareMgr.Connect())
  1201. {
  1202. COTSMsrPrjResultData cProjMgr = m_MeasureAppForm.m_ProjParam.GetResultData();
  1203. //获取工作样品对象
  1204. COTSSample sampleClr = cProjMgr.GetWorkingSample();
  1205. //清空之前记录的标识
  1206. if (m_ElementPointGDIObjects != null)
  1207. {
  1208. if (m_ElementPointGDIObjects.Count > 0)
  1209. {
  1210. //清空
  1211. m_ElementPointGDIObjects.Clear();
  1212. }
  1213. }
  1214. //2.获取鼠标在图像的位置
  1215. dMouseImgX = m_MouseMoveImageX;
  1216. dMouseImgY = m_MouseMoveImageY;
  1217. //3.根据所要扫描的位置进行元素分析
  1218. uint a_Milliseconds = 0;
  1219. //采集时间
  1220. a_Milliseconds = Convert.ToUInt32(sampleClr.GetMsrParams().GetXRayParam().GetMidAnalyAQTime());
  1221. //元素数量
  1222. ValueType a_nElementNum = 0;
  1223. //元素名称
  1224. string a_strElementName = "";
  1225. //元素Xray数据
  1226. uint[] a_ElementXrayData = new uint[2000];
  1227. if (GetXRayAndElements(a_Milliseconds, (int)dMouseImgX, (int)dMouseImgY, ref a_ElementXrayData, ref a_nElementNum, ref a_strElementName))
  1228. {
  1229. log.Trace("--获取单点扫描数据:元素数量:'" + a_nElementNum + "' ,元素名称:'" + a_strElementName + "'--");
  1230. //4.在BSE上绘制扫描标记
  1231. //4-1 获取鼠标在BSE图上的位置
  1232. Point p_mouseCurrentTempPoint = m_mouseCurrentPoint;
  1233. //4-2 根据位置绘制标记
  1234. Point ImgPoint = new Point((int)dMouseImgX, (int)dMouseImgY);
  1235. Rectangle rect = new Rectangle(p_mouseCurrentTempPoint, new Size(1, 1));
  1236. CRectangleGDIObject createRect = new CRectangleGDIObject(rect, ImgPoint, m_CurrentMultiple, CreateRectangleType.DrawBSEElementSignPoint);
  1237. m_ElementPointGDIObjects.Add(createRect);
  1238. //5.获取成功后弹出对话框
  1239. //计数率
  1240. double electronicCount = 0;
  1241. uint[] u_ElementXrayData = new uint[2000];
  1242. for (int i = 0; i < a_ElementXrayData.Length; i++)
  1243. {
  1244. u_ElementXrayData[i] = (uint)a_ElementXrayData[i];
  1245. //累加计数率
  1246. electronicCount += a_ElementXrayData[i];
  1247. }
  1248. //显示Xray控件
  1249. panelXray.Visible = true;
  1250. //获取数据后,需要对xraytable设置
  1251. string[] strGroup = a_strElementName.Split('\n');
  1252. //get CElementChemistryClr list
  1253. List<ShowElementInfo> list_showelementinfo = new List<ShowElementInfo>();
  1254. for (int i = 0; i < strGroup.Length; i++)
  1255. {
  1256. if (!strGroup[i].Equals(""))
  1257. {
  1258. ShowElementInfo ls_sei = new ShowElementInfo();
  1259. ls_sei.ElementName = strGroup[i].Split(':')[0];
  1260. ls_sei.Percentage = Convert.ToDouble(strGroup[i].Split(':')[1]);
  1261. ls_sei.dKF = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).K_Peak);
  1262. double de_sx2 = 0;
  1263. if (CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "" || CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "-")
  1264. {
  1265. de_sx2 = 0;
  1266. }
  1267. else
  1268. {
  1269. de_sx2 = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak);
  1270. }
  1271. ls_sei.dLF = de_sx2;
  1272. list_showelementinfo.Add(ls_sei);
  1273. }
  1274. }
  1275. //设置分析Xray数据
  1276. control_XRayTable1.SetXRayShowLineValue(new uint[2000], u_ElementXrayData, list_showelementinfo);
  1277. //需要显示计数率
  1278. string strElectronicCount = string.Empty;
  1279. if (electronicCount > 1000)
  1280. {
  1281. strElectronicCount = (Convert.ToDouble(electronicCount) / 1000).ToString("f2") + "kcps";
  1282. }
  1283. control_XRayTable1.List_ShowElementInfo = list_showelementinfo;
  1284. }
  1285. ExportScanInfoMenuItem.Enabled = true;
  1286. this.Invalidate();
  1287. }
  1288. }
  1289. public bool GetXRayAndElements(uint a_nXRayAQTime, int dMouseImgX, int dMouseImgY, ref uint[] a_XrayData, ref ValueType a_nElementNum, ref string a_strResult)
  1290. {
  1291. var expC = m_MeasureAppForm.m_ProjRstData.GetWorkingSample().GetMsrParams().GetXRayParam().GetAnalyExpCount();
  1292. var eds = EDSController.GetEDSController(m_iWidth, m_iHeight, expC);
  1293. var mode = m_MeasureAppForm.m_ProjRstData.GetWorkingSample().GetMsrParams().GetXRayParam().GetScanMode();
  1294. var part = new COTSParticleClr();
  1295. part.SetXRayPos(new Point(dMouseImgX, dMouseImgY));
  1296. var xray = part.GetXray();
  1297. xray.SetIndex(0);
  1298. part.SetXray(xray);
  1299. var parts = new List<COTSParticleClr>();
  1300. parts.Add(part);
  1301. if (mode == otsdataconst.OTS_X_RAY_SCAN_MODE.PointMode)
  1302. {
  1303. eds.GetXRayByParts(parts, a_nXRayAQTime, true);
  1304. }
  1305. else
  1306. {
  1307. eds.GetXRayByFeatures(parts, a_nXRayAQTime, true);
  1308. }
  1309. a_XrayData = parts[0].GetXray().GetXrayData();
  1310. a_strResult = parts[0].GetXray().GetQuantifiedElementsStr();
  1311. return true;
  1312. }
  1313. public void DelElementPointGDIObjects()
  1314. {
  1315. if (m_ElementPointGDIObjects != null)
  1316. {
  1317. if (m_ElementPointGDIObjects.Count > 0)
  1318. {
  1319. //删除点标记
  1320. m_ElementPointGDIObjects.Clear();
  1321. this.Invalidate();
  1322. }
  1323. }
  1324. }
  1325. private void ExportScanInfoMenuItem_Click(object sender, EventArgs e)
  1326. {
  1327. //导出图片到报告中
  1328. ExportReport();
  1329. }
  1330. /// <summary>
  1331. /// 导出Image到报告
  1332. /// </summary>
  1333. private bool ExportReport()
  1334. {
  1335. string startupPath = System.Windows.Forms.Application.StartupPath + "\\TempReport\\";
  1336. if (!Directory.Exists(startupPath))
  1337. {
  1338. Directory.CreateDirectory(startupPath);
  1339. }
  1340. //保存Xray图片
  1341. string ImgFilePath = startupPath + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpg";
  1342. Bitmap bseBM = new Bitmap(this.picBox.Width, this.picBox.Height);
  1343. this.picBox.DrawToBitmap(bseBM, new Rectangle(0, 0, this.picBox.Width, this.picBox.Height));
  1344. //保存图片
  1345. bseBM.Save(ImgFilePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  1346. //释放资源
  1347. bseBM.Dispose();
  1348. //保存Xray图片
  1349. string ImgXrayFilePath = startupPath + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpg";
  1350. int xrayWidth = control_XRayTable1.Width;
  1351. int xrayHeight = control_XRayTable1.Height;
  1352. Bitmap xrayBM = new Bitmap(xrayWidth, xrayHeight);
  1353. this.control_XRayTable1.DrawToBitmap(xrayBM, new Rectangle(0, 0, xrayWidth, xrayHeight));
  1354. //保存图片
  1355. xrayBM.Save(ImgXrayFilePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  1356. //释放资源
  1357. xrayBM.Dispose();
  1358. List<string> listFilePath = new List<string>();
  1359. listFilePath.Add(ImgFilePath);
  1360. listFilePath.Add(ImgXrayFilePath);
  1361. List<ShowElementInfo> list_ElementInfo = control_XRayTable1.List_ShowElementInfo;
  1362. //1.编辑信息
  1363. DataTable dt = new DataTable();
  1364. dt.Columns.Add("元素名称");
  1365. dt.Columns.Add("原子数");
  1366. dt.Columns.Add("质量百分比");
  1367. dt.Columns.Add("摩尔比");
  1368. foreach (var item in list_ElementInfo)
  1369. {
  1370. //获取摩尔比与原子数
  1371. CElementChemistry cElementChemistry = new CElementChemistry();
  1372. cElementChemistry.SetName(item.ElementName);
  1373. cElementChemistry.SetPercentage(item.Percentage);
  1374. double molarValue = Math.Round(cElementChemistry.GetMolarPercentage(), 2);
  1375. int atomNum = (int)CElement.GetAtomicNum(item.ElementName);
  1376. DataRow dr = dt.NewRow();
  1377. dr[0] = item.ElementName;
  1378. dr[1] = atomNum;
  1379. dr[2] = item.Percentage;
  1380. dr[3] = molarValue;
  1381. dt.Rows.Add(dr);
  1382. }
  1383. DataGridView dgv = new DataGridView();
  1384. dgv.DataSource = dt.DefaultView;
  1385. List<DataTable> list_ElementData = new List<DataTable>();
  1386. list_ElementData.Add(dt);
  1387. //将数据插入Excel中
  1388. return InsertDataToExcelTable(list_ElementData, startupPath, listFilePath);
  1389. }
  1390. public bool InsertDataToExcelTable(List<System.Data.DataTable> a_list_ElementData, string a_filePath, List<string> a_ImgFilePath)
  1391. {
  1392. var m_xe = new ExcelEdit();
  1393. m_xe.Create();
  1394. Microsoft.Office.Interop.Excel.Worksheet ws = m_xe.GetSheet("Sheet1");
  1395. m_xe.m_ws = ws;
  1396. string str_ExcelFilePath = a_filePath + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx";
  1397. m_xe.m_ws.Shapes.AddPicture(a_ImgFilePath[0], Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, 0, 0, 400, 300);
  1398. m_xe.m_ws.Shapes.AddPicture(a_ImgFilePath[1], Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, 0, 320, 400, 100);
  1399. if (str_ExcelFilePath.IndexOf(":") < 0)
  1400. {
  1401. return false;
  1402. }
  1403. if (m_xe.m_app == null)
  1404. {
  1405. return false;
  1406. }
  1407. //数据列表 行数
  1408. int dataRow = 30;
  1409. //写入标题
  1410. foreach (var dgv in a_list_ElementData)
  1411. {
  1412. for (int i = 0; i < dgv.Columns.Count; i++)
  1413. {
  1414. m_xe.m_ws.Cells[dataRow + 1, i + 1] = dgv.Columns[i].ColumnName;
  1415. }
  1416. //写入数值
  1417. for (int r = 0; r < dgv.Rows.Count; r++)
  1418. {
  1419. for (int i = 0; i < dgv.Columns.Count; i++)
  1420. {
  1421. m_xe.m_ws.Cells[dataRow + r + 2, i + 1] = dgv.Rows[r].ItemArray[i];
  1422. }
  1423. System.Windows.Forms.Application.DoEvents();
  1424. }
  1425. }
  1426. //列宽自适应
  1427. m_xe.m_ws.Columns.EntireColumn.AutoFit();
  1428. if (str_ExcelFilePath != "")
  1429. {
  1430. try
  1431. {
  1432. m_xe.m_wb.Saved = true;
  1433. m_xe.m_wb.SaveCopyAs(str_ExcelFilePath);
  1434. }
  1435. catch (Exception ex)
  1436. {
  1437. log.Error(ex.ToString());
  1438. }
  1439. }
  1440. //关闭excel
  1441. m_xe.Close();
  1442. //强行销毁
  1443. GC.Collect();
  1444. //干掉进程里的EXCEL
  1445. foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcesses())
  1446. {
  1447. if (p.ProcessName == "EXCEL")
  1448. {
  1449. p.Kill();
  1450. }
  1451. }
  1452. //删除图片文件
  1453. foreach (string imgPath in a_ImgFilePath)
  1454. {
  1455. if (File.Exists(imgPath))
  1456. {
  1457. //如果存在则删除
  1458. File.Delete(imgPath);
  1459. }
  1460. }
  1461. System.Diagnostics.Process.Start(str_ExcelFilePath);
  1462. return true;
  1463. }
  1464. public void HideXRayTable()
  1465. {
  1466. panelXray.Visible = false;
  1467. //清空元素标记对象
  1468. if (m_ElementPointGDIObjects != null)
  1469. {
  1470. if (m_ElementPointGDIObjects.Count > 0)
  1471. {
  1472. m_ElementPointGDIObjects.Clear();
  1473. }
  1474. }
  1475. }
  1476. //在picturebox的鼠标按下事件里,记录三个变量.
  1477. int xPos;
  1478. int yPos;
  1479. bool MoveFlag = false;
  1480. private void pbBSEImage_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
  1481. {
  1482. if (e.Button == MouseButtons.Left)
  1483. {
  1484. //在线扫描未选中的情况下 设置移动标识与获取当前鼠标位置
  1485. if (!(MenuItemLineScan.Checked))
  1486. {
  1487. MoveFlag = true;//已经按下.
  1488. xPos = e.X;//当前x坐标.
  1489. yPos = e.Y;//当前y坐标.
  1490. }
  1491. else
  1492. {
  1493. MoveFlag = false;
  1494. }
  1495. }
  1496. }
  1497. //在picturebox的鼠标按下事件里.
  1498. private void pbBSEImage_MouseUp(object sender, MouseEventArgs e)
  1499. {
  1500. MoveFlag = false;
  1501. }
  1502. //在picturebox鼠标移动
  1503. private void pbBSEImage_MouseMove(object sender, MouseEventArgs e)
  1504. {
  1505. if (MoveFlag)
  1506. {
  1507. picBox.Left = Convert.ToInt32(e.X - xPos);//设置x坐标.
  1508. picBox.Top = Convert.ToInt32(e.Y - yPos);//设置y坐标.
  1509. }
  1510. }
  1511. //在picturebox鼠标缩放
  1512. private void pbBSEImage_MouseWheel(object sender, MouseEventArgs e)
  1513. {
  1514. if (m_imagetype != ImageType.BSEImage)
  1515. {
  1516. return;
  1517. }
  1518. //鼠标滚动缩放 BSE图
  1519. if (e.Delta > 0)
  1520. {
  1521. if (m_CurrentMultiple < m_MaxMultipleRange)
  1522. {
  1523. m_CurrentMultiple += Convert.ToSingle(m_Multiple.ToString("f2"));
  1524. picBox.Width += Convert.ToInt32(m_iWidth * m_Multiple);
  1525. picBox.Height += Convert.ToInt32(m_iHeight * m_Multiple);
  1526. WheelElementPointGDIObjects(e.Location, m_CurrentMultiple);
  1527. }
  1528. }
  1529. else
  1530. {
  1531. m_CurrentMultiple -= Convert.ToSingle(m_Multiple.ToString("f2"));
  1532. if (m_CurrentMultiple > 0)
  1533. {
  1534. picBox.Width -= Convert.ToInt32(m_iWidth * m_Multiple);
  1535. picBox.Height -= Convert.ToInt32(m_iHeight * m_Multiple);
  1536. }
  1537. else
  1538. {
  1539. m_CurrentMultiple = 0;
  1540. picBox.Height = this.RestoreBounds.Height;
  1541. picBox.Width = this.RestoreBounds.Height * 4 / 3;
  1542. picBox.Left = 0;
  1543. picBox.Top = 0;
  1544. Rectangle rectangle = GetPictureBoxZoomSize(picBox);
  1545. Point sizeChangePoint = rectangle.Location;
  1546. //修改窗体宽度后,设置单点采集的位置
  1547. if (m_ElementPointGDIObjects != null)
  1548. {
  1549. if (m_ElementPointGDIObjects.Count > 0)
  1550. {
  1551. if (m_GetBSEImageInitPoint != sizeChangePoint)
  1552. {
  1553. int sizeChangeX = sizeChangePoint.X - m_GetBSEImageInitPoint.X;
  1554. int sizeChangeY = sizeChangePoint.Y - m_GetBSEImageInitPoint.Y;
  1555. RectangleF sizeChangeRectF = m_ElementPointGDIObjects[0].GetZoomedRegionF();
  1556. sizeChangeRectF.X = m_ElementPointGDIObjects[0].GetZoomedRegionF().X + sizeChangeX;
  1557. m_ElementPointGDIObjects[0].SetInitRegionF(sizeChangeRectF);
  1558. m_GetBSEImageInitPoint = sizeChangePoint;
  1559. }
  1560. }
  1561. }
  1562. }
  1563. WheelElementPointGDIObjects(e.Location, m_CurrentMultiple);
  1564. }
  1565. }
  1566. /// <summary>
  1567. /// 缩放时改变 单点标识位置
  1568. /// </summary>
  1569. /// <param name="m_CurrentMultiple"></param>
  1570. public void WheelElementPointGDIObjects(Point refPoint, float CurrentMultiple)
  1571. {
  1572. if (m_ElementPointGDIObjects.Count > 0)
  1573. {
  1574. foreach (CRectangleGDIObject item in m_ElementPointGDIObjects)
  1575. {
  1576. item.Zoom(refPoint, CurrentMultiple);
  1577. }
  1578. }
  1579. }
  1580. private void OTSMeasureStatusWindow_MouseClick(object sender, MouseEventArgs e)
  1581. {
  1582. if (e.Button == MouseButtons.Right && e.Clicks == 1)
  1583. {
  1584. contextMenuStrip1.Show(PointToScreen(e.Location));
  1585. SetContentMenu();
  1586. }
  1587. }
  1588. private void ViewStripMenuItem_Click(object sender, EventArgs e)
  1589. {
  1590. if (m_iWidth == 0 || m_iHeight == 0)
  1591. {
  1592. string str = m_MeasureAppForm.m_ProjParam.GetBSEImageResolutionStr();// 举例:1024X768
  1593. string[] sArray = str.Split('X');
  1594. if (sArray[0] != "" && sArray[1] != "")
  1595. {
  1596. m_iWidth = Convert.ToInt32(sArray[0]);
  1597. m_iHeight = Convert.ToInt32(sArray[1]);
  1598. }
  1599. }
  1600. ToolWindow toolWindow = new ToolWindow(m_MeasureAppForm, this);
  1601. int grayStart = 0;
  1602. int grayEnd = 0;
  1603. if (originalBseData != null)
  1604. {
  1605. Bitmap bitmap = CImageHandler.ToGrayBitmap(originalBseData, m_iWidth, m_iHeight);
  1606. toolWindow.BseImg = bitmap;
  1607. toolWindow.BBseData = originalBseData;
  1608. //获取去背景灰度值
  1609. grayStart = m_MeasureAppForm.m_ProjParam.GetWorkSample().GetMsrParams().GetImageProcessParam().GetBGGray().GetStart();
  1610. grayEnd = m_MeasureAppForm.m_ProjParam.GetWorkSample().GetMsrParams().GetImageProcessParam().GetBGGray().GetEnd();
  1611. //设置可视化中的属性
  1612. toolWindow.BseGrayMinValue = grayStart;
  1613. toolWindow.BseGrayMaxValue = grayEnd;
  1614. }
  1615. DialogResult dialogResult = toolWindow.ShowDialog();
  1616. if (dialogResult == DialogResult.Yes)
  1617. {
  1618. //获取去背景参数
  1619. grayStart = toolWindow.BseGrayMinValue;
  1620. grayEnd = toolWindow.BseGrayMaxValue;
  1621. //设置去背景参数
  1622. COTSImageProcParam cOTSImgProc;
  1623. cOTSImgProc = m_MeasureAppForm.m_ProjParam.GetResultData().GetWorkingSample().GetMsrParams().GetImageProcessParam();
  1624. CIntRange cIntRange = new CIntRange();
  1625. cIntRange.SetStart(grayStart);
  1626. cIntRange.SetEnd(grayEnd);
  1627. cOTSImgProc.SetBGGray(cIntRange);
  1628. m_MeasureAppForm.m_ProjParam.GetResultData().GetWorkingSample().GetMsrParams().SetImageProcessParam(cOTSImgProc);
  1629. //更新属性窗口
  1630. m_MeasureAppForm.UpdatePropertyVal();
  1631. //确认后进行去背景
  1632. var m_systype = m_MeasureAppForm.m_ProjParam.GetResultData().SystemTypeId;
  1633. if (m_systype == otsdataconst.OTS_SysType_ID.CleannessA)
  1634. {
  1635. ShowColoredRemoveBGImage();
  1636. }
  1637. else
  1638. {
  1639. ShowRemoveBGImage();
  1640. }
  1641. }
  1642. }
  1643. private void toolStripMenuItem1_Click(object sender, EventArgs e)
  1644. {
  1645. if (m_iWidth == 0 || m_iHeight == 0)
  1646. {
  1647. string str = m_MeasureAppForm.m_ProjParam.GetBSEImageResolutionStr();// 举例:1024X768
  1648. string[] sArray = str.Split('X');
  1649. if (sArray[0] != "" && sArray[1] != "")
  1650. {
  1651. m_iWidth = Convert.ToInt32(sArray[0]);
  1652. m_iHeight = Convert.ToInt32(sArray[1]);
  1653. }
  1654. }
  1655. SpecialParticleForm specialParticleForm = new SpecialParticleForm(CSpecialGrayRangeParam.GetParamFileFullName(), m_MeasureAppForm, originalBseData, m_iWidth, m_iHeight, this);
  1656. DialogResult dialogResult = specialParticleForm.ShowDialog();
  1657. }
  1658. private void toolStripMenuItem2_Click(object sender, EventArgs e)
  1659. {
  1660. //设置右键菜单中的项 是否可编辑
  1661. SetContextMenuEnabled(true);
  1662. m_imagetype = ImageType.RemoveBGImage;
  1663. ShowColoredRemoveBGImage();
  1664. m_CurrentMultiple = 0;
  1665. panelXray.Visible = false;
  1666. }
  1667. private void timer1_Tick(object sender, EventArgs e)
  1668. {
  1669. if (!backgroundWorker1.IsBusy)
  1670. {
  1671. backgroundWorker1.RunWorkerAsync();
  1672. }
  1673. }
  1674. private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
  1675. {
  1676. //更新当前的图
  1677. log.Info("begin to acquire image");
  1678. bool rst = AcquireBSEImage();
  1679. if (m_imagetype == ImageType.GrayLevelLineScan)
  1680. {
  1681. log.Info("begin to show image");
  1682. UpdateImageAndLineScanChart();
  1683. }
  1684. }
  1685. }
  1686. }