using NLog;
using OTSCommon.Model;
using OTSIncAReportApp;
using OTSIncAReportApp._3_ServiceCenter;
using OTSIncAReportApp.DataOperation.DataAccess;
using OTSIncAReportApp.OTSSampleReportInfo;
using OTSIncAReportApp.SysMgrTools;
using OTSIncAReportGraph.Class;
using OTSIncAReportGraph.OTSIncAReportGraphFuncation;
using OTSIncAReportMailInterface;
using OTSRptPeriodicTable;
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using System.Windows.Media.Imaging;
using System.Xml;
namespace OTSIncAReportGraph.Controls
{
public enum SelectedShape
{
Rectangle=0,
Ellipse = 1
}
public struct SelectTool
{
public SelectedShape Shape;
public Point StartPoint;
public bool IsSelecting;
//进行选择的矩形范围
public RectangleF Rect ;
}
public struct ParticleSegmentation
{
public Point StartPoint;
public bool IsParticleSegmentation;
public Point EndPoint;
public Particle ParticleData;
}
public enum RightButtonMenu
{
Include=0,
MoveSEMToParticle=1,
CopyImage=2,
OriginalSplicing= 3,
DeleteParticle=4,
CopyDatabase=5,
ParticleSegmentation=6
}
///
/// 选择导出的图片是原图还是颗粒渲染后的图片
///
public enum Outpic_enum
{
pic=0,
Render_pic=1
}
public partial class Control_DrawDistrbutionImageAndBSE : UserControl
{
//缩放的增大缩小的增量
private const float const_zoom_increment = 0.05f;
//最大缩放倍数
private const float m_f_zoom_max = 4f;
//最小缩放倍数
private float m_f_zoom_mix = 0.05f;
//标尺原先大小的记录,参与计算
private const float m_f_old_ruler_size = 100;
//int m_operator_currentid;
double ls_d_cz_width;
double ls_d_cz_height;
#region 变量定义
private SelectTool m_SelectTool;
private ParticleSegmentation m_ParticleSegmentation;
//缩放的基数,临时变量
private float m_Zoom_Base = 0;
//与原先缩放的记录数
private float m_zoom_record = 1;
//标尺的大小记录
public float m_f_ruler_size = 100;
//每像素代表的尺寸大小,还不知道在哪里进行计算
public float m_pixelSize = 4.5f;
//国际化存储信息
System.Collections.Hashtable table;
//包含particle的field的列表对象
public List m_list_allDfield = null;
//这里要做成控件,不要是窗体
public List m_list_allDPart = null;
//总背景矩形
public RectangleF m_backRect = new RectangleF();
//记录原值,总背景矩形
public RectangleF m_old_backRect = new RectangleF();
//记录总物理矩形总大小
public RectangleF m_back_wl_rectf = new RectangleF();
//是否显示网格线
private bool m_is_showgrid = false;
//绘制的网格中,需要几条线,宽
public double m_i_grid_showlinesnumber_width = 0;
//绘制的网格中,需要几条线,高
public double m_i_grid_showlinesnumber_height = 0;
//是否拖动
private bool m_isDrag = false;
//拖动前的坐标记录
private PointF m_beforedrag_pointf = new PointF();
//提供鼠标在右下角显示的文本,左侧
private string m_str_mouseshow_left = "";
//提供鼠标在右下角显示的文本,右侧
private string m_str_mouseshow_right = "";
//整个背景矩形的背景色
private Color m_backrangecolor = Color.White;
OTSImageDisHelp m_ReportFun = null;
//当前鼠标的位置
Point m_mouse_now_point = new Point();
//记录当前鼠标位置对应SEM电镜的位置
Point m_sem_mouse_now_point = new Point();
//鼠标移动经过的颗粒对象,临时存放,用来记录是否要显示xray与隐藏xray
DisplayParticle m_mouseOver_dparticle = null;
//保存数据源名称
private string m_showsourcename = "";
//保存当前数据源的ID
private int m_datasourceid = 0;
//移动SEM到指定位置发生线程
private Thread m_mythread;
//记录线程是否已经运行完成的状态
//private bool m_mythread_state = false;
private Color m_ColorNotContent = Color.SkyBlue;
//读取背景原图的名称和图片
private Dictionary originalImages = new Dictionary();
//private List originalImageNames = new List();
//背景使用原图
private bool OriginalBackground = false;
static System.Windows.Forms.Timer delaytimer = new System.Windows.Forms.Timer();
Logger log;
///
/// 当前正在显示的数据源名称,用来与框架调用条件判断使用
///
public string ShowSourceName
{
set { m_showsourcename = value; }
get { return m_showsourcename; }
}
///
/// 当前正在显示的数据源的ID
///
public int DataSourceID
{
set { m_datasourceid = value; }
get { return m_datasourceid; }
}
///
/// 背景矩形属性
///
public RectangleF BackRectF
{
set { m_backRect = value; }
get { return m_backRect; }
}
public OTSImageDisHelp ReportFun { get => m_ReportFun; set => m_ReportFun = value; }
//测试用隐藏颗粒的id号,回头去掉
public int test_hide_particle_tagid = 1000;
//进度条窗体
public Frm_UserProgress m_frm_userprogress;
///
/// 是否显示过小颗粒
///
public bool bShowSmallParticle = false;
OTSIncAReportApp.frmReportApp m_ReportApp;
ResultFile resultFile = null;
#endregion
#region 构造函数及窗体加载
public Control_DrawDistrbutionImageAndBSE(OTSIncAReportApp.frmReportApp ReportApp)
{
log = NLog.LogManager.GetCurrentClassLogger();
m_list_allDfield = new List();
m_list_allDPart = new List();
m_frm_userprogress = new Frm_UserProgress();
//m_mythread_state = false;
m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
m_ReportApp = ReportApp;
resultFile = m_ReportApp.m_rstDataMgr.CurResultFile;
//初始化底层操作类
ReportFun = new OTSImageDisHelp(resultFile);
InitializeComponent();
#region 国际化语言
Language lan = new Language(this);
table = lan.GetNameTable(this.Name);
#endregion
//load the userdefine control dynamically
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Control_DrawDistrbutionImageAndBSE));
this.control_XRayTable1 = new Control_XRayTable();
this.control_XRayTable1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
this.control_XRayTable1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.control_XRayTable1.GBInfoStr = "";
this.control_XRayTable1.GoodChineseName = "";
this.control_XRayTable1.MaterialName = "";
this.control_XRayTable1.List_ShowElementInfo = ((System.Collections.Generic.List)(resources.GetObject("control_XRayTable1.List_ShowElementInfo")));
this.control_XRayTable1.Location = new System.Drawing.Point(0, 400);
this.control_XRayTable1.Name = "control_XRayTable1";
this.control_XRayTable1.ShowAnalysisXray = true;
this.control_XRayTable1.ShowSearchXray = false;
this.control_XRayTable1.Size = new System.Drawing.Size(1004, 200);
this.control_XRayTable1.STDName = "";
this.control_XRayTable1.TabIndex = 6;
this.control_XRayTable1.Visible = false;
//
// control_Ruler1
//
this.control_Ruler1 = new Control_Ruler();
this.control_Ruler1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(200)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
this.control_Ruler1.Location = new System.Drawing.Point(3, 400);
this.control_Ruler1.Name = "control_Ruler1";
this.control_Ruler1.RulerWidth = 100;
this.control_Ruler1.ShowString = "100um";
this.control_Ruler1.Size = new System.Drawing.Size(120, 40);
this.control_Ruler1.TabIndex = 8;
this.control_Ruler1.Value = 0D;
this.control_Ruler1.Visible = false;
this.Controls.Add(this.control_XRayTable1);
this.Controls.Add(this.control_Ruler1);
}
private void ProgressBarUpdate(int progress, string message)
{
//显示进度条,计算进度条应该显示的位置和宽度
if (m_frm_userprogress.Visible == false)
{
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(progress, message);
}
private void LoadUpdateDisplay()
{
ProgressBarUpdate(0, table["str1"].ToString());
//执行获取颗粒分布图数据,总过程函数
GetDistrbutionImageAndBSE_Total();
//设置双缓冲
SetDoubleBufferByIsDraw();
//设置标尺
//根据f_onepixel_size计算出要显示出100um的实际宽度
double d_onefixel_width = 100 / m_pixelSize;
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_pixelSize);
}
ReportFun.m_original_list_baseobject.Clear();
//记录原值,用于缩放计算操作 ,此处要用克隆 ,原particle颗粒的值,在底层调用时已经赋值过了
foreach (DisplayParticle ls_dp in m_list_allDPart)
{
ls_dp.SetPaintState(PaintState.NORMALPAINT);
DisplayParticle old_dp = ls_dp.Clone() as DisplayParticle;
ReportFun. m_original_list_baseobject.Add(old_dp);
}
//加载时将背景rect设置与整个窗体一边大小
m_old_backRect = m_backRect;
ReportFun.m_original_list_dfield.Clear();
////赋值给old保存原值
for (int i = 0; i < m_list_allDfield.Count; i++)
{
DisplayField df = new DisplayField(m_list_allDfield[i].List_DParticle);
df.Show_Rect = new RectangleF(m_list_allDfield[i].Show_Rect.X,
m_list_allDfield[i].Show_Rect.Y,
m_list_allDfield[i].Show_Rect.Width,
m_list_allDfield[i].Show_Rect.Height);
ReportFun. m_original_list_dfield.Add(df);
}
ProgressBarUpdate(100, table["str2"].ToString());
//加载完成,关闭进度条
m_frm_userprogress.Visible = false;
//m_frm_userprogress.Close();
}
private void Control_DrawDistrbutionImageAndBSE_Load(object sender, EventArgs e)
{
LoadUpdateDisplay();
}
///
/// 获取组整个获取分布图和排序图图像数据的底层数据组建方式,的总过程
///
public void GetDistrbutionImageAndBSE_Total()
{
string str27 = "begin to loading data....";
log.Info(str27);
Application.DoEvents();
ProgressBarUpdate(1, str27);
List fieldlist = resultFile.List_OTSField;
//防止有时底层返回的Field的List是0,直接返回
if (fieldlist.Count == 0)
{
ProgressBarUpdate(100, "field number =0 !....");
return;
}
string str29 = "begin to composit field picture....";
log.Info(str29);
Application.DoEvents();
ProgressBarUpdate(15, str29);
//第一次循环,用来计算单个Field的像素分辨率,和将所有的物理位置存放到List当中
List list_point = new List();
int fieldwidth = 0, fieldheight = 0;
//获取到该field的分辨率大小,循环中都是一样的
if (fieldlist.Count > 0)
{
Bitmap bitmp = DrawFunction.ReadImageFile(fieldlist[0].FieldImage);
fieldwidth = bitmp.Width;
fieldheight = 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);
}
//计算出整个绘制图像总Rectagnle的大小
m_backRect = ReportFun. ConvertAndGetMaxRect(list_point, fieldwidth, fieldheight);
ProgressBarUpdate(18, "calculate ruler....");
#region //标尺相关------------------------------------------------------------------------------
RectangleF ls_jsblrect = ReportFun.GetPhysicalFieldWidthAndHeight(list_point,fieldwidth,fieldheight);
//然后用宽度来除以i_field_width 获取单个的像素比例
double d_onepixel_scale = Convert.ToDouble(ls_jsblrect.Width) / Convert.ToDouble(fieldwidth);
//再用该比例对标尺进行相应的赋值
m_pixelSize = (float)d_onepixel_scale;
#endregion //---------------------------------------------------------------------------------------
ProgressBarUpdate(20, "composit whole picture....");
//70的进度条给到下面的循环中,计算进度条各分类进度分配
float ls_int_progresscalc = 0;
if (fieldlist.Count > 0)
ls_int_progresscalc = (float)70 / (float)fieldlist.Count;
string str32 = "finished ";
string str33 = "total ";
string str34 = "field...";
var otsLeftBottomPoint = ReportFun.GetOTSCoordLeftBottomPoint(list_point);
m_list_allDfield.Clear();
m_list_allDPart.Clear();
for (int i = 0; i < fieldlist.Count(); i++)
{
ProgressBarUpdate(20 + (int)(ls_int_progresscalc * (i + 1)), str32 + i.ToString() + str33 + resultFile.List_OTSField.Count.ToString() + str34);
//取出该Field的物理坐标,将其转换成对应的屏幕像素坐标,屏幕左上角为原点(0,0)的偏移值,用于后面计算各Segment的位置使用
Point thisfield_point = new Point() { X = fieldlist[i].FieldPosX, Y = fieldlist[i].FieldPosY };
Point offset_point = ReportFun.ConvertOTSCoordinateToScreenCoord(otsLeftBottomPoint, m_pixelSize, thisfield_point, m_backRect, new RectangleF(0,0,fieldwidth,fieldheight));//the ots coordinate is always the up right positive.
DisplayField df = new DisplayField(fieldlist[i],fieldwidth,fieldheight, offset_point);
m_list_allDfield.Add(df);
m_list_allDPart.AddRange(df.List_DParticle);
}
ProgressBarUpdate(90, "convert solution...");
//然后这里还需要计算出,各field的宽和高,帧图边框分别需要显示多少个框
if (fieldwidth != 0 && fieldheight != 0)
{
m_i_grid_showlinesnumber_width = Convert.ToInt32(BackRectF.Width / fieldwidth);
m_i_grid_showlinesnumber_height = Convert.ToInt32(BackRectF.Height / fieldheight);
}
ProgressBarUpdate(95, "other work...");
//相关计数
ReportFun.m_field_count = fieldlist.Count;
ReportFun.m_particle_count = m_list_allDPart.Count;
}
///
/// 分布图和BSE图中,从底层获取相关结果后,重新组织显示
///
///
public void FilterParticleByOtherCondition(ReportCondition sourceGridData)
{
bool sizeconditionResult;
bool stdIdconditionResult;
string stdId = "";
int stdIdIndex = 0;
//find the stdId condition
var STDIdItm = sourceGridData.ConditionItemList.Find(s => s.iItemId == OTS_REPORT_PROP_GRID_ITEMS.STD_ID);
if (STDIdItm != null)
{
stdId = STDIdItm.itemDisplayVal.ToString();
stdIdIndex = STDIdItm.comboDownList.IndexOf(stdId);
}
//find the size condition
var size_cal_method_type = (SIZE_CAL_METHOD_TYPE)sourceGridData.GetComboDownListIndexByItemName(OTS_REPORT_PROP_GRID_ITEMS.SIZE_CAL_METHOD_TYPE);
var itm = sourceGridData.ConditionItemList.Find(s => s.iItemId == OTS_REPORT_PROP_GRID_ITEMS.GRAIN_SIZE_CLASS);
string size = itm.itemDisplayVal.ToString();
int index = itm.comboDownList.IndexOf(size);
string min = "0";
string max = "999";
if (index > 0)
{
max = sourceGridData.ConditionItemList.Find(s => s.iItemId == OTS_REPORT_PROP_GRID_ITEMS.GRAIN_SIZE_MAX).itemDisplayVal.ToString();
min = sourceGridData.ConditionItemList.Find(s => s.iItemId == OTS_REPORT_PROP_GRID_ITEMS.GRAIN_SIZE_MIN).itemDisplayVal.ToString();
if (max.ToLower() == "max")
{
max = "999";
}
}
double dia_min = Convert.ToDouble(min);
double dia_max = Convert.ToDouble(max);
foreach (DisplayParticle ls_dp in m_list_allDPart)
{
if (index > 0)
{
double diameter = 0;
switch (size_cal_method_type)
{
case SIZE_CAL_METHOD_TYPE.DMAX:
diameter = ls_dp.objParticleData.DMAX;
break;
case SIZE_CAL_METHOD_TYPE.DMIN:
diameter = ls_dp.objParticleData.DMIN;
break;
case SIZE_CAL_METHOD_TYPE.CIRCLE:
diameter = Math.Sqrt(ls_dp.objParticleData.Area / 3.14159f) * 2f;
break;
case SIZE_CAL_METHOD_TYPE.DFERET:
diameter = ls_dp.objParticleData.DFERET;
break;
default:
diameter = 0;
break;
}
if (diameter >= dia_min && diameter <= dia_max)
{
sizeconditionResult = true;
}
else
{
sizeconditionResult = false;
}
}
else
{
sizeconditionResult = true;
}
if (stdIdIndex > 0)// it's not "All"
{
if (ls_dp.objParticleData.TypeName != stdId)
{
stdIdconditionResult = false;
}
else
{
stdIdconditionResult = true;
}
}
else
{
stdIdconditionResult = true;
}
if (stdIdconditionResult && sizeconditionResult)
{
ls_dp.SetDisplayState(DisplayState.DISPLAY);
}
else
{
ls_dp.SetDisplayState(DisplayState.NODISPLAY);
}
}
}
#endregion
#region 设置双缓冲
///
/// 设置双缓冲
///
public void SetDoubleBufferByIsDraw()
{
SetStyle(ControlStyles.UserPaint, true); //没什么效果,开与关
SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景,关了闪
SetStyle(ControlStyles.OptimizedDoubleBuffer, true); // 双缓冲,关了闪
//上面是必须有的
SetStyle(ControlStyles.UserMouse, true); //执行自己的鼠标行为,这个打开后,在win7下鼠标操作明显改善
}
#endregion
#region 绘制函数
protected override void OnPaint(PaintEventArgs e)//处理重绘情况
{
if (OriginalBackground)
{
GetPic(e);
}
else
{
#region //填充个背景色矩形-----------------------------------------------
SolidBrush b = new SolidBrush(m_backrangecolor);
e.Graphics.FillRectangle(b, m_backRect);
#endregion
}
#region //计算并进行绘制部份------------------------------------
//log.Info(" m_f_widthAndheight_js=" +m_Zoom_Base.ToString());
foreach (BaseObject item in m_list_allDPart)
{
DisplayParticle dp = (DisplayParticle)item;
if (dp.GetPaintState() != PaintState.NOPAINT)
{
dp.OnPaint(e);
}
}
#endregion
#region //判断是否使用了矩形或圆形工具进行多选,是的话,那么这里就开始绘制------------------------
if (m_SelectTool.IsSelecting)
{
if (m_SelectTool.Shape==SelectedShape.Rectangle && m_SelectTool.Rect.Width > 0 && m_SelectTool.Rect.Height > 0)
{
Graphics g = e.Graphics;
//绘制矩形
g.DrawRectangle(new Pen(Color.Blue), m_SelectTool.Rect.X, m_SelectTool.Rect.Y, m_SelectTool.Rect.Width, m_SelectTool.Rect.Height);
//半透明画刷
SolidBrush brush = new SolidBrush(Color.FromArgb(50, m_ColorNotContent));
//填充选择矩形
g.FillRectangle(brush, m_SelectTool.Rect.X, m_SelectTool.Rect.Y, m_SelectTool.Rect.Width, m_SelectTool.Rect.Height);
}
if (m_SelectTool.Shape == SelectedShape.Ellipse && m_SelectTool.Rect.Width > 0 && m_SelectTool.Rect.Height > 0)
{
Graphics g = e.Graphics;
//绘制圆形
g.DrawEllipse(new Pen(Color.Blue), m_SelectTool.Rect.X, m_SelectTool.Rect.Y, m_SelectTool.Rect.Width, m_SelectTool.Rect.Height);
//半透明画刷
SolidBrush brush = new SolidBrush(Color.FromArgb(50, m_ColorNotContent));
//填充选择圆形
g.FillEllipse(brush, m_SelectTool.Rect.X, m_SelectTool.Rect.Y, m_SelectTool.Rect.Width, m_SelectTool.Rect.Height);
}
}
#endregion
#region //判断是否使用颗粒分割,是的话,那么这里就开始绘制------------------------
if (m_ParticleSegmentation.IsParticleSegmentation)
{
e.Graphics.DrawLine(new Pen(Color.Red), m_ParticleSegmentation.StartPoint.X, m_ParticleSegmentation.StartPoint.Y, m_ParticleSegmentation.EndPoint.X, m_ParticleSegmentation.EndPoint.Y);
}
#endregion
#region 绘制网格线,帧图边框部份
if (true == m_is_showgrid)
{
RectangleF ls_rect_gridline = Rectangle.Round(new RectangleF(m_backRect.X,
m_backRect.Y,
m_backRect.Width,
m_backRect.Height));
//共绘制外边框,和里面横竖,各4个线
ControlPaint.DrawBorder(e.Graphics,
Rectangle.Ceiling(ls_rect_gridline),
Color.BurlyWood,
1,
ButtonBorderStyle.Solid,
Color.BurlyWood,
1,
ButtonBorderStyle.Solid,
Color.BurlyWood,
1,
ButtonBorderStyle.Solid,
Color.BurlyWood,
1,
ButtonBorderStyle.Solid);
//然后再把rectangle,横竖分成4块,画上4条横竖线
//画横线
for (int i = 1; i < m_i_grid_showlinesnumber_height; i++)
{
double y_zl = ls_rect_gridline.Height / m_i_grid_showlinesnumber_height;
e.Graphics.DrawLine(new Pen(Color.BurlyWood),
ls_rect_gridline.X,
Convert.ToInt64(ls_rect_gridline.Y + y_zl * i),
ls_rect_gridline.X + ls_rect_gridline.Width,
Convert.ToInt64(ls_rect_gridline.Y + y_zl * i));
}
//画竖线
for (int i = 1; i < m_i_grid_showlinesnumber_width; i++)
{
double x_zl = ls_rect_gridline.Width / m_i_grid_showlinesnumber_width;
e.Graphics.DrawLine(new Pen(Color.BurlyWood),
Convert.ToInt64(ls_rect_gridline.X + x_zl * i),
ls_rect_gridline.Y,
Convert.ToInt64(ls_rect_gridline.X + x_zl * i),
ls_rect_gridline.Y + ls_rect_gridline.Height);
}
}
#endregion
#region 绘制鼠标跟踪线部份
//XX虚线-----------------------------------------------
Pen xxpen = new Pen(Color.GreenYellow, 1);
xxpen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;
xxpen.DashPattern = new float[] { 5, 5 };
//竖线
e.Graphics.DrawLine(xxpen, 0, m_mouse_now_point.Y, m_mouse_now_point.X - 10, m_mouse_now_point.Y);
e.Graphics.DrawLine(xxpen, m_mouse_now_point.X + 10, m_mouse_now_point.Y, this.Width, m_mouse_now_point.Y);
//横线
e.Graphics.DrawLine(xxpen, m_mouse_now_point.X, 0, m_mouse_now_point.X, m_mouse_now_point.Y - 10);
e.Graphics.DrawLine(xxpen, m_mouse_now_point.X, m_mouse_now_point.Y + 10, m_mouse_now_point.X, this.Height);
////--------------------------------------------------------------------------------
#endregion
}
#endregion
#region 鼠标操作事件
///
/// 按指定的增量刻度对整个图像进行缩放,x,y为手动缩放时当前鼠标所在的位置,如果在其它地方调用则传入0在计算过程中,不会影响
///
///
private void ImageZoomByIncrement(float zoom, float in_mouse_x, float in_mouse_y)
{
//先计算鼠标的位置与背景rect的位置的差值
//用于存储锚点缩放记录原backrectf值的,一用来于计算差值
float oldwidth = m_backRect.Width;
float oldheight = m_backRect.Height;
m_backRect.Width = (float)(m_backRect.Width + Convert.ToDouble(m_old_backRect.Width * zoom));
m_backRect.Height = (float)(m_backRect.Height + Convert.ToDouble(m_old_backRect.Height * zoom));
//锚点缩放补差值计算,得出差值
float f_czx = (in_mouse_x - m_backRect.X) * ((oldwidth - m_backRect.Width) / oldwidth);
float f_czy = (in_mouse_y - m_backRect.Y) * ((oldheight - m_backRect.Height) / oldheight);
//对背景矩形与所有的segment进行修补差值
m_backRect.X = m_backRect.X + f_czx;
m_backRect.Y = m_backRect.Y + f_czy;
for (int i = 0; i < m_list_allDPart.Count(); i++)
{
DisplayParticle dp = (DisplayParticle)m_list_allDPart[i];
//dp.displayState = DisplayState.NORMALDISPLAY;
for (int y = 0; y < dp.DSegments.Count(); y++)
{
//这里重新设置每条线的高度,和x,y坐标
DisplaySegment ds = dp.DSegments[y];
DisplaySegment old_ds = ((DisplayParticle)ReportFun.m_original_list_baseobject[i]).DSegments[y];
ds.PenWidthAndHeight = ds.PenWidthAndHeight + old_ds.PenWidthAndHeight
* zoom;
ds.Rect = new RectangleF(ds.Rect.X + old_ds.Rect.X * zoom + f_czx, ds.Rect.Y + old_ds.Rect.Y * zoom + f_czy,
ds.Rect.Width + old_ds.Rect.Width * zoom, ds.Rect.Height + old_ds.Rect.Height * zoom);
}
//获取矩形的rectangle
dp.Rect = dp.GetRectFromDSegment();
//重新计算小矩形边框
dp.SmallRect = dp.GetSmallRectangleFromRect();
//设置缩放到多少倍时进行显示
if (m_zoom_record >= dp.Zoom_DisPlayThreshold)
{
dp.SetPaintState(PaintState.NORMALPAINT);
}
else
{
dp.SetPaintState(PaintState.CONCISEPAINT);
}
if (dp.Rect.Left < -120 || dp.Rect.Right > this.Width+120 || dp.Rect.Top < -120 || dp.Rect.Bottom > this.Height+120)
{
dp.SetPaintState(PaintState.NOPAINT);//the particles which are out of screen don't display.to speed up the display efficient.
}
}
if (m_list_allDfield != null)
{
if (m_list_allDfield.Count > 0)
{
for (int i = 0; i < m_list_allDfield.Count; i++)
{
DisplayField theField = m_list_allDfield[i];
theField.Current_Rect = new RectangleF(theField.Current_Rect.X + theField.Show_Rect.X * zoom + f_czx,
theField.Current_Rect.Y + theField.Show_Rect.Y * zoom + f_czy,
theField.Current_Rect.Width + theField.Show_Rect.Width * zoom,
theField.Current_Rect.Height + theField.Show_Rect.Height * zoom);
}
}
}
#region 计算标尺尺寸部份-----放大------
//计算标尺实际占用像素的宽度
m_f_ruler_size = m_f_ruler_size + Convert.ToInt32(m_f_old_ruler_size * zoom);
control_Ruler1.SetValue(m_f_ruler_size, m_pixelSize);
#endregion
}
protected override void OnMouseWheel(MouseEventArgs e)
{
if (e.Delta > 0)
{
if (m_zoom_record < m_f_zoom_max)
{
//图形缩放计算部份-------放大------------//是放大 一个刻度
m_Zoom_Base = const_zoom_increment;
}
else return;
}
else
{
if (m_zoom_record > m_f_zoom_mix)
{
//图形缩放计算部份------缩小--------------//是缩小 一个刻度
m_Zoom_Base = -const_zoom_increment;
}
else return;
}
m_zoom_record = m_zoom_record + m_Zoom_Base;
//这里对缩放的总记录进行校验
if (m_zoom_record < m_f_zoom_mix)
{
m_zoom_record = m_f_zoom_mix;
return;
}
//传入增减缩放的刻度,进行缩放
ImageZoomByIncrement(m_Zoom_Base, e.X, e.Y);
Invalidate();
}
protected override void OnMouseDown(MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.Cursor = Cursors.Hand;
if (m_SelectTool.IsSelecting)
{
m_SelectTool.StartPoint = e.Location;
}
else if (m_ParticleSegmentation.IsParticleSegmentation)
{
m_ParticleSegmentation.StartPoint= e.Location;
}
else
{
bool ifClickOnParticle=false;
foreach (BaseObject item in m_list_allDPart)
{
var dp = (DisplayParticle)item;
if (ReportFun.WhetherInRange(dp, e.Location))
{
dp.IsSelect = !dp.IsSelect;
ifClickOnParticle = true;
break;
}
}
if (ifClickOnParticle == false)
{
foreach (BaseObject item in m_list_allDPart)
{
var dp = (DisplayParticle)item;
if (dp.Rect.Left > -120 && dp.Rect.Right < this.Width + 120 && dp.Rect.Top > -120 && dp.Rect.Bottom < this.Height + 120)
{
item.IsDragging = true;
}
item.DraggingPoint = e.Location;
if (OriginalBackground)
{
dp.SetPaintState(PaintState.NOPAINT);
}
}
foreach (DisplayField item in m_list_allDfield)
{
item.IsDragging = true;
item.DraggingPoint = e.Location;
}
m_isDrag = true;
m_beforedrag_pointf = e.Location;
}
}
}
Invalidate();
}
protected override void OnMouseMove(MouseEventArgs e)
{
//当前鼠标的位置,用来绘制鼠标线用
m_mouse_now_point = e.Location;
if (m_SelectTool.IsSelecting)
{
if (e.Button == MouseButtons.Left)
{
if (e.Location.X > m_SelectTool.StartPoint.X && e.Location.Y > m_SelectTool.StartPoint.Y)
{
//右下拖动
m_SelectTool.Rect = new RectangleF(m_SelectTool.StartPoint, new SizeF(e.Location.X - m_SelectTool.StartPoint.X, e.Location.Y - m_SelectTool.StartPoint.Y));
}
if (e.Location.X < m_SelectTool.StartPoint.X && e.Location.Y < m_SelectTool.StartPoint.Y)
{
//左上拖动
PointF lspointf = new PointF(e.Location.X, e.Location.Y);
m_SelectTool.Rect = new RectangleF(lspointf, new SizeF(m_SelectTool.StartPoint.X - e.Location.X, m_SelectTool.StartPoint.Y - e.Location.Y));
}
if (e.Location.X > m_SelectTool.StartPoint.X && e.Location.Y < m_SelectTool.StartPoint.Y)
{
//右上,这种画法,需要将左下,右上两点转换成左上,右下
PointF left_pointf = new PointF(m_SelectTool.StartPoint.X, e.Location.Y);
PointF right_pointf = new PointF(e.Location.X, m_SelectTool.StartPoint.Y);
m_SelectTool.Rect = new RectangleF(left_pointf, new SizeF(right_pointf.X - left_pointf.X, right_pointf.Y - left_pointf.Y));
}
if (e.Location.X < m_SelectTool.StartPoint.X && e.Location.Y > m_SelectTool.StartPoint.Y)
{
//左下,这种画法,需要将左下,右上两点转换成左上,右下
PointF left_pointf = new PointF(e.Location.X, m_SelectTool.StartPoint.Y);
PointF right_pointf = new PointF(m_SelectTool.StartPoint.X, e.Location.Y);
m_SelectTool.Rect = new RectangleF(left_pointf, new SizeF(right_pointf.X - left_pointf.X, right_pointf.Y - left_pointf.Y));
}
}
}
else if(m_ParticleSegmentation.IsParticleSegmentation)
{
if (e.Button == MouseButtons.Left)
{
m_ParticleSegmentation.EndPoint = e.Location;
}
}
else
{
if (m_isDrag)
{
foreach (BaseObject item in m_list_allDPart)
{
DisplayParticle dp = (DisplayParticle)item;
if (true == item.IsDragging)
{
foreach (DisplaySegment ds in dp.DSegments)
{
var rec = ds.Rect;
rec.X = ds.Rect.X + e.X - item.DraggingPoint.X; //获取到原先点与移动点的增减量,+原先的x坐标,就是新的坐标
rec.Y = ds.Rect.Y + e.Y - item.DraggingPoint.Y;
ds.Rect = rec;
ds.DraggingPoint = e.Location;
}
item.DraggingPoint = e.Location;
//获取矩形的rectangle
dp.Rect = dp.GetRectFromDSegment();
//重新计算小矩形边框
dp.SmallRect = dp.GetSmallRectangleFromRect();
if (m_zoom_record >= dp.Zoom_DisPlayThreshold)
{
dp.SetPaintState(PaintState.NORMALPAINT);
}
else
{
dp.SetPaintState(PaintState.CONCISEPAINT);
}
if (dp.Rect.Left < -120 || dp.Rect.Right > this.Width + 120 || dp.Rect.Top < -120 || dp.Rect.Bottom > this.Height + 120)
{
dp.SetPaintState(PaintState.NOPAINT);
}
}
}
foreach (var item in m_list_allDfield)
{
if (true == item.IsDragging)
{
item.Current_Rect = new RectangleF(
item.Current_Rect.Left + Convert.ToSingle((e.X - item.DraggingPoint.X)),
item.Current_Rect.Top + Convert.ToSingle((e.Y - item.DraggingPoint.Y)),
item.Current_Rect.Width,
item.Current_Rect.Height);
item.DraggingPoint = e.Location;
}
}
//同样重新计算backrectf的坐标
m_backRect = new RectangleF(m_backRect.Location.X + e.X - m_beforedrag_pointf.X,
m_backRect.Location.Y + e.Y - m_beforedrag_pointf.Y, m_backRect.Width, m_backRect.Height);
m_beforedrag_pointf = e.Location;
}
else
{
foreach (BaseObject item in m_list_allDPart)
{
DisplayParticle dp = (DisplayParticle)item;
if (dp.GetPaintState() == PaintState.NORMALPAINT)
{
if (ReportFun.WhetherInRange(dp, e.Location))
{
dp.IsMouseOver = true;
//显示x-ray能谱图
if (control_XRayTable1.Visible == false)
ShowXRay(dp);
//m_sem_mouse_now_point = new Point(dp.SEMPosX, dp.SEMPosY);
m_str_mouseshow_left = "颗粒SEM位置:" + dp.SEMPosX.ToString() + ":" + dp.SEMPosY.ToString();
m_sem_mouse_now_point = new Point(dp.SEMPosX, dp.SEMPosY);
}
else
{
dp.IsMouseOver = false;
//移动在颗粒外面时,要判断,Operator_ShowXray不为选下显示XRAY时,才对XRay进行隐藏
if (dp.Operator_ShowXRay != ParticleShowXray.SELECTANDDISPLAYXRAY)
{
//隐藏x-ray能谱图
HideXRay(dp);
}
}
}
}
}
}
#region 向报告程序右下角,传送鼠标颗粒等相关信息
//获取颜色方法1,使用API来获取当前鼠标指向位置的颜色值-----------------------------------------------------
Color ls_c = GetColorByMousePoint(e.X, e.Y);
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();
}
///
/// 获取鼠标所在位置的信息,显示在框架的右下角
///
///
///
public void GetMouseLowerRightCornerText(out string mouseshow_left, out string mouseshow_rightb)
{
mouseshow_left = m_str_mouseshow_left;
mouseshow_rightb = m_str_mouseshow_right;
}
///
/// 鼠标抬起事件
///
///
protected override void OnMouseUp(MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.Cursor = Cursors.Default;
if (m_SelectTool.IsSelecting)
{
if (m_SelectTool.Rect.Width > 0 && m_SelectTool.Rect.Height > 0)
{
GraphicsPath ls_gpath = new GraphicsPath();
switch (m_SelectTool.Shape)
{
case SelectedShape.Rectangle:
ls_gpath.AddRectangle(m_SelectTool.Rect);
break;
case SelectedShape.Ellipse:
ls_gpath.AddEllipse(m_SelectTool.Rect);
break;
default:
break;
}
foreach (DisplayParticle dp in m_list_allDPart)
{
if (dp.GetPaintState() != PaintState.NOPAINT )
{
PointF[] lspointf = ls_gpath.PathPoints;
if (true == ReportFun.WhetherInRange(m_SelectTool.Rect, lspointf,new Point((int)dp.Rect.X,(int)dp.Rect.Y)))
{
dp.IsSelect =!dp.IsSelect ;// set the particle to the opsite selected state
}
}
}
}
m_SelectTool.IsSelecting = false;
}
else if(m_ParticleSegmentation.IsParticleSegmentation)
{
m_ParticleSegmentation.EndPoint = e.Location;
GraphicsPath ls_gpath = new GraphicsPath();
//ls_gpath.AddLine(m_ParticleSegmentation.StartPoint.X, m_ParticleSegmentation.StartPoint.Y, m_ParticleSegmentation.EndPoint.X, m_ParticleSegmentation.EndPoint.Y);
//m_ParticleSegmentation.IsParticleSegmentation = false;
DialogResult res = MessageBox.Show("Is it ok?");
if (res == DialogResult.OK)
{
foreach (BaseObject item in m_list_allDPart)
{
DisplayParticle dp = (DisplayParticle)item;
if (ReportFun.WhetherInRange(dp, e.Location))
{
List segments = dp.objParticleData.SegmentList;
}
}
}
}
else
{
if (m_isDrag)
{
foreach (BaseObject item in m_list_allDPart)
{
DisplayParticle dp = (DisplayParticle)item;
foreach (DisplaySegment ds in dp.DSegments)
{
var rec = ds.Rect;
rec.X = ds.Rect.X + e.X - item.DraggingPoint.X; //获取到原先点与移动点的增减量,+原先的x坐标,就是新的坐标
rec.Y = ds.Rect.Y + e.Y - item.DraggingPoint.Y;
ds.Rect = rec;
ds.DraggingPoint = Point.Empty;
ds.IsDragging = false;
}
item.DraggingPoint = Point.Empty;
item.IsDragging = false;
//获取矩形的rectangle
dp.Rect = dp.GetRectFromDSegment();
//重新计算小矩形边框
dp.SmallRect = dp.GetSmallRectangleFromRect();
if (m_zoom_record >= dp.Zoom_DisPlayThreshold)
{
dp.SetPaintState(PaintState.NORMALPAINT);
}
else
{
dp.SetPaintState(PaintState.CONCISEPAINT);
}
if (dp.Rect.Left < -120 || dp.Rect.Right > this.Width + 120 || dp.Rect.Top < -120 || dp.Rect.Bottom > this.Height + 120)
{
dp.SetPaintState(PaintState.NOPAINT);
}
}
m_isDrag = false;
}
}
}
if (e.Button == MouseButtons.Right)
{
bool ifClickOnParticle=false;
bool ifThereIsSelectedParticle = false;
foreach (BaseObject item in m_list_allDPart)
{
if (true == ReportFun.WhetherInRange((DisplayParticle)item, e.Location))
{
ifClickOnParticle = true;
CMenuStrip.Items[(int)RightButtonMenu.Include].Visible = false;
CMenuStrip.Items[(int)RightButtonMenu.CopyImage].Visible = false;
CMenuStrip.Items[(int)RightButtonMenu.OriginalSplicing].Visible = false;
CMenuStrip.Items[(int)RightButtonMenu.DeleteParticle].Visible = true;
//CMenuStrip.Items[(int)RightButtonMenu.CopyDatabase].Visible = true;
CMenuStrip.Items[(int)RightButtonMenu.MoveSEMToParticle].Visible = true;
CMenuStrip.Items[(int)RightButtonMenu.MoveSEMToParticle].Tag = item;
CMenuStrip.Items[(int)RightButtonMenu.ParticleSegmentation].Visible = true;
DisplayParticle dp = (DisplayParticle)item;
m_ParticleSegmentation.ParticleData = dp.objParticleData;
}
if (((DisplayParticle)item).IsSelect)
{
ifThereIsSelectedParticle = true;
}
}
if (ifClickOnParticle == false)
{
if (ifThereIsSelectedParticle)
{
CMenuStrip.Items[(int)RightButtonMenu.Include].Visible = true;
}
else
{
CMenuStrip.Items[(int)RightButtonMenu.Include].Visible = false;
}
CMenuStrip.Items[(int)RightButtonMenu.DeleteParticle].Visible = false;
//CMenuStrip.Items[(int)RightButtonMenu.CopyDatabase].Visible = false;
CMenuStrip.Items[(int)RightButtonMenu.CopyImage].Visible = true;
CMenuStrip.Items[(int)RightButtonMenu.OriginalSplicing].Visible = true;
CMenuStrip.Items[(int)RightButtonMenu.MoveSEMToParticle].Visible = false;
CMenuStrip.Items[(int)RightButtonMenu.ParticleSegmentation].Visible = false;
}
}
Invalidate();
}
#endregion
#region 鼠标右键菜单
private void ToolStripMenuItem_id_Click(object sender, EventArgs e)
{
//ID
//DisplayParticle dp = (DisplayParticle)CMenuStrip.Items[0].Tag;
//MessageBox.Show(dp.guid.ToString());
}
//是否显示过小颗菜单
private void ToolStripMenuItem_ShowSmallParticle_Click(object sender, EventArgs e)
{
}
private void ToolStripMenuItem_selected_Click(object sender, EventArgs e)
{
List selectedParts = new List();
List Particles = new List();
foreach (var dp in m_list_allDPart)
{
if (dp.IsSelect)
{
selectedParts.Add((DisplayParticle)dp);
Particle particle = new Particle();
particle.FieldId = ((OTSIncAReportGraph.DisplayParticle)dp).FieldId;
particle.ParticleId = ((OTSIncAReportGraph.DisplayParticle)dp).ParticleId;
Particles.Add(particle);
}
}
frmReportApp.selectedRegion = m_SelectTool.Rect;
SendSelectParticleListToReportFrame(selectedParts);
}
///
/// 显示x-ray能谱图
///
///
private void ShowXRay(DisplayParticle in_dparticle)
{
m_mouseOver_dparticle = in_dparticle;//将显示xray的dparticle记录给全局变量
if (delaytimer.Enabled == false)
{
delaytimer.Tick += Delaytimer_Tick;
delaytimer.Interval = 500;
delaytimer.Start();
}
}
private void Delaytimer_Tick(object sender, EventArgs e)
{
delaytimer.Enabled = false;
//显示xray相关信息
uint[] Search_xray = new uint[2000];
uint[] Analysis_xray = new uint[2000];
//
int i_xray_id = 0;
List list_celementchemistryclr = new List();
//获取Xray数据
ReportFun.GetXrayByParticleTagIDAndFieldID_ForDrawDistrbutionImageAndBSE(m_mouseOver_dparticle.ParticleId, m_mouseOver_dparticle.FieldId, 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);
double de_sx2 = 0;
if (CListPeriodic.GetPeriodicByYsm(CListPeriodic.GetListPeriodic(), ls_sei.ElementName).SX2 == "" || CListPeriodic.GetPeriodicByYsm(CListPeriodic.GetListPeriodic(), ls_sei.ElementName).SX2 == "-")
{
de_sx2 = 0;
}
else
{
de_sx2 = Convert.ToDouble(CListPeriodic.GetPeriodicByYsm(CListPeriodic.GetListPeriodic(), ls_sei.ElementName).SX2);
}
ls_sei.dLF = de_sx2;
list_showelementinfo.Add(ls_sei);
}
//获取使用标准库的名称
string str_IncAName = "";
str_IncAName = m_mouseOver_dparticle.TypeName;
//获取数据后,需要对xraytable设置
control_XRayTable1.Visible = false;
control_XRayTable1.SetXRayShowLineValue(Search_xray, Analysis_xray, list_showelementinfo);
//颗粒国标信息
control_XRayTable1.GBInfoStr = "";
control_XRayTable1.MaterialName = str_IncAName;//杂夹物
control_XRayTable1.List_ShowElementInfo = list_showelementinfo;
control_XRayTable1.Visible = true;
this.Refresh();
}
///
/// 隐藏x-ray能谱图
///
private void HideXRay(DisplayParticle in_dparticle)
{
if (m_mouseOver_dparticle == null)
return;
if (m_mouseOver_dparticle.guid == in_dparticle.guid)
{
//如果是刚才移动过的颗粒的话,那么这里再对xray进行隐藏
control_XRayTable1.Visible = false;
delaytimer.Enabled = false;
}
}
///
/// 根据传入的鼠标位置,来获取当前鼠标位置上的灰度值
///
///
///
///
private Color GetColorByMousePoint(int int_x, int int_y)
{
Graphics g = Graphics.FromHwnd(this.Handle);
IntPtr hdc = g.GetHdc();
uint u_color = 0;
try
{
u_color = DrawFunction.GetPixel(hdc, int_x, int_y);
}
catch
{ }
Color ls_c = Color.FromArgb
(
(int)(u_color << 24 >> 24),
(int)(u_color << 16 >> 24),
(int)(u_color << 8 >> 24)
);
return ls_c;
}
///
/// 封装,将分布图中的颗粒list传送给报告项目框架中
///
private void SendSelectParticleListToReportFrame(List selectParts)
{
//先获取分布图中,有哪些颗粒已经被选择上了
foreach (var p in selectParts)
{
if (!frmReportApp.selectedParticles.ContainsKey(p.guid))
{
frmReportApp.selectedParticles.Add(p.guid, p);
}
}
}
///
/// 设置当前对哪些颗粒进行设置为选择状态
///
///
public void SetSelectParticle(List particles)
{
if (particles == null)
{
return;
}
if (particles.Count == 0)
{
return;
}
foreach (DisplayParticle ls_dp in m_list_allDPart)
{
if (ls_dp.GetPaintState() == PaintState.NORMALPAINT)
{
for (int i = 0; i < particles.Count; i++)
{
if (particles[i].ParticleId == ls_dp.ParticleId
&& particles[i].FieldId == ls_dp.FieldId)
{
ls_dp.IsSelect=true;
}
}
}
}
}
private void ToolStripMenuItem_delete_Click(object sender, EventArgs e)
{
List selectedParts = new List();
foreach (var obj in m_list_allDPart)
{
var dp = (DisplayParticle)obj;
if (dp.IsSelect)
{
dp.IsDeleted = true;
}
else
{
selectedParts.Add(dp);
}
}
SendSelectParticleListToReportFrame(selectedParts);
}
//复制图像
private void toolStripMenuItem_copyimage_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
//|ALL Files(*.*)|*.*
//BMP Files(*.bmp)| *.bmp |
sfd.Filter = "png Files(*.png)| *.png |BMP Files(*.bmp)| *.bmp |JPG Files(*.jpg)|*.jpg;*.jpeg";
if (sfd.ShowDialog() == DialogResult.OK)
{
OutPIC outpic = new OutPIC();
outpic.m_list_allDfield = m_list_allDfield;
outpic.resultFile = resultFile;
outpic.sfd = sfd;
outpic.type = (int)Outpic_enum.pic;
Thread bThread = new Thread(new ThreadStart(outpic.opencv_outpic));
bThread.IsBackground = true;
bThread.Start();
}
}
private void ToolStripMenuItem_movesempoint_Click(object sender, EventArgs e)
{
//移动SEM到指定位置
if (m_mythread == null)
{
return;
}
if (m_mythread.ThreadState == System.Threading.ThreadState.Running || m_mythread.ThreadState == System.Threading.ThreadState.WaitSleepJoin)
{
return;
}
if (m_mythread.ThreadState == System.Threading.ThreadState.Stopped)
{
m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
}
//改为线程调用,先判断线程状态
m_mythread.Start(new Point(m_sem_mouse_now_point.X, m_sem_mouse_now_point.Y));
}
#endregion
#region 自定义功能函数
///
/// 复制图像
///
private void CopyImage()
{
int height, width;
width = this.Width;
height = this.Height;
Bitmap image = new Bitmap(width, height);
//this.BackgroundImage
this.DrawToBitmap(image, new Rectangle(0, 0, width, height));
Clipboard.SetImage(image);
}
///
/// 移动SEM到指定位置线程函数
///
private void Thread_GO(object in_obj)
{
Point sem_point = (Point)in_obj;
//第一步,连接电镜
ReportFun.ConnectToSEM();
Thread.Sleep(500);
//第二步,移动到指定位置,先读取再设置
if (ReportFun.m_SEMConnectionState == true)
{
ReportFun.MoveSemToPointXY(sem_point.X, sem_point.Y);
}
Thread.Sleep(1500);
//第三步,断开电镜连接
ReportFun.DisConnectSEM();
}
///
/// 按框架传入的底层计算结果,重新对颗粒进行区分显示
///
///
public void DrawDistrbutionImageAndBSE_ByQuery(OTSIncAReportApp.OTSSampleReportInfo.ReportCondition in_griddata)
{
FilterParticleByOtherCondition(in_griddata);
Invalidate();
this.Refresh();
}
///
/// 对分布图进行宽度匹配操作
///
public void WidthMatch()
{
if (this.Width != m_backRect.Width)
{
float f_cz = 0;//进行调整的差值
f_cz = -((m_backRect.Width - this.Width) / m_old_backRect.Width);
m_zoom_record = m_zoom_record + f_cz;//更新上缩放值,与下面处理缩放对应上
ImageZoomByIncrement(f_cz, 0, 0);
}
MoveImageToPoint(new PointF(0, 0));
}
///
/// 对分布图进行高度匹配操作
///
public void HeightMatch()
{
if (this.Height != m_backRect.Height)
{
float f_cz = 0;//进行调整的差值
f_cz = -((m_backRect.Height - this.Height) / m_old_backRect.Height);
m_zoom_record = m_zoom_record + f_cz;//更新上缩放值,与下面处理缩放对应上
ImageZoomByIncrement(f_cz, 0, 0);
}
//移动到,this.width - backrectf.width /2
int ls_x = (int)(this.Width - m_backRect.Width) / 2;
MoveImageToPoint(new PointF(ls_x, 0));
}
///
/// 对分布图进行全图匹配操作
///
public void FullGraphMatch()
{
//全图匹配,首先要判断出来是按宽度来计算缩放,还是按高度来计算缩放
double thiswidth = this.Width;
double thisheight = this.Height;
double imagewidth = m_backRect.Width;
double imageheight = m_backRect.Height;
//如果宽已相等rect在thisheight范围内,是宽度匹配已经达到目的,或是高已相等rect在thiswidth范围内,是高度匹配已经达到目的
if ((thiswidth == imagewidth && thisheight > imagewidth) || (thisheight == imageheight && thiswidth > imagewidth))
{
//已经达到目的不操作,返回
return;
}
//判断当前是否宽度匹配未达到全图匹配效果
if (thiswidth == imagewidth && thisheight < imageheight)
{
//说明目前已经达到了宽度匹配,但是未能显示完全整图需要高度匹配
HeightMatch();
return;
}
//判断当前是否高度匹配未达到全图匹配效果
if (thisheight == imageheight && thiswidth < imagewidth)
{
//说明目前已经达到了高度匹配,但是未能显示完全的整图需要宽度匹配
WidthMatch();
return;
}
ls_d_cz_width = Math.Abs(thiswidth / imagewidth);
ls_d_cz_height = Math.Abs(thisheight / imageheight);
//应该是看谁差的倍数大就按谁的进行调整,而不只能看高宽的差值
if ((1 - ls_d_cz_width) > (1 - ls_d_cz_height))
{
//宽差大,就调用WidthMate
WidthMatch();
}
else
{
//高差大,则调用HightMate
HeightMatch();
}
m_f_zoom_mix = m_zoom_record;
}
///
/// 将整个图像的位置移动到指定的位置上
///
private void MoveImageToPoint(PointF in_pointf)
{
//先计算,当前所在的位置,和需要移动的位置之间的差
//想复杂了,其实就是当前backrectf的x,y与in_pointf的差就完了呗
PointF offex_p = new PointF(m_backRect.X - in_pointf.X, m_backRect.Y - in_pointf.Y);
for (int i = 0; i < m_list_allDPart.Count; i++)
{
DisplayParticle dp = (DisplayParticle)m_list_allDPart[i];
for (int k = 0; k < dp.DSegments.Count; k++)
{
dp.DSegments[k].Rect = new RectangleF(
dp.DSegments[k].Rect.X - offex_p.X,
dp.DSegments[k].Rect.Y - offex_p.Y,
dp.DSegments[k].Rect.Width,
dp.DSegments[k].Rect.Height);
}
//获取矩形的rectangle
dp.Rect = dp.GetRectFromDSegment();
//通过line获取路径边缘
dp.GPath = dp.GetRegionFromDSegments();
//重新计算小矩形边框
dp.SmallRect = dp.GetSmallRectangleFromRect();
if (dp.Rect.Left < -120 || dp.Rect.Right > this.Width + 120 || dp.Rect.Top < -120 || dp.Rect.Bottom > this.Height + 120)
{
dp.SetPaintState(PaintState.NOPAINT);
}
}
//同样重新计算backrectf的坐标
m_backRect = new RectangleF(m_backRect.X - offex_p.X, m_backRect.Y - offex_p.Y,
m_backRect.Width, m_backRect.Height);
for (int i =0;i< m_list_allDfield.Count;i++)
{
RectangleF dField = m_list_allDfield[i].Current_Rect;
dField.X = dField.X-offex_p.X;
dField.Y = dField.Y - offex_p.Y;
m_list_allDfield[i].Current_Rect = dField;
}
Invalidate();
}
///
/// 是否显示边框格线,自动切换显示与不显示
///
///
public void ShowGridLine()
{
m_is_showgrid = !m_is_showgrid;
}
///
/// 是否显示标尺控件
///
///
public void ShowRulerControl()
{
control_Ruler1.Visible = !control_Ruler1.Visible;
}
///
/// 是否显示边框格线,带参重载
///
///
public void ShowGridLine(bool b_show)
{
m_is_showgrid = b_show;
}
///
/// 是否显示标尺控件,带参重载
///
///
public void ShowRulerControl(bool b_show)
{
control_Ruler1.Visible = b_show;
}
///
/// 颗粒分割
///
public void Particle_Segmentation()
{
m_ParticleSegmentation.IsParticleSegmentation = true;
m_ParticleSegmentation.StartPoint = new Point();
m_ParticleSegmentation.EndPoint = new Point();
}
///
/// 是否进行矩形多选操作
///
public void MultiSelect_Rectangle()
{
m_SelectTool.IsSelecting = true;
m_SelectTool.Shape = SelectedShape.Rectangle;
m_SelectTool.Rect = new RectangleF();
m_SelectTool.Rect.Width = 0;
m_SelectTool.Rect.Height = 0;
}
///
/// 是否进行圆形多选操作
///
public void MultiSelect_Ellipse()
{
m_SelectTool.IsSelecting = true;
m_SelectTool.Shape = SelectedShape.Ellipse;
m_SelectTool.Rect = new RectangleF();
m_SelectTool.Rect.Width = 0;
m_SelectTool.Rect.Height = 0;
}
///
/// 对选择的多边形进行反选操作
///
public void ReverseSelection()
{
foreach (DisplayParticle dp in m_list_allDPart)
{
if (dp.IsSelect)
{
dp.IsSelect = false;
}
else
{
dp.IsSelect = true;
}
}
//将排列图选择的颗粒传送给报告框架中
//SendSelectParticleListToReportFrame();
this.Invalidate();
}
///
/// 取消所有的颗粒的选择状态
///
public void DeselectAllParticle()
{
foreach (DisplayParticle dp in m_list_allDPart)
{
dp.IsSelect=false;
}
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);
}
///
/// 设置显示BSE原图,还是显示分布图带有标准库的
///
public void ShowMode(IMAGE_TYPE a_type)
{
if (a_type == IMAGE_TYPE.BSE)
{
OriginalBackground = false;
//bse图时,显示背景图为白色
m_backrangecolor = Color.White;
foreach (DisplayParticle ls_dp in m_list_allDPart)
{
foreach (DisplaySegment ls_ds in ls_dp.DSegments)
{
ls_ds.ShowMode = SegmentShowMode.DRAWPOINT;
}
}
FullGraphMatch();
}
else if (a_type == IMAGE_TYPE.CLASSIFIED)
{
m_backrangecolor = Color.Gainsboro;
OriginalBackground = false;
foreach (DisplayParticle ls_dp in m_list_allDPart)
{
//ls_dp.DisplayState = DisplayState.DISPLAY;
foreach (DisplaySegment ls_ds in ls_dp.DSegments)
{
ls_ds.ShowMode = SegmentShowMode.DRAWLINE;
}
}
FullGraphMatch();
}
else if (a_type== IMAGE_TYPE.ORIGINAl)
{
m_backrangecolor = Color.Gainsboro;
OriginalBackground = true;
foreach (DisplayParticle ls_dp in m_list_allDPart)
{
ls_dp.SetDisplayState(DisplayState.NODISPLAY);
}
FullGraphMatch();
}
else if(a_type== IMAGE_TYPE.ORIGINALCLASSIFIED)
{
m_backrangecolor = Color.Gainsboro;
OriginalBackground = true;
foreach (DisplayParticle ls_dp in m_list_allDPart)
{
//ls_dp.DisplayState = DisplayState.DISPLAY;
foreach (DisplaySegment ls_ds in ls_dp.DSegments)
{
ls_ds.ShowMode = SegmentShowMode.DRAWLINE;
}
}
FullGraphMatch();
}
this.Invalidate();
}
///
/// 根据传入的颗粒状态,来获取所有该颗粒状态下的数据,用来测试统计使用
///
///
///
public int GetParticleNumberByState(PaintState in_ParticleState)
{
int icount = 0;
foreach (DisplayParticle ls_dp in m_list_allDPart)
{
if (ls_dp.GetPaintState() == in_ParticleState)
{
icount++;
}
}
return icount;
}
///
/// 获取所有原图
///
///
///
private void GetPic(PaintEventArgs args)
{
//outpic();
foreach (var f in m_list_allDfield)
{
var curfldrec = f.Current_Rect;
if (curfldrec.Left > -1000 && curfldrec.Right < this.Width + 1000 && curfldrec.Top > -1000 && curfldrec.Bottom < this.Height + 1000)
{
args.Graphics.DrawImage(f.OriginalImage, f.Current_Rect.X, f.Current_Rect.Y, f.Current_Rect.Width, f.Current_Rect.Height);
Graphics g = args.Graphics;
for (int i = 0; i < f.List_DParticle.Count; i++)
{
PointF xrayPos = new PointF(f.List_DParticle[i].objParticleData.PosX, f.List_DParticle[i].objParticleData.PosY);
PointF p = new PointF(xrayPos.X / f.OriginalImage.Width*f.Current_Rect.Width+f.Current_Rect.X, xrayPos.Y / f.OriginalImage.Height* f.Current_Rect.Height+f.Current_Rect.Y);
g.DrawString("+", new Font("黑体", 6), new SolidBrush(Color.Red), p);
}
}
}
}
#endregion
private static byte[] ImgtoByte(Image img)
{
MemoryStream ms = new MemoryStream();
byte[] imagedata = null;
img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
imagedata = ms.GetBuffer();
return imagedata;
}
private static Image BytesToImage(byte[] buffer)
{
MemoryStream ms = new MemoryStream(buffer);
Image image = System.Drawing.Image.FromStream(ms);
return image;
}
#region Debug下执行的辅助测试代码
private void Control_DrawDistrbutionImageAndBSE_MouseDoubleClick(object sender, MouseEventArgs e)
{
#if DEBUG
Screen[] screens = Screen.AllScreens;
string ls_str = "";
for (int i = 0; i < screens.Count(); i++)
{
ls_str = ls_str + "显示器" + (i + 1).ToString() + " 名称:" + screens[i].DeviceName + Environment.NewLine +
"显示器" + (i + 1).ToString() + " 是否主要显示器:" + screens[i].Primary + Environment.NewLine +
"显示器" + (i + 1).ToString() + " WorkingArea:" + screens[i].WorkingArea + Environment.NewLine +
"显示器" + (i + 1).ToString() + " Bounds:" + screens[i].Bounds + Environment.NewLine +
"显示器" + (i + 1).ToString() + " 色深:" + screens[i].BitsPerPixel + Environment.NewLine;
}
MessageBox.Show("------------------该段代码主要用来测试程序---------------------" + Environment.NewLine +
//"当前窗体X:" + this.ParentForm.Location.X.ToString() + " Y:" + this.ParentForm.Location.Y.ToString() + Environment.NewLine +
"显示器数量" + Screen.AllScreens.Count().ToString() + Environment.NewLine +
ls_str +
"DESKTOP.Width:" + MyPrimaryScreen.DESKTOP.Width + " DESKTOP.Height:" + MyPrimaryScreen.DESKTOP.Height + Environment.NewLine +
"DpiX:" + MyPrimaryScreen.DpiX + " DpiY:" + MyPrimaryScreen.DpiY + Environment.NewLine +
"ScaleX:" + MyPrimaryScreen.ScaleX + " ScaleY:" + MyPrimaryScreen.ScaleY + Environment.NewLine +
"WorkingArea.Width:" + MyPrimaryScreen.WorkingArea.Width + " WorkingArea.Height:" + MyPrimaryScreen.WorkingArea.Height + Environment.NewLine +
"this.Width:" + this.Width + " this.Height:" + this.Height + Environment.NewLine +
"单像素比:" + m_pixelSize.ToString() + Environment.NewLine +
"缩放倍数:" + m_zoom_record.ToString() + Environment.NewLine +
"屏幕像素backrectf x:" + m_backRect.X.ToString() + " y:" + m_backRect.Y.ToString() + " width:" + m_backRect.Width.ToString() + " height:" + m_backRect.Height.ToString() + Environment.NewLine +
"屏幕像素oldbackrectf x:" + m_old_backRect.X.ToString() + " y:" + m_old_backRect.Y.ToString() + " width:" + m_old_backRect.Width.ToString() + " height:" + m_old_backRect.Height.ToString() + Environment.NewLine +
"物理像素back_wl_rectf x:" + m_back_wl_rectf.X.ToString() + " y:" + m_back_wl_rectf.Y.ToString() + " width:" + m_back_wl_rectf.Width.ToString() + " height:" + m_back_wl_rectf.Height.ToString() + Environment.NewLine +
//"单个Field视域屏幕像素宽:" + m_OneField_Screen_BackRectf.Width.ToString() + " 高:" + m_OneField_Screen_BackRectf.Height.ToString() + Environment.NewLine +
//"单个OTS视域屏幕像素宽:" + m_OneField_OTS_Rect.Width.ToString() + " 高:" + m_OneField_OTS_Rect.Height.ToString() + Environment.NewLine +
"屏幕像素backrectf x:" + m_backRect.X.ToString() + " y:" + m_backRect.Y.ToString() + " width:" + m_backRect.Width.ToString() + " height:" + m_backRect.Height.ToString() + Environment.NewLine +
"包含Field数量:" + ReportFun.m_field_count.ToString() + " Particle数量:" + ReportFun.m_particle_count.ToString() + Environment.NewLine +
"正常显示Paticle数量:" + GetParticleNumberByState(PaintState.NORMALPAINT).ToString() + " 不显示Particel数量:" + GetParticleNumberByState(PaintState.NOPAINT).ToString() + Environment.NewLine +
//"删除Particle数量:" + GetParticleNumberByState("删除").ToString() + " 选中Particle数量:" + GetParticleNumberByState("选择").ToString() + Environment.NewLine +
"加载底层数据用时:" + ReportFun.m_time_str + Environment.NewLine +
"组建并计算图像用时:" + ReportFun.m_time_str2 + Environment.NewLine +
"---------------------------END----------------------------------"
);
#endif
}
#endregion
private void ExportoriginalspliceToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
//|ALL Files(*.*)|*.*
//BMP Files(*.bmp)| *.bmp |
sfd.Filter = "png Files(*.png)| *.png |BMP Files(*.bmp)| *.bmp |JPG Files(*.jpg)|*.jpg;*.jpeg";
if (sfd.ShowDialog() == DialogResult.OK)
{
OutPIC outpic = new OutPIC();
outpic.m_list_allDfield = m_list_allDfield;
outpic.resultFile = resultFile;
outpic.sfd = sfd;
outpic.type = (int)Outpic_enum.Render_pic;
Thread bThread = new Thread(new ThreadStart(outpic.opencv_outpic));
bThread.IsBackground = true;
bThread.Start();
}
}
private void ToolStripMenuItemDelete_Particle_Click(object sender, EventArgs e)
{
DialogResult dr = MessageBox.Show("Should I delete particles", "Tips", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
if (dr== DialogResult.OK)
{
if (ReportFun.DeleteParticlesFromLibrary(m_mouseOver_dparticle.ParticleId, m_mouseOver_dparticle.FieldId))
{
MessageBox.Show("Deleted successfully");
FieldData fieldData = new FieldData(resultFile.FilePath);
List fieldlist = fieldData.GetFieldList();
m_ReportApp.m_rstDataMgr.CurResultFile.List_OTSField = fieldlist;
LoadUpdateDisplay();
}
else
{
MessageBox.Show("Delete failed");
}
}
else
{
return;
}
}
int GetsIntersectionOfTheIntercepts(Point P1,Point P2,int y)
{
int x = (y - P1.Y * P2.X + P1.X * P2.Y) / (P2.Y - P1.Y);
return x;
}
private void ParticleSegmentation_Click(object sender, EventArgs e)
{
Particle_Segmentation();
}
}
}