DisplayRectangle.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. using OTSCommon.DBOperate.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 DisplayRectangle
  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 DisplayRectangle(Field fld, float fldwidth, float fldheight,double pixelSize,PointF 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 PointF(screenPos.X - fldwidth / 2, screenPos.Y -fldheight / 2);
  52. SetShow_Rect(new RectangleF(ltPoint, new SizeF(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( (float)left,(float)top,(float)right,(float)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((int)fldwidth, (int)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((float )partLeft, (float)partTop, (float)partRight, (float)partBottom);
  80. m_list_dparticle.Add(dp);
  81. }
  82. }
  83. public DisplayRectangle(List<DisplayParticle> in_list_dparticle)
  84. {
  85. m_list_dparticle = in_list_dparticle;
  86. }
  87. public DisplayRectangle(float fldwidth, float fldheight,PointF OTSPos, PointF screenPos)
  88. {
  89. m_id = System.Guid.NewGuid();
  90. var ltPoint = new PointF(screenPos.X - fldwidth / 2, screenPos.Y - fldheight / 2);
  91. SetShow_Rect(new RectangleF(ltPoint, new SizeF(fldwidth, fldheight)));
  92. m_ots_point = OTSPos;
  93. }
  94. public bool WhetherInRange( PointF WhetherPoint)
  95. {
  96. var rect = GetShowRect();
  97. if ((rect.Left < WhetherPoint.X && WhetherPoint.X < rect.Right) && (rect.Top < WhetherPoint.Y && WhetherPoint.Y < rect.Bottom))
  98. {
  99. return true;
  100. }
  101. else
  102. {
  103. return false;
  104. }
  105. }
  106. public void Zoom(float zoomDelta , PointF refPoint)
  107. {
  108. m_Rect.Width += m_Rect.Width/ m_currentZoom * zoomDelta;
  109. m_Rect.Height += m_Rect.Height/ m_currentZoom * zoomDelta;
  110. //锚点缩放补差值计算,得出差值
  111. float xShiftOld = m_Rect.X - refPoint.X;
  112. float yShiftOld = m_Rect.Y - refPoint.Y;
  113. float xShift = m_Rect.X - refPoint.X + xShiftOld/ m_currentZoom * zoomDelta;
  114. float yShift = m_Rect.Y - refPoint.Y + yShiftOld/ m_currentZoom * zoomDelta;
  115. m_Rect.X = refPoint.X + xShift;
  116. m_Rect.Y = refPoint.Y + yShift;
  117. m_currentZoom += zoomDelta;
  118. }
  119. public void DraggingMove(PointF mousePoint)
  120. {
  121. m_Rect = new RectangleF(
  122. m_Rect.Left + Convert.ToSingle((mousePoint.X - DraggingPoint.X)),
  123. m_Rect.Top + Convert.ToSingle((mousePoint.Y - DraggingPoint.Y)),
  124. m_Rect.Width,
  125. m_Rect.Height);
  126. DraggingPoint = mousePoint;
  127. }
  128. public void Move(SizeF xyShift)
  129. {
  130. m_Rect = new RectangleF(
  131. m_Rect.Left- Convert.ToSingle(xyShift.Width),
  132. m_Rect.Top - Convert.ToSingle(xyShift.Height),
  133. m_Rect.Width,
  134. m_Rect.Height);
  135. }
  136. public Guid guid { get => m_id; set => m_id = value; }
  137. /// <summary>
  138. /// 是否被拖动标识
  139. /// </summary>
  140. public bool IsDragging { get => m_IsDragging; set => m_IsDragging = value; }
  141. /// <summary>
  142. /// 被拖动到的位置坐标
  143. /// </summary>
  144. public PointF DraggingPoint { get => m_dragingpoint; set => m_dragingpoint = value; }
  145. /// <summary>
  146. /// 与底层对应的ID,这里叫成FieldID
  147. /// </summary>
  148. public string FieldID
  149. {
  150. get { return m_fieldid; }
  151. set { m_fieldid = value; }
  152. }
  153. /// <summary>
  154. /// 包含的Particle列表
  155. /// </summary>
  156. public List<DisplayParticle> List_DParticle
  157. {
  158. get { return m_list_dparticle; }
  159. set { m_list_dparticle = value; }
  160. }
  161. /// <summary>
  162. /// 该Field的OTS坐标及大小
  163. /// </summary>
  164. public PointF OTSCoordinatePos
  165. {
  166. get { return m_ots_point; }
  167. set { m_ots_point = value; }
  168. }
  169. /// <summary>
  170. /// 该Field最后在屏幕上显示的坐标及大小
  171. /// </summary>
  172. public RectangleF GetShowRect()
  173. { return m_Rect; }
  174. /// <summary>
  175. /// 该Field最后在屏幕上显示的坐标及大小
  176. /// </summary>
  177. public void SetShow_Rect(RectangleF value)
  178. { m_Rect = value; }
  179. public Bitmap OriginalImage { get => m_originalImage; set => m_originalImage = value; }
  180. public Color ContentColor { get => disColor; set =>disColor = value; }
  181. public void Paint(PaintEventArgs e,Color bodyColor)
  182. {
  183. Graphics g = e.Graphics;
  184. float w = 1;
  185. Pen p = new Pen(bodyColor, w);
  186. var r = new Rectangle((int)m_Rect.Left, (int)m_Rect.Top, (int)m_Rect.Width, (int)m_Rect.Height);
  187. g.DrawRectangle(p, r);
  188. if (gradeString != "")
  189. {
  190. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(100, disColor));
  191. //字体大小 根据样品孔Rectangle大小
  192. float fontSize = m_Rect.Width / 20;
  193. Font font = new Font("宋体", fontSize, FontStyle.Bold);
  194. if (fontSize == 0)
  195. {
  196. font = new Font("宋体", 5, FontStyle.Bold);
  197. }
  198. RectangleF rectFont = m_Rect;
  199. rectFont.X += 2;
  200. rectFont.Y += 2;
  201. g.DrawString(gradeString, font, solidBrush, rectFont);
  202. }
  203. }
  204. }
  205. }