PropItem.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. #include "stdafx.h"
  2. #include "PropItem.h"
  3. namespace OTSMODEL {
  4. // CPropItem
  5. // constructor
  6. CPropItem::CPropItem()
  7. {
  8. // initialization
  9. Init();
  10. }
  11. // copy constructor
  12. CPropItem::CPropItem(const CPropItem& a_oSource)
  13. {
  14. // can't copy itself
  15. if (&a_oSource == this)
  16. {
  17. return;
  18. }
  19. // copy data over
  20. Duplicate(a_oSource);
  21. }
  22. CPropItem::CPropItem(CPropItem* a_poSource)
  23. {
  24. // input check
  25. ASSERT(a_poSource);
  26. if (!a_poSource)
  27. {
  28. return;
  29. }
  30. // can't copy itself
  31. if (a_poSource == this)
  32. {
  33. return;
  34. }
  35. // copy data over
  36. Duplicate(*a_poSource);
  37. }
  38. // =operator
  39. CPropItem& CPropItem::operator=(const CPropItem& a_oSource)
  40. {
  41. // cleanup
  42. Cleanup();
  43. // copy the class data over
  44. Duplicate(a_oSource);
  45. // return class
  46. return *this;
  47. }
  48. // destructor
  49. CPropItem::~CPropItem()
  50. {
  51. // cleanup
  52. Cleanup();
  53. }
  54. // class function
  55. // public
  56. // set sample parameter
  57. void CPropItem::SetSmplParameter(OTS_SAMPLE_PROP_GRID_ITEMS a_nSmplId, OTS_ITEM_TYPES a_nType, BOOL a_bReadOnly, BOOL a_bShow)
  58. {
  59. m_nSmplId = a_nSmplId;
  60. m_nType = a_nType;
  61. m_bReadOnly = a_bReadOnly;
  62. m_bShow = a_bShow;
  63. }
  64. // set report parameter
  65. void CPropItem::SetReportParameter(OTS_RETORT_PROP_GRID_ITEMS a_nReportId, OTS_ITEM_TYPES a_nType, BOOL a_bReadOnly)
  66. {
  67. m_nReportId = a_nReportId;
  68. m_nType = a_nType;
  69. m_bReadOnly = a_bReadOnly;
  70. }
  71. // protected
  72. // cleanup
  73. void CPropItem::Cleanup()
  74. {
  75. }
  76. // initialization
  77. void CPropItem::Init()
  78. {
  79. m_strName = _T("");
  80. m_strDescription = _T("");
  81. m_nSmplId = OTS_SAMPLE_PROP_GRID_ITEMS::INVALID;
  82. m_nReportId = OTS_RETORT_PROP_GRID_ITEMS::INVALID;
  83. m_nType = OTS_ITEM_TYPES::INVALID;
  84. m_bReadOnly = FALSE;
  85. m_bShow = TRUE;
  86. }
  87. // duplication
  88. void CPropItem::Duplicate(const CPropItem& a_oSource)
  89. {
  90. // initialization
  91. Init();
  92. // copy data over
  93. m_strName = a_oSource.m_strName;
  94. m_strDescription = a_oSource.m_strDescription;
  95. m_nSmplId = a_oSource.m_nSmplId;
  96. m_nReportId = a_oSource.m_nReportId;
  97. m_nType = a_oSource.m_nType;
  98. m_bReadOnly = a_oSource.m_bReadOnly;
  99. m_bShow = a_oSource.m_bShow;
  100. }
  101. // CPropItemGrp
  102. CPropItemGrp::CPropItemGrp()
  103. {
  104. // initialization
  105. Init();
  106. }
  107. // copy constructor
  108. CPropItemGrp::CPropItemGrp(const CPropItemGrp& a_oSource)
  109. {
  110. // can't copy itself
  111. if (&a_oSource == this)
  112. {
  113. return;
  114. }
  115. // copy data over
  116. Duplicate(a_oSource);
  117. }
  118. CPropItemGrp::CPropItemGrp(CPropItemGrp* a_poSource)
  119. {
  120. // input check
  121. ASSERT(a_poSource);
  122. if (!a_poSource)
  123. {
  124. return;
  125. }
  126. // can't copy itself
  127. if (a_poSource == this)
  128. {
  129. return;
  130. }
  131. // copy data over
  132. Duplicate(*a_poSource);
  133. }
  134. // =operator
  135. CPropItemGrp& CPropItemGrp::operator=(const CPropItemGrp& a_oSource)
  136. {
  137. // cleanup
  138. Cleanup();
  139. // copy the class data over
  140. Duplicate(a_oSource);
  141. // return class
  142. return *this;
  143. }
  144. // destructor
  145. CPropItemGrp::~CPropItemGrp()
  146. {
  147. // clean up
  148. Cleanup();
  149. }
  150. // class function
  151. // public
  152. // items list
  153. void CPropItemGrp::SetItemsList(CPropItemsList& a_listPropItems)
  154. {
  155. m_listPropItems.clear();
  156. for (auto poPropItem : a_listPropItems)
  157. {
  158. CPropItemPtr poPropItemNew(new CPropItem(poPropItem.get()));
  159. m_listPropItems.push_back(poPropItemNew);
  160. }
  161. }
  162. void CPropItemGrp::GetItemsIdRange(OTS_SAMPLE_PROP_GRID_ITEMS& a_nPropItemIdMin, OTS_SAMPLE_PROP_GRID_ITEMS& a_nPropItemIdMax)
  163. {
  164. a_nPropItemIdMin = a_nPropItemIdMax = OTS_SAMPLE_PROP_GRID_ITEMS::INVALID;
  165. if (m_listPropItems.size() > 0)
  166. {
  167. a_nPropItemIdMin = a_nPropItemIdMax = m_listPropItems[0]->GetSmplItemId();
  168. for (auto poPropItem : m_listPropItems)
  169. {
  170. a_nPropItemIdMin = (OTS_SAMPLE_PROP_GRID_ITEMS)min((int)a_nPropItemIdMin, (int)poPropItem->GetSmplItemId());
  171. a_nPropItemIdMax = (OTS_SAMPLE_PROP_GRID_ITEMS)max((int)a_nPropItemIdMax, (int)poPropItem->GetSmplItemId());
  172. }
  173. }
  174. }
  175. // protected
  176. // cleanup
  177. void CPropItemGrp::Cleanup()
  178. {
  179. m_listPropItems.clear();
  180. }
  181. // initialization
  182. void CPropItemGrp::Init()
  183. {
  184. m_strName = _T("");
  185. m_listPropItems.clear();
  186. }
  187. // duplication
  188. void CPropItemGrp::Duplicate(const CPropItemGrp& a_oSource)
  189. {
  190. // initialization
  191. Init();
  192. // copy data over
  193. m_strName = a_oSource.m_strName;
  194. for (auto poPropItem : a_oSource.m_listPropItems)
  195. {
  196. CPropItemPtr poPropItemNew(new CPropItem(poPropItem.get()));
  197. m_listPropItems.push_back(poPropItemNew);
  198. }
  199. }
  200. }