using OTSCommon.DBOperate.Model; using OTSIncAReportGraph.Class; using OTSMeasureApp._0_OTSModel.OTSDataType; using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; namespace OTSIncAReportGraph { public class DisplayRectangle { Guid m_id; Color disColor; string m_fieldid; bool m_IsDragging; public string gradeString=""; List m_list_dparticle; private float m_currentZoom=1; PointF m_ots_point; //按底层设计结构,底层返回的物理坐标位置及大小,OTS坐标大小 RectangleF m_Rect;//最后换算到在显示器上显示的坐标位置大小 PointF m_dragingpoint;//鼠标拖动的位置 public COTSRect myOTSRect = new COTSRect(); private Bitmap m_originalImage; public enum RemoveParticleType { INVALID = -1, MIN = 0, UNCLASSIFY = 0, NOT_USE2 = 1, AVE_GRAY_NOT_INRANRE = 2, SEARCH_X_RAY = 3, LOW_COUNT = 4, NO_INTEREST_ELEMENTS = 5, NO_ANALYSIS_X_RAY = 6, ISNOT_INCLUTION = 7, NOT_USE = 8, NOT_IDENTIFIED = 9, IDENTIFIED = 10,//当为可识别类型时(10),可以被进一步识别为用户类型(1000以上),系统预定义类型(10000以上),所以最终颗粒类型不会为10,最终的组号可能为7,9(非夹杂物和未识别)或其他预定义的组,ID号则为识别出的ID号 MAX = 10, } const int INVALIDPARTICLE= -1; /// /// 构造函数 /// public DisplayRectangle(Field fld, float fldwidth, float fldheight,double pixelSize,PointF screenPos) { m_list_dparticle = new List(); m_id = System.Guid.NewGuid(); Point thisfield_point = new Point() { X = fld.FieldPosX, Y = fld.FieldPosY }; FieldID = fld.FieldID.ToString(); var ltPoint = new PointF(screenPos.X - fldwidth / 2, screenPos.Y -fldheight / 2); SetShow_Rect(new RectangleF(ltPoint, new SizeF(fldwidth, fldheight))); OTSCoordinatePos = new PointF(thisfield_point.X, thisfield_point.Y); double left = OTSCoordinatePos.X - fldwidth * pixelSize / 2; double right = OTSCoordinatePos.X + fldwidth * pixelSize / 2; double top = OTSCoordinatePos.Y + fldheight * pixelSize / 2; double bottom = OTSCoordinatePos.Y - fldheight * pixelSize / 2; myOTSRect.SetRectData( (float)left,(float)top,(float)right,(float)bottom); //先获取该Field中的所有Particle List list_particle; list_particle = fld.ParticleList; //然后将取出的数据,转换成Bitmap对象 m_originalImage = DrawFunction.ReadImageFile(fld.FieldImageName); Bitmap dpImage = new Bitmap((int)fldwidth, (int)fldheight); //再循环计算所有的Particle对象 foreach (Particle particle in list_particle) { //分布图排列图无效颗粒不显示 if (particle.TypeId == (int)RemoveParticleType.INVALID|| particle.TypeId == (int)RemoveParticleType.LOW_COUNT) { continue; } //创建DParticle颗粒 DisplayParticle dp = new DisplayParticle(particle, ltPoint, m_originalImage/*,dpImage*/); double partLeft=dp.objParticleData.RectLeft*pixelSize+myOTSRect.GetTopLeft().X; double partRight = partLeft+dp.objParticleData.RectWidth*pixelSize; double partTop = myOTSRect.GetTopLeft().Y - dp.objParticleData.RectTop * pixelSize; double partBottom = partTop - dp.objParticleData.RectHeight * pixelSize; dp.OTSRect.SetRectData((float )partLeft, (float)partTop, (float)partRight, (float)partBottom); m_list_dparticle.Add(dp); } } public DisplayRectangle(List in_list_dparticle) { m_list_dparticle = in_list_dparticle; } public DisplayRectangle(float fldwidth, float fldheight,PointF OTSPos, PointF screenPos) { m_id = System.Guid.NewGuid(); var ltPoint = new PointF(screenPos.X - fldwidth / 2, screenPos.Y - fldheight / 2); SetShow_Rect(new RectangleF(ltPoint, new SizeF(fldwidth, fldheight))); m_ots_point = OTSPos; } public bool WhetherInRange( PointF WhetherPoint) { var rect = GetShowRect(); if ((rect.Left < WhetherPoint.X && WhetherPoint.X < rect.Right) && (rect.Top < WhetherPoint.Y && WhetherPoint.Y < rect.Bottom)) { return true; } else { return false; } } public void Zoom(float zoomDelta , PointF refPoint) { m_Rect.Width += m_Rect.Width/ m_currentZoom * zoomDelta; m_Rect.Height += m_Rect.Height/ m_currentZoom * zoomDelta; //锚点缩放补差值计算,得出差值 float xShiftOld = m_Rect.X - refPoint.X; float yShiftOld = m_Rect.Y - refPoint.Y; float xShift = m_Rect.X - refPoint.X + xShiftOld/ m_currentZoom * zoomDelta; float yShift = m_Rect.Y - refPoint.Y + yShiftOld/ m_currentZoom * zoomDelta; m_Rect.X = refPoint.X + xShift; m_Rect.Y = refPoint.Y + yShift; m_currentZoom += zoomDelta; } public void DraggingMove(PointF mousePoint) { m_Rect = new RectangleF( m_Rect.Left + Convert.ToSingle((mousePoint.X - DraggingPoint.X)), m_Rect.Top + Convert.ToSingle((mousePoint.Y - DraggingPoint.Y)), m_Rect.Width, m_Rect.Height); DraggingPoint = mousePoint; } public void Move(SizeF xyShift) { m_Rect = new RectangleF( m_Rect.Left- Convert.ToSingle(xyShift.Width), m_Rect.Top - Convert.ToSingle(xyShift.Height), m_Rect.Width, m_Rect.Height); } public Guid guid { get => m_id; set => m_id = value; } /// /// 是否被拖动标识 /// public bool IsDragging { get => m_IsDragging; set => m_IsDragging = value; } /// /// 被拖动到的位置坐标 /// public PointF DraggingPoint { get => m_dragingpoint; set => m_dragingpoint = value; } /// /// 与底层对应的ID,这里叫成FieldID /// public string FieldID { get { return m_fieldid; } set { m_fieldid = value; } } /// /// 包含的Particle列表 /// public List List_DParticle { get { return m_list_dparticle; } set { m_list_dparticle = value; } } /// /// 该Field的OTS坐标及大小 /// public PointF OTSCoordinatePos { get { return m_ots_point; } set { m_ots_point = value; } } /// /// 该Field最后在屏幕上显示的坐标及大小 /// public RectangleF GetShowRect() { return m_Rect; } /// /// 该Field最后在屏幕上显示的坐标及大小 /// public void SetShow_Rect(RectangleF value) { m_Rect = value; } public Bitmap OriginalImage { get => m_originalImage; set => m_originalImage = value; } public Color ContentColor { get => disColor; set =>disColor = value; } public void Paint(PaintEventArgs e,Color bodyColor) { Graphics g = e.Graphics; float w = 1; Pen p = new Pen(bodyColor, w); var r = new Rectangle((int)m_Rect.Left, (int)m_Rect.Top, (int)m_Rect.Width, (int)m_Rect.Height); g.DrawRectangle(p, r); if (gradeString != "") { SolidBrush solidBrush = new SolidBrush(Color.FromArgb(100, disColor)); //字体大小 根据样品孔Rectangle大小 float fontSize = m_Rect.Width / 20; Font font = new Font("宋体", fontSize, FontStyle.Bold); if (fontSize == 0) { font = new Font("宋体", 5, FontStyle.Bold); } RectangleF rectFont = m_Rect; rectFont.X += 2; rectFont.Y += 2; g.DrawString(gradeString, font, solidBrush, rectFont); } } } }