Exemplo n.º 1
0
        //##############################################################################################################################################################################################

        /// <summary>
        /// Calculate the edge type (LINE, BULB, HOLE)
        /// </summary>
        private void classify()
        {
            try
            {
                EdgeType = EdgeTypes.UNKNOWN;
                if (NormalizedContour.Size <= 1)
                {
                    return;
                }

                //See if it is an outer edge comparing the distance between beginning and end with the arc length.
                double contour_length = CvInvoke.ArcLength(NormalizedContour, false);

                double begin_end_distance = Utils.Distance(NormalizedContour.ToArray().First(), NormalizedContour.ToArray().Last());
                if (contour_length < begin_end_distance * 1.3)
                {
                    EdgeType = EdgeTypes.LINE;
                }

                if (EdgeType == EdgeTypes.UNKNOWN)
                {
                    //Find the minimum or maximum value for x in the normalized contour and base the classification on that
                    int minx = 100000000;
                    int maxx = -100000000;
                    for (int i = 0; i < NormalizedContour.Size; i++)
                    {
                        if (minx > NormalizedContour[i].X)
                        {
                            minx = (int)NormalizedContour[i].X;
                        }
                        if (maxx < NormalizedContour[i].X)
                        {
                            maxx = (int)NormalizedContour[i].X;
                        }
                    }

                    if (Math.Abs(minx) > Math.Abs(maxx))
                    {
                        EdgeType = EdgeTypes.BULB;
                    }
                    else
                    {
                        EdgeType = EdgeTypes.HOLE;
                    }
                }

                if (PluginFactory.GetGeneralSettingsPlugin().SolverShowDebugResults)
                {
                    Bitmap contourImg = PieceImgColor.Bmp;
                    for (int i = 0; i < contour.Size; i++)
                    {
                        Graphics g = Graphics.FromImage(contourImg);
                        g.DrawEllipse(new Pen(Color.Red), new RectangleF(PointF.Subtract(contour[i], new Size(1, 1)), new SizeF(2, 2)));
                    }
                    _logHandle.Report(new LogEventImage(PieceID + " Edge " + EdgeNumber.ToString() + " " + EdgeType.ToString(), contourImg));
                    ContourImg.Bmp = contourImg;
                    contourImg.Dispose();
                }
            }
            catch (Exception ex)
            {
                _logHandle.Report(new LogBox.LogEvents.LogEventError(ex.Message));
            }
        }
Exemplo n.º 2
0
        public override void ToMachining(double AssociatedDist, ToolFile toolFile)
        {
            //由于这个指令是指定了板件的1-8个点进行定位的,所以要把空间的绝对坐标换算回机加工原点的相对坐标
            //matrix1负责把所在点的坐标转换为板件中心的坐标
            //matrix2负责把板件中心的坐标,再转换为MP中心的坐标
            Point3d  pt      = Part.GetPartPointByNumber(EdgeNumber.ToString());
            Matrix3d matrix1 = Matrix3d.AlignCoordinateSystem(
                Point3d.Origin,
                Vector3d.XAxis,
                Vector3d.YAxis,
                Vector3d.ZAxis,
                pt,
                (Part.MachinePoint.IsRotated) ? this.GetPointYAxis(EdgeNumber) : this.GetPointXAxis(EdgeNumber),
                (Part.MachinePoint.IsRotated) ? this.GetPointXAxis(EdgeNumber) : this.GetPointYAxis(EdgeNumber),
                Vector3d.ZAxis);
            Matrix3d matrix2 = Matrix3d.AlignCoordinateSystem(
                Part.MPPoint,
                Part.MPXAxis,
                Part.MPYAxis,
                Part.MPZAxis,
                Point3d.Origin,
                Vector3d.XAxis,
                Vector3d.YAxis,
                Vector3d.ZAxis);

            if (LeadIn > 0)
            {
                double  rRadius  = LeadIn;
                Point3d firstPt  = new Point3d(Radius + rRadius, -rRadius, Depth);
                Point3d secondPt = new Point3d(Radius, 0, Depth);
                Point3d thirdPt  = new Point3d(0, Radius, Depth);
                Point3d forthPt  = new Point3d(-rRadius, Radius + rRadius, Depth);

                firstPt  = firstPt.TransformBy(matrix1).TransformBy(matrix2);
                secondPt = secondPt.TransformBy(matrix1).TransformBy(matrix2);
                thirdPt  = thirdPt.TransformBy(matrix1).TransformBy(matrix2);
                forthPt  = forthPt.TransformBy(matrix1).TransformBy(matrix2);

                double   firstBulge = -0.414214;
                ToolComp comp       = ToolComp.None;

                if (firstPt.X >= thirdPt.X && firstPt.Y >= thirdPt.Y)
                {
                    comp        = ToolComp.Left;
                    firstBulge *= -1;
                }
                else if (firstPt.X >= thirdPt.X && firstPt.Y < thirdPt.Y)
                {
                    comp = ToolComp.Right;
                }
                else if (firstPt.X < thirdPt.X && firstPt.Y < thirdPt.Y)
                {
                    comp        = ToolComp.Left;
                    firstBulge *= -1;
                }
                else if (firstPt.X < thirdPt.X && firstPt.Y >= thirdPt.Y)
                {
                    comp = ToolComp.Right;
                }

                Machinings.Routing route = new Machinings.Routing();
                route.ToolName = ToolName;
                route.Points   = new List <Point3d>()
                {
                    firstPt, secondPt, thirdPt, forthPt
                };
                route.Part     = Part;
                route.ToolComp = comp;
                route.Bulges   = (new double[] { 0, firstBulge, 0, 0 }).ToList();
                if (FaceNumber == 5)
                {
                    route.OnFace5 = true;
                }
                else
                {
                    route.OnFace5 = false;
                }

                Part.Routings.Add(route);
            }
        }
Exemplo n.º 3
0
        public override void ToMachining(double AssociatedDist, Entities.ToolFile toolFile)
        {
            //先以当前点为坐标系,建立两点坐标
            double  xydist   = System.Math.Sqrt(DistX * DistX + DistY * DistY);
            double  cos      = DistX / xydist;
            double  sin      = DistY / xydist;
            Point3d firstPt  = new Point3d(DistX + LeadIn * cos, -LeadIn * sin, Depth);
            Point3d secondPt = new Point3d(-LeadIn * cos, DistY + LeadIn * sin, Depth);

            //把两点坐标,转换为世界坐标,再转为MP坐标系
            Point3d  pt      = Part.GetPartPointByNumber(EdgeNumber.ToString());
            Matrix3d matrix1 = Matrix3d.AlignCoordinateSystem(
                Point3d.Origin,
                Vector3d.XAxis,
                Vector3d.YAxis,
                Vector3d.ZAxis,
                pt,
                (Part.MachinePoint.IsRotated) ? this.GetPointYAxis(EdgeNumber) : this.GetPointXAxis(EdgeNumber),
                (Part.MachinePoint.IsRotated) ? this.GetPointXAxis(EdgeNumber) : this.GetPointYAxis(EdgeNumber),
                Vector3d.ZAxis);
            Matrix3d matrix2 = Matrix3d.AlignCoordinateSystem(
                Part.MPPoint,
                Part.MPXAxis,
                Part.MPYAxis,
                Part.MPZAxis,
                Point3d.Origin,
                Vector3d.XAxis,
                Vector3d.YAxis,
                Vector3d.ZAxis);

            firstPt  = firstPt.TransformBy(matrix1).TransformBy(matrix2);
            secondPt = secondPt.TransformBy(matrix1).TransformBy(matrix2);

            ToolComp comp = ToolComp.None;

            if (firstPt.X >= secondPt.X && firstPt.Y >= secondPt.Y)
            {
                comp = ToolComp.Left;
            }
            else if (firstPt.X >= secondPt.X && firstPt.Y < secondPt.Y)
            {
                comp = ToolComp.Right;
            }
            else if (firstPt.X < secondPt.X && firstPt.Y < secondPt.Y)
            {
                comp = ToolComp.Left;
            }
            else if (firstPt.X < secondPt.X && firstPt.Y >= secondPt.Y)
            {
                comp = ToolComp.Right;
            }

            List <Point3d> points = new List <Point3d>()
            {
                firstPt, secondPt
            };

            Machinings.Routing route = new Machinings.Routing();
            route.ToolName = ToolName;
            route.Points   = points;
            route.Part     = Part;
            route.ToolComp = comp;
            route.Bulges   = (new double[] { 0, 0 }).ToList();
            if (FaceNumber == 5)
            {
                route.OnFace5 = true;
            }
            else
            {
                route.OnFace5 = false;
            }

            Part.Routings.Add(route);
        }
Exemplo n.º 4
0
        public override void ToMachining(double AssociatedDist, Entities.ToolFile toolFile)
        {
            //由于这个指令是指定了板件的1-8个点进行定位的,所以要把空间的绝对坐标换算回机加工原点的相对坐标
            //matrix1负责把所在点的坐标转换为板件中心的坐标
            //matrix2负责把板件中心的坐标,再转换为MP中心的坐标
            Point3d  pt      = Part.GetPartPointByNumber(EdgeNumber.ToString());
            Matrix3d matrix1 = Matrix3d.AlignCoordinateSystem(
                Point3d.Origin,
                Vector3d.XAxis,
                Vector3d.YAxis,
                Vector3d.ZAxis,
                pt,
                (Part.MachinePoint.IsRotated) ? this.GetPointYAxis(EdgeNumber) : this.GetPointXAxis(EdgeNumber),
                (Part.MachinePoint.IsRotated) ? this.GetPointXAxis(EdgeNumber) : this.GetPointYAxis(EdgeNumber),
                Vector3d.ZAxis);
            Matrix3d matrix2 = Matrix3d.AlignCoordinateSystem(
                Part.MPPoint,
                Part.MPXAxis,
                Part.MPYAxis,
                Part.MPZAxis,
                Point3d.Origin,
                Vector3d.XAxis,
                Vector3d.YAxis,
                Vector3d.ZAxis);

            //板件如果旋转,则生成的坐标点是不一样的
            List <Point3d> Points   = new List <Point3d>();
            Point3d        firstPt  = new Point3d(XDist, -LeadIn, Depth);
            Point3d        secondPt = new Point3d(XDist, YDist, Depth);
            Point3d        thirdPt  = new Point3d(-LeadIn, YDist, Depth);

            firstPt  = firstPt.TransformBy(matrix1).TransformBy(matrix2);
            secondPt = secondPt.TransformBy(matrix1).TransformBy(matrix2);
            thirdPt  = thirdPt.TransformBy(matrix1).TransformBy(matrix2);
            Points.Add(new Point3d(firstPt.X, firstPt.Y, Depth));
            Points.Add(new Point3d(secondPt.X, secondPt.Y, Depth));
            Points.Add(new Point3d(thirdPt.X, thirdPt.Y, Depth));

            //判断刀补的方向
            ToolComp comp = ToolComp.None;

            if (firstPt.X >= thirdPt.X && firstPt.Y >= thirdPt.Y)
            {
                comp = ToolComp.Left;
            }
            else if (firstPt.X >= thirdPt.X && firstPt.Y < thirdPt.Y)
            {
                comp = ToolComp.Right;
            }
            else if (firstPt.X < thirdPt.X && firstPt.Y < thirdPt.Y)
            {
                comp = ToolComp.Left;
            }
            else if (firstPt.X < thirdPt.X && firstPt.Y >= thirdPt.Y)
            {
                comp = ToolComp.Right;
            }

            Machinings.Routing route = new Machinings.Routing();
            route.ToolName = ToolName;
            route.Points   = Points;
            route.Part     = Part;
            route.ToolComp = comp;
            route.Bulges   = (new double[] { 0, 0, 0 }).ToList();
            if (FaceNumber == 5)
            {
                route.OnFace5 = true;
            }
            else
            {
                route.OnFace5 = false;
            }

            Part.Routings.Add(route);
        }