123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- 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<Particle> SelectedParticles;
- ResultFile resultFile;
- int nBrukerDwellTime = 0;
- private delegate void DelSetPro(string txt, RichTextBox richTextBox);//设置进度条进度的委托方法
- /// <summary>
- /// 设置进度。
- /// </summary>
- /// <param name="pro"></param>
- /// <param name="proBar"></param>
- 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的尾部上
- /// <summary>
- /// 将文本追加到RictBox的尾部上
- /// </summary>
- 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<Particle> 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<string, object> sampleMembers = ((Dictionary<string, object>)((Dictionary<string, object>)resultFile.ResultInfo["Sample"])["Members"]);
- Dictionary<string, object> SEMDataMsr = (Dictionary<string, object>)((Dictionary<string, object>)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<string, object> sampleMembers = ((Dictionary<string, object>)((Dictionary<string, object>)resultFile.ResultInfo["Sample"])["Members"]);
- Dictionary<string, object> imageScanParam = (Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)sampleMembers["MsrParams"])["Members"])["ImageScanParam"];
- string ImageResolution = imageScanParam["ImageResolution"].ToString();
- int width = int.Parse(ImageResolution.Split('_')[1]);
- int height = int.Parse(ImageResolution.Split('_')[2]);
- Dictionary<string, object> SEMStageData = (Dictionary<string, object>)resultFile.ResultInfo["SEMStageData"];
- string ScanFieldSize = SEMStageData["scanFieldSize"].ToString();
- string leftOrRight = SEMStageData["xAxisDir"].ToString().Split('_')[0];
- string downOrUp = SEMStageData["yAxisDir"].ToString().Split('_')[0];
- #region 按帧图分类
- //Dictionary<int, List<Particle>> keyValues = new Dictionary<int, List<Particle>>();
- //ParticleList.OrderBy(a => a.FieldId).ToList();
- //for (int i = 0; i < ParticleList.Count; i++)
- //{
- // if (keyValues.ContainsKey(ParticleList[i].FieldId))
- // {
- // List<Particle> Particles = keyValues[ParticleList[i].FieldId];
- // Particles.Add(ParticleList[i]);
- // keyValues[ParticleList[i].FieldId] = Particles;
- // }
- // else
- // {
- // List<Particle> Particles = new List<Particle>();
- // 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;
- }
- }
- }
- }
|