STDItem.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. #include "stdafx.h"
  2. //#include "OTSData.h"
  3. #include "STDItem.h"
  4. namespace OTSClassifyEngine {
  5. // CSTDItem
  6. // constructor
  7. CSTDItem::CSTDItem()
  8. {
  9. // initialization
  10. Init();
  11. }
  12. // copy constructor
  13. CSTDItem::CSTDItem(const CSTDItem& a_oSource)
  14. {
  15. // can't copy itself
  16. if (&a_oSource == this)
  17. {
  18. return;
  19. }
  20. // copy data over
  21. Duplicate(a_oSource);
  22. }
  23. // copy constructor
  24. CSTDItem::CSTDItem(CSTDItem* a_poSource)
  25. {
  26. // can't copy itself
  27. if (a_poSource == this)
  28. {
  29. return;
  30. }
  31. // copy data over
  32. Duplicate(*a_poSource);
  33. }
  34. // =operator
  35. CSTDItem& CSTDItem::operator=(const CSTDItem& a_oSource)
  36. {
  37. // cleanup
  38. Cleanup();
  39. // copy the class data over
  40. Duplicate(a_oSource);
  41. // return class
  42. return *this;
  43. }
  44. // ==operator
  45. BOOL CSTDItem::operator==(const CSTDItem& a_oSource)
  46. {
  47. // element rangers list
  48. int nSize = (int)m_listElementRange.size();
  49. if (nSize != (int)a_oSource.m_listElementRange.size())
  50. {
  51. return FALSE;
  52. }
  53. for (int i = 0; i < nSize; ++i)
  54. {
  55. if ( !( *(m_listElementRange[i].get()) == *(a_oSource.m_listElementRange[i].get())))
  56. {
  57. return FALSE;
  58. }
  59. }
  60. // members
  61. return m_strName.Compare(a_oSource.m_strName) == 0 &&
  62. m_nSTDId == a_oSource.m_nSTDId &&
  63. m_clrColor == a_oSource.m_clrColor &&
  64. abs(m_dCircleRadio - a_oSource.m_dCircleRadio) < MIN_DOUBLE_VALUE &&
  65. abs(m_dRectRadio - a_oSource.m_dRectRadio) < MIN_DOUBLE_VALUE &&
  66. abs(m_dWidth_Height - a_oSource.m_dWidth_Height) < MIN_DOUBLE_VALUE &&
  67. *(m_poGrayLevel.get()) == *(a_oSource.m_poGrayLevel.get());
  68. }
  69. // destructor
  70. CSTDItem::~CSTDItem()
  71. {
  72. // cleanup
  73. Cleanup();
  74. }
  75. // CSTDItem member functions
  76. // public
  77. // serialization
  78. // element ranges list
  79. void CSTDItem::SetElementRangeList(CElementRangeList& a_listElementRange, BOOL a_bClear /*= TRUE*/)
  80. {
  81. // clear the element ranges list if necessary
  82. if (a_bClear)
  83. {
  84. m_listElementRange.clear();
  85. }
  86. // go through the input list
  87. for (auto pElementRange : a_listElementRange)
  88. {
  89. // create a element range copy
  90. CElementRangePtr pElementRangeNew(new CElementRange(pElementRange.get()));
  91. // add the new element range into element ranges list
  92. m_listElementRange.push_back(pElementRangeNew);
  93. }
  94. }
  95. // protected
  96. void CSTDItem::Serialize(bool isStoring, tinyxml2::XMLDocument * classDoc, tinyxml2::XMLElement * rootNode)
  97. {
  98. // name
  99. xmls::xString xstrName;
  100. // color
  101. xmls::xString xsclrColor;//COLORREF, C# can't access
  102. // circle radio
  103. xmls::xDouble xdCircleRadio;
  104. // rectangle radio
  105. xmls::xDouble xdRectRadio;
  106. // STD id
  107. xmls::xInt xnSTDId;
  108. // width/height radio
  109. xmls::xDouble xdWidth_Height;
  110. // element range num
  111. xmls::xInt xnElement;
  112. xmls::Collection< CElementRange> xElementRanges;
  113. xmls::Slo slo;
  114. slo.Register("Name", &xstrName);
  115. slo.Register("Color", &xsclrColor);
  116. slo.Register("CircleRadio", &xdCircleRadio);
  117. slo.Register("RectRadio", &xdRectRadio);
  118. slo.Register("STDId", &xnSTDId);
  119. slo.Register("Width_Height", &xdWidth_Height);
  120. slo.Register("GrayLevel", m_poGrayLevel.get());
  121. slo.Register("ElementRanges", &xElementRanges);
  122. if (isStoring)
  123. {
  124. xstrName = m_strName;
  125. xsclrColor = m_clrColor;
  126. xdCircleRadio = m_dCircleRadio;
  127. xdRectRadio = m_dRectRadio;
  128. xdWidth_Height = m_dWidth_Height;
  129. xnSTDId = m_nSTDId;
  130. xElementRanges.Clear();
  131. for (auto poElementRange : m_listElementRange)
  132. {
  133. xElementRanges.addItem(poElementRange.get());
  134. }
  135. slo.Serialize(true, classDoc, rootNode);
  136. }
  137. else
  138. {
  139. slo.Serialize(false, classDoc, rootNode);
  140. m_strName = xstrName.value().c_str();
  141. m_clrColor = xsclrColor.value().c_str();
  142. m_dCircleRadio = xdCircleRadio.value();
  143. m_dRectRadio = xdRectRadio.value();
  144. m_dWidth_Height = xdWidth_Height.value();
  145. m_nSTDId = xnSTDId.value();
  146. m_listElementRange.clear();
  147. for (int i = 0; i < xElementRanges.size (); ++i)
  148. {
  149. m_listElementRange.push_back(CElementRangePtr(xElementRanges.getItem(i)));
  150. }
  151. xElementRanges.Clear();
  152. }
  153. }
  154. // cleanup
  155. void CSTDItem::Cleanup()
  156. {
  157. // need to do nothing at the moment
  158. }
  159. // initialization
  160. void CSTDItem::Init()
  161. {
  162. // initialization
  163. m_strName = _T("");
  164. m_clrColor = _T("");
  165. m_nSTDId = 0;
  166. m_dCircleRadio = 0.0;
  167. m_dRectRadio = 0;
  168. m_dWidth_Height = 0;
  169. m_poGrayLevel = CIntRangePtr(new CIntRange());
  170. m_listElementRange.clear();
  171. }
  172. // duplication
  173. void CSTDItem::Duplicate(const CSTDItem& a_oSource)
  174. {
  175. // initialization
  176. Init();
  177. // copy data over
  178. m_strName = a_oSource.m_strName;
  179. m_clrColor = a_oSource.m_clrColor;
  180. m_nSTDId = a_oSource.m_nSTDId;
  181. m_dCircleRadio = a_oSource.m_dCircleRadio;
  182. m_dRectRadio = a_oSource.m_dRectRadio;
  183. m_dWidth_Height = a_oSource.m_dWidth_Height;
  184. m_poGrayLevel = CIntRangePtr(new CIntRange(a_oSource.m_poGrayLevel.get()));
  185. for (auto pElementRange : a_oSource.m_listElementRange)
  186. {
  187. CElementRangePtr pElementRangeNew = CElementRangePtr(new CElementRange(pElementRange.get()));
  188. m_listElementRange.push_back(pElementRange);
  189. }
  190. }
  191. }