123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333 |
- using OTSDataType;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using static OTSDataType.otsdataconst;
- namespace OTSMeasureApp._7_OTSProgMgrInfo.Stage
- {
- class StageDisplayHelp
- {
- public const int RATIO_RECT_LEFT = 22; //ratio rect left edge
- public const int PIC_EDGE = 12; //edge width
- public const int RATIO_RECT_HEIGHT = 30; //ratio rect height
- public const int RATIO_RECT_DOWN = 10; //ratio rect down edge
- public const int DOMAIN_ITEM_NUMBER = 5;
- public StageDisplayHelp()
- {
- }
- public void DrawStageBoundery(CStage a_pStage, int a_nWidth, int a_nHeight, Object pDC, double a_dPixSize)
- {
- if (a_pStage == null)
- {
- return;
- }
- CDomain pBoundery = a_pStage.GetBoundary();
- otsdataconst.DOMAIN_SHAPE nShape = (otsdataconst.DOMAIN_SHAPE)(-1);
- nShape = pBoundery.GetShape();
- Rectangle PixRect = new Rectangle();
- GetPixRect(pBoundery, a_nWidth, a_nHeight, a_dPixSize, ref PixRect);
- DrawShape(PixRect, pDC, nShape, true);
- }
- // draw stage hole
- public void DrawStageHole(CStage a_pStage, int a_nWidth, int a_nHeight, Object pDC, double a_dPixSize)
- {
- if (a_pStage == null)
- {
- return;
- }
- if (a_pStage.GetHoleList().Count == 0)
- {
- return;
- }
- foreach (var pHole in a_pStage.GetHoleList())
- {
- otsdataconst.DOMAIN_SHAPE nShape = (otsdataconst.DOMAIN_SHAPE)(-1);
- nShape = pHole.GetShape();
- Rectangle PixRect = new Rectangle();
- GetPixRect(pHole, a_nWidth, a_nHeight, a_dPixSize, ref PixRect);
- DrawShape(PixRect, pDC, nShape, true);
- int nHeight = PixRect.Height * 2 / 3;
- //设置文字对齐方式
- StringFormat sf = new StringFormat();
- sf.Alignment = StringAlignment.Center;
- sf.LineAlignment = StringAlignment.Center;
- //文字颜色
- string ColorStr = "#90ee90";
- Color myColor = ColorTranslator.FromHtml(ColorStr);
- System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
- SolidBrush solidBrush = new SolidBrush(Color.FromArgb(50, Color.Black));
- //字体大小 根据样品孔Rectangle大小
- float fontSize = PixRect.Width / 4;
- Font font = new Font("宋体", fontSize, FontStyle.Regular);
- if (fontSize == 0)
- {
- font = new Font("宋体", fontSize, FontStyle.Regular);
- }
- //绘制文字阴影
- Rectangle rectFont = PixRect;
- rectFont.X += 2;
- rectFont.Y += 2;
- ((Graphics)pDC).DrawString(pHole.GetName(), font, solidBrush, rectFont, sf);
- ((Graphics)pDC).DrawString(pHole.GetName(), font, sampleBrush, PixRect, sf);
- }
- }
- // draw ratio
- public void DrawRatio(int a_nBounderyWidth, int a_nWidth, int a_nHeight, Object pDC, IntPtr pWnd, Rectangle rc)
- {
- if (pDC == null)
- {
- return;
- }
- if (pWnd == null)
- {
- return;
- }
- int nRatio = a_nBounderyWidth * (a_nWidth / 2 - RATIO_RECT_LEFT - 10) / (a_nWidth - PIC_EDGE * 2) / 1000; //显示在标尺上的mm数
- //string sRatio;
- Point oRatioStart = new Point();
- oRatioStart.X = RATIO_RECT_LEFT;
- oRatioStart.Y = a_nHeight - RATIO_RECT_HEIGHT - RATIO_RECT_DOWN;
- Point oRatioEnd = new Point();
- oRatioEnd.X = a_nWidth / 2;
- oRatioEnd.Y = a_nHeight - RATIO_RECT_DOWN;
-
- }
- // get pixle rect
- public bool GetPixRect(CDomain a_pDomain, int a_nWidth, int a_nHeight, double a_dPixSize, ref Rectangle PixRect)
- {
- if (a_pDomain == null)
- {
- return false;
- }
- RectangleF DomainRect = a_pDomain.GetDomainRect();
- int CenterX = a_nWidth / 2; //pixle center
- int CenterY = a_nHeight / 2;
- PointF DomainCenter = a_pDomain.GetDomainCenter(); // um center
- Point PixCenter = new Point();
- PixCenter.X = (int)((double)DomainCenter.X / a_dPixSize);
- PixCenter.Y = (int)((double)DomainCenter.Y / a_dPixSize); // um to pixle
- int PixRectCenterX = CenterX + PixCenter.X;
- int PixRectCenterY = CenterY - PixCenter.Y;//OTS y dirction is different with pixle direction
- int delteX = PixRectCenterX - PixCenter.X;
- int delteY = PixRectCenterY - PixCenter.Y;
- int Left = (int)(DomainRect.Left / a_dPixSize + delteX);
- int Top = (int)(DomainRect.Top / a_dPixSize + delteY);
- int Right = (int)(DomainRect.Right / a_dPixSize + delteX);
- int Bottom = (int)(DomainRect.Bottom / a_dPixSize + delteY);
- PixRect.Location = new Point(Left, Top);
- PixRect.Size = new Size(Math.Abs(Right - Left), Math.Abs(Bottom - Top));
- return true;
- }
- // draw shape
- public void DrawShape(Rectangle a_PixRect, Object a_pDC, otsdataconst.DOMAIN_SHAPE a_nShape, bool a_bIsRand)
- {
- if (a_pDC == null)
- {
- return;
- }
- Graphics graphicsShape = (Graphics)a_pDC;
- switch ((int)a_nShape)
- {
- case (int)otsdataconst.DOMAIN_SHAPE.ROUND:
- graphicsShape.DrawEllipse(new Pen(Color.Black), a_PixRect);
- break;
- case (int)otsdataconst.DOMAIN_SHAPE.RECTANGLE:
- if (a_bIsRand)
- {
- //graphicsShape.DrawRectangle(new Pen(Color.Black), a_PixRect, new Point(ROUND_VALUE, ROUND_VALUE));
- graphicsShape.DrawRectangle(new Pen(Color.Black), a_PixRect);
- }
- else
- {
- graphicsShape.DrawEllipse(new Pen(Color.Black), a_PixRect);
- }
- break;
- }
- }
- // get domain
- public CDomain GetDomain(String a_strValue)
- {
- // domain
- CDomain pDomain = null;
- // check value string
- a_strValue.Trim();
- if (a_strValue == "")
- {
- return pDomain;
- }
- // split the value string
- List<string> listStr = new List<string>(a_strValue.Split(','));
- pDomain = GetDomain(listStr);
- // return the domain pointer
- return pDomain;
- }
- CDomain GetDomain(List<string> a_listString)
- {
- // domain
- CDomain pDomain = null;
- // check value string list size
- if ((int)a_listString.Count != DOMAIN_ITEM_NUMBER)
- {
- return pDomain;
- }
- // shape
- int nValue;
- string strValue = a_listString[0];
- nValue = Convert.ToInt32(strValue);
- // check the shape value
- if (nValue < (int)DOMAIN_SHAPE.ROUND || nValue > (int)DOMAIN_SHAPE.RECTANGLE)
- {
- return pDomain;
- }
- DOMAIN_SHAPE nShape = (DOMAIN_SHAPE)nValue;
- // position
- strValue = a_listString[1];
- nValue = Convert.ToInt32(strValue);
- int nCentreX = nValue;
- strValue = a_listString[2];
- nValue = Convert.ToInt32(strValue);
- int nCentreY = nValue;
- // diameter/width
- strValue = a_listString[3];
- nValue = Convert.ToInt32(strValue);
- int nDiameter_Width = nValue;
- // height/spare
- strValue = a_listString[4];
- if (nShape == DOMAIN_SHAPE.RECTANGLE)
- {
- nValue = Convert.ToInt32(strValue);
- }
- int nDiameter_nHeight = nValue;
- // create domain
- Rectangle rectDomain = new Rectangle(0, 0, nDiameter_Width, nDiameter_nHeight);
- pDomain = new CDomain(nShape, rectDomain);
- pDomain.OffsetDomain(new Point(nCentreX - (nDiameter_Width / 2), nCentreY - (nDiameter_nHeight / 2)));
- // return the domain pointer
- return pDomain;
- }
- #region 画出X轴与Y轴
- /// <summary>
- /// 在任意的panel里画一个坐标,坐标所在的四边形距离panel边50像素
- /// </summary>
- /// <param name="pan"></param>
- public void DrawXY(Object a_pDC, double width,double height, double a_dPixSize,double coordinateSystemEndpointX, double coordinateSystemEndpointY)
- {
- if (a_pDC == null)
- {
- return;
- }
- Graphics g = (Graphics)a_pDC;
- //绘制X轴,
- double ObjectCenterX = width/ 2;
- double ObjectCenterY = height / 2;
- int X0 = (int)(coordinateSystemEndpointX / a_dPixSize + ObjectCenterX);
- int Y0 = (int)(0 / a_dPixSize + ObjectCenterY);
- int X1 = (int)(-coordinateSystemEndpointX / a_dPixSize + ObjectCenterX);
- int Y1 = (int)(0 / a_dPixSize + ObjectCenterY);
- Point px1 = new Point(X0, Y0);
- Point px2 = new Point(X1, Y1);
- Pen pen = new Pen(Brushes.Green, 1);
- g.DrawLine(pen, px1, px2);
- //绘制Y轴
- int X3 = (int)(0 / a_dPixSize + ObjectCenterX);
- int Y3 = (int)(coordinateSystemEndpointY / a_dPixSize + ObjectCenterY);
- int X4 = (int)(0 / a_dPixSize + ObjectCenterX);
- int Y4 = (int)(-coordinateSystemEndpointY / a_dPixSize + ObjectCenterY);
- PointF py1 = new PointF(X3, Y3);
- PointF py2 = new PointF(X4, Y4);
- g.DrawLine(pen, py1, py2);
- g.DrawString("0", new Font("宋体 ", 9f), Brushes.Green, new PointF((float)ObjectCenterX - 12, (float)ObjectCenterY + 3));
- int move = 5,len=10;
- for (int i = 1; i <= len; i++) //len等分Y正轴
- {
- Point px3 = new Point((int)ObjectCenterX + move, (int)(ObjectCenterY + (-coordinateSystemEndpointY / a_dPixSize) / len * i));
- Point px4 = new Point((int)ObjectCenterX, (int)(ObjectCenterY + (-coordinateSystemEndpointY / a_dPixSize) / len * i));
- string sx = ((int)(-(-coordinateSystemEndpointY) / len * i)).ToString();
- g.DrawLine(pen, px3, px4);
- StringFormat drawFormat = new StringFormat();
- drawFormat.Alignment = StringAlignment.Far;
- drawFormat.LineAlignment = StringAlignment.Center;
- g.DrawString(sx, new Font("宋体", 8f), Brushes.Green, new Point((int)ObjectCenterX - 5, (int)(ObjectCenterY + (-coordinateSystemEndpointY / a_dPixSize) / len * i)), drawFormat);
- }
- for (int i = 1; i <= len; i++)
- {
- Point px3 = new Point((int)ObjectCenterX + move, (int)(ObjectCenterY + (coordinateSystemEndpointY / a_dPixSize) / len * i));
- Point px4 = new Point((int)ObjectCenterX, (int)(ObjectCenterY + (coordinateSystemEndpointY / a_dPixSize) / len * i));
- string sx = ((int)((-coordinateSystemEndpointY) / len * i)).ToString();
- g.DrawLine(pen, px3, px4);
- StringFormat drawFormat = new StringFormat();
- drawFormat.Alignment = StringAlignment.Far;
- drawFormat.LineAlignment = StringAlignment.Center;
- g.DrawString(sx, new Font("宋体", 8f), Brushes.Green, new Point((int)ObjectCenterX - 5, (int)(ObjectCenterY + (coordinateSystemEndpointY / a_dPixSize) / len * i)), drawFormat);
- }
- for (int i = 1; i <= len; i++) //len等分X正轴
- {
- Point px3 = new Point((int)(ObjectCenterX + (coordinateSystemEndpointX / a_dPixSize) / len * i) , (int)(ObjectCenterY + move));
- Point px4 = new Point((int)(ObjectCenterX + (coordinateSystemEndpointX / a_dPixSize) / len * i), (int)ObjectCenterY);
- string sx = ((int)(coordinateSystemEndpointX / len * i)).ToString();
- g.DrawLine(pen, px3, px4);
- StringFormat drawFormat = new StringFormat();
- drawFormat.Alignment = StringAlignment.Far;
- drawFormat.LineAlignment = StringAlignment.Center;
- g.DrawString(sx, new Font("宋体", 6f), Brushes.Green, new Point((int)(ObjectCenterX + (coordinateSystemEndpointX / a_dPixSize) / len * i)+5, (int)(ObjectCenterY + 15)), drawFormat);
- }
- for (int i = 1; i <= len; i++)
- {
- Point px3 = new Point((int)(ObjectCenterX + (-coordinateSystemEndpointX / a_dPixSize) / len * i), (int)(ObjectCenterY + move));
- Point px4 = new Point((int)(ObjectCenterX + (-coordinateSystemEndpointX / a_dPixSize) / len * i), (int)(ObjectCenterY));
- string sx = ((int)((-coordinateSystemEndpointX) / len * i)).ToString();
- g.DrawLine(pen, px3, px4);
- StringFormat drawFormat = new StringFormat();
- drawFormat.Alignment = StringAlignment.Far;
- drawFormat.LineAlignment = StringAlignment.Center;
- g.DrawString(sx, new Font("宋体", 6f), Brushes.Green, new Point((int)(ObjectCenterX + (-coordinateSystemEndpointX / a_dPixSize) / len * i)+5, (int)(ObjectCenterY + 15)), drawFormat);
- }
- //g.Dispose();
- }
- #endregion
- }
- }
|