SemPosition.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. //时间:20200610
  2. //作者:郝爽
  3. //功能:六孔坐标位置
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using FileManager;
  10. using System.Xml;
  11. namespace MeasureData
  12. {
  13. //六轴坐标系统
  14. public class SemPosition:ISlo
  15. {
  16. private float m_x, m_y, m_z, m_r, m_t, m_m;
  17. #region X
  18. //限定范围
  19. const float Xmax = 100;
  20. const float Xmin = 0;
  21. public float X
  22. {
  23. get { return this.m_x; }
  24. set => this.m_x = rangeCheckedX(value);
  25. }
  26. private static float rangeCheckedX(float x)
  27. {
  28. if (x > Xmax) x = Xmax;
  29. else if (x < Xmin) x = Xmin;
  30. return x;
  31. }
  32. #endregion
  33. #region Y
  34. //限定范围
  35. const float Ymax = 100;
  36. const float Ymin = 0;
  37. public float Y
  38. {
  39. get { return this.m_y; }
  40. set => this.m_y = rangeCheckedY(value);
  41. }
  42. private static float rangeCheckedY(float y)
  43. {
  44. if (y > Ymax) y = Ymax;
  45. else if (y < Ymin) y = Ymin;
  46. return y;
  47. }
  48. #endregion
  49. #region Z
  50. //限定范围
  51. const float Zmax = 100;
  52. const float Zmin = (float)0.005;
  53. public float Z
  54. {
  55. get { return this.m_z; }
  56. set => this.m_z = rangeCheckedZ(value);
  57. }
  58. private static float rangeCheckedZ(float z)
  59. {
  60. if (z > Zmax) z = Zmax;
  61. else if (z < Zmin) z = Zmin;
  62. return z;
  63. }
  64. #endregion
  65. #region R
  66. //限定范围
  67. const float Rmax = 360;
  68. const float Rmin = 0;
  69. public float R
  70. {
  71. get { return this.m_r; }
  72. set => this.m_r = rangeCheckedR(value);
  73. }
  74. private static float rangeCheckedR(float r)
  75. {
  76. if (r > Rmax) r = Rmax;
  77. else if (r < Rmin) r = Rmin;
  78. return r;
  79. }
  80. #endregion
  81. #region T
  82. //限定范围
  83. const float Tmax = 180;
  84. const float Tmin = 0;
  85. public float T
  86. {
  87. get { return this.m_t; }
  88. set => this.m_t = rangeCheckedT(value);
  89. }
  90. private static float rangeCheckedT(float t)
  91. {
  92. if (t > Tmax) t = Tmax;
  93. else if (t < Tmin) t = Tmin;
  94. return t;
  95. }
  96. #endregion
  97. #region M
  98. //限定范围
  99. const float Mmax = 100;
  100. const float Mmin = 0;
  101. public float M
  102. {
  103. get { return this.m_m; }
  104. set => this.m_m = rangeCheckedM(value);
  105. }
  106. private static float rangeCheckedM(float m)
  107. {
  108. if (m > Mmax) m = Mmax;
  109. else if (m < Mmin) m = Mmin;
  110. return m;
  111. }
  112. #endregion
  113. public SemPosition()
  114. {
  115. m_x = 0;
  116. m_y = 0;
  117. m_z = 0;
  118. m_r = 0;
  119. m_t = 0;
  120. m_m = 0;
  121. }
  122. public override void Serialize(bool isStoring, XmlDocument xml, XmlNode rootNode)
  123. {
  124. Slo<SemPosition> slo_sp = new Slo<SemPosition>();
  125. xDouble ptx = new xDouble();
  126. ptx.AssignValue(this.X);
  127. slo_sp.Register("X", ptx);
  128. xDouble pty = new xDouble();
  129. pty.AssignValue(this.Y);
  130. slo_sp.Register("Y", pty);
  131. xDouble ptz = new xDouble();
  132. ptz.AssignValue(this.Z);
  133. slo_sp.Register("Z", ptz);
  134. xDouble ptt = new xDouble();
  135. ptt.AssignValue(this.T);
  136. slo_sp.Register("T", ptt);
  137. xDouble ptr = new xDouble();
  138. ptr.AssignValue(this.R);
  139. slo_sp.Register("R", ptr);
  140. xDouble ptm = new xDouble();
  141. ptm.AssignValue(this.M);
  142. slo_sp.Register("M", ptm);
  143. if (isStoring)
  144. {
  145. slo_sp.Serialize(true, xml, rootNode);
  146. }
  147. else
  148. {
  149. slo_sp.Serialize(false, xml, rootNode);
  150. this.X = (float)ptx.value();
  151. this.Y = (float)pty.value();
  152. this.Z = (float)ptz.value();
  153. this.T = (float)ptt.value();
  154. this.R = (float)ptr.value();
  155. this.M = (float)ptm.value();
  156. }
  157. }
  158. }
  159. }