Esempio n. 1
0
        /// <summary>
        /// Sets color of the pen
        /// </summary>
        /// <param name="cmdLine">Current command line</param>
        /// <returns>True or false whether tool is changed or not</returns>
        public virtual bool Tool(string cmdLine)
        {
            if (cmdLine[cmdLine.Length - 1] == ';')
            {
                cmdLine = cmdLine.Substring(0, cmdLine.Length - 1).Trim();
            }

            if (cmdLine[0] == 'M')
            {
                cmdLine = TextHndlr.NextCommand(cmdLine, "M");
            }

            int color;

            // Skip command after tool select
            if (cmdLine.Contains('F'))
            {
                color = int.Parse(cmdLine.Substring(1, cmdLine.IndexOf('F') - 1).Trim());
            }
            else if (cmdLine.Contains('H'))
            {
                color = int.Parse(cmdLine.Substring(1, cmdLine.IndexOf('M') - 1).Trim());
            }
            else if (cmdLine.Contains('T'))
            {
                if (cmdLine.Substring(1).Contains('M'))
                {
                    color = int.Parse(cmdLine.Substring(1, cmdLine.IndexOf('M') - 1));
                }
                else
                {
                    color = int.Parse(cmdLine.Substring(1).Trim());
                }
            }
            else if (cmdLine.Contains("SP"))
            {
                color = int.Parse(cmdLine.Substring(2).Trim());
            }
            else if (TextHndlr.IsNumber(cmdLine.Substring(1)))
            {
                color = int.Parse(cmdLine.Substring(1).Trim());
            }
            else
            {
                color = Color;
            }

            // Set color
            Color = color;

            return(true);
        }
Esempio n. 2
0
        private bool ConvertLine(string Line)
        {
            bool result = false;

            /// Delete comments from current line
            Line = TextHndlr.CleanComments(Line);

            do
            {
                // Get command from current line
                Command = TextHndlr.CutCommand(Line);

                // Check if command is avaible, invoke command's method with current line
                if (FunctionDic.ContainsKey(Command))
                {
                    result = FunctionDic[Command].Invoke(Line);
                }
                else if (Command != "" && (Command[0] == 'X' || Command[0] == 'Y') && Functions.ModularCommand != null)
                {
                    // Get reoccurring command in line
                    Command = Functions.ModularCommand;
                    // Create new line for reoccuring command
                    Line = Command + Line;
                    // Invoke new commandline
                    result = FunctionDic[Command].Invoke(Line);
                }

                // Save command as old command
                LastCommand = Command;
                // Look for next command in line
                Line = TextHndlr.NextCommand(Line, Command);

                // Skip line if the pen already moved
                if (LastCommand == "G01" || LastCommand == "G1" || LastCommand == "G02" || LastCommand == "G2" || LastCommand == "G03" || LastCommand == "G3" || LastCommand == "G0" || LastCommand == "G00" || LastCommand == "DFS")
                {
                    Line = "";
                }
            } while (Line != "");

            return(result);
        }
Esempio n. 3
0
        public virtual bool Rotary(string cmdLine)
        {
            string fCmd = cmdLine.Substring(0, cmdLine.IndexOf('X')).Trim();

            cmdLine = TextHndlr.NextCommand(cmdLine, fCmd);

            string[] cmds = cmdLine.Split('X', 'A', 'R');
            X = double.Parse(cmds[1], CultureInfo.InvariantCulture);
            Y = double.Parse(cmds[2], CultureInfo.InvariantCulture);
            I = double.Parse(cmds[3], CultureInfo.InvariantCulture);

            NewX = (RelativeCoord) ? X + LastX : X;
            NewY = (RelativeCoord) ? Y * I + LastY : Y * I;

            if (PenDown)
            {
                Output.OutputLine(LastX, LastY, NewX, NewY, Color);
            }

            LastX = NewX;
            LastY = NewY;

            return(true);
        }
Esempio n. 4
0
        /// <summary>
        /// Creates an arc in the output file
        /// </summary>
        /// <param name="cmdLine">Current command line</param>
        /// <returns>True of false whether the arc is drawn</returns>
        public virtual bool Arc(string cmdLine)
        {
            ReplaceAxis(ref cmdLine);

            if (((cmdLine.Contains("G0") || cmdLine.Contains("G00")) && !cmdLine.Contains("G01")) && SubColors.ContainsKey(CurrentSub))
            {
                Color = SubColors[CurrentSub];
            }

            // Detect move command
            //if ((cmdLine.Contains("G2") || cmdLine.Contains("G02")) && !cmdLine.Contains("G03"))
            //    PenDown = false;
            //else
            //    PenDown = true;

            // Get first command
            string fCmd = TextHndlr.CutCommand(cmdLine);

            cmdLine = TextHndlr.NextCommand(cmdLine, fCmd);

            // If X is still not found, use modular command
            if (!cmdLine.Contains('X') && !cmdLine.Contains('Y'))
            {
                ModularCommand = fCmd;

                if (cmdLine.Contains('Z'))
                {
                    PenDown = cmdLine[cmdLine.IndexOf('Z') + 1] == '-';
                }

                return(true);
            }

            // Split the string
            string[] cmds;
            if (!cmdLine.Contains("F"))
            {
                cmds = cmdLine.Split('X', 'Y', 'I', 'J');
            }
            else
            {
                cmds = cmdLine.Split('X', 'Y', 'I', 'J', 'F');
            }

            X = double.Parse(cmds[1], CultureInfo.InvariantCulture);
            Y = double.Parse(cmds[2], CultureInfo.InvariantCulture);
            I = double.Parse(cmds[3], CultureInfo.InvariantCulture);
            J = double.Parse(cmds[4], CultureInfo.InvariantCulture);

            // Add old coordinates if coordinates are relative
            NewX = (RelativeCoord) ? X + LastX : X;
            NewY = (RelativeCoord) ? Y + LastY : Y;

            // Add old centre coordinates if whole program is relative
            if (Module_Main.RelativeArc)
            {
                I = I + LastX;
                J = J + LastY;
            }
            // Add old centre coordinates if centre coordinates are relative
            else
            {
                I = (RelativeCoord) ? I + LastX : I;
                J = (RelativeCoord) ? J + LastY : J;
            }

            // Skip if radius is too small
            if (Radius == 0)
            {
                return(false);
            }

            // Draw circle if coordinates are from the same origen
            if (LastX == NewX && LastY == NewY)
            {
                // Draw circle
                if (PenDown)
                {
                    Output.OutputCircle(I, J, Radius, Color);
                }
            }
            else
            {
                // otherwise it is an arc
                if (fCmd == "G02" || fCmd == "G2")
                {
                    Radius = -Radius;
                }
                //  Draw arc
                if (PenDown)
                {
                    Output.OutputArc(LastX, LastY, NewX, NewY, I, J, Radius, Color);
                }
            };

            // Set new coordinates to old coordinates
            LastX = NewX;
            LastY = NewY;

            ModularCommand = fCmd;

            return(true);
        }
Esempio n. 5
0
        /// <summary>
        /// Creates a line and writes it in output file
        /// </summary>
        /// <param name="cmdLine">Current command line</param>
        /// <returns>Returns true or false whether line is drawn or not</returns>
        public virtual bool Line(string cmdLine)
        {
            ReplaceAxis(ref cmdLine);

            if (((cmdLine.Contains("G0") || cmdLine.Contains("G00")) && !cmdLine.Contains("G01")) && SubColors.ContainsKey(CurrentSub))
            {
                Color = SubColors[CurrentSub];
            }

            // If there is no axis, skip command
            if (!cmdLine.Contains('X') && !cmdLine.Contains('Y'))
            {
                ModularCommand = TextHndlr.CutCommand(cmdLine);

                if (cmdLine.Contains('Z'))
                {
                    PenDown = cmdLine[cmdLine.IndexOf('Z') + 1] == '-';
                }

                return(true);
            }

            // Detect move command
            if ((cmdLine.Contains("G0") || cmdLine.Contains("G00")) && !cmdLine.Contains("G01"))
            {
                PenDown = false;
            }
            else if (!cmdLine.Contains("G0") && !cmdLine.Contains("G00") && !cmdLine.Contains("G01") && !cmdLine.Contains("G1") && cmdLine.Contains("X"))
            {
                PenDown = false;
            }
            else
            {
                PenDown = true;
            }

            // Get first command
            string fCmd = TextHndlr.CutCommand(cmdLine);

            // Get begin of coordinates
            if (fCmd != "X")
            {
                cmdLine = TextHndlr.NextCommand(cmdLine, fCmd);
            }
            // If X is still not found, use modular command
            if (fCmd != "X")
            {
                ModularCommand = fCmd;
            }

            if (cmdLine.Contains("G76"))
            {
                cmdLine = TextHndlr.NextCommand(cmdLine, fCmd);
            }

            // Split the string for X and Y coords
            if (cmdLine.Contains('X') && cmdLine.Contains('Y'))
            {
                string[] cmds = cmdLine.Split('X', 'Y');
                X = double.Parse(cmds[1], CultureInfo.InvariantCulture);
                Y = double.Parse(cmds[2], CultureInfo.InvariantCulture);
            }
            // Check if only X has to be changes
            else if (cmdLine.Contains('X'))
            {
                // If the line contains an F, cut number from X to F
                if (cmdLine.Contains('F'))
                {
                    X = double.Parse(cmdLine.Substring(cmdLine.IndexOf('X') + 1, cmdLine.IndexOf('F') - cmdLine.IndexOf('X') - 1).Trim());
                }
                else
                {
                    X = double.Parse(cmdLine.Substring(cmdLine.IndexOf('X') + 1).Trim());
                }
            }
            // Check if only Y has to be changes
            else if (cmdLine.Contains('Y'))
            {
                // If the line contains an F, cut number from Y to F
                if (cmdLine.Contains('F'))
                {
                    Y = double.Parse(cmdLine.Substring(cmdLine.IndexOf('Y') + 1, cmdLine.IndexOf('F') - cmdLine.IndexOf('Y') - 1).Trim());
                }
                else
                {
                    Y = double.Parse(cmdLine.Substring(cmdLine.IndexOf('Y') + 1).Trim());
                }
            }

            // If line contains Z, use Z to move pen up and down
            if (cmdLine.Contains('Z'))
            {
                PenDown = cmdLine[cmdLine.IndexOf('Z') + 1] == '-';
            }

            // Add old coordinates if coordinates are relative
            NewX = (RelativeCoord) ? X + LastX : X;
            NewY = (RelativeCoord) ? Y + LastY : Y;

            // Draw line
            if (PenDown)
            {
                Output.OutputLine(LastX, LastY, NewX, NewY, Color);
            }

            // Set new coordinates to old coordinates
            LastX = NewX;
            LastY = NewY;

            if (PenDown)
            {
                ModularCommand = "G1";
            }
            else
            {
                ModularCommand = "G0";
            }

            return(true);
        }