private void UpdateFS(GrblCommand cmd)
            {
                if (cmd is JogCommand)
                {
                    return;
                }

                mCurF.Update(cmd.F);
                mCurS.Update(cmd.S);
            }
 private decimal GetSegmentLenght(GrblCommand cmd)
 {
     if (cmd.IsLinearMovement)
     {
         return(Tools.MathHelper.LinearDistance(mCurX.Previous, mCurY.Previous, mCurX.Number, mCurY.Number));
     }
     else if (cmd.IsArcMovement)                 //arc of given radius
     {
         return((decimal)GetArcHelper(cmd).AbsLenght);
     }
     else
     {
         return(0);
     }
 }
 private void UpdateXYZ(GrblCommand cmd)
 {
     if (cmd is JogCommand)
     {
         mCurX.Update(cmd.X, cmd.IsAbsoluteCoord, mWcoX);
         mCurY.Update(cmd.Y, cmd.IsAbsoluteCoord, mWcoY);
         mCurZ.Update(cmd.Z, cmd.IsAbsoluteCoord, mWcoZ);
     }
     else if (cmd.IsMovement)
     {
         mCurX.Update(cmd.X, ABS, mWcoX);
         mCurY.Update(cmd.Y, ABS, mWcoY);
         mCurZ.Update(cmd.Z, ABS, mWcoZ);
     }
 }
 private void UpdateWCO(GrblCommand cmd)
 {
     if (cmd.IsSetWCO)
     {
         if (cmd.X != null)
         {
             mWcoX = mCurX.Number - cmd.X.Number;
         }
         if (cmd.Y != null)
         {
             mWcoY = mCurY.Number - cmd.Y.Number;
         }
         if (cmd.Z != null)
         {
             mWcoZ = mCurZ.Number - cmd.Z.Number;
         }
     }
 }
            //private void UpdateModals(GrblCommand cmd) //update modals - BUILD IF NEEDED
            //{
            //	bool delete = !cmd.JustBuilt;
            //	if (!cmd.JustBuilt) cmd.BuildHelper();

            //	UpdateModalsNB(cmd);

            //	if (delete) cmd.DeleteHelper();
            //}

            protected void UpdateModalsNB(GrblCommand cmd)             //update modals - EXTERNAL BUILD
            {
                if (cmd is JogCommand)
                {
                    return;
                }

                MotionMode.Update(cmd.G);
                CoordinateSelect.Update(cmd.G);
                PlaneSelect.Update(cmd.G);
                DistanceMode.Update(cmd.G);
                ArcDistanceMode.Update(cmd.G);
                FeedRateMode.Update(cmd.G);
                CutterRadiusCompensation.Update(cmd.G);
                ToolLengthOffset.Update(cmd.G);

                ProgramMode.Update(cmd.M);
                CoolantState.Update(cmd.M);
                SpindleState.Update(cmd.M);
            }
            private TimeSpan ComputeExecutionTime(GrblCommand cmd, GrblConf conf)
            {
                decimal f = cmd is JogCommand && cmd.F != null ? cmd.F.Number : mCurF.Number;

                if (G0 && cmd.IsLinearMovement)
                {
                    return(TimeSpan.FromMinutes((double)GetSegmentLenght(cmd) / (double)conf.MaxRateX));                    //todo: use a better computation of xy if different x/y max speed
                }
                else if (G1G2G3 && cmd.IsMovement && f != 0)
                {
                    return(TimeSpan.FromMinutes((double)GetSegmentLenght(cmd) / (double)Math.Min(f, conf.MaxRateX)));
                }
                else if (cmd.IsPause)
                {
                    return(cmd.P != null?TimeSpan.FromSeconds((double)cmd.P.Number) : cmd.S != null?TimeSpan.FromSeconds((double)cmd.S.Number) : TimeSpan.Zero);
                }
                else
                {
                    return(TimeSpan.Zero);
                }
            }
            public TimeSpan AnalyzeCommand(GrblCommand cmd, bool compute, GrblConf conf = null)
            {
                bool delete = !cmd.JustBuilt;

                if (!cmd.JustBuilt)
                {
                    cmd.BuildHelper();
                }

                UpdateModalsNB(cmd);
                UpdateWCO(cmd);
                UpdateXYZ(cmd);
                UpdateFS(cmd);

                TimeSpan rv = compute ? ComputeExecutionTime(cmd, conf) : TimeSpan.Zero;

                if (delete)
                {
                    cmd.DeleteHelper();
                }

                return(rv);
            }
 public GrblCommand(Element first, GrblCommand toappend)
 {
     mLine = string.Format("{0} {1}", first, toappend.mLine);
 }
 internal G2G3Helper GetArcHelper(GrblCommand cmd)
 {
     return(new G2G3Helper(this, cmd));
 }