1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801 |
- using OTS.WinFormsUI.Docking;
- using OTSCLRINTERFACE;
- using OTSDataType;
- using OTSIncAGraph.Controls;
- using OTSMeasureApp._0_OTSModel.OTSDataType;
- using OTSModelSharp;
- using OTSModelSharp.ServiceCenter;
- using OTSPeriodicTable;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.IO;
- using System.Reflection;
- using System.Windows.Forms;
- namespace OTSMeasureApp
- {
- public enum MeasureStateMenuType
- {
- //获取BSE图
- ReadBSEPic = 0,
- //设置可视化灰度
- SetVisualGray = 1,
- //显示BSE灰度曲线图
- SetVisualGrayForSpecialGray = 2,
- grayToolStripMenuItem = 3,
- //切换至BSE图
- ChangeDiffImageShow = 4,
- //BSE去背景图
- DelBSEBG = 5,
- ColoredBSENoBG = 6,
- //显示BSE去背景灰度曲线图
- SampleHoleBSEImage = 7,
- //线扫描曲线
- MenuItemLineScam = 8,
- //单点采集Xray与元素信息
- PointScanElementMenuItem = 9,
- BatchCollectXray = 10,
- //导出采集信息报告
- ExportReport = 11
- }
- public partial class OTSMeasureStatusWindow : DockContent
- {
- class CrossSign
- {
- public Point position;
- private OTSMeasureStatusWindow mywin;
- public CrossSign(int x, int y, OTSMeasureStatusWindow win)
- {
- position = new Point(x, y);
- mywin = win;
- }
- public void OnPaint(PaintEventArgs e)
- {
- System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Green);
- e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
- e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
- e.Graphics.CompositingQuality = CompositingQuality.HighQuality;//再加一点
- Pen pen = new Pen(sampleBrush, 2f);
- var picboxPos = GetPocboxPosByImagePos(position.X, position.Y);
- int X = picboxPos.X;
- int Y = picboxPos.Y;
- e.Graphics.DrawLine(pen, new Point(X - 8, Y), new Point(X + 8, Y));
- e.Graphics.DrawLine(pen, new Point(X, Y - 8), new Point(X, Y + 8));
- }
- private Point GetPocboxPosByImagePos(int x, int y)
- {
- var rectangle = mywin.ImgZoomRectangle;
- double x1 = x;
- double y1 = y;
- var picX = x1 / mywin.GetIWidth() * rectangle.Width + rectangle.X;
- var picY = y1 / mywin.GetIHeight() * rectangle.Height + rectangle.Y;
- return new Point((int)picX, (int)picY);
- }
- }
- #region 全部变量
- public OTSIncAMeasureAppForm m_MeasureAppForm;
- int m_iWidth = 0;
- int m_iHeight = 0;
- public byte[] originalBseData;
- //去背景图
- private byte[] removeBGBseData;
- private Bitmap coloredParticleImage;
- //绘制采集点对象
- private static List<CrossSign> m_ElementPointGDIObjects = new List<CrossSign>();
- float m_ZoomRecord = 1;
- float m_ZoomCoefficient = 0.2f;
- int m_MaxZoom = 12;
- NLog.Logger log;
- //国际化
- OTSCommon.Language lan;
- #endregion
- #region 在右下角状态栏中显示鼠标当前位置所需要的参数
- private COTSField myFld;
- private CBSEImgClr originalBse;
- Rectangle originalImgRectangle;
- private RectangleF ImgZoomRectangle = new RectangleF();
- #endregion
- public enum ImageType
- {
- //BSE图
- BSEImage = 0,
- //去背景图
- RemoveBGImage = 1,
- //线扫描曲线
- GrayLevelLineScan = 2,
- //
- ColorParticleImage = 3
- }
- //图bfResult
- public static bool bfResult = false;
- //当前默认值
- ImageType m_imagetype = ImageType.BSEImage;
- public OTSMeasureStatusWindow(OTSIncAMeasureAppForm MeasureApp)
- {
- InitializeComponent();
- m_MeasureAppForm = MeasureApp;
- //进入时首先对XRayTable进行隐藏
- panelXray.Visible = false;
- lan = new OTSCommon.Language(this);
- }
- public void ShowSingleImage(Bitmap bmpImage)
- {
- picBox.Image = bmpImage;
- //设置Pictrue显示位置
- picBox.Height = this.RestoreBounds.Height;
- picBox.Width = this.RestoreBounds.Width;
- //获取黄线坐标位置
- originalImgRectangle = GetPictureBoxImageSize(picBox);
- pointStart.X = originalImgRectangle.X;
- pointEnd.X = originalImgRectangle.X + originalImgRectangle.Width;
- pointStart.Y = originalImgRectangle.Y + (originalImgRectangle.Height) / 2;
- pointEnd.Y = originalImgRectangle.Y + (originalImgRectangle.Height) / 2;
- picBox.Left = 0;
- picBox.Top = 0;
- picBox.Show();
- ImgZoomRectangle.Width = originalImgRectangle.Width;
- ImgZoomRectangle.Height = originalImgRectangle.Height;
- ImgZoomRectangle.X = originalImgRectangle.X;
- ImgZoomRectangle.Y = originalImgRectangle.Y;
- pictureBox2.Visible = false;
- }
- public void ShowDoubleImage(Bitmap image1, Bitmap image2)
- {
- if (image1 != null)
- {
- picBox.Image = image1;
- }
- //设置Pictrue显示位置
- picBox.Height = this.RestoreBounds.Height;
- picBox.Width = this.RestoreBounds.Width / 2;
- //获取黄线坐标位置
- originalImgRectangle = GetPictureBoxImageSize(picBox);
- pointStart.X = originalImgRectangle.X;
- pointEnd.X = originalImgRectangle.X + originalImgRectangle.Width;
- pointStart.Y = originalImgRectangle.Y + (originalImgRectangle.Height) / 2;
- pointEnd.Y = originalImgRectangle.Y + (originalImgRectangle.Height) / 2;
- ImgZoomRectangle.Width = originalImgRectangle.Width;
- ImgZoomRectangle.Height = originalImgRectangle.Height;
- ImgZoomRectangle.X = originalImgRectangle.X;
- ImgZoomRectangle.Y = originalImgRectangle.Y;
- picBox.Left = 0;
- picBox.Top = 0;
- picBox.Show();
- if (image2 != null)
- {
- pictureBox2.Image = image2;
- }
- pictureBox2.Height = this.RestoreBounds.Height;
- pictureBox2.Width = this.RestoreBounds.Width / 2;
- pictureBox2.Left = this.RestoreBounds.Width / 2;
- pictureBox2.Top = 0;
- pictureBox2.Show();
- }
- //显示扫描曲线图方法
- #region 显示扫描曲线图方法
- private void DrawCurve(byte[] buf, Graphics g)
- {
- //创建位图
- Rectangle rectangle = GetPictureBoxImageSize(picBox);
- double rate = (double)rectangle.Height / (double)picBox.Image.Height;
- Pen mypenYellow = new Pen(Color.Yellow, 0.001f);//点颜色
- int len = buf.Length;
- PointF[] CurvePointF = new PointF[len];//坐标点
- float pointX = 0;
- float pointY = 0;
- for (int i = 0; i < buf.Length; i++)
- {
- pointX = (picBox.Width - rectangle.Width) / 2 + Convert.ToSingle(i * rate);
- float imagei = (int)GrayLevel.Max - Convert.ToInt32(buf[i]);
- float imagerate = (Convert.ToSingle(Convert.ToDouble(rectangle.Height) / 510));
- pointY = imagei * imagerate + (rectangle.Height) / 4 + rectangle.Top;
- CurvePointF[i] = new PointF(pointX, pointY);
- }
- float Tension = 0.001f;
- g.DrawCurve(mypenYellow, CurvePointF, Tension);//画曲线
- }
- #endregion
- //处理获取调试图菜单事件
- #region 处理获取调试图菜单事件
- private void AcquireBSEImage_Click(object sender, EventArgs e)
- {
- m_ElementPointGDIObjects.Clear();
- bool rst = AcquireBSEImage();
- //取图不成功就返回
- if (rst)
- {
- bfResult = true;
- }
- if (!rst)
- {
- if (contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Enabled == true)
- {
- contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Enabled = false;
- }
- //显示单点扫描元素信息菜单
- contextMenuStrip1.Items[(int)MeasureStateMenuType.PointScanElementMenuItem].Enabled = false;
- picBox.Hide();
- return;
- }
- else
- {
- //显示单点扫描元素信息菜单
- SetContextMenuEnabled(true);
- }
- m_imagetype = ImageType.BSEImage;
- Bitmap bitmap = CImageHandler.ToGrayBitmap(originalBseData, GetIWidth(), GetIHeight());
- ShowSingleImage(bitmap);
- m_ZoomRecord = 1;
- picBox.Height = this.RestoreBounds.Height;
- picBox.Left = 0;
- picBox.Top = 0;
- panelXray.Visible = false;
- }
- /// <summary>
- /// 获取BSE图方法
- /// </summary>
- private bool AcquireBSEImage()
- {
- //建立图像数据
- originalBseData = new byte[GetIWidth() * GetIHeight()];
- //获取图像数据
- DwellTimeLevel nDwellTime = DwellTimeLevel.Low;
- try
- {
- int level = (int)m_MeasureAppForm.m_ProjParam.GetResultData().GetWorkingSample().GetMsrParams().GetImageScanParam().GetScanImageSpeed();
- switch (level)
- {
- case 0:
- nDwellTime = DwellTimeLevel.Low;
- break;
- case 1:
- nDwellTime = DwellTimeLevel.Medium;
- break;
- case 2:
- nDwellTime = DwellTimeLevel.High;
- break;
- }
- }
- catch (Exception)
- {
- nDwellTime = DwellTimeLevel.Low;
- }
- CBSEImgClr img;
- bool rst = GetScanImage(GetIWidth(), GetIHeight(), nDwellTime, out img);
- originalBse = img;
- originalBseData = img.GetImageDataPtr();
- myFld = new COTSField();
- myFld.SetBSEImage(img);
- myFld.Sample = m_MeasureAppForm.m_ProjParam.GetResultData().GetWorkingSample();
- return rst;
- }
- private void UpdateImageAndLineScanChart()
- {
- m_imagetype = ImageType.GrayLevelLineScan;
- Bitmap bitmap = CImageHandler.ToGrayBitmap(originalBseData, GetIWidth(), GetIHeight());
- ShowSingleImage(bitmap);
- picBox.Refresh();
- }
- public bool GetScanImage(int iWidth, int iHeight, DwellTimeLevel iDwellTime, out CBSEImgClr bseImg)
- {
- //电镜设置对象
- IScanController cfun = ScanController.GetScanController();
- ISemController sem = SemController.GetSEMController();
- try
- {
- //连接电镜
- bool IsConnec = cfun.Init();
- if (!IsConnec)
- {
- string strErrorInfo = "(OTSBSEImageFun.GetScanImage) cfun.ConncetSem() = false Failed";
- log.Error(strErrorInfo);
- bseImg = null;
- return false;
- }
- cfun.SetImageSize(iWidth, iHeight);
- cfun.SetDwellTime(iDwellTime);
- var bse = cfun.AcquireBSEImage();
- bseImg = bse;
- sem.SetScanExternal(false);
- }
- catch (Exception ex)
- {
- log.Error(ex.Message.ToString());
- bseImg = null;
- return false;
- }
- return true;
- }
- #endregion
- //显示去背景图 = AUTO
- #region 显示去背景图
- private void ShowRemoveBGImage_Click(object sender, EventArgs e)
- {
- //设置右键菜单中的项 是否可编辑
- SetContextMenuEnabled(true);
- m_imagetype = ImageType.RemoveBGImage;
- ShowRemoveBGImage();
- panelXray.Visible = false;
- }
- protected void ShowRemoveBGImage()
- {
- //获取图像数据
- COTSSample WSample = m_MeasureAppForm.m_ProjRstData.GetWorkingSample();
- double pixelSize = WSample.CalculatePixelSize();
- var imageProcessParam = WSample.GetMsrParams().GetImageProcessParam();
- var imageHandle = new CImageHandler();
- myFld = new COTSField(new Point(0, 0), pixelSize);
- myFld.SetBSEImage(originalBse);
- myFld.Sample = WSample;
- bfResult = imageHandle.GetBSEImage(myFld, imageProcessParam, pixelSize, GetIWidth(), GetIHeight(), ref removeBGBseData);
- //取图不成功就返回
- if (!bfResult) { return; }
- Bitmap bitmap = CImageHandler.ToGrayBitmap(removeBGBseData, GetIWidth(), GetIHeight());
- ShowDoubleImage((Bitmap)picBox.Image, bitmap);
- //切换显示至BSE图
- contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Enabled = true;
- }
- protected void ShowColoredRemoveBGImage()
- {
- //获取图像数据
- COTSSample WSample = m_MeasureAppForm.m_ProjRstData.GetWorkingSample();
- double pixelSize = WSample.CalculatePixelSize();
- var imageProcessParam = WSample.GetMsrParams().GetImageProcessParam();
- var imageHandle = new CImageHandler();
- coloredParticleImage = new Bitmap(GetIWidth(), GetIHeight());
- myFld = new COTSField(new Point(0, 0), pixelSize);
- myFld.SetBSEImage(originalBse);
- myFld.Sample = WSample;
- CBSEImgClr pImgNoBG = new CBSEImgClr(new Rectangle(0, 0, GetIWidth(), GetIHeight()));
- bfResult = imageHandle.GetColoredImage(myFld, imageProcessParam, pixelSize, GetIWidth(), GetIHeight(), ref pImgNoBG, ref coloredParticleImage);
- removeBGBseData = pImgNoBG.GetImageDataPtr();
- //取图不成功就返回
- if (!bfResult) { return; }
- ShowDoubleImage((Bitmap)picBox.Image, coloredParticleImage);
- picBox.Show();
- //切换显示至BSE图
- contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Enabled = true;
- }
- #endregion
- //显示线扫描曲线
- #region 显示线扫描曲线
- private void ShowLineScanChart_Click(object sender, EventArgs e)
- {
- ShowSingleImage((Bitmap)picBox.Image);
- if (MenuItemLineScan.Checked)
- {
- m_imagetype = ImageType.GrayLevelLineScan;
- timer1.Enabled = true;
- }
- else
- {
- m_imagetype = ImageType.BSEImage;
- timer1.Enabled = false;
- }
- }
- #endregion
- static Rectangle GetPictureBoxImageSize(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);
- }
- private void SetDoubleBufferByIsDraw()
- {
- SetStyle(ControlStyles.UserPaint, true); //没什么效果,开与关
- SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景,关了闪
- SetStyle(ControlStyles.OptimizedDoubleBuffer, true); // 双缓冲,关了闪
- //上面是必须有的
- SetStyle(ControlStyles.UserMouse, true); //执行自己的鼠标行为,这个打开后,在win7下鼠标操作明显改善
- }
- private void OTSMeasureStatusWindow_Load(object sender, EventArgs e)
- {
- SetDoubleBufferByIsDraw();
- this.control_XRayTable1 = new Control_XRayTable();
- this.panelXray.Controls.Add(this.control_XRayTable1);
- picBox.MouseClick += new MouseEventHandler(HiddenXrayTablePanel_MouseClick);
- pictureBox2.MouseClick += new MouseEventHandler(HiddenXrayTablePanel_MouseClick);
- this.picBox.MouseUp += new MouseEventHandler(this.pbBSEImage_MouseUp);
- this.pictureBox2.MouseUp += new MouseEventHandler(this.pbBSEImage_MouseUp);
- this.picBox.MouseWheel += new MouseEventHandler(this.pbBSEImage_MouseWheel);
- this.pictureBox2.MouseWheel += new MouseEventHandler(this.pbBSEImage_MouseWheel);
- //设置右键菜单中的项 是否可编辑
- SetContextMenuEnabled(true);
- log = NLog.LogManager.GetCurrentClassLogger();
- }
- private void HiddenXrayTablePanel_MouseClick(object sender, MouseEventArgs e)
- {
- if (e.Button != MouseButtons.Right)
- {
- if (m_ElementPointGDIObjects.Count > 0)
- {
- foreach (var item in m_ElementPointGDIObjects)
- {
- if (Math.Abs(e.Y - item.position.Y) < 5 && Math.Abs(e.X - item.position.X) < 5)
- {
- //显示Xray图像
- panelXray.Visible = true;
- }
- else
- {
- panelXray.Visible = false;
- }
- }
- }
- }
- }
- #region 设置右键菜单中的项 是否可编辑
- protected void SetContextMenuEnabled(bool isEnabled)
- {
- MenuItemLineScan.Enabled = true;
- PointScanElementMenuItem.Enabled = isEnabled;
- bool showExprot = m_ElementPointGDIObjects.Count > 0 ? true : false;
- ExportScanInfoMenuItem.Enabled = showExprot;
- VisualAdjustingMenu.Enabled = isEnabled;
- toolStripMenuItem1.Enabled = true;
- 批量采集ToolStripMenuItem.Enabled = true;
- this.Cursor = Cursors.Default;
- this.Validate();
- }
- #endregion
- #region 获取行数据
- private void GetLineImage(int iHeight, int iWidth, ref byte[] bdata)
- {
- Stream stream = null;
- stream = new MemoryStream(originalBseData);
- if (iHeight >= 0)
- {
- stream.Seek(iHeight * iWidth, SeekOrigin.Begin);
- }
- stream.Read(bdata, 0, iWidth);
- }
- #endregion
- private void contextMenuStrip1_Opened(object sender, EventArgs e)
- {
- if (bfResult)
- {
- SampleParaLock.Enabled = true;
- ToolStripMenuItem.Enabled = true;
- toolStripMenuItem2.Enabled = true;
- ChangeDiffImageShow.Enabled = true;
- PointScanElementMenuItem.Enabled = true;
- if (!MenuItemLineScan.Checked)
- {
- PointScanElementMenuItem.Enabled = true;
- ExportScanInfoMenuItem.Enabled = true;
- }
- else
- {
- PointScanElementMenuItem.Enabled = false;
- ExportScanInfoMenuItem.Enabled = false;
- return;
- }
- PointScanElementMenuItem.Enabled = true;
- bool showExprot = m_ElementPointGDIObjects.Count > 0 ? true : false;
- if (showExprot)
- {
- ExportScanInfoMenuItem.Enabled = true;
- }
- COTSSample WSample = m_MeasureAppForm.m_ProjRstData.GetWorkingSample();
- COTSImageProcParam ImgProcPrm = WSample.GetMsrParams().GetImageProcessParam();
- if (ImgProcPrm.GetBGRemoveType() == otsdataconst.OTS_BGREMOVE_TYPE.MANUAL)
- {
- VisualAdjustingMenu.Enabled = true;
- }
- else
- {
- VisualAdjustingMenu.Enabled = false;
- }
- }
- else
- {
- ToolStripMenuItem.Enabled = false;
- MenuItemLineScan.Enabled = false;
- }
- }
- //拖动灰度线
- #region 拖动灰度线
- int LineX = 0;
- int LineXEnd = 0;
- private Point pointStart = new Point(100, 100);
- private Point pointEnd = new Point(400, 100);
- //private bool m_bMouseDown = false;
- void DrawLineScan(PictureBox pic, Graphics g)
- {
- Rectangle rectangle = GetPictureBoxImageSize(pic);
- if (pointStart.Equals(pointEnd))
- {
- return;
- }
- double rate = (double)picBox.Image.Height / (double)rectangle.Height;
- //显示线扫描 黄色线的曲线数据
- var Imagedata = new byte[GetIWidth()];
- int YSize = Convert.ToInt32((rate * (double)pointStart.Y));
- GetLineImage(YSize, GetIWidth(), ref Imagedata);
- DrawCurve(Imagedata, g);
- g.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));
- g.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));
- g.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);
- g.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));
- g.DrawString(i.ToString(), font, solidBrush, rectangle.X + 20, (rectangle.Y + rectangle.Height * 3 / 4) - scaleLine - fontOffHeight, sf);
- }
- #endregion
- }
- private void pictureBox1_Paint(object sender, PaintEventArgs e)
- {
- if (!bfResult)
- {
- return;
- }
- if (picBox.Image == null)
- {
- return;
- }
- var g = e.Graphics;
- g.Clear(Color.Gainsboro);
- g.DrawImage(picBox.Image, ImgZoomRectangle);
- if (m_imagetype == ImageType.GrayLevelLineScan)
- {
- DrawLineScan(picBox, e.Graphics);
- }
- else
- {
- if (m_ElementPointGDIObjects != null)
- {
- if (m_ElementPointGDIObjects.Count > 0)
- {
- //绘制采集点标记
- foreach (CrossSign item in m_ElementPointGDIObjects)
- {
- if (item != null)
- {
- item.OnPaint(e);
- }
- }
- }
- }
- }
- }
- private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
- {
- if (m_MeasureAppForm.m_MsrThreadWrapper.BGWorkThreadIsRunning())
- {
- return;
- }
- //如果pictureBox1中没有图像 则return退出
- if (picBox.Image == null)
- {
- return;
- }
- if (MoveFlag)
- {
- ImgZoomRectangle.X = Convert.ToInt32(e.X + xbias);//设置x坐标.
- ImgZoomRectangle.Y = Convert.ToInt32(e.Y + ybias);//设置y坐标.
- }
- var imagepos = GetImagePosByPicBoxPos(e.X, e.Y);
- int startimageX = imagepos.X;
- int startimageY = imagepos.Y;
- //处理灰度值
- int grayValue = 0;
- if (originalBseData != null)
- {
- //如果当前鼠标在图像Y轴中
- if (startimageX >= 0 && startimageX < GetIWidth() && startimageY >= 0 && startimageY < GetIHeight())
- {
- var binPos = startimageX + (startimageY * GetIWidth());
- grayValue = originalBseData[binPos];
- }
- }
- string strGrayValue = " " + grayValue.ToString();
- //此处调接口显示灰度值
- m_MeasureAppForm.ShowGrayVal(strGrayValue.ToString());
- m_MeasureAppForm.ShowSemCoordvAL(imagepos.ToString());
- if (m_imagetype != ImageType.GrayLevelLineScan)
- {
- 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.position.Y) < 5 && Math.Abs(e.X - item.position.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);
- picBox.Refresh();
- pictureBox2.Refresh();
- }
- float xbias;
- float ybias;
- private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
- {
- if (!MenuItemLineScan.Checked)
- {
- xPos = e.X;//当前x坐标.
- yPos = e.Y;//当前y坐标.
- if (e.Button == MouseButtons.Left)
- {
- MoveFlag = true;
- this.Cursor = Cursors.Hand;
- xbias = ImgZoomRectangle.X - xPos;
- ybias = ImgZoomRectangle.Y - yPos;
- }
- }
- }
- #endregion
- private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Right && e.Clicks == 1)
- {
- var picBox = (PictureBox)sender;
- int XMenu = picBox.Left + e.Location.X;
- int YMenu = picBox.Top + e.Location.Y;
- Point mousePoint = new Point(XMenu, YMenu);
- contextMenuStrip1.Show(PointToScreen(mousePoint));
- SetContentMenu();
- }
- }
- private void ChangeDiffImageShow_Click(object sender, EventArgs e)
- {
- SetContextMenuEnabled(true);
- //显示BSE图
- if (originalBseData != null)
- {
- //用于线扫描曲线
- m_imagetype = ImageType.BSEImage;
- //在控件中显示图像
- Bitmap bitmap = CImageHandler.ToGrayBitmap(originalBseData, GetIWidth(), GetIHeight());
- ShowSingleImage(bitmap);
- }
- panelXray.Visible = false;
- }
- #region 设置测量状态初始化
- /// <summary>
- /// 设置测量状态初始化
- /// </summary>
- public void SetMeasureStatusInit()
- {
- picBox.Hide();
- foreach (ToolStripItem item in contextMenuStrip1.Items)
- {
- if (item != contextMenuStrip1.Items[(int)MeasureStateMenuType.ReadBSEPic])
- {
- item.Enabled = false;
- }
- }
- }
- #endregion
- #region 设置右键菜单项是否可用
- /// <summary>
- /// 设置右键菜单项是否可用
- /// </summary>
- 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;
- double bri = 0;
- double contra = 0;
- double kv = 0;
- m_MeasureAppForm.m_ProjParam.GetWorkingSampleSEMData(ref iWDistance, ref dMagni, ref bri, ref contra, ref kv);
- if (iWDistance != 0 && dMagni != 0 && bri != 0 && contra != 0)
- {
- contextMenuStrip1.Items[(int)MeasureStateMenuType.ReadBSEPic].Enabled = true;
- }
- }
- }
- #endregion
- private Point GetImagePosByPicBoxPos(int x, int y)
- {
- var rectangle = ImgZoomRectangle;
- double ratex = x - rectangle.X;
- var imageX = ratex / rectangle.Width * GetIWidth();
- double ratey = y - rectangle.Y;
- var imageY = ratey / rectangle.Height * GetIHeight();
- return new Point((int)imageX, (int)imageY);
- }
- private void 单点采集MenuItem_Click(object sender, EventArgs e)
- {
- MenuItemLineScan.Checked = false;
- //电镜设置对象
- //控制类对象初始化
- var expC = m_MeasureAppForm.m_ProjRstData.GetWorkingSample().GetMsrParams().GetXRayParam().GetAnalyExpCount();
- var ifautoid = m_MeasureAppForm.m_ProjRstData.GetWorkingSample().GetMsrParams().GetXRayParam().IfAutoId;
- var knownelements = m_MeasureAppForm.m_ProjRstData.GetWorkingSample().GetMsrParams().GetXRayParam().AnalysisElements;
- IEDSController m_EDSHardwareMgr = EDSController.GetEDSController(GetIWidth(), GetIHeight(), expC, ifautoid, knownelements);
- //1.连接电镜
- if (m_EDSHardwareMgr.Connect())
- {
- COTSMsrPrjResultData cProjMgr = m_MeasureAppForm.m_ProjParam.GetResultData();
- //获取工作样品对象
- COTSSample sampleClr = cProjMgr.GetWorkingSample();
- //清空之前记录的标识
- if (m_ElementPointGDIObjects != null)
- {
- if (m_ElementPointGDIObjects.Count > 0)
- {
- //清空
- m_ElementPointGDIObjects.Clear();
- }
- }
- var mousepos = GetImagePosByPicBoxPos(xPos, yPos);
- //3.根据所要扫描的位置进行元素分析
- uint a_Milliseconds = 0;
- //采集时间
- a_Milliseconds = Convert.ToUInt32(sampleClr.GetMsrParams().GetXRayParam().GetMidAnalyAQTime());
- string classifyName = "";
- //元素名称
- string a_strElementName = "";
- string classifyColor = "";
- //元素Xray数据
- uint[] a_ElementXrayData;
- COTSParticleClr selpart = null;
- var mode = m_MeasureAppForm.m_ProjRstData.GetWorkingSample().GetMsrParams().GetXRayParam().GetScanMode();
- GetSelectedParticle((int)mousepos.X, (int)mousepos.Y, ref selpart);
- if (selpart == null)
- {
- var part = new COTSParticleClr();
- part.SetXRayPos(new Point(mousepos.X, mousepos.Y));
- var xray = part.GetXray();
- xray.SetIndex(0);
- part.SetXray(xray);
- selpart = part;
- if (mode != otsdataconst.OTS_X_RAY_SCAN_MODE.PointMode)
- {
- log.Warn("There's no particle to be found at this position,only point mode xray collection can be done!");
- mode = otsdataconst.OTS_X_RAY_SCAN_MODE.PointMode;
- }
- }
- List<COTSParticleClr> parts = new List<COTSParticleClr>();
- parts.Add(selpart);
- if (GetXRayAndElements(a_Milliseconds, parts, mode))
- {
- log.Trace("--获取单点扫描数据:" + "元素名称:" + a_strElementName + "'--");
- a_ElementXrayData = selpart.GetXray().GetXrayData();
- a_strElementName = selpart.GetXray().GetQuantifiedElementsStr();
- classifyName = selpart.GetTypeName();
- classifyColor = selpart.GetTypeColor();
- Color colorValue = ColorTranslator.FromHtml(classifyColor);
- CrossSign theSign = new CrossSign(mousepos.X, mousepos.Y, this);
- m_ElementPointGDIObjects.Add(theSign);
- //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<ShowElementInfo> list_showelementinfo = new List<ShowElementInfo>();
- 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]);
- ls_sei.dKF = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).K_Peak);
- double de_sx2 = 0;
- if (CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "" || CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "-")
- {
- de_sx2 = 0;
- }
- else
- {
- de_sx2 = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak);
- }
- ls_sei.dLF = de_sx2;
- list_showelementinfo.Add(ls_sei);
- }
- }
- control_XRayTable1.List_ShowElementInfo = list_showelementinfo;
- control_XRayTable1.GoodName = classifyName;
- //设置分析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";
- }
- }
- var img = myFld.GetAnalysisParticleSTDColoredImage();
- pictureBox2.Image = img;
- ExportScanInfoMenuItem.Enabled = true;
- this.Refresh();
- }
- }
- public bool GetSelectedParticle(int dMouseImgX, int dMouseImgY, ref COTSParticleClr selectedPart)
- {
- var fldParts = myFld.GetListAnalysisParticles();
- var partPos = new Point(dMouseImgX, dMouseImgY);
- selectedPart = null;
- foreach (var p in fldParts)
- {
- Rectangle r = (Rectangle)p.GetParticleRect();
- if (r.Contains(partPos))
- {
- selectedPart = p;
- break;
- }
- }
- if (selectedPart == null)
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- public bool GetXRayAndElements(uint a_nXRayAQTime, List<COTSParticleClr> selectedParts, otsdataconst.OTS_X_RAY_SCAN_MODE mode)
- {
- var expC = m_MeasureAppForm.m_ProjRstData.GetWorkingSample().GetMsrParams().GetXRayParam().GetAnalyExpCount();
- var ifautoid = m_MeasureAppForm.m_ProjRstData.GetWorkingSample().GetMsrParams().GetXRayParam().IfAutoId;
- var knownelements = m_MeasureAppForm.m_ProjRstData.GetWorkingSample().GetMsrParams().GetXRayParam().AnalysisElements;
- var eds = EDSController.GetEDSController(GetIWidth(), GetIHeight(), expC, ifautoid, knownelements);
- //var parts = new List<COTSParticleClr>();
- //parts.Add(selectedPart);
- if (mode == otsdataconst.OTS_X_RAY_SCAN_MODE.PointMode)
- {
- eds.GetXRayByParts(selectedParts, a_nXRayAQTime, true);
- }
- else if (mode == otsdataconst.OTS_X_RAY_SCAN_MODE.FeatureMode)
- {
- eds.GetXRayByFeatures(selectedParts, a_nXRayAQTime, true);
- }
- else if (mode == otsdataconst.OTS_X_RAY_SCAN_MODE.ExpandMode)
- {
- eds.GetXRayByExpandFeatures(selectedParts, a_nXRayAQTime, true);
- }
- ClassifyParticles(selectedParts);
- return true;
- }
- void ClassifyParticles(List<COTSParticleClr> parts)
- {
- if (m_MeasureAppForm.m_ProjRstData.SystemTypeId == otsdataconst.OTS_SysType_ID.IncA)
- {
- var smplmeasure = new CSmplMeasureIncA("", m_MeasureAppForm.m_ProjRstData.GetWorkingSample());
- foreach (var p in parts)
- {
- smplmeasure.ClassifyIncAParticle(p, m_MeasureAppForm.m_ProjRstData.GetWorkingSample().GetMsrParams().GetSTDName());
- }
- }
- else
- {
- var smplmeasure = new CSmplMeasureCleanliness("", m_MeasureAppForm.m_ProjRstData.GetWorkingSample());
- smplmeasure.ClassifyParticles(parts, m_MeasureAppForm.m_ProjRstData.GetWorkingSample().GetMsrParams().GetSTDName());
- }
- }
- 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)
- {
- //导出图片到报告中
- ExportReport();
- }
- /// <summary>
- /// 导出Image到报告
- /// </summary>
- private bool ExportReport()
- {
- if (m_ElementPointGDIObjects.Count == 0)
- {
- return false;
- }
- 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.picBox.Width, this.picBox.Height);
- this.picBox.DrawToBitmap(bseBM, new Rectangle(0, 0, this.picBox.Width, this.picBox.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<string> listFilePath = new List<string>();
- listFilePath.Add(ImgFilePath);
- listFilePath.Add(ImgXrayFilePath);
- List<ShowElementInfo> 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<DataTable> list_ElementData = new List<DataTable>();
- list_ElementData.Add(dt);
- //将数据插入Excel中
- return InsertDataToExcelTable(list_ElementData, startupPath, listFilePath);
- }
- public bool InsertDataToExcelTable(List<System.Data.DataTable> a_list_ElementData, string a_filePath, List<string> a_ImgFilePath)
- {
- var m_xe = new ExcelEdit();
- m_xe.Create();
- Microsoft.Office.Interop.Excel.Worksheet ws = m_xe.GetSheet("Sheet1");
- m_xe.m_ws = ws;
- string str_ExcelFilePath = a_filePath + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx";
- m_xe.m_ws.Shapes.AddPicture(a_ImgFilePath[0], Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, 0, 0, 400, 300);
- m_xe.m_ws.Shapes.AddPicture(a_ImgFilePath[1], Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, 0, 320, 400, 100);
- if (str_ExcelFilePath.IndexOf(":") < 0)
- {
- return false;
- }
- if (m_xe.m_app == null)
- {
- return false;
- }
- //数据列表 行数
- int dataRow = 30;
- //写入标题
- foreach (var dgv in a_list_ElementData)
- {
- for (int i = 0; i < dgv.Columns.Count; i++)
- {
- m_xe.m_ws.Cells[dataRow + 1, i + 1] = dgv.Columns[i].ColumnName;
- }
- //写入数值
- for (int r = 0; r < dgv.Rows.Count; r++)
- {
- for (int i = 0; i < dgv.Columns.Count; i++)
- {
- m_xe.m_ws.Cells[dataRow + r + 2, i + 1] = dgv.Rows[r].ItemArray[i];
- }
- System.Windows.Forms.Application.DoEvents();
- }
- }
- //列宽自适应
- m_xe.m_ws.Columns.EntireColumn.AutoFit();
- if (str_ExcelFilePath != "")
- {
- try
- {
- m_xe.m_wb.Saved = true;
- m_xe.m_wb.SaveCopyAs(str_ExcelFilePath);
- }
- catch (Exception ex)
- {
- log.Error(ex.ToString());
- }
- }
- //关闭excel
- m_xe.Close();
- //强行销毁
- GC.Collect();
- //干掉进程里的EXCEL
- foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcesses())
- {
- if (p.ProcessName == "EXCEL")
- {
- p.Kill();
- }
- }
- //删除图片文件
- foreach (string imgPath in a_ImgFilePath)
- {
- if (File.Exists(imgPath))
- {
- //如果存在则删除
- File.Delete(imgPath);
- }
- }
- System.Diagnostics.Process.Start(str_ExcelFilePath);
- return true;
- }
- 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;
- public int GetIHeight()
- {
- string str = m_MeasureAppForm.m_ProjParam.GetBSEImageResolutionStr();
- string[] sArray = str.Split('X');
- if (sArray[0] != "" && sArray[1] != "")
- {
-
- SetIHeight(Convert.ToInt32(sArray[1]));
- }
- return m_iHeight;
- }
- public void SetIHeight(int value)
- {
- m_iHeight = value;
- }
- public int GetIWidth()
- {
- string str = m_MeasureAppForm.m_ProjParam.GetBSEImageResolutionStr();
- string[] sArray = str.Split('X');
- if (sArray[0] != "" && sArray[1] != "")
- {
- SetIWidth(Convert.ToInt32(sArray[0]));
-
- }
- return m_iWidth;
- }
- public void SetIWidth(int value)
- {
- m_iWidth = value;
- }
- //在picturebox的鼠标按下事件里.
- private void pbBSEImage_MouseUp(object sender, MouseEventArgs e)
- {
- MoveFlag = false;
- this.Cursor = Cursors.Default;
- picBox.Refresh();
- }
- //在picturebox鼠标缩放
- private void pbBSEImage_MouseWheel(object sender, MouseEventArgs e)
- {
- if (MenuItemLineScan.Checked)
- {
- return;
- }
- if (m_MeasureAppForm.m_MsrThreadWrapper.BGWorkThreadIsRunning())
- {
- return;
- }
- var refPoint = e.Location;
- float newZoom;
- float zoomDelta;
- //鼠标滚动缩放 BSE图
- if (e.Delta > 0)
- {
- newZoom = m_ZoomRecord + m_ZoomCoefficient;
- }
- else
- {
- newZoom = m_ZoomRecord - m_ZoomCoefficient;
- }
- if (newZoom > m_MaxZoom)
- {
- newZoom = m_MaxZoom;
- }
- if (newZoom < 1)
- {
- newZoom = 1;
- }
- zoomDelta = newZoom - m_ZoomRecord;
- if (newZoom == 1)
- {
- ImgZoomRectangle.Width = originalImgRectangle.Width;
- ImgZoomRectangle.Height = originalImgRectangle.Height;
- ImgZoomRectangle.X = originalImgRectangle.X;
- ImgZoomRectangle.Y = originalImgRectangle.Y;
- }
- else
- {
- float xShiftOld = (refPoint.X - ImgZoomRectangle.X);
- float yShiftOld = (refPoint.Y - ImgZoomRectangle.Y);
- float xShift = xShiftOld * (1 + 1 / m_ZoomRecord * zoomDelta);
- float yShift = yShiftOld * (1 + 1 / m_ZoomRecord * zoomDelta);
- ImgZoomRectangle.Width += Convert.ToInt32(ImgZoomRectangle.Width / m_ZoomRecord * zoomDelta);
- ImgZoomRectangle.Height += Convert.ToInt32(ImgZoomRectangle.Height / m_ZoomRecord * zoomDelta);
- ImgZoomRectangle.X = (refPoint.X - xShift);
- ImgZoomRectangle.Y = (refPoint.Y - yShift);
- }
- m_ZoomRecord = newZoom;
- picBox.Invalidate();
- pictureBox2.Invalidate();
- }
- private void OTSMeasureStatusWindow_MouseClick(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Right && e.Clicks == 1)
- {
- contextMenuStrip1.Show(PointToScreen(e.Location));
- SetContentMenu();
- }
- }
- private void ViewStripMenuItem_Click(object sender, EventArgs e)
- {
- ToolWindow toolWindow = new ToolWindow(m_MeasureAppForm, this);
- int grayStart = 0;
- int grayEnd = 0;
- if (originalBse != null)
- {
- Bitmap bitmap = CImageHandler.ToGrayBitmap(originalBseData, GetIWidth(), GetIHeight());
- toolWindow.BseImg = bitmap;
- toolWindow.OriginalBseData = originalBseData;
- //获取去背景灰度值
- 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;
- 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();
- //确认后进行去背景
- var m_systype = m_MeasureAppForm.m_ProjParam.GetResultData().SystemTypeId;
- ShowColoredRemoveBGImage();
- }
- }
- private void toolStripMenuItem1_Click(object sender, EventArgs e)
- {
- SpecialParticleForm specialParticleForm = new SpecialParticleForm(CSpecialGrayRangeParam.GetParamFileFullName(), m_MeasureAppForm, originalBseData, GetIWidth(), GetIHeight(), this);
- DialogResult dialogResult = specialParticleForm.ShowDialog();
- }
- private void toolStripMenuItem2_Click(object sender, EventArgs e)
- {
- //设置右键菜单中的项 是否可编辑
- SetContextMenuEnabled(true);
- m_imagetype = ImageType.RemoveBGImage;
- ShowColoredRemoveBGImage();
- //m_CurrentMultiple = 0;
- panelXray.Visible = false;
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- if (!backgroundWorker1.IsBusy)
- {
- backgroundWorker1.RunWorkerAsync();
- }
- }
- private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
- {
- //更新当前的图
- log.Info("begin to acquire image");
- bool rst = AcquireBSEImage();
- if (m_imagetype == ImageType.GrayLevelLineScan)
- {
- log.Info("begin to show image");
- UpdateImageAndLineScanChart();
- }
- }
- private void pictureBox2_Paint(object sender, PaintEventArgs e)
- {
- if (pictureBox2.Image != null)
- {
- var g = e.Graphics;
- g.Clear(Color.Gainsboro);
- g.DrawImage(pictureBox2.Image, ImgZoomRectangle);
- if (m_ElementPointGDIObjects != null)
- {
- if (m_ElementPointGDIObjects.Count > 0)
- {
- //绘制采集点标记
- foreach (CrossSign item in m_ElementPointGDIObjects)
- {
- if (item != null)
- {
- item.OnPaint(e);
- }
- }
- }
- }
- }
- }
- private void OTSMeasureStatusWindow_Activated(object sender, EventArgs e)
- {
- //获取电镜中图像大小
- if (m_MeasureAppForm.m_ProjParam.GetWorkSample() != null)
- {
- string str = m_MeasureAppForm.m_ProjParam.GetBSEImageResolutionStr();
- string[] sArray = str.Split('X');
- if (sArray[0] != "" && sArray[1] != "")
- {
- SetIWidth(Convert.ToInt32(sArray[0]));
- SetIHeight(Convert.ToInt32(sArray[1]));
- }
- }
- }
- private void pictureBox2_MouseClick(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Right && e.Clicks == 1)
- {
- int XMenu = pictureBox2.Left + e.Location.X;
- int YMenu = pictureBox2.Top + e.Location.Y;
- Point mousePoint = new Point(XMenu, YMenu);
- contextMenuStrip1.Show(PointToScreen(mousePoint));
- SetContentMenu();
- }
- }
- private void 批量采集ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- var expC = m_MeasureAppForm.m_ProjRstData.GetWorkingSample().GetMsrParams().GetXRayParam().GetAnalyExpCount();
- var ifautoid = m_MeasureAppForm.m_ProjRstData.GetWorkingSample().GetMsrParams().GetXRayParam().IfAutoId;
- var knownelements = m_MeasureAppForm.m_ProjRstData.GetWorkingSample().GetMsrParams().GetXRayParam().AnalysisElements;
- IEDSController m_EDSHardwareMgr = EDSController.GetEDSController(GetIWidth(), GetIHeight(), expC, ifautoid, knownelements);
- var mode = m_MeasureAppForm.m_ProjRstData.GetWorkingSample().GetMsrParams().GetXRayParam().GetScanMode();
- if (m_EDSHardwareMgr.Connect())
- {
- COTSMsrPrjResultData cProjMgr = m_MeasureAppForm.m_ProjParam.GetResultData();
- //获取工作样品对象
- COTSSample sampleClr = cProjMgr.GetWorkingSample();
- //清空之前记录的标识
- if (m_ElementPointGDIObjects != null)
- {
- if (m_ElementPointGDIObjects.Count > 0)
- {
- //清空
- m_ElementPointGDIObjects.Clear();
- }
- }
- //3.根据所要扫描的位置进行元素分析
- uint a_Milliseconds = 0;
- //采集时间
- a_Milliseconds = Convert.ToUInt32(sampleClr.GetMsrParams().GetXRayParam().GetMidAnalyAQTime());
- var parts = myFld.GetListAnalysisParticles();
- GetXRayAndElements(a_Milliseconds, parts, mode);
- var colorImg = myFld.GetAnalysisParticleSTDColoredImage();
- pictureBox2.Image = colorImg;
- ExportScanInfoMenuItem.Enabled = true;
- this.Refresh();
- }
- }
- }
- }
|