OTSMeasureStatusWindow.cs 82 KB

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