Example #1
0
        private GCodeLine HandleComment(string token)
        {
            GCodeLine gCodeLine = new GCodeLine(lexerGCode.CurrentLineNumber);

            bool comment = false;

            while (token != EOL)
            {
                if (token.StartsWith("#"))
                {
                    //Comment
                    comment = true;
                }

                if (!comment)
                {
                    multiLineG01G00 = false;
                    //Error
                    gCodeLine.Error.Add(new GCodeLine.ErrorGCode(lexerGCode.CurrentTokenNumber
                                                                 , GCodeLine.GCodeErrorCodes.WrongCommand, token));
                }

                token = lexerGCode.GetNextToken();
            }

            return(gCodeLine);
        }
Example #2
0
        private GCodeLine HandleG04()
        {
            GCodeLine gCodeLine = new GCodeLine(lexerGCode.CurrentLineNumber);

            string token = lexerGCode.GetNextToken();

            if (token.StartsWith("P"))
            {
                GCodeLine.CopyInside(ref gCodeLine, HandleP(token));
                token = lexerGCode.GetNextToken();
            }
            else
            {
                //Error
                gCodeLine.Error.Add(new GCodeLine.ErrorGCode(lexerGCode.CurrentTokenNumber
                                                             , GCodeLine.GCodeErrorCodes.MissingPCommand));
            }

            if (token != EOL)
            {
                GCodeLine.CopyInside(ref gCodeLine, HandleComment(token));
            }

            return(gCodeLine);
        }
Example #3
0
        private GCodeLine HandleMFunction(string token)
        {
            GCodeLine gCodeLine = new GCodeLine(lexerGCode.CurrentLineNumber);

            switch (token)
            {
            case "M00":
            case "M0":
                gCodeLine.Command.Add("M0");
                break;

            case "M02":
            case "M2":
                gCodeLine.Command.Add("M2");
                break;

            case "M09":
            case "M9":
                gCodeLine.Command.Add("M9");
                break;

            case "M10":
                gCodeLine.Command.Add("M10");
                break;

            case "M11":
                gCodeLine.Command.Add("M11");
                break;

            case "M12":
                gCodeLine.Command.Add("M12");
                break;

            case "M17":
                GCodeLine.CopyInside(ref gCodeLine, HandleM17());
                break;

            case "M30":
                GCodeLine.CopyInside(ref gCodeLine, HandleM30());
                break;

            default:
                //Error
                gCodeLine.Error.Add(new GCodeLine.ErrorGCode(lexerGCode.CurrentTokenNumber, GCodeLine.GCodeErrorCodes.WrongMCommand, token));
                break;
            }

            token = lexerGCode.GetNextToken();

            if (token != EOL)
            {
                GCodeLine.CopyInside(ref gCodeLine, HandleComment(token));
            }

            return(gCodeLine);
        }
Example #4
0
        private GCodeLine HandleLY(string token)
        {
            double    number;
            GCodeLine gCodeLine = new GCodeLine(lexerGCode.CurrentLineNumber);

            if (Double.TryParse(token.Substring(2).Replace(".", ","), out number))
            {
                //number will be secured
                gCodeLine.SubPrgDistanceY = number;
            }
            else
            {
                //Error
                gCodeLine.Error.Add(new GCodeLine.ErrorGCode(lexerGCode.CurrentTokenNumber, GCodeLine.GCodeErrorCodes.LYNumber, token));
            }
            return(gCodeLine);
        }
Example #5
0
        private GCodeLine HandleTY(string token)
        {
            int       number;
            GCodeLine gCodeLine = new GCodeLine(lexerGCode.CurrentLineNumber);

            if (int.TryParse(token.Substring(2).Replace(".", ","), out number))
            {
                //number will be secured
                gCodeLine.PartsY = number;
            }
            else
            {
                //Error
                gCodeLine.Error.Add(new GCodeLine.ErrorGCode(lexerGCode.CurrentTokenNumber, GCodeLine.GCodeErrorCodes.TYNumber, token));
            }


            return(gCodeLine);
        }
Example #6
0
        private GCodeLine HandleM30()
        {
            GCodeLine gCodeLine = new GCodeLine(lexerGCode.CurrentLineNumber);

            gCodeLine.Command.Add("M30");

            PrgHasFinished = true;

            if (toolcompensationActivated)
            {
                gCodeLine.Error.Add(new GCodeLine.ErrorGCode(lexerGCode.CurrentTokenNumber, GCodeLine.GCodeErrorCodes.ToolCompensationNotDeactivate));
            }

            if (_isSubProgram)
            {
                gCodeLine.Error.Add(new GCodeLine.ErrorGCode(lexerGCode.CurrentTokenNumber, GCodeLine.GCodeErrorCodes.WrongMCommand));
            }

            return(gCodeLine);
        }
Example #7
0
        public static void CopyInside(ref GCodeLine gCodeLine1, GCodeLine gCodeLine2)
        {
            if (gCodeLine1.LineNumber != gCodeLine2.LineNumber)
            {
                throw new Exception("LineNumber is not equal");
            }

            #region Copy Commands
            if (gCodeLine2.Command.Count() != 0)
            {
                foreach (string command in gCodeLine2.Command)
                {
                    gCodeLine1.Command.Add(command);
                }
            }
            #endregion

            #region Copy X,Y,Z
            if (gCodeLine1.XPos != null && gCodeLine2.XPos != null)
            {
                throw new Exception("XPos has in both variables a value");
            }
            else
            if (gCodeLine1.XPos == null)
            {
                gCodeLine1.XPos = gCodeLine2.XPos;
            }

            if (gCodeLine1.YPos != null && gCodeLine2.YPos != null)
            {
                throw new Exception("YPos has in both variables a value");
            }
            else
            if (gCodeLine1.YPos == null)
            {
                gCodeLine1.YPos = gCodeLine2.YPos;
            }

            if (gCodeLine1.ZPos != null && gCodeLine2.ZPos != null)
            {
                throw new Exception("ZPos has in both variables a value");
            }
            else
            if (gCodeLine1.ZPos == null)
            {
                gCodeLine1.ZPos = gCodeLine2.ZPos;
            }
            #endregion

            #region Copy Circle
            if (gCodeLine1.IPos != null && gCodeLine2.IPos != null)
            {
                throw new Exception("IPos has in both variables a value");
            }
            else
            if (gCodeLine1.IPos == null)
            {
                gCodeLine1.IPos = gCodeLine2.IPos;
            }

            if (gCodeLine1.JPos != null && gCodeLine2.JPos != null)
            {
                throw new Exception("JPos has in both variables a value");
            }
            else
            if (gCodeLine1.JPos == null)
            {
                gCodeLine1.JPos = gCodeLine2.JPos;
            }

            if (gCodeLine1.CRNumber != null && gCodeLine2.CRNumber != null)
            {
                throw new Exception("CRNumber has in both variables a value");
            }
            else
            if (gCodeLine1.CRNumber == null)
            {
                gCodeLine1.CRNumber = gCodeLine2.CRNumber;
            }
            #endregion

            #region Copy Break;
            if (gCodeLine1.PNumber != null && gCodeLine2.PNumber != null)
            {
                throw new Exception("PNumber has in both variables a value");
            }
            else
            if (gCodeLine1.PNumber == null)
            {
                gCodeLine1.PNumber = gCodeLine2.PNumber;
            }
            #endregion

            #region Copy SubProgram
            if (gCodeLine1.SubPrgName != null && gCodeLine2.SubPrgName != null)
            {
                throw new Exception("SubProgramName has in both variables a value");
            }
            else
            if (gCodeLine1.SubPrgName == null)
            {
                gCodeLine1.SubPrgName = gCodeLine2.SubPrgName;
            }

            if (gCodeLine1.PartsX != null && gCodeLine2.PartsX != null)
            {
                throw new Exception("PartsX has in both variables a value");
            }
            else
            if (gCodeLine1.PartsX == null)
            {
                gCodeLine1.PartsX = gCodeLine2.PartsX;
            }

            if (gCodeLine1.PartsY != null && gCodeLine2.PartsY != null)
            {
                throw new Exception("PartsY has in both variables a value");
            }
            else
            if (gCodeLine1.PartsY == null)
            {
                gCodeLine1.PartsY = gCodeLine2.PartsY;
            }

            if (gCodeLine1.SubPrgDistanceX != null && gCodeLine2.SubPrgDistanceX != null)
            {
                throw new Exception("SubDistanceX has in both variables a value");
            }
            else
            if (gCodeLine1.SubPrgDistanceX == null)
            {
                gCodeLine1.SubPrgDistanceX = gCodeLine2.SubPrgDistanceX;
            }

            if (gCodeLine1.SubPrgDistanceY != null && gCodeLine2.SubPrgDistanceY != null)
            {
                throw new Exception("SubDistanceY has in both variables a value");
            }
            else
            if (gCodeLine1.SubPrgDistanceY == null)
            {
                gCodeLine1.SubPrgDistanceY = gCodeLine2.SubPrgDistanceY;
            }
            #endregion


            #region Copy Error
            for (int i = 0; i < gCodeLine2.Error.Count(); i++)
            {
                gCodeLine1.Error.Add(gCodeLine2.Error[i]);
            }
            #endregion
        }
Example #8
0
        private GCodeLine HandleG02G03()
        {
            string token = lexerGCode.GetNextToken();

            GCodeLine gCodeLine = new GCodeLine(lexerGCode.CurrentLineNumber);

            bool oneFoundXY         = false;
            bool oneFoundIJ         = false;
            bool CircleDefinitionIJ = false;
            bool CircleDefinitionCR = false;

            if (token.StartsWith("X"))
            {
                oneFoundXY = true;
                GCodeLine.CopyInside(ref gCodeLine, HandleX(token));
                token = lexerGCode.GetNextToken();
            }

            if (token.StartsWith("Y"))
            {
                oneFoundXY = true;
                GCodeLine.CopyInside(ref gCodeLine, HandleY(token));
                token = lexerGCode.GetNextToken();
            }

            if (!oneFoundXY)
            {
                //Error
                gCodeLine.Error.Add(new GCodeLine.ErrorGCode(lexerGCode.CurrentTokenNumber
                                                             , GCodeLine.GCodeErrorCodes.MissingCommand));
            }

            if (token.StartsWith("I"))
            {
                oneFoundIJ         = true;
                CircleDefinitionIJ = true;
                GCodeLine.CopyInside(ref gCodeLine, HandleX(token));
                token = lexerGCode.GetNextToken();
            }

            if (token.StartsWith("J"))
            {
                oneFoundIJ         = true;
                CircleDefinitionIJ = true;
                GCodeLine.CopyInside(ref gCodeLine, HandleY(token));
                token = lexerGCode.GetNextToken();
            }

            if (token.StartsWith("CR"))
            {
                CircleDefinitionCR = true;
                GCodeLine.CopyInside(ref gCodeLine, HandleCR(token));
                token = lexerGCode.GetNextToken();
            }

            if (!oneFoundIJ && !CircleDefinitionCR)
            {
                //Error
                gCodeLine.Error.Add(new GCodeLine.ErrorGCode(lexerGCode.CurrentTokenNumber, GCodeLine.GCodeErrorCodes.MissingCommand));
            }

            if (CircleDefinitionIJ && CircleDefinitionCR)
            {
                //Error
                gCodeLine.Error.Add(new GCodeLine.ErrorGCode(lexerGCode.CurrentTokenNumber, GCodeLine.GCodeErrorCodes.IJAndCR));
            }

            if (token != EOL)
            {
                GCodeLine.CopyInside(ref gCodeLine, HandleComment(token));
            }

            return(gCodeLine);
        }
Example #9
0
        private GCodeLine HandleG00G01(string token = "")
        {
            if (token == "")
            {
                token = lexerGCode.GetNextToken();
            }

            GCodeLine gCodeLine = new GCodeLine(lexerGCode.CurrentLineNumber);

            bool oneFound       = false;
            bool checkXY        = false;
            int  commandCounter = 0;

            if (token == "G41")
            {
                gCodeLine.Command.Add("G41");
                token = lexerGCode.GetNextToken();
                toolcompensationActivated = true;
            }

            if (token == "G42")
            {
                gCodeLine.Command.Add("G42");
                token = lexerGCode.GetNextToken();
                toolcompensationActivated = true;
            }

            if (token.StartsWith("X"))
            {
                oneFound = true;
                checkXY  = true;
                commandCounter++;
                GCodeLine.CopyInside(ref gCodeLine, HandleX(token));
                token = lexerGCode.GetNextToken();
            }

            if (token.StartsWith("Y"))
            {
                oneFound = true;
                checkXY  = true;
                commandCounter++;
                GCodeLine.CopyInside(ref gCodeLine, HandleY(token));
                token = lexerGCode.GetNextToken();
            }

            if (token.StartsWith("SEG"))
            {
                oneFound = true;
                commandCounter++;
                GCodeLine.CopyInside(ref gCodeLine, HandleSEG(token));
                token = lexerGCode.GetNextToken();
            }

            if (token.StartsWith("ANG"))
            {
                commandCounter++;
                GCodeLine.CopyInside(ref gCodeLine, HandleANG(token));
                token = lexerGCode.GetNextToken();
            }

            if (!oneFound)
            {
                //Error
                gCodeLine.Error.Add(new GCodeLine.ErrorGCode(lexerGCode.CurrentTokenNumber
                                                             , GCodeLine.GCodeErrorCodes.MissingCommand));
            }

            if (commandCounter > 2)
            {
                //Error
                gCodeLine.Error.Add(new GCodeLine.ErrorGCode(lexerGCode.CurrentTokenNumber
                                                             , GCodeLine.GCodeErrorCodes.ToManyCommands));
            }
            else if (commandCounter < 2 && !checkXY && oneFound)
            {
                //Error
                gCodeLine.Error.Add(new GCodeLine.ErrorGCode(lexerGCode.CurrentTokenNumber
                                                             , GCodeLine.GCodeErrorCodes.MissingCommand));
            }

            if (token != EOL)
            {
                GCodeLine.CopyInside(ref gCodeLine, HandleComment(token));
            }

            return(gCodeLine);
        }
Example #10
0
        private void HandleCode()
        {
            bool   finish      = false;
            bool   SubPrgFound = false;
            string token;

            do
            {
                token = lexerGCode.GetNextToken();

                GCodeLine gCodeLine = new GCodeLine(lexerGCode.CurrentLineNumber);

                switch (token.Substring(0, 1))
                {
                case "G":
                    if (PrgHasFinished)
                    {
                        gCodeLine.Error.Add(new GCodeLine.ErrorGCode(lexerGCode.CurrentLineNumber, GCodeLine.GCodeErrorCodes.PrgHasFinished, token));
                    }
                    GCodeLine.CopyInside(ref gCodeLine, HandleGFunction(token));
                    break;

                case "M":
                    if (PrgHasFinished)
                    {
                        gCodeLine.Error.Add(new GCodeLine.ErrorGCode(lexerGCode.CurrentLineNumber, GCodeLine.GCodeErrorCodes.PrgHasFinished, token));
                    }
                    GCodeLine.CopyInside(ref gCodeLine, HandleMFunction(token));
                    multiLineG01G00 = false;
                    break;

                case "X":
                case "Y":
                    if (PrgHasFinished)
                    {
                        gCodeLine.Error.Add(new GCodeLine.ErrorGCode(lexerGCode.CurrentLineNumber, GCodeLine.GCodeErrorCodes.PrgHasFinished, token));
                    }
                    GCodeLine.CopyInside(ref gCodeLine, HandleG00G01(token));

                    if (!multiLineG01G00)
                    {
                        gCodeLine.Error.Add(new GCodeLine.ErrorGCode(lexerGCode.CurrentTokenNumber, GCodeLine.GCodeErrorCodes.MissingG00OrG01, token));
                    }
                    else
                    {
                        gCodeLine.Command.Add(multiLineCommand);
                    }
                    break;

                default:
                    switch (token)
                    {
                    case EOL:
                        break;

                    case EOF:
                        finish = true;
                        break;

                    default:
                        foreach (string subPrg in _subPrograms)
                        {
                            if (token == subPrg)
                            {
                                if (PrgHasFinished)
                                {
                                    gCodeLine.Error.Add(new GCodeLine.ErrorGCode(lexerGCode.CurrentLineNumber, GCodeLine.GCodeErrorCodes.PrgHasFinished, token));
                                }

                                GCodeLine.CopyInside(ref gCodeLine, HandleSubProgram(token));
                                SubPrgFound = true;
                                break;
                            }
                        }

                        if (!SubPrgFound)
                        {
                            GCodeLine.CopyInside(ref gCodeLine, HandleComment(token));
                        }
                        break;
                    }
                    break;
                }
                gCodeLines.Add(gCodeLine);
                Debugger.Log(1, "Test", "Hallo");
            } while (!finish);
        }
Example #11
0
        private GCodeLine HandleSubProgram(string token)
        {
            GCodeLine gCodeLine = new GCodeLine(lexerGCode.CurrentLineNumber);

            gCodeLine.Command.Add("SubPrg");
            gCodeLine.SubPrgName = token;

            token = lexerGCode.GetNextToken();

            #region TX
            if (token.StartsWith("TX"))
            {
                GCodeLine.CopyInside(ref gCodeLine, HandleTX(token));
                token = lexerGCode.GetNextToken();
            }
            else
            {
                //Error
                gCodeLine.Error.Add(new GCodeLine.ErrorGCode(lexerGCode.CurrentTokenNumber
                                                             , GCodeLine.GCodeErrorCodes.MissingTXCommand));
            }
            #endregion

            #region TY
            if (token.StartsWith("TY"))
            {
                GCodeLine.CopyInside(ref gCodeLine, HandleTY(token));
                token = lexerGCode.GetNextToken();
            }
            else
            {
                //Error
                gCodeLine.Error.Add(new GCodeLine.ErrorGCode(lexerGCode.CurrentTokenNumber
                                                             , GCodeLine.GCodeErrorCodes.MissingTYCommand));
            }
            #endregion

            #region LX
            if (token.StartsWith("LX"))
            {
                GCodeLine.CopyInside(ref gCodeLine, HandleLX(token));
                token = lexerGCode.GetNextToken();
            }
            else
            {
                //Error
                gCodeLine.Error.Add(new GCodeLine.ErrorGCode(lexerGCode.CurrentTokenNumber
                                                             , GCodeLine.GCodeErrorCodes.MissingLXCommand));
            }
            #endregion

            #region LY
            if (token.StartsWith("LY"))
            {
                GCodeLine.CopyInside(ref gCodeLine, HandleLY(token));
                token = lexerGCode.GetNextToken();
            }
            else
            {
                //Error
                gCodeLine.Error.Add(new GCodeLine.ErrorGCode(lexerGCode.CurrentTokenNumber
                                                             , GCodeLine.GCodeErrorCodes.MissingLYCommand));
            }
            #endregion

            if (token != EOL)
            {
                GCodeLine.CopyInside(ref gCodeLine, HandleComment(token));
            }

            return(gCodeLine);
        }
Example #12
0
        private GCodeLine HandleGFunction(string token)
        {
            GCodeLine gCodeLine = new GCodeLine(lexerGCode.CurrentLineNumber);

            multiLineG01G00 = false;

            switch (token)
            {
            case "G00":
            case "G0":
                gCodeLine.Command.Add("G0");
                GCodeLine.CopyInside(ref gCodeLine, HandleG00G01());
                multiLineG01G00  = true;
                multiLineCommand = "G0";
                break;

            case "G01":
            case "G1":
                gCodeLine.Command.Add("G1");
                GCodeLine.CopyInside(ref gCodeLine, HandleG00G01());
                multiLineG01G00  = true;
                multiLineCommand = "G1";
                break;

            case "G02":
            case "G2":
                gCodeLine.Command.Add("G2");
                GCodeLine.CopyInside(ref gCodeLine, HandleG02G03());
                break;

            case "G03":
            case "G3":
                gCodeLine.Command.Add("G3");
                GCodeLine.CopyInside(ref gCodeLine, HandleG02G03());
                break;

            case "G4":
            case "G04":
                gCodeLine.Command.Add("G4");
                GCodeLine.CopyInside(ref gCodeLine, HandleG04());
                break;

            case "G40":
                gCodeLine.Command.Add("G40");
                if (!multiLineG01G00)
                {
                    gCodeLine.Error.Add(new GCodeLine.ErrorGCode(lexerGCode.CurrentTokenNumber, GCodeLine.GCodeErrorCodes.MissingG00OrG01));
                }
                GCodeLine.CopyInside(ref gCodeLine, HandleG00G01());
                toolcompensationActivated = false;
                break;

            case "G41":
                gCodeLine.Command.Add("G41");
                if (!multiLineG01G00)
                {
                    gCodeLine.Error.Add(new GCodeLine.ErrorGCode(lexerGCode.CurrentTokenNumber, GCodeLine.GCodeErrorCodes.MissingG00OrG01));
                }
                GCodeLine.CopyInside(ref gCodeLine, HandleG00G01());
                toolcompensationActivated = true;
                break;

            case "G42":
                gCodeLine.Command.Add("G42");
                if (!multiLineG01G00)
                {
                    gCodeLine.Error.Add(new GCodeLine.ErrorGCode(lexerGCode.CurrentTokenNumber, GCodeLine.GCodeErrorCodes.MissingG00OrG01));
                }
                GCodeLine.CopyInside(ref gCodeLine, HandleG00G01());
                toolcompensationActivated = true;
                break;

            case "G53":
                gCodeLine.Command.Add("G53");
                GCodeLine.CopyInside(ref gCodeLine, HandleComment(lexerGCode.GetNextToken()));
                break;

            case "G54":
                gCodeLine.Command.Add("G54");
                GCodeLine.CopyInside(ref gCodeLine, HandleComment(lexerGCode.GetNextToken()));
                break;

            case "G55":
                gCodeLine.Command.Add("G55");
                GCodeLine.CopyInside(ref gCodeLine, HandleComment(lexerGCode.GetNextToken()));
                break;

            case "G56":
                gCodeLine.Command.Add("G56");
                GCodeLine.CopyInside(ref gCodeLine, HandleComment(lexerGCode.GetNextToken()));
                break;

            case "G57":
                gCodeLine.Command.Add("G57");
                GCodeLine.CopyInside(ref gCodeLine, HandleComment(lexerGCode.GetNextToken()));
                break;

            case "G58":
                gCodeLine.Command.Add("G58");
                GCodeLine.CopyInside(ref gCodeLine, HandleG58G59());
                break;

            case "G59":
                gCodeLine.Command.Add("G59");
                GCodeLine.CopyInside(ref gCodeLine, HandleG58G59());
                break;

            case "G90":
                gCodeLine.Command.Add("G55");
                GCodeLine.CopyInside(ref gCodeLine, HandleComment(lexerGCode.GetNextToken()));
                break;

            case "G91":
                gCodeLine.Command.Add("G55");
                GCodeLine.CopyInside(ref gCodeLine, HandleComment(lexerGCode.GetNextToken()));
                break;

            default:
                //Error
                gCodeLine.Error.Add(new GCodeLine.ErrorGCode(lexerGCode.CurrentTokenNumber, GCodeLine.GCodeErrorCodes.WrongGCommand, token));
                GCodeLine.CopyInside(ref gCodeLine, HandleComment(token));
                break;
            }

            return(gCodeLine);
        }