Browse Source

添加StageDisplayHelp.cs

CXS 3 years ago
parent
commit
44bc0d1a04
1 changed files with 305 additions and 0 deletions
  1. 305 0
      OTSIncAMeasureApp/7-OTSProgMgrInfo/Stage/StageDisplayHelp.cs

+ 305 - 0
OTSIncAMeasureApp/7-OTSProgMgrInfo/Stage/StageDisplayHelp.cs

@@ -0,0 +1,305 @@
+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;
+
+            //标尺
+
+            //Pen pen = new Pen(Color.Black, 10f);
+            //((Graphics)pDC).DrawLine(pen,new Point(oRatioStart.X + 5, oRatioStart.Y + 5),new Point(oRatioStart.X + 5, oRatioEnd.Y - 15));
+            //((Graphics)pDC).DrawLine(pen, new Point(oRatioStart.X + 5, oRatioStart.Y + 10),new Point(oRatioEnd.X - 5, oRatioStart.Y + 10));
+            //((Graphics)pDC).DrawLine(pen, new Point(oRatioEnd.X - 5, oRatioStart.Y + 5),new Point(oRatioEnd.X - 5, oRatioEnd.Y - 15));
+
+
+            //pDC->MoveTo(CPoint(oRatioStart.x + 5, oRatioStart.y + 5));
+            //pDC->LineTo(CPoint(oRatioStart.x + 5, oRatioEnd.y - 15));
+            //pDC->MoveTo(CPoint(oRatioStart.x + 5, oRatioStart.y + 10));
+            //pDC->LineTo(CPoint(oRatioEnd.x - 5, oRatioStart.y + 10));
+            //pDC->MoveTo(CPoint(oRatioEnd.x - 5, oRatioStart.y + 5));
+            //pDC->LineTo(CPoint(oRatioEnd.x - 5, oRatioEnd.y - 15));
+
+            //CFont font;
+            //VERIFY(font.CreateFont(
+            //    12,                        // nHeight
+            //    0,                         // nWidth
+            //    0,                         // nEscapement
+            //    0,                         // nOrientation
+            //    FW_THIN,                 // nWeight
+            //    FALSE,                     // bItalic
+            //    FALSE,                     // bUnderline
+            //    0,                         // cStrikeOut
+            //    ANSI_CHARSET,              // nCharSet
+            //    OUT_DEFAULT_PRECIS,        // nOutPrecision
+            //    CLIP_DEFAULT_PRECIS,       // nClipPrecision
+            //    DEFAULT_QUALITY,           // nQuality
+            //    DEFAULT_PITCH | FF_SWISS,  // nPitchAndFamily
+            //    _T("Arial")));                 // lpszFacename
+
+
+            //CFont* def_font = pDC->SelectObject(&font);
+            //pDC->TextOut(oRatioStart.x + 70, oRatioStart.y + 15, sRatio);
+            //pDC->SelectObject(def_font);
+
+            //// Done with the font.  Delete the font object.
+            //font.DeleteObject();
+
+            //CRect oRect(oRatioStart, oRatioEnd);
+
+            //HDC hDC;
+            //hDC = ::GetDC(pWnd->m_hWnd);
+            //HDC hBitmapDC = CreateCompatibleDC(hDC);
+            //HBITMAP hBitmap = CreateCompatibleBitmap(hDC, rc.Width(), rc.Height());
+            //SelectObject(hBitmapDC, hBitmap);
+
+            //BLENDFUNCTION bf;
+            //bf.BlendOp = AC_SRC_OVER;
+            //bf.BlendFlags = 0;
+            //bf.AlphaFormat = 0;
+            //bf.SourceConstantAlpha = 10;
+            //AlphaBlend(hDC, oRect.left, oRect.top, oRect.Width(), oRect.Height(), hBitmapDC, 0, 0, oRect.Width(), oRect.Height(), bf);
+        }
+
+        // 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;
+            }
+
+            Rectangle DomainRect = a_pDomain.GetDomainRect();
+
+            int CenterX = a_nWidth / 2;     //pixle center
+            int CenterY = a_nHeight / 2;
+
+            Point 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;
+        }
+
+
+    }
+}