Skip to content

Commit

Permalink
Improve parser warnings
Browse files Browse the repository at this point in the history
close #92
  • Loading branch information
martin2250 committed Mar 26, 2019
1 parent 1da9910 commit 7d19d07
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 8 deletions.
4 changes: 2 additions & 2 deletions OpenCNCPilot/GCode/GCodeCommands/Command.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace OpenCNCPilot.GCode.GCodeCommands
{
public interface Command
public abstract class Command
{

public int LineNumber = -1;
}
}
2 changes: 1 addition & 1 deletion OpenCNCPilot/GCode/GCodeFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private GCodeFile(List<Command> toolpath)

if (m.Start == m.End)
{
Warnings.Add($"ignoring empty move at position {i} (not equal to line number)");
Warnings.Add($"ignoring zero-length move from line number {m.LineNumber}");
toolpath.RemoveAt(i--);
}
}
Expand Down
8 changes: 5 additions & 3 deletions OpenCNCPilot/GCode/GCodeParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ static void Parse(string line, int lineNumber)
if (param != Words[i].Parameter || param < 0)
throw new ParseException("M code can only have positive integer parameters", lineNumber);

Commands.Add(new MCode() { Code = param });
Commands.Add(new MCode() { Code = param, LineNumber = lineNumber });

Words.RemoveAt(i);
i--;
Expand All @@ -192,7 +192,7 @@ static void Parse(string line, int lineNumber)
if (param < 0)
Warnings.Add($"spindle speed must be positive. (line {lineNumber})");

Commands.Add(new Spindle() { Speed = Math.Abs(param) });
Commands.Add(new Spindle() { Speed = Math.Abs(param), LineNumber = lineNumber });

Words.RemoveAt(i);
i--;
Expand Down Expand Up @@ -274,7 +274,7 @@ static void Parse(string line, int lineNumber)
if (Words[i + 1].Parameter < 0)
Warnings.Add($"dwell time must be positive. (line {lineNumber})");

Commands.Add(new Dwell() { Seconds = Math.Abs(Words[i + 1].Parameter) });
Commands.Add(new Dwell() { Seconds = Math.Abs(Words[i + 1].Parameter), LineNumber = lineNumber });
Words.RemoveAt(i + 1);
Words.RemoveAt(i);
i--;
Expand Down Expand Up @@ -373,6 +373,7 @@ static void Parse(string line, int lineNumber)
motion.End = EndPos;
motion.Feed = State.Feed;
motion.Rapid = MotionMode == 0;
motion.LineNumber = lineNumber;
State.PositionValid.CopyTo(motion.PositionValid, 0);

Commands.Add(motion);
Expand Down Expand Up @@ -542,6 +543,7 @@ static void Parse(string line, int lineNumber)
arc.Direction = (MotionMode == 2) ? ArcDirection.CW : ArcDirection.CCW;
arc.U = U;
arc.V = V;
arc.LineNumber = lineNumber;
arc.Plane = State.Plane;

Commands.Add(arc);
Expand Down
6 changes: 4 additions & 2 deletions OpenCNCPilot/MainWindow.xaml.MachineStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,12 @@ private void Machine_FileChanged()

if (ToolPath.Warnings.Count > 0)
{
MessageBox.Show(@"Warning! There were some errors while parsing this file!
WarningWindow ww = new WarningWindow(@"Warning! Parsing this file resulted in some warnings!
Do not use OpenCNCPilot's edit functions unless you are sure that these warnings can be ignored!
If you use edit functions, check the output file for errors before running the gcode!
Be aware that the affected lines will likely move when using edit functions" + "\n\n >" + string.Join("\n >", ToolPath.Warnings));
Be aware that the affected lines will likely move when using edit functions." + "\n\n", ToolPath.Warnings);

ww.ShowDialog();
}

if (Properties.Settings.Default.EnableCodePreview)
Expand Down
7 changes: 7 additions & 0 deletions OpenCNCPilot/OpenCNCPilot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@
<Compile Include="Util\UpdateCheck.cs" />
<Compile Include="Util\Vector2.cs" />
<Compile Include="Util\Vector3.cs" />
<Compile Include="WarningWindow.xaml.cs">
<DependentUpon>WarningWindow.xaml</DependentUpon>
</Compile>
<Page Include="EditMacroItemWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -182,6 +185,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="WarningWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
Expand Down
15 changes: 15 additions & 0 deletions OpenCNCPilot/WarningWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Window x:Class="OpenCNCPilot.WarningWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:OpenCNCPilot"
mc:Ignorable="d"
Title="Warnings" Height="450" Width="800">
<Grid>
<TextBox Name="TextBlockWarnings" Margin="5,5,5,35" HorizontalAlignment="Stretch" ScrollViewer.VerticalScrollBarVisibility="Auto" IsReadOnly="True"/>
<!--<ScrollViewer Margin="5,5,5,35" HorizontalAlignment="Stretch" IsDeferredScrollingEnabled="True">
</ScrollViewer>-->
<Button Content="Ok" Margin="0,0,10,10" HorizontalAlignment="Right" Width="75" Height="20" VerticalAlignment="Bottom" Click="Button_Click"/>
</Grid>
</Window>
31 changes: 31 additions & 0 deletions OpenCNCPilot/WarningWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Collections.Generic;
using System.Text;
using System.Windows;

namespace OpenCNCPilot
{
public partial class WarningWindow : Window
{
public WarningWindow(string header, IEnumerable<string> warnings)
{
InitializeComponent();

StringBuilder b = new StringBuilder(header);
int i = 1;

foreach (string warning in warnings)
{
b.Append(i++);
b.Append(" > ");
b.AppendLine(warning);
}

TextBlockWarnings.Text = b.ToString();
}

private void Button_Click(object sender, RoutedEventArgs e)
{
Close();
}
}
}

0 comments on commit 7d19d07

Please sign in to comment.