示例#1
0
        public override void BuildProcessing(MillingCommandGenerator generator)
        {
            switch (CalcMethod)
            {
            case CalcMethodType.Average:
                for (int i = 0; i < PointsX.Count; i++)
                {
                    generator.GCommand(CommandNames.Fast, 0, x: PointsX[i] + 230, y: PointsY[i] - 100 - TechProcess.Tool.Thickness.GetValueOrDefault());
                    generator.ToolPosition.Point -= new Vector3d(0, 0, 1);
                    generator.GCommand("", 0, z: Thickness.GetValueOrDefault() + TechProcess.ZSafety);

                    generator.Command("M131");
                    generator.Command($"DBL THICK{i} = %TastL.ZLastra - %TastL.ZBanco", "Измерение");
                    generator.Command($"G0 Z(THICK{i}/1000 + 100)");
                }
                var s = String.Join(" + ", Enumerable.Range(0, PointsX.Count).Select(p => $"THICK{p}"));
                generator.Command($"DBL THICK = ({s})/{PointsX.Count}/1000");
                break;

            case CalcMethodType.Minimum:
                for (int i = 0; i < PointsX.Count; i++)
                {
                    generator.GCommand(CommandNames.Fast, 0, x: PointsX[i] + 230, y: PointsY[i] - 100 - TechProcess.Tool.Thickness.GetValueOrDefault());
                    generator.ToolPosition.Point -= new Vector3d(0, 0, 1);
                    generator.GCommand("", 0, z: Thickness.GetValueOrDefault() + TechProcess.ZSafety);

                    generator.Command("M131");
                    generator.Command($"DBL THICK{i} = %TastL.ZLastra - %TastL.ZBanco", "Измерение");
                    generator.Command($"G0 Z(THICK{i}/1000 + 100)");

                    if (i != 0)
                    {
                        generator.Command($"IF (THICK{i} < THICK0) THEN");
                        generator.Command($" THICK0 = THICK{i}");
                        generator.Command("ENDIF");
                    }
                }
                generator.Command("DBL THICK = THICK0/1000");
                break;

            case CalcMethodType.Сorners:

                var points  = PointsX.Select((p, i) => new Point2d(p, PointsY[i])).OrderBy(p => p.X).ToList();
                var corners = points.Take(2).OrderBy(p => p.Y).Concat(points.Skip(2).OrderByDescending(p => p.Y)).ToList();

                for (int i = 0; i < corners.Count; i++)
                {
                    generator.GCommand(CommandNames.Fast, 0, x: corners[i].X + 230, y: corners[i].Y - 100 - TechProcess.Tool.Thickness.GetValueOrDefault());
                    generator.ToolPosition.Point -= new Vector3d(0, 0, 1);
                    generator.GCommand("", 0, z: Thickness.GetValueOrDefault() + TechProcess.ZSafety);

                    generator.Command("M131");
                    generator.Command($"DBL THICK{i} = (%TastL.ZLastra - %TastL.ZBanco)/1000", "Измерение");
                    generator.Command($"G0 Z(THICK{i} + 100)");
                }
                var l1 = corners[3].X - corners[0].X;
                var l2 = corners[1].Y - corners[0].Y;
                generator.Command($"DBL KK1=(THICK3 - THICK0) / {l1}");
                generator.Command($"DBL KK2=(THICK2 - THICK1) / {l1}");
                generator.Command("DBL THICK");
                generator.ThickCommand = $"THICK = (({{0}}-{corners[0].X})*KK2+THICK1)*({{1}}-{corners[0].Y})/{l2} + (({{0}}-{corners[0].X})*KK1+THICK0)*(1-({{1}}-{corners[0].Y})/{l2})";
                break;
            }
            generator.WithThick = true;
        }
示例#2
0
        public override void BuildProcessing(MillingCommandGenerator generator)
        {
            var tactileTechProcess = (TactileTechProcess)TechProcess;
            var isDiag             = tactileTechProcess.ProcessingAngle1 != 0;

            var contour       = tactileTechProcess.GetContour();
            var contourPoints = contour.GetPolyPoints().ToArray();

            var point = tactileTechProcess.Objects.Select(p => p.GetCurve()).OfType <Circle>().Select(p => p.Center).OrderBy(p => (int)p.Y).ThenBy(p => p.X).First();
            var x     = point.X;
            var y     = point.Y;
            var stepX = tactileTechProcess.BandSpacing.Value + tactileTechProcess.BandWidth.Value;
            var stepY = stepX;

            if (isDiag)
            {
                stepY /= Math.Sqrt(2);
                stepX  = stepY * 2;
            }
            generator.SetTool(2, Frequency, 90, false);
            generator.ZSafety = ZSafety;

            while (y < contourPoints[1].Y)
            {
                Cutting();
                x += stepX;
                if (x > contourPoints[3].X)
                {
                    y    += stepY;
                    x    -= stepY;
                    stepX = -stepX;
                    if (x > contourPoints[3].X)
                    {
                        x += stepX;
                    }
                }
                if (x < contourPoints[1].X)
                {
                    y    += stepY;
                    x    += stepY;
                    stepX = -stepX;
                    if (x < contourPoints[1].X)
                    {
                        x += stepX;
                    }
                }
            }

            void Cutting()
            {
                generator.Move(x, y);
                generator.Move(z: ZEntry);
                var    zMin    = -Depth;
                double z       = 0.2;
                int    counter = 0;

                while (z > zMin)
                {
                    z -= 0.2;
                    if (z < zMin)
                    {
                        z = zMin;
                    }

                    var feed = (int)((FeedMax - FeedMin) / zMin * (z * z / zMin - 2 * z) + FeedMax);
                    generator.Cutting(x, y, z, feed);
                    if (z <= -2)
                    {
                        if (++counter == 5) // Подъем на 1мм для охлаждения
                        {
                            counter = 0;
                            Pause();
                            generator.Uplifting(z + 1);
                            generator.Cutting(x, y, z + 0.2, (int)(FeedMax * 1.5));
                            generator.Cutting(x, y, z, feed);
                        }
                    }
                }
                Pause();
                generator.Uplifting();

                void Pause() => generator.Command("G4 F0.2", "Пауза");
            }

            contour.Dispose();
        }
示例#3
0
        public override void BuildProcessing(MillingCommandGenerator generator)
        {
            const int CornerIndentIncrease = 5;
            var       curve        = ProcessingArea.GetCurve();
            var       thickness    = TechProcess.Thickness.Value + 2; // запил на 2мм ниже нижнего края
            var       toolDiameter = TechProcess.Tool.Diameter;
            var       engineSide   = Side.None;
            double    offsetArc    = 0;
            double    angleA       = 0;

            if (TechProcess.MachineType == MachineType.ScemaLogic)
            {
                AngleA = 0;
            }

            switch (curve)
            {
            case Arc arc:
                CalcArc(arc);
                break;

            case Line line:
                CalcLine(line);
                break;

            case Polyline polyline:
                CalcPolyline(polyline);
                break;

            default:
                throw new InvalidOperationException($"Кривая типа {curve.GetType()} не может быть обработана.");
            }

            var outerSideSign = OuterSide == Side.Left ^ curve is Line ? -1 : 1;
            var offsetCoeff   = Math.Tan(angleA) * outerSideSign;
            var depthCoeff    = 1 / Math.Cos(angleA);
            var toolThickness = TechProcess.Tool.Thickness.Value * depthCoeff;
            var compensation  = (offsetArc + (engineSide == OuterSide ^ TechProcess.MachineType == MachineType.Donatoni ? toolThickness : 0)) * outerSideSign;
            var shift         = angleA > 0 ? -thickness * offsetCoeff : 0;

            var sumIndent = CalcIndent(thickness) * (Convert.ToInt32(IsExactlyBegin) + Convert.ToInt32(IsExactlyEnd));

            if (sumIndent >= curve.Length())
            {
                if (AngleA != 0)
                {
                    throw new InvalidOperationException("Расчет намечания выполняется только при нулевом вертикальном угле.");
                }
                var point = Scheduling();
                var angle = BuilderUtils.CalcToolAngle((curve.EndPoint - curve.StartPoint).ToVector2d().Angle, engineSide);
                generator.Move(point.X, point.Y, angleC: angle);
                generator.Cutting(point.X, point.Y, point.Z, TechProcess.PenetrationFeed);
                return;
            }

            var modes = SawingModes.ConvertAll(p => new CuttingMode {
                Depth = p.Depth, DepthStep = p.DepthStep, Feed = p.Feed
            });
            var passList = BuilderUtils.GetPassList(modes, thickness, !ProcessingArea.ObjectId.IsLine()).ToList();

            Curve toolpathCurve = null;

            foreach (var item in passList)
            {
                CreateToolpath(item.Key, compensation + shift + item.Key * offsetCoeff);
                if (generator.IsUpperTool)
                {
                    var point  = engineSide == Side.Right ^ (passList.Count() % 2 == 1) ? toolpathCurve.EndPoint : toolpathCurve.StartPoint;
                    var vector = Vector3d.ZAxis * (item.Key + generator.ZSafety);
                    if (angleA != 0)
                    {
                        vector = vector.RotateBy(outerSideSign * angleA, ((Line)toolpathCurve).Delta) * depthCoeff;
                    }
                    var p0     = point + vector;
                    var angleC = BuilderUtils.CalcToolAngle(toolpathCurve, point, engineSide);
                    generator.Move(p0.X, p0.Y, angleC: angleC, angleA: Math.Abs(AngleA));
                    if (TechProcess.MachineType == MachineType.ScemaLogic)
                    {
                        generator.Command("28;;XYCZ;;;;;;", "Цикл");
                    }
                }
                generator.Cutting(toolpathCurve, item.Value, TechProcess.PenetrationFeed, engineSide);
            }
            generator.Uplifting(Vector3d.ZAxis.RotateBy(outerSideSign * angleA, toolpathCurve.EndPoint - toolpathCurve.StartPoint) * (thickness + generator.ZSafety) * depthCoeff);

            if ((!IsExactlyBegin || !IsExactlyEnd) && Departure == 0)
            {
                var gashCurve = curve.GetOffsetCurves(shift)[0] as Curve;
                var gashList  = new List <ObjectId>();
                if (!IsExactlyBegin)
                {
                    gashList.Add(Acad.CreateGash(gashCurve, gashCurve.StartPoint, OuterSide, thickness * depthCoeff, toolDiameter, toolThickness));
                }
                if (!IsExactlyEnd)
                {
                    gashList.Add(Acad.CreateGash(gashCurve, gashCurve.EndPoint, OuterSide, thickness * depthCoeff, toolDiameter, toolThickness));
                }
                if (gashList.Count > 0)
                {
                    Modify.AppendToGroup(base.TechProcess.ExtraObjectsGroup.Value, gashList.ToArray());
                }
                gashCurve.Dispose();
            }

            // Local func ------------------------

            void CalcArc(Arc arc)
            {
                AngleA = 0;
                var startSide      = Math.Sign(Math.Cos(arc.StartAngle.Round(3)));
                var endSide        = Math.Sign(Math.Cos(arc.EndAngle.Round(3)));
                var cornersOneSide = Math.Sign(startSide * endSide);

                if (arc.TotalAngle.Round(3) > Math.PI && cornersOneSide > 0)
                {
                    throw new InvalidOperationException("Обработка дуги невозможна - дуга пересекает углы 90 и 270 градусов.");
                }

                if (cornersOneSide < 0) //  дуга пересекает углы 90 или 270 градусов
                {
                    if (TechProcess.MachineType == MachineType.ScemaLogic)
                    {
                        throw new InvalidOperationException("Обработка дуги невозможна - дуга пересекает угол 90 или 270 градусов.");
                    }

                    engineSide = startSide > 0 ? Side.Left : Side.Right;
                }
                if (OuterSide == Side.Left)                                                         // внутренний рез дуги
                {
                    if (TechProcess.MachineType == MachineType.Donatoni && engineSide != Side.Left) // подворот диска при вн. резе дуги
                    {
                        engineSide = Side.Right;
                        //var comp = arc.Radius - Math.Sqrt(arc.Radius * arc.Radius - thickness * (toolDiameter - thickness));
                        //AngleA = Math.Atan2(comp, thickness).ToDeg();

                        var R    = arc.Radius;
                        var t    = thickness;
                        var d    = toolDiameter;
                        var comp = (2 * R * t * t - Math.Sqrt(-d * d * d * d * t * t + 4 * d * d * R * R * t * t + d * d * t * t * t * t)) / (d * d - 4 * R * R);
                        AngleA = -Math.Atan2(comp, thickness).ToDeg();
                    }
                    else
                    {
                        offsetArc = arc.Radius - Math.Sqrt(arc.Radius * arc.Radius - thickness * (toolDiameter - thickness));
                    }
                }
                if (engineSide == Side.None)
                {
                    engineSide = (startSide + endSide) > 0 ? Side.Right : Side.Left;
                }
            }

            void CalcLine(Line line)
            {
                angleA     = AngleA.ToRad();
                engineSide = AngleA == 0 ? BuilderUtils.CalcEngineSide(line.Angle) : AngleA > 0 ? OuterSide : OuterSide.Opposite();
            }

            void CalcPolyline(Polyline polyline)
            {
                int sign = 0;

                for (int i = 0; i < polyline.NumberOfVertices; i++)
                {
                    var point = polyline.GetPoint3dAt(i);
                    var s     = Math.Sign(Math.Sin(polyline.GetTangent(point).Angle.Round(6)));
                    if (s == 0)
                    {
                        continue;
                    }
                    if (sign == 0)
                    {
                        sign = s;
                        continue;
                    }
                    var bulge = polyline.GetBulgeAt(i - 1);
                    if (bulge == 0)
                    {
                        bulge = polyline.GetBulgeAt(i);
                    }

                    if (s != sign)
                    {
                        if (TechProcess.MachineType == MachineType.ScemaLogic)
                        {
                            throw new InvalidOperationException("Обработка полилинии невозможна - кривая пересекает углы 90 или 270 градусов.");
                        }
                        var side = sign > 0 ^ bulge < 0 ? Side.Left : Side.Right;
                        if (engineSide != Side.None)
                        {
                            if (engineSide != side)
                            {
                                throw new InvalidOperationException("Обработка полилинии невозможна.");
                            }
                        }
                        else
                        {
                            engineSide = side;
                        }
                        sign = s;
                    }
                    else
                    if (Math.Abs(bulge) > 1)
                    {
                        throw new InvalidOperationException("Обработка невозможна - дуга полилинии пересекает углы 90 и 270 градусов.");
                    }
                }
                if (engineSide == Side.None)
                {
                    engineSide = BuilderUtils.CalcEngineSide(polyline.GetTangent(polyline.StartPoint).Angle);
                }
            }

            void CreateToolpath(double depth, double offset)
            {
                toolpathCurve = curve.GetOffsetCurves(offset)[0] as Curve;
                toolpathCurve.TransformBy(Matrix3d.Displacement(-Vector3d.ZAxis * depth));

                if (Departure > 0 && toolpathCurve is Line line)
                {
                    if (!IsExactlyBegin)
                    {
                        toolpathCurve.StartPoint = line.ExpandStart(Departure);
                    }
                    if (!IsExactlyEnd)
                    {
                        toolpathCurve.EndPoint = line.ExpandEnd(Departure);
                    }
                }

                if (!IsExactlyBegin && !IsExactlyEnd)
                {
                    return;
                }
                var indent = CalcIndent(depth * depthCoeff);

                switch (toolpathCurve)
                {
                case Line l:
                    if (IsExactlyBegin)
                    {
                        l.StartPoint = l.GetPointAtDist(indent);
                    }
                    if (IsExactlyEnd)
                    {
                        l.EndPoint = l.GetPointAtDist(l.Length - indent);
                    }
                    break;

                case Arc a:
                    var indentAngle = indent / ((Arc)curve).Radius;
                    if (IsExactlyBegin)
                    {
                        a.StartAngle = a.StartAngle + indentAngle;
                    }
                    if (IsExactlyEnd)
                    {
                        a.EndAngle = a.EndAngle - indentAngle;
                    }
                    break;

                case Polyline p:
                    if (IsExactlyBegin)
                    {
                        p.SetPointAt(0, p.GetPointAtDist(indent).ToPoint2d());
                    }
                    //p.StartPoint = p.GetPointAtDist(indent);
                    if (IsExactlyEnd)
                    {
                        //p.EndPoint = p.GetPointAtDist(p.Length - indent);
                        p.SetPointAt(p.NumberOfVertices - 1, p.GetPointAtDist(p.Length - indent).ToPoint2d());
                    }
                    break;
                }
                ;
            }

            double CalcIndent(double depth) => Math.Sqrt(depth * (toolDiameter - depth)) + CornerIndentIncrease;

            /// <summary>
            /// Расчет точки намечания
            /// </summary>
            Point3d Scheduling()
            {
                var vector = curve.EndPoint - curve.StartPoint;
                var depth  = thickness;
                var point  = Point3d.Origin;

                if (IsExactlyBegin && IsExactlyEnd)
                {
                    var l = vector.Length - 2 * CornerIndentIncrease;
                    depth = (toolDiameter - Math.Sqrt(toolDiameter * toolDiameter - l * l)) / 2;
                    point = curve.StartPoint + vector / 2;
                }
                else
                {
                    var indentVector = vector.GetNormal() * (Math.Sqrt(depth * (toolDiameter - depth)) + CornerIndentIncrease);
                    point = IsExactlyBegin ? curve.StartPoint + indentVector : curve.EndPoint - indentVector;
                    Acad.CreateGash(curve, IsExactlyBegin ? curve.EndPoint : curve.StartPoint, OuterSide, depth, toolDiameter, toolThickness, point);
                }
                return(point + vector.GetPerpendicularVector().GetNormal() * compensation - Vector3d.ZAxis * depth);
            }
        }