Ejemplo n.º 1
0
        void CalcToolpath(ProcessObject obj, VertexType vertex)
        {
            if (obj == null)
            {
                return;
            }
            ProcessObject srcObj        = obj.ConnectObject[vertex.Index()];
            VertexType    srcVertex     = obj.ConnectVertex[vertex.Index()];
            SideType      containedSide = vertex != srcVertex ? srcObj.Side : srcObj.Side.Opposite();

            if (obj.IsExactly[vertex.Index()] != srcObj.IsExactly[srcVertex.Index()] || obj.Side != containedSide || (obj.ToolpathCurve == null && obj.ProcessActions == null))
            {
                obj.IsExactly[vertex.Index()] = srcObj.IsExactly[srcVertex.Index()];
                vertex = vertex.Opposite();

                if ((obj.Side != containedSide && obj.ConnectObject[vertex.Index()] != null) || (obj.ToolpathCurve == null && obj.ProcessActions == null))
                {
                    obj.Side = containedSide;
                    obj.IsExactly[vertex.Index()] = CalcExactlyEnd(obj, vertex);
                }
                obj.Side = containedSide;
                ConstructToolpathObject(obj);

                CalcToolpath(obj.ConnectObject[vertex.Index()], obj.ConnectVertex[vertex.Index()]);
            }
        }
Ejemplo n.º 2
0
        double GetOffsetValue(ProcessObject obj)
        {
            bool   hasOffset = false;
            double d         = 0;

            switch (obj.ObjectType)
            {
            case ObjectType.Line:
                hasOffset = ((obj as ProcessObjectLine).AngleRound > 0 && (obj as ProcessObjectLine).AngleRound <= cPI) ^ (obj.Side == SideType.Left);
                break;

            case ObjectType.Arc:
                hasOffset = (obj.ProcessArc.StartAngle >= cPI2 && obj.ProcessArc.StartAngle < cPI + cPI2) ^ (obj.Side == SideType.Right);
                if (obj.Side == SideType.Left)
                {
                    double R = obj.ProcessArc.Radius;
                    d = R - Math.Sqrt(R * R - obj.DepthAll * (obj.Diameter - obj.DepthAll));
                    (obj as ProcessObjectArc).Compensation = d;
                    (obj as ProcessObjectArc).BetaGrad     = Math.Atan2(d, obj.DepthAll) * 180 / Math.PI;
                }
                break;

            case ObjectType.Polyline:
                hasOffset = true;      // TODO GetOffsetValue
                break;
            }
            double sign = obj.Side == SideType.Left ^ obj.ObjectType == ObjectType.Arc ? 1 : -1;

            return(sign * ((hasOffset ? obj.Thickness : 0) + d));
        }
Ejemplo n.º 3
0
 public void DeleteObject(ProcessObject obj)
 {
     // TODO удалить обработчики
     //obj.ProcessCurve.Modified -= ProcessCurveModifiedEventHandler;
     //obj.ProcessCurve.Erased -= ProcessCurveErasedEventHandler;
     if (obj.ToolpathCurve != null || obj.ProcessActions != null)
     {
         using (DocumentLock doclock = Document.LockDocument())
         {
             using (AcDb.Transaction trans = TransactionManager.StartTransaction())
             {
                 if (obj.ToolpathCurve != null)
                 {
                     trans.GetObject(obj.ToolpathCurve.ObjectId, AcDb.OpenMode.ForWrite);
                     obj.ToolpathCurve.Erase();
                 }
                 else
                 {
                     obj.ProcessActions.ForEach(p =>
                     {
                         trans.GetObject(p.Toolpath.ObjectId, AcDb.OpenMode.ForWrite);
                         p.Toolpath.Erase();
                     });
                 }
                 trans.Commit();
                 Editor.UpdateScreen();
             }
         }
     }
     RemoveConnect(obj, VertexType.Start);
     RemoveConnect(obj, VertexType.End);
     ObjectList.Remove(obj);
     ObjectForm.RefreshList();
 }
Ejemplo n.º 4
0
        void ToolpathCurveErasedEventHandlerRavelli(object senderObj, EventArgs evtArgs)
        {
            ProcessObject obj = ObjectList.Find(p => p.ProcessActions.Any(t => t.Toolpath == ((Curve)senderObj)));

            if (obj != null)
            {
                obj.ProcessActions.RemoveAll(t => t.Toolpath == ((Curve)senderObj));
            }
        }
Ejemplo n.º 5
0
        void ToolpathCurveErasedEventHandler(object senderObj, EventArgs evtArgs)
        {
            ProcessObject obj = ObjectList.Find(p => p.ToolpathCurve == senderObj as Curve);

            if (obj != null)
            {
                obj.ToolpathCurve = null;
                obj.Side          = SideType.None;
            }
        }
Ejemplo n.º 6
0
        void ProcessCurveErasedEventHandler(object senderObj, EventArgs evtArgs)
        {
            //Application.ShowAlertDialog("Erased");
            ProcessObject obj = ObjectList.Find(p => p.ProcessCurve == senderObj as Curve);

            if (obj != null)
            {
                DeleteObject(obj);
            }
        }
Ejemplo n.º 7
0
        public void SetProcessSide(ProcessObject obj)
        {
            SideType side = InputProcessSide(obj);

            if (side != SideType.None && side != obj.Side)
            {
                obj.Side = side;
                StartCalcToolpath(obj);
            }
        }
Ejemplo n.º 8
0
 void RemoveConnect(ProcessObject obj, VertexType vertex)
 {
     if (obj.ConnectObject[vertex.Index()] != null)
     {
         ProcessObject connectObject = obj.ConnectObject[vertex.Index()];
         VertexType    connectVertex = obj.ConnectVertex[vertex.Index()];
         connectObject.ConnectObject[connectVertex.Index()] = null;
         connectObject.IsExactly[connectVertex.Index()]     = false;
         ConstructToolpathObject(connectObject);
         obj.ConnectObject[vertex.Index()] = null;
     }
 }
Ejemplo n.º 9
0
        void StartCalcToolpath(ProcessObject obj)
        {
            if (obj.Side != SideType.None)
            {
                obj.IsExactly[VertexType.Start.Index()] = CalcExactlyEnd(obj, VertexType.Start);
                obj.IsExactly[VertexType.End.Index()]   = CalcExactlyEnd(obj, VertexType.End);

                ConstructToolpathObject(obj);

                CalcToolpath(obj.ConnectObject[VertexType.Start.Index()], obj.ConnectVertex[VertexType.Start.Index()]);
                CalcToolpath(obj.ConnectObject[VertexType.End.Index()], obj.ConnectVertex[VertexType.End.Index()]);
            }
        }
Ejemplo n.º 10
0
        SideType InputProcessSide(ProcessObject obj)
        {
            // TODO попытка после нажатия кнопки переключитьсся на окно автокада - не получилось нихуйа

            //EditorUserInteraction edInt = ed.StartUserInteraction(Program.ps as System.Windows.Forms.Control);
            //Program.ps.Visible = false;
            //Program.ed.UpdateScreen();
            //[System.Runtime.InteropServices.DllImport("user32.dll")]
            //static extern int SetActiveWindow(IntPtr hwnd);
            //SetActiveWindow(doc.Window.Handle);

            PromptAngleOptions promptOptions = new PromptAngleOptions("\nВыберите направление внешней нормали к объекту");

            //                AcEd.PromptPointOptions ptOpt = new AcEd.PromptPointOptions("\nВыберите направление внешней нормали к объекту");

            promptOptions.BasePoint     = obj.ProcessCurve.GetPointAtDist(obj.Length / 2);
            promptOptions.UseBasePoint  = true;
            promptOptions.UseDashedLine = true;

            PromptDoubleResult promptResult = Editor.GetAngle(promptOptions);

            //                AcEd.PromptPointResult resPt2 = ed.GetPoint(ptOpt);

            //Program.ps.Visible = true;
            //            edInt.End();
            if (promptResult.Status == PromptStatus.OK)
            {
                double angle = 0;
                switch (obj.ObjectType)
                {
                case ObjectType.Line:
                    angle = obj.ProcessLine.Angle;
                    break;

                case ObjectType.Arc:
                    angle = (obj.ProcessArc.StartAngle + obj.ProcessArc.TotalAngle / 2 + cPI2) % c2PI;
                    break;

                case ObjectType.Polyline:
                    angle = obj.ProcessCurve.GetFirstDerivative(promptOptions.BasePoint).GetAngleTo(Vector3d.XAxis);
                    break;
                }
                return(Math.Sin(promptResult.Value - angle) > 0 ? SideType.Left : SideType.Right);
            }
            else
            {
                return(SideType.None);
            }
        }
Ejemplo n.º 11
0
        public void SetExactlyEnd(ProcessObject obj, VertexType vertex)
        {
            if (obj.Side != SideType.None)
            {
                ConstructToolpathObject(obj);

                if (vertex == VertexType.Start)
                {
                    CalcToolpath(obj.ConnectObject[VertexType.Start.Index()], obj.ConnectVertex[VertexType.Start.Index()]);
                }
                else
                {
                    CalcToolpath(obj.ConnectObject[VertexType.End.Index()], obj.ConnectVertex[VertexType.End.Index()]);
                }
            }
        }
Ejemplo n.º 12
0
        double GetOffsetValueRavelli(ProcessObject obj)
        {
            bool   hasOffset = obj.TopEdge;
            double d         = 0;

            if (obj.ObjectType == ObjectType.Arc && obj.Side == SideType.Left)
            {
                obj.TopEdge = true;
                hasOffset   = true;
                double R = obj.ProcessArc.Radius;
                d = R - Math.Sqrt(R * R - obj.DepthAll * (obj.Diameter - obj.DepthAll));
                (obj as ProcessObjectArc).Compensation = d;
                obj.VerticalAngleDeg = Math.Atan2(d, obj.DepthAll) * 180 / Math.PI;
            }
            double sign = obj.Side == SideType.Left ^ obj.ObjectType == ObjectType.Arc ? 1 : -1;

            return(sign * ((hasOffset ? (obj.Thickness / Math.Cos(obj.VerticalAngle)) : 0) + d));
        }
Ejemplo n.º 13
0
        void SetConnect(ProcessObject obj, VertexType vertex)
        {
            RemoveConnect(obj, vertex);
            Point3d point = vertex == VertexType.Start ? obj.ProcessCurve.StartPoint : obj.ProcessCurve.EndPoint;
            List <ProcessObject> connectList = ObjectList.FindAll(p => p != obj && (p.ProcessCurve.StartPoint == point || p.ProcessCurve.EndPoint == point));

            if (connectList.Count == 1)  // TODO поиск первого
            {
                ProcessObject connectObject = connectList[0];
                VertexType    connectVertex = point == connectObject.ProcessCurve.StartPoint ? VertexType.Start : VertexType.End;
                obj.ConnectObject[vertex.Index()] = connectObject;
                obj.ConnectVertex[vertex.Index()] = connectVertex;
                connectObject.ConnectObject[connectVertex.Index()] = obj;
                connectObject.ConnectVertex[connectVertex.Index()] = vertex;
                if (connectObject.Side != SideType.None)
                {
                    obj.Side = vertex != connectVertex ? connectObject.Side : connectObject.Side.Opposite();
                }
            }
        }
Ejemplo n.º 14
0
        void ProcessCurveModifiedEventHandler(object senderObj, EventArgs evtArgs)  // TODO изменение для дуг
        {
            Curve         curve = senderObj as Curve;
            ProcessObject obj   = ObjectList.Find(p => p.ProcessCurve == curve);

            if (obj != null &&
                (
                    (float)curve.StartPoint.X != obj.StartPoint.X || (float)curve.StartPoint.Y != obj.StartPoint.Y ||
                    (float)curve.EndPoint.X != obj.EndPoint.X || (float)curve.EndPoint.Y != obj.EndPoint.Y))
            {
                if ((float)curve.StartPoint.X != obj.StartPoint.X || (float)curve.StartPoint.Y != obj.StartPoint.Y)
                {
                    SetConnect(obj, VertexType.Start);
                }
                if ((float)curve.EndPoint.X != obj.EndPoint.X || (float)curve.EndPoint.Y != obj.EndPoint.Y)
                {
                    SetConnect(obj, VertexType.End);
                }
                obj.RefreshProcessCurveData();
                StartCalcToolpath(obj);
                ObjectForm.RefreshProperty();
                //Application.ShowAlertDialog("Modified");
            }
        }
Ejemplo n.º 15
0
 public void addProcess(ProcessObject processObject)
 {
     m_processList.Add(processObject);
     fmObject.AddItem(processObject.ToString());
 }
Ejemplo n.º 16
0
        private void Намечание(ProcessObject obj, double s)
        {
            if (!(obj is ProcessObjectLine))
            {
                return;
            }
            double  h;
            Point3d pointC;

            if (obj.IsBeginExactly && obj.IsEndExactly)
            {
                var l = obj.Length - 2 * ExactlyIncrease;
                h      = (obj.Diameter - Math.Sqrt(obj.Diameter * obj.Diameter - l * l)) / 2;
                pointC = obj.ProcessCurve.GetPointAtParameter(obj.ProcessCurve.EndParam / 2);
            }
            else
            {
                h      = obj.DepthAll;
                pointC = obj.ProcessCurve.StartPoint + obj.ProcessCurve.GetFirstDerivative(0).GetNormal() * (obj.IsBeginExactly ? s : obj.Length - s);
            }

            using (DocumentLock doclock = Document.LockDocument())
            {
                using (AcDb.Transaction trans = TransactionManager.StartTransaction())
                {
                    BlockTable       BlkTbl    = trans.GetObject(Database.BlockTableId, OpenMode.ForRead, false) as BlockTable;
                    BlockTableRecord BlkTblRec = trans.GetObject(BlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false) as BlockTableRecord;
                    if (obj.ProcessActions != null)
                    {
                        obj.ProcessActions.ForEach(p => trans.GetObject(p.Toolpath.ObjectId, OpenMode.ForWrite).Erase());
                    }

                    obj.ProcessActions = new List <ProcessAction>();
                    var layerId = GetProcessLayer(trans);

                    var point0 = new Point3d(pointC.X, pointC.Y, ProcessOptions.ZSafety);
                    var point1 = new Point3d(pointC.X, pointC.Y, -h);

                    obj.ProcessActions.Add(new ProcessAction
                    {
                        Command  = "Заглубление",
                        Toolpath = new Line(point0, point1),
                        Point    = point1
                    });
                    obj.ProcessActions.Add(new ProcessAction
                    {
                        Command  = "Подъем",
                        Toolpath = new Line(point1, point0),
                        Point    = point0
                    });

                    obj.ProcessActions.ForEach(p =>
                    {
                        p.Toolpath.LayerId = layerId;
                        BlkTblRec.AppendEntity(p.Toolpath);
                        trans.AddNewlyCreatedDBObject(p.Toolpath, true);
                        p.Toolpath.Erased += new ObjectErasedEventHandler(ToolpathCurveErasedEventHandlerRavelli);
                    });
                    trans.Commit();
                    Editor.UpdateScreen();
                }
            }
        }
Ejemplo n.º 17
0
        double CalcAngle(ProcessObject obj, double angle)
        {
            var angleDeg = angle * 180 / Math.PI;

            return(obj.TopEdge ^ obj.Side == SideType.Right ? (450 - angleDeg) % 360 : (630 - angleDeg) % 360);
        }
Ejemplo n.º 18
0
 public void SelectObject(ProcessObject obj)
 {
     Editor.SetImpliedSelection(new ObjectId[] { obj.ProcessCurve.ObjectId });
     Editor.UpdateScreen();
 }
Ejemplo n.º 19
0
        public void ConstructToolpathObject(ProcessObject obj)
        {
            if (obj.Side == SideType.None)
            {
                return;
            }
            if (ProcessOptions.Machine == ProcessOptions.TTypeMachine.Ravelli)
            {
                ConstructToolpathObjectRavelli(obj);
                return;
            }
            if (obj.ObjectType == ObjectType.Arc && (
                    (obj.ProcessArc.StartAngle < cPI2 && obj.ProcessArc.EndAngle > cPI2) ||
                    (obj.ProcessArc.StartAngle < cPI + cPI2 && (obj.ProcessArc.EndAngle > cPI + cPI2 || obj.ProcessArc.EndAngle < obj.ProcessArc.StartAngle))))
            {
                Application.ShowAlertDialog("Обработка дуги невозможна - дуга пересекает угол 90 или 270 градусов. Текущие углы: начальный " +
                                            (180 / cPI * obj.ProcessArc.StartAngle).ToString() + ", конечный " + (180 / cPI * obj.ProcessArc.EndAngle).ToString());
                //Application.ShowAlertDialog($"Обработка дуги {obj} невозможна - дуга пересекает угол 90 или 270 градусов. Текущие углы: начальный {180 / cPI * obj.ProcessArc.StartAngle}, конечный {180 / cPI * obj.ProcessArc.EndAngle}");
                return;
            }
            double s = Math.Sqrt(obj.DepthAll * (obj.Diameter - obj.DepthAll)) + ExactlyIncrease;

            if ((obj.IsBeginExactly || obj.IsEndExactly) && (obj.Length <= s))
            {
                Application.ShowAlertDialog("Обработка объекта " + obj.ToString() + " невозможна вследствие слишком малой длины");
                return;
            }
            Curve toolpathCurve = obj.ProcessCurve.GetOffsetCurves(GetOffsetValue(obj))[0] as Curve;  // TODO расчет OffsetCurves + ModifiedEventHandler

            switch (obj.ObjectType)
            {
            case ObjectType.Line:

                if (obj.IsBeginExactly)
                {
                    toolpathCurve.StartPoint = toolpathCurve.GetPointAtDist(s);
                }
                if (obj.IsEndExactly)
                {
                    toolpathCurve.EndPoint = toolpathCurve.GetPointAtDist((toolpathCurve as Line).Length - s);
                }
                break;

            case ObjectType.Arc:

                if (obj.IsBeginExactly)
                {
                    (toolpathCurve as Arc).StartAngle = obj.ProcessArc.StartAngle + s / obj.ProcessArc.Radius;
                }
                if (obj.IsEndExactly)
                {
                    (toolpathCurve as Arc).EndAngle = obj.ProcessArc.EndAngle - s / obj.ProcessArc.Radius;
                }
                break;
            }
            using (DocumentLock doclock = Document.LockDocument())
            {
                using (AcDb.Transaction trans = TransactionManager.StartTransaction())
                {
                    if (obj.ToolpathCurve == null)  // TODO удаление объекта
                    {
                        BlockTable       BlkTbl    = trans.GetObject(Database.BlockTableId, OpenMode.ForRead, false) as BlockTable;
                        BlockTableRecord BlkTblRec = trans.GetObject(BlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false) as BlockTableRecord;

                        toolpathCurve.LayerId = GetProcessLayer(trans);
                        BlkTblRec.AppendEntity(toolpathCurve);
                        trans.AddNewlyCreatedDBObject(toolpathCurve, true);
                        toolpathCurve.Erased += new ObjectErasedEventHandler(ToolpathCurveErasedEventHandler);
                        obj.ToolpathCurve     = toolpathCurve;
                    }
                    else
                    {
                        trans.GetObject(obj.ToolpathCurve.ObjectId, AcDb.OpenMode.ForWrite);
                        switch (obj.ObjectType)
                        {                                   // TODO копия объекта
                        case ObjectType.Line:
                            obj.ToolpathCurve.StartPoint = toolpathCurve.StartPoint;
                            obj.ToolpathCurve.EndPoint   = toolpathCurve.EndPoint;
                            break;

                        case ObjectType.Arc:
                            (obj.ToolpathCurve as Arc).Center     = (toolpathCurve as Arc).Center;
                            (obj.ToolpathCurve as Arc).Radius     = (toolpathCurve as Arc).Radius;
                            (obj.ToolpathCurve as Arc).StartAngle = (toolpathCurve as Arc).StartAngle;
                            (obj.ToolpathCurve as Arc).EndAngle   = (toolpathCurve as Arc).EndAngle;
                            break;
                        }
                    }
                    trans.Commit();
                    Editor.UpdateScreen();
                }
            }
        }
Ejemplo n.º 20
0
        bool CalcExactlyEnd(ProcessObject obj, VertexType vertex)
        {
            ProcessObject connectObject = obj.ConnectObject[vertex.Index()];
            VertexType    connectVertex = obj.ConnectVertex[vertex.Index()];
            bool          isLeftTurn, isLeftProcessSide, isNextStartPoint;
            double        angle;
            bool          isExactly = false;

            if (connectObject != null)
            {
                switch (obj.ObjectType)
                {
                case ObjectType.Line:
                    switch (connectObject.ObjectType)
                    {
                    case ObjectType.Line:

                        angle = connectObject.ProcessLine.Angle - obj.ProcessLine.Angle;
                        if (Math.Abs(angle) > AngleTolerance)
                        {
                            isLeftTurn        = Math.Sin(angle) > 0;
                            isLeftProcessSide = obj.Side == SideType.Left;
                            isNextStartPoint  = connectVertex == VertexType.Start;
                            //bool isSameDirection = point == obj.ProcessEndPoint ? nextObj.ProcessStartPoint == point : nextObj.ProcessEndPoint == point;
                            //bool isNextPosDir = point == obj.ProcessEndPoint;
                            isExactly = isLeftTurn ^ isLeftProcessSide ^ isNextStartPoint;
                        }
                        break;

                    case ObjectType.Arc:

                        double angleTan = connectVertex == VertexType.Start ? connectObject.ProcessArc.StartAngle + cPI2 : connectObject.ProcessArc.EndAngle - cPI2;
                        angle = angleTan - obj.ProcessLine.Angle;
                        if (Math.Abs(angle) > AngleTolerance)
                        {
                            isLeftTurn = Math.Sin(angle) > 0;
                        }
                        else
                        {
                            isLeftTurn = connectVertex == VertexType.Start;
                        }
                        bool isRightProcessSide = obj.Side == SideType.Right;
                        isExactly = isLeftTurn ^ isRightProcessSide;
                        break;

                    case ObjectType.Polyline:           // TODO концы полилиний
                        break;
                    }
                    break;

                case ObjectType.Arc:       // TODO концы дуг
                    if (connectObject.ObjectType == ObjectType.Line)
                    {
                        connectObject.Side = vertex != connectVertex ? obj.Side : obj.Side.Opposite();
                        isExactly          = CalcExactlyEnd(connectObject, connectVertex);
                    }
                    break;

                case ObjectType.Polyline:       // TODO концы полилиний
                    break;
                }
            }
            return(isExactly);
        }
Ejemplo n.º 21
0
        public void ConstructToolpathObjectRavelli(ProcessObject obj)
        {
            if (obj.Side == SideType.None)
            {
                return;
            }
            if (obj.VerticalAngleDeg == 90)
            {
                ConstructPlaneToolpath(obj);
                return;
            }
            double s = Math.Sqrt(obj.DepthAll * (obj.Diameter - obj.DepthAll / Math.Cos(obj.VerticalAngle))) + ExactlyIncrease;

            if ((obj.IsBeginExactly || obj.IsEndExactly) && (obj.Length <= s) || (obj.IsBeginExactly && obj.IsEndExactly) && (obj.Length <= 2 * s))
            {
                Намечание(obj, s);
                return;
            }
            Curve toolpathCurve = GetOffsetCopy(obj.ProcessCurve, GetOffsetValueRavelli(obj));  // TODO расчет OffsetCurves + ModifiedEventHandler

            switch (obj.ObjectType)
            {
            case ObjectType.Line:

                if (obj.IsBeginExactly)
                {
                    toolpathCurve.StartPoint = toolpathCurve.GetPointAtDist(s);
                }
                if (obj.IsEndExactly)
                {
                    toolpathCurve.EndPoint = toolpathCurve.GetPointAtDist((toolpathCurve as Line).Length - s);
                }
                break;

            case ObjectType.Arc:

                if (obj.IsBeginExactly)
                {
                    (toolpathCurve as Arc).StartAngle = obj.ProcessArc.StartAngle + s / obj.ProcessArc.Radius;
                }
                if (obj.IsEndExactly)
                {
                    (toolpathCurve as Arc).EndAngle = obj.ProcessArc.EndAngle - s / obj.ProcessArc.Radius;
                }
                break;
            }
            using (DocumentLock doclock = Document.LockDocument())
            {
                using (AcDb.Transaction trans = TransactionManager.StartTransaction())
                {
                    BlockTable       BlkTbl    = trans.GetObject(Database.BlockTableId, OpenMode.ForRead, false) as BlockTable;
                    BlockTableRecord BlkTblRec = trans.GetObject(BlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false) as BlockTableRecord;
                    if (obj.ProcessActions != null)
                    {
                        obj.ProcessActions.ForEach(p => trans.GetObject(p.Toolpath.ObjectId, OpenMode.ForWrite).Erase());
                    }

                    obj.ProcessActions = new List <ProcessAction>();
                    var layerId  = GetProcessLayer(trans);
                    var tanAngle = Math.Tan(obj.VerticalAngle);

                    double angleStart = 0;
                    double angleEnd   = 0;
                    if (obj.ObjectType == ObjectType.Arc)
                    {
                        angleStart = CalcAngle(obj, (toolpathCurve as Arc).StartAngle);
                        angleEnd   = CalcAngle(obj, (toolpathCurve as Arc).EndAngle);
                    }
                    if (!obj.TopEdge)
                    {
                        s = (ProcessOptions.Thickness + ProcessOptions.ZSafety) * tanAngle;
                        var     sign    = obj.Side == SideType.Left ^ obj.ObjectType == ObjectType.Arc ? -1 : 1;
                        var     tCurve0 = GetDisplacementCopy(GetOffsetCopy(toolpathCurve, sign * s), ProcessOptions.ZSafety);
                        var     isStart = true;
                        var     point0  = tCurve0.StartPoint;
                        Point3d point;
                        int     d = 0;
                        if (obj.ObjectType == ObjectType.Arc)
                        {
                            d = -obj.Depth;
                        }

                        do
                        {
                            d += obj.Depth;
                            if (d > obj.DepthAll)
                            {
                                d = obj.DepthAll;
                            }
                            s = (ProcessOptions.Thickness - d) * tanAngle;
                            var tCurve = GetDisplacementCopy(GetOffsetCopy(toolpathCurve, sign * s), -d);
                            point = isStart ? tCurve.StartPoint : tCurve.EndPoint;
                            obj.ProcessActions.Add(new ProcessAction
                            {
                                Command     = "Заглубление",
                                Toolpath    = new Line(point0, point),
                                Point       = point,
                                Angle       = isStart ? angleStart : angleEnd,
                                IsClockwise = isStart
                            });
                            isStart = !isStart;
                            point0  = isStart ? tCurve.StartPoint : tCurve.EndPoint;
                            obj.ProcessActions.Add(new ProcessAction
                            {
                                Command     = "Рез",
                                Toolpath    = tCurve,
                                Point       = point0,
                                Angle       = isStart ? angleStart : angleEnd,
                                IsClockwise = isStart
                            });
                        }while (d < obj.DepthAll);
                        point = isStart ? tCurve0.StartPoint : tCurve0.EndPoint;
                        obj.ProcessActions.Add(new ProcessAction
                        {
                            Command     = "Подъем",
                            Toolpath    = new Line(point0, point),
                            Point       = point,
                            Angle       = isStart ? angleStart : angleEnd,
                            IsClockwise = isStart
                        });
                    }
                    else
                    {
                        s = ProcessOptions.ZSafety * tanAngle;
                        var     sign    = obj.Side == SideType.Left ^ obj.ObjectType == ObjectType.Arc ? -1 : 1;
                        var     tCurve0 = GetDisplacementCopy(GetOffsetCopy(toolpathCurve, sign * (-s)), ProcessOptions.ZSafety);
                        var     isStart = true;
                        var     point0  = tCurve0.StartPoint;
                        Point3d point;
                        int     d = 0;
                        if (obj.ObjectType == ObjectType.Arc)
                        {
                            d = -obj.Depth;
                        }
                        do
                        {
                            d += obj.Depth;
                            if (d > obj.DepthAll)
                            {
                                d = obj.DepthAll;
                            }
                            s = d * tanAngle;
                            var tCurve = GetDisplacementCopy(GetOffsetCopy(toolpathCurve, sign * s), -d);
                            point = isStart ? tCurve.StartPoint : tCurve.EndPoint;
                            obj.ProcessActions.Add(new ProcessAction
                            {
                                Command     = "Заглубление",
                                Toolpath    = new Line(point0, point),
                                Point       = point,
                                Angle       = isStart ? angleStart : angleEnd,
                                IsClockwise = isStart
                            });
                            isStart = !isStart;
                            point0  = isStart ? tCurve.StartPoint : tCurve.EndPoint;
                            obj.ProcessActions.Add(new ProcessAction
                            {
                                Command     = "Рез",
                                Toolpath    = tCurve,
                                Point       = point0,
                                Angle       = isStart ? angleStart : angleEnd,
                                IsClockwise = isStart
                            });
                        }while (d < obj.DepthAll);
                        point = isStart ? tCurve0.StartPoint : tCurve0.EndPoint;
                        obj.ProcessActions.Add(new ProcessAction
                        {
                            Command     = "Подъем",
                            Toolpath    = new Line(point0, point),
                            Point       = point,
                            Angle       = isStart ? angleStart : angleEnd,
                            IsClockwise = isStart
                        });
                    }

                    obj.ProcessActions.ForEach(p =>
                    {
                        p.Toolpath.LayerId = layerId;
                        BlkTblRec.AppendEntity(p.Toolpath);
                        trans.AddNewlyCreatedDBObject(p.Toolpath, true);
                        p.Toolpath.Erased += new ObjectErasedEventHandler(ToolpathCurveErasedEventHandlerRavelli);
                    });
                    trans.Commit();
                    Editor.UpdateScreen();
                }
            }
        }
Ejemplo n.º 22
0
        private void ConstructPlaneToolpath(ProcessObject obj)
        {
            using (DocumentLock doclock = Document.LockDocument())
            {
                using (AcDb.Transaction trans = TransactionManager.StartTransaction())
                {
                    BlockTable       BlkTbl    = trans.GetObject(Database.BlockTableId, OpenMode.ForRead, false) as BlockTable;
                    BlockTableRecord BlkTblRec = trans.GetObject(BlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false) as BlockTableRecord;
                    if (obj.ProcessActions != null)
                    {
                        obj.ProcessActions.ForEach(p => trans.GetObject(p.Toolpath.ObjectId, OpenMode.ForWrite).Erase());
                    }

                    obj.ProcessActions = new List <ProcessAction>();
                    var layerId  = GetProcessLayer(trans);
                    var tanAngle = Math.Tan(obj.VerticalAngle);

                    double angleStart = 0;
                    double angleEnd   = 0;
                    if (obj.ObjectType == ObjectType.Arc)
                    {
                        angleStart = CalcAngle(obj, (obj.ProcessCurve as Arc).StartAngle);
                        angleEnd   = CalcAngle(obj, (obj.ProcessCurve as Arc).EndAngle);
                    }
                    var sign     = obj.Side == SideType.Left ^ obj.ObjectType == ObjectType.Arc ? -1 : 1;
                    var tCurve0  = GetDisplacementCopy(obj.ProcessCurve, -ProcessOptions.Thickness);
                    var tCurve   = GetOffsetCopy(tCurve0, -sign * obj.Depth);
                    var tCurve01 = tCurve;
                    var isStart  = true;
                    var point    = tCurve.StartPoint;
                    obj.ProcessActions.Add(new ProcessAction
                    {
                        Command  = "Опускание",
                        Toolpath = new Line(new Point3d(point.X, point.Y, ProcessOptions.ZSafety), point),
                        Point    = point,
                        Angle    = isStart ? angleStart : angleEnd,
                    });
                    var point0 = point;
                    var d      = 0;
                    do
                    {
                        d += obj.Depth;
                        if (d > obj.DepthAll)
                        {
                            d = obj.DepthAll;
                        }
                        tCurve = GetOffsetCopy(tCurve0, sign * d);
                        point  = isStart ? tCurve.StartPoint : tCurve.EndPoint;
                        obj.ProcessActions.Add(new ProcessAction
                        {
                            Command  = "Заглубление",
                            Toolpath = new Line(point0, point),
                            Point    = point,
                            Angle    = isStart ? angleStart : angleEnd
                        });
                        isStart = !isStart;
                        point0  = isStart ? tCurve.StartPoint : tCurve.EndPoint;
                        obj.ProcessActions.Add(new ProcessAction
                        {
                            Command     = "Рез",
                            Toolpath    = tCurve,
                            Point       = point0,
                            Angle       = isStart ? angleStart : angleEnd,
                            IsClockwise = isStart
                        });
                    }while (d < obj.DepthAll);
                    point = isStart ? tCurve01.StartPoint : tCurve01.EndPoint;
                    obj.ProcessActions.Add(new ProcessAction
                    {
                        Command  = "Отвод",
                        Toolpath = new Line(point0, point),
                        Point    = point,
                        Angle    = isStart ? angleStart : angleEnd
                    });
                    obj.ProcessActions.Add(new ProcessAction
                    {
                        Command  = "Подъем",
                        Toolpath = new Line(point, new Point3d(point.X, point.Y, ProcessOptions.ZSafety)),
                        Point    = new Point3d(point.X, point.Y, ProcessOptions.ZSafety),
                        Angle    = isStart ? angleStart : angleEnd
                    });

                    obj.ProcessActions.ForEach(p =>
                    {
                        p.Toolpath.LayerId = layerId;
                        BlkTblRec.AppendEntity(p.Toolpath);
                        trans.AddNewlyCreatedDBObject(p.Toolpath, true);
                        p.Toolpath.Erased += new ObjectErasedEventHandler(ToolpathCurveErasedEventHandlerRavelli);
                    });
                    trans.Commit();
                    Editor.UpdateScreen();
                }
            }
        }
Ejemplo n.º 23
0
        void AddSelectedObject(ProcessOptions processOptions)
        {
            List <ProcessObject> addList = new List <ProcessObject>();

            using (Transaction acTrans = TransactionManager.StartTransaction())
            {
                PromptSelectionResult sel = Editor.SelectPrevious(); //SelectImplied(); //
                if (sel.Status == PromptStatus.OK)
                {
                    foreach (ObjectId objId in sel.Value.GetObjectIds())
                    {
                        if (!ObjectList.Exists(p => p.ProcessCurve.ObjectId == objId))
                        {
                            DBObject obj = acTrans.GetObject(objId, OpenMode.ForRead);
                            if ((((Entity)obj).Layer != "Обработка") && (((obj is Line) || (obj is Arc) || (obj is Polyline))))
                            {
                                obj.Modified += new EventHandler(ProcessCurveModifiedEventHandler);
                                obj.Erased   += new ObjectErasedEventHandler(ProcessCurveErasedEventHandler);
                                ProcessObject processObject = null;
                                if (obj is Line)
                                {
                                    processObject = new ProcessObjectLine(obj as Curve, processOptions);
                                }
                                if (obj is Arc)
                                {
                                    processObject = new ProcessObjectArc(obj as Curve, processOptions);
                                }
                                if (obj is Polyline)
                                {
                                    processObject = new ProcessObjectPolyline(obj as Curve, processOptions);
                                }
                                ObjectList.Add(processObject);
                                addList.Add(processObject);
                                if (processObject.ConnectObject[VertexType.Start.Index()] == null)
                                {
                                    SetConnect(processObject, VertexType.Start);
                                }
                                if (processObject.ConnectObject[VertexType.End.Index()] == null)
                                {
                                    SetConnect(processObject, VertexType.End);
                                }
                            }
                        }
                    }
                }
                else
                {
                    Editor.WriteMessage("Объекты для добавления не найдены");
                }
            }
            if (addList.Count > 0)
            {
                do
                {
                    var findObj = addList.Find(p => p.Side != SideType.None);
                    if (findObj != null)
                    {
                        StartCalcToolpath(findObj);
                    }
                    else
                    {
                        SetProcessSide(addList[0]);
                    }
                }while (addList.RemoveAll(p => p.ToolpathCurve != null || p.ProcessActions != null) > 0 && addList.Count > 0);
            }
        }