CHole.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. var r = cDomain.GetRectDomain();
  46. m_rectangle = new Rectangle(new Point((int)r.X,(int)r.Y),new Size((int)r.Width,(int)r.Height));
  47. //myDomainClr = new CDomainClr((int)cDomain.GetShape(), cDomain.GetRectDomain());
  48. }
  49. public string GetName() { return m_strName; }
  50. // copy constructor
  51. public CHole(CHole a_oSource)
  52. {
  53. // copy data over
  54. Duplicate(a_oSource);
  55. }
  56. // public Rectangle GetRectDomain() { return null; }
  57. public bool equals(CHole a_oSource)
  58. {
  59. return m_strName == a_oSource.m_strName && m_nShape == a_oSource.m_nShape && m_rectangle == a_oSource.m_rectangle;
  60. }
  61. public override void Serialize(bool isStoring, XmlDocument classDoc, XmlNode rootNode)
  62. {
  63. Slo slo = new Slo();
  64. xInt xnShape = new xInt();
  65. xRect xRecDomain = new xRect();
  66. xString xnstrName = new xString();
  67. slo.Register("HoleName", xnstrName);
  68. slo.Register("shape", xnShape);
  69. slo.Register("rectDomian", xRecDomain);
  70. if (isStoring)
  71. {
  72. xnstrName.AssignValue(m_strName);
  73. xnShape.AssignValue((int)m_nShape);
  74. //we have to save the rectangle parameter according to the previouse rule.(left,top,width,height or centerX centerY,diamiter,0)
  75. System.Drawing.RectangleF rect = new System.Drawing.Rectangle();
  76. rect.X = m_rectangle.X;
  77. rect.Y = m_rectangle.Y;
  78. rect.Width = m_rectangle.Width;
  79. rect.Height = m_rectangle.Height;
  80. xRecDomain.AssignValue(rect, (int)m_nShape);
  81. slo.Serialize(true, classDoc, rootNode);
  82. }
  83. else
  84. {
  85. slo.Serialize(false, classDoc, rootNode);
  86. m_strName = xnstrName.value();
  87. m_nShape = (otsdataconst.DOMAIN_SHAPE)xnShape.value();
  88. List<string> rectDomain = xRecDomain.toString().Split(',').ToList();
  89. m_rectangle = new Rectangle(Convert.ToInt32(rectDomain[0]), Convert.ToInt32(rectDomain[1]), 0, 0);
  90. //do the regulation
  91. float nCentreX = m_rectangle.Left;
  92. float nCentreY = m_rectangle.Top;
  93. float nWidth;
  94. float nHeight;
  95. int nDiameter;
  96. if (m_nShape == otsdataconst.DOMAIN_SHAPE.ROUND)
  97. {
  98. nDiameter = Convert.ToInt32(rectDomain[2]);
  99. // create domain
  100. m_rectangle = new Rectangle(0, 0, nDiameter, nDiameter);
  101. OffsetDomain(new PointF(nCentreX - (nDiameter / 2), nCentreY - (nDiameter / 2)));
  102. }
  103. else if (m_nShape == otsdataconst.DOMAIN_SHAPE.RECTANGLE)
  104. {
  105. nWidth = m_rectangle.Right;
  106. nHeight = m_rectangle.Bottom;
  107. m_rectangle = new Rectangle(0, 0, (int)nWidth, (int)nHeight);
  108. OffsetDomain(new PointF(nCentreX - (nWidth / 2), nCentreY - (nHeight / 2)));
  109. }
  110. }
  111. }
  112. }
  113. }