コード例 #1
0
ファイル: BandsTechOperation.cs プロジェクト: 15831944/CAM
        public void CalcPassList()
        {
            if (TechProcess.Tool.Thickness == null)
            {
                Acad.Alert("Не указана толщина инструмента");
                return;
            }
            var toolThickness = TechProcess.Tool.Thickness.Value;

            if (MaxCrestWidth == 0 || MaxCrestWidth > toolThickness)
            {
                MaxCrestWidth = toolThickness;
            }
            var periodAll   = BandWidth - toolThickness;
            var periodWidth = toolThickness + MaxCrestWidth;
            var count       = Math.Ceiling(periodAll / periodWidth);

            periodWidth = periodAll / count;
            var x     = (toolThickness - (periodWidth - toolThickness)) / 2;
            var shift = TechProcess.MachineType == MachineType.ScemaLogic ^ ProcessingAngle == 45? toolThickness : 0;

            PassList = new List <Pass> {
                new Pass(shift, CuttingType.Roughing)
            };
            for (int i = 1; i <= count; i++)
            {
                PassList.Add(new Pass(i * periodWidth + shift, CuttingType.Roughing));
                PassList.Add(new Pass(i * periodWidth + x + shift - toolThickness, CuttingType.Finishing));
            }
        }
コード例 #2
0
 public override bool Validate()
 {
     if (StepPass == 0)
     {
         Acad.Alert("Не заполнено поле \"Шаг межстрочный\"");
     }
     return(StepPass != 0);
 }
コード例 #3
0
ファイル: PolishingTechProcess.cs プロジェクト: airmay/CAM
 public override bool Validate()
 {
     if (Angle2 >= 90)
     {
         Acad.Alert("Угол2 должен быть меньше 90");
     }
     return(Angle2 < 90);
 }
コード例 #4
0
 public override bool Validate()
 {
     if (LongStep == 0 || ProfileStep == 0)
     {
         Acad.Alert("Не заполнено поле \"Шаг\"");
     }
     return(!(LongStep == 0 || ProfileStep == 0));
 }
コード例 #5
0
        private void bObjects_Click(object sender, EventArgs e)
        {
            if (_techProcess.ProcessingArea == null)
            {
                Acad.Alert("Укажите контур плитки");
                return;
            }
            Interaction.SetActiveDocFocus();
            Acad.SelectObjectIds();
            var ids = Interaction.GetSelection("\nВыберите 2 элемента плитки");

            if (ids.Length > 0)
            {
                _techProcess.CalcType(ids);
                _techProcess.Objects = AcadObject.CreateList(ids);
                tbObjects.Text       = _techProcess.Objects.GetDesc();
                tactileTechProcessBindingSource.ResetBindings(false);
                SetParamsEnabled();
            }
        }
コード例 #6
0
ファイル: TactileTechProcess.cs プロジェクト: presscad/CAM
        public void CalcType(ObjectId[] ids)
        {
            Type             = null;
            BandSpacing      = null;
            BandWidth        = null;
            BandStart1       = null;
            BandStart2       = null;
            ProcessingAngle1 = null;
            ProcessingAngle2 = null;

            if (ids.Length < 2)
            {
                Acad.Alert("Выберите 2 элемента");
                return;
            }
            var contourPoints = GetContour().GetPolyPoints().ToArray();
            var curves        = ids.QOpenForRead <Curve>();
            var circles       = curves.OfType <Circle>().ToArray();

            if (circles.Any())
            {
                var radius = circles.Max(p => p.Radius);
                circles = circles.Where(p => p.Radius == radius).ToArray();
                const double Delta = 1;
                radius += Delta;
                var vector = circles[1].Center - circles[0].Center;
                var center = (circles[1].Center.X < circles[0].Center.X ? circles[1] : circles[0]).Center;
                BandSpacing = radius * 2;
                BandWidth   = vector.Length - BandSpacing.Value;
                if (vector.IsParallelTo(Vector3d.XAxis) || vector.IsPerpendicularTo(Vector3d.XAxis))
                {
                    Type             = "Конусы прямые";
                    ProcessingAngle1 = 0;
                    ProcessingAngle2 = 90;
                    BandStart1       = center.Y + radius - contourPoints[0].Y;
                    BandStart2       = center.X + radius - contourPoints[0].X;
                }
                else
                {
                    Type = "Конусы диагональные";
                    var ray = new Ray {
                        BasePoint = center
                    };

                    ProcessingAngle1 = 135;
                    ray.UnitDir      = Vector3d.XAxis.RotateBy(Graph.ToRad(ProcessingAngle1.Value), Vector3d.ZAxis);
                    BandStart1       = ray.GetDistToPoint(contourPoints[0], true) + radius;

                    ProcessingAngle2 = 45;
                    ray.UnitDir      = Vector3d.XAxis.RotateBy(Graph.ToRad(ProcessingAngle2.Value), Vector3d.ZAxis);
                    BandStart2       = ray.GetDistToPoint(contourPoints[3], true) % vector.Length + radius;
                }
                RoundParams();
                return;
            }
            var lines = curves.OfType <Line>().ToArray();

            if (lines.Length == 8)
            {
                Type             = "Квадраты";
                ProcessingAngle1 = 0;
                ProcessingAngle2 = 90;
                BandSpacing      = lines.First().Length;
                var points = lines.SelectMany(p => Graph.GetStartEndPoints(p));
                var point1 = new Point3d(points.Min(p => p.X), points.Min(p => p.Y), 0);
                BandStart1 = point1.Y + BandSpacing - contourPoints[0].Y;
                BandStart2 = point1.X + BandSpacing - contourPoints[0].X;
                var point2 = new Point3d(points.Max(p => p.X), points.Max(p => p.Y), 0);
                var vector = point2 - point1;
                BandWidth = (vector.X > vector.Y ? point2.X - point1.X : point2.Y - point1.Y) - BandSpacing * 2;

                RoundParams();
                return;
            }
            if (lines.Length == 3 || lines.Length == 4)
            {
                var vector = lines[0].Delta;
                if (vector.IsParallelTo(Vector3d.XAxis, Tolerance.Global))
                {
                    ProcessingAngle1 = 0;
                }
                if (vector.IsParallelTo(Vector3d.XAxis.RotateBy(Math.PI / 4, Vector3d.ZAxis)))
                {
                    ProcessingAngle1 = 45;
                }
                if (vector.IsParallelTo(Vector3d.YAxis, Tolerance.Global))
                {
                    ProcessingAngle1 = 90;
                }
                if (vector.IsParallelTo(Vector3d.XAxis.RotateBy(Math.PI * 3 / 4, Vector3d.ZAxis)))
                {
                    ProcessingAngle1 = 45;
                }
                if (ProcessingAngle1.HasValue)
                {
                    Type = $"Полосы {ProcessingAngle1}";
                    var point = ProcessingAngle1 == 45 ? contourPoints[3] : contourPoints[0];
                    var dist  = lines.Select(p => p.GetDistToPoint(point)).OrderBy(p => p).ToArray();
                    var s1    = dist[1] - dist[0];
                    var s2    = dist[2] - dist[1];
                    BandWidth   = Math.Max(s1, s2);
                    BandSpacing = Math.Min(s1, s2);
                    BandStart1  = (s1 > s2 ? dist[0] : dist[1]) % (BandWidth + BandSpacing);

                    RoundParams();
                    return;
                }
            }
            Acad.Alert("Тип плитки не распознан");

            void RoundParams()
            {
                BandSpacing = BandSpacing?.Round(3);
                BandWidth   = BandWidth?.Round(3);
                BandStart1  = BandStart1?.Round(3);
                BandStart2  = BandStart2?.Round(3);
            }
        }
コード例 #7
0
        private void bPulling_Click(object sender, EventArgs e)
        {
            if (_isPullingActive)
            {
                return;
            }

            var objectIds = Interaction.GetPickSet();

            if (objectIds.Length == 0)
            {
                Acad.Alert($"Выделите притягиваемые кривые");
                return;
            }
            lPulling.Text = $"Включен режим притягивания {objectIds.Length} объектов";

            Acad.Editor.SetImpliedSelection(Array.Empty <ObjectId>());
            App.LockAndExecute(() => Interaction.HighlightObjects(objectIds));
            Acad.Write($"Выполняется притягивание {objectIds.Length} объектов");
            _isPullingActive = true;

            while (true)
            {
                Interaction.SetActiveDocFocus();
                var sideId = Interaction.GetEntity("\nВыберите притягиваемую сторону", typeof(Line));
                if (sideId == ObjectId.Null)
                {
                    break;
                }

                if (!objectIds.Contains(sideId))
                {
                    Acad.Write($"Притягиваемая сторона должна быть из числа притягиваемых кривых");
                    continue;
                }
                Acad.Editor.SetImpliedSelection(new ObjectId[] { sideId });
                var guideId = Interaction.GetEntity("\nВыберите отрезок к которому выполнить притягивание", typeof(Line));
                if (guideId == ObjectId.Null)
                {
                    break;
                }

                Line guide = guideId.QOpenForRead <Line>();
                Line side  = sideId.QOpenForRead <Line>();

                var isObjLeft = !side.IsTurnRight(objectIds.GetCenter());
                double.TryParse(tbDist.Text, out double dist);
                var normalVector = guide.Delta.GetNormal().GetPerpendicularVector() * dist;

                if (cbMove.Checked)
                {
                    Interaction.SetActiveDocFocus();

                    using (Acad.ActiveDocument.LockDocument())
                    {
                        Interaction.HighlightObjects(new[] { guideId });
                        Acad.Editor.SetImpliedSelection(objectIds);
                        PromptSelectionResult psr = Acad.Editor.SelectImplied();
                        PromptPointResult     ppr = Acad.Editor.Drag(psr.Value, "\nУкажите точку вставки объектов: ",
                                                                     (Point3d pt, ref Matrix3d mtx) =>
                        {
                            mtx = CalcMatrix(pt, guide, side, normalVector, isObjLeft);
                            return(SamplerStatus.OK);
                        });
                        if (ppr.Status == PromptStatus.OK)
                        {
                            var matrix = CalcMatrix(ppr.Value, guide, side, normalVector, isObjLeft);
                            objectIds.QForEach <Entity>(dbobject => dbobject.TransformBy(matrix));
                        }
                        App.LockAndExecute(() => Interaction.UnhighlightObjects(new ObjectId[] { guideId }));
                    }
                }
                else
                {
                    var mt = CalcMatrix(side.StartPoint, guide, side, normalVector, isObjLeft);
                    App.LockAndExecute(() => objectIds.QForEach <Curve>(p => p.TransformBy(mt)));
                }
                Acad.Editor.SetImpliedSelection(Array.Empty <ObjectId>());
                App.LockAndExecute(() => Interaction.HighlightObjects(objectIds));
            }
            Acad.Editor.SetImpliedSelection(Array.Empty <ObjectId>());
            App.LockAndExecute(() => Interaction.UnhighlightObjects(objectIds));
            lPulling.Text = "";
            Acad.Write($"Притягивание завершено");
            _isPullingActive = false;

            Matrix3d CalcMatrix(Point3d point, Line guide, Line side, Vector3d normalVector, bool isObjLeft)
            {
                var isPointLeft    = !guide.IsTurnRight(point);
                var rotAngle       = side.GetVector2d().ZeroTo2PiAngleTo((isObjLeft ^ isPointLeft) ? guide.GetVector2d().Negate() : guide.GetVector2d());
                var rotCenter      = side.StartPoint;
                var rotationMatrix = Matrix3d.Rotation(rotAngle, Vector3d.ZAxis, rotCenter);

                point  = guide.GetClosestPointTo(point, true);
                point += isPointLeft ? normalVector : -normalVector;
                var displacementMatrix = Matrix3d.Displacement(rotCenter.GetVectorTo(point));

                return(displacementMatrix * rotationMatrix);
            }
        }