OTSMeasureStatusWindow.cs 81 KB

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