CHole.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using OTSCLRINTERFACE;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Xml;
  9. namespace OTSDataType
  10. {
  11. public class CHole : CDomain
  12. {
  13. private string m_strName;
  14. public CHole()
  15. {
  16. Init();
  17. // initialization
  18. m_strName = "";
  19. }
  20. public void Duplicate(CHole a_oSource)
  21. {
  22. // initialization
  23. base.Init();
  24. // base class duplication
  25. base.Duplicate(a_oSource);
  26. // copy data over
  27. m_strName = a_oSource.m_strName;
  28. }
  29. public CHole(string a_strName, otsdataconst.DOMAIN_SHAPE a_nShape, Rectangle a_rectDomain)
  30. {
  31. // initialization
  32. Init();
  33. // assign class members
  34. m_strName = a_strName;
  35. m_nShape = a_nShape;
  36. m_rectangle = a_rectDomain;
  37. }
  38. public CHole(string a_strName, CDomain cDomain)
  39. {
  40. // initialization
  41. Init();
  42. // assign class members
  43. m_strName = a_strName;
  44. m_nShape = cDomain.GetShape();
  45. m_rectangle = cDomain.GetRectDomain();
  46. //myDomainClr = new CDomainClr((int)cDomain.GetShape(), cDomain.GetRectDomain());
  47. }
  48. public string GetName() { return m_strName; }
  49. // copy constructor
  50. public CHole(CHole a_oSource)
  51. {
  52. // copy data over
  53. Duplicate(a_oSource);
  54. }
  55. // public Rectangle GetRectDomain() { return null; }
  56. public bool equals(CHole a_oSource)
  57. {
  58. return m_strName == a_oSource.m_strName && m_nShape == a_oSource.m_nShape && m_rectangle == a_oSource.m_rectangle;
  59. }
  60. public override void Serialize(bool isStoring, XmlDocument classDoc, XmlNode rootNode)
  61. {
  62. Slo slo = new Slo();
  63. xInt xnShape = new xInt();
  64. xRect xRecDomain = new xRect();
  65. xString xnstrName = new xString();
  66. slo.Register("HoleName", xnstrName);
  67. slo.Register("shape", xnShape);
  68. slo.Register("rectDomian", xRecDomain);
  69. if (isStoring)
  70. {
  71. xnstrName.AssignValue(m_strName);
  72. xnShape.AssignValue((int)m_nShape);
  73. //we have to save the rectangle parameter according to the previouse rule.(left,top,width,height or centerX centerY,diamiter,0)
  74. System.Drawing.Rectangle rect = new System.Drawing.Rectangle();
  75. rect.X = m_rectangle.X;
  76. rect.Y = m_rectangle.Y;
  77. rect.Width = m_rectangle.Width;
  78. rect.Height = m_rectangle.Height;
  79. xRecDomain.AssignValue(rect, (int)m_nShape);
  80. slo.Serialize(true, classDoc, rootNode);
  81. }
  82. else
  83. {
  84. slo.Serialize(false, classDoc, rootNode);
  85. m_strName = xnstrName.value();
  86. m_nShape = (otsdataconst.DOMAIN_SHAPE)xnShape.value();
  87. List<string> rectDomain = xRecDomain.toString().Split(',').ToList();
  88. m_rectangle = new Rectangle(Convert.ToInt32(rectDomain[0]), Convert.ToInt32(rectDomain[1]), 0, 0);
  89. //do the regulation
  90. int nCentreX = m_rectangle.Left;
  91. int nCentreY = m_rectangle.Top;
  92. int nWidth;
  93. int nHeight;
  94. int nDiameter;
  95. if (m_nShape == otsdataconst.DOMAIN_SHAPE.ROUND)
  96. {
  97. nDiameter = Convert.ToInt32(rectDomain[2]);
  98. // create domain
  99. m_rectangle = new Rectangle(0, 0, nDiameter, nDiameter);
  100. OffsetDomain(new Point(nCentreX - (nDiameter / 2), nCentreY - (nDiameter / 2)));
  101. }
  102. else if (m_nShape == otsdataconst.DOMAIN_SHAPE.RECTANGLE)
  103. {
  104. nWidth = m_rectangle.Right;
  105. nHeight = m_rectangle.Bottom;
  106. m_rectangle = new Rectangle(0, 0, nWidth, nHeight);
  107. OffsetDomain(new Point(nCentreX - (nWidth / 2), nCentreY - (nHeight / 2)));
  108. }
  109. }
  110. }
  111. }
  112. }