Example #1
0
        public void Paint(IOutputCommand output, object param)
        {
            var  commandstate    = new CommandState();
            bool haveseencurrent = Current == null;

            foreach (Command cmd in this)
            {
                if (!haveseencurrent)
                {
                    haveseencurrent = cmd == Current;
                }

                commandstate.IsSelected = haveseencurrent;
                cmd.SetCommandState(commandstate);
                cmd.Draw(output, commandstate, param);
            }
        }
Example #2
0
        public override string[] GetGCodeCommands(Point3D startfrom, CommandState state)
        {
            string[] ret;
            if (ParameterNo >= 0)
            {
                ret = new[]
                {
                    GCodeLineNumber(" ") + Code + ParameterNo.ToString() + " =" + GCodeAdd
                };
            }
            else
            {
                ret = new[]
                {
                    GCodeLineNumber(" ") + GCodeAdd
                };
            }

            return(ret);
        }
Example #3
0
        private bool EvaluateParameterValue(CommandState state, out double paramvalue)
        {
            var linestream = new CommandStream()
            {
                Line = GCodeAdd
            };
            var expressionparser = new GCodeExpressionParser(linestream)
            {
                ParameterValues = state.ParameterValues
            };

            expressionparser.Parse();
            if (expressionparser.IsError())
            {
                paramvalue = 0;
                return(false);
            }

            paramvalue = expressionparser.Answer;
            return(true);
        }
Example #4
0
        public bool TryGetVariable(char name, CommandState state, out double val)
        {
            Variable var = GetVariable(name);

            if (var?.Value != null)
            {
                val = var.Value.Value;
                return(true);
            }

            if (var?.Parameter != null)
            {
                if (var.ParameterIsTerm)
                {
                    var lineStream = new CommandStream()
                    {
                        Line = var.Parameter
                    };
                    var expressionParser = new GCodeExpressionParser(lineStream)
                    {
                        ParameterValues = state.ParameterValues
                    };
                    expressionParser.Parse();
                    if (!expressionParser.IsError())
                    {
                        val = expressionParser.Answer;
                        return(true);
                    }
                }
                else if (int.TryParse(var.Parameter, out int parameterNo) && state.ParameterValues.ContainsKey(parameterNo))
                {
                    val = state.ParameterValues[parameterNo];
                    return(true);
                }
            }

            val = 0;
            return(false);
        }
Example #5
0
        public override void Draw(IOutputCommand output, CommandState state, object param)
        {
            double I, J, K;

            if (!TryGetVariable('I', state, out I))
            {
                I = 0;
            }

            if (!TryGetVariable('J', state, out J))
            {
                J = 0;
            }

            if (!TryGetVariable('K', state, out K))
            {
                K = 0;
            }

            output.DrawArc(this, param, Convert(MoveType, state), CalculatedStartPosition, CalculatedEndPosition, new Point3D {
                X = I, Y = J, Z = K
            }, false, state.CurrentPane);
        }
Example #6
0
        public IEnumerable <string> ToStringList()
        {
            var list = new List <string>();

            Command last  = null;
            var     state = new CommandState();

            foreach (Command r in this)
            {
                string[] cmds = r.GetGCodeCommands(last?.CalculatedEndPosition, state);
                if (cmds != null)
                {
                    foreach (string str in cmds)
                    {
                        list.Add(str);
                    }
                }

                last = r;
            }

            return(list);
        }
Example #7
0
        public override Command[] ConvertCommand(CommandState state, ConvertOptions options)
        {
            if (!options.SubstG82)
            {
                return(base.ConvertCommand(state, options));
            }

            // from
            // G82 X-8.8900 Y3.8100  Z-0.2794 F400 R0.5000  P0.000000
            // next command with R and P G82 X-11.4300 Y3.8100
            // to
            // G00 X-8.8900 Y3.8100
            // G01 Z-0.2794 F400
            // (G04 P0)
            // G00 Z0.5000

            Variable r = GetVariable('R');

            if (r == null)
            {
                r = state.G82R;
            }
            else
            {
                state.G82R = r.ShallowCopy();
            }

            Variable p = GetVariable('P');

            if (p == null)
            {
                p = state.G82P;
            }
            else
            {
                state.G82P = p.ShallowCopy();
            }

            Variable z = GetVariable('Z');

            if (z == null)
            {
                z = state.G82Z;
            }
            else
            {
                state.G82Z = z.ShallowCopy();
            }

            var list = new List <Command>();

            var move1 = new G00Command();

            CopyVariable('X', move1);
            CopyVariable('Y', move1);
            list.Add(move1);

            var move2 = new G01Command();

            move2.AddVariable('Z', z);
            CopyVariable('F', move2);
            list.Add(move2);

            if (p != null && Math.Abs(p.Value ?? 0.0) > double.Epsilon)
            {
                var move3 = new G04Command();
                move3.AddVariable('P', p);
                list.Add(move3);
            }

            var move4 = new G00Command();

            move4.AddVariable('Z', r);
            list.Add(move4);

            return(list.ToArray());
        }
Example #8
0
 public virtual void Draw(IOutputCommand output, CommandState state, object param)
 {
     output.DrawLine(this, param, Convert(MoveType, state), CalculatedStartPosition, CalculatedEndPosition);
 }
Example #9
0
 public virtual Command[] ConvertCommand(CommandState state, ConvertOptions options)
 {
     return(new[] { this });
 }
Example #10
0
 public virtual void SetCommandState(CommandState state)
 {
 }