OTSMeasureStatusWindow.cs 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012
  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. DwellTimeLevel nDwellTime=DwellTimeLevel.Low;
  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 = DwellTimeLevel.Low;
  322. break;
  323. case 1:
  324. nDwellTime = DwellTimeLevel.Medium;
  325. break;
  326. case 2:
  327. nDwellTime =DwellTimeLevel.High;
  328. break;
  329. }
  330. }
  331. catch (Exception)
  332. {
  333. nDwellTime = DwellTimeLevel.Low;
  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, DwellTimeLevel 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. var ifautoid = m_MeasureAppForm.m_ProjRstData.GetWorkingSample().GetMsrParams().GetXRayParam().IfAutoId;
  1199. var knownelements = m_MeasureAppForm.m_ProjRstData.GetWorkingSample().GetMsrParams().GetXRayParam().AnalysisElements;
  1200. string deviceType = FileHelper.GetXMLInformations("EDSName");
  1201. var semtype = FileHelper.GetXMLInformations("SemControllerName");
  1202. IEDSController m_EDSHardwareMgr = EDSController.GetEDSController(semtype,deviceType, m_iWidth, m_iHeight, expC,ifautoid,knownelements);
  1203. //1.连接电镜
  1204. if (m_EDSHardwareMgr.Connect())
  1205. {
  1206. COTSMsrPrjResultData cProjMgr = m_MeasureAppForm.m_ProjParam.GetResultData();
  1207. //获取工作样品对象
  1208. COTSSample sampleClr = cProjMgr.GetWorkingSample();
  1209. //清空之前记录的标识
  1210. if (m_ElementPointGDIObjects != null)
  1211. {
  1212. if (m_ElementPointGDIObjects.Count > 0)
  1213. {
  1214. //清空
  1215. m_ElementPointGDIObjects.Clear();
  1216. }
  1217. }
  1218. //2.获取鼠标在图像的位置
  1219. dMouseImgX = m_MouseMoveImageX;
  1220. dMouseImgY = m_MouseMoveImageY;
  1221. //3.根据所要扫描的位置进行元素分析
  1222. uint a_Milliseconds = 0;
  1223. //采集时间
  1224. a_Milliseconds = Convert.ToUInt32(sampleClr.GetMsrParams().GetXRayParam().GetMidAnalyAQTime());
  1225. //元素数量
  1226. ValueType a_nElementNum = 0;
  1227. //元素名称
  1228. string a_strElementName = "";
  1229. //元素Xray数据
  1230. uint[] a_ElementXrayData = new uint[2000];
  1231. if (GetXRayAndElements(a_Milliseconds, (int)dMouseImgX, (int)dMouseImgY, ref a_ElementXrayData, ref a_nElementNum, ref a_strElementName))
  1232. {
  1233. log.Trace("--获取单点扫描数据:元素数量:'" + a_nElementNum + "' ,元素名称:'" + a_strElementName + "'--");
  1234. //4.在BSE上绘制扫描标记
  1235. //4-1 获取鼠标在BSE图上的位置
  1236. Point p_mouseCurrentTempPoint = m_mouseCurrentPoint;
  1237. //4-2 根据位置绘制标记
  1238. Point ImgPoint = new Point((int)dMouseImgX, (int)dMouseImgY);
  1239. Rectangle rect = new Rectangle(p_mouseCurrentTempPoint, new Size(1, 1));
  1240. CRectangleGDIObject createRect = new CRectangleGDIObject(rect, ImgPoint, m_CurrentMultiple, CreateRectangleType.DrawBSEElementSignPoint);
  1241. m_ElementPointGDIObjects.Add(createRect);
  1242. //5.获取成功后弹出对话框
  1243. //计数率
  1244. double electronicCount = 0;
  1245. uint[] u_ElementXrayData = new uint[2000];
  1246. for (int i = 0; i < a_ElementXrayData.Length; i++)
  1247. {
  1248. u_ElementXrayData[i] = (uint)a_ElementXrayData[i];
  1249. //累加计数率
  1250. electronicCount += a_ElementXrayData[i];
  1251. }
  1252. //显示Xray控件
  1253. panelXray.Visible = true;
  1254. //获取数据后,需要对xraytable设置
  1255. string[] strGroup = a_strElementName.Split('\n');
  1256. //get CElementChemistryClr list
  1257. List<ShowElementInfo> list_showelementinfo = new List<ShowElementInfo>();
  1258. for (int i = 0; i < strGroup.Length; i++)
  1259. {
  1260. if (!strGroup[i].Equals(""))
  1261. {
  1262. ShowElementInfo ls_sei = new ShowElementInfo();
  1263. ls_sei.ElementName = strGroup[i].Split(':')[0];
  1264. ls_sei.Percentage = Convert.ToDouble(strGroup[i].Split(':')[1]);
  1265. ls_sei.dKF = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).K_Peak);
  1266. double de_sx2 = 0;
  1267. if (CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "" || CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "-")
  1268. {
  1269. de_sx2 = 0;
  1270. }
  1271. else
  1272. {
  1273. de_sx2 = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak);
  1274. }
  1275. ls_sei.dLF = de_sx2;
  1276. list_showelementinfo.Add(ls_sei);
  1277. }
  1278. }
  1279. //设置分析Xray数据
  1280. control_XRayTable1.SetXRayShowLineValue(new uint[2000], u_ElementXrayData, list_showelementinfo);
  1281. //需要显示计数率
  1282. string strElectronicCount = string.Empty;
  1283. if (electronicCount > 1000)
  1284. {
  1285. strElectronicCount = (Convert.ToDouble(electronicCount) / 1000).ToString("f2") + "kcps";
  1286. }
  1287. control_XRayTable1.List_ShowElementInfo = list_showelementinfo;
  1288. }
  1289. ExportScanInfoMenuItem.Enabled = true;
  1290. this.Invalidate();
  1291. }
  1292. }
  1293. public bool GetXRayAndElements(uint a_nXRayAQTime, int dMouseImgX, int dMouseImgY, ref uint[] a_XrayData, ref ValueType a_nElementNum, ref string a_strResult)
  1294. {
  1295. var expC = m_MeasureAppForm.m_ProjRstData.GetWorkingSample().GetMsrParams().GetXRayParam().GetAnalyExpCount();
  1296. var ifautoid = m_MeasureAppForm.m_ProjRstData.GetWorkingSample().GetMsrParams().GetXRayParam().IfAutoId;
  1297. var knownelements = m_MeasureAppForm.m_ProjRstData.GetWorkingSample().GetMsrParams().GetXRayParam().AnalysisElements;
  1298. string deviceType = FileHelper.GetXMLInformations("EDSName");
  1299. var semtype = FileHelper.GetXMLInformations("SemControllerName");
  1300. var eds = EDSController.GetEDSController(semtype, deviceType,m_iWidth, m_iHeight, expC,ifautoid,knownelements);
  1301. var mode = m_MeasureAppForm.m_ProjRstData.GetWorkingSample().GetMsrParams().GetXRayParam().GetScanMode();
  1302. var part = new COTSParticleClr();
  1303. part.SetXRayPos(new Point(dMouseImgX, dMouseImgY));
  1304. var xray = part.GetXray();
  1305. xray.SetIndex(0);
  1306. part.SetXray(xray);
  1307. var parts = new List<COTSParticleClr>();
  1308. parts.Add(part);
  1309. if (mode == otsdataconst.OTS_X_RAY_SCAN_MODE.PointMode)
  1310. {
  1311. eds.GetXRayByParts(parts, a_nXRayAQTime, true);
  1312. }
  1313. else
  1314. {
  1315. eds.GetXRayByFeatures(parts, a_nXRayAQTime, true);
  1316. }
  1317. a_XrayData = parts[0].GetXray().GetXrayData();
  1318. a_strResult = parts[0].GetXray().GetQuantifiedElementsStr();
  1319. return true;
  1320. }
  1321. public void DelElementPointGDIObjects()
  1322. {
  1323. if (m_ElementPointGDIObjects != null)
  1324. {
  1325. if (m_ElementPointGDIObjects.Count > 0)
  1326. {
  1327. //删除点标记
  1328. m_ElementPointGDIObjects.Clear();
  1329. this.Invalidate();
  1330. }
  1331. }
  1332. }
  1333. private void ExportScanInfoMenuItem_Click(object sender, EventArgs e)
  1334. {
  1335. //导出图片到报告中
  1336. ExportReport();
  1337. }
  1338. /// <summary>
  1339. /// 导出Image到报告
  1340. /// </summary>
  1341. private bool ExportReport()
  1342. {
  1343. string startupPath = System.Windows.Forms.Application.StartupPath + "\\TempReport\\";
  1344. if (!Directory.Exists(startupPath))
  1345. {
  1346. Directory.CreateDirectory(startupPath);
  1347. }
  1348. //保存Xray图片
  1349. string ImgFilePath = startupPath + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpg";
  1350. Bitmap bseBM = new Bitmap(this.picBox.Width, this.picBox.Height);
  1351. this.picBox.DrawToBitmap(bseBM, new Rectangle(0, 0, this.picBox.Width, this.picBox.Height));
  1352. //保存图片
  1353. bseBM.Save(ImgFilePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  1354. //释放资源
  1355. bseBM.Dispose();
  1356. //保存Xray图片
  1357. string ImgXrayFilePath = startupPath + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpg";
  1358. int xrayWidth = control_XRayTable1.Width;
  1359. int xrayHeight = control_XRayTable1.Height;
  1360. Bitmap xrayBM = new Bitmap(xrayWidth, xrayHeight);
  1361. this.control_XRayTable1.DrawToBitmap(xrayBM, new Rectangle(0, 0, xrayWidth, xrayHeight));
  1362. //保存图片
  1363. xrayBM.Save(ImgXrayFilePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  1364. //释放资源
  1365. xrayBM.Dispose();
  1366. List<string> listFilePath = new List<string>();
  1367. listFilePath.Add(ImgFilePath);
  1368. listFilePath.Add(ImgXrayFilePath);
  1369. List<ShowElementInfo> list_ElementInfo = control_XRayTable1.List_ShowElementInfo;
  1370. //1.编辑信息
  1371. DataTable dt = new DataTable();
  1372. dt.Columns.Add("元素名称");
  1373. dt.Columns.Add("原子数");
  1374. dt.Columns.Add("质量百分比");
  1375. dt.Columns.Add("摩尔比");
  1376. foreach (var item in list_ElementInfo)
  1377. {
  1378. //获取摩尔比与原子数
  1379. CElementChemistry cElementChemistry = new CElementChemistry();
  1380. cElementChemistry.SetName(item.ElementName);
  1381. cElementChemistry.SetPercentage(item.Percentage);
  1382. double molarValue = Math.Round(cElementChemistry.GetMolarPercentage(), 2);
  1383. int atomNum = (int)CElement.GetAtomicNum(item.ElementName);
  1384. DataRow dr = dt.NewRow();
  1385. dr[0] = item.ElementName;
  1386. dr[1] = atomNum;
  1387. dr[2] = item.Percentage;
  1388. dr[3] = molarValue;
  1389. dt.Rows.Add(dr);
  1390. }
  1391. DataGridView dgv = new DataGridView();
  1392. dgv.DataSource = dt.DefaultView;
  1393. List<DataTable> list_ElementData = new List<DataTable>();
  1394. list_ElementData.Add(dt);
  1395. //将数据插入Excel中
  1396. return InsertDataToExcelTable(list_ElementData, startupPath, listFilePath);
  1397. }
  1398. public bool InsertDataToExcelTable(List<System.Data.DataTable> a_list_ElementData, string a_filePath, List<string> a_ImgFilePath)
  1399. {
  1400. var m_xe = new ExcelEdit();
  1401. m_xe.Create();
  1402. Microsoft.Office.Interop.Excel.Worksheet ws = m_xe.GetSheet("Sheet1");
  1403. m_xe.m_ws = ws;
  1404. string str_ExcelFilePath = a_filePath + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx";
  1405. m_xe.m_ws.Shapes.AddPicture(a_ImgFilePath[0], Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, 0, 0, 400, 300);
  1406. m_xe.m_ws.Shapes.AddPicture(a_ImgFilePath[1], Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, 0, 320, 400, 100);
  1407. if (str_ExcelFilePath.IndexOf(":") < 0)
  1408. {
  1409. return false;
  1410. }
  1411. if (m_xe.m_app == null)
  1412. {
  1413. return false;
  1414. }
  1415. //数据列表 行数
  1416. int dataRow = 30;
  1417. //写入标题
  1418. foreach (var dgv in a_list_ElementData)
  1419. {
  1420. for (int i = 0; i < dgv.Columns.Count; i++)
  1421. {
  1422. m_xe.m_ws.Cells[dataRow + 1, i + 1] = dgv.Columns[i].ColumnName;
  1423. }
  1424. //写入数值
  1425. for (int r = 0; r < dgv.Rows.Count; r++)
  1426. {
  1427. for (int i = 0; i < dgv.Columns.Count; i++)
  1428. {
  1429. m_xe.m_ws.Cells[dataRow + r + 2, i + 1] = dgv.Rows[r].ItemArray[i];
  1430. }
  1431. System.Windows.Forms.Application.DoEvents();
  1432. }
  1433. }
  1434. //列宽自适应
  1435. m_xe.m_ws.Columns.EntireColumn.AutoFit();
  1436. if (str_ExcelFilePath != "")
  1437. {
  1438. try
  1439. {
  1440. m_xe.m_wb.Saved = true;
  1441. m_xe.m_wb.SaveCopyAs(str_ExcelFilePath);
  1442. }
  1443. catch (Exception ex)
  1444. {
  1445. log.Error(ex.ToString());
  1446. }
  1447. }
  1448. //关闭excel
  1449. m_xe.Close();
  1450. //强行销毁
  1451. GC.Collect();
  1452. //干掉进程里的EXCEL
  1453. foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcesses())
  1454. {
  1455. if (p.ProcessName == "EXCEL")
  1456. {
  1457. p.Kill();
  1458. }
  1459. }
  1460. //删除图片文件
  1461. foreach (string imgPath in a_ImgFilePath)
  1462. {
  1463. if (File.Exists(imgPath))
  1464. {
  1465. //如果存在则删除
  1466. File.Delete(imgPath);
  1467. }
  1468. }
  1469. System.Diagnostics.Process.Start(str_ExcelFilePath);
  1470. return true;
  1471. }
  1472. public void HideXRayTable()
  1473. {
  1474. panelXray.Visible = false;
  1475. //清空元素标记对象
  1476. if (m_ElementPointGDIObjects != null)
  1477. {
  1478. if (m_ElementPointGDIObjects.Count > 0)
  1479. {
  1480. m_ElementPointGDIObjects.Clear();
  1481. }
  1482. }
  1483. }
  1484. //在picturebox的鼠标按下事件里,记录三个变量.
  1485. int xPos;
  1486. int yPos;
  1487. bool MoveFlag = false;
  1488. private void pbBSEImage_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
  1489. {
  1490. if (e.Button == MouseButtons.Left)
  1491. {
  1492. //在线扫描未选中的情况下 设置移动标识与获取当前鼠标位置
  1493. if (!(MenuItemLineScan.Checked))
  1494. {
  1495. MoveFlag = true;//已经按下.
  1496. xPos = e.X;//当前x坐标.
  1497. yPos = e.Y;//当前y坐标.
  1498. }
  1499. else
  1500. {
  1501. MoveFlag = false;
  1502. }
  1503. }
  1504. }
  1505. //在picturebox的鼠标按下事件里.
  1506. private void pbBSEImage_MouseUp(object sender, MouseEventArgs e)
  1507. {
  1508. MoveFlag = false;
  1509. }
  1510. //在picturebox鼠标移动
  1511. private void pbBSEImage_MouseMove(object sender, MouseEventArgs e)
  1512. {
  1513. if (MoveFlag)
  1514. {
  1515. picBox.Left = Convert.ToInt32(e.X - xPos);//设置x坐标.
  1516. picBox.Top = Convert.ToInt32(e.Y - yPos);//设置y坐标.
  1517. }
  1518. }
  1519. //在picturebox鼠标缩放
  1520. private void pbBSEImage_MouseWheel(object sender, MouseEventArgs e)
  1521. {
  1522. if (m_imagetype != ImageType.BSEImage)
  1523. {
  1524. return;
  1525. }
  1526. //鼠标滚动缩放 BSE图
  1527. if (e.Delta > 0)
  1528. {
  1529. if (m_CurrentMultiple < m_MaxMultipleRange)
  1530. {
  1531. m_CurrentMultiple += Convert.ToSingle(m_Multiple.ToString("f2"));
  1532. picBox.Width += Convert.ToInt32(m_iWidth * m_Multiple);
  1533. picBox.Height += Convert.ToInt32(m_iHeight * m_Multiple);
  1534. WheelElementPointGDIObjects(e.Location, m_CurrentMultiple);
  1535. }
  1536. }
  1537. else
  1538. {
  1539. m_CurrentMultiple -= Convert.ToSingle(m_Multiple.ToString("f2"));
  1540. if (m_CurrentMultiple > 0)
  1541. {
  1542. picBox.Width -= Convert.ToInt32(m_iWidth * m_Multiple);
  1543. picBox.Height -= Convert.ToInt32(m_iHeight * m_Multiple);
  1544. }
  1545. else
  1546. {
  1547. m_CurrentMultiple = 0;
  1548. picBox.Height = this.RestoreBounds.Height;
  1549. picBox.Width = this.RestoreBounds.Height * 4 / 3;
  1550. picBox.Left = 0;
  1551. picBox.Top = 0;
  1552. Rectangle rectangle = GetPictureBoxZoomSize(picBox);
  1553. Point sizeChangePoint = rectangle.Location;
  1554. //修改窗体宽度后,设置单点采集的位置
  1555. if (m_ElementPointGDIObjects != null)
  1556. {
  1557. if (m_ElementPointGDIObjects.Count > 0)
  1558. {
  1559. if (m_GetBSEImageInitPoint != sizeChangePoint)
  1560. {
  1561. int sizeChangeX = sizeChangePoint.X - m_GetBSEImageInitPoint.X;
  1562. int sizeChangeY = sizeChangePoint.Y - m_GetBSEImageInitPoint.Y;
  1563. RectangleF sizeChangeRectF = m_ElementPointGDIObjects[0].GetZoomedRegionF();
  1564. sizeChangeRectF.X = m_ElementPointGDIObjects[0].GetZoomedRegionF().X + sizeChangeX;
  1565. m_ElementPointGDIObjects[0].SetInitRegionF(sizeChangeRectF);
  1566. m_GetBSEImageInitPoint = sizeChangePoint;
  1567. }
  1568. }
  1569. }
  1570. }
  1571. WheelElementPointGDIObjects(e.Location, m_CurrentMultiple);
  1572. }
  1573. }
  1574. /// <summary>
  1575. /// 缩放时改变 单点标识位置
  1576. /// </summary>
  1577. /// <param name="m_CurrentMultiple"></param>
  1578. public void WheelElementPointGDIObjects(Point refPoint, float CurrentMultiple)
  1579. {
  1580. if (m_ElementPointGDIObjects.Count > 0)
  1581. {
  1582. foreach (CRectangleGDIObject item in m_ElementPointGDIObjects)
  1583. {
  1584. item.Zoom(refPoint, CurrentMultiple);
  1585. }
  1586. }
  1587. }
  1588. private void OTSMeasureStatusWindow_MouseClick(object sender, MouseEventArgs e)
  1589. {
  1590. if (e.Button == MouseButtons.Right && e.Clicks == 1)
  1591. {
  1592. contextMenuStrip1.Show(PointToScreen(e.Location));
  1593. SetContentMenu();
  1594. }
  1595. }
  1596. private void ViewStripMenuItem_Click(object sender, EventArgs e)
  1597. {
  1598. if (m_iWidth == 0 || m_iHeight == 0)
  1599. {
  1600. string str = m_MeasureAppForm.m_ProjParam.GetBSEImageResolutionStr();// 举例:1024X768
  1601. string[] sArray = str.Split('X');
  1602. if (sArray[0] != "" && sArray[1] != "")
  1603. {
  1604. m_iWidth = Convert.ToInt32(sArray[0]);
  1605. m_iHeight = Convert.ToInt32(sArray[1]);
  1606. }
  1607. }
  1608. ToolWindow toolWindow = new ToolWindow(m_MeasureAppForm, this);
  1609. int grayStart = 0;
  1610. int grayEnd = 0;
  1611. if (originalBseData != null)
  1612. {
  1613. Bitmap bitmap = CImageHandler.ToGrayBitmap(originalBseData, m_iWidth, m_iHeight);
  1614. toolWindow.BseImg = bitmap;
  1615. toolWindow.BBseData = originalBseData;
  1616. //获取去背景灰度值
  1617. grayStart = m_MeasureAppForm.m_ProjParam.GetWorkSample().GetMsrParams().GetImageProcessParam().GetBGGray().GetStart();
  1618. grayEnd = m_MeasureAppForm.m_ProjParam.GetWorkSample().GetMsrParams().GetImageProcessParam().GetBGGray().GetEnd();
  1619. //设置可视化中的属性
  1620. toolWindow.BseGrayMinValue = grayStart;
  1621. toolWindow.BseGrayMaxValue = grayEnd;
  1622. }
  1623. DialogResult dialogResult = toolWindow.ShowDialog();
  1624. if (dialogResult == DialogResult.Yes)
  1625. {
  1626. //获取去背景参数
  1627. grayStart = toolWindow.BseGrayMinValue;
  1628. grayEnd = toolWindow.BseGrayMaxValue;
  1629. //设置去背景参数
  1630. COTSImageProcParam cOTSImgProc;
  1631. cOTSImgProc = m_MeasureAppForm.m_ProjParam.GetResultData().GetWorkingSample().GetMsrParams().GetImageProcessParam();
  1632. CIntRange cIntRange = new CIntRange();
  1633. cIntRange.SetStart(grayStart);
  1634. cIntRange.SetEnd(grayEnd);
  1635. cOTSImgProc.SetBGGray(cIntRange);
  1636. m_MeasureAppForm.m_ProjParam.GetResultData().GetWorkingSample().GetMsrParams().SetImageProcessParam(cOTSImgProc);
  1637. //更新属性窗口
  1638. m_MeasureAppForm.UpdatePropertyVal();
  1639. //确认后进行去背景
  1640. var m_systype = m_MeasureAppForm.m_ProjParam.GetResultData().SystemTypeId;
  1641. if (m_systype != otsdataconst.OTS_SysType_ID.IncA)
  1642. {
  1643. ShowColoredRemoveBGImage();
  1644. }
  1645. else
  1646. {
  1647. ShowRemoveBGImage();
  1648. }
  1649. }
  1650. }
  1651. private void toolStripMenuItem1_Click(object sender, EventArgs e)
  1652. {
  1653. if (m_iWidth == 0 || m_iHeight == 0)
  1654. {
  1655. string str = m_MeasureAppForm.m_ProjParam.GetBSEImageResolutionStr();// 举例:1024X768
  1656. string[] sArray = str.Split('X');
  1657. if (sArray[0] != "" && sArray[1] != "")
  1658. {
  1659. m_iWidth = Convert.ToInt32(sArray[0]);
  1660. m_iHeight = Convert.ToInt32(sArray[1]);
  1661. }
  1662. }
  1663. SpecialParticleForm specialParticleForm = new SpecialParticleForm(CSpecialGrayRangeParam.GetParamFileFullName(), m_MeasureAppForm, originalBseData, m_iWidth, m_iHeight, this);
  1664. DialogResult dialogResult = specialParticleForm.ShowDialog();
  1665. }
  1666. private void toolStripMenuItem2_Click(object sender, EventArgs e)
  1667. {
  1668. //设置右键菜单中的项 是否可编辑
  1669. SetContextMenuEnabled(true);
  1670. m_imagetype = ImageType.RemoveBGImage;
  1671. ShowColoredRemoveBGImage();
  1672. m_CurrentMultiple = 0;
  1673. panelXray.Visible = false;
  1674. }
  1675. private void timer1_Tick(object sender, EventArgs e)
  1676. {
  1677. if (!backgroundWorker1.IsBusy)
  1678. {
  1679. backgroundWorker1.RunWorkerAsync();
  1680. }
  1681. }
  1682. private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
  1683. {
  1684. //更新当前的图
  1685. log.Info("begin to acquire image");
  1686. bool rst = AcquireBSEImage();
  1687. if (m_imagetype == ImageType.GrayLevelLineScan)
  1688. {
  1689. log.Info("begin to show image");
  1690. UpdateImageAndLineScanChart();
  1691. }
  1692. }
  1693. }
  1694. }