using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml; namespace OTSDataType { public class CSampleHolder : ISlo { // stage name String m_strName; // boundary CDomain m_poBourary; // std CDomain m_poSTD; // sample holes list List m_listHoles; // constructor public CSampleHolder() { // initialization Init(); } // initialization public void Init() { // initialization m_strName = ""; m_poBourary = new CDomain(); m_poSTD = new CDomain(); m_listHoles = new List(); } public CSampleHolder(CSampleHolder a_poSource) { // can't copy itself if (a_poSource == this) { return; } Duplicate(a_poSource); } public bool Equals(CSampleHolder a_oSource) // CBSEImg& operator=(const CBSEImg&); // =operator { // return FASLE, if the two holes list are in different size int nSize = m_listHoles.Count; if (nSize != a_oSource.m_listHoles.Count) { return false; } // return FALSE if any of the pare holes are different for (int i = 0; i < nSize; ++i) { if (m_listHoles[i] != a_oSource.m_listHoles[i]) { return false; } } // members check return m_strName == a_oSource.m_strName && m_poBourary == a_oSource.m_poBourary && m_poSTD == a_oSource.m_poSTD; } // stage name public String GetName() { return m_strName; } //public int GetBourary() { return 0; } public void SetName(String a_strName) { m_strName = a_strName; } // boundary public CDomain GetBoundary() { return m_poBourary; } // boundary public void SetBoundary(CDomain a_poBourary) { m_poBourary = a_poBourary; } // std public CDomain GetSTD() { return m_poSTD; } // std public void SetSTD(CDomain a_poSTD) { m_poSTD = new CDomain(a_poSTD); } // sample holes list public List GetHoleList() { return m_listHoles; } // holes list public void SetHoleList(List a_listHoles, bool a_bClear /* = TRUE*/) { // clear holes list if necessary if (a_bClear) { m_listHoles.Clear(); } // copy the list foreach (var pHole in a_listHoles) { CHole pHoleNew = new CHole(pHole); m_listHoles.Add(pHoleNew); } } // sample holes list public CHole GetHoleByIndex(int a_nIndex) { if (a_nIndex < 0 || a_nIndex >= (int)m_listHoles.Count) { // invalid index return null; } return m_listHoles[a_nIndex]; } public CHole GetHoleByName(String a_strHoleName) { a_strHoleName.Trim(); if (a_strHoleName == "") { // invalid hole name return null; } CHole p = new CHole(); for (int i = 0; i < m_listHoles.Count; i++) { if (m_listHoles[i].GetName() == a_strHoleName) { p = m_listHoles[i]; break; } } return p; } // duplication void Duplicate(CSampleHolder a_oSource) { Init(); // copy data over m_strName = a_oSource.m_strName; m_poBourary = new CDomain(a_oSource.m_poBourary); m_poSTD = new CDomain(a_oSource.m_poSTD); foreach (var pHole in a_oSource.m_listHoles) { CHole pHoleNew = new CHole(pHole); m_listHoles.Add(pHoleNew); } } public override void Serialize(bool isStoring, XmlDocument classDoc, XmlNode rootNode) { xString xnstrName = new xString(); Collection xHolelist = new Collection(); CDomain x_poBourary = new CDomain(); CDomain x_poSTD = new CDomain(); Slo slo = new Slo(); slo.Register("strName", xnstrName); slo.Register("boundary", x_poBourary); slo.Register("std", x_poSTD); slo.Register("Holes", xHolelist); if (isStoring) { xnstrName.AssignValue(m_strName); x_poBourary.SetPolygonPoint(m_poBourary.GetPolygonPoint()); x_poBourary.SetRectDomain(m_poBourary.GetDomainRect()); x_poBourary.SetShape(m_poBourary.GetShape()); x_poSTD.SetPolygonPoint(m_poSTD.GetPolygonPoint()); x_poSTD.SetRectDomain(m_poSTD.GetDomainRect()); x_poSTD.SetShape(m_poSTD.GetShape()); xHolelist.Clear(); for (int i = 0; i < m_listHoles.Count; i++) { xHolelist.addItem(m_listHoles[i]); } slo.Serialize(true, classDoc, rootNode); } else { slo.Serialize(false, classDoc, rootNode); m_strName = xnstrName.value(); m_poBourary = x_poBourary; m_poSTD = x_poSTD; m_listHoles.Clear(); for (int i = 0; i < xHolelist.size(); i++) { m_listHoles.Add(xHolelist.getItem(i)); } } } } }