12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012 |
- 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;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Reflection;
- using System.Windows.Forms;
- //using OTSMeasureApp._0_OTSModel.Measure.ParamData;
- namespace OTSMeasureApp
- {
- public enum idLine
- {
- //曲线
- GrayLine = 0,
- //灰度图
- GrayImage = 1
- }
- 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,
- //导出采集信息报告
- ExportReport = 10
- }
- public partial class OTSMeasureStatusWindow : DockContent
- {
- #region 全部变量
- public OTSIncAMeasureAppForm m_MeasureAppForm;
- static int m_iWidth = 0;
- static int m_iHeight = 0;
- //获取BSE图时最初的位置
- Point m_GetBSEImageInitPoint = new Point();
- // 调试图图片数据
- public byte[] originalBseData;
- //去背景图
- private byte[] removeBGBseData;
- private Bitmap coloredParticleImage;
- //灰度图数据
- public double[] dGrayLevelData;
- //灰度峰值
- private double dGrayLevelMax;
- //去背景灰度图数据
- private double[] dGrayAbandonLevelData;
- //去背景灰度峰值
- private double dGrayAbandonLevelMax;
- public string FileName;
- //原图Y轴
- int YSize = 0;
- //int drawflag = 0;
- private int height = 0;
- private int width = 0;
- //画布大小
- private Bitmap bitmap;
- //要画曲线的点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;
- //绘制采集点对象
- public static List<CRectangleGDIObject> 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;
- int FieldWitdh = 0;
- double FieldHeight = 0;
- #endregion
- public enum ImageType
- {
- //BSE图
- BSEImage = 0,
- //去背景图
- RemoveBGImage = 1,
- //显示灰度曲线图
- GrayLevelChart = 2,
- //线扫描曲线
- GrayLevelLineScan = 3,
- //显示去背景BSE图灰度曲线
- GrayAbandonLevelChart = 4,
- //
- ColorParticleImage = 5
- }
- //图bfResult
- public static bool bfResult = false;
- //当前是否显示线扫描
- //public static bool IsShowGrayLevelLine = false;
- //当前默认值
- ImageType m_imagetype = ImageType.BSEImage;
- //ImageType m_IsShowImageType = ImageType.BSEImage;
- public OTSMeasureStatusWindow(OTSIncAMeasureAppForm MeasureApp)
- {
- InitializeComponent();
- m_MeasureAppForm = MeasureApp;
- m_ElementPointGDIObjects = new List<CRectangleGDIObject>();
- //进入时首先对XRayTable进行隐藏
- panelXray.Visible = false;
- //国际化
- lan = new OTSCommon.Language(this);
- table = lan.GetNameTable(this.Name);
- if (OTSCommon.Language.ReadDefaultLanguage() == "ZH")
- {
- contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Text = "切换显示至BSE图";
- }
- else
- {
- contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Text = "SwitchDisplayToBSEDiagram";
- }
- }
- /// <summary>
- /// 在控件中显示BSE图像
- /// </summary>
- /// <param name="m_iWidth"></param>
- /// <param name="m_iHeigh"></param>
- /// <param name="bBseData"></param>
- public void ShowImage(int iWidth, int iHeight, byte[] bBseData)
- {
- try
- {
- Bitmap bitmap = CImageHandler.ToGrayBitmap(bBseData, iWidth, iHeight);
- ShowBitmapInPicbox1(bitmap);
- }
- catch (Exception e)
- {
- NLog.LogManager.GetCurrentClassLogger().Error(e.Message);
- }
- }
- public void ShowBitmapInPicbox1(Bitmap bmpImage)
- {
- picBox.Image = bmpImage;
- //设置Pictrue显示位置
- picBox.Height = this.RestoreBounds.Height;
- picBox.Width = this.RestoreBounds.Height * 4 / 3;
- //获取黄线坐标位置
- Rectangle rectangle = GetPictureBoxZoomSize(picBox);
- 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;
- picBox.Left = 0;
- picBox.Top = 0;
- picBox.Show();
- 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.Height * 2 / 3;
- //获取黄线坐标位置
- Rectangle rectangle = GetPictureBoxZoomSize(picBox);
- 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;
- picBox.Left = 0;
- picBox.Top = 0;
- picBox.Show();
- if (image2 != null)
- {
- pictureBox2.Image = image2;
- }
- pictureBox2.Height = this.RestoreBounds.Height;
- pictureBox2.Width = this.RestoreBounds.Height * 2 / 3;
- pictureBox2.Left = this.RestoreBounds.Width / 2;
- pictureBox2.Top = 0;
- pictureBox2.Show();
- }
- /// <summary>
- /// 在控件中显示图像
- /// </summary>
- /// <param name="m_iWidth"></param>
- /// <param name="m_iHeigh"></param>
- /// <param name="bBseData"></param>
- public Image ShowImageStatus(int m_iWidth, int m_iHeigh, byte[] bBseData)
- {
- return CImageHandler.ToGrayBitmap(bBseData, m_iWidth, m_iHeigh);
- }
- //显示扫描曲线图方法
- #region 显示扫描曲线图方法
- private void DrawCurve(byte[] buf, PaintEventArgs e)
- {
- //创建位图
- Rectangle rectangle = GetPictureBoxZoomSize(picBox);
- double rate = (double)rectangle.Height / (double)picBox.Image.Height;
- width = rectangle.Width;
- height = rectangle.Height;
- bitmap = new Bitmap(width, 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;
- if (pointY > ((rectangle.Height) * 3 / 4))
- {
- float ii = pointY;
- }
- CurvePointF[i] = new PointF(pointX, pointY);
- }
- float Tension = 0.001f;
- e.Graphics.DrawCurve(mypenYellow, CurvePointF, Tension);//画曲线
- }
- #endregion
- //处理获取调试图菜单事件
- #region 处理获取调试图菜单事件
- private void AcquireBSEImage_Click(object sender, EventArgs e)
- {
- if (m_ElementPointGDIObjects != null)
- {
- m_ElementPointGDIObjects.Clear();
- }
- //设置右键菜单中的项 是否可编辑
- SetContextMenuEnabled(true);
- 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
- {
- //显示单点扫描元素信息菜单
- contextMenuStrip1.Items[(int)MeasureStateMenuType.PointScanElementMenuItem].Enabled = true;
- }
- //m_IsShowImageType = ImageType.BSEImage;
- m_imagetype = ImageType.BSEImage;
- Bitmap bitmap = CImageHandler.ToGrayBitmap(originalBseData, m_iWidth, m_iHeight);
- ShowBitmapInPicbox1(bitmap);
- myChart.Visible = false;
- //图像加载后的显示位置
- m_CurrentMultiple = 0;
- picBox.Height = this.RestoreBounds.Height;
- picBox.Left = 0;
- picBox.Top = 0;
- DelElementPointGDIObjects();
- panelXray.Visible = false;
- m_CurrentMultiple = 0;
- }
- /// <summary>
- /// 获取BSE图方法
- /// </summary>
- private bool AcquireBSEImage()
- {
- //获取电镜中图像大小
- string str = m_MeasureAppForm.m_ProjParam.GetBSEImageResolutionStr();// 举例:1024X768
- string[] sArray = str.Split('X');
- if (sArray[0] != "" && sArray[1] != "")
- {
- m_iWidth = Convert.ToInt32(sArray[0]);
- m_iHeight = Convert.ToInt32(sArray[1]);
- }
- //建立图像数据
- originalBseData = new byte[m_iWidth * m_iHeight];
- //获取图像数据
- 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;
- }
- bool rst = GetScanImage(m_iWidth, m_iHeight, nDwellTime, ref originalBseData);
- return rst;
- }
- private void UpdateImageAndLineScanChart()
- {
- Bitmap bitmap = CImageHandler.ToGrayBitmap(originalBseData, m_iWidth, m_iHeight);
- ShowBitmapInPicbox1(bitmap);
- //获取灰度图数据
- dGrayLevelData = new double[(int)GrayLevel.Max];
- dGrayLevelData = GetGaryData(originalBseData, dGrayLevelData);
- //计算灰度最大值
- dGrayLevelMax = dGrayLevelData[0];
- for (int i = 1; i < (int)GrayLevel.Max; i++)
- {
- dGrayLevelMax = Math.Max(dGrayLevelMax, dGrayLevelData[i]);
- }
- 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];
- }
- DisChartData(XData, YData, ImageType.GrayLevelLineScan);
- picBox.Refresh();
- }
- public double[] GetGaryData(byte[] Imagedata, double[] GrayLevelData)
- {
- //获得下标每一点的灰度值,并在数组里加一
- for (int i = 0; i < Imagedata.Length; i++)
- {
- byte graylevel = Imagedata[i];
- if (graylevel > 0 && graylevel < 255)
- {
- GrayLevelData[graylevel] += 1;
- }
- }
- return GrayLevelData;
- }
- public bool GetScanImage(int iWidth, int iHeight, DwellTimeLevel iDwellTime, ref byte[] bImageData)
- {
- //电镜设置对象
- 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);
- return false;
- }
- cfun.SetImageSize(iWidth, iHeight);
- cfun.SetDwellTime(iDwellTime);
- var bse = cfun.AcquireBSEImage();
- bImageData = bse.GetImageDataPtr();
- sem.SetScanExternal(false);
- }
- catch (Exception ex)
- {
- log.Error(ex.Message.ToString());
- return false;
- }
- return true;
- }
- #endregion
- //显示去背景图 = AUTO
- #region 显示去背景图
- private void ShowRemoveBGImage_Click(object sender, EventArgs e)
- {
- //设置右键菜单中的项 是否可编辑
- SetContextMenuEnabled(true);
- m_imagetype = ImageType.RemoveBGImage;
- ShowRemoveBGImage();
- m_CurrentMultiple = 0;
- panelXray.Visible = false;
- }
- protected void ShowRemoveBGImage()
- {
- //获取电镜中图像大小
- string str = m_MeasureAppForm.m_ProjParam.GetBSEImageResolutionStr();
- 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_ProjRstData.GetWorkingSample();
- double pixelSize = WSample.CalculatePixelSize();
- var imageProcessParam = WSample.GetMsrParams().GetImageProcessParam();
- var imageHandle = new CImageHandler();
- bfResult = imageHandle.GetBSEImage(imageProcessParam, pixelSize, originalBseData, m_iWidth, m_iHeight, ref removeBGBseData);
- //取图不成功就返回
- if (!bfResult) { return; }
- Bitmap bitmap = CImageHandler.ToGrayBitmap(removeBGBseData, m_iWidth, m_iHeight);
- ShowDoubleImage((Bitmap)picBox.Image, bitmap);
-
- myChart.Visible = false;
- //切换显示至BSE图
- contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Enabled = true;
- }
- protected void ShowColoredRemoveBGImage()
- {
- //获取电镜中图像大小
- string str = m_MeasureAppForm.m_ProjParam.GetBSEImageResolutionStr();
- 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_ProjRstData.GetWorkingSample();
- double pixelSize = WSample.CalculatePixelSize();
- var imageProcessParam = WSample.GetMsrParams().GetImageProcessParam();
- var imageHandle = new CImageHandler();
- coloredParticleImage = new Bitmap(m_iWidth, m_iHeight);
- CBSEImgClr pImgNoBG = new CBSEImgClr(new Rectangle(0, 0, m_iWidth, m_iHeight));
- bfResult = imageHandle.GetColoredImage(imageProcessParam, pixelSize, originalBseData, m_iWidth, m_iHeight, ref pImgNoBG, ref coloredParticleImage);
- removeBGBseData = pImgNoBG.GetImageDataPtr();
- //获取去背景灰度图数据
- dGrayAbandonLevelData = new double[(int)GrayLevel.Max];
- dGrayAbandonLevelData = GetGrayAbandonData(removeBGBseData, dGrayAbandonLevelData);
- //计算灰度去背景最大值
- dGrayAbandonLevelMax = dGrayAbandonLevelData[0];
- for (int i = 1; i < (int)GrayLevel.Max; i++)
- {
- dGrayAbandonLevelMax = Math.Max(dGrayAbandonLevelMax, dGrayAbandonLevelData[i]);
- }
- //取图不成功就返回
- if (!bfResult) { return; }
- ShowDoubleImage((Bitmap)picBox.Image, coloredParticleImage);
-
- myChart.Visible = false;
- picBox.Show();
- //切换显示至BSE图
- contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Enabled = true;
- }
- #endregion
- //显示灰度曲线
- #region 显示灰度曲线
- private void ShowGrayLevelImage_Click(object sender, EventArgs e)
- {
- //设置右键菜单中的项 是否可编辑
- SetContextMenuEnabled(false);
- ShowGrayLevelImage();
- }
- protected void ShowGrayLevelImage()
- {
- //切换显示至BSE图
- contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Enabled = true;
- contextMenuStrip1.Items[(int)MeasureStateMenuType.ChangeDiffImageShow].Enabled = true;
- //获取灰度图数据
- dGrayLevelData = new double[(int)GrayLevel.Max];
- dGrayLevelData = GetGaryData(originalBseData, dGrayLevelData);
- 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];
- }
- DisChartData(XData, YData, ImageType.GrayLevelChart);
- }
- #endregion
- //显示线扫描曲线
- #region 显示线扫描曲线
- private void ShowLineScanChart_Click(object sender, EventArgs e)
- {
- ShowBitmapInPicbox1((Bitmap)picBox.Image);
- if (MenuItemLineScan.Checked)
- {
- m_imagetype = ImageType.GrayLevelLineScan;
- timer1.Enabled = true;
- }
- else
- {
- m_imagetype = ImageType.BSEImage;
- timer1.Enabled = false;
- }
- }
- #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<OTSIncAGraph.Controls.ShowElementInfo>)(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);
- picBox.MouseClick += new MouseEventHandler(HiddenXrayTablePanel_MouseClick);
- //
- // pbBSEImage添加鼠标操作
- //
- this.picBox.MouseUp += new MouseEventHandler(this.pbBSEImage_MouseUp);
- this.picBox.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 (m_imagetype != ImageType.GrayLevelLineScan)
- {
- if (m_ElementPointGDIObjects != null)
- {
- if (m_ElementPointGDIObjects.Count > 0)
- {
- foreach (var item in m_ElementPointGDIObjects)
- {
- 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)
- {
- if (e.Button == MouseButtons.Right && e.Clicks == 1)
- {
- contextMenuStrip1.Show(PointToScreen(e.Location));
- SetContentMenu();
- }
- }
- #region 设置右键菜单中的项 是否可编辑
- protected void SetContextMenuEnabled(bool isEnabled)
- {
- //隐藏右键菜单中的项
- //MenuItemLineScan.Checked = false;
- MenuItemLineScan.Enabled = true;
- PointScanElementMenuItem.Enabled = isEnabled;
- bool showExprot = m_ElementPointGDIObjects.Count > 0 ? true : false;
- ExportScanInfoMenuItem.Enabled = showExprot;
- //IsShowGrayLevelLine = false;
- VisualAdjustingMenu.Enabled = isEnabled;
- toolStripMenuItem1.Enabled = true;
- this.Cursor = Cursors.Default;
- this.Validate();
- }
- #endregion
- #region 获取行数据
- private void GetLineImage(int iHeight, int iWidth, ref byte[] bdata)
- {
- Stream stream = null;
- //if (m_imagetype == ImageType.BSEImage)
- //{
- stream = new MemoryStream(originalBseData);
- //}
- //else if (m_imagetype == ImageType.RemoveBGImage)
- //{
- // stream = new MemoryStream(removeBGBseData);
- //}
- if (iHeight >= 0)
- {
- stream.Seek(iHeight * iWidth, SeekOrigin.Begin);
- }
- stream.Read(bdata, 0, iWidth);
- }
- #endregion
- private void panel1_Click(object sender, EventArgs e)
- {
- picBox.Show();
- }
- private void contextMenuStrip1_Opened(object sender, EventArgs e)
- {
- if (bfResult)
- {
- SampleParaLock.Enabled = true;
- ToolStripMenuItem.Enabled = true;
- grayToolStripMenuItem.Enabled = true;
- AbandonGrayStripMenuItem.Enabled = true;
- toolStripMenuItem2.Enabled = true;
- ChangeDiffImageShow.Enabled = true;
- if (0 <= m_MouseMoveImageX && m_MouseMoveImageX <= 1024)
- {
- PointScanElementMenuItem.Enabled = true;
- }
- else
- {
- PointScanElementMenuItem.Enabled = false;
- }
- if (!MenuItemLineScan.Checked)
- {
- PointScanElementMenuItem.Enabled = true;
- bool showExprot = m_ElementPointGDIObjects.Count > 0 ? true : false;
- if (showExprot)
- {
- ExportScanInfoMenuItem.Enabled = true;
- }
- }
- else
- {
- PointScanElementMenuItem.Enabled = false;
- ExportScanInfoMenuItem.Enabled = false;
- return;
- }
- if (myChart.Visible)
- {
- //MenuItemLineScan.Enabled = false;
- PointScanElementMenuItem.Enabled = false;
- ExportScanInfoMenuItem.Enabled = false;
- }
- else
- {
- //MenuItemLineScan.Enabled = true;
- 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;
- grayToolStripMenuItem.Enabled = false;
- MenuItemLineScan.Enabled = false;
- AbandonGrayStripMenuItem.Enabled = false;
- }
- }
- //拖动灰度线
- #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)
- {
- if (!bfResult)
- {
- return;
- }
- if (m_imagetype == ImageType.GrayLevelLineScan)
- {
- Rectangle rectangle = GetPictureBoxZoomSize(picBox);
- if (pointStart.Equals(pointEnd))
- {
- return;
- }
- Point start = new Point(100, pointStart.Y);
- Point end = new Point(500, pointEnd.Y);
- double rate = (double)picBox.Image.Height / (double)rectangle.Height;
- int YSize = Convert.ToInt32((rate * (double)pointStart.Y));
- //显示线扫描 黄色线的曲线数据
- var Imagedata = new byte[m_iWidth];
-
- 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
- {
- if (m_ElementPointGDIObjects != null)
- {
- if (m_ElementPointGDIObjects.Count > 0)
- {
- //绘制采集点标记
- foreach (CRectangleGDIObject item in m_ElementPointGDIObjects)
- {
- if (item != null)
- {
- item.OnPaint(e);
- }
- }
- }
- }
- }
- }
- private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
- {
- //如果pictureBox1中没有图像 则return退出
- if (picBox.Image == null)
- {
- return;
- }
- Control lCtrl = (sender as Control);
- Rectangle rectangle = GetPictureBoxZoomSize(picBox);
- 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 (originalBseData != null)
- {
- if ((picBox.Width - rectangle.Width) / 2 < e.X && e.X < (picBox.Width - rectangle.Width) / 2 + rectangle.Width)
- {
- imageX = e.X - (picBox.Width - rectangle.Width) / 2;
- rateX = (double)m_iWidth / (double)rectangle.Width;
- startimageX = Convert.ToInt32(imageX * rateX);
- m_MouseMoveImageX = startimageX;
- if (MoveFlag)
- {
- picBox.Left += Convert.ToInt32(e.X - xPos);//设置x坐标.
- picBox.Top += Convert.ToInt32(e.Y - yPos);//设置y坐标.
- }
- }
- else
- {
- startimageX = 0;
- m_MouseMoveImageX = -1;
- }
- if ((picBox.Height - rectangle.Height) / 2 < e.Y && e.Y < (picBox.Height - rectangle.Height) / 2 + rectangle.Height)
- {
- imageY = e.Y - (picBox.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);
-
- grayValue = originalBseData[startimageX];
-
- }
- else if (startimageY == 1)
- {
-
- grayValue = originalBseData[startimageX];
-
- }
- }
- else
- {
- grayValue = 0;
- }
- }
- LineX = rectangle.X + 1;
- LineXEnd = rectangle.X + rectangle.Width;
- if (LineX < MouseLine && MouseLine < LineXEnd)
- {
- if (MenuItemLineScan.Checked)
- {
- if (Math.Abs(e.Y - pointStart.Y) < 2)
- {
- this.Cursor = Cursors.SizeNS;
- }
- else
- {
- this.Cursor = Cursors.Default;
- }
- }
- }
- //Y值
- double rate = (double)picBox.Image.Height / (double)rectangle.Height;
- int YSize = Convert.ToInt32((rate * (double)e.Y));
- 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 (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.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);
- picBox.Refresh();
- }
- private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
- {
- m_mouseCurrentPoint = e.Location;
- if (e.Button != MouseButtons.Left)
- {
- return;
- }
- m_bMouseDown = !m_bMouseDown;
- }
- #endregion
- //显示去背景BSE图得灰度曲线值
- #region 显示去背景BSE图得灰度曲线值
- private void ShowAbandonGrayLevelImage_Click(object sender, EventArgs e)
- {
- //设置右键菜单中的项 是否可编辑
- SetContextMenuEnabled(false);
- ShowAbandonGrayLevelImage();
- }
- private double[] GetGrayAbandonData(byte[] Imagedata, double[] GrayAbandonLevelData)
- {
- //获得下标每一点的灰度值,并在数组里加一
- for (int i = 0; i < Imagedata.Length; i++)
- {
- byte graylevel = Imagedata[i];
- if (graylevel > 0 && graylevel < 255)
- {
- GrayAbandonLevelData[graylevel] += 1;
- }
- }
- return GrayAbandonLevelData;
- }
- protected void ShowAbandonGrayLevelImage()
- {
- m_imagetype = ImageType.GrayAbandonLevelChart;
- COTSSample WSample = m_MeasureAppForm.m_ProjRstData.GetWorkingSample();
- var pixelSize = WSample.CalculatePixelSize();
- var imageHandle = new CImageHandler();
- if (removeBGBseData == null)
- {
- bfResult = imageHandle.GetBSEImage(WSample.GetMsrParams().GetImageProcessParam(), pixelSize, originalBseData, m_iWidth, m_iHeight, ref removeBGBseData);
- }
- if (bfResult)
- {
- dGrayAbandonLevelData = new double[(int)GrayLevel.Max];
- GetGrayAbandonData(removeBGBseData, dGrayAbandonLevelData);
- //计算灰度去背景最大值
- dGrayAbandonLevelMax = dGrayAbandonLevelData[0];
- for (int i = 0; i < (int)GrayLevel.Max; i++)
- {
- dGrayAbandonLevelMax = Math.Max(dGrayAbandonLevelMax, dGrayAbandonLevelData[i]);
- }
- }
- //picBox.Hide();
- 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];
- }
- DisChartData(XData, YData, ImageType.GrayAbandonLevelChart);
- }
- #endregion
- private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Right && e.Clicks == 1)
- {
- int XMenu = picBox.Left + e.Location.X;
- int YMenu = picBox.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();
- }
- }
- }
- private void ChangeDiffImageShow_Click(object sender, EventArgs e)
- {
- SetContextMenuEnabled(true);
- //显示BSE图
- if (originalBseData != null)
- {
- //用于线扫描曲线
- m_imagetype = ImageType.BSEImage;
- //在控件中显示图像
- Bitmap bitmap = CImageHandler.ToGrayBitmap(originalBseData, m_iWidth, m_iHeight);
- ShowBitmapInPicbox1(bitmap);
- }
- m_CurrentMultiple = 0;
- panelXray.Visible = false;
- }
- #region 显示鼠标位置
- /// <summary>
- /// 显示鼠标位置
- /// </summary>
- /// <param name="eMouseLocation">当前处理后的鼠标路径 减去边缘</param>
- /// <param name="imageRect">Pictrue中的图像尺寸与位置</param>
- 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 + "";
- }
- #endregion
- #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>
- /// <param name="mouseCurrentLocation"></param>
- /// <param name="picBox"></param>
- /// <returns></returns>
- 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 判断当前电镜位置是否在样品台内部
- /// <summary>
- /// 判断当前电镜位置是否在样品台内部
- /// </summary>
- /// <param name="semLocation">电镜当前位置</param>
- /// <param name="SampleStage">样品台尺寸与位置</param>
- /// <returns></returns>
- public bool IsSEMLocationOnTheSampleStage(Point semLocation)
- {
- return m_MeasureAppForm.m_SamplepaceWindow.m_visualStage.IfMouseInStage(semLocation);
- }
- #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;
- m_MeasureAppForm.m_ProjParam.GetWorkingSampleSEMData(ref iWDistance, ref dMagni);
- if (iWDistance != 0 && dMagni != 0)
- {
- contextMenuStrip1.Items[(int)MeasureStateMenuType.ReadBSEPic].Enabled = true;
- }
- }
- }
- #endregion
- public void DisChartData(int[] XData, int[] YData, ImageType imgtype)
- {
- m_imagetype = imgtype;
- //添加数据
- myChart.Series[0].Points.DataBindXY(XData, YData);
- myChart.Series[0].Label = "";
- myChart.Series[0].LegendText = "";
- myChart.Series[0].Name = "Graph";
- myChart.Series[0].IsVisibleInLegend = false;
- switch (imgtype)
- {
- case ImageType.GrayLevelChart:
- myChart.Titles[0].Text = "B-GrayCurve";
- picBox.Hide();
- pictureBox2.Hide();
- myChart.Visible = true;
- break;
- case ImageType.GrayAbandonLevelChart:
- myChart.Titles[0].Text = "Remove Background Gray-scaleCurve";
- picBox.Hide();
- pictureBox2.Hide();
- myChart.Visible = true;
- break;
- case ImageType.GrayLevelLineScan:
- pictureBox2.Hide();
- myChart.Visible = true;
- break;
- default:
- myChart.Titles[0].Text = "";
- break;
- }
-
- panelXray.Visible = false;
- }
- private void PointScanElementMenuItem_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;
- string deviceType = FileHelper.GetXMLInformations("EDSName");
- var semtype = FileHelper.GetXMLInformations("SemControllerName");
- IEDSController m_EDSHardwareMgr = EDSController.GetEDSController(semtype,deviceType, m_iWidth, m_iHeight, 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();
- }
- }
- //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];
- if (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<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);
- }
- }
- //设置分析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();
- }
- }
- public bool GetXRayAndElements(uint a_nXRayAQTime, int dMouseImgX, int dMouseImgY, ref uint[] a_XrayData, ref ValueType a_nElementNum, ref string a_strResult)
- {
- 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;
- string deviceType = FileHelper.GetXMLInformations("EDSName");
- var semtype = FileHelper.GetXMLInformations("SemControllerName");
- var eds = EDSController.GetEDSController(semtype, deviceType,m_iWidth, m_iHeight, expC,ifautoid,knownelements);
- var mode = m_MeasureAppForm.m_ProjRstData.GetWorkingSample().GetMsrParams().GetXRayParam().GetScanMode();
- var part = new COTSParticleClr();
- part.SetXRayPos(new Point(dMouseImgX, dMouseImgY));
- var xray = part.GetXray();
- xray.SetIndex(0);
- part.SetXray(xray);
- var parts = new List<COTSParticleClr>();
- parts.Add(part);
- if (mode == otsdataconst.OTS_X_RAY_SCAN_MODE.PointMode)
- {
- eds.GetXRayByParts(parts, a_nXRayAQTime, true);
- }
- else
- {
- eds.GetXRayByFeatures(parts, a_nXRayAQTime, true);
- }
- a_XrayData = parts[0].GetXray().GetXrayData();
- a_strResult = parts[0].GetXray().GetQuantifiedElementsStr();
- return true;
- }
- 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()
- {
- 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;
- private void pbBSEImage_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Left)
- {
- //在线扫描未选中的情况下 设置移动标识与获取当前鼠标位置
- if (!(MenuItemLineScan.Checked))
- {
- MoveFlag = true;//已经按下.
- xPos = e.X;//当前x坐标.
- yPos = e.Y;//当前y坐标.
- }
- else
- {
- MoveFlag = false;
- }
- }
- }
- //在picturebox的鼠标按下事件里.
- private void pbBSEImage_MouseUp(object sender, MouseEventArgs e)
- {
- MoveFlag = false;
- }
- //在picturebox鼠标移动
- private void pbBSEImage_MouseMove(object sender, MouseEventArgs e)
- {
- if (MoveFlag)
- {
- picBox.Left = Convert.ToInt32(e.X - xPos);//设置x坐标.
- picBox.Top = Convert.ToInt32(e.Y - yPos);//设置y坐标.
- }
- }
- //在picturebox鼠标缩放
- private void pbBSEImage_MouseWheel(object sender, MouseEventArgs e)
- {
- if (m_imagetype != ImageType.BSEImage)
- {
- return;
- }
- //鼠标滚动缩放 BSE图
- if (e.Delta > 0)
- {
- if (m_CurrentMultiple < m_MaxMultipleRange)
- {
- m_CurrentMultiple += Convert.ToSingle(m_Multiple.ToString("f2"));
- picBox.Width += Convert.ToInt32(m_iWidth * m_Multiple);
- picBox.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)
- {
- picBox.Width -= Convert.ToInt32(m_iWidth * m_Multiple);
- picBox.Height -= Convert.ToInt32(m_iHeight * m_Multiple);
- }
- else
- {
- m_CurrentMultiple = 0;
- picBox.Height = this.RestoreBounds.Height;
- picBox.Width = this.RestoreBounds.Height * 4 / 3;
- picBox.Left = 0;
- picBox.Top = 0;
- Rectangle rectangle = GetPictureBoxZoomSize(picBox);
- 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_GetBSEImageInitPoint = sizeChangePoint;
- }
- }
- }
- }
- WheelElementPointGDIObjects(e.Location, m_CurrentMultiple);
- }
- }
- /// <summary>
- /// 缩放时改变 单点标识位置
- /// </summary>
- /// <param name="m_CurrentMultiple"></param>
- public void WheelElementPointGDIObjects(Point refPoint, float CurrentMultiple)
- {
- if (m_ElementPointGDIObjects.Count > 0)
- {
- foreach (CRectangleGDIObject item in m_ElementPointGDIObjects)
- {
- item.Zoom(refPoint, CurrentMultiple);
- }
- }
- }
- 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)
- {
- if (m_iWidth == 0 || m_iHeight == 0)
- {
- string str = m_MeasureAppForm.m_ProjParam.GetBSEImageResolutionStr();// 举例: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 (originalBseData != null)
- {
- Bitmap bitmap = CImageHandler.ToGrayBitmap(originalBseData, m_iWidth, m_iHeight);
- toolWindow.BseImg = bitmap;
- toolWindow.BBseData = 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;
- if (m_systype != otsdataconst.OTS_SysType_ID.IncA)
- {
- ShowColoredRemoveBGImage();
- }
- else
- {
- ShowRemoveBGImage();
- }
- }
- }
- private void toolStripMenuItem1_Click(object sender, EventArgs e)
- {
- if (m_iWidth == 0 || m_iHeight == 0)
- {
- string str = m_MeasureAppForm.m_ProjParam.GetBSEImageResolutionStr();// 举例: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, originalBseData, m_iWidth, m_iHeight, 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();
- }
-
- }
- }
- }
|