Example #1
0
        private void ParseCommands()
        {
            bool penDown = false;

            SKPoint last = new SKPoint(0, 0);

            foreach (var v in CodeCommands)
            {
                if (v.Value.Length != 0)
                {
                    var codeCommand = new GCodeCommand(v.Value, v.Key);
                    int classif     = Util.ClassifyCommand(codeCommand);


                    switch (classif)
                    {
                    case (-1):
                        Console.WriteLine("UNKOWN! :" + v.Value);
                        break;

                    case (0):
                        //FeedRate = (int)codeCommand.getParameters()['F'];
                        break;

                    case (1):
                    case (2):
                    case (4):     //TODO REDO R-ARC classification
                        //Line
                        //Console.WriteLine("Line! :" + v.Value);
                        DrawCommands.Add(v.Key, new GcodeLine(codeCommand, penDown, last));
                        last = new SKPoint((float)codeCommand.getParameters()['X'],
                                           (float)codeCommand.getParameters()['Y']);


                        break;

                    case (3):
                        //ARC
                        //Console.WriteLine("Arc! :" + v.Value);
                        DrawCommands.Add(v.Key, new GcodeArc(codeCommand, penDown, last, classif));
                        last = new SKPoint((float)codeCommand.getParameters()['X'],
                                           (float)codeCommand.getParameters()['Y']);
                        break;

                    case (11):
                        penDown = false;
                        //Console.WriteLine("Pen Up! :" + v.Value);

                        break;

                    case (12):
                        penDown = true;
                        //Console.WriteLine("Pen Down! :" + v.Value);
                        break;
                    }
                }
            }
        }
Example #2
0
        private void LoadFile(string file)
        {
            string[] Glines  = System.IO.File.ReadAllLines(file);
            int      counter = 0;

            foreach (var v in Glines)
            {
                if (v != "")
                {
                    fileLines.Add(counter, v);
                    counter++;
                }
            }

            foreach (var Entry in fileLines)
            {
                var command = new GCodeCommand(Entry.Value, Entry.Key);
                CodeLines.Add(Entry.Key, command);
            }

            DrawSegment lastSegment = null;
            bool        PDown       = false;
            float       FeedRate    = 0;

            for (int i = 0; i < CodeLines.Count; i++)
            {
                int classif = Util.ClassifyCommand(CodeLines[i]);

                switch (classif)
                {
                case (0):
                    FeedRate = (int)CodeLines[i].getParameters()['F'];
                    break;

                case (1):
                case (2):
                    SegmentLine d = new SegmentLine(CodeLines[i], PDown, FeedRate, lastSegment);
                    lastSegment = d;
                    OriginalSegments.Add(d.Index, d);
                    break;

                case (3):
                case (4):
                    SegmentArc a = new SegmentArc(CodeLines[i], PDown, FeedRate, lastSegment);
                    lastSegment = a;
                    OriginalSegments.Add(a.Index, a);
                    break;

                case (11):
                    PDown = false;
                    break;

                case (12):
                    PDown = true;
                    break;
                }
            }
        }
Example #3
0
        public GcodeLine(GCodeCommand command, bool drawn, SKPoint start)
        {
            this.OriginalCommand = command;
            this.PenDown         = drawn;

            Start    = start;
            End      = new SKPoint((float)command.getParameters()['X'], (float)command.getParameters()['Y']);
            DrawType = typeof(GcodeLine);
        }
Example #4
0
 public static int ClassifyLine(GCodeCommand input)
 {
     if (input.getParameters().ContainsKey('F'))
     {
         return(0);
     }
     else
     {
         return(2);
     }
 }
Example #5
0
 public static int ClassifyArc(GCodeCommand input)
 {
     if (input.getParameters().ContainsKey('R'))
     {
         return(4);
     }
     else
     {
         return(3);
     }
 }
Example #6
0
        public SegmentLine(GCodeCommand command, bool pen, float feed, DrawSegment Previous = null)
        {
            if (Previous == null)
            {
                End = new SKPoint(0.0f, 0.0f);
            }
            else
            {
                Start = Previous.End;
            }

            End      = command.getEndPoint();
            Command  = command;
            Index    = command.getIndex();
            PenDown  = pen;
            FeedRate = feed;
        }
Example #7
0
        public static int ClassifyCommand(GCodeCommand input)
        {
            /*
             * CLASSIFICATIONS:
             *   Motion Commands
             *    0 - Feed rate        [G1 Fxxxx]
             *    1 - Rapid Move       [G0 X0 Y0]
             *    2 - Linear Move      [G1 X10 Y10]
             *    3 - Arc Move IJ      [G2 X303.6584 Y78.2006 I-140.515 J-2.321]
             *    4 - Arc Move R
             *
             *   Machine
             *    10 - Delay
             *    11 - Pen Up
             *    12 - Pen Down
             *
             *   Coordinate
             *    20 - Absolute Programming [G90]
             *    21 - Incremental Programmming [G91]
             *
             *
             */

            if (input.getParameters().ContainsKey('G'))
            {
                switch ((int)input.getParameters()['G'])
                {
                case (0):     //G0
                    return(1);

                    break;

                case (1):     //G1
                    return(ClassifyLine(input));

                    break;

                case (2):     //G2 and G3
                case (3):
                    return(ClassifyArc(input));

                    break;

                case (4):     //G4
                    return(10);

                    break;
                }
            }
            else if (input.getParameters().ContainsKey('M'))
            {
                switch ((int)input.getParameters()['M'])
                {
                case (3):
                    if ((int)input.getParameters()['S'] == 0)      //Pen UP
                    {
                        return(11);
                    }
                    else
                    {
                        return(12);
                    }

                    break;

                case (4):     //G4
                    return(10);

                    break;
                }
            }
            else
            {
                return(-1);
            }

            return(-1);
        }
Example #8
0
        public GcodeArc(GCodeCommand command, bool drawn, SKPoint start, int classification)
        {
            this.OriginalCommand = command;
            this.PenDown         = drawn;


            /*
             * Regex Gcode = new Regex("[ngxyzfijrps][+-]?[0-9]*\\.?[0-9]*", RegexOptions.IgnoreCase);
             * MatchCollection m = Gcode.Matches(command);
             *
             * float x = 0;
             * float y = 0;
             * float i = 0;
             * float j = 0;
             * float r = float.NaN;
             *
             * foreach (var Parameter in m)
             * {
             *  char param = Parameter.ToString().ToUpper()[0];
             *
             *  switch (param)
             *  {
             *      case ('X'):
             *          x = float.Parse(Parameter.ToString().Substring(1));
             *          break;
             *      case ('Y'):
             *          y = float.Parse(Parameter.ToString().Substring(1));
             *          break;
             *      case ('I'):
             *          i = float.Parse(Parameter.ToString().Substring(1));
             *          break;
             *      case ('J'):
             *          j = float.Parse(Parameter.ToString().Substring(1));
             *          break;
             *      case ('R'):
             *          r = float.Parse(Parameter.ToString().Substring(1));
             *          break;
             *  }
             * }
             */


            End = new SKPoint((float)command.getParameters()['X'], (float)command.getParameters()['Y']);


            Start = start;
            //End = new SKPoint(x, y);
            //TODO: Arc Centerpoint control

            if (classification == 3)
            {
                Center    = new SKPoint((float)command.getParameters()['I'], (float)command.getParameters()['J']);
                CenterAbs = new SKPoint(Start.X + Center.X, Start.Y + Center.Y);
            }
            else
            {
                //TODO: R arc classification calculations
            }

            if ((int)command.getParameters()['G'] == 2)
            {
                ClockWise = true;
            }
            else
            {
                ClockWise = false;
            }

            DrawType = typeof(GcodeArc);
        }