DisplayField.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. using OTSCommon.Model;
  2. using OTSIncAReportGraph.Class;
  3. using OTSMeasureApp._0_OTSModel.OTSDataType;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Drawing;
  7. using System.Windows.Forms;
  8. namespace OTSIncAReportGraph
  9. {
  10. public class DisplayField
  11. {
  12. Guid m_id;
  13. Color disColor;
  14. string m_fieldid;
  15. bool m_IsDragging;
  16. public string gradeString="";
  17. List<DisplayParticle> m_list_dparticle;
  18. private float m_currentZoom=1;
  19. PointF m_ots_point; //按底层设计结构,底层返回的物理坐标位置及大小,OTS坐标大小
  20. RectangleF m_Rect;//最后换算到在显示器上显示的坐标位置大小
  21. PointF m_dragingpoint;//鼠标拖动的位置
  22. public COTSRect myOTSRect = new COTSRect();
  23. private Bitmap m_originalImage;
  24. public enum RemoveParticleType
  25. {
  26. INVALID = -1,
  27. MIN = 0,
  28. UNCLASSIFY = 0,
  29. NOT_USE2 = 1,
  30. AVE_GRAY_NOT_INRANRE = 2,
  31. SEARCH_X_RAY = 3,
  32. LOW_COUNT = 4,
  33. NO_INTEREST_ELEMENTS = 5,
  34. NO_ANALYSIS_X_RAY = 6,
  35. ISNOT_INCLUTION = 7,
  36. NOT_USE = 8,
  37. NOT_IDENTIFIED = 9,
  38. IDENTIFIED = 10,//当为可识别类型时(10),可以被进一步识别为用户类型(1000以上),系统预定义类型(10000以上),所以最终颗粒类型不会为10,最终的组号可能为7,9(非夹杂物和未识别)或其他预定义的组,ID号则为识别出的ID号
  39. MAX = 10,
  40. }
  41. const int INVALIDPARTICLE= -1;
  42. /// <summary>
  43. /// 构造函数
  44. /// </summary>
  45. public DisplayField(Field fld, int fldwidth, int fldheight,double pixelSize,Point screenPos)
  46. {
  47. m_list_dparticle = new List<DisplayParticle>();
  48. m_id = System.Guid.NewGuid();
  49. Point thisfield_point = new Point() { X = fld.FieldPosX, Y = fld.FieldPosY };
  50. FieldID = fld.FieldID.ToString();
  51. var ltPoint = new Point(screenPos.X - fldwidth / 2, screenPos.Y -fldheight / 2);
  52. SetShow_Rect(new Rectangle(ltPoint, new Size(fldwidth, fldheight)));
  53. OTSCoordinatePos = new PointF(thisfield_point.X, thisfield_point.Y);
  54. double left = OTSCoordinatePos.X - fldwidth * pixelSize / 2;
  55. double right = OTSCoordinatePos.X + fldwidth * pixelSize / 2;
  56. double top = OTSCoordinatePos.Y + fldheight * pixelSize / 2;
  57. double bottom = OTSCoordinatePos.Y + fldheight * pixelSize / 2;
  58. myOTSRect.SetRectData( (int)left,(int)top,(int)right,(int)bottom);
  59. //先获取该Field中的所有Particle
  60. List<Particle> list_particle;
  61. list_particle = fld.ParticleList;
  62. //然后将取出的数据,转换成Bitmap对象
  63. m_originalImage = DrawFunction.ReadImageFile(fld.FieldImageName);
  64. Bitmap dpImage = new Bitmap(fldwidth, fldheight);
  65. //再循环计算所有的Particle对象
  66. foreach (Particle particle in list_particle)
  67. {
  68. //分布图排列图无效颗粒不显示
  69. if (particle.TypeId == (int)RemoveParticleType.INVALID|| particle.TypeId == (int)RemoveParticleType.LOW_COUNT)
  70. {
  71. continue;
  72. }
  73. //创建DParticle颗粒
  74. DisplayParticle dp = new DisplayParticle(particle, ltPoint, m_originalImage,dpImage);
  75. double partLeft=dp.objParticleData.RectLeft*pixelSize+myOTSRect.GetTopLeft().X;
  76. double partRight = partLeft+dp.objParticleData.RectWidth*pixelSize;
  77. double partTop = myOTSRect.GetTopLeft().Y - dp.objParticleData.RectTop * pixelSize;
  78. double partBottom = partTop - dp.objParticleData.RectHeight * pixelSize;
  79. dp.OTSRect.SetRectData((int)partLeft, (int)partTop, (int)partRight, (int)partBottom);
  80. m_list_dparticle.Add(dp);
  81. }
  82. }
  83. public DisplayField(List<DisplayParticle> in_list_dparticle)
  84. {
  85. m_list_dparticle = in_list_dparticle;
  86. }
  87. public DisplayField(int fldwidth, int fldheight,Point OTSPos, Point screenPos)
  88. {
  89. m_id = System.Guid.NewGuid();
  90. var ltPoint = new Point(screenPos.X - fldwidth / 2, screenPos.Y - fldheight / 2);
  91. SetShow_Rect(new Rectangle(ltPoint, new Size(fldwidth, fldheight)));
  92. m_ots_point = OTSPos;
  93. }
  94. public void Zoom(float zoomDelta , PointF refPoint)
  95. {
  96. m_Rect.Width += m_Rect.Width/ m_currentZoom * zoomDelta;
  97. m_Rect.Height += m_Rect.Height/ m_currentZoom * zoomDelta;
  98. //锚点缩放补差值计算,得出差值
  99. float xShiftOld = m_Rect.X - refPoint.X;
  100. float yShiftOld = m_Rect.Y - refPoint.Y;
  101. float xShift = m_Rect.X - refPoint.X + xShiftOld/ m_currentZoom * zoomDelta;
  102. float yShift = m_Rect.Y - refPoint.Y + yShiftOld/ m_currentZoom * zoomDelta;
  103. m_Rect.X = refPoint.X + xShift;
  104. m_Rect.Y = refPoint.Y + yShift;
  105. m_currentZoom += zoomDelta;
  106. }
  107. public void DraggingMove(PointF mousePoint)
  108. {
  109. m_Rect = new RectangleF(
  110. m_Rect.Left + Convert.ToSingle((mousePoint.X - DraggingPoint.X)),
  111. m_Rect.Top + Convert.ToSingle((mousePoint.Y - DraggingPoint.Y)),
  112. m_Rect.Width,
  113. m_Rect.Height);
  114. DraggingPoint = mousePoint;
  115. }
  116. public void Move(SizeF xyShift)
  117. {
  118. m_Rect = new RectangleF(
  119. m_Rect.Left- Convert.ToSingle(xyShift.Width),
  120. m_Rect.Top - Convert.ToSingle(xyShift.Height),
  121. m_Rect.Width,
  122. m_Rect.Height);
  123. }
  124. public Guid guid { get => m_id; set => m_id = value; }
  125. /// <summary>
  126. /// 是否被拖动标识
  127. /// </summary>
  128. public bool IsDragging { get => m_IsDragging; set => m_IsDragging = value; }
  129. /// <summary>
  130. /// 被拖动到的位置坐标
  131. /// </summary>
  132. public PointF DraggingPoint { get => m_dragingpoint; set => m_dragingpoint = value; }
  133. /// <summary>
  134. /// 与底层对应的ID,这里叫成FieldID
  135. /// </summary>
  136. public string FieldID
  137. {
  138. get { return m_fieldid; }
  139. set { m_fieldid = value; }
  140. }
  141. /// <summary>
  142. /// 包含的Particle列表
  143. /// </summary>
  144. public List<DisplayParticle> List_DParticle
  145. {
  146. get { return m_list_dparticle; }
  147. set { m_list_dparticle = value; }
  148. }
  149. /// <summary>
  150. /// 该Field的OTS坐标及大小
  151. /// </summary>
  152. public PointF OTSCoordinatePos
  153. {
  154. get { return m_ots_point; }
  155. set { m_ots_point = value; }
  156. }
  157. /// <summary>
  158. /// 该Field最后在屏幕上显示的坐标及大小
  159. /// </summary>
  160. public RectangleF GetShowRect()
  161. { return m_Rect; }
  162. /// <summary>
  163. /// 该Field最后在屏幕上显示的坐标及大小
  164. /// </summary>
  165. public void SetShow_Rect(RectangleF value)
  166. { m_Rect = value; }
  167. public Bitmap OriginalImage { get => m_originalImage; set => m_originalImage = value; }
  168. public Color ContentColor { get => disColor; set =>disColor = value; }
  169. public void OnPaint(PaintEventArgs e,Color bodyColor)
  170. {
  171. Graphics g = e.Graphics;
  172. float w = 1;
  173. Pen p = new Pen(bodyColor, w);
  174. var r = new Rectangle((int)m_Rect.Left, (int)m_Rect.Top, (int)m_Rect.Width, (int)m_Rect.Height);
  175. g.DrawRectangle(p, r);
  176. if (gradeString != "")
  177. {
  178. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(100, disColor));
  179. //字体大小 根据样品孔Rectangle大小
  180. float fontSize = m_Rect.Width / 20;
  181. Font font = new Font("宋体", fontSize, FontStyle.Bold);
  182. if (fontSize == 0)
  183. {
  184. font = new Font("宋体", 5, FontStyle.Bold);
  185. }
  186. RectangleF rectFont = m_Rect;
  187. rectFont.X += 2;
  188. rectFont.Y += 2;
  189. g.DrawString(gradeString, font, solidBrush, rectFont);
  190. }
  191. }
  192. }
  193. }