GridData.cpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. #include "stdafx.h"
  2. #include "GridData.h"
  3. namespace OTSDATA {
  4. //CGridRow:
  5. // constructor
  6. CGridRow::CGridRow() // constructor
  7. {
  8. Init();
  9. }
  10. CGridRow::CGridRow(const CGridRow& a_oSource) // copy constructor
  11. {
  12. // can't copy itself
  13. if (&a_oSource == this)
  14. {
  15. return;
  16. }
  17. // copy data over
  18. Duplicate(a_oSource);
  19. }
  20. CGridRow::CGridRow(CGridRow* a_poSource) // copy constructor
  21. {
  22. // input check
  23. ASSERT(a_poSource);
  24. if (!a_poSource)
  25. {
  26. return;
  27. }
  28. // can't copy itself
  29. if (a_poSource == this)
  30. {
  31. return;
  32. }
  33. // copy data over
  34. Duplicate(*a_poSource);
  35. }
  36. CGridRow& CGridRow::operator=(const CGridRow& a_oSource) // =operator
  37. {
  38. // cleanup
  39. Cleanup();
  40. // copy the class data over
  41. Duplicate(a_oSource);
  42. // return class
  43. return *this;
  44. }
  45. BOOL CGridRow::operator==(const CGridRow& a_oSource) // ==operator
  46. {
  47. return (m_strValue.Compare(a_oSource.m_strValue) == 0 &&
  48. *(m_oParticle.get()) == *(a_oSource.m_oParticle.get()) &&
  49. m_nDataType == a_oSource.m_nDataType &&
  50. m_nIntValue == a_oSource.m_nIntValue &&
  51. m_dFloatValue == a_oSource.m_dFloatValue);
  52. }
  53. CGridRow::~CGridRow() // destructor
  54. {
  55. // cleanup
  56. Cleanup();
  57. }
  58. BOOL CGridRow::SetParticle(COTSParticlePtr a_oParticle)
  59. {
  60. ASSERT(a_oParticle);
  61. if (!a_oParticle)
  62. {
  63. return FALSE;
  64. }
  65. m_oParticle = COTSParticlePtr(new COTSParticle(*a_oParticle.get()));
  66. return TRUE;
  67. }
  68. //protected
  69. // cleanup
  70. void CGridRow::Cleanup()
  71. {
  72. }
  73. // initialization
  74. void CGridRow::Init()
  75. {
  76. // data type
  77. m_nDataType = REPORT_GRID_DATA_TYPE::INVALID;
  78. // string data
  79. m_strValue = _T("");
  80. // particle data
  81. m_oParticle = COTSParticlePtr(new COTSParticle());
  82. // int value
  83. m_nIntValue = -1;
  84. // float value
  85. m_dFloatValue = 0.0;
  86. }
  87. // duplication
  88. void CGridRow::Duplicate(const CGridRow& a_oSource)
  89. {
  90. // initialization
  91. Init();
  92. m_nDataType = a_oSource.m_nDataType;
  93. // string data
  94. m_strValue = a_oSource.m_strValue;
  95. // particle data
  96. m_oParticle = COTSParticlePtr(new COTSParticle(*a_oSource.m_oParticle.get()));
  97. // int value
  98. m_nIntValue = a_oSource.m_nIntValue;
  99. // float value
  100. m_dFloatValue = a_oSource.m_dFloatValue;
  101. }
  102. //CGridColumn
  103. // constructor
  104. CGridColumn::CGridColumn() // constructor
  105. {
  106. Init();
  107. }
  108. CGridColumn::CGridColumn(const CGridColumn& a_oSource) // copy constructor
  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. CGridColumn::CGridColumn(CGridColumn* a_poSource) // copy constructor
  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. CGridColumn& CGridColumn::operator=(const CGridColumn& a_oSource) // =operator
  135. {
  136. // cleanup
  137. Cleanup();
  138. // copy the class data over
  139. Duplicate(a_oSource);
  140. // return class
  141. return *this;
  142. }
  143. BOOL CGridColumn::operator==(const CGridColumn& a_oSource) // ==operator
  144. {
  145. CGridRowsList listGridRows = a_oSource.m_listGridRows;
  146. if ((int)listGridRows.size() != (int)m_listGridRows.size())
  147. {
  148. return FALSE;
  149. }
  150. for (int i = 0; i< (int)m_listGridRows.size(); i++)
  151. {
  152. if (*(m_listGridRows[i].get()) == *(listGridRows[i].get()))
  153. {
  154. return FALSE;
  155. }
  156. }
  157. return (m_strName.Compare(a_oSource.m_strName) == 0);
  158. }
  159. CGridColumn::~CGridColumn() // destructor
  160. {
  161. }
  162. BOOL CGridColumn::SetGridRowsList(CGridRowsList a_listGridRows, BOOL a_bClear/* = TRUE*/)
  163. {
  164. if (a_bClear)
  165. {
  166. m_listGridRows.clear();
  167. }
  168. for (auto pGridRows : a_listGridRows)
  169. {
  170. CGridRowPtr pGridRowNew = CGridRowPtr(new CGridRow(*pGridRows.get()));
  171. m_listGridRows.push_back(pGridRowNew);
  172. }
  173. return TRUE;
  174. }
  175. //protected
  176. // cleanup
  177. void CGridColumn::Cleanup()
  178. {
  179. }
  180. // initialization
  181. void CGridColumn::Init()
  182. {
  183. // name
  184. m_strName = _T("");
  185. // list of rows
  186. m_listGridRows.clear();
  187. }
  188. // duplication
  189. void CGridColumn::Duplicate(const CGridColumn& a_oSource)
  190. {
  191. m_strName = a_oSource.m_strName;
  192. // list of rows
  193. m_listGridRows.clear();
  194. for (auto pGridRows : a_oSource.m_listGridRows)
  195. {
  196. CGridRowPtr pGridRowNew = CGridRowPtr(new CGridRow(*pGridRows.get()));
  197. m_listGridRows.push_back(pGridRowNew);
  198. }
  199. }
  200. // CGridColunm
  201. // constructor
  202. CGridData::CGridData() // constructor
  203. {
  204. Init();
  205. }
  206. CGridData::CGridData(const CGridData& a_oSource) // copy constructor
  207. {
  208. // can't copy itself
  209. if (&a_oSource == this)
  210. {
  211. return;
  212. }
  213. // copy data over
  214. Duplicate(a_oSource);
  215. }
  216. CGridData::CGridData(CGridData* a_poSource) // copy constructor
  217. {
  218. // input check
  219. ASSERT(a_poSource);
  220. if (!a_poSource)
  221. {
  222. return;
  223. }
  224. // can't copy itself
  225. if (a_poSource == this)
  226. {
  227. return;
  228. }
  229. // copy data over
  230. Duplicate(*a_poSource);
  231. }
  232. CGridData& CGridData::operator=(const CGridData& a_oSource) // =operator
  233. {
  234. // cleanup
  235. Cleanup();
  236. // copy the class data over
  237. Duplicate(a_oSource);
  238. // return class
  239. return *this;
  240. }
  241. BOOL CGridData::operator==(const CGridData& a_oSource) // ==operator
  242. {
  243. CGridColumnsList listGridColumns = a_oSource.m_listGridColumn;
  244. if ((int)listGridColumns.size() != (int)m_listGridColumn.size())
  245. {
  246. return FALSE;
  247. }
  248. for (int i = 0; i < (int)m_listGridColumn.size(); i++)
  249. {
  250. if (*(m_listGridColumn[i].get()) == *(listGridColumns[i].get()))
  251. {
  252. return FALSE;
  253. }
  254. }
  255. return TRUE;
  256. }
  257. CGridData::~CGridData() // destructor
  258. {
  259. }
  260. BOOL CGridData::SetGridColumnList(CGridColumnsList a_listGridColumn, BOOL a_bClear/* = TRUE*/)
  261. {
  262. if (a_bClear)
  263. {
  264. m_listGridColumn.clear();
  265. }
  266. for (auto pGridColumn : a_listGridColumn)
  267. {
  268. CGridColumnPtr pGridColumnNew = CGridColumnPtr(new CGridColumn(*pGridColumn.get()));
  269. m_listGridColumn.push_back(pGridColumnNew);
  270. }
  271. return TRUE;
  272. }
  273. // data source id
  274. BOOL CGridData::SetDataSourceList(std::vector<CString> a_listDataSource)
  275. {
  276. // data source count is reduced?
  277. if (m_listDataSource.size() > a_listDataSource.size())
  278. {
  279. // need to check if data source id has to be changed
  280. // data source count is 0
  281. if ((int)a_listDataSource.size() == 0)
  282. {
  283. // set data source id to -1, no working data source
  284. m_nDataSourceId = -1;
  285. }
  286. // need to set data source id to 0?
  287. else if (m_nDataSourceId >= (int)a_listDataSource.size())
  288. {
  289. // set data source id to 0, the first data source is the working data source
  290. m_nDataSourceId = 0;
  291. }
  292. else if (m_nDataSourceId == -1 && (int)a_listDataSource.size() > 0)
  293. {
  294. // set data source id to 0, the first data source is the working data source
  295. m_nDataSourceId = 0;
  296. }
  297. }
  298. // set data source count
  299. m_listDataSource = a_listDataSource;
  300. // ok, return TRUE
  301. return TRUE;
  302. }
  303. BOOL CGridData::SetDataSourceId(int a_nDataSourceId)
  304. {
  305. // data source id can't be < -1, -1 means no working data source
  306. if (a_nDataSourceId < -1)
  307. {
  308. return FALSE;
  309. }
  310. // data source id >= data source count
  311. /*else if (a_nDataSourceId >= (int)m_listDataSource.size())
  312. {
  313. return FALSE;
  314. }*/
  315. m_nDataSourceId = a_nDataSourceId;
  316. // ok, return TRUE
  317. return TRUE;
  318. }
  319. //protected
  320. // cleanup
  321. void CGridData::Cleanup()
  322. {
  323. }
  324. // initialization
  325. void CGridData::Init()
  326. {
  327. // list of rows
  328. m_listGridColumn.clear();
  329. }
  330. // duplication
  331. void CGridData::Duplicate(const CGridData& a_oSource)
  332. {
  333. Init();
  334. // list of rows
  335. m_listGridColumn.clear();
  336. for (auto pGridColumn : a_oSource.m_listGridColumn)
  337. {
  338. CGridColumnPtr pGridColumnNew = CGridColumnPtr(new CGridColumn(*pGridColumn.get()));
  339. m_listGridColumn.push_back(pGridColumnNew);
  340. }
  341. // data source id
  342. for (auto strDataSource : a_oSource.m_listDataSource)
  343. {
  344. m_listDataSource.push_back(strDataSource);
  345. }
  346. m_nDataSourceId = a_oSource.m_nDataSourceId;
  347. }
  348. }