Exemplo 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()]);
            }
        }
Exemplo n.º 2
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;
     }
 }
Exemplo n.º 3
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();
                }
            }
        }
Exemplo n.º 4
0
        public void ProgramGenerate()
        {
            ProgramLine.Reset();
            ProgramList.Clear();

            if (ProcessOptions.Machine == ProcessOptions.TTypeMachine.Denver)
            {
                AddGCommand(98);
                AddMCommand(97, 2, 1);
                AddGCommand(17, "XYCZ");
                AddGCommand(28, "XYCZ");
                AddMCommand(97, 6, ObjectList[0].ToolNo);
            }
            else
            {
                AddCommand("G54G17G90G642");
                AddCommand("G0G90G153D0Z0");

                AddCommand("T18");
                AddCommand("M6");
                AddCommand("D6");
                AddCommand("TRAORI");
                AddCommand("G54");
            }
            VertexType vertex = VertexType.Start;
            //int ind = 0;
            int z = 0;

            double[] angle = new double[2];
            int[]    type  = { 2, 3 };

            foreach (ProcessObject obj in ObjectList)
            {
                if (obj.ToolpathCurve == null)
                {
                    Application.ShowAlertDialog("Не указана сторона обработки объекта " + obj.ToString());
                    continue;
                }
                Point3d[] point = { obj.ToolpathCurve.StartPoint, obj.ToolpathCurve.EndPoint };
                //int rest = (int)Math.Ceiling((double)obj.DepthAll / obj.Depth) % 2;
                bool hasRest = (int)Math.Ceiling((double)obj.DepthAll / obj.Depth) % 2 == 1;

                switch (obj.ObjectType)
                {
                case ObjectType.Line:
                    //ind = (obj.ToolpathLine.Angle > 0 && obj.ToolpathLine.Angle <= Math.PI) ? 1 - rest : rest;
                    var processObjectLine = obj as ProcessObjectLine;
                    vertex   = (processObjectLine.AngleRound > 0 && processObjectLine.AngleRound <= Math.PI) ^ hasRest ? VertexType.End : VertexType.Start;
                    angle[0] = angle[1] = processObjectLine.ToolpathAngle;
                    z        = 0;
                    break;

                case ObjectType.Arc:
                    //ind = (obj.ToolpathArc.StartAngle >= Math.PI * 0.5 && obj.ToolpathArc.StartAngle < Math.PI * 1.5) ? 1 - rest : rest;
                    bool isLeftArc = obj.ToolpathArc.StartAngle >= Math.PI * 0.5 && obj.ToolpathArc.StartAngle < Math.PI * 1.5;
                    vertex = isLeftArc ^ hasRest ? VertexType.End : VertexType.Start;
                    if (isLeftArc)
                    {
                        angle[VertexType.Start.Index()] = (Math.PI * 1.5 - obj.ToolpathArc.StartAngle) * 180 / Math.PI;
                        angle[VertexType.End.Index()]   = (Math.PI * 1.5 - obj.ToolpathArc.EndAngle) * 180 / Math.PI;
                    }
                    else
                    {
                        angle[VertexType.Start.Index()] = ((Math.PI * 2.5 - obj.ToolpathArc.StartAngle) % (2 * Math.PI)) * 180 / Math.PI;
                        angle[VertexType.End.Index()]   = ((Math.PI * 2.5 - obj.ToolpathArc.EndAngle) % (2 * Math.PI)) * 180 / Math.PI;
                    }
                    z = -obj.Depth;
                    break;
                }
                if (ProcessOptions.Machine == ProcessOptions.TTypeMachine.Denver)
                {
                    //                ProgramList.Add(new ProgramLine(0, 0, "XYC", 0, point[vertex.Index()].X, point[vertex.Index()].Y, angle[vertex.Index()]));
                    AddSetToolCommand("XYC", point[vertex.Index()].X, point[vertex.Index()].Y, angle[vertex.Index()], obj.ToString());
                    //                ProgramList.Add(new ProgramLine(0, 0, "XYZ", 0, point[vertex.Index()].X, point[vertex.Index()].Y, 20));
                    AddSetToolCommand("XYZ", point[vertex.Index()].X, point[vertex.Index()].Y, ProcessOptions.ZSafety, obj.ToString());
                }
                else
                {
                    AddCommand("G0" + ToGCode("X", point[vertex.Index()].X)
                               + ToGCode("Y", point[vertex.Index()].Y)
                               + CToGCode(angle[vertex.Index()])
                               + " B-90");
                    AddCommand("G0" + ZToGCode(20));
                }
                if (ProcessOptions.Machine == ProcessOptions.TTypeMachine.Denver)
                {
                    if (obj == ObjectList.First())
                    {
                        AddMCommand(97, 7);
                        AddMCommand(97, 8);
                        AddMCommand(97, 3, obj.Frequency);
                    }
                    //                ProgramList.Add(new ProgramLine(28, 0, "XYCZ"));
                    AddGCommand(28, "XYCZ");
                }
                else
                {
                    if (obj == ObjectList.First())
                    {
                        AddCommand("M3" + "S" + ProcessOptions.Frequency.ToString());
                        AddCommand("M8");
                        AddCommand("M7");
                    }
                }

                do
                {
                    z += obj.Depth;
                    if (z > obj.DepthAll)
                    {
                        z = obj.DepthAll;
                    }
//                    ProgramList.Add(new ProgramLine(1, 0, "XYCZ", obj.SmallSpeed, point[vertex.Index()].X, point[vertex.Index()].Y, angle[vertex.Index()], -z));

                    if (ProcessOptions.Machine == ProcessOptions.TTypeMachine.Denver)
                    {
                        AddProcessCommand(1, obj.SmallSpeed, point[vertex.Index()].X, point[vertex.Index()].Y, angle[vertex.Index()], -z, obj.ToString());
                    }
                    else
                    {
                        AddCommand("G1" + ToGCode("X", point[vertex.Index()].X)
                                   + ToGCode("Y", point[vertex.Index()].Y)
                                   + ZToGCode(-z)
                                   + CToGCode(angle[vertex.Index()])
                                   + ToGCode("F", obj.SmallSpeed));
                    }

                    double xOld = point[vertex.Index()].X;
                    double yOld = point[vertex.Index()].Y;

                    vertex = vertex.Opposite();

                    switch (obj.ObjectType)
                    {
                    case ObjectType.Line:
//                            ProgramList.Add(new ProgramLine(1, 0, "XYCZ", obj.GreatSpeed, point[vertex.Index()].X, point[vertex.Index()].Y, angle[vertex.Index()], -z));
                        if (ProcessOptions.Machine == ProcessOptions.TTypeMachine.Denver)
                        {
                            AddProcessCommand(1, obj.GreatSpeed, point[vertex.Index()].X, point[vertex.Index()].Y, angle[vertex.Index()], -z, obj.ToString());
                        }
                        else
                        {
                            AddCommand("G1" + ToGCode("X", point[vertex.Index()].X)
                                       + ToGCode("Y", point[vertex.Index()].Y)
                                       + ZToGCode(-z)
                                       + CToGCode(angle[vertex.Index()])
                                       + ToGCode("F", obj.GreatSpeed));
                        }
                        ;
                        break;

                    case ObjectType.Arc:
//                            ProgramList.Add(new ProgramLine(type[vertex.Index()], 0, "XYCZ", obj.GreatSpeed, point[vertex.Index()].X, point[vertex.Index()].Y, obj.ToolpathArc.Center.X, obj.ToolpathArc.Center.Y));
                        if (ProcessOptions.Machine == ProcessOptions.TTypeMachine.Denver)
                        {
                            AddProcessCommand(type[vertex.Index()], obj.GreatSpeed, point[vertex.Index()].X, point[vertex.Index()].Y, obj.ToolpathArc.Center.X, obj.ToolpathArc.Center.Y, obj.ToString());
                        }
                        else
                        {
                            AddCommand("G" + type[vertex.Index()].ToString()
                                       + ToGCode("X", point[vertex.Index()].X)
                                       + ToGCode("Y", point[vertex.Index()].Y)
                                       + ToGCode("I", obj.ToolpathArc.Center.X - xOld)
                                       + ToGCode("J", obj.ToolpathArc.Center.Y - yOld)
                                       + CToGCode(angle[vertex.Index()])
                                       + ToGCode("F", obj.GreatSpeed));
                        }
                        ;
                        break;
                    }
                }while (z < obj.DepthAll);

//                ProgramList.Add(new ProgramLine(0, 0, "XYZ", 0, point[vertex.Index()].X, point[vertex.Index()].Y, 20));
                if (ProcessOptions.Machine == ProcessOptions.TTypeMachine.Denver)
                {
                    AddSetToolCommand("XYZ", point[vertex.Index()].X, point[vertex.Index()].Y, ProcessOptions.ZSafety, obj.ToString());
                }
                else
                {
                    AddCommand("G0" + ToGCode("X", point[vertex.Index()].X)
                               + ToGCode("Y", point[vertex.Index()].Y)
                               + ZToGCode(20));
                }
            }
            if (ProcessOptions.Machine == ProcessOptions.TTypeMachine.Denver)
            {
                AddMCommand(97, 9);
                AddMCommand(97, 10);
                AddMCommand(97, 5);
                AddMCommand(97, 30);
            }
            else
            {
                AddCommand("M5");
                AddCommand("M9");
                AddCommand("TRAFOOF");
                AddCommand("G0G90G153D0Z0");
                AddCommand("M30");
            }
            ProgramForm.RefreshGrid();
            PaletteSet.Activate(2);
        }
Exemplo n.º 5
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);
        }