using OTSDataType; using OTSCommon.Model; using OTSMeasureApp; using OTSModelSharp.ResourceManage; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using OTSIncAReportGrids.OTSIncAReportGridsFuncation; using System.Threading; using static OTSDataType.otsdataconst; using OTSModelSharp.ServiceCenter; namespace OTSIncAReportApp._1_UI { public partial class frmReMeasure : Form { OTSReportGridsFun m_OTSIncAReportGridsFun; List SelectedParticles; ResultFile resultFile; int nBrukerDwellTime = 0; private delegate void DelSetPro(string txt, RichTextBox richTextBox);//设置进度条进度的委托方法 /// /// 设置进度。 /// /// /// private void SetProgressMessage(string txt, RichTextBox richTextBox) { //如果当前调用方不是创建控件的一方,则需要使用this.Invoke() //在这里,ProgressBar控件是由主线程创建的,所以子线程要对该控件进行操作 //必须执行this.InvokeRequired进行判断。 if (this.InvokeRequired) { DelSetPro setPro = new DelSetPro(SetProgressMessage); this.Invoke(setPro, new object[] { txt, richTextBox }); } else { WriteRictBox(txt); } } #region 将文本追加到RictBox的尾部上 /// /// 将文本追加到RictBox的尾部上 /// public void WriteRictBox(string in_str) { //追加到rictbox尾部 richTextBox_process.AppendText("[" + DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Second.ToString() + "]" + in_str + Environment.NewLine); richTextBox_process.ScrollToCaret(); } #endregion public frmReMeasure(OTSReportGridsFun m_OTSIncAReportGridsFun, List SelectedParticles, ResultFile resultFile) { InitializeComponent(); this.m_OTSIncAReportGridsFun = m_OTSIncAReportGridsFun; this.SelectedParticles = SelectedParticles; this.resultFile = resultFile; } private void frmReMeasure_Load(object sender, EventArgs e) { //图像扫描精度 IDC_COMBO_IMGSCANSPEED.Items.Clear(); foreach (otsdataconst.OTS_IMAGE_SCANSPEED_OPTIONS enum_one in Enum.GetValues(typeof(otsdataconst.OTS_IMAGE_SCANSPEED_OPTIONS))) { ComboBoxItem cbi = new ComboBoxItem(); cbi.Text = GetScanSpeedString(enum_one); cbi.Value = (int)enum_one; IDC_COMBO_IMGSCANSPEED.Items.Add(cbi); } IDC_COMBO_IMGSCANSPEED.SelectedIndex = (int)otsdataconst.OTS_IMAGE_SCANSPEED_OPTIONS.high; //X-Ray扫描方式 IDC_COMBO_XRAYSCANMODE.Items.Clear(); foreach (otsdataconst.OTS_X_RAY_SCAN_MODE enum_one in Enum.GetValues(typeof(otsdataconst.OTS_X_RAY_SCAN_MODE))) { ComboBoxItem cbi = new ComboBoxItem(); cbi.Text = GetXRayScanModeIdString(enum_one); cbi.Value = (int)enum_one; IDC_COMBO_XRAYSCANMODE.Items.Add(cbi); } IDC_COMBO_XRAYSCANMODE.SelectedIndex = (int)otsdataconst.OTS_X_RAY_SCAN_MODE.PointMode; //旧放大倍数 Dictionary sampleMembers = ((Dictionary)((Dictionary)resultFile.ResultInfo["Sample"])["Members"]); Dictionary SEMDataMsr = (Dictionary)((Dictionary)sampleMembers["SEMDataMsr"]); double ScanFieldSize = double.Parse(SEMDataMsr["ScanFieldSize"].ToString()); double ScanFieldSize100 = double.Parse(SEMDataMsr["ScanFieldSize100"].ToString()); double oldMag = Math.Round((ScanFieldSize100 / ScanFieldSize) * 100, 2); LB_OLDMAGVALUE.Text = oldMag.ToString(); NUD_MAG.Minimum = (decimal)oldMag; NUD_MAG.Value = (decimal)(oldMag * 2); } public string GetScanSpeedString(otsdataconst.OTS_IMAGE_SCANSPEED_OPTIONS a_nScanSpeed) { string strScanSpeedId = ""; if (a_nScanSpeed >= otsdataconst.OTS_IMAGE_SCANSPEED_OPTIONS.low && a_nScanSpeed <= otsdataconst.OTS_IMAGE_SCANSPEED_OPTIONS.high) { strScanSpeedId = XmlResourceData.GetInstance().GetStringByKey(ResourceID.GrpOtherParam, ResourceID.IDS_SCANSPEED + (int)a_nScanSpeed); } return strScanSpeedId; } public static string GetXRayScanModeIdString(otsdataconst.OTS_X_RAY_SCAN_MODE a_nXRayScanMode) { string strXRayScanModeId = ""; if (a_nXRayScanMode >= otsdataconst.OTS_X_RAY_SCAN_MODE.PointMode && a_nXRayScanMode <= otsdataconst.OTS_X_RAY_SCAN_MODE.FeatureMode) { strXRayScanModeId = XmlResourceData.GetInstance().GetStringByKey(ResourceID.GrpOtherParam, ResourceID.IDS_XRAYSCANMODE + (int)a_nXRayScanMode); } return strXRayScanModeId; } private void BTN_NO_Click(object sender, EventArgs e) { this.Close(); } private void BTN_YES_Click(object sender, EventArgs e) { //参数定义 int nBrukerDwellTimeId = 3; switch (IDC_COMBO_IMGSCANSPEED.SelectedIndex) { case (int)OTS_IMAGE_SCANSPEED_OPTIONS.low: nBrukerDwellTimeId = 3; break; case (int)OTS_IMAGE_SCANSPEED_OPTIONS.meddium: nBrukerDwellTimeId = 4; break; case (int)OTS_IMAGE_SCANSPEED_OPTIONS.high: nBrukerDwellTimeId = 5; break; default: nBrukerDwellTimeId = 3; break; } nBrukerDwellTime = DWELLTIME_BRUKER_VALUES[nBrukerDwellTimeId]; bgw_process.RunWorkerAsync(); } private Point GetPartPoint(string leftOrRight, string downOrUp, string ScanFieldSize, Particle particle) { Point point = new Point(); if (leftOrRight == "RIGHT") { point.X = particle.SEMPosX - int.Parse(ScanFieldSize) / 2 + particle.PosX; } else { point.X = particle.SEMPosX + int.Parse(ScanFieldSize) / 2 + particle.PosX; } if (downOrUp == "UP") { point.Y = particle.SEMPosY + int.Parse(ScanFieldSize) / 2 + particle.PosY; } else { point.Y = particle.SEMPosY - int.Parse(ScanFieldSize) / 2 + particle.PosY; } return point; } private void bgw_process_DoWork(object sender, DoWorkEventArgs e) { //颗粒信息 Dictionary sampleMembers = ((Dictionary)((Dictionary)resultFile.ResultInfo["Sample"])["Members"]); Dictionary imageScanParam = (Dictionary)((Dictionary)((Dictionary)sampleMembers["MsrParams"])["Members"])["ImageScanParam"]; string ImageResolution = imageScanParam["ImageResolution"].ToString(); int width = int.Parse(ImageResolution.Split('_')[1]); int height = int.Parse(ImageResolution.Split('_')[2]); Dictionary SEMStageData = (Dictionary)resultFile.ResultInfo["SEMStageData"]; string ScanFieldSize = SEMStageData["scanFieldSize"].ToString(); string leftOrRight = SEMStageData["xAxisDir"].ToString().Split('_')[0]; string downOrUp = SEMStageData["yAxisDir"].ToString().Split('_')[0]; #region 按帧图分类 //Dictionary> keyValues = new Dictionary>(); //ParticleList.OrderBy(a => a.FieldId).ToList(); //for (int i = 0; i < ParticleList.Count; i++) //{ // if (keyValues.ContainsKey(ParticleList[i].FieldId)) // { // List Particles = keyValues[ParticleList[i].FieldId]; // Particles.Add(ParticleList[i]); // keyValues[ParticleList[i].FieldId] = Particles; // } // else // { // List Particles = new List(); // Particles.Add(ParticleList[i]); // keyValues.Add(ParticleList[i].FieldId, Particles); // } //} #endregion //第一步,连接电镜 m_OTSIncAReportGridsFun.Connection_ForParticlesGrid(); Thread.Sleep(500); SetProgressMessage("设置放大倍数", richTextBox_process); if (!m_OTSIncAReportGridsFun.SetMagnification((double)NUD_MAG.Value)) { SetProgressMessage("设置放大倍数失败", richTextBox_process); } for (int i = 0; i < SelectedParticles.Count; i++) { SetProgressMessage("开始处理颗粒:" + (i + 1), richTextBox_process); if (m_OTSIncAReportGridsFun.m_SEMConnectionState == true) { Point point = GetPartPoint(leftOrRight, downOrUp, ScanFieldSize, SelectedParticles[i]); SetProgressMessage("移动到颗粒中心位置", richTextBox_process); if (!m_OTSIncAReportGridsFun.MoveSemToPointXY_ForParticlesGrid(point.X, point.Y)) { SetProgressMessage("移动到颗粒中心位置失败", richTextBox_process); } SetProgressMessage("拍图", richTextBox_process); byte[] ImageByte = new byte[width * height]; if (!m_OTSIncAReportGridsFun.AcquireBSEImage(width, height, nBrukerDwellTime, ref ImageByte)) { SetProgressMessage("拍图失败", richTextBox_process); } bgw_process.ReportProgress(0, CImageHandler.ToGrayBitmap(ImageByte, width, height)); SetProgressMessage("寻找新位置颗粒信息", richTextBox_process); if (!m_OTSIncAReportGridsFun.AcquireBSEImage(width, height, nBrukerDwellTime, ref ImageByte)) { SetProgressMessage("拍图失败", richTextBox_process); } } } Thread.Sleep(500); } private void bgw_process_ProgressChanged(object sender, ProgressChangedEventArgs e) { switch (e.ProgressPercentage) { case 0: pictureBox_part.Image = (Bitmap)e.UserState; break; default: break; } } } }