Ejemplo n.º 1
0
        private string[] SplitLine(string cmdLine)
        {
            string cmd = TextHndlr.CutCommand(cmdLine);

            string[] result = { };
            string[] temp   = { };

            temp   = cmdLine.Split(new char[] { ';', ',' });
            result = (string[])temp.Clone();

            for (int i = 0; i < result.Length; i++)
            {
                for (int n = 0; n < result[i].Length; n++)
                {
                    if (TextHndlr.IsLetter(result[i][n].ToString()))
                    {
                        temp[i] = result[i].Substring(n + 1);
                    }
                    else if (TextHndlr.IsNumber(result[i][n].ToString()))
                    {
                        continue;
                    }
                    else
                    {
                        if (result[i][n] != '.' && result[i][n] != '-')
                        {
                            temp[i] = result[i].Substring(n + 1);
                        }
                    }
                }

                if (temp[i] == "")
                {
                    Array.Clear(temp, i, 1);
                }
            }

            result = (string[])temp.Clone();
            temp   = new string[] { };

            for (int i = 0; i < result.Length; i++)
            {
                if (result[i] != null)
                {
                    Array.Resize(ref temp, temp.Count() + 1);
                    temp[temp.Count() - 1] = result[i];
                }
            }

            result = temp;

            return(result);
        }
Ejemplo n.º 2
0
        public bool Circle(string cmdLine)
        {
            string fCmd = TextHndlr.CutCommand(cmdLine);

            string[] coords = SplitLine(cmdLine);

            if (PenDown)
            {
                Output.OutputCircle(LastX, LastY, Radius, Color);
            }

            return(false);
        }
Ejemplo n.º 3
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);
        }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo n.º 6
0
        public override bool Arc(string cmdLine)
        {
            // Get the first command it finds
            string fCmd = TextHndlr.CutCommand(cmdLine);

            //cmdLine = TextHndlr.NextCommand(cmdLine, fCmd);

            if (fCmd == "AA")
            {
                Absolute(cmdLine);
            }
            else if (fCmd == "AR")
            {
                Relative(cmdLine);
            }

            // Get coordinates and angle from line
            string[] coords = SplitLine(cmdLine);
            // Define I coord
            I = Math.Round(double.Parse(coords[0]) / Factor, 3);
            // Define J coord
            J = Math.Round(double.Parse(coords[1]) / Factor, 3);
            // Define angle
            Angle = Math.Round(double.Parse(coords[2]), 3);

            // 360 Angle is a circle
            if (Angle == 360)
            {
                // Draw circle
                Output.OutputCircle(I, J, Radius, Color);
            }
            else
            {
                if (DiX == 0)
                {
                    // Calcute end of angle
                    EndAngle = Angle * Module_Main.PI / 180 + (Module_Main.PI / 2) * Math.Sign(DiY);
                }
                else
                {
                    if (DiY != 0)
                    {
                        if (DiX < 0)
                        {
                            // Calculate start of angle
                            StartAngle = (DiY < 0) ? Math.Atan(DiY / DiX) + Module_Main.PI : Module_Main.PI - Math.Atan(DiY / (-DiX));
                        }
                        else
                        {
                            // Calculate start of angle
                            StartAngle = Math.Atan(DiY / DiX);
                        }

                        // Calculate end of angle
                        EndAngle = Angle * Module_Main.PI / 180 + StartAngle;
                    }
                    else
                    {
                        // Calculate end of engle
                        EndAngle = Angle * Module_Main.PI / 180 + ((DiX > 0) ? 0 : Module_Main.PI);
                    }
                }

                // Calculate new X and Y coordinates
                NewX = Radius * Math.Cos(EndAngle) + I;
                NewY = Radius * Math.Sin(EndAngle) + J;

                // Clockwise or counterclockwise
                if (Angle < 0)
                {
                    Radius = -Radius;
                }

                if (PenDown)
                {
                    Output.OutputArc(LastX, LastY, NewX, NewY, I, J, Radius, Color);
                }

                LastX = NewX;
                LastY = NewY;
            }

            return(true);
        }
Ejemplo n.º 7
0
        public override bool Line(string cmdLine)
        {
            try
            {
                // Get the first command it finds
                string fCmd = TextHndlr.CutCommand(cmdLine);
                //cmdLine = TextHndlr.NextCommand(cmdLine, fCmd);
                // Create a string array of coordinates
                string[] coords = { };

                //PenDown = (fCmd == "PD" && fCmd != "PU") ? true : false;

                if (cmdLine.Contains("AA"))
                {
                    Arc(cmdLine);
                }

                // Look if the command is absolute
                if (fCmd == "PA")
                {
                    Absolute(cmdLine);
                }
                // Look if the command is relative
                else if (fCmd == "PR")
                {
                    Relative(cmdLine);
                }

                // Look if the commandline contains any coords
                if (cmdLine.Contains(','))
                {
                    // Fill string array with coordinates
                    coords = SplitLine(cmdLine);
                }
                else
                {
                    return(false);
                }

                // Define X coord
                X = double.Parse(coords[0]);
                // Define Y coord
                Y = double.Parse(coords[1]);
                // Scale new by factor
                NewX = X / Factor;
                NewY = Y / Factor;

                // Write if current penstate is down
                if (PenDown)
                {
                    Output.OutputLine(LastX, LastY, NewX, NewY, Color);
                }

                // Change old coords to new coords
                LastX = NewX;
                LastY = NewY;

                if (coords.Length > 2)
                {
                    string temp = fCmd;

                    for (int i = 2; i < coords.Length; i++)
                    {
                        temp += coords[i] + ",";
                    }

                    Line(temp);
                }
            }
            catch (Exception e)
            {
            }

            return(true);
        }