OTSMeasureStatusWindow.cs 72 KB

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