Ejemplo n.º 1
0
 protected virtual void InitFrame()
 {
     if (Program.Count <= FrameNumber)
     {
         ProgramEnded(this, EventArgs.Empty);
         return;
     }
     SetOldCoordinates(CurrentCoordinates);
     CurrentFrame       = Program[FrameNumber];
     CurrentCoordinates = CurrentFrame.Coordinate;
     UpdateModalGCodes(CurrentFrame.GCodes.ToHashSet());
     UpdateNonModalGCodes(CurrentFrame.GCodes.ToHashSet());
     UpdateModalMCodes(CurrentFrame.MCodes.ToHashSet());
     UpdateNonModalMCodes(CurrentFrame.MCodes.ToHashSet());
     if (CurrentFrame.Feedrate.HasValue)
     {
         FeedRate = CurrentFrame.Feedrate.Value;
     }
     CurrentMCodes.Clear();
     CurrentMCodes.UnionWith(CurrentFrame.MCodes);
     ToolNumber = CurrentFrame.ToolNumber ?? ToolNumber;
     FrameChanged(this, new FrameChangedEventArgs(FrameNumber, CurrentFrame));
 }
Ejemplo n.º 2
0
        public override string ToString()
        {
            var builder = new StringBuilder();

            if (ModalGCodes != null && ModalGCodes.Count > 0)
            {
                if (ModalGCodes.Count > 1)
                {
                    builder.Append(ModalGCodes.Select(c => $"G{c}").Aggregate((s1, s2) => $"{s1} {s2} "));
                }
                else
                {
                    builder.Append($"G{ModalGCodes.First().ToString(CultureInfo.InvariantCulture)} ");
                }
            }
            if (CurrentGCodes != null && CurrentGCodes.Count > 0)
            {
                if (CurrentGCodes.Count > 1)
                {
                    builder.Append(CurrentGCodes.Select(c => $"G{c}").Aggregate((s1, s2) => $"{s1} {s2} "));
                }
                else
                {
                    builder.Append($"G{CurrentGCodes.First().ToString(CultureInfo.InvariantCulture)} ");
                }
            }

            builder.Append($"T{ToolNumber} ");
            builder.Append($"F{FeedRate} ");

            if (ModalMCodes != null && ModalMCodes.Count > 0)
            {
                if (ModalGCodes.Count > 1)
                {
                    builder.Append(ModalMCodes.Select(c => $"M{c}").Aggregate((s1, s2) => $"{s1} {s2} "));
                }
                else
                {
                    builder.Append($"M{ModalMCodes.First().ToString(CultureInfo.InvariantCulture)} ");
                }
            }
            if (CurrentMCodes != null && CurrentMCodes.Count > 0)
            {
                if (CurrentMCodes.Count > 1)
                {
                    builder.Append(CurrentMCodes.Select(c => $"M{c}").Aggregate((s1, s2) => $"{s1} {s2} "));
                }
                else
                {
                    builder.Append($"M{CurrentMCodes.First().ToString(CultureInfo.InvariantCulture)} ");
                }
            }

            var x = CurrentCoordinates.X.HasValue ? $"X{CurrentCoordinates.X.Value} " : string.Empty;
            var y = CurrentCoordinates.Y.HasValue ? $"Y{CurrentCoordinates.Y.Value} " : string.Empty;
            var i = CurrentFrame.IValue.HasValue ? $"I{CurrentFrame.IValue.Value} " : string.Empty;
            var j = CurrentFrame.JValue.HasValue ? $"J{CurrentFrame.JValue.Value} " : string.Empty;
            var r = CurrentFrame.RValue.HasValue ? $"R{CurrentFrame.RValue.Value} " : string.Empty;

            builder.Append($"{x}{y}{i}{j}{r}");

            return(builder.ToString());
        }