OTSMeasureStatusWindow.cs 90 KB

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