123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Xml;
- using OTSCLRINTERFACE;
- namespace OTSDataType
- {
- public class CDomain : ISlo
- {
- //protected const int DOMAIN_ITEM_NUMBER = 5;
- protected otsdataconst.DOMAIN_SHAPE m_nShape;
- protected Rectangle m_rectangle;
- protected List<Point> m_PolygonPoint;
-
- public CDomain()
- {
- m_nShape = (otsdataconst.DOMAIN_SHAPE)(-1);
- m_rectangle = new Rectangle(0, 0, 0, 0);
- m_PolygonPoint = new List<Point>();
- }
- public CDomain(otsdataconst.DOMAIN_SHAPE a_nShape, RectangleF a_rectRegion)
- {
- m_nShape = a_nShape;
- m_rectangle =new Rectangle( (int)a_rectRegion.X,(int)a_rectRegion.Y,(int)a_rectRegion.Width,(int)a_rectRegion.Height);
- m_PolygonPoint = new List<Point>();
-
- }
- public CDomainClr GetClrDomainObj()
- {
- var myDomainClr = new CDomainClr((int)m_nShape, m_rectangle);
- myDomainClr.SetPolygonPoint(m_PolygonPoint);
- return myDomainClr;
- }
- public bool equals(CDomain a_source)
- {
- return m_nShape == a_source.m_nShape && m_rectangle == a_source.m_rectangle;
- }
- public CDomain(CDomain d)
- {
- Duplicate(d);
- }
- protected void Duplicate(CDomain a_oSource)
- {
- m_nShape = a_oSource.m_nShape;
- m_rectangle = new Rectangle(a_oSource.m_rectangle.Location, a_oSource.m_rectangle.Size);
- m_PolygonPoint = new List<Point>();
- foreach (var p in a_oSource.GetPolygonPoint())
- {
- m_PolygonPoint.Add(p);
- }
-
- }
- public bool IsInvalid()
- {
- return (m_nShape < otsdataconst.DOMAIN_SHAPE.ROUND) || m_nShape > otsdataconst.DOMAIN_SHAPE.RECTANGLE || m_rectangle.IsEmpty;
- }
- public void SetRectDomain(RectangleF val)
- {
- m_rectangle= new Rectangle(new Point((int)val.X,(int)val.Y),new Size((int)val.Width,(int)val.Height));
-
- }
- public RectangleF GetRectDomain() { return m_rectangle; }
- public bool IsEmpty() { return m_rectangle.IsEmpty; }
- public bool IsRound() { return m_nShape == otsdataconst.DOMAIN_SHAPE.ROUND; }
- public bool IsRect() { return m_nShape == otsdataconst.DOMAIN_SHAPE.RECTANGLE; }
- public PointF GetDomainCenter() { return new PointF(m_rectangle.X + m_rectangle.Width / 2, m_rectangle.Y + m_rectangle.Height / 2); }
- public void OffsetDomain(PointF a_poiMove) { m_rectangle.X += (int)a_poiMove.X; m_rectangle.Y += (int)a_poiMove.Y; }
- public float GetDiameter() { return m_rectangle.Width; }
- public RectangleF GetDomainRect() { return m_rectangle; }
- public void SetDomainRect(RectangleF a_rect) { m_rectangle = new Rectangle(new Point((int)a_rect.Location.X,(int)a_rect.Location.Y), new Size((int)a_rect.Size.Width,(int)a_rect.Size.Height)); }
- public otsdataconst.DOMAIN_SHAPE GetShape() { return m_nShape; }
- public void SetShape(otsdataconst.DOMAIN_SHAPE a_nShape) { m_nShape = a_nShape; }
- public void SetPolygonPoint(List<Point> a_PolygonPoint)
- {
- m_PolygonPoint = a_PolygonPoint;
-
- }
- public List<Point> GetPolygonPoint() { return m_PolygonPoint; }
- public bool IntersectDomain(CDomain a_oDomain)
- {
- CDomainClr dom = GetClrDomainObj();
- var dom1 = a_oDomain.GetClrDomainObj();
- bool ifWithIn = dom.IntersectDomain(dom1);
- dom.MyDispose();
- dom1.MyDispose();
- return ifWithIn;
- }
- public bool PtInDomain( Point a_poiCheck)
- {
- var dom = GetClrDomainObj();
- dom.PtInDomain(a_poiCheck);
- dom.MyDispose();
- return true;
- }
- public bool DomainInDomain( CDomain a_oDomain)
- {
- var dom = GetClrDomainObj();
- var dom1 = a_oDomain.GetClrDomainObj();
- bool ifWithIn = dom.DomainInDomain(dom1);
- dom.MyDispose();
- dom1.MyDispose();
- return ifWithIn;
- }
- protected void Init()
- {
- m_nShape = (otsdataconst.DOMAIN_SHAPE)(-1);
- m_rectangle = new Rectangle(0, 0, 0, 0);
- m_PolygonPoint = new List<Point>();
- }
- public override void Serialize(bool isStoring, XmlDocument classDoc, XmlNode rootNode)
- {
- Slo slo = new Slo();
- xString xnShape = new xString();
- xRect xRecDomain = new xRect();
- xString xPolygonPoint = new xString();
- slo.Register("shape", xnShape);
- slo.Register("rectDomian", xRecDomain);
- slo.Register("PolygonPoint", xPolygonPoint);
- if (isStoring)
- {
- xnShape.AssignValue((int)m_nShape+":"+ m_nShape.ToString());
- //we have to save the rectangle parameter according to the previouse rule.(left,top,width,height or centerX centerY,diamiter,0)
- System.Drawing.RectangleF rect = new System.Drawing.RectangleF();
- rect.X = m_rectangle.X;
- rect.Y = m_rectangle.Y;
- rect.Width = m_rectangle.Width;
- rect.Height = m_rectangle.Height;
- xRecDomain.AssignValue(rect, (int)m_nShape);
- if (m_PolygonPoint != null)
- {
- string pointStr;
- pointStr = string.Join("_", m_PolygonPoint);
- xPolygonPoint.AssignValue(pointStr);
- }
- slo.Serialize(true, classDoc, rootNode);
- }
- else
- {
- slo.Serialize(false, classDoc, rootNode);
- m_nShape = (otsdataconst.DOMAIN_SHAPE)Convert.ToInt32( xnShape.value().Split(':')[0]);
- List<string> rectDomain = xRecDomain.toString().Split(',').ToList();
- m_rectangle = new Rectangle(Convert.ToInt32(rectDomain[0]), Convert.ToInt32(rectDomain[1]), 0, 0);
- //do the regulation
- float nCentreX = m_rectangle.Left;
- float nCentreY = m_rectangle.Top;
- int nWidth;
- int nHeight;
- int nDiameter;
- if (m_nShape == otsdataconst.DOMAIN_SHAPE.ROUND)
- {
- nDiameter = Convert.ToInt32(rectDomain[2]);
- // create domain
- m_rectangle = new Rectangle(0, 0, nDiameter, nDiameter);
- OffsetDomain(new PointF(nCentreX - (nDiameter / 2), nCentreY - (nDiameter / 2)));
- }
- else if (m_nShape == otsdataconst.DOMAIN_SHAPE.RECTANGLE)
- {
- nWidth = Convert.ToInt32(rectDomain[2]);
- nHeight = Convert.ToInt32(rectDomain[3]);
- m_rectangle = new Rectangle(0, 0, nWidth, nHeight);
- OffsetDomain(new PointF(nCentreX - (nWidth / 2), nCentreY - (nHeight / 2)));
- }
- else
- {
- int left = Convert.ToInt32(rectDomain[0]);
- int top = Convert.ToInt32(rectDomain[1]);
- int right = Convert.ToInt32(rectDomain[2]);
- int bottom = Convert.ToInt32(rectDomain[3]);
- nWidth = right - left;
- nHeight = bottom - top;
- m_rectangle = new Rectangle(0, 0, nWidth, nHeight);
- OffsetDomain(new PointF(nCentreX - (nWidth / 2), nCentreY - (nHeight / 2)));
-
- }
- if (m_PolygonPoint == null)
- {
- m_PolygonPoint = new List<Point>();
- }
- //myDomainClr = new CDomainClr((int)m_nShape, m_rectangle);
- if (xPolygonPoint != null)
- {
- if(xPolygonPoint.value() != null)
- {
- List<string> pointList = xPolygonPoint.toString().Split('_').ToList();
- if (pointList.Count > 2)
- {
- foreach (var item in pointList)
- {
- // 先去掉大括号
- string str = item.Replace("{", "").Replace("}", "");
- int x = Convert.ToInt32(str.Split(',')[0].Split('=')[1]);
- int y = Convert.ToInt32(str.Split(',')[1].Split('=')[1]);
- Point point = new Point(x, y);
- m_PolygonPoint.Add(point);
- }
- }
- }
- }
- }
-
- }
- }
- }
|