Skip to content

Commit

Permalink
add rotate button to edit tab
Browse files Browse the repository at this point in the history
  • Loading branch information
martin2250 committed Dec 24, 2018
1 parent 6bfd824 commit e9eabf1
Show file tree
Hide file tree
Showing 4 changed files with 375 additions and 302 deletions.
56 changes: 56 additions & 0 deletions OpenCNCPilot/GCode/GCodeFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,5 +377,61 @@ public GCodeFile ApplyHeightMap(HeightMap map)

return new GCodeFile(newToolPath);
}

public GCodeFile RotateCW()
{
List<Command> newFile = new List<Command>();

foreach (Command oldCommand in Toolpath)
{
if (oldCommand is Motion)
{
Motion oldMotion = (Motion)oldCommand;
Motion newMotion;

if (oldCommand is Arc)
{
Arc oldArc = (Arc)oldMotion;
Arc newArc = new Arc();

// would be possible, but I'm too lazy to implement this properly
if (oldArc.Plane != ArcPlane.XY)
throw new Exception("GCode contains arcs in YZ or XZ plane (G18/19), can't rotate gcode. Use Arcs to Lines if you really need this.");

newArc.Direction = oldArc.Direction;
newArc.Plane = oldArc.Plane;
newArc.U = oldArc.V;
newArc.V = -oldArc.U;
newMotion = newArc;
}
else if (oldCommand is Line)
{
Line oldLine = (Line)oldMotion;
Line newLine = new Line();
newLine.Rapid = oldLine.Rapid;
newMotion = newLine;
}
else
throw new Exception("this shouldn't happen, please contact the autor on GitHub");

newMotion.Start = oldMotion.Start;
newMotion.End = oldMotion.End;
newMotion.Start.X = oldMotion.Start.Y;
newMotion.Start.Y = -oldMotion.Start.X;
newMotion.End.X = oldMotion.End.Y;
newMotion.End.Y = -oldMotion.End.X;

newMotion.Feed = oldMotion.Feed;

newFile.Add(newMotion);
}
else
{
newFile.Add(oldCommand);
}
}

return new GCodeFile(newFile);
}
}
}
Loading

0 comments on commit e9eabf1

Please sign in to comment.