ViewRectangleEx.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. using SmartCoalApplication.Annotation.Enum;
  2. using SmartCoalApplication.Base.CommTool;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.Drawing;
  7. using System.Drawing.Drawing2D;
  8. using System.Globalization;
  9. using System.Runtime.Serialization;
  10. using System.Windows.Forms;
  11. namespace SmartCoalApplication.Annotation.FieldView
  12. {
  13. /// <summary>
  14. /// 矩形视场绘制
  15. /// </summary>
  16. public class ViewRectangleEx : ViewBase
  17. {
  18. public override void SetK()
  19. {
  20. K = (double)(Points[1].Y - Points[0].Y) / (Points[1].X - Points[0].X);
  21. }
  22. #region Constructor
  23. public ViewRectangleEx()
  24. {
  25. objectType = DrawClass.View;
  26. drawToolType = DrawToolType.ViewRectangleEx;
  27. Rotatable = true;
  28. Initialize();
  29. }
  30. public ViewRectangleEx(Point p) : this()
  31. {
  32. for (int i = 0; i < 4; i++) AddPoint(p);
  33. }
  34. public ViewRectangleEx(List<PointF> points) : this()
  35. {
  36. Points = points;
  37. SetK();
  38. }
  39. #endregion
  40. /// <summary>
  41. /// 帮助创建任意四边形视场
  42. /// </summary>
  43. ///
  44. public void CreatStep(Point point, int step)
  45. {
  46. switch (step)
  47. {
  48. case 1:
  49. Points[1] = point;
  50. Points[2] = point;
  51. SetK();
  52. break;
  53. case 2:
  54. MoveCorner(point, 2);
  55. break;
  56. }
  57. OnPropertyChanged();
  58. }
  59. #region Handle
  60. public override int HandleCount => 9;
  61. public override PointF GetHandle(int i)
  62. {
  63. if (i == 9)
  64. {
  65. var x = GetHandle(2).X + GetHandle(3).X;
  66. var y = GetHandle(2).Y + GetHandle(3).Y;
  67. x = (float)((x / 2));
  68. y = (float)((y / 2));
  69. return new PointF(x, y);
  70. }
  71. else
  72. {
  73. var count = Points.Count;
  74. var x = Points[(i / 2) % count].X + Points[(i - 1) / 2].X;
  75. var y = Points[(i / 2) % count].Y + Points[(i - 1) / 2].Y;
  76. return new PointF(x / 2, y / 2);
  77. }
  78. }
  79. public override Cursor GetHandleCursor(int handleNumber)
  80. {
  81. if (handleNumber == 9)
  82. return m_rotateCursor;
  83. else
  84. return m_resizeCursor;
  85. }
  86. public override void MoveHandleTo(Point point, int handleNumber)
  87. {
  88. if (handleNumber == 9)
  89. MoveRotate(point);
  90. else if (handleNumber % 2 == 0)
  91. MoveEdge(point, handleNumber / 2 - 1);
  92. else
  93. MoveCorner(point, handleNumber / 2);
  94. OnPropertyChanged();
  95. }
  96. private void MoveCorner(Point point, int i)
  97. {
  98. this.Points[i] = point;
  99. if (i % 2 == 0)
  100. {
  101. this.Points[(i + 3) % 4] = BasicCalculationHelper.GetDropFeet(this.Points[(i + 2) % 4], K, point);
  102. this.Points[(i + 1) % 4] = BasicCalculationHelper.GetDropFeet(this.Points[(i + 2) % 4], -1 / K, point);
  103. }
  104. else
  105. {
  106. this.Points[(i + 1) % 4] = BasicCalculationHelper.GetDropFeet(this.Points[(i + 2) % 4], K, point);
  107. this.Points[(i + 3) % 4] = BasicCalculationHelper.GetDropFeet(this.Points[(i + 2) % 4], -1 / K, point);
  108. }
  109. }
  110. private void MoveEdge(Point point, int i)
  111. {
  112. var tempk = i % 2 != 0 ? K : -1 / K;
  113. this.Points[i] = BasicCalculationHelper.GetDropFeet(Points[(i + 3) % 4], tempk, point);
  114. this.Points[(i + 1) % 4] = BasicCalculationHelper.GetDropFeet(Points[(i + 2) % 4], tempk, point);
  115. }
  116. #endregion
  117. #region Clone
  118. public override DrawObject Clone()
  119. {
  120. return Clone(ISurfaceBox);
  121. }
  122. /// <summary>
  123. /// Clone this instance
  124. /// </summary>
  125. public override DrawObject Clone(ISurfaceBox surfaceBox)
  126. {
  127. ViewRectangleEx drawRectangle = new ViewRectangleEx(Points);
  128. drawRectangle.ISurfaceBox = surfaceBox;
  129. drawRectangle.combineMode = this.combineMode;
  130. drawRectangle.Color = Color;
  131. drawRectangle.ID = ID;
  132. FillDrawObjectFields(drawRectangle);
  133. return drawRectangle;
  134. }
  135. #endregion
  136. }
  137. }