CSampleHolder.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Xml;
  7. namespace OTSDataType
  8. {
  9. public class CSampleHolder : ISlo
  10. {
  11. // stage name
  12. String m_strName;
  13. // boundary
  14. CDomain m_poBourary;
  15. // std
  16. CDomain m_poSTD;
  17. // sample holes list
  18. List<CHole> m_listHoles;
  19. // constructor
  20. public CSampleHolder()
  21. {
  22. // initialization
  23. Init();
  24. }
  25. // initialization
  26. public void Init()
  27. {
  28. // initialization
  29. m_strName = "";
  30. m_poBourary = new CDomain();
  31. m_poSTD = new CDomain();
  32. m_listHoles = new List<CHole>();
  33. }
  34. public CSampleHolder(CSampleHolder a_poSource)
  35. {
  36. // can't copy itself
  37. if (a_poSource == this)
  38. {
  39. return;
  40. }
  41. Duplicate(a_poSource);
  42. }
  43. public bool Equals(CSampleHolder a_oSource) // CBSEImg& operator=(const CBSEImg&); // =operator
  44. {
  45. // return FASLE, if the two holes list are in different size
  46. int nSize = m_listHoles.Count;
  47. if (nSize != a_oSource.m_listHoles.Count)
  48. {
  49. return false;
  50. }
  51. // return FALSE if any of the pare holes are different
  52. for (int i = 0; i < nSize; ++i)
  53. {
  54. if (m_listHoles[i] != a_oSource.m_listHoles[i])
  55. {
  56. return false;
  57. }
  58. }
  59. // members check
  60. return m_strName == a_oSource.m_strName &&
  61. m_poBourary == a_oSource.m_poBourary &&
  62. m_poSTD == a_oSource.m_poSTD;
  63. }
  64. // stage name
  65. public String GetName()
  66. {
  67. return m_strName;
  68. }
  69. //public int GetBourary() { return 0; }
  70. public void SetName(String a_strName)
  71. {
  72. m_strName = a_strName;
  73. }
  74. // boundary
  75. public CDomain GetBoundary()
  76. {
  77. return m_poBourary;
  78. }
  79. // boundary
  80. public void SetBoundary(CDomain a_poBourary)
  81. {
  82. m_poBourary = a_poBourary;
  83. }
  84. // std
  85. public CDomain GetSTD()
  86. {
  87. return m_poSTD;
  88. }
  89. // std
  90. public void SetSTD(CDomain a_poSTD)
  91. {
  92. m_poSTD = new CDomain(a_poSTD);
  93. }
  94. // sample holes list
  95. public List<CHole> GetHoleList()
  96. {
  97. return m_listHoles;
  98. }
  99. // holes list
  100. public void SetHoleList(List<CHole> a_listHoles, bool a_bClear /* = TRUE*/)
  101. {
  102. // clear holes list if necessary
  103. if (a_bClear)
  104. {
  105. m_listHoles.Clear();
  106. }
  107. // copy the list
  108. foreach (var pHole in a_listHoles)
  109. {
  110. CHole pHoleNew = new CHole(pHole);
  111. m_listHoles.Add(pHoleNew);
  112. }
  113. }
  114. // sample holes list
  115. public CHole GetHoleByIndex(int a_nIndex)
  116. {
  117. if (a_nIndex < 0 || a_nIndex >= (int)m_listHoles.Count)
  118. {
  119. // invalid index
  120. return null;
  121. }
  122. return m_listHoles[a_nIndex];
  123. }
  124. public CHole GetHoleByName(String a_strHoleName)
  125. {
  126. a_strHoleName.Trim();
  127. if (a_strHoleName == "")
  128. {
  129. // invalid hole name
  130. return null;
  131. }
  132. CHole p = new CHole();
  133. for (int i = 0; i < m_listHoles.Count; i++)
  134. {
  135. if (m_listHoles[i].GetName() == a_strHoleName)
  136. {
  137. p = m_listHoles[i];
  138. break;
  139. }
  140. }
  141. return p;
  142. }
  143. // duplication
  144. void Duplicate(CSampleHolder a_oSource)
  145. {
  146. Init();
  147. // copy data over
  148. m_strName = a_oSource.m_strName;
  149. m_poBourary = new CDomain(a_oSource.m_poBourary);
  150. m_poSTD = new CDomain(a_oSource.m_poSTD);
  151. foreach (var pHole in a_oSource.m_listHoles)
  152. {
  153. CHole pHoleNew = new CHole(pHole);
  154. m_listHoles.Add(pHoleNew);
  155. }
  156. }
  157. public override void Serialize(bool isStoring, XmlDocument classDoc, XmlNode rootNode)
  158. {
  159. xString xnstrName = new xString();
  160. Collection<CHole> xHolelist = new Collection<CHole>();
  161. CDomain x_poBourary = new CDomain();
  162. CDomain x_poSTD = new CDomain();
  163. Slo slo = new Slo();
  164. slo.Register("strName", xnstrName);
  165. slo.Register("boundary", x_poBourary);
  166. slo.Register("std", x_poSTD);
  167. slo.Register("Holes", xHolelist);
  168. if (isStoring)
  169. {
  170. xnstrName.AssignValue(m_strName);
  171. x_poBourary.SetPolygonPoint(m_poBourary.GetPolygonPoint());
  172. x_poBourary.SetRectDomain(m_poBourary.GetDomainRect());
  173. x_poBourary.SetShape(m_poBourary.GetShape());
  174. x_poSTD.SetPolygonPoint(m_poSTD.GetPolygonPoint());
  175. x_poSTD.SetRectDomain(m_poSTD.GetDomainRect());
  176. x_poSTD.SetShape(m_poSTD.GetShape());
  177. xHolelist.Clear();
  178. for (int i = 0; i < m_listHoles.Count; i++)
  179. {
  180. xHolelist.addItem(m_listHoles[i]);
  181. }
  182. slo.Serialize(true, classDoc, rootNode);
  183. }
  184. else
  185. {
  186. slo.Serialize(false, classDoc, rootNode);
  187. m_strName = xnstrName.value();
  188. m_poBourary = x_poBourary;
  189. m_poSTD = x_poSTD;
  190. m_listHoles.Clear();
  191. for (int i = 0; i < xHolelist.size(); i++)
  192. {
  193. m_listHoles.Add(xHolelist.getItem(i));
  194. }
  195. }
  196. }
  197. }
  198. }