PropItem.cpp 4.3 KB

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