public override void DrawToPicBox(MPicBox picBox)
 {
     if (Config.CanDrawToPicBox)
     {
         if (config.IsNormalShape)
         {
             picBox.points.Add(new PointAttribute(new Pen(Color.OrangeRed), P_Intersection));
         }
         else
         {
             P_Intersection    = ToolGroupEdit.GetRotatePoint(new PointF(), P_Intersection, Shape.Angle);
             P_Intersection.X += Shape.CenterX;
             P_Intersection.Y += Shape.CenterY;
             picBox.points.Add(new PointAttribute(new Pen(Color.OrangeRed), P_Intersection));
         }
     }
 }
Esempio n. 2
0
        public override void DrawToPicBox(MPicBox picBox)
        {
            if (Config.CanDrawToPicBox)
            {
                PointF p1 = new PointF(config.P_CenterX, config.P_CenterY);
                p1.X += Shape.CenterX;
                p1.Y += Shape.CenterY;
                p1    = ToolGroupEdit.GetRotatePoint(new PointF(Shape.CenterX, Shape.CenterY), p1, Shape.Angle);
                PointF p2 = P_Intersection;
                p2.X += Shape.CenterX;
                p2.Y += Shape.CenterY;
                p2    = ToolGroupEdit.GetRotatePoint(new PointF(Shape.CenterX, Shape.CenterY), p2, Shape.Angle);
                picBox.lines.Add(new LineAttribute(new Pen(Color.OrangeRed), p1, p2));
                PointF p3 = new PointF((config.P_CenterX + P_Intersection.X) / 2,
                                       (config.P_CenterY + P_Intersection.Y) / 2);
                p3.X += Shape.CenterX;
                p3.Y += Shape.CenterY;
                p3    = ToolGroupEdit.GetRotatePoint(new PointF(Shape.CenterX, Shape.CenterY), p3, Shape.Angle);

                picBox.strs.Add(new StrAttribute(Distance.ToString(), Color.OrangeRed, new Point((int)p3.X, (int)p3.Y)));
            }
        }
        public override bool Run(bool isTaskRun)
        {
            if (config.ShapeName != null && config.ShapeName != string.Empty && config.ShapeName != "默认坐标系")
            {
                foreach (var item in ParentTask.Events)
                {
                    if (item is ShapeEvent)
                    {
                        ShapeEvent se = item as ShapeEvent;
                        if (se.Config.ToolName == config.ShapeName)
                        {
                            Shape.SetCenterXY(se.OrgX, se.OrgY);
                            Shape.Angle = se.Angle;
                            break;
                        }
                    }
                }
            }
            else
            {
                Shape.SetCenterXY(0, 0);
                Shape.Angle = 0;
            }

            float linkX1, linkY1, linkA1, linkX2, linkY2, linkA2;

            GetValueFromLinkStr(config.LinkL_CenterX1, out linkX1);
            GetValueFromLinkStr(config.LinkL_CenterY1, out linkY1);
            GetValueFromLinkStr(config.LinkL_Angle1, out linkA1);
            GetValueFromLinkStr(config.LinkL_CenterX2, out linkX2);
            GetValueFromLinkStr(config.LinkL_CenterY2, out linkY2);
            GetValueFromLinkStr(config.LinkL_Angle2, out linkA2);

            config.L_CenterX1 = linkX1;
            config.L_CenterY1 = linkY1;
            config.L_Angle1   = linkA1;
            config.L_CenterX2 = linkX2;
            config.L_CenterY2 = linkY2;
            config.L_Angle2   = linkA2;

            double k1, b1, k2, b2;

            k1 = Math.Tan(config.L_Angle1 * (Math.PI / 180));
            b1 = config.L_CenterY1 - k1 * config.L_CenterX1;

            k2 = Math.Tan(config.L_Angle2 * (Math.PI / 180));
            b2 = config.L_CenterY2 - k2 * config.L_CenterX2;

            HaveIntersection = k1 != k2;
            if (HaveIntersection)
            {
                double p_x, p_y;
                if (config.L_Angle1 % 90 == 0 && config.L_Angle1 % 180 != 0)
                {
                    p_x = config.L_CenterX1;
                    p_y = k2 * config.L_CenterX1 + b2;
                }
                else if (config.L_Angle2 % 90 == 0 && config.L_Angle2 % 180 != 0)
                {
                    p_x = config.L_CenterX2;
                    p_y = k1 * config.L_CenterX2 + b1;
                }
                else
                {
                    p_x = (b1 - b2) / (k2 - k1);
                    p_y = k1 * p_x + b1;
                }

                P_Intersection = new PointF((float)p_x, (float)p_y);

                if (config.IsNormalShape)
                {
                    P_Intersection    = ToolGroupEdit.GetRotatePoint(new PointF(), P_Intersection, Shape.Angle);
                    P_Intersection.X += Shape.CenterX;
                    P_Intersection.Y += Shape.CenterY;
                }
            }
            else
            {
                P_Intersection = new PointF();
            }

            ResultData.Name = config.ToolName;
            ResultData.ValueParams.Clear();
            ResultData.ValueParams.Add("有无交点", new float[] { Convert.ToSingle(HaveIntersection) });
            ResultData.ValueParams.Add("交点X坐标", new float[] { P_Intersection.X });
            ResultData.ValueParams.Add("交点Y坐标", new float[] { P_Intersection.Y });

            if (isTaskRun)
            {
                ParentTask.ResultDatas.Add(ResultData);
            }


            return(true);
        }