CDoubleRange.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Xml;
  7. namespace OTSDataType
  8. {
  9. public class CDoubleRange:ISlo
  10. {
  11. private double m_dStart;
  12. private double m_dEnd;
  13. public CDoubleRange()
  14. {
  15. m_dStart = 0;
  16. m_dEnd = 0;
  17. }
  18. public CDoubleRange(double a_dStart, double a_dEnd)
  19. {
  20. m_dStart = Math.Min(a_dStart, a_dEnd);
  21. m_dEnd = Math.Max(a_dStart, a_dEnd);
  22. }
  23. public CDoubleRange(CDoubleRange a_poSource)
  24. {
  25. // can't copy itself
  26. if (a_poSource == this)
  27. {
  28. return;
  29. }
  30. // copy data over
  31. Duplicate(a_poSource);
  32. }
  33. public void Duplicate( CDoubleRange a_oSource)
  34. { // copy data over
  35. m_dStart = a_oSource.m_dStart;
  36. m_dEnd = a_oSource.m_dEnd;
  37. }
  38. public void Normalise()
  39. {
  40. m_dEnd = Math.Max(m_dStart, m_dEnd);
  41. m_dStart = Math.Min(m_dStart, m_dEnd);
  42. }
  43. public bool DataInRange(double a_dData)
  44. {
  45. return a_dData >= m_dStart && a_dData <= m_dEnd;
  46. }
  47. // start
  48. public void SetStart(double a_dStart)
  49. {
  50. m_dStart = a_dStart;
  51. Normalise();
  52. }
  53. public double GetStart()
  54. {
  55. return m_dStart;
  56. }
  57. // end
  58. public void SetEnd(double a_dEnd)
  59. {
  60. m_dEnd = a_dEnd;
  61. Normalise();
  62. }
  63. public double GetEnd()
  64. {
  65. return m_dEnd;
  66. }
  67. public bool equals(CDoubleRange a_oSource)
  68. {
  69. return m_dStart == a_oSource.m_dStart && m_dEnd == a_oSource.m_dEnd;
  70. }
  71. public override void Serialize(bool isStoring, XmlDocument classDoc, XmlNode rootNode)
  72. {
  73. xDouble xStart=new xDouble();
  74. xDouble xEnd=new xDouble();
  75. Slo slo=new Slo();
  76. slo.Register("start", xStart);
  77. slo.Register("end", xEnd);
  78. if (isStoring)
  79. {
  80. xStart.AssignValue( m_dStart);
  81. xEnd .AssignValue(m_dEnd);
  82. slo.Serialize(true, classDoc, rootNode);
  83. }
  84. else
  85. {
  86. slo.Serialize(false, classDoc, rootNode);
  87. m_dStart = xStart.value();
  88. m_dEnd = xEnd.value();
  89. }
  90. }
  91. }
  92. }