using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using OTS.WinFormsUI.Docking; using System.IO; /*处理ImageDispos*/ using OTSCommon; /*处理PropertyInfo*/ using System.Reflection; using OTSCLRINTERFACE; using System.Data; using System.Collections; using System.Drawing.Imaging; using OTSIncAGraph.Controls; using OTSModelSharp; using OTSDataType; using OTSModelSharp.ServiceInterface; using OTSModelSharp.ServiceCenter; using OTSMeasureApp._0_OTSModel.Measure.ParamData; namespace OTSMeasureApp { public partial class OTSMeasureStatusWindow : DockContent { #region 全部变量 public OTSIncAMeasureAppForm m_MeasureAppForm; /* 接收图像数据 */ public byte[] Imagedata = new byte[m_iWidth]; static int m_iWidth = 0; static int m_iHeight = 0; OTSImageData m_ImageData = null; //获取BSE图时最初的位置 Point m_GetBSEImageInitPoint = new Point(); // 调试图图片数据 public byte[] bBseData; //去背景图 public byte[] cBseData; //灰度图数据 public double[] dGrayLevelData; //灰度峰值 public double dGrayLevelMax; //去背景灰度图数据 public double[] dGrayAbandonLevelData; //去背景灰度峰值 public double dGrayAbandonLevelMax; public string FileName; //原图Y轴 int YSize = 0; int drawflag = 0; private int height = 0; private int width = 0; //画布大小 private Bitmap bitmap; private Graphics graphics; private float Tension = 0.001f; //要画曲线的点y坐标值,x值为10s采集一次数据 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 }; //记录鼠标在BSE移动时 图像的位置 double m_MouseMoveImageX = -1; double m_MouseMoveImageY = -1; //采集时间(毫秒) //int m_Milliseconds = 120; //记录采集点 List m_ElementSignPoint = new List(); //绘制采集点对象 public static List m_ElementPointGDIObjects; Point m_mouseCurrentPoint = new Point(); //鼠标缩放倍数 float m_CurrentMultiple = 0; float m_Multiple = 0.2f; int m_MaxMultipleRange = 4; //单击采集的鼠标位置 double dMouseImgX = 0; double dMouseImgY = 0; NLog.Logger log; //国际化 OTSCommon.Language lan; Hashtable table; #endregion #region 在右下角状态栏中显示鼠标当前位置所需要的参数 double dPositionX = 0; double dPositionY = 0; //double dPositionR = 0; //double Magnification = 0; int FieldWitdh = 0; double FieldHeight = 0; #endregion public enum ImageType { //BSE图 BSEImage = 0, //去背景图 RemoveBGImage = 1, //显示灰度曲线图 GrayLevelChart = 2, //显示去背景BSE图灰度曲线 GrayAbandonLevelChart = 4, //线扫描曲线 GrayLevelLine = 3 } //图bfResult public static bool bfResult = false; //当前是否显示线扫描 public static bool IsShowGrayLevelLine = false; //当前默认值 ImageType imagetype = ImageType.BSEImage; ImageType IsShowImageType = ImageType.BSEImage; public OTSMeasureStatusWindow(OTSIncAMeasureAppForm MeasureApp) { InitializeComponent(); m_MeasureAppForm = MeasureApp; if (m_ImageData == null) { m_ImageData = new OTSImageData(this, m_MeasureAppForm); } m_ElementPointGDIObjects = new List(); //进入时首先对XRayTable进行隐藏 panelXray.Visible = false; //国际化 lan = new OTSCommon.Language(this); table = lan.GetNameTable(this.Name); } /// /// 在控件中显示BSE图像 /// /// /// /// public void ShowImage(int m_iWidth, int m_iHeigh, byte[] bBseData) { try { Bitmap bitmap = CImageHandler.ToGrayBitmap(bBseData, m_iWidth, m_iHeigh); pbBSEImage.Image = bitmap; //设置Pictrue显示位置 pbBSEImage.Height = this.RestoreBounds.Height; pbBSEImage.Width = this.RestoreBounds.Height * 4 / 3; //获取黄线坐标位置 Rectangle rectangle = GetPictureBoxZoomSize(pbBSEImage); m_GetBSEImageInitPoint = rectangle.Location; pointStart.X = rectangle.X; pointEnd.X = rectangle.X + rectangle.Width; pointStart.Y = rectangle.Y + (rectangle.Height) / 2; pointEnd.Y = rectangle.Y + (rectangle.Height) / 2; pbBSEImage.Left = 0; pbBSEImage.Top = 0; } catch (Exception ex) { log.Error("(LZMeasureStatusWindow.ShowImage) " + ex.ToString()); } } /// /// 在控件中显示图像 /// /// /// /// public Image ShowImageStatus(int m_iWidth, int m_iHeigh, byte[] bBseData) { try { return CImageHandler.ToGrayBitmap(bBseData, m_iWidth, m_iHeigh); } catch (Exception ex) { log.Error("(LZMeasureStatusWindow.ShowImage) " + ex.ToString()); return null; } } //显示扫描曲线图方法 #region 显示扫描曲线图方法 private void DrawCurve(byte[] buf, PaintEventArgs e) { try { //创建位图 Rectangle rectangle = GetPictureBoxZoomSize(pbBSEImage); double rate = (double)rectangle.Height / (double)pbBSEImage.Image.Height; width = rectangle.Width; height = rectangle.Height; bitmap = new Bitmap(width, height); //创建Graphics类对象 graphics = Graphics.FromImage(bitmap); //清空图片背景色 //graphics.Clear(Color.White); Font font = new System.Drawing.Font("Arial", 9, FontStyle.Regular); Brush brush2 = new SolidBrush(Color.SaddleBrown); Brush brushPoint = new SolidBrush(Color.Red); Pen mypenRed = new Pen(Color.Red, 1); Pen mypenYellow = new Pen(Color.Yellow, 0.001f);//点颜色 //画曲线 if (drawflag == 1) { int len = Imagedata.Length; PointF[] CurvePointF = new PointF[len];//坐标点 float pointX = 0; float pointY = 0; for (int i = 0; i < Imagedata.Length; i++) { pointX = (pbBSEImage.Width - rectangle.Width) / 2 + Convert.ToSingle(i * rate); float imagei = (int)GrayLevel.Max - Convert.ToInt32(Imagedata[i]); float imagerate = (Convert.ToSingle(Convert.ToDouble(rectangle.Height) / 510)); pointY = imagei * imagerate + (rectangle.Height) / 4; if (pointY > ((rectangle.Height) * 3 / 4)) { float ii = pointY; } CurvePointF[i] = new PointF(pointX, pointY); } e.Graphics.DrawCurve(mypenYellow, CurvePointF, Tension);//画曲线 } } catch (Exception ex) { log.Error("(LZMeasureStatusWindow.DrawCurve) " + ex.ToString()); } } #endregion //处理获取调试图菜单事件 #region 处理获取调试图菜单事件 private void AcquireBSEImage_Click(object sender, EventArgs e) { try { if (m_ElementPointGDIObjects != null) { m_ElementPointGDIObjects.Clear(); } //设置右键菜单中的项 是否可编辑 SetContextMenuEnabled(true); GetAcquireBSEImage(); } catch (Exception ex) { MessageBox.Show(table["message20"].ToString() + ex.ToString()); } try { DelElementPointGDIObjects(); panelXray.Visible = false; m_CurrentMultiple = 0; } catch (Exception ex) { MessageBox.Show(table["message21"].ToString() + ex.ToString()); } } /// /// 获取BSE图方法 /// private void GetAcquireBSEImage() { try { //获取电镜中图像大小 string str = m_MeasureAppForm.m_ProjParam.GetBSEImageResolution();// 举例:1024X768 string[] sArray = str.Split('X'); if (sArray[0] != "" && sArray[1] != "") { m_iWidth = Convert.ToInt32(sArray[0]); m_iHeight = Convert.ToInt32(sArray[1]); } //建立图像数据 bBseData = new byte[m_iWidth * m_iHeight]; //获取图像数据 int nDwellTime = 4; try { int level = (int)m_MeasureAppForm.m_ProjParam.GetResultData().GetWorkingSample().GetMsrParams().GetImageScanParam().GetScanImageSpeed(); switch (level) { case 0: nDwellTime = 4; break; case 1: nDwellTime = 8; break; case 2: nDwellTime = 16; break; } } catch (Exception) { nDwellTime = 8; } OTSBSEImageFun m_GetBseImage = new OTSBSEImageFun(); int imageCount = m_GetBseImage.GetScanImage(m_iWidth, m_iHeight, nDwellTime, ref bBseData); //取图不成功就返回 if (imageCount > 0) { bfResult = true; } if (!bfResult) { if (contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Enabled == true) { contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Enabled = false; } //显示单点扫描元素信息菜单 contextMenuStrip1.Items[(int)MeasureStateMenuType.PointScanElementMenuItem].Enabled = false; pbBSEImage.Hide(); return; } else { //显示单点扫描元素信息菜单 contextMenuStrip1.Items[(int)MeasureStateMenuType.PointScanElementMenuItem].Enabled = true; } //获取灰度图数据 dGrayLevelData = new double[(int)GrayLevel.Max]; dGrayLevelData = m_ImageData.GetGaryData(bBseData, dGrayLevelData); //计算灰度最大值 dGrayLevelMax = dGrayLevelData[0]; for (int i = 1; i < (int)GrayLevel.Max; i++) { dGrayLevelMax = Math.Max(dGrayLevelMax, dGrayLevelData[i]); } SetClickMenuBSEImg(); //更新当前的图 UpdataImageChart(); myChart.Visible = false; //图像加载后的显示位置 m_CurrentMultiple = 0; pbBSEImage.Height = this.RestoreBounds.Height; //pbBSEImage.Width = this.RestoreBounds.Height * 4 / 3; pbBSEImage.Left = 0; pbBSEImage.Top = 0; } catch (Exception ex) { log.Error("(LZMeasureStatusWindow.AcquireBSEImage_Click) " + ex.ToString()); } } #endregion #region 设置点击BSE菜单 public void SetClickMenuBSEImg() { //用于线扫描曲线 IsShowImageType = ImageType.BSEImage; imagetype = ImageType.BSEImage; pbBSEImage.Show(); //panel1.Visible = false; //panel1.Hide(); } #endregion //更新当前的图 #region 更新当前的图 private void UpdataImageChart() { try { switch (imagetype) { case ImageType.BSEImage: { //在控件中显示图像 ShowImage(m_iWidth, m_iHeight, bBseData); Imagedata = new byte[m_iWidth]; IsShowGrayLevelLine = false; //获取默认Y轴 GetYSize(); //获取行数据 GetLineImage(YSize, m_iWidth, ref Imagedata); } break; case ImageType.RemoveBGImage: { ShowImage(m_iWidth, m_iHeight, cBseData); Imagedata = new byte[m_iWidth]; IsShowGrayLevelLine = false; //获取默认Y轴 GetYSize(); //获取行数据 GetLineImage(YSize, m_iWidth, ref Imagedata); } break; case ImageType.GrayLevelLine: { GetLineImage(YSize, m_iWidth, ref Imagedata); } break; default: { } break; } this.Refresh(); } catch (Exception ex) { log.Error("(LZMeasureStatusWindow.UpdataImageChart) " + ex.ToString()); } } #endregion //显示去背景图 = AUTO #region 显示去背景图 private void ShowRemoveBGImage_Click(object sender, EventArgs e) { //设置右键菜单中的项 是否可编辑 SetContextMenuEnabled(true); ShowRemoveBGImage(); m_CurrentMultiple = 0; panelXray.Visible = false; } protected void ShowRemoveBGImage() { try { //获取电镜中图像大小 string str = m_MeasureAppForm.m_ProjParam.GetBSEImageResolution(); string[] sArray = str.Split('X'); if (sArray[0] != "" && sArray[1] != "") { m_iWidth = Convert.ToInt32(sArray[0]); m_iHeight = Convert.ToInt32(sArray[1]); } //获取图像数据 COTSSample WSample = m_MeasureAppForm.m_ProjData.GetWorkingSample(); double pixelSize = WSample.CalculatePixelSize(); var imageProcessParam = WSample.GetMsrParams().GetImageProcessParam(); bfResult = m_ImageData.GetRemoveBGImage(imageProcessParam,pixelSize,m_iWidth, m_iHeight, bBseData, ref cBseData); //取图不成功就返回 if (!bfResult) { return; } //获取去背景灰度图数据 dGrayAbandonLevelData = new double[(int)GrayLevel.Max]; dGrayAbandonLevelData = m_ImageData.GetGrayAbandonData(cBseData, dGrayAbandonLevelData); //计算灰度去背景最大值 dGrayAbandonLevelMax = dGrayAbandonLevelData[0]; for (int i = 1; i < (int)GrayLevel.Max; i++) { dGrayAbandonLevelMax = Math.Max(dGrayAbandonLevelMax, dGrayAbandonLevelData[i]); } //用于线扫描曲线 IsShowImageType = ImageType.RemoveBGImage; imagetype = ImageType.RemoveBGImage; UpdataImageChart(); //panel1.Hide(); //panel1.Visible = false; myChart.Visible = false; pbBSEImage.Show(); //切换显示至BSE图 contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Enabled = true; if (OTSCommon.Language.ReadDefaultLanguage() == "ZH") { contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Text = "切换显示至BSE图"; } else { contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Text = "SwitchDisplayToBSEDiagram"; } } catch (Exception ex) { log.Error("(LZMeasureStatusWindow.ShowRemoveBGImage_Click) " + ex.ToString()); } } #endregion //显示灰度曲线 #region 显示灰度曲线 private void ShowGrayLevelImage_Click(object sender, EventArgs e) { //设置右键菜单中的项 是否可编辑 SetContextMenuEnabled(false); ShowGrayLevelImage(); myChart.Visible = true; panelXray.Visible = false; IsShowGrayLevelLine = false; } protected void ShowGrayLevelImage() { try { imagetype = ImageType.GrayLevelChart; //panel1.Visible = true; //panel1.Show(); pbBSEImage.Hide(); m_ImageData.Line = idLine.GrayImage; //切换显示至BSE图 contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Enabled = true; contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Enabled = true; if (OTSCommon.Language.ReadDefaultLanguage() == "ZH") { contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Text = "切换显示至BSE图"; } else { contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Text = "SwitchDisplayToBSEDiagram"; } UpdataImageChart(); int[] XData = new int[(int)GrayLevel.Max]; for (int i = 0; i < (int)GrayLevel.Max; i++) { XData[i] = i + 1; } int[] YData = new int[dGrayLevelData.Length]; for (int i = 0; i < dGrayLevelData.Length; i++) { YData[i] = (int)dGrayLevelData[i]; } chartData(XData, YData); } catch (Exception ex) { log.Error("(LZMeasureStatusWindow.ShowGrayLevelImage_Click) " + ex.ToString()); } } #endregion //显示线扫描曲线 #region 显示线扫描曲线 private void ShowGrayLevelLine_Click(object sender, EventArgs e) { panelXray.Visible = false; ShowGrayLevelLine(); } protected void ShowGrayLevelLine() { try { imagetype = ImageType.GrayLevelLine; //取图不成功就返回 if (!bfResult) { return; } UpdataImageChart(); m_ImageData.Line = idLine.GrayLine; } catch (Exception ex) { log.Error("(LZMeasureStatusWindow.ShowGrayLevelLine_Click) " + ex.ToString()); } } #endregion #region 扫描线轴X public Rectangle GetPictureBoxZoomSize(PictureBox p_PictureBox) { if (p_PictureBox != null) { PropertyInfo _ImageRectanglePropert = p_PictureBox.GetType().GetProperty("ImageRectangle", BindingFlags.Instance | BindingFlags.NonPublic); return (Rectangle)_ImageRectanglePropert.GetValue(p_PictureBox, null); } return new Rectangle(0, 0, 0, 0); } #endregion private void OTSMeasureStatusWindow_Load(object sender, EventArgs e) { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(OTSMeasureStatusWindow)); this.control_XRayTable1 = new Control_XRayTable(); this.control_XRayTable1.BackColor = System.Drawing.Color.FromArgb(180,255,255); this.control_XRayTable1.Dock = System.Windows.Forms.DockStyle.Fill; this.control_XRayTable1.GBInfoStr = ""; this.control_XRayTable1.GoodChineseName = ""; this.control_XRayTable1.GoodName = ""; this.control_XRayTable1.List_ShowElementInfo = ((System.Collections.Generic.List)(resources.GetObject("control_XRayTable1.List_ShowElementInfo"))); this.control_XRayTable1.Location = new System.Drawing.Point(0, 0); this.control_XRayTable1.Margin = new System.Windows.Forms.Padding(2); this.control_XRayTable1.Name = "control_XRayTable1"; this.control_XRayTable1.ShowAnalysisXray = true; this.control_XRayTable1.ShowSearchXray = false; this.control_XRayTable1.Size = new System.Drawing.Size(781, 200); this.control_XRayTable1.STDName = ""; this.control_XRayTable1.TabIndex = 0; this.control_XRayTable1 = new OTSIncAGraph.Controls.Control_XRayTable(); this.panelXray.Controls.Add(this.control_XRayTable1); //添加鼠标点击事件 myChart.MouseClick += new MouseEventHandler(this.LZMeasureStatusWindow_MouseClick); pbBSEImage.MouseClick += new MouseEventHandler(HiddenXrayTablePanel_MouseClick); // // pbBSEImage添加鼠标操作 // this.pbBSEImage.MouseUp += new MouseEventHandler(this.pbBSEImage_MouseUp); this.pbBSEImage.MouseDown += new MouseEventHandler(this.pbBSEImage_MouseDown); this.MouseUp += new MouseEventHandler(this.pbBSEImage_MouseUp); this.MouseDown += new MouseEventHandler(this.pbBSEImage_MouseDown); this.MouseWheel += new MouseEventHandler(this.pbBSEImage_MouseWheel); log = NLog.LogManager.GetCurrentClassLogger(); } private void HiddenXrayTablePanel_MouseClick(object sender, MouseEventArgs e) { if (e.Button != MouseButtons.Right) { if (!IsShowGrayLevelLine) { if (m_ElementPointGDIObjects != null) { if (m_ElementPointGDIObjects.Count > 0) { foreach (var item in m_ElementPointGDIObjects) { Rectangle rect = new Rectangle(e.Location, new Size(1, 1)); if (Math.Abs(e.Y - item.GetOrigionalDrawRegionF().Y) < 5 && Math.Abs(e.X - item.GetOrigionalDrawRegionF().X) < 5) { //显示Xray图像 panelXray.Visible = true; } else { panelXray.Visible = false; } } } } } } } private void LZMeasureStatusWindow_MouseClick(object sender, MouseEventArgs e) { try { if (e.Button == MouseButtons.Right && e.Clicks == 1) { contextMenuStrip1.Show(PointToScreen(e.Location)); SetContentMenu(); } } catch (Exception ex) { log.Error("(LZMeasureStatusWindow.LZMeasureStatusWindow_MouseClick) " + ex.ToString()); } } #region 设置右键菜单中的项 是否可编辑 protected void SetContextMenuEnabled(bool isEnabled) { //隐藏右键菜单中的项 MenuItemLineScam.Checked = false; MenuItemLineScam.Enabled = isEnabled; PointScanElementMenuItem.Enabled = isEnabled; bool showExprot = m_ElementPointGDIObjects.Count > 0 ? true : false; ExportScanInfoMenuItem.Enabled = showExprot; IsShowGrayLevelLine = false; ViewStripMenuItem.Enabled = isEnabled; toolStripMenuItem1.Enabled = true; this.Cursor = Cursors.Default; this.Validate(); } #endregion #region 获取行数据 private void GetLineImage(int iHeight, int iWidth, ref byte[] bdata) { try { Stream stream = null; if (IsShowImageType == ImageType.BSEImage) { stream = new MemoryStream(bBseData); } else if (IsShowImageType == ImageType.RemoveBGImage) { stream = new MemoryStream(cBseData); } if (iHeight >= 0) { stream.Seek(iHeight * iWidth, SeekOrigin.Begin); } stream.Read(bdata, 0, iWidth); } catch (Exception ex) { log.Error("(LZMeasureStatusWindow.GetLineImage) " + ex.ToString()); } } #endregion private void panel1_Click(object sender, EventArgs e) { pbBSEImage.Show(); } private void contextMenuStrip1_Opened(object sender, EventArgs e) { try { if (bfResult) { SampleParaLock.Enabled = true; ToolStripMenuItem.Enabled = true; grayToolStripMenuItem.Enabled = true; AbandonGrayStripMenuItem.Enabled = true; if (0 <= m_MouseMoveImageX && m_MouseMoveImageX <= 1024) { contextMenuStrip1.Items[(int)MeasureStateMenuType.PointScanElementMenuItem].Enabled = true; } else { contextMenuStrip1.Items[(int)MeasureStateMenuType.PointScanElementMenuItem].Enabled = false; } if (!MenuItemLineScam.Checked) { contextMenuStrip1.Items[(int)MeasureStateMenuType.PointScanElementMenuItem].Enabled = true; bool showExprot = m_ElementPointGDIObjects.Count > 0 ? true : false; if (showExprot) { contextMenuStrip1.Items[(int)MeasureStateMenuType.ExportReport].Enabled = true; } } else { contextMenuStrip1.Items[(int)MeasureStateMenuType.PointScanElementMenuItem].Enabled = false; contextMenuStrip1.Items[(int)MeasureStateMenuType.ExportReport].Enabled = false; return; } if (myChart.Visible) { MenuItemLineScam.Enabled = false; contextMenuStrip1.Items[(int)MeasureStateMenuType.PointScanElementMenuItem].Enabled = false; contextMenuStrip1.Items[(int)MeasureStateMenuType.ExportReport].Enabled = false; } else { MenuItemLineScam.Enabled = true; contextMenuStrip1.Items[(int)MeasureStateMenuType.PointScanElementMenuItem].Enabled = true; bool showExprot = m_ElementPointGDIObjects.Count > 0 ? true : false; if (showExprot) { contextMenuStrip1.Items[(int)MeasureStateMenuType.ExportReport].Enabled = true; } } //根据去背景方式 设置可视化使用状态 COTSSample WSample = m_MeasureAppForm.m_ProjData.GetWorkingSample(); COTSImageProcParam ImgProcPrm = WSample.GetMsrParams().GetImageProcessParam(); if (ImgProcPrm.GetBGRemoveType() == otsdataconst.OTS_BGREMOVE_TYPE.MANUAL) { contextMenuStrip1.Items[(int)MeasureStateMenuType.SetVisualGray].Enabled = true; } else { contextMenuStrip1.Items[(int)MeasureStateMenuType.SetVisualGray].Enabled = false; } } else { ToolStripMenuItem.Enabled = false; grayToolStripMenuItem.Enabled = false; MenuItemLineScam.Enabled = false; AbandonGrayStripMenuItem.Enabled = false; } } catch (Exception ex) { log.Error("(LZMeasureStatusWindow.contextMenuStrip1_Opened) " + ex.ToString()); } } //拖动灰度线 #region 拖动灰度线 int LineX = 0; int LineXEnd = 0; public Point pointStart = new Point(100, 100); public Point pointEnd = new Point(400, 100); private bool m_bMouseDown = false; private void pictureBox1_Paint(object sender, PaintEventArgs e) { try { if (bfResult) { if (MenuItemLineScam.Checked) { IsShowGrayLevelLine = true; Rectangle rectangle = GetPictureBoxZoomSize(pbBSEImage); if (pointStart.Equals(pointEnd)) { return; } Point start = new Point(100, pointStart.Y); Point end = new Point(500, pointEnd.Y); int lens = curvebuf.Length; if (lens <= 1) { drawflag = 0; MessageBox.Show(table["message22"].ToString(), table["message23"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { drawflag = 1; //Y值 double rate = (double)pbBSEImage.Image.Height / (double)rectangle.Height; int YSize = Convert.ToInt32((rate * (double)pointStart.Y)); //显示线扫描 黄色线的曲线数据 GetLineImage(YSize, m_iWidth, ref Imagedata); DrawCurve(Imagedata, e); } 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)); 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)); e.Graphics.DrawLine(new Pen(Color.Blue), new Point(rectangle.X, pointStart.Y), new Point(rectangle.X + rectangle.Width, pointEnd.Y)); #region 绘制刻度条 float offHeight = (rectangle.Y + (rectangle.Height) / 4) - (rectangle.Y + rectangle.Height * 3 / 4); float grayValue = Math.Abs(offHeight / 255); //设置文字对齐方式 StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; SolidBrush solidBrush = new SolidBrush(Color.FromArgb(100, Color.Red)); //字体大小 根据样品孔Rectangle大小 float fontSize = 15; Font font = new Font("黑体", fontSize, FontStyle.Bold); Pen pen = new Pen(Color.Red, 1); pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom; pen.DashPattern = new float[] { 5, 5 }; int fontOffWidth = 50; int fontOffHeight = 10; int scaleLine = 0; for (int i = 25; i <= 225; i+=25) { scaleLine = (int)(grayValue * i); 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)); e.Graphics.DrawString(i.ToString(), font, solidBrush, rectangle.X + 20, (rectangle.Y + rectangle.Height * 3 / 4) - scaleLine - fontOffHeight, sf); } #endregion } else { IsShowGrayLevelLine = false; } } if (!MenuItemLineScam.Checked) { if (m_ElementPointGDIObjects != null) { if (m_ElementPointGDIObjects.Count > 0) { //绘制采集点标记 foreach (CRectangleGDIObject item in m_ElementPointGDIObjects) { if (item != null) { item.OnPaint(e); } } } } } } catch (Exception ex) { log.Error("(LZMeasureStatusWindow.pictureBox1_Paint) " + ex.ToString()); } } private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { try { //如果pictureBox1中没有图像 则return退出 if (pbBSEImage.Image == null) { return; } Control lCtrl = (sender as Control); Rectangle rectangle = GetPictureBoxZoomSize(pbBSEImage); int startimageX = 0; int startimageY = 0; //处理灰度值 int grayValue = 0; // 生成鼠标的位置 int MouseLine = e.X; //当前鼠标所在图片中的位置 int imageX = 0; int imageY = 0; //当前pictrueBox与实际图片的X、Y比例 double rateX = 0; double rateY = 0; if (bBseData != null) { if ((pbBSEImage.Width - rectangle.Width) / 2 < e.X && e.X < (pbBSEImage.Width - rectangle.Width) / 2 + rectangle.Width) { imageX = e.X - (pbBSEImage.Width - rectangle.Width) / 2; rateX = (double)m_iWidth / (double)rectangle.Width; startimageX = Convert.ToInt32(imageX * rateX); m_MouseMoveImageX = startimageX; if (MoveFlag) { pbBSEImage.Left += Convert.ToInt32(e.X - xPos);//设置x坐标. pbBSEImage.Top += Convert.ToInt32(e.Y - yPos);//设置y坐标. } } else { startimageX = 0; m_MouseMoveImageX = -1; } if ((pbBSEImage.Height - rectangle.Height) / 2 < e.Y && e.Y < (pbBSEImage.Height - rectangle.Height) / 2 + rectangle.Height) { imageY = e.Y - (pbBSEImage.Height - rectangle.Height) / 2; rateY = (double)m_iHeight / (double)rectangle.Height; startimageY = Convert.ToInt32(imageY * rateY); m_MouseMoveImageY = startimageY; } //如果当前鼠标在图像Y轴中 if (imageX > 0 && imageY > 0) { if (imageY > 1) { startimageX = startimageX + (startimageY * m_iWidth); if (IsShowImageType == ImageType.BSEImage) { grayValue = bBseData[startimageX]; } else { grayValue = cBseData[startimageX]; } } else if (startimageY == 1) { if (IsShowImageType == ImageType.BSEImage) { grayValue = bBseData[startimageX]; } else { grayValue = cBseData[startimageX]; } } } else { grayValue = 0; } } LineX = rectangle.X + 1; LineXEnd = rectangle.X + rectangle.Width; if (LineX < MouseLine && MouseLine < LineXEnd) { if (MenuItemLineScam.Checked) { if (Math.Abs(e.Y - pointStart.Y) < 2) { this.Cursor = Cursors.SizeNS; } else { this.Cursor = Cursors.Default; } } } //Y值 double rate = (double)pbBSEImage.Image.Height / (double)rectangle.Height; int YSize = Convert.ToInt32((rate * (double)e.Y)); //显示线扫描 黄色线的曲线数据 GetLineImage(YSize, m_iWidth, ref Imagedata); string strGrayValue = grayValue.ToString(); switch (strGrayValue.ToString().Length) { case 1: strGrayValue = " " + grayValue.ToString(); break; case 2: strGrayValue = " " + grayValue.ToString(); break; } //此处调接口显示灰度值 m_MeasureAppForm.ShowGrayVal(strGrayValue.ToString()); if (!IsShowGrayLevelLine) { if (m_ElementPointGDIObjects != null) { if (m_ElementPointGDIObjects.Count > 0) { foreach (var item in m_ElementPointGDIObjects) { Rectangle rect = new Rectangle(e.Location, new Size(1, 1)); if (Math.Abs(e.Y - item.GetOrigionalDrawRegionF().Y) < 5 && Math.Abs(e.X - item.GetOrigionalDrawRegionF().X) < 5) { //设置鼠标样式 this.Cursor = Cursors.Hand; } else { this.Cursor = Cursors.Default; } } } } } if (e.Button != MouseButtons.Left) { return; } pointStart = new Point(pointStart.X, e.Y); pointEnd = new Point(pointEnd.X, e.Y); pbBSEImage.Refresh(); } catch (Exception ex) { log.Error("(LZMeasureStatusWindow.pictureBox1_MouseMove) " + ex.ToString()); } } private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { try { m_mouseCurrentPoint = e.Location; if (e.Button != MouseButtons.Left) { return; } m_bMouseDown = !m_bMouseDown; } catch (Exception ex) { log.Error("(LZMeasureStatusWindow.pictureBox1_MouseDown) " + ex.ToString()); } } #endregion //显示去背景BSE图得灰度曲线值 #region 显示去背景BSE图得灰度曲线值 private void ShowAbandonGrayLevelImage_Click(object sender, EventArgs e) { //设置右键菜单中的项 是否可编辑 SetContextMenuEnabled(false); ShowAbandonGrayLevelImage(); myChart.Visible = true; panelXray.Visible = false; IsShowGrayLevelLine = false; } protected void ShowAbandonGrayLevelImage() { try { imagetype = ImageType.GrayAbandonLevelChart; COTSSample WSample = m_MeasureAppForm.m_ProjData.GetWorkingSample(); var pixelSize = WSample.CalculatePixelSize(); bool bfResult = m_ImageData.GetRemoveBGImage(WSample.GetMsrParams().GetImageProcessParam(),pixelSize,m_iWidth, m_iHeight, bBseData, ref cBseData); if (bfResult) { dGrayAbandonLevelData = new double[(int)GrayLevel.Max]; m_ImageData.GetGrayAbandonData(cBseData, dGrayAbandonLevelData); //计算灰度去背景最大值 dGrayAbandonLevelMax = dGrayAbandonLevelData[0]; for (int i = 0; i < (int)GrayLevel.Max; i++) { dGrayAbandonLevelMax = Math.Max(dGrayAbandonLevelMax, dGrayAbandonLevelData[i]); } } pbBSEImage.Hide(); m_ImageData.Line = idLine.GrayImage; //切换显示至BSE图 contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Enabled = true; contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Enabled = true; if (OTSCommon.Language.ReadDefaultLanguage() == "ZH") { contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Text = "切换显示至BSE图"; } else { contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Text = "SwitchDisplayToBSEDiagram"; } UpdataImageChart(); int[] XData = new int[(int)GrayLevel.Max]; for (int i = 0; i < (int)GrayLevel.Max; i++) { XData[i] = i + 1; } int[] YData = new int[dGrayAbandonLevelData.Length]; for (int i = 0; i < dGrayAbandonLevelData.Length; i++) { YData[i] = (int)dGrayAbandonLevelData[i]; } chartData(XData, YData); } catch (Exception ex) { log.Error("(LZMeasureStatusWindow.ShowAbandonGrayLevelImage_Click) " + ex.ToString()); } } #endregion private void pictureBox1_MouseClick(object sender, MouseEventArgs e) { try { if (e.Button == MouseButtons.Right && e.Clicks == 1) { int XMenu = pbBSEImage.Left + e.Location.X; int YMenu = pbBSEImage.Top + e.Location.Y; Point mousePoint = new Point(XMenu, YMenu); contextMenuStrip1.Show(PointToScreen(mousePoint)); //电镜位置信息 Point semLocatin = new Point((int)dPositionX, (int)dPositionY); //Rectangle semRect = new Rectangle(); if (IsSEMLocationOnTheSampleStage(semLocatin)) { SetContentMenu(); } } } catch (Exception ex) { log.Error("(MeasureStatusWindow.pictureBox1_MouseClick) " + ex.ToString()); } } private void ChangeDiffImageShow_Click(object sender, EventArgs e) { //设置右键菜单中的项 是否可编辑 SetContextMenuEnabled(true); //显示切换至BSE图 if (contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Text == "切换显示至BSE图"|| contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Text == "SwitchDisplayToBSEDiagram") { contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Enabled = true; if (OTSCommon.Language.ReadDefaultLanguage() == "ZH") { contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Text = "切换显示至BSE去背景图"; } else { contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Text = "SwitchDisplayToBSEBackgroundImage"; } //显示BSE图 if (bBseData != null) { //用于线扫描曲线 IsShowImageType = ImageType.BSEImage; imagetype = ImageType.BSEImage; //在控件中显示图像 ShowImage(m_iWidth, m_iHeight, bBseData); pbBSEImage.Show(); //panel1.Visible = false; } } else if (contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Text == "切换显示至BSE去背景图"|| contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Text == "SwitchDisplayToBSEBackgroundImage") { contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Enabled = true; if (OTSCommon.Language.ReadDefaultLanguage() == "ZH") { contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Text = "切换显示至BSE图"; } else { contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Text = "SwitchDisplayToBSEDiagram"; } //显示去背景BSE图 if (bBseData != null) { //用于线扫描曲线 IsShowImageType = ImageType.RemoveBGImage; imagetype = ImageType.RemoveBGImage; ShowImage(m_iWidth, m_iHeight, cBseData); //panel1.Visible = false; pbBSEImage.Show(); } } myChart.Visible = false; UpdataImageChart(); GetLineImage(YSize, m_iWidth, ref Imagedata); m_CurrentMultiple = 0; panelXray.Visible = false; } #region 显示鼠标位置 /// /// 显示鼠标位置 /// /// 当前处理后的鼠标路径 减去边缘 /// Pictrue中的图像尺寸与位置 public void ShowMouseSEMCurrentLocation(Point eMouseLocation, Rectangle imageRect, Rectangle semRect) { //真实图像中心点 Point imgRealCenterPoint = new Point(); //显示图像中心点 Point imgCenterPoint = new Point(); int imgWidth = 0; int imgHeight = 0; //获取真实图片的分辨率 m_MeasureAppForm.m_ProjParam.GetBSEImageSize(ref imgWidth, ref imgHeight); //根据真实图像的像素 获取真实图像中心点 imgRealCenterPoint.X = imgWidth / 2; imgRealCenterPoint.Y = imgHeight / 2; //图像与真是图像的宽高的比例 double witdhRote = 0; double heightRote = 0; //获取显示图像与真是图像的宽高的比例 witdhRote = (double)imageRect.Width / imgWidth; heightRote = (double)imageRect.Height / imgHeight; //获取每个单位中包含多少像素 根据帧图的长度 与 真实图像的长度计算 double lenghtInPixWidth = (double)FieldWitdh / imgWidth / witdhRote; double lenghtInPixHeight = (double)FieldHeight / imgHeight / heightRote; //通过鼠标当前位置 获取位置 原点为控件的左上角起始点 double MouseWidth = (double)eMouseLocation.X * lenghtInPixWidth; double MouseHeight = (double)eMouseLocation.Y * lenghtInPixHeight; //根据显示图像的像素 获取真实图像中心点 imgCenterPoint.X = imageRect.Width / 2; imgCenterPoint.Y = imageRect.Height / 2; //通过鼠标当前位置 获取位置 原点为控件的左上角起始点 double imgCenterWidth = (double)imgCenterPoint.X * lenghtInPixWidth; double imgCenterHeight = (double)imgCenterPoint.Y * lenghtInPixHeight; //获取当前鼠标坐标与SEM当前坐标的距离 单位毫米 double apartCenterPointWidth = MouseWidth - imgCenterWidth; double apartCenterPointHeight = MouseHeight - imgCenterHeight; //将微米转换为毫米 float mousePointX = Convert.ToSingle((apartCenterPointWidth / 1000).ToString("F3")); float mousePointY = Convert.ToSingle((apartCenterPointHeight / 1000).ToString("F3")); //根据Sem电镜当前位置 计算与SEM坐标起始点相差的距离 //1.获取电镜当前位置 double semX = dPositionX; double semY = dPositionY; //2.获取当前电镜位置与SEM原点位置的距离 string apartToSEMWidth = Convert.ToSingle(semX + mousePointX).ToString("F3"); string apartToSEMHeight = Convert.ToSingle(semY - mousePointY).ToString("F3"); //编辑显示内容 string STSemCoordinate = "X:" + apartToSEMWidth + "|Y:" + apartToSEMHeight + ""; //显示XY轴 //m_MeasureAppForm.ShowSemCoordvAL(STSemCoordinate); } #endregion #region 设置测量状态初始化 /// /// 设置测量状态初始化 /// public void SetMeasureStatusInit() { //panel1.Hide(); //panel1.Visible = false; pbBSEImage.Hide(); foreach (ToolStripItem item in contextMenuStrip1.Items) { if (item != contextMenuStrip1.Items[(int)MeasureStateMenuType.ReadBSEPic]) { item.Enabled = false; } } } #endregion #region 获取SEM当前位置 public void GetSEMLocation(ref double dPositionX, ref double dPositionY, ref double dPositionR) { try { //获取SEM当前位置 m_ImageData.GetSemPositionXY(ref dPositionX, ref dPositionY, ref dPositionR); } catch (Exception ex) { MessageBox.Show(table["message24"].ToString() + ex.ToString()); } } #endregion #region 鼠标是否在图像上移动 /// /// 鼠标是否在图像上移动 /// /// /// /// public bool IsOnTheImage(Point mouseCurrentLocation, PictureBox picBox, ref Point mouseLocation, ref Rectangle imageRect) { //通过Pictrue获取图像尺寸位置 Rectangle rectangle = GetPictureBoxZoomSize(picBox); imageRect = rectangle; //当前鼠标坐标是否包含在图像中 bool result = imageRect.Contains(mouseCurrentLocation); if (result) { //获取与边框的间隔 mouseLocation.X = mouseCurrentLocation.X - rectangle.X; mouseLocation.Y = mouseCurrentLocation.Y; return true; } return false; } #endregion #region 判断当前电镜位置是否在样品台内部 /// /// 判断当前电镜位置是否在样品台内部 /// /// 电镜当前位置 /// 样品台尺寸与位置 /// public bool IsSEMLocationOnTheSampleStage(Point semLocation) { //获取样品台信息 //StageDrawingData SData = m_MeasureAppForm.m_SamplepaceWindow.m_visualStage.GetOTSSampleStageData(); //string stageName = SData.sStageName; //int widthDomain = 0; //int heightDomain = 0; ////获取样品台 //ShapeType StageShape = SData.bStageShape; //ValueType XDomain = new Point(SData.StageDomain.Left, SData.StageDomain.Top); //ValueType YDomain = new Point(SData.StageDomain.Right, SData.StageDomain.Bottom); ////转换类型 //Point xDomain = ((System.Drawing.Point)XDomain); //Point yDomain = ((System.Drawing.Point)YDomain); ////宽度 //widthDomain = Math.Abs(((Point)yDomain).X - ((Point)xDomain).X); //heightDomain = Math.Abs(((Point)yDomain).Y - ((Point)xDomain).Y); ////设置样品台宽度 //int wDomain = widthDomain; //int IsWidth = this.Height > this.Width ? 0 : 1; //ShapeType Shape = SData.bStageShape; //CreateRectangle CreateBourary = null; ////0:区域圆形 1:区域矩形 2:文字 //if (SData.bStageShape == (ShapeType)CreateRectangleType.Rectangle) //{ // CreateBourary = m_MeasureAppForm.m_SamplepaceWindow.m_visualStage.GetCtrlCoordRect ( xDomain,yDomain,CreateRectangleType.Rectangle, "", ""); //} //else //{ // CreateBourary = OTSSamplespaceGraphicsPanelFun.GetPixRect(CreateRectangleType.SampleBackGround_Circle, "", "", this.Width, this.Height); //} ////获取SEM位置 //CreateRectangle semRectangle = OTSSamplespaceGraphicsPanelFun.GetPixRect( CreateRectangleType.Rectangle, "", "", this.Width, this.Height); //semRect = semRectangle.Region; return m_MeasureAppForm.m_SamplepaceWindow.m_visualStage.IfMouseInStage(semLocation); } #endregion #region 设置右键菜单项是否可用 /// /// 设置右键菜单项是否可用 /// public void SetContentMenu() { int sampleCount = m_MeasureAppForm.m_ProjParam.GetSampleCount(); if (sampleCount == 0) { foreach (ToolStripItem item in contextMenuStrip1.Items) { item.Enabled = false; } } else { if (m_MeasureAppForm.MeasureThreadRunFlag) { if (m_MeasureAppForm.m_MsrThreadWrapper.BgWorkIsPaused()) { foreach (ToolStripItem item in contextMenuStrip1.Items) { item.Enabled = true; } } else { foreach (ToolStripItem item in contextMenuStrip1.Items) { item.Enabled = false; } } } double iWDistance = 0; double dMagni = 0; m_MeasureAppForm.m_ProjParam.GetWorkingSampleSEMData(ref iWDistance, ref dMagni); if (iWDistance != 0 && dMagni != 0) { contextMenuStrip1.Items[(int)MeasureStateMenuType.ReadBSEPic].Enabled = true; } } } #endregion #region 获取线扫描初始位置 public void GetYSize() { Rectangle rectangle = GetPictureBoxZoomSize(pbBSEImage); double rate = (double)pbBSEImage.Image.Height / (double)rectangle.Height; YSize = Convert.ToInt32((rate * (double)pointStart.Y)); } #endregion public void chartData(int[] XData, int[] YData) { //添加数据 myChart.Series[0].Points.DataBindXY(XData, YData); myChart.Series[0].Label = ""; myChart.Series[0].LegendText = ""; if (OTSCommon.Language.ReadDefaultLanguage() == "ZH") { myChart.Series[0].Name = "曲线图"; } else { myChart.Series[0].Name = "Graph"; } myChart.Series[0].IsVisibleInLegend = false; switch (imagetype) { case ImageType.GrayLevelChart: if (OTSCommon.Language.ReadDefaultLanguage() == "ZH") { myChart.Titles[0].Text = "灰度曲线图"; } else { myChart.Titles[0].Text = "B-GrayCurve"; } break; case ImageType.GrayAbandonLevelChart: if (OTSCommon.Language.ReadDefaultLanguage() == "ZH") { myChart.Titles[0].Text = "去背景灰度曲线图"; } else { myChart.Titles[0].Text = "Background-freeGray-scaleCurve"; } break; default: myChart.Titles[0].Text = ""; break; } } private void PointScanElementMenuItem_Click(object sender, EventArgs e) { MenuItemLineScam.Checked = false; //电镜设置对象 //控制类对象初始化 EDSController m_EDSHardwareMgr = EDSController.GetEDSController(); SemController m_SEMHardwareMgr = SemController.GetSEMController(); //1.连接电镜 if (m_EDSHardwareMgr.Connect()) { bool initResult = false; //线程调用 加载 initResult = m_EDSHardwareMgr.Init(); if (initResult) { COTSMsrPrjResultData cProjMgr = m_MeasureAppForm.m_ProjParam.GetResultData(); //获取工作样品对象 COTSSample sampleClr = cProjMgr.GetWorkingSample(); //清空之前记录的标识 if (m_ElementPointGDIObjects != null) { if (m_ElementPointGDIObjects.Count > 0) { //清空 m_ElementPointGDIObjects.Clear(); } } //2.获取鼠标在图像的位置 dMouseImgX = m_MouseMoveImageX; dMouseImgY = m_MouseMoveImageY; //3.根据所要扫描的位置进行元素分析 uint a_Milliseconds = 0; //采集时间 a_Milliseconds = Convert.ToUInt32(sampleClr.GetMsrParams().GetXRayParam().GetMidAnalyAQTime()); //元素数量 ValueType a_nElementNum = 0; //元素名称 string a_strElementName = ""; //元素Xray数据 uint[] a_ElementXrayData = new uint[2000]; //设置分辨率 sampleClr.GetBSESize(out m_iWidth, out m_iHeight); m_EDSHardwareMgr.SetResolution(m_iWidth, m_iHeight); //设置期望计数率 m_EDSHardwareMgr.SetAnalyExpCount(m_MeasureAppForm.m_ProjData.GetWorkingSample().GetMsrParams().GetXRayParam().GetAnalyExpCount()); if (m_EDSHardwareMgr.GetXRayAndElements(a_Milliseconds, (int)dMouseImgX, (int)dMouseImgY, ref a_ElementXrayData, ref a_nElementNum, ref a_strElementName)) { log.Trace("--获取单点扫描数据:元素数量:'" + a_nElementNum + "' ,元素名称:'" + a_strElementName + "'--"); //4.在BSE上绘制扫描标记 //4-1 获取鼠标在BSE图上的位置 Point p_mouseCurrentTempPoint = m_mouseCurrentPoint; //4-2 根据位置绘制标记 Point ImgPoint = new Point((int)dMouseImgX, (int)dMouseImgY); Rectangle rect = new Rectangle(p_mouseCurrentTempPoint, new Size(1, 1)); CRectangleGDIObject createRect = new CRectangleGDIObject(rect, ImgPoint, m_CurrentMultiple, CreateRectangleType.DrawBSEElementSignPoint); m_ElementPointGDIObjects.Add(createRect); //5.获取成功后弹出对话框 //计数率 double electronicCount = 0; uint[] u_ElementXrayData = new uint[2000]; for (int i = 0; i < a_ElementXrayData.Length; i++) { u_ElementXrayData[i] = (uint)a_ElementXrayData[i]; //累加计数率 electronicCount += a_ElementXrayData[i]; } //显示Xray控件 panelXray.Visible = true; //获取数据后,需要对xraytable设置 string[] strGroup = a_strElementName.Split('\n'); //get CElementChemistryClr list List list_showelementinfo = new List(); for (int i = 0; i < strGroup.Length; i++) { if (!strGroup[i].Equals("")) { ShowElementInfo ls_sei = new ShowElementInfo(); ls_sei.ElementName = strGroup[i].Split(':')[0]; ls_sei.Percentage = Convert.ToDouble(strGroup[i].Split(':')[1]); list_showelementinfo.Add(ls_sei); } } //设置分析Xray数据 control_XRayTable1.SetXRayShowLineValue(new uint[2000], u_ElementXrayData, list_showelementinfo); //需要显示计数率 string strElectronicCount = string.Empty; if (electronicCount > 1000) { strElectronicCount = (Convert.ToDouble(electronicCount) / 1000).ToString("f2") + "kcps"; } control_XRayTable1.List_ShowElementInfo = list_showelementinfo; } ExportScanInfoMenuItem.Enabled = true; this.Invalidate(); } } } #region 根据夹杂物编号获取夹杂物名称 public string GetInclusionName(int nInclusionID) { //获取使用标准库的名称,也许这个也不是很正确?? string str_stdname = ""; string str_IncALibName = ""; COTSSample cSample = m_MeasureAppForm.m_ProjParam.GetResultData().GetWorkingSample(); if (nInclusionID < 1000) { //小于1000,使用系统默认分类 str_IncALibName = ""; str_stdname = "默认标准库"; } else if (nInclusionID >= 1000 && nInclusionID < 10000) { //大于等于1000,并且小于10000时,使用系统数据库中夹杂物来分析 str_IncALibName = ""; str_stdname = "用户定义标准库"; } else if (nInclusionID > 10000) { //查询数据中的化合物名称 SQliteManageClass sQliteManageClass = new SQliteManageClass(); str_IncALibName = sQliteManageClass.GetNameByIncAId(nInclusionID.ToString()); //大于10000时,使用用户标准库来分析夹杂物名称 if (str_stdname == "") str_stdname = "系统标准库"; } return str_IncALibName; } #endregion public void DelElementPointGDIObjects() { if (m_ElementPointGDIObjects != null) { if (m_ElementPointGDIObjects.Count > 0) { //删除点标记 m_ElementPointGDIObjects.Clear(); this.Invalidate(); } } } private void ExportScanInfoMenuItem_Click(object sender, EventArgs e) { try { //导出图片到报告中 ExportReport(); } catch (Exception ex) { log.Error("ExportScanInfoMenuItem_Click:保存图片错误日志: " + ex.ToString()); } } /// /// 导出Image到报告 /// private bool ExportReport() { string startupPath = System.Windows.Forms.Application.StartupPath + "\\TempReport\\"; if (!Directory.Exists(startupPath)) { Directory.CreateDirectory(startupPath); } //保存Xray图片 string ImgFilePath = startupPath + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpg"; Bitmap bseBM = new Bitmap(this.pbBSEImage.Width, this.pbBSEImage.Height); this.pbBSEImage.DrawToBitmap(bseBM, new Rectangle(0, 0, this.pbBSEImage.Width, this.pbBSEImage.Height)); //保存图片 bseBM.Save(ImgFilePath, System.Drawing.Imaging.ImageFormat.Jpeg); //释放资源 bseBM.Dispose(); //保存Xray图片 string ImgXrayFilePath = startupPath + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpg"; int xrayWidth = control_XRayTable1.Width; int xrayHeight = control_XRayTable1.Height; Bitmap xrayBM = new Bitmap(xrayWidth, xrayHeight); this.control_XRayTable1.DrawToBitmap(xrayBM, new Rectangle(0, 0, xrayWidth, xrayHeight)); //保存图片 xrayBM.Save(ImgXrayFilePath, System.Drawing.Imaging.ImageFormat.Jpeg); //释放资源 xrayBM.Dispose(); List listFilePath = new List(); listFilePath.Add(ImgFilePath); listFilePath.Add(ImgXrayFilePath); List list_ElementInfo = control_XRayTable1.List_ShowElementInfo; //1.编辑信息 DataTable dt = new DataTable(); dt.Columns.Add("元素名称"); dt.Columns.Add("原子数"); dt.Columns.Add("质量百分比"); dt.Columns.Add("摩尔比"); foreach (var item in list_ElementInfo) { //获取摩尔比与原子数 CElementChemistry cElementChemistry = new CElementChemistry(); cElementChemistry.SetName(item.ElementName); cElementChemistry.SetPercentage(item.Percentage); double molarValue = Math.Round(cElementChemistry.GetMolarPercentage(), 2); int atomNum = (int)CElement.GetAtomicNum(item.ElementName); DataRow dr = dt.NewRow(); dr[0] = item.ElementName; dr[1] = atomNum; dr[2] = item.Percentage; dr[3] = molarValue; dt.Rows.Add(dr); } DataGridView dgv = new DataGridView(); dgv.DataSource = dt.DefaultView; List list_ElementData = new List(); list_ElementData.Add(dt); //将数据插入Excel中 return m_ImageData.InsertDataToExcelTable(list_ElementData, startupPath, listFilePath); } public void HideXRayTable() { panelXray.Visible = false; //清空元素标记对象 if (m_ElementPointGDIObjects != null) { if (m_ElementPointGDIObjects.Count > 0) { m_ElementPointGDIObjects.Clear(); } } } //在picturebox的鼠标按下事件里,记录三个变量. int xPos; int yPos; bool MoveFlag = false; private void pbBSEImage_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { if (e.Button == MouseButtons.Left) { //在线扫描未选中的情况下 设置移动标识与获取当前鼠标位置 if (!((System.Windows.Forms.ToolStripMenuItem)contextMenuStrip1.Items[(int)MeasureStateMenuType.MenuItemLineScam]).Checked) { MoveFlag = true;//已经按下. xPos = e.X;//当前x坐标. yPos = e.Y;//当前y坐标. } } } //在picturebox的鼠标按下事件里. private void pbBSEImage_MouseUp(object sender, MouseEventArgs e) { MoveFlag = false; } //在picturebox鼠标移动 private void pbBSEImage_MouseMove(object sender, MouseEventArgs e) { if (MoveFlag) { pbBSEImage.Left = Convert.ToInt32(e.X - xPos);//设置x坐标. pbBSEImage.Top = Convert.ToInt32(e.Y - yPos);//设置y坐标. } } //在picturebox鼠标缩放 private void pbBSEImage_MouseWheel(object sender, MouseEventArgs e) { //鼠标滚动缩放 BSE图 if (e.Delta > 0) { if (m_CurrentMultiple < m_MaxMultipleRange) { m_CurrentMultiple += Convert.ToSingle(m_Multiple.ToString("f2")); pbBSEImage.Width += Convert.ToInt32(m_iWidth * m_Multiple); pbBSEImage.Height += Convert.ToInt32(m_iHeight * m_Multiple); WheelElementPointGDIObjects(e.Location,m_CurrentMultiple); } } else { m_CurrentMultiple -= Convert.ToSingle(m_Multiple.ToString("f2")); if (m_CurrentMultiple > 0) { pbBSEImage.Width -= Convert.ToInt32(m_iWidth * m_Multiple); pbBSEImage.Height -= Convert.ToInt32(m_iHeight * m_Multiple); } else { m_CurrentMultiple = 0; pbBSEImage.Height = this.RestoreBounds.Height; pbBSEImage.Width = this.RestoreBounds.Height * 4 / 3; pbBSEImage.Left = 0; pbBSEImage.Top = 0; Rectangle rectangle = GetPictureBoxZoomSize(pbBSEImage); Point sizeChangePoint = rectangle.Location; //修改窗体宽度后,设置单点采集的位置 if (m_ElementPointGDIObjects != null) { if (m_ElementPointGDIObjects.Count > 0) { if (m_GetBSEImageInitPoint != sizeChangePoint) { int sizeChangeX = sizeChangePoint.X - m_GetBSEImageInitPoint.X; int sizeChangeY = sizeChangePoint.Y - m_GetBSEImageInitPoint.Y; RectangleF sizeChangeRectF = m_ElementPointGDIObjects[0].GetZoomedRegionF(); sizeChangeRectF.X = m_ElementPointGDIObjects[0].GetZoomedRegionF().X + sizeChangeX; m_ElementPointGDIObjects[0].SetInitRegionF(sizeChangeRectF); //m_ElementPointGDIObjects[0].DrawRegionF = sizeChangeRectF; m_GetBSEImageInitPoint = sizeChangePoint; } } } } WheelElementPointGDIObjects(e.Location,m_CurrentMultiple); } } /// /// 缩放时改变 单点标识位置 /// /// public void WheelElementPointGDIObjects(Point refPoint,float CurrentMultiple) { if (m_ElementPointGDIObjects.Count > 0) { foreach (CRectangleGDIObject item in m_ElementPointGDIObjects) { //RectangleF rectF = new RectangleF(); //rectF.X = item.GetZoomedRegionF().X + Convert.ToSingle(dMouseImgX) * m_CurrentMultiple; //rectF.Y = item.GetZoomedRegionF().Y + Convert.ToSingle(dMouseImgY) * m_CurrentMultiple; ////改变位置 //RectangleF elementPointRctF = new RectangleF(); //elementPointRctF.X = rectF.X; //elementPointRctF.Y = rectF.Y; //item.SetScaleRegionF(elementPointRctF); item.Zoom(refPoint, CurrentMultiple); } } } private void button1_Click(object sender, EventArgs e) { COTSSample cSample = m_MeasureAppForm.m_ProjParam.GetWorkSample(); int start = cSample.GetMsrParams().GetImageProcessParam().GetBGGray().GetStart(); int end = cSample.GetMsrParams().GetImageProcessParam().GetBGGray().GetEnd(); Image bInput = pbBSEImage.Image; List colorMapTemp = new List(); for (int i = start; i <= end; i++) { ColorMap colorMap = new ColorMap(); string colorName = "#" + Color.FromArgb(i, i, i).Name.ToString(); colorMap.OldColor = ColorTranslator.FromHtml(colorName); colorMap.NewColor = Color.Red; colorMapTemp.Add(colorMap); } Bitmap outBitmap = new Bitmap(bInput); //创建Graphics对象 Graphics g = Graphics.FromImage(outBitmap); //生成的图像大小 int width = bInput.Width; int height = bInput.Height; //编辑被着急图像所要显示的位置 Rectangle DrawRect = new Rectangle(0, 0, 1024, 768); //编辑输出画布中着色的位置 Rectangle ShowRect = new Rectangle(0, 0, 1024, 768); ImageAttributes attr = new ImageAttributes(); attr.SetRemapTable(colorMapTemp.ToArray()); //从输入图像中截图至临时图像中 g.DrawImage(bInput, ShowRect, 0, 0, DrawRect.Width, DrawRect.Height, GraphicsUnit.Pixel, attr); pbBSEImage.Image = outBitmap; } private void OTSMeasureStatusWindow_MouseClick(object sender, MouseEventArgs e) { try { if (e.Button == MouseButtons.Right && e.Clicks == 1) { contextMenuStrip1.Show(); contextMenuStrip1.Show(PointToScreen(e.Location)); SetContentMenu(); } } catch (Exception ex) { log.Error("(OTSMeasureStatusWindow.OTSMeasureStatusWindow_MouseClick) " + ex.ToString()); } } private void ViewStripMenuItem_Click(object sender, EventArgs e) { if (m_iWidth == 0 || m_iHeight == 0) { string str = m_MeasureAppForm.m_ProjParam.GetBSEImageResolution();// 举例:1024X768 string[] sArray = str.Split('X'); if (sArray[0] != "" && sArray[1] != "") { m_iWidth = Convert.ToInt32(sArray[0]); m_iHeight = Convert.ToInt32(sArray[1]); } } ToolWindow toolWindow = new ToolWindow(m_MeasureAppForm, this); int grayStart = 0; int grayEnd = 0; if (bBseData != null) { Bitmap bitmap = CImageHandler.ToGrayBitmap(bBseData, m_iWidth, m_iHeight); toolWindow.BseImg = bitmap; toolWindow.BBseData = bBseData; //获取去背景灰度值 grayStart = m_MeasureAppForm.m_ProjParam.GetWorkSample().GetMsrParams().GetImageProcessParam().GetBGGray().GetStart(); grayEnd = m_MeasureAppForm.m_ProjParam.GetWorkSample().GetMsrParams().GetImageProcessParam().GetBGGray().GetEnd(); //设置可视化中的属性 toolWindow.BseGrayMinValue = grayStart; toolWindow.BseGrayMaxValue = grayEnd; } DialogResult dialogResult = toolWindow.ShowDialog(); if (dialogResult == DialogResult.Yes) { //获取去背景参数 grayStart = toolWindow.BseGrayMinValue; grayEnd = toolWindow.BseGrayMaxValue; //设置去背景参数 COTSImageProcParam cOTSImgProc = new COTSImageProcParam(); cOTSImgProc = m_MeasureAppForm.m_ProjParam.GetResultData().GetWorkingSample().GetMsrParams().GetImageProcessParam(); CIntRange cIntRange = new CIntRange(); cIntRange.SetStart(grayStart); cIntRange.SetEnd(grayEnd); cOTSImgProc.SetBGGray(cIntRange); m_MeasureAppForm.m_ProjParam.GetResultData().GetWorkingSample().GetMsrParams().SetImageProcessParam(cOTSImgProc); //更新属性窗口 m_MeasureAppForm.UpdatePropertyVal(); //确认后进行去背景 ShowRemoveBGImage(); return; } } private void toolStripMenuItem1_Click(object sender, EventArgs e) { if (m_iWidth == 0 || m_iHeight == 0) { string str = m_MeasureAppForm.m_ProjParam.GetBSEImageResolution();// 举例:1024X768 string[] sArray = str.Split('X'); if (sArray[0] != "" && sArray[1] != "") { m_iWidth = Convert.ToInt32(sArray[0]); m_iHeight = Convert.ToInt32(sArray[1]); } } SpecialParticleForm specialParticleForm = new SpecialParticleForm(CSpecialGrayRangeParam.GetParamFileFullName(), m_MeasureAppForm, bBseData, m_iWidth, m_iHeight,this); DialogResult dialogResult = specialParticleForm.ShowDialog(); } } }