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.Drawing; using System.Drawing.Drawing2D; using System.Linq; using System.Threading; using System.Windows.Forms; namespace OTSIncAReportGraph.Controls { public partial class Control_DrawDistrbutionSortImage : UserControl { #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; //日志文件名 const String m_csFileName = "OTSReportAppLog"; //底层封装类 OTSIncAReportFun m_OTSIncAReportFun = 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_KeyDownControl = 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_OTSIncAReportFun = new OTSIncAReportFun(this, 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); //设置鼠标为等待样式 //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()); //调用填充排序图颗粒数据,总过程方法 m_OTSIncAReportFun.GetDistrbutionSortImage_Total(m_ReportApp); //设置双缓冲 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(); } #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) 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) { //实现直接滚动,进行拖动,按下ctrl进行滚动,是缩放 if (e.Delta > 0) { if (m_KeyDownControl == false) { OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, e.X, e.Y, e.Delta)); OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, e.X, e.Y, e.Delta)); OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, e.X, e.Y + 30, e.Delta)); OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, e.X, e.Y, e.Delta)); } else { if (m_f_zoom_record <= m_f_zoom_max) { //放大 ZoomIn(); } } } else { if (m_KeyDownControl == false) { OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, e.X, e.Y, e.Delta)); OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, e.X, e.Y, e.Delta)); OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, e.X, e.Y - 30, e.Delta)); OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, e.X, e.Y, e.Delta)); } else { if (m_f_zoom_record >= m_f_zoom_mix) { //缩小 ZoomOut(); } } } 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_KeyDownControl = true; } } private void Control_DrawDistrbutionSortImage_KeyUp(object sender, KeyEventArgs e) { //判断是否按下了ctrl键 if (e.KeyCode == Keys.ControlKey) { m_KeyDownControl = 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 == WhetherInRange(ls_gpath.PathPoints, 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 == WhetherInRange(lspointf, 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 == WhetherInRange(item.GPath.PathPoints, 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; ////获取当前颗粒的OTS坐标 //Point ls_otspoint = m_OTSIncAReportFun.GetOTSPointFromOld_list_sortparticledistribution(dp.CLRFieldID, dp.CLRTagID, this); ////再将该OTS坐标转成SEM坐标 //Point ls_sempoint = m_OTSIncAReportFun.ChangeOTSToSemCoord(ls_otspoint); //m_sem_mouse_now_point = ls_sempoint; ////当移动到某个颗粒后,在屏幕右下角应该显示的是该颗粒的SEM坐标,而不显示鼠标位置 //m_str_mouseshow_left = "视域位置:" + ls_sempoint.X.ToString() + ":" + ls_sempoint.Y.ToString(); 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 = DrawFuncation.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 == WhetherInRange(dp.GPath.PathPoints, 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 (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 == WhetherInRange(dp.GPath.PathPoints, e.Location)) { if (dp.Operator == ParticleOperator.DISPLAY) { ////获取当前颗粒的OTS坐标 //Point ls_otspoint = m_OTSIncAReportFun.GetOTSPointFromOld_list_sortparticledistribution(dp.CLRFieldID, dp.CLRTagID, this); ////再将该OTS坐标转成SEM坐标 //Point ls_sempoint = m_OTSIncAReportFun.ChangeOTSToSemCoord(ls_otspoint); //m_sem_mouse_now_point = ls_sempoint; ////当移动到某个颗粒后,在屏幕右下角应该显示的是该颗粒的SEM坐标,而不显示鼠标位置 //m_str_mouseshow_left = "视域位置:" + ls_sempoint.X.ToString() + ":" + ls_sempoint.Y.ToString(); 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 = DrawFuncation.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_OTSIncAReportFun.ConnectToSEM(); Thread.Sleep(500); //第二步,移动到指定位置,先读取再设置 if (m_OTSIncAReportFun.m_SEMConnectionState == true) { m_OTSIncAReportFun.MoveSemToPointXY(sem_point.X, sem_point.Y); } Thread.Sleep(1500); //第三步,断开电镜连接 m_OTSIncAReportFun.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_OTSIncAReportFun.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 = m_OTSIncAReportFun.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; m_OTSIncAReportFun.GetDistrbutionSortimage_ByQuery(in_list_cgriddataclr); } /// /// 判断该点是否在多边形的范围内 /// /// /// /// 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 ReDo() { //如果已经是最后一条了,那么不可以再进行重做操作 if (m_list_historyapolygon.Count() < 1) return; HistoryApolygon hap = m_list_historyapolygon[m_operator_currentid]; foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution) { foreach (DParticle dp in ls_sortparticledistribution.List_DParticle) { if (hap.APolygonID == dp.ID) { dp.Operator = hap.Operator; } } } if (m_operator_currentid < m_list_historyapolygon.Count - 1) m_operator_currentid = m_operator_currentid + 1; } /// /// 撤消删除 /// public void UnDo() { //首先找到历史操作记录类最后一项,然后取出颗粒操作的id,及颗粒最后的操作类型,还原成oldoperator状态 if (m_list_historyapolygon.Count() < 1) return; HistoryApolygon hap = m_list_historyapolygon[m_operator_currentid]; foreach (SortParticleDistribution ls_sortparticledistribution in m_list_sortparticledistribution) { foreach (DParticle dp in ls_sortparticledistribution.List_DParticle) { if (hap.APolygonID == dp.ID) { dp.Operator = hap.OldOperator; } } } if (m_operator_currentid != 0) { m_operator_currentid = m_operator_currentid - 1; } } /// /// 是否显示标尺控件,自动切换显示与不显示 /// /// 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 SortApolygonBySize_FromBigToSmall() { SortDParticleBySize(m_list_baseobject, "从大到小"); m_f_zoom_increment = 0.1f; m_f_widthandheight_js = 0; m_f_zoom_record = 1; m_f_ruler_size = 100; ClassifyDParticleGrid(); } /// /// 从小到大对多边形进行排序 /// public void SortApolygonBySize_FromSmallToBig() { SortDParticleBySize(m_list_baseobject, "从小到大"); m_f_zoom_increment = 0.1f; m_f_widthandheight_js = 0; m_f_zoom_record = 1; m_f_ruler_size = 100; ClassifyDParticleGrid(); } //测试回头去掉,记录哪些颗粒被选择,保存成clr的list形式,回头需要时再传给底层 public void test_selected() { m_OTSIncAReportFun.GetSelectedParticleList_ForDrawDistrbutionSortImage(); } /// /// 是否进行矩形多选操作 /// 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 MultiSelect_Ban() { m_is_multiselect_ellipse = false; m_is_multiselect_rectangle = false; } /// /// 对选择的多边形进行反选操作 /// 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); m_OTSIncAReportFun.GetDistrbutionSortimage_ByQuery(m_list_cgriddataclr); } #endregion } }