using OTSIncAReportApp.DataOperation.DataAccess; using OTSIncAReportApp.DataOperation.Model; using OTSIncAReportApp.OTSSampleReportInfo; using OTSIncAReportApp.SysMgrTools; using OTSIncAReportGraph.Class; using OTSIncAReportGraph.OTSIncAReportGraphFuncation; using OTSIncAReportMailInterface; using OTSPeriodicTable; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; using System.Threading; using System.Windows.Forms; namespace OTSIncAReportGraph.Controls { public partial class Control_DrawDistrbutionSortImage : UserControl { //防止segment过多的数量限制, private const int m_segment_overflownumber = 400; #region 变量定义 //这里要做成控件,不要是窗体 public List m_list_baseobject = null; //多边形的分栏,list public List m_list_sortparticledistribution = null; //多边形的分栏list,的原先值,用于缩放拖动等计算使用 public List m_old_list_sortparticledistribution = null; //记录操作记录类 List m_list_historyapolygon = null; //操作历史类,当前操作到的id private int m_operator_currentid = 0; //背景矩形 private RectangleF m_backrectf = new RectangleF(); //记录原值,背景矩形 private RectangleF m_old_backrectf = new RectangleF(); //单一Field视域,屏幕像素的宽高 public RectangleF m_OneField_Screen_BackRectf = new RectangleF(); //单一Field视域,OTS物理像素的宽高 public RectangleF m_OneField_OTS_Rectf = new RectangleF(); //是否使用矩形进行多选操作 private bool m_is_multiselect_rectangle = false; //是否使用圆形进行多选操作 private bool m_is_multiselect_ellipse = false; //是否可以进行绘制,提供给矩形多选与圆形多选使用的临时变量 private bool m_is_multiselect_onpaint = false; //进行选择的矩形范围 private RectangleF m_multiselect_rect = new RectangleF(); //在进行拖选前鼠标记录的点 private PointF m_beforemultiselect_point = new PointF(); //是否拖动 private bool m_isDrag = false; //拖动前的坐标记录 private PointF m_beforedrag_pointf = new PointF(); //记录鼠标拖选完成后形成的路径 private GraphicsPath m_selectmulti_gpath = new GraphicsPath(); //缩放的增大缩小的增量 private float m_f_zoom_increment = 0.1f; //缩放的基数,临时变量 private float m_f_widthandheight_js = 0; //与原先缩放的记录数 public float m_f_zoom_record = 1; //最大缩放倍数 private float m_f_zoom_max = 4f; //最小缩放倍数 private float m_f_zoom_mix = 0.5f; //标尺的大小记录 public float m_f_ruler_size = 100; //标尺原先大小的记录,参与计算 private float m_f_old_ruler_size = 100; //每像素代表的尺寸大小,还不知道在哪里进行计算 public float m_f_onepixel_size = 4.5f; //提供鼠标在右下角显示的文本,左侧 private string m_str_mouseshow_left = ""; //提供鼠标在右下角显示的文本,右侧 private string m_str_mouseshow_right = ""; //分栏网格边框的颜色 private Color m_c_ColumnRectangleColor = Color.LightSteelBlue; //底层封装类 OTSIncAReportFun m_ReportFun = null; //鼠标移动经过的颗粒对象,临时存放,用来记录是否要显示xray与隐藏xray DParticle m_move_dparticle = null; //保存数据源名称 private string m_showsourcename = ""; //保存数据源的ID private int m_datasourceid = 0; //记录当前鼠标位置对应SEM电镜的位置 Point m_sem_mouse_now_point = new Point(); //移动SEM到指定位置发生线程 private Thread m_mythread; //记录线程是否已经运行完成的状态 private bool m_mythread_state = false; private bool m_CtrlKeyDown = false; /// /// 当前正在显示的数据源名称,用来与框架调用条件判断使用 /// public string ShowSourceName { set { m_showsourcename = value; } get { return m_showsourcename; } } /// /// 当前正在显示的数据源ID /// public int DataSourceID { set { m_datasourceid = value; } get { return m_datasourceid; } } /// /// 返回当前缩放的大小因数 /// public float FZOOMRecord { get { return m_f_zoom_record; } set { m_f_zoom_record = value; } } //进度条窗体 public Frm_UserProgress m_frm_userprogress; /// /// 是否显示过小颗粒 /// public bool bShowSmallParticle = false; OTSSampleMeaInfo m_list_cgriddataclr = null; public OTSIncAReportApp.frmReportApp m_ReportApp; //国际化存储信息 Hashtable table; ResultFile resultFile = null; #endregion #region 构造函数及窗体加载 /// /// 排序图构造函数 /// /// 传入,委托类对象 /// 传入,项目管理类对象 /// 传入,项目类对象 /// 传入,文件管理类对象 /// 传入,文件类对象 public Control_DrawDistrbutionSortImage(OTSIncAReportApp.frmReportApp ReportApp) { m_list_baseobject = new List(); m_list_historyapolygon = new List(); m_list_sortparticledistribution = new List(); m_old_list_sortparticledistribution = new List(); m_mythread_state = false; m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO)); m_frm_userprogress = new Frm_UserProgress(); m_ReportApp = ReportApp; resultFile = m_ReportApp.resultFilesList[m_ReportApp.WorkingResult]; //初始化底层操作类 m_ReportFun = new OTSIncAReportFun( resultFile); InitializeComponent(); #region 国际化语言 Language lan = new Language(this); table = lan.GetNameTable(this.Name); #endregion } private void Control_DrawDistrbutionSortImage_Load(object sender, EventArgs e) { //向父窗体注册键盘按键事件 this.Parent.KeyDown += new KeyEventHandler(Control_DrawDistrbutionSortImage_KeyDown); this.Parent.KeyUp += new KeyEventHandler(Control_DrawDistrbutionSortImage_KeyUp); control_Ruler1 = new Control_Ruler(); control_XRayTable1 = new Control_XRayTable(); //设置鼠标为等待样式 //m_sec.SendCall("设置鼠标样式", "", "WaitCursor"); //显示进度条,计算进度条应该显示的位置和宽度 Form ls_main_form = this.ParentForm.ParentForm;//取出父窗体 m_frm_userprogress.Width = (int)(MyPrimaryScreen.DESKTOP.Width / MyPrimaryScreen.ScaleX * 0.9); m_frm_userprogress.Location = new Point(ls_main_form.Location.X + 80, ls_main_form.Location.Y + (int)(MyPrimaryScreen.DESKTOP.Height / MyPrimaryScreen.ScaleX) / 2); m_frm_userprogress.Show(); m_frm_userprogress.SetProgressValueAndText(0, table["str1"].ToString()); //调用填充排序图颗粒数据,总过程方法 GetDistrbutionSortImage_Total(); //设置双缓冲 SetDoubleBufferByIsDraw(); //设置标尺 //根据f_onepixel_size计算出要显示出100um的实际宽度 double d_onefixel_width = 100 / m_f_onepixel_size; if (d_onefixel_width == 0) { this.control_Ruler1.Visible = false; } else { //将标尺定位到合理的位置上 this.control_Ruler1.Location = new Point(10, MyPrimaryScreen.WorkingArea.Height - 300); this.control_Ruler1.Visible = true; this.control_Ruler1.SetValue(m_f_ruler_size, m_f_onepixel_size); } //加载时将背景rect设置与整个窗体一边大小 m_backrectf = this.ClientRectangle; //该背景大小并未与实际获得像素的进行关联,这里注意一下,回头观察是否需要改进掉 m_old_backrectf = m_backrectf; //进入时首先对XRayTable进行隐藏 control_XRayTable1.Visible = false; //设置鼠标为默认 //m_sec.SendCall("设置鼠标样式", "", "Default"); m_frm_userprogress.SetProgressValueAndText(100, table["str2"].ToString()); //加载完成,关闭进度条 m_frm_userprogress.Close(); } /// /// 排序图获取底层数据,组建整张排序图的总方法过程 /// public void GetDistrbutionSortImage_Total() { string str48 = "begin to load data...."; //str48 = table["str48"].ToString(); m_frm_userprogress.SetProgressValueAndText(1, str48); string path = resultFile.FilePath; FieldData fieldData = new FieldData(path); List fieldlist = fieldData.GetFieldList(); //将field的list对象给全局变量中,供后面获取xray使用 m_ReportFun.m_list_OTSField = fieldlist; string str49 = "begin to composit image...."; //str49 = table["str49"].ToString(); m_frm_userprogress.SetProgressValueAndText(15, str49); //第一次,用来计算,总大小等,获取Field的坐标,id,同时获取对应的ImgClr里的宽高,图像大小 List list_point = new List(); int i_field_width = 0, i_field_height = 0; //获取到该field的分辨率大小,循环中都是一样的 if (fieldlist.Count > 0) { Bitmap bitmp = DrawFunction.ReadImageFile(fieldlist[0].FieldImage); i_field_width = bitmp.Width; i_field_height = bitmp.Height; } for (int i = 0; i < fieldlist.Count(); i++) { //然后取出物理坐标,这个一会要与分辨率坐标进行变算一下 Point ls_point = new Point() { X = fieldlist[i].FieldPosX, Y = fieldlist[i].FieldPosY }; list_point.Add(ls_point); } //对单个Field视域的屏幕像素宽高,进行记录 m_OneField_Screen_BackRectf = new RectangleF(0, 0, i_field_width, i_field_height); //获取单个OTS视域像素宽高,并进行记录 Rectangle OTS_FieldRect = m_ReportFun.GetOneFieldWidthAndHeight(list_point); m_OneField_OTS_Rectf = OTS_FieldRect; string str50 = "calculate ruler...."; //str50 = table["str50"].ToString(); m_frm_userprogress.SetProgressValueAndText(18, str50); #region //标尺相关------------------------------------------------------------------------------ //在此处通过上面的i_field_width,ifield_height和list_point,来计算出个像素与实际物理值的比例 Rectangle ls_jsblrect = m_ReportFun.GetOneFieldWidthAndHeight(list_point); //然后用宽度来除以i_field_width 获取单个的像素比例 double d_onepixel_scale = Convert.ToDouble(ls_jsblrect.Width) / Convert.ToDouble(i_field_width); //再用该比例对标尺进行相应的赋值 m_f_onepixel_size = (float)d_onepixel_scale; #endregion //--------------------------------------------------------------------------------------- string str51 = "build the whole image...."; //str51 = table["str51"].ToString(); m_frm_userprogress.SetProgressValueAndText(20, str51); //70的进度条给到下面的循环中 float ls_int_progresscalc = 0; if (fieldlist.Count > 0) ls_int_progresscalc = (float)80 / (float)fieldlist.Count; string str52 = "Finished"; //str52 = table["str52"].ToString(); string str53 = "total"; //str53 = table["str53"].ToString(); string str54 = "..."; //str54 = table["str54"].ToString(); //第二次,再通过Field取到对应的Particle,循环一次 for (int i = 0; i < fieldlist.Count(); i++) { m_frm_userprogress.SetProgressValueAndText(20 + (int)(ls_int_progresscalc * (i + 1)), str52 + i.ToString() + str53 + m_ReportFun.m_list_OTSField.Count.ToString() + str54); //先获取该field中的所有particle List list_cotsparticleclr = new List(); list_cotsparticleclr = fieldlist[i].ParticleList; //取出该Field中,从物理坐标转换到像素坐标后.不知道该算法是否可靠,先进行测试判断 Point offset_point = m_ReportFun.GetFieldPhysicsConvertToScreen(list_point, i_field_width, i_field_height, new Point() { X = fieldlist[i].FieldPosX, Y = fieldlist[i].FieldPosY }); //然后将取出的数据,转换成Bitmap对象 Bitmap ls_bt = DrawFunction.ReadImageFile(fieldlist[i].FieldImage); //再循环取出所有的particle foreach (Particle ls_cotsparticleclr in list_cotsparticleclr) { List list_cotssegmentclr = new List(); list_cotssegmentclr = ls_cotsparticleclr.FeatureList; //创建颗粒分布图对应的类对象 List list_dsegment = new List(); //定义particle颗粒,并获取该颗粒与标准库中对应的颜色 DParticle ls_dp = new DParticle(); ls_dp.CLRFieldID = ls_cotsparticleclr.FieldId; //为我封装的颗粒保存上,底层对应的FieldID ls_dp.CLRTagID = ls_cotsparticleclr.ParticleId; //为我封装的颗粒对象保存上,底层对应的TagID ls_dp.STDTypeID = ls_cotsparticleclr.TypeId; //为我封装的颗粒对象保存上,类型 ls_dp.TypeId = ls_cotsparticleclr.TypeId; ls_dp.TypeName = ls_cotsparticleclr.TypeName; ls_dp.XRayId = ls_cotsparticleclr.XrayId; ls_dp.SEMPosX = ls_cotsparticleclr.SEMPosX; ls_dp.SEMPosY = ls_cotsparticleclr.SEMPosY; ls_dp.Color = m_ReportFun.GetColorBySTDTypeIDForBSEAndSorImage(ls_cotsparticleclr.TypeColor, ls_cotsparticleclr.TypeId); //防止segment过多造成程序卡死 if (list_cotssegmentclr.Count < m_segment_overflownumber) //再循环取出里面所有的segment foreach (Feature ls_cotssegmentclr in list_cotssegmentclr) { //这里的坐标未转换 DSegment ds = new DSegment(); ds.Rect = new Rectangle(ls_cotssegmentclr.Start + offset_point.X, //i_field_height - ls_cotssegmentclr.GetHeight() + offset_point.Y, ls_cotssegmentclr.Height + offset_point.Y, ls_cotssegmentclr.Length, 1); //图像上下反了,翻转一下,上下翻转 //ls_bt.RotateFlip(RotateFlipType.Rotate180FlipX);//使用系统带的图像处理方法,进行x轴的翻转 //合成图像完成,开始抠取像素---------------------为显示BSE原图而用-------------------------------------------- int i_ls_length = ls_cotssegmentclr.Length; List ls_list_colors = new List(); for (int m = 0; m < i_ls_length; m++) { //这里实现一下代码保护 int lsjs_x = ls_cotssegmentclr.Start + m; //int lsjs_y = i_field_height - ls_cotssegmentclr.GetHeight(); int lsjs_y = ls_cotssegmentclr.Height; if (lsjs_x < 0) lsjs_x = 0; if (lsjs_x >= i_field_width) lsjs_x = i_field_width - 1; if (lsjs_y < 0) lsjs_y = 0; if (lsjs_y >= i_field_height) lsjs_y = i_field_height - 1; //按理说这里应该加上个横向抠取像素颜色,这里需要再处理一下 ls_list_colors.Add(ls_bt.GetPixel(lsjs_x, lsjs_y)); } //---------------------------------------------存入标准库相关的信息------------------------------------------------ ds.Color = ls_dp.Color;//将线的颜色对应到颗粒的颜色 //------------------------------------------------------------------------------------------------------ ds.List_Colors = ls_list_colors; list_dsegment.Add(ds); //ls_bt.Dispose(); } ls_dp.Zoom_DisPlayMultiplier = 0.5f; ls_dp.Zoom_DisPlay = true; ls_dp.DSegments = list_dsegment; //将segment对应的设置到particle中 //并对DParticle相关信息进行计算 ls_dp.Rect = ls_dp.GetRectFromDSegment(); ls_dp.GPath = ls_dp.GetRegionFromDSegments(); ls_dp.SmallRect = ls_dp.GetSmallRectangleFromRect(); //将每个颗粒添加到颗粒分布图中的列表中 m_list_baseobject.Add(ls_dp); } } } /// /// 根据颗粒排序图获取已经选择上的颗粒,返回被选择上的颗粒的列表 /// /// public List GetSelectedParticleList_ForDrawDistrbutionSortImage() { List ls_list_cotsparticleclr = new List(); //防止为空校验判断 if (m_ReportFun.m_list_OTSField == null) { return ls_list_cotsparticleclr; } //先取出,所有被选择的dparticle列表的 List ls_list_dp = new List(); foreach (SortParticleDistribution spd in m_list_sortparticledistribution) { foreach (DParticle ls_dp in spd.List_DParticle) { if (ls_dp.Operator == ParticleOperator.SELECTED) { ls_list_dp.Add(ls_dp); } } } //并开始查找包含tagid和fieldid的cotsparticle的对象,保存到list当中 for (int i = 0; i < ls_list_dp.Count(); i++) { for (int j = 0; j < m_ReportFun.m_list_OTSField.Count(); j++) { //先获取该field中的所有particle List list_cotsparticleclr = new List(); list_cotsparticleclr = m_ReportFun.m_list_OTSField[j].ParticleList; for (int k = 0; k < list_cotsparticleclr.Count(); k++) { if (list_cotsparticleclr[k].ParticleId == ls_list_dp[i].CLRTagID && list_cotsparticleclr[k].FieldId == ls_list_dp[i].CLRFieldID) { //将cotsparticleclr保存到list当中 ls_list_cotsparticleclr.Add(list_cotsparticleclr[k]); } } } } return ls_list_cotsparticleclr; } #endregion #region 获取数据及初始化数据等 private void ClassifyDParticleGrid() { //-------------------这里开始对分布图的颗粒信息,位置大小等重新进行计算----------------------------------------------------- //初始化分栏的大小,及多少个分栏。 //模拟数据,分别将<=1和>1 and <=2和 >2 and <=3的颗粒数据分成三组,进行显示 SortParticleDistribution sortparticledistribution = new SortParticleDistribution(); sortparticledistribution.RectF = new RectangleF(this.ClientRectangle.X, this.ClientRectangle.Y, 800, this.ClientRectangle.Height); sortparticledistribution.ShowStr = "AAAA的颗粒[尺寸<=1的颗粒]"; sortparticledistribution.Size_Min = 0; sortparticledistribution.Size_Max = 1; SortParticleDistribution sortparticledistribution2 = new SortParticleDistribution(); sortparticledistribution2.RectF = new RectangleF(this.ClientRectangle.X, this.ClientRectangle.Y, 800, this.ClientRectangle.Height); sortparticledistribution2.ShowStr = "BBBBB的颗粒[尺寸<2的颗粒]"; sortparticledistribution2.Size_Min = 0; sortparticledistribution2.Size_Max = 1; SortParticleDistribution sortparticledistribution3 = new SortParticleDistribution(); sortparticledistribution3.RectF = new RectangleF(this.ClientRectangle.X, this.ClientRectangle.Y, 800, this.ClientRectangle.Height); sortparticledistribution3.ShowStr = "CCCCC的颗粒[尺寸<3的颗粒]"; sortparticledistribution3.Size_Min = 0; sortparticledistribution3.Size_Max = 1; //筛选并进行装载 foreach (DParticle ls_dp in m_list_baseobject) { if (ls_dp.Zoom_DisPlayMultiplier <= 1f) { DParticle sort_dp = ls_dp.Clone() as DParticle; sort_dp.Rect = sort_dp.GetRectFromDSegment(); sortparticledistribution.List_DParticle.Add(sort_dp); } if (ls_dp.Zoom_DisPlayMultiplier > 1f && ls_dp.Zoom_DisPlayMultiplier <= 1.5f) { DParticle sort_dp = ls_dp.Clone() as DParticle; sort_dp.Rect = sort_dp.GetRectFromDSegment(); sortparticledistribution2.List_DParticle.Add(sort_dp); } if (ls_dp.Zoom_DisPlayMultiplier > 1.5f && ls_dp.Zoom_DisPlayMultiplier <= 2f) { DParticle sort_dp = ls_dp.Clone() as DParticle; sort_dp.Rect = sort_dp.GetRectFromDSegment(); sortparticledistribution3.List_DParticle.Add(sort_dp); } } //这里计算每个Grid所在的坐标位置,第二个跟在第一个y轴下面,第三个跟在第二个y轴下面,依此类推 sortparticledistribution.RectF = new RectangleF(sortparticledistribution.RectF.X, sortparticledistribution.RectF.Y, sortparticledistribution.RectF.Width, sortparticledistribution.GetSortGridHeight()); sortparticledistribution2.RectF = new RectangleF(sortparticledistribution2.RectF.X, sortparticledistribution.RectF.Y + sortparticledistribution.RectF.Height + sortparticledistribution2.RectF.Y - 10,/*-5是为了分栏边框不开缝*/ sortparticledistribution2.RectF.Width, sortparticledistribution2.GetSortGridHeight()); sortparticledistribution3.RectF = new RectangleF(sortparticledistribution3.RectF.X, sortparticledistribution2.RectF.Y + sortparticledistribution2.RectF.Height + sortparticledistribution3.RectF.Y - 10, sortparticledistribution3.RectF.Width, sortparticledistribution3.GetSortGridHeight()); m_list_sortparticledistribution.Clear(); m_old_list_sortparticledistribution.Clear(); m_list_sortparticledistribution.Add(sortparticledistribution); m_list_sortparticledistribution.Add(sortparticledistribution2); m_list_sortparticledistribution.Add(sortparticledistribution3); //分类完成后,对颗粒重新进行摆放,包括重新计算里面的线,和计算里面多边形的外矩形,+号位置等 sortparticledistribution.SortDParticle(m_f_zoom_record); sortparticledistribution2.SortDParticle(m_f_zoom_record); sortparticledistribution3.SortDParticle(m_f_zoom_record); //记录原值,从这里继续,clone未完成 foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution) { SortParticleDistribution old_sortparticledistribution = ls_sortparticledistribution.Clone() as SortParticleDistribution; m_old_list_sortparticledistribution.Add(old_sortparticledistribution); foreach (DParticle ls_dp in old_sortparticledistribution.List_DParticle) { ls_dp.Rect = ls_dp.GetRectFromDSegment(); } } //--------------------------------分类排序颗粒结束----------------------------------------------------- } /// /// 获取随机的颜色 /// /// public Color GetRandomColor() { int R = new Random((int)DateTime.Now.Ticks).Next(255); int G = new Random((int)DateTime.Now.Ticks).Next(255); int B = new Random((int)DateTime.Now.Ticks).Next(255); B = (R + G > 400) ? R + G - 400 : B;//0 : 380 - R - G; B = (B > 255) ? 255 : B; return Color.FromArgb(R, G, B); } /// /// 随机获取一个多边形 /// /// /// /// /// /// public DParticle GetRondemDParticle(int x, int y, int width, int height, int r) { DParticle ls_dp = new DParticle(); for (int i = 0; i < height; i++) { DSegment ls_ds = new DSegment(); ls_ds.Color = GetRandomColor(); //随机生成x坐标偏移,和宽度 Random rd = new Random((int)DateTime.Now.Ticks); int a = rd.Next(1); if (a == 0) { int n = rd.Next(r); x = x + n; width = width + n; } else { int n = rd.Next(r); x = -+n; width = width - n; } ls_ds.Rect = new Rectangle(x, y + i, width, 1);//高度是1的线段 ls_dp.DSegments.Add(ls_ds); } return ls_dp; } #endregion #region 设置双缓冲 /// /// 设置双缓冲 /// public void SetDoubleBufferByIsDraw() { SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景. this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); // 双缓冲 SetStyle(ControlStyles.UserMouse, true);//执行自己的鼠标行为,这个打开后,在win7下鼠标操作明显改善 } #endregion #region 绘制函数 protected override void OnPaint(PaintEventArgs e)//处理重绘情况 { #region //填充个背景色矩形----------------------------------------------- foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution) { SolidBrush b = new SolidBrush(Color.White); e.Graphics.FillRectangle(b, ls_sortparticledistribution.RectF); //绘制矩形的外边框 ControlPaint.DrawBorder(e.Graphics, Rectangle.Round(ls_sortparticledistribution.RectF), m_c_ColumnRectangleColor, 3, ButtonBorderStyle.Solid, m_c_ColumnRectangleColor, 3, ButtonBorderStyle.Solid, m_c_ColumnRectangleColor, 3, ButtonBorderStyle.Solid, m_c_ColumnRectangleColor, 3, ButtonBorderStyle.Solid); } #endregion #region //计算并进行绘制部份------------------------------------ //绘制完缩放的图形后,将基数变回,否则会一直刷新无限变大变小 if (m_f_widthandheight_js != 0) { foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution) { //缩放完成,重新计算颗粒的矩形,和边缘路径,这里应该写成,判断 如果有进行了缩放的操作后,再进行重新的计算 foreach (BaseObject item in ls_sortparticledistribution.List_DParticle) { DParticle dp = (DParticle)item; //获取矩形的rectangle dp.Rect = dp.GetRectFromDSegment(); //通过line获取路径边缘 dp.GPath = dp.GetRegionFromDSegments(); //重新计算小矩形边框 dp.SmallRect = dp.GetSmallRectangleFromRect(); } } m_f_widthandheight_js = 0; } foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution) { //开始向下传递并进行绘制 foreach (BaseObject item in ls_sortparticledistribution.List_DParticle) { DParticle dp = (DParticle)item; if (dp.Operator != ParticleOperator.DELETED) { if (dp.Operator == ParticleOperator.DISPLAY) { item.OnPaint(e); } } } } #endregion #region //判断是否使用了矩形或圆形工具进行多选,是的话,那么这里就开始绘制------------------------ if (true == m_is_multiselect_onpaint) { if (true == m_is_multiselect_rectangle && m_multiselect_rect.Width > 0 && m_multiselect_rect.Height > 0) { Graphics g = e.Graphics; //绘制矩形 g.DrawRectangle(new Pen(Color.Blue), m_multiselect_rect.X, m_multiselect_rect.Y, m_multiselect_rect.Width, m_multiselect_rect.Height); //半透明画刷 SolidBrush brush = new SolidBrush(Color.FromArgb(50, Color.SkyBlue)); //填充选择矩形 g.FillRectangle(brush, m_multiselect_rect.X, m_multiselect_rect.Y, m_multiselect_rect.Width, m_multiselect_rect.Height); } if (true == m_is_multiselect_ellipse && m_multiselect_rect.Width > 0 && m_multiselect_rect.Height > 0) { Graphics g = e.Graphics; //绘制圆形 g.DrawEllipse(new Pen(Color.Blue), m_multiselect_rect.X, m_multiselect_rect.Y, m_multiselect_rect.Width, m_multiselect_rect.Height); //半透明画刷 SolidBrush brush = new SolidBrush(Color.FromArgb(50, Color.SkyBlue)); //填充选择圆形 g.FillEllipse(brush, m_multiselect_rect.X, m_multiselect_rect.Y, m_multiselect_rect.Width, m_multiselect_rect.Height); } } #endregion #region 分栏Grid的标签文本透明文字实现 foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution) { SolidBrush b = new SolidBrush(Color.White); string str_show = ls_sortparticledistribution.ShowStr; SizeF sif = e.Graphics.MeasureString(str_show, new Font("宋体", 9)); e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(125, m_c_ColumnRectangleColor)), ls_sortparticledistribution.RectF.X + ls_sortparticledistribution.RectF.Width - sif.Width - 3, ls_sortparticledistribution.RectF.Y, sif.Width, sif.Height + 3); e.Graphics.DrawString(str_show, new Font("宋体", 9), new SolidBrush(Color.Black), ls_sortparticledistribution.RectF.X + ls_sortparticledistribution.RectF.Width - sif.Width - 3, ls_sortparticledistribution.RectF.Y + 3); } #endregion } #endregion #region 鼠标操作相关事件 protected override void OnMouseWheel(MouseEventArgs e) { if (m_CtrlKeyDown == true) { if (e.Delta > 0) { ZoomIn(); } else { ZoomOut(); } } else { foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution) { foreach (BaseObject item in ls_sortparticledistribution.List_DParticle) { DParticle dp = (DParticle)item; foreach (DSegment ds in dp.DSegments) { ds.Rect = new RectangleF( ds.Rect.X, //获取到原先点与移动点的增减量,+原先的x坐标,就是新的坐标 ds.Rect.Y + e.Delta / 2, ds.Rect.Width, ds.Rect.Height); } //获取矩形的rectangle dp.Rect = dp.GetRectFromDSegment(); if (dp.Rect.Left < -60 || dp.Rect.Right > this.Width +60|| dp.Rect.Top < -60 || dp.Rect.Bottom > this.Height+60) { dp.Operator = ParticleOperator.NODISPLAY; } else { dp.Operator = ParticleOperator.DISPLAY; } } } foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution) { ls_sortparticledistribution.RectF = new RectangleF(ls_sortparticledistribution.RectF.Location.X, ls_sortparticledistribution.RectF.Location.Y + e.Delta / 2, ls_sortparticledistribution.RectF.Width, ls_sortparticledistribution.RectF.Height); } } Invalidate(); } /// /// 放大 /// private void ZoomIn() { #region //图形缩放计算部份-------放大------------//是放大 m_f_widthandheight_js = m_f_zoom_increment; for (int x = 0; x < m_list_sortparticledistribution.Count(); x++) { SortParticleDistribution ls_sortparticledistribution = m_list_sortparticledistribution[x]; SortParticleDistribution old_ls_sortparticledstribution = m_old_list_sortparticledistribution[x]; //先计算Grid的背景矩形 ls_sortparticledistribution.RectF = new RectangleF(ls_sortparticledistribution.RectF.X + old_ls_sortparticledstribution.RectF.X * m_f_zoom_increment, ls_sortparticledistribution.RectF.Y + old_ls_sortparticledstribution.RectF.Y * m_f_zoom_increment, ls_sortparticledistribution.RectF.Width + Convert.ToInt32(old_ls_sortparticledstribution.RectF.Width * m_f_zoom_increment), ls_sortparticledistribution.RectF.Height + Convert.ToInt32(old_ls_sortparticledstribution.RectF.Height * m_f_zoom_increment)); for (int y = 0; y < ls_sortparticledistribution.List_DParticle.Count(); y++) { DParticle ls_dp = ls_sortparticledistribution.List_DParticle[y]; DParticle old_ls_dp = m_old_list_sortparticledistribution[x].List_DParticle[y]; for (int z = 0; z < ls_dp.DSegments.Count(); z++) { DSegment ds = ls_dp.DSegments[z]; DSegment old_ds = old_ls_dp.DSegments[z]; ds.PenWidthAndHeight = ds.PenWidthAndHeight + old_ds.PenWidthAndHeight * m_f_zoom_increment; ds.Rect = new RectangleF(ds.Rect.X + old_ds.Rect.X * m_f_zoom_increment, ds.Rect.Y + old_ds.Rect.Y * m_f_zoom_increment, ds.Rect.Width + old_ds.Rect.Width * m_f_zoom_increment, ds.Rect.Height + old_ds.Rect.Height * m_f_zoom_increment); } //设置缩放到多少倍时进行显示 if (ls_dp.Zoom_DisPlayMultiplier <= m_f_zoom_record) { ls_dp.Zoom_DisPlay = true; } else { ls_dp.Zoom_DisPlay = false; } } } m_f_zoom_record = m_f_zoom_record + m_f_zoom_increment; m_f_zoom_record = float.Parse(m_f_zoom_record.ToString("#0.0")); //四舍五入,保留一位小数,如果不这样,float会不附合规则 #endregion #region 计算标尺尺寸部份-----放大------ m_f_ruler_size = m_f_ruler_size + Convert.ToInt32(m_f_old_ruler_size * m_f_zoom_increment); control_Ruler1.SetValue(m_f_ruler_size, m_f_onepixel_size); #endregion } /// /// 缩小 /// private void ZoomOut() { #region //图形缩放计算部份------缩小-------------------- m_f_widthandheight_js = -m_f_zoom_increment; for (int x = 0; x < m_list_sortparticledistribution.Count(); x++) { SortParticleDistribution ls_sortparticledistribution = m_list_sortparticledistribution[x]; SortParticleDistribution old_ls_sortparticledistribution = m_old_list_sortparticledistribution[x]; //先计算Grid的背景矩形 ls_sortparticledistribution.RectF = new RectangleF(ls_sortparticledistribution.RectF.X + old_ls_sortparticledistribution.RectF.X * -m_f_zoom_increment, ls_sortparticledistribution.RectF.Y + old_ls_sortparticledistribution.RectF.Y * -m_f_zoom_increment, ls_sortparticledistribution.RectF.Width + Convert.ToInt32(old_ls_sortparticledistribution.RectF.Width * -m_f_zoom_increment), ls_sortparticledistribution.RectF.Height + Convert.ToInt32(old_ls_sortparticledistribution.RectF.Height * -m_f_zoom_increment)); for (int y = 0; y < ls_sortparticledistribution.List_DParticle.Count(); y++) { DParticle ls_dp = ls_sortparticledistribution.List_DParticle[y]; DParticle old_ls_dp = m_old_list_sortparticledistribution[x].List_DParticle[y]; for (int z = 0; z < ls_dp.DSegments.Count(); z++) { DSegment ds = ls_dp.DSegments[z]; DSegment old_ds = old_ls_dp.DSegments[z]; ds.PenWidthAndHeight = ds.PenWidthAndHeight + old_ds.PenWidthAndHeight * -m_f_zoom_increment; ds.Rect = new RectangleF(ds.Rect.X + old_ds.Rect.X * -m_f_zoom_increment, ds.Rect.Y + old_ds.Rect.Y * -m_f_zoom_increment, ds.Rect.Width + old_ds.Rect.Width * -m_f_zoom_increment, ds.Rect.Height + old_ds.Rect.Height * -m_f_zoom_increment); } //设置缩放到多少倍时进行显示 if (ls_dp.Zoom_DisPlayMultiplier <= m_f_zoom_record) { ls_dp.Zoom_DisPlay = true; } else { ls_dp.Zoom_DisPlay = false; } } } m_f_zoom_record = m_f_zoom_record - m_f_zoom_increment; m_f_zoom_record = float.Parse(m_f_zoom_record.ToString("#0.0")); //四舍五入,保留一位小数,如果不这样,float会不附合规则 #endregion #region 计算标尺尺寸部份-----缩小------f_onepixel_size,是不是该乘以rulerwidth是实际的长度 m_f_ruler_size = m_f_ruler_size + Convert.ToInt32(m_f_old_ruler_size * -m_f_zoom_increment); control_Ruler1.SetValue(m_f_ruler_size, m_f_onepixel_size); #endregion } private void Control_DrawDistrbutionSortImage_KeyDown(object sender, KeyEventArgs e) { //判断是否按下了ctrl键 if (e.KeyCode == Keys.ControlKey) { m_CtrlKeyDown = true; } } private void Control_DrawDistrbutionSortImage_KeyUp(object sender, KeyEventArgs e) { //判断是否按下了ctrl键 if (e.KeyCode == Keys.ControlKey) { m_CtrlKeyDown = false; } } protected override void OnMouseDown(MouseEventArgs e) { if (e.Button == MouseButtons.Left) { this.Cursor = Cursors.Hand; //是否可以按矩形进行选取,如果选择了矩形或圆形多选后 if (true == m_is_multiselect_rectangle || true == m_is_multiselect_ellipse) { m_multiselect_rect.Width = 0; m_multiselect_rect.Height = 0; m_is_multiselect_onpaint = true; m_beforemultiselect_point = e.Location; } //在进行多选时,不让其拖动 if (false == m_is_multiselect_onpaint) { foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution) { foreach (DParticle ls_dp in ls_sortparticledistribution.List_DParticle) { ls_dp.IsDragging = true; ls_dp.DraggingPoint = e.Location; } } } m_isDrag = true; m_beforedrag_pointf = e.Location; } Invalidate(); } protected override void OnMouseUp(MouseEventArgs e) { if (e.Button == MouseButtons.Left) { this.Cursor = Cursors.Default; //还原多选变量 if (true == m_is_multiselect_onpaint) { //首先清除掉所有已经选择的项 foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution) { foreach (DParticle dp in ls_sortparticledistribution.List_DParticle) { if (dp.Operator == ParticleOperator.SELECTED) { dp.Operator = ParticleOperator.DISPLAY; } } } //然后在这里判断都有哪些颗粒所有的point点,是否在选取的图形graphicsPath闭合路径中 //首先先将选取的图形填充成graphicsPath if (m_multiselect_rect.Width > 0 && m_multiselect_rect.Height > 0) { GraphicsPath ls_gpath = new GraphicsPath(); ls_gpath.AddRectangle(m_multiselect_rect); foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution) { foreach (DParticle dp in ls_sortparticledistribution.List_DParticle) { if (dp.Operator != ParticleOperator.NODISPLAY && dp.Operator != ParticleOperator.DELETED)//不显示的和删除状态的不让进行选择 { PointF[] lspointf = dp.GPath.PathPoints; for (int i = 0; i < lspointf.Count(); i++) { if (true == m_ReportFun.WhetherInRange(dp, lspointf[i])) { //选择到了该路径,那么就选取该图像 dp.Operator = ParticleOperator.SELECTED; } } } } } } //这里恢复默认值 m_multiselect_rect.Width = 0; m_multiselect_rect.Height = 0; m_is_multiselect_onpaint = false; m_is_multiselect_ellipse = false; m_is_multiselect_rectangle = false; //将排列图选择的颗粒传送给报告框架中 SelectParticleListSendToReportFrame(); } //在进行多选时,不让其拖动 if (false == m_is_multiselect_onpaint) { foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution) { foreach (BaseObject item in ls_sortparticledistribution.List_DParticle) { if (true == item.IsDragging) { item.IsSelect = false; item.IsDragging = false; item.DraggingPoint = Point.Empty; } } } m_isDrag = false; //在颗粒上点击,则对该颗粒附加显示x-ray的状态,同时将其它颗粒上显示x-ray的状态全部去掉。 if (false == m_isDrag) { foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution) { foreach (DParticle dp in ls_sortparticledistribution.List_DParticle) { PointF[] lspointf = dp.GPath.PathPoints; if (true ==m_ReportFun. WhetherInRange(dp, new Point(e.X, e.Y))) { //选择到了该路径,那么就选取该图像b dp.Operator_ShowXRay = ParticleOperatorShowXray.SELECTANDDISPLAYXRAY; } else { dp.Operator_ShowXRay = ParticleOperatorShowXray.NODISPLAY; } } } } } } //右键菜单控件 CMenuStrip.Items[0].Tag = ""; CMenuStrip.Items[0].Enabled = false; CMenuStrip.Items[1].Tag = ""; CMenuStrip.Items[1].Enabled = false; CMenuStrip.Items[2].Tag = ""; CMenuStrip.Items[2].Enabled = false; CMenuStrip.Items[3].Tag = ""; CMenuStrip.Items[3].Enabled = false; CMenuStrip.Items[4].Tag = ""; CMenuStrip.Items[4].Enabled = false; if (e.Button == MouseButtons.Right) { //这个判断右键菜单加在这里,也不知道对不对 foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution) { foreach (BaseObject item in ls_sortparticledistribution.List_DParticle) { if (true == m_ReportFun.WhetherInRange((DParticle)item, e.Location)) { DParticle dp = (DParticle)item; if (dp.Operator == ParticleOperator.DISPLAY || dp.Operator == ParticleOperator.SELECTED) { CMenuStrip.Items[0].Enabled = true; CMenuStrip.Items[0].Tag = dp; CMenuStrip.Items[1].Enabled = true; if (dp.Operator == ParticleOperator.SELECTED) { CMenuStrip.Items[1].Text = "取消颗粒选择"; } else { CMenuStrip.Items[1].Text = "选择颗粒"; } CMenuStrip.Items[2].Enabled = true; CMenuStrip.Items[3].Enabled = true; //线程未执行完成,则不让再进行选择,右键移动到SEM位置的菜单选项 if (m_mythread_state == false) CMenuStrip.Items[4].Enabled = true; else CMenuStrip.Items[4].Enabled = false; m_sem_mouse_now_point = new Point(dp.SEMPosX, dp.SEMPosY); m_str_mouseshow_left = "颗粒SEM位置:" + dp.SEMPosX.ToString() + ":" + dp.SEMPosY.ToString(); //获取颜色方法1,使用API来获取当前鼠标指向位置的颜色值------------------------------------------- Graphics g = Graphics.FromHwnd(this.Handle); IntPtr hdc = g.GetHdc(); uint u_color = 0; try { u_color = DrawFunction.GetPixel(hdc, e.X, e.Y); } catch { } Color ls_c = Color.FromArgb ( (int)(u_color << 24 >> 24), (int)(u_color << 16 >> 24), (int)(u_color << 8 >> 24) ); m_str_mouseshow_right = "灰度#" + ls_c.R.ToString(); // 这里发送消息 m_ReportApp.mouseMatter.Text = m_str_mouseshow_right; m_ReportApp.RSGrayVal.Text = m_str_mouseshow_left; } } } } } //Invalidate(); } protected override void OnMouseMove(MouseEventArgs e) { //如果是进行多选的话 if (true == m_is_multiselect_onpaint) { if (e.Location.X > m_beforemultiselect_point.X && e.Location.Y > m_beforemultiselect_point.Y) { //右下拖动 m_multiselect_rect = new RectangleF(m_beforemultiselect_point, new SizeF(e.Location.X - m_beforemultiselect_point.X, e.Location.Y - m_beforemultiselect_point.Y)); } if (e.Location.X < m_beforemultiselect_point.X && e.Location.Y < m_beforemultiselect_point.Y) { //左上拖动 PointF lspointf = new PointF(e.Location.X, e.Location.Y); m_multiselect_rect = new RectangleF(lspointf, new SizeF(m_beforemultiselect_point.X - e.Location.X, m_beforemultiselect_point.Y - e.Location.Y)); } if (e.Location.X > m_beforemultiselect_point.X && e.Location.Y < m_beforemultiselect_point.Y) { //右上,这种画法,需要将左下,右上两点转换成左上,右下 PointF left_pointf = new PointF(m_beforemultiselect_point.X, e.Location.Y); PointF right_pointf = new PointF(e.Location.X, m_beforemultiselect_point.Y); m_multiselect_rect = new RectangleF(left_pointf, new SizeF(right_pointf.X - left_pointf.X, right_pointf.Y - left_pointf.Y)); } if (e.Location.X < m_beforemultiselect_point.X && e.Location.Y > m_beforemultiselect_point.Y) { //左下,这种画法,需要将左下,右上两点转换成左上,右下 PointF left_pointf = new PointF(e.Location.X, m_beforemultiselect_point.Y); PointF right_pointf = new PointF(m_beforemultiselect_point.X, e.Location.Y); m_multiselect_rect = new RectangleF(left_pointf, new SizeF(right_pointf.X - left_pointf.X, right_pointf.Y - left_pointf.Y)); } } //判断没有在进行多选状态时,在进行多选时,不让其拖动 if (false == m_is_multiselect_onpaint) { foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution) { foreach (BaseObject item in ls_sortparticledistribution.List_DParticle) { DParticle dp = (DParticle)item; //在计算前,先重新对颗粒的边缘进行计算,防止错误 dp.GPath = dp.GetRegionFromDSegments(); if (true == m_ReportFun.WhetherInRange(dp, e.Location)) { if (dp.Operator == ParticleOperator.DISPLAY) { dp.IsMouseMove = true; //显示xray图 if (control_XRayTable1.Visible == false) ShowXRay(dp); } } else { dp.IsMouseMove = false; //移动在颗粒外面时,要判断,Operator_ShowXray不为选下显示XRAY时,才对XRay进行隐藏 if (dp.Operator_ShowXRay != ParticleOperatorShowXray.SELECTANDDISPLAYXRAY) { //隐藏x-ray能谱图 HideXRay(dp); } } if (true == item.IsDragging) { //再将里面的线也进行计算坐标 foreach (DSegment ds in dp.DSegments) { ds.Rect = new RectangleF( ds.Rect.X + e.X - item.DraggingPoint.X, //获取到原先点与移动点的增减量,+原先的x坐标,就是新的坐标 ds.Rect.Y + e.Y - item.DraggingPoint.Y, ds.Rect.Width, ds.Rect.Height); ds.DraggingPoint = e.Location; } item.DraggingPoint = e.Location; //获取矩形的rectangle dp.Rect = dp.GetRectFromDSegment(); //通过line获取路径边缘 dp.GPath = dp.GetRegionFromDSegments(); //重新计算小矩形边框 dp.SmallRect = dp.GetSmallRectangleFromRect(); if (dp.Rect.Left < 0 || dp.Rect.Right > this.Width || dp.Rect.Top < 0 || dp.Rect.Bottom > this.Height) { dp.Operator = ParticleOperator.NODISPLAY; } } } } //如果在拖动中 if (true == m_isDrag) { //同样重新计算backrectf的坐标 foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution) { ls_sortparticledistribution.RectF = new RectangleF(ls_sortparticledistribution.RectF.Location.X + e.X - m_beforedrag_pointf.X, ls_sortparticledistribution.RectF.Location.Y + e.Y - m_beforedrag_pointf.Y, ls_sortparticledistribution.RectF.Width, ls_sortparticledistribution.RectF.Height); } m_beforedrag_pointf = e.Location; } } #region 向报告程序右下角,传送鼠标颗粒等相关信息 //然后这里还要将鼠标移动经过的过程,传输给reportapp中,为了能让reportapp能显示出来 //如果前面鼠标没有移动到颗粒的位置上,str_mouseshow_left=="",所以再取显示鼠标的位置信息 m_str_mouseshow_left = "无"; foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution) { foreach (BaseObject item in ls_sortparticledistribution.List_DParticle) { DParticle dp = (DParticle)item; if (true == m_ReportFun.WhetherInRange(dp, e.Location)) { if (dp.Operator == ParticleOperator.DISPLAY) { m_sem_mouse_now_point = new Point(dp.SEMPosX, dp.SEMPosY); m_str_mouseshow_left = "颗粒SEM位置:" + dp.SEMPosX.ToString() + ":" + dp.SEMPosY.ToString(); } } } } //获取颜色方法1,使用API来获取当前鼠标指向位置的颜色值------------------------------------------- Graphics g = Graphics.FromHwnd(this.Handle); IntPtr hdc = g.GetHdc(); uint u_color = 0; try { u_color = DrawFunction.GetPixel(hdc, e.X, e.Y); } catch { } Color ls_c = Color.FromArgb ( (int)(u_color << 24 >> 24), (int)(u_color << 16 >> 24), (int)(u_color << 8 >> 24) ); m_str_mouseshow_right = "灰度#" + ls_c.R.ToString(); // 这里发送消息 m_ReportApp.mouseMatter.Text = m_str_mouseshow_right; m_ReportApp.RSGrayVal.Text = m_str_mouseshow_left; #endregion Invalidate(); } #endregion #region 自定义功能函数 /// /// 复制图像 /// private void CopyImage() { int height, width; width = this.Width; height = this.Height; Bitmap image = new Bitmap(width, height); this.DrawToBitmap(image, new Rectangle(0, 0, width, height)); Clipboard.SetImage(image); } /// /// 移动SEM到指定位置线程函数 /// private void Thread_GO(object in_obj) { if (m_mythread_state == false) { m_mythread_state = true; Point sem_point = (Point)in_obj; //第一步,连接电镜 m_ReportFun.ConnectToSEM(); Thread.Sleep(500); //第二步,移动到指定位置,先读取再设置 if (m_ReportFun.m_SEMConnectionState == true) { m_ReportFun.MoveSemToPointXY(sem_point.X, sem_point.Y); } Thread.Sleep(1500); //第三步,断开电镜连接 m_ReportFun.DisConnectSEM(); //Thread.Sleep(1000); m_mythread_state = false; } } /// /// 显示x-ray能谱图 /// /// private void ShowXRay(DParticle in_dparticle) { //显示xray相关信息 uint[] Search_xray = new uint[2000]; uint[] Analysis_xray = new uint[2000]; // int i_xray_id = 0; List list_celementchemistryclr = new List(); //获取Xray数据 m_ReportFun.GetXrayByParticleTagIDAndFieldID_ForDrawDistrbutionImageAndBSE(in_dparticle.CLRTagID, in_dparticle.CLRFieldID, out Search_xray, out Analysis_xray, out i_xray_id, out list_celementchemistryclr); //get CElementChemistryClr list List list_showelementinfo = new List(); for (int i = 0; i < list_celementchemistryclr.Count; i++) { ShowElementInfo ls_sei = new ShowElementInfo(); ls_sei.ElementName = list_celementchemistryclr[i].Name; ls_sei.Percentage = list_celementchemistryclr[i].Percentage; ls_sei.dKF = Convert.ToDouble(CListPeriodic.GetPeriodicByYsm(CListPeriodic.GetListPeriodic(), ls_sei.ElementName).SX1); list_showelementinfo.Add(ls_sei); } //获取使用标准库的名称,也许这个也不是很正确?? string str_stdname = ""; string str_IncALibName = ""; //List FLID = new List() { 0, 1, 2, 4, 6, 9 }; //List NameList = new List() { "过小颗粒", "过大颗粒", "亮度不在分析范围内的颗粒", "低计数率颗粒", "不含分析元素的颗粒", "未识别颗粒" }; //if (in_dparticle.STDTypeID < 1000) //{ // int index = FLID.IndexOf(in_dparticle.TypeId); // if (index == -1) // { // index = 5; // } // //小于1000,使用系统默认分类 // str_IncALibName = NameList[index]; // str_stdname = "默认标准库"; //} //else if (in_dparticle.STDTypeID >= 1000 && in_dparticle.STDTypeID < 10000) //{ // //大于等于1000,并且小于10000时,使用系统数据库中夹杂物来分析 // str_IncALibName = in_dparticle.TypeName; // str_stdname = "用户定义标准库"; //} //else if (in_dparticle.STDTypeID > 10000) //{ // //大于10000时,使用用户标准库来分析夹杂物名称 // str_IncALibName = in_dparticle.TypeName; // if (str_stdname == "") // str_stdname = "系统标准库"; //} //获取数据后,需要对xraytable设置 control_XRayTable1.Visible = false; control_XRayTable1.SetXRayShowLineValue(Search_xray, Analysis_xray, list_showelementinfo); //control_XRayTable1.GoodName = str_IncALibName + "(" + in_dparticle.STDTypeID.ToString() + ")";//杂夹物 control_XRayTable1.GoodName = str_IncALibName;//杂夹物 control_XRayTable1.STDName = str_stdname;//标准库 control_XRayTable1.List_ShowElementInfo = list_showelementinfo; control_XRayTable1.Visible = true; //将显示xray的dparticle记录给全局变量 m_move_dparticle = in_dparticle; this.Refresh(); } /// /// 隐藏x-ray能谱图 /// private void HideXRay(DParticle in_dparticle) { if (m_move_dparticle == null) return; else if (m_move_dparticle.ID == in_dparticle.ID) { //如果是刚才移动过的颗粒的话,那么这里再对xray进行隐藏 control_XRayTable1.Visible = false; } } /// /// 封装,将排列图中的颗粒list传送给报告项目框架中 /// private void SelectParticleListSendToReportFrame() { //先获取排列图中,有哪些颗粒已经被选择上了 m_ReportApp.SelectedParticles = GetSelectedParticleList_ForDrawDistrbutionSortImage(); } /// /// 设置当前对哪些颗粒进行设置为选择状态 /// /// public void SetSelectParticle(List in_list_cotsparticleclr) { if (in_list_cotsparticleclr == null) { return; } if (in_list_cotsparticleclr.Count == 0) { return; } foreach (SortParticleDistribution spd in m_list_sortparticledistribution) { foreach (DParticle ls_dp in spd.List_DParticle) { //只有显示状态,才可以切换到选择状态,考虑可能会出现如果在条件选择成不显示状态下,如果被选择了,是不是就强制切换成了选择状态 if (ls_dp.Operator == ParticleOperator.DISPLAY) { for (int i = 0; i < in_list_cotsparticleclr.Count; i++) { if (in_list_cotsparticleclr[i].ParticleId == ls_dp.CLRTagID && in_list_cotsparticleclr[i].FieldId == ls_dp.CLRFieldID) { ls_dp.Operator = ParticleOperator.SELECTED; } } } } } } /// /// 按框架传入的底层计算结果,重新对颗粒进行区分显示 /// /// public void Control_DrawDistrbutionSortImage_ByQuery(OTSIncAReportApp.OTSSampleReportInfo.OTSSampleMeaInfo in_list_cgriddataclr) { m_list_cgriddataclr = in_list_cgriddataclr; GetDistrbutionSortimage_ByQuery(in_list_cgriddataclr); } /// /// 颗粒排序图中的颗粒,重新组织显示颗粒排序规则 /// public void GetDistrbutionSortimage_ByQuery(OTSIncAReportApp.OTSSampleReportInfo.OTSSampleMeaInfo sourceGridData) { List FLNameList = new List(); //List FLID = new List() { -1,0, 1, 2, 4, 6, 7, 8, 9 }; List FLID = new List() { 0, 1, 2, 4, 6, 9, 10 }; List NameList = new List(); int fltype = 0; //先清除list m_list_sortparticledistribution.Clear(); m_old_list_sortparticledistribution.Clear(); m_f_zoom_record = 1; //------------------------------------分解结果内容部份------------------------------------ string display_type = ""; string con = ""; var list = sourceGridData.SampleDataList.Find(s => Convert.ToInt32(s.iItemId) == 4); string sort_type = list.itemVal.ToString(); int _type = list.comboDownList.IndexOf(sort_type); switch (_type) { case 0: fltype = 0; break; case 1: fltype = 1; break; case 2: fltype = 2; display_type = sourceGridData.SampleDataList.Find(s => Convert.ToInt32(s.iItemId) == 13).itemVal.ToString(); switch (display_type) { case "DMAX": con = "DMAX"; break; case "DMIN": con = "DMIN"; break; case "Area": con = "Area"; break; case "FERET": con = "DFERET"; break; } break; } string path = resultFile.FilePath; ParticleData particleData = new ParticleData(path); List particles = particleData.GetParticleListByCon("", "", "", 0); foreach (DParticle ls_dp in m_list_baseobject) { int dis = 0; foreach (Particle particle in particles) { //找到对应的颗粒,将分类设置进去 if (ls_dp.CLRTagID == particle.ParticleId && ls_dp.CLRFieldID == particle.FieldId) { if (!FLNameList.Contains(particle.TypeName) && particle.TypeName != "") { FLNameList.Add(particle.TypeName); } if (fltype == 0) { ls_dp.ParticleFL = particle.TypeId.ToString(); } if (fltype == 1) { ls_dp.ParticleFL = particle.TypeName.ToString(); } if (fltype == 2) { if (con == "DMAX") ls_dp.ParticleFL = particle.DMAX.ToString(); if (con == "DMIN") ls_dp.ParticleFL = particle.DMIN.ToString(); if (con == "Area") ls_dp.ParticleFL = particle.Area.ToString(); if (con == "DFERET") ls_dp.ParticleFL = particle.FERET.ToString(); } ls_dp.Operator = ParticleOperator.DISPLAY; dis = 1; break; } } if (dis == 0) { ls_dp.Operator = ParticleOperator.NODISPLAY; } } if (fltype == 0) { //NameList = new List() { table["partcletype0"].ToString(), table["partcletype1"].ToString(), table["partcletype2"].ToString(), table["partcletype4"].ToString(), table["partcletype6"].ToString(), table["partcletype7"].ToString(), table["partcletype8"].ToString(), table["partcletype9"].ToString(), table["partcletype10"].ToString() }; NameList = new List() { table["partcletype9"].ToString(), table["partcletype10"].ToString() }; } if (fltype == 1) { NameList = FLNameList; } if (fltype == 2) { //获取粒级表 string flpath = m_ReportApp.m_RptConfigFile.FileFolderSize + m_ReportApp.m_RptConfigFile.PartSizeFile; DataSet ds = XMLoperate.GetXml(flpath); string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString(); List sizeList = new List(); for (int i = 0; i < sizestr.Split(',').Length - 1; i++) { if (sizestr.Split(',')[i].Length > 0) { double d1 = Convert.ToDouble(sizestr.Split(',')[i]); double d2 = Convert.ToDouble(sizestr.Split(',')[i + 1]); sizeList.Add(d1.ToString() + "~" + d2.ToString()); } } double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]); sizeList.Add(d.ToString() + "~MAX"); NameList = sizeList; } //为颗粒排序图,创建分栏grid foreach (string name in NameList) { SortParticleDistribution sortparticledistribution = new SortParticleDistribution(); sortparticledistribution.RectF = new RectangleF(ClientRectangle.X, ClientRectangle.Y, 800, ClientRectangle.Height); sortparticledistribution.ShowStr = name;//设置分类grid m_list_sortparticledistribution.Add(sortparticledistribution); } //然后再重新将list_baseobject中的颗粒,分别添加到对应的sortgrid中 foreach (DParticle ls_dp in m_list_baseobject) { var sort = m_list_sortparticledistribution; for (int i = 0; i < sort.Count; i++) { if (fltype == 0) { if (ls_dp.STDTypeID == FLID[i]) { //将对应的颗粒添加到分栏grid中 DParticle sort_dp = ls_dp.Clone() as DParticle; sort_dp.Rect = sort_dp.GetRectFromDSegment(); sort[i].List_DParticle.Add(sort_dp); break; } else if (ls_dp.STDTypeID > 10000) { //将对应的颗粒添加到分栏grid中 DParticle sort_dp = ls_dp.Clone() as DParticle; sort_dp.Rect = sort_dp.GetRectFromDSegment(); sort[sort.Count - 1].List_DParticle.Add(sort_dp); break; } } else if (fltype == 1) { if (ls_dp.TypeName == NameList[i]) { //将对应的颗粒添加到分栏grid中 DParticle sort_dp = ls_dp.Clone() as DParticle; sort_dp.Rect = sort_dp.GetRectFromDSegment(); sort[i].List_DParticle.Add(sort_dp); break; } } else if (fltype == 2) { double min = Convert.ToDouble(NameList[i].Split('~')[0]); double max = 0; if (NameList[i].Split('~')[1].ToLower() != "max") { max = Convert.ToDouble(NameList[i].Split('~')[1]); } else { max = 999; } double size = Convert.ToDouble(ls_dp.ParticleFL); if (size <= max && size >= min) { //将对应的颗粒添加到分栏grid中 DParticle sort_dp = ls_dp.Clone() as DParticle; sort_dp.Rect = sort_dp.GetRectFromDSegment(); sort[i].List_DParticle.Add(sort_dp); break; } } } } //循环分栏grid,对各分栏grid进行摆放 for (int i = 0; i < m_list_sortparticledistribution.Count(); i++) { //计算y轴,的增量 float ls_height = 0; if (i == 0) { ls_height = 0; } else { ls_height = m_list_sortparticledistribution[i - 1].RectF.Y + m_list_sortparticledistribution[i - 1].RectF.Height - 10; } m_list_sortparticledistribution[i].RectF = new RectangleF( m_list_sortparticledistribution[i].RectF.X, m_list_sortparticledistribution[i].RectF.Y + ls_height, m_list_sortparticledistribution[i].RectF.Width, m_list_sortparticledistribution[i].GetSortGridHeight() + 50);//为每栏的高度增加了50补充,防止图像溢出 } //然后再重新对分栏grid中的颗粒,重新进行摆放 foreach (SortParticleDistribution ls_spd in m_list_sortparticledistribution) { ls_spd.SortDParticle(FZOOMRecord); } //最后,将分栏grid,分别存放到old的分栏grid中 foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution) { SortParticleDistribution old_sortparticledistribution = ls_sortparticledistribution.Clone() as SortParticleDistribution; m_old_list_sortparticledistribution.Add(old_sortparticledistribution); foreach (DParticle ls_dp in old_sortparticledistribution.List_DParticle) { ls_dp.Rect = ls_dp.GetRectFromDSegment(); } } } /// /// 判断该点是否在多边形的范围内 /// /// /// /// //private bool WhetherInRange(PointF[] inPoints, Point WhetherPoint) //{ // bool b_inrange = false; // GraphicsPath myGraphicsPath = new GraphicsPath(); // Region myRegion = new Region(); // myGraphicsPath.Reset(); // myGraphicsPath.AddPolygon(inPoints); // myRegion.MakeEmpty(); // myRegion.Union(myGraphicsPath); // //返回判断点是否在多边形里 // b_inrange = myRegion.IsVisible(WhetherPoint); // return b_inrange; //} ///// ///// 判断该点是否在多边形的范围内的float版本重载 ///// ///// ///// ///// //private bool WhetherInRange(PointF[] inPoints, PointF WhetherPoint) //{ // bool b_inrange = false; // GraphicsPath myGraphicsPath = new GraphicsPath(); // Region myRegion = new Region(); // myGraphicsPath.Reset(); // myGraphicsPath.AddPolygon(inPoints); // myRegion.MakeEmpty(); // myRegion.Union(myGraphicsPath); // //返回判断点是否在多边形里 // b_inrange = myRegion.IsVisible(WhetherPoint); // return b_inrange; //} /// /// 是否显示标尺控件,自动切换显示与不显示 /// /// public void ShowRulerControl() { control_Ruler1.Visible = !control_Ruler1.Visible; } /// /// 是否显示标尺控件,带参重载 /// /// public void ShowRulerControl(bool b_show) { control_Ruler1.Visible = b_show; } /// /// 设置显示BSE原图,还是显示排序图带有标准库的 /// /// false为显示原bse图像,true为显示带有标准库代表色的图像 public void ShowMode(bool in_b) { if (in_b == false) { foreach (SortParticleDistribution item in m_list_sortparticledistribution) { foreach (DParticle ls_dp in item.List_DParticle) { foreach (DSegment ls_ds in ls_dp.DSegments) { ls_ds.ShowMode = SegmentShowMode.DRAWPOINT; } } } } else { foreach (SortParticleDistribution item in m_list_sortparticledistribution) { foreach (DParticle ls_dp in item.List_DParticle) { foreach (DSegment ls_ds in ls_dp.DSegments) { ls_ds.ShowMode = SegmentShowMode.DRAWLINE; } } } } this.Invalidate(); } /// /// 对颗粒进行排序 /// /// /// 排序的方法,从小到到,小大到小 public void SortDParticleBySize(List in_list_baseobject, string str_sort) { List list_dp1 = new List(); foreach (DParticle ls_dp in in_list_baseobject) { DParticle dp1 = ls_dp.Clone() as DParticle; list_dp1.Add(dp1); } in_list_baseobject.Clear(); if (str_sort == "从小到大") { int icount = list_dp1.Count(); for (int i = 0; i < icount; i++) { float f_min_size = 10000000; string str_jlguid = ""; DParticle ls_dp = new DParticle(); foreach (DParticle ls_del_dp in list_dp1) { ls_del_dp.FSize = ls_del_dp.GetSizeFormSegmentsAllWidth(); if (f_min_size > ls_del_dp.FSize) { f_min_size = ls_del_dp.FSize; str_jlguid = ls_del_dp.ID; ls_dp = ls_del_dp; } } list_dp1.Remove(ls_dp); in_list_baseobject.Add(ls_dp); } } else if (str_sort == "从大到小") { int icount = list_dp1.Count(); for (int i = 0; i < icount; i++) { float f_max_size = 0; string str_jlguid = ""; DParticle ls_dp = new DParticle(); foreach (DParticle ls_del_dp in list_dp1) { ls_del_dp.FSize = ls_del_dp.GetSizeFormSegmentsAllWidth(); if (f_max_size < ls_del_dp.FSize) { f_max_size = ls_del_dp.FSize; str_jlguid = ls_del_dp.ID; ls_dp = ls_del_dp; } } list_dp1.Remove(ls_dp); ls_dp.Rect = ls_dp.GetRectFromDSegment(); in_list_baseobject.Add(ls_dp); } } } /// /// 是否进行矩形多选操作 /// public void MultiSelect_Rectangle() { if (m_is_multiselect_ellipse == true) { m_is_multiselect_ellipse = false; } m_is_multiselect_rectangle = true; } /// /// 是否进行圆形多选操作 /// public void MultiSelect_Ellipse() { if (m_is_multiselect_rectangle == true) { m_is_multiselect_rectangle = false; } m_is_multiselect_ellipse = true; } /// /// 对选择的多边形进行反选操作 /// public void ReverSeSelection() { foreach (SortParticleDistribution aag in m_list_sortparticledistribution) { foreach (DParticle dp in aag.List_DParticle) { if (ParticleOperator.DISPLAY == dp.Operator) { dp.Operator = ParticleOperator.SELECTED; } else if (ParticleOperator.SELECTED == dp.Operator) { dp.Operator = ParticleOperator.DISPLAY; } } } //将排列图选择的颗粒传送给报告框架中 SelectParticleListSendToReportFrame(); this.Invalidate(); } /// /// 取消所有的颗粒的选择状态 /// public void DeselectAllParticle() { foreach (SortParticleDistribution aag in m_list_sortparticledistribution) { foreach (DParticle dp in aag.List_DParticle) { if (ParticleOperator.SELECTED == dp.Operator) { dp.Operator = ParticleOperator.DISPLAY; } } } //将排列图选择的颗粒传送给报告框架中 SelectParticleListSendToReportFrame(); this.Invalidate(); } /// /// 将整个图像拷贝到内存中 /// public void CopyToBitmap() { Bitmap bp = new Bitmap(this.Size.Width, this.Size.Height); this.DrawToBitmap(bp, new Rectangle(0, 0, this.Size.Width, this.Size.Height)); Clipboard.SetImage(bp); } #endregion #region 鼠标菜单右键 private void ToolStripMenuItem_id_Click(object sender, EventArgs e) { //ID DParticle dp = (DParticle)CMenuStrip.Items[0].Tag; MessageBox.Show(dp.ID.ToString()); } private void ToolStripMenuItem_selected_Click(object sender, EventArgs e) { //选择 DParticle dp = (DParticle)CMenuStrip.Items[0].Tag; if (ParticleOperator.SELECTED == dp.Operator) { dp.Operator = ParticleOperator.DISPLAY; CMenuStrip.Items[1].Text = "选择颗粒"; control_XRayTable1.Visible = false; } else { dp.Operator = ParticleOperator.SELECTED; CMenuStrip.Items[1].Text = "取消颗粒选择"; } //将排列图选择的颗粒传送给报告框架中 SelectParticleListSendToReportFrame(); } private void ToolStripMenuItem_delete_Click(object sender, EventArgs e) { //删除颗粒 DParticle dp = (DParticle)CMenuStrip.Items[0].Tag; //同样,要在历史操作记录类中,添加记录,好可以进行撤消操作 HistoryApolygon hApolygon = new HistoryApolygon(); hApolygon.APolygonID = dp.ID; hApolygon.Operator = ParticleOperator.DELETED; hApolygon.OldOperator = dp.Operator; hApolygon.ID = m_list_historyapolygon.Count; m_list_historyapolygon.Add(hApolygon); m_operator_currentid = hApolygon.ID;//当前操作到的历史操作记录 //设置颗粒的状态为已经被删除 dp.Operator = ParticleOperator.DELETED; } private void ToolStripMenuItem_movesempoint_Click(object sender, EventArgs e) { //移动SEM到指定位置 if (m_mythread == null) { return; } if (m_mythread.ThreadState == ThreadState.Running || m_mythread.ThreadState == ThreadState.WaitSleepJoin) { return; } if (m_mythread.ThreadState == ThreadState.Stopped) { m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO)); } if (m_sem_mouse_now_point.X != 0 && m_sem_mouse_now_point.Y != 0) { //改为线程调用,先判断线程状态 m_mythread.Start(new Point(m_sem_mouse_now_point.X, m_sem_mouse_now_point.Y)); } } //复制图像 private void ToolStripMenuItem_copyimage_Click(object sender, EventArgs e) { CopyImage(); } //显示过小颗粒 private void ToolStripMenuItemShowSmallParticle_Click(object sender, EventArgs e) { if (bShowSmallParticle == false) { bShowSmallParticle = true; CMenuStrip.Items[6].Text = "不显示过小颗粒"; } else { bShowSmallParticle = false; CMenuStrip.Items[6].Text = "显示过小颗粒"; } //缩放的增大缩小的增量 m_f_zoom_increment = 0.1f; //缩放的基数,临时变量 m_f_widthandheight_js = 0; //与原先缩放的记录数 m_f_zoom_record = 1; //最大缩放倍数 m_f_zoom_max = 4f; //最小缩放倍数 m_f_zoom_mix = 0.5f; //标尺的大小记录 m_f_ruler_size = 100; //标尺原先大小的记录,参与计算 m_f_old_ruler_size = 100; //每像素代表的尺寸大小,还不知道在哪里进行计算 m_f_onepixel_size = 4.5f; //提供鼠标在右下角显示的文本,左侧 m_str_mouseshow_left = ""; //提供鼠标在右下角显示的文本,右侧 m_str_mouseshow_right = ""; //分栏网格边框的颜色 m_c_ColumnRectangleColor = Color.LightSteelBlue; //记录操作记录类 m_list_historyapolygon = null; //操作历史类,当前操作到的id m_operator_currentid = 0; m_list_baseobject = new List(); m_list_historyapolygon = new List(); m_list_sortparticledistribution = new List(); m_old_list_sortparticledistribution = new List(); m_mythread_state = false; m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO)); m_frm_userprogress = new Frm_UserProgress(); Control_DrawDistrbutionSortImage_Load(null, null); GetDistrbutionSortimage_ByQuery(m_list_cgriddataclr); } #endregion } }