DisplayRectangle.cs 9.8 KB

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