Skip to content

Commit

Permalink
2.2 release candidate
Browse files Browse the repository at this point in the history
many improvements
-new GcodeViewer
-wrong interpolation of height map (serious)
-ability to translate toolpath
-ability to generate heightmaps from expressions for testing
and much more
  • Loading branch information
martin2250 committed Jul 22, 2015
1 parent d014c89 commit 5d68839
Show file tree
Hide file tree
Showing 26 changed files with 1,761 additions and 189 deletions.
2 changes: 1 addition & 1 deletion Bounds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace GrblHeightProbe2
{
class Bounds
public class Bounds
{
public float MinX { get; set; }
public float MaxX { get; set; }
Expand Down
201 changes: 201 additions & 0 deletions Forms/GCodePreview.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

112 changes: 112 additions & 0 deletions Forms/GCodePreview.Preview.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GrblHeightProbe2
{
partial class GCodePreview : Form
{
void RedrawPreview()
{
Stopwatch stopW = Stopwatch.StartNew();

if (pictureBox1.Image != null)
{
pictureBox1.Image.Dispose();
pictureBox1.Image = null;
}

Bounds dimensions = Commands.Dimensions();
dimensions.MinX -= 5;
dimensions.MaxX += 5;
dimensions.MinY -= 5;
dimensions.MaxY += 5;

float pxPerMM = Math.Min(
(float)pictureBox1.Width / dimensions.SizeX,
(float)pictureBox1.Height / dimensions.SizeY);

Bitmap b = new Bitmap((int)(dimensions.SizeX * pxPerMM), (int)(dimensions.SizeY * pxPerMM));

Graphics gfx = Graphics.FromImage(b);

gfx.Clear(Color.Snow);

float pensize = Math.Min(pictureBox1.Width, pictureBox1.Height) / 360f;
if (pensize < 1)
pensize = 1;

Pen straightPen = new Pen(Color.Black, pensize);
Pen rapidPen = new Pen(Color.Gray, pensize / 2f);
Pen arcPen = new Pen(Color.DarkBlue, pensize);

Func<float, float> getX = (x) => { return (x - dimensions.MinX) * pxPerMM; };
Func<float, float> getY = (y) => { return b.Height - (y - dimensions.MinY) * pxPerMM; };
Func<float, float> deg = (rad) => { return rad * 180 / (float)Math.PI; };

foreach (GCodeCommand command in Commands)
{
Arc arc = command as Arc;

if (arc != null)
{
//System.Drawing interprets angles in exactly the opposite of the "industry standard" System.Math way ... thanks for that MS
//countless hours of trial and error rearranging these few lines... don't you dare touch them
float start = 360 - deg(arc.StartAngle);
float end = 360 - deg(arc.EndAngle);

float sweepAngle = start - end;

if (sweepAngle < 0)
sweepAngle += 360;

if(arc.Direction == ArcDirection.CW)
{
sweepAngle = 360 - sweepAngle;
}
else
{
start = end;
}

gfx.DrawArc(arcPen,
getX(arc.Center.X - arc.Radius),
getY(arc.Center.Y + arc.Radius),
arc.Radius * 2 * pxPerMM,
arc.Radius * 2 * pxPerMM,
start,
sweepAngle
);
}

Straight str = command as Straight;

if (str != null)
{
gfx.DrawLine(str.Rapid ? rapidPen : straightPen,
getX(str.Start.X),
getY(str.Start.Y),
getX(str.End.X),
getY(str.End.Y)
);
}
}

gfx.Flush();

gfx.Dispose();
straightPen.Dispose();
rapidPen.Dispose();

pictureBox1.Image = b;

stopW.Stop();
Console.WriteLine("Updating GCode Preview: {0} ms", stopW.Elapsed.TotalMilliseconds);
}
}
}
Loading

0 comments on commit 5d68839

Please sign in to comment.