Пример #1
0
        public static ObjectId CreateToolCurve(double x, double y, double?height)
        {
            Polyline pline = new Polyline();

            pline.AddVertexAt(0, new Point2d(x, y), 0, 0, 0);
            pline.AddVertexAt(0, new Point2d(x, y - height.GetValueOrDefault()), 0.5, 0, 0);
            pline.AddVertexAt(0, new Point2d(50 + x, y - height.GetValueOrDefault()), 0, 0, 0);
            pline.AddVertexAt(0, new Point2d(50 + x, y), 0.5, 0, 0);
            pline.Closed = true;

            return(AutocadUtils.AddCurve(pline, ActionType.Direction));
        }
Пример #2
0
        private void ChangePosition(ActionType actionType, string param = null, double?x = null, double?y = null, double?z = null, int?speed = null)
        {
            var action      = CreateProcessAction(actionType, param, speed: speed);
            var oldPosition = _position;

            _position = new Point3d(x ?? _position.X, y ?? _position.Y, z ?? _position.Z);
            var line = new Line(oldPosition, _position);

            action.ObjectId       = AutocadUtils.AddCurve(line, actionType);
            action.DirectObjectId = SetDirectLine(line, x == null && y == null);
            SetCoordinates(action, oldPosition, _position);
        }
Пример #3
0
        /// <summary>
        /// Установить стрелку направления обработки
        /// </summary>
        /// <param name="curve">Траектория обработки</param>
        /// <param name="isVertical">Вертикальная прямая</param>
        private ObjectId SetDirectLine(Curve curve, bool isVertical = false)
        {
            var curveLength = curve.GetLength();

            if (curveLength < 10)
            {
                return(ObjectId.Null);
            }
            var dist = Math.Min(50, curveLength / 2);

            if (_position == curve.StartPoint)
            {
                dist = curveLength - dist;
            }
            var points = new Point3dCollection {
                curve.GetPointAtDist(dist)
            };
            var arrowLength = Math.Min(10, curveLength / 3);
            var vector      = curve.GetFirstDerivative(points[0]).GetNormal() * arrowLength;

            if (_position == curve.EndPoint)
            {
                vector = vector.Negate();
            }
            var          sidn  = _compensation == CompensationSide.Left ? -1 : 1;
            const double angle = 0.4;
            var          axis  = isVertical ? Vector3d.YAxis : Vector3d.ZAxis;

            points.Add(points[0] + vector.RotateBy(angle * sidn, axis));
            points.Add(_compensation == CompensationSide.None
                    ? points[0] + vector.RotateBy(-angle * sidn, axis)
                    : curve.GetClosestPointTo(points[1], false));
            var directCurve = new Polyline3d(Poly3dType.SimplePoly, points, true);

            return(AutocadUtils.AddCurve(directCurve, ActionType.Direction));
        }
Пример #4
0
        /// <summary>
        /// Движение инструмента по траектории
        /// </summary>
        /// <param name="actionType">Тип действия</param>
        /// <param name="path">Траектория</param>
        private ProcessingAction PathMovement(ActionType actionType, Curve path, int?speed = null)
        {
            if (path == null)
            {
                return(null);
            }

            var oldPosition = _position;

            if ((_position == path.StartPoint) || (Math.Abs(_position.X - path.StartPoint.X) < CalcUtils.Tolerance) && (Math.Abs(_position.Y - path.StartPoint.Y) < CalcUtils.Tolerance))
            {
                _position = path.EndPoint;
            }
            else if ((_position == path.EndPoint) || (Math.Abs(_position.X - path.EndPoint.X) < CalcUtils.Tolerance) && (Math.Abs(_position.Y - path.EndPoint.Y) < CalcUtils.Tolerance))
            {
                _position = path.StartPoint;
            }
            else
            {
                AutocadUtils.ShowError("Ошибка: не соответствие позиции при расчете траектории");
                return(null);
            }

            var action = CreateProcessAction(actionType, speed: speed);

            action.ObjectId       = path.ObjectId != ObjectId.Null ? path.ObjectId : AutocadUtils.AddCurve(path, actionType);
            action.DirectObjectId = SetDirectLine(path);
            SetCoordinates(action, oldPosition, _position, path is Arc);

            if (path is Line)
            {
                action.ToolpathCurveType = ToolpathCurveType.Line;
            }
            if (path is Arc)
            {
                var arc = path as Arc;
                action.ToolpathCurveType = (_position == arc.StartPoint
                                                              ? ToolpathCurveType.ArcClockwise
                                                              : ToolpathCurveType.ArcCounterclockwise);
                if (action.ToolpathCurveType == ToolpathCurveType.ArcClockwise ^ _compensation == CompensationSide.Left) // инструмент внутри дуги
                {
                    if (arc.Radius <= _tool.Diameter / 2)
                    {
                        action.Note    = "Радиус дуги меньше или равен радиусу инструмента";
                        action.IsError = true;
                        var message = String.Format("Строка {0}: {1}", action.No, action.Note);
                        AutocadUtils.ShowError(message);
                    }
                    if (arc.Radius <= 1.5 * _tool.Diameter)
                    {
                        action.Speed    = 200;
                        _isSpeedChanged = true;
                    }
                }
                action.I = Round(arc.Center.X);
                action.J = Round(arc.Center.Y);
                var vector = oldPosition.GetVectorTo(arc.Center);
                action.Irel = Round(vector.X);
                action.Jrel = Round(vector.Y);
            }
            action.Param = action.ToolpathCurveType.ToString();

            return(action);
        }