SEMDataMsr.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. // SEMDtaMsr.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. //#include "OTSData.h"
  5. #include "SEMDataMsr.h"
  6. namespace OTSDATA {
  7. // constructor
  8. CSEMDataMsr::CSEMDataMsr()
  9. {
  10. // initialization
  11. Init();
  12. }
  13. // copy constructor
  14. CSEMDataMsr::CSEMDataMsr(const CSEMDataMsr& a_oSource)
  15. {
  16. // can't copy itself
  17. if (&a_oSource == this)
  18. {
  19. return;
  20. }
  21. // copy data over
  22. Duplicate(a_oSource);
  23. }
  24. // copy constructor
  25. CSEMDataMsr::CSEMDataMsr(CSEMDataMsr* a_poSource)
  26. {
  27. // can't copy itself
  28. if (a_poSource == this)
  29. {
  30. return;
  31. }
  32. // copy data over
  33. Duplicate(*a_poSource);
  34. }
  35. // =operator
  36. CSEMDataMsr& CSEMDataMsr::operator=(const CSEMDataMsr& a_oSource)
  37. {
  38. // cleanup
  39. Cleanup();
  40. // copy the class data over
  41. Duplicate(a_oSource);
  42. // return class
  43. return *this;
  44. }
  45. // destructor
  46. CSEMDataMsr::~CSEMDataMsr()
  47. {
  48. // cleanup
  49. Cleanup();
  50. }
  51. // ==operator
  52. BOOL CSEMDataMsr::operator==(const CSEMDataMsr& a_oSource)
  53. {
  54. return m_nScanFieldSize == a_oSource.m_nScanFieldSize &&
  55. m_nScanFieldSize100 == a_oSource.m_nScanFieldSize100 &&
  56. abs(m_dWorkingDistance - a_oSource.m_dWorkingDistance) < MIN_DOUBLE_VALUE /*&&
  57. m_nTotalFields == a_oSource.m_nTotalFields*/;
  58. }
  59. // CSEMDataMsr member functions
  60. // public
  61. // serialization
  62. void CSEMDataMsr::Serialize(bool isStoring, tinyxml2::XMLDocument * classDoc, tinyxml2::XMLElement * rootNode)
  63. {
  64. xmls::xInt xnScanFieldSize;
  65. xmls::xInt xnScanFieldSize100;
  66. xmls::xDouble xdWorkingDistance;
  67. xmls::xInt xnTotalFields;
  68. xmls::Slo slo;
  69. slo.Register("ScanFieldSize", &xnScanFieldSize);
  70. slo.Register("ScanFieldSize100", &xnScanFieldSize100);
  71. slo.Register("WorkingDistance", &xdWorkingDistance);
  72. slo.Register("TotalFields", &xnTotalFields);
  73. if (isStoring)
  74. {
  75. xnScanFieldSize = m_nScanFieldSize;
  76. xnScanFieldSize100 = m_nScanFieldSize100;
  77. xdWorkingDistance = m_dWorkingDistance;
  78. xnTotalFields = m_nTotalFields;
  79. slo.Serialize(true, classDoc, rootNode);
  80. }
  81. else
  82. {
  83. slo.Serialize(false, classDoc, rootNode);
  84. m_nScanFieldSize = xnScanFieldSize.value();
  85. m_nScanFieldSize100 = xnScanFieldSize100.value();
  86. m_dWorkingDistance = xdWorkingDistance.value();
  87. m_nTotalFields = xnTotalFields.value();
  88. }
  89. }
  90. // get magnification
  91. double CSEMDataMsr::GetMagnification()
  92. {
  93. // magnification
  94. double dMag = 0.0;
  95. // convert scan field size to magnification
  96. if (m_nScanFieldSize > 0)
  97. {
  98. dMag = (double)m_nScanFieldSize100 * 100.0 / (double)m_nScanFieldSize;
  99. }
  100. // return magnification
  101. return dMag;
  102. }
  103. void CSEMDataMsr::SetMagnification(double a_dMag)
  104. {
  105. if (a_dMag < MAGNIFICATION_MIN)
  106. {
  107. return;
  108. }
  109. m_nScanFieldSize = (int)(100.0 * (double)m_nScanFieldSize100 / a_dMag + 0.5);
  110. }
  111. // protected
  112. // cleanup
  113. void CSEMDataMsr::Cleanup()
  114. {
  115. // need to do nothing at the moment
  116. }
  117. // initialization
  118. void CSEMDataMsr::Init()
  119. {
  120. m_nScanFieldSize = 0;
  121. m_nScanFieldSize100 = 0;
  122. m_dWorkingDistance = 0;
  123. m_nTotalFields = 0;
  124. }
  125. // duplication
  126. void CSEMDataMsr::Duplicate(const CSEMDataMsr& a_oSource)
  127. {
  128. // initialization
  129. Init();
  130. // copy data over
  131. m_nScanFieldSize = a_oSource.m_nScanFieldSize;
  132. m_nScanFieldSize100 = a_oSource.m_nScanFieldSize100;
  133. m_dWorkingDistance = a_oSource.m_dWorkingDistance;
  134. m_nTotalFields = a_oSource.m_nTotalFields;
  135. }
  136. }