SEMDataMsr.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 xnScanFieldHeight;
  66. xmls::xInt xnScanFieldSize100;
  67. xmls::xDouble xdWorkingDistance;
  68. xmls::xInt xnTotalFields;
  69. xmls::Slo slo;
  70. slo.Register("ScanFieldSize", &xnScanFieldSize);
  71. slo.Register("ScanFieldHeight", &xnScanFieldHeight);
  72. slo.Register("ScanFieldSize100", &xnScanFieldSize100);
  73. slo.Register("WorkingDistance", &xdWorkingDistance);
  74. slo.Register("TotalFields", &xnTotalFields);
  75. if (isStoring)
  76. {
  77. xnScanFieldSize = m_nScanFieldSize;
  78. xnScanFieldHeight = m_nScanFieldHeight;
  79. xnScanFieldSize100 = m_nScanFieldSize100;
  80. xdWorkingDistance = m_dWorkingDistance;
  81. xnTotalFields = m_nTotalFields;
  82. slo.Serialize(true, classDoc, rootNode);
  83. }
  84. else
  85. {
  86. slo.Serialize(false, classDoc, rootNode);
  87. m_nScanFieldSize = xnScanFieldSize.value();
  88. m_nScanFieldHeight = xnScanFieldHeight.value();
  89. m_nScanFieldSize100 = xnScanFieldSize100.value();
  90. m_dWorkingDistance = xdWorkingDistance.value();
  91. m_nTotalFields = xnTotalFields.value();
  92. }
  93. }
  94. // get magnification
  95. double CSEMDataMsr::GetMagnification()
  96. {
  97. // magnification
  98. double dMag = 0.0;
  99. // convert scan field size to magnification
  100. if (m_nScanFieldSize > 0)
  101. {
  102. dMag = (double)m_nScanFieldSize100 * 100.0 / (double)m_nScanFieldSize;
  103. }
  104. // return magnification
  105. return dMag;
  106. }
  107. void CSEMDataMsr::SetMagnification(double a_dMag)
  108. {
  109. if (a_dMag < MAGNIFICATION_MIN)
  110. {
  111. return;
  112. }
  113. m_nScanFieldSize = (int)(100.0 * (double)m_nScanFieldSize100 / a_dMag + 0.5);
  114. }
  115. // protected
  116. // cleanup
  117. void CSEMDataMsr::Cleanup()
  118. {
  119. // need to do nothing at the moment
  120. }
  121. // initialization
  122. void CSEMDataMsr::Init()
  123. {
  124. m_nScanFieldSize = 0;
  125. m_nScanFieldSize100 = 0;
  126. m_dWorkingDistance = 0;
  127. m_nTotalFields = 0;
  128. }
  129. // duplication
  130. void CSEMDataMsr::Duplicate(const CSEMDataMsr& a_oSource)
  131. {
  132. // initialization
  133. Init();
  134. // copy data over
  135. m_nScanFieldSize = a_oSource.m_nScanFieldSize;
  136. m_nScanFieldSize100 = a_oSource.m_nScanFieldSize100;
  137. m_dWorkingDistance = a_oSource.m_dWorkingDistance;
  138. m_nTotalFields = a_oSource.m_nTotalFields;
  139. }
  140. }