OTSMeasureStatusWindow.cs 81 KB

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