Пример #1
0
        protected override void BuildProcessing(MillingCommandGenerator generator)
        {
            var toolThickness = Tool.Thickness.Value;
            var profile       = ProcessingArea[0].GetCurve();

            if (Delta != 0)
            {
                profile = (Curve)profile.GetOffsetCurves(Delta)[0];
            }

            var zMax = profile.GetStartEndPoints().Max(p => p.Y);

            generator.SetZSafety(ZSafety, zMax);
            var xMax = 0D;

            using (var curve = profile.ToCompositeCurve2d())
                using (var ray = new Ray2d())
                    using (var intersector = new CurveCurveIntersector2d())
                    {
                        var angleC = 360;
                        var gCode  = 2;

                        for (var z = StartZ; z > 0; z -= StepZ)
                        {
                            var xMin = RadiusMin;
                            for (int i = 0; i < 3; i++)
                            {
                                ray.Set(new Point2d(0, z + i * toolThickness / 2), Vector2d.XAxis);
                                intersector.Set(curve, ray);
                                if (intersector.NumberOfIntersectionPoints == 1)
                                {
                                    xMin = Math.Max(xMin, intersector.GetIntersectionPoint(0).X);
                                }
                            }
                            if (xMin == 0)
                            {
                                throw new Exception("Нет точек пересечения с профилем");
                            }

                            var x         = Math.Max(xMin, RadiusMax - Penetration);
                            var s         = x - xMin;
                            int passCount = (int)Math.Ceiling(s / Penetration);
                            var dx        = s > Consts.Epsilon ? s / passCount : 1;

                            if (generator.IsUpperTool)
                            {
                                generator.Move(0, -x - ZSafety, angleC: 0, angleA: 90);
                            }
                            else
                            {
                                generator.Transition(y: -x - ZSafety, feed: CuttingFeed);
                            }
                            generator.Transition(z: z);
                            do
                            {
                                var arc = new Arc(new Point3d(0, 0, z), x, Math.PI * 1.5, Math.PI * 1.5 - Consts.Epsilon);
                                generator.Cutting(0, -x, z, PenetrationFeed);
                                generator.GCommand(CommandNames.Cutting, gCode, angleC: angleC, curve: arc, center: arc.Center.To2d(), feed: CuttingFeed);
                                angleC = 360 - angleC;
                                gCode  = 5 - gCode;
                                x     -= dx;
                            }while (x >= xMin - Consts.Epsilon);

                            xMax = Math.Max(xMin, RadiusMax);
                        }
                        generator.Transition(y: -xMax - ZSafety, feed: PenetrationFeed);
                        generator.Uplifting();
                    }
        }
Пример #2
0
        public override void BuildProcessing(MillingCommandGenerator generator)
        {
            var disk3DTechProcess = (Disk3DTechProcess)TechProcess;

            var offsetSurface = CreateOffsetSurface();

            //generator.ZSafety = offsetSurface.GeometricExtents.MinPoint.Z + TechProcess.Thickness.Value + TechProcess.ZSafety;
            //generator.ToolPosition.Point += Vector3d.ZAxis * generator.ZSafety;
            //generator.ToolLocation.Set(new Point3d(double.NaN, double.NaN, generator.ZSafety), 0, TechProcess.IsA90 ? 90 : 0);

            generator.SetZSafety(TechProcess.ZSafety, offsetSurface.GeometricExtents.MinPoint.Z + TechProcess.Thickness.Value);

            Matrix3d?matrix = null;

            if (TechProcess.IsA90)
            {
                matrix = Matrix3d.Rotation(-Math.PI / 2, Vector3d.XAxis, Point3d.Origin);
            }
            if (TechProcess.Angle != 0)
            {
                var m = Matrix3d.Rotation(disk3DTechProcess.Angle.ToRad(), Vector3d.ZAxis, Point3d.Origin);
                matrix = matrix.HasValue ? matrix.Value * m : m;
            }
            if (matrix.HasValue)
            {
                offsetSurface.TransformBy(matrix.Value);
            }
            var bounds = offsetSurface.GeometricExtents;

            //generator.ZSafety = bounds.MinPoint.Z + TechProcess.Thickness.Value + TechProcess.ZSafety;
            //generator.ToolLocation.Point += Vector3d.ZAxis * generator.ZSafety;

            //var ray = new Ray { UnitDir = Vector3d.XAxis };
            //var y = StartPass;
            //do
            //{
            //    ray.BasePoint = new Point3d(0, y, 0);

            //    var curves = s.ProjectOnToSurface(point, Vector3d.ZAxis);
            //    curves[0].ColorIndex = 2;
            //    curves[0].AddToCurrentSpace();
            //    y += StepPass;
            //}
            //while (y < boundsModel.MaxPoint.Y);

            //var startTime = System.Diagnostics.Stopwatch.StartNew();
            //var point = new DBPoint();
            //int cnt = 0;
            //for (var y = boundsModel.MinPoint.Y + StartPass; y < boundsModel.MaxPoint.Y; y += StepPass)
            //{
            //    for (var x = boundsModel.MinPoint.X; x < boundsModel.MaxPoint.X; x += StepLong)
            //    {
            //        for (var s = 0; s <= 2; s += 4)
            //        {
            //            point.Position = new Point3d(x, y + s, 0);

            //            //line.StartPoint = new Point3d(x, y, 0);
            //            //line.EndPoint = new Point3d(x, y + 8, 0);

            //            try
            //            {
            //                var curves = offsetSurfaces.ProjectOnToSurface(point, Vector3d.ZAxis);
            //                cnt++;
            //                if (curves.Length == 0)
            //                    Acad.Write("111");
            //                curves[0].ColorIndex = 6;
            //                curves[0].AddToCurrentSpace();
            //            }
            //            catch
            //            {
            //            }
            //        }
            //    }
            //}
            //startTime.Stop();
            //var resultTime = startTime.Elapsed;
            //Acad.Write("timer=" + resultTime);
            //Acad.Write("cnt=" + cnt);


            //var startTime = System.Diagnostics.Stopwatch.StartNew();
            //var line = new Line();
            //int cnt = 0;
            //int err = 0;
            //for (var y = boundsModel.MinPoint.Y + StartPass; y < boundsModel.MaxPoint.Y; y += StepPass)
            //{
            //    for (var x = boundsModel.MinPoint.X; x < boundsModel.MaxPoint.X; x += StepLong)
            //    {
            //        for (var s = 0; s <= 2; s += 4)
            //        {
            //            line.StartPoint = new Point3d(x, y, 0);
            //            line.EndPoint = new Point3d(x, y + 8, 0);

            //            try
            //            {
            //                var curves = offsetSurfaces.ProjectOnToSurface(line, Vector3d.ZAxis);
            //                cnt++;
            //                if (curves.Length == 0)
            //                    Acad.Write("111");
            //                curves[0].ColorIndex = 6;
            //                curves[0].AddToCurrentSpace();
            //            }
            //            catch (Exception ex)
            //            {
            //                err++;
            //            }
            //        }
            //    }
            //}
            //startTime.Stop();
            //var resultTime = startTime.Elapsed;
            //Acad.Write("timer=" + resultTime);
            //Acad.Write("cnt=" + cnt);

            //var contour = NoDraw.Rectang(new Point3d(bounds.MinPoint.X, bounds.MinPoint.Y, 0), new Point3d(bounds.MaxPoint.X, bounds.MaxPoint.Y, 0));
            //var ray = new Ray
            //{
            //    BasePoint = contour.StartPoint,
            //    UnitDir = Vector3d.XAxis.RotateBy(((Disk3DTechProcess)TechProcess).Angle.ToRad(), Vector3d.ZAxis)
            //};
            //ray.BasePoint += ray.UnitDir.GetPerpendicularVector() * StartPass;
            //var crossVector = ray.UnitDir.GetPerpendicularVector() * StepPass;
            //var plane = new Plane();
            //while (true)
            //{
            //    var pc = new Point3dCollection();
            //    ray.IntersectWith(contour, Intersect.ExtendThis, plane, pc, IntPtr.Zero, IntPtr.Zero);
            //    if (pc.Count != 2)
            //        break;

            //        var vector = (points[1] - points[0]).GetNormal() * tactileTechProcess.TactileTechProcessParams.Departure;
            //        var startPoint = points[0] + passDir * s - vector - Vector3d.ZAxis * Depth;
            //        var endPoint = points[1] + passDir * s + vector - Vector3d.ZAxis * Depth;
            //        if (generator.IsUpperTool)
            //            generator.Move(startPoint.X, startPoint.Y, angleC: BuilderUtils.CalcToolAngle(ProcessingAngle.ToRad()));
            //        generator.Cutting(startPoint, endPoint, feed, tactileTechProcess.TactileTechProcessParams.TransitionFeed);

            //    ray.BasePoint += crossVector;
            //}

            var startY = StartPass == 0 ? bounds.MinPoint.Y : StartPass;
            var endY   = (EndPass == 0 ? bounds.MaxPoint.Y : EndPass) - (disk3DTechProcess.IsExactlyEnd ? TechProcess.Tool.Thickness : 0);

            //double startY, endY;
            //if (!TechProcess.IsA90)
            //{
            //    startY = bounds.MinPoint.Y + StartPass;
            //    var endY = EndPass != 0 ? bounds.MinPoint.Y + EndPass : bounds.MaxPoint.Y;
            //}
            //if (startY < endY)
            //{
            //    if (disk3DTechProcess.IsExactlyEnd)
            //        endY -= TechProcess.Tool.Thickness.Value;
            //}
            //else
            //{
            //    startY -= TechProcess.Tool.Thickness.Value;
            //    if (!disk3DTechProcess.IsExactlyEnd)
            //        endY -= TechProcess.Tool.Thickness.Value;
            //    StepPass *= -1;
            //}

            //var count = bounds.MaxPoint.Y - (disk3DTechProcess.IsExactlyEnd ? TechProcess.Tool.Thickness : 0);
            //Acad.SetLimitProgressor((int)((endY - startY) / StepPass));
            //var PassList = new List<List<Point3d>>();
            //for (var y = startY; StepPass > 0 ? y < endY : y > endY; y += StepPass)



            // расчет точек начала и конца поверхности

            //var boundCurves = new List<Curve>();
            //var entitySet = new DBObjectCollection();
            //offsetSurface.Explode(entitySet);
            //for (int i = 0; i < entitySet.Count; i++)
            //{
            //    if (entitySet[i] is DbSurface)
            //    {
            //        var subEntitySet = new DBObjectCollection();
            //        ((Entity)entitySet[i]).Explode(subEntitySet);
            //        boundCurves.AddRange(subEntitySet.Cast<Curve>());
            //    }
            //    else
            //    {
            //        boundCurves.Add(entitySet[i] as Curve);
            //    }
            //}

            //var boundCurves2d = new List<Curve>();
            //var plene = new Plane(Point3d.Origin, Vector3d.ZAxis);
            //foreach (var curve in boundCurves)
            //{
            //    if (curve != null)
            //    {
            //        boundCurves2d.Add(curve.ToCurve2dArray GetOrthoProjectedCurve(plene));
            //    }
            //}

            Acad.SetLimitProgressor((int)((endY - startY) / StepPass));
            var PassList = new List <List <Point3d> >();

            for (var y = startY; y < endY; y += StepPass)
            {
                Acad.ReportProgressor();
                var points = new Point3dCollection();

                //var pass = new Line2d(new Point2d(bounds.MinPoint.X, y), new Point2d(bounds.MinPoint.X, y));
                //foreach (var cv in boundCurves2d)
                //{
                //    pass.IntersectWith(cv.to);
                //}

                for (var x = bounds.MinPoint.X; x <= bounds.MaxPoint.X; x += StepLong)
                {
                    double z = 0;
                    for (double s = 0; s <= TechProcess.Tool.Thickness; s += TechProcess.Tool.Thickness.Value)
                    {
                        if (y + s > bounds.MaxPoint.Y)
                        {
                            break;
                        }
                        offsetSurface.RayTest(new Point3d(x, y + s, bounds.MinPoint.Z), Vector3d.ZAxis, 0.0001, out SubentityId[] col, out DoubleCollection par);
                        //if (par.Count == 0)
                        //{
                        //    z = 0;
                        //    break;
                        //}
                        if (par.Count > 0)
                        {
                            z = par[par.Count - 1] > z ? par[par.Count - 1] : z;
                        }
                    }
                    if (z > 0)
                    {
                        var point = new Point3d(x, y, bounds.MinPoint.Z + z);
                        var ind   = points.Count - 1;
                        if (ind > 0 && points[ind - 1].GetVectorTo(points[ind]).IsCodirectionalTo(points[ind].GetVectorTo(point)))
                        {
                            points[ind] = point;
                        }
                        else
                        {
                            points.Add(point);
                        }
                        //Draw.Point(point);
                    }
                }
                if (points.Count > 1)
                {
                    PassList.Add(CalcOffsetPoints(points, bounds));
                }
            }
            offsetSurface.Dispose();


            if (matrix.HasValue)
            {
                matrix = matrix.Value.Inverse();
            }
            if (TechProcess.IsA90 && PassList.First()[0].TransformBy(matrix.Value).Z < PassList.Last()[0].TransformBy(matrix.Value).Z)
            {
                PassList.Reverse();
            }
            if (IsReverse)
            {
                PassList.Reverse();
            }

            if (TechProcess.IsA90)
            {
                generator.Matrix = matrix;
            }

            Point3d?lastPoint = null;

            PassList.ForEach(p =>
            {
                var points = p;
                if (TechProcess.MachineType == MachineType.ScemaLogic) //Settongs.IsFrontPlaneZero
                {
                    points = points.ConvertAll(x => new Point3d(x.X, x.Y + TechProcess.Tool.Thickness.Value, x.Z));
                }
                if (matrix.HasValue && !TechProcess.IsA90)
                {
                    points = points.ConvertAll(x => x.TransformBy(matrix.Value));
                }
                var loc = generator.ToolPosition;
                if (lastPoint.HasValue && lastPoint.Value.DistanceTo(points.First()) > lastPoint.Value.DistanceTo(points.Last()))
                {
                    points.Reverse();
                }

                if (TechProcess.IsA90)
                {
                    lastPoint = BuildPassA90(generator, points, matrix.Value, bounds.MinPoint.Z + PenetrationAll);
                }
                else
                {
                    lastPoint = BuildPass(generator, points);
                }
            });
            if (TechProcess.IsA90)
            {
                generator.Move(lastPoint.Value.Add(Vector3d.ZAxis * 100));
            }

            if (generator is DonatoniCommandGenerator donatoniCommandGenerator)
            {
                donatoniCommandGenerator.IsSupressMoveHome = true;
            }
            //progressor.Stop();
        }