OTSMeasureStatusWindow.cs 81 KB

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