OTSMeasureStatusWindow.cs 71 KB

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