private void CreateHexagon(double x, double y, double radius) { if (radius < 0.000001) { return; // true black do nothing } if (radius * 2 < LaserSize) { CreateToSmallShape(x, y); return; } double rotateangel = Math.PI / 6.0; double startx = x + radius * Math.Cos(rotateangel); double starty = y + radius * Math.Sin(rotateangel); Command c = new G00Command(); c.AddVariable('X', ToGCode(startx - StartLaserDist)); c.AddVariable('Y', ToGCode(starty - StartLaserDist / 2)); Commands.Add(c); LaserOn(); //for (double rad = Math.PI / 3.0; rad < Math.PI * 2.0 + 0.1; rad += Math.PI / 3.0) for (double rad = 0; rad < Math.PI * 2.0 + 0.1; rad += Math.PI / 3.0) { double radrotated = rad + Math.PI / 6.0; c = new G01Command(); c.AddVariable('X', ToGCode(x + radius * Math.Cos(radrotated))); c.AddVariable('Y', ToGCode(y + radius * Math.Sin(radrotated))); Commands.Add(c); } }
private void LoadPenDown(Point3D pt) { if (LoadOptions.PenMoveType == LoadOptions.PenType.ZMove) { var r = new G01Command(); if (LoadOptions.EngravePosInParameter) { r.AddVariableParam('Z', "2", false); } else { r.AddVariable('Z', LoadOptions.EngravePosDown); } if (LoadOptions.EngraveDownSpeed.HasValue) { r.AddVariable('F', LoadOptions.EngraveDownSpeed.Value); _needSpeed = LoadOptions.MoveSpeed.HasValue; } Commands.AddCommand(r); } else // if (LoadOptions.PenMoveType == LoadInfo.PenType.Command) { LaserOn(); } AddCamBamPLine(); AddCamBamPoint(pt); }
private void CreateToSmallShape(double x, double y) { Command cc = new G00Command(); cc.AddVariable('X', ToGCode(x)); cc.AddVariable('Y', ToGCode(y)); Commands.Add(cc); LaserOn(); cc = new G01Command(); cc.AddVariable('X', ToGCode(x)); cc.AddVariable('Y', ToGCode(y)); Commands.Add(cc); }
protected void WriteGCode(System.Drawing.Bitmap b) { Bitmap = b; SizeX = b.Width; SizeY = b.Height; PixelSizeX = 25.4 / b.HorizontalResolution; PixelSizeY = 25.4 / b.VerticalResolution; ShiftX = (double)LoadOptions.LaserSize / 2.0; ShiftY = (double)LoadOptions.LaserSize / 2.0; if (!string.IsNullOrEmpty(LoadOptions.ImageWriteToFileName)) { b.Save(Environment.ExpandEnvironmentVariables(LoadOptions.ImageWriteToFileName), System.Drawing.Imaging.ImageFormat.Bmp); } AddComment("Image.Width", b.Width); AddComment("Image.Height", b.Width); AddComment("Image.HorizontalResolution(DPI)", b.HorizontalResolution); AddComment("Image.VerticalResolution(DPI)", b.VerticalResolution); AddComment("ImageInvert", LoadOptions.ImageInvert.ToString()); if (LoadOptions.MoveSpeed.HasValue) { var setSpeed = new G01Command(); setSpeed.AddVariable('F', LoadOptions.MoveSpeed.Value); Commands.Add(setSpeed); } WriteGCode(); }
private void CreateCircle(double x, double y, double radius) { if (radius < 0.000001) { return; // true black do nothing } if (radius * 2 < LaserSize) { CreateToSmallShape(x, y); return; } Command c = new G00Command(); c.AddVariable('X', ToGCode(x + radius - StartLaserDist)); c.AddVariable('Y', ToGCode(y)); Commands.Add(c); LaserOn(); c = new G01Command(); c.AddVariable('X', ToGCode(x + radius)); Commands.Add(c); c = new G03Command(); c.AddVariable('I', ToGCode(-radius)); Commands.Add(c); }
private void CreateDiamond(double x, double y, double hsizeX2, double hsizeY2) { if (hsizeX2 < 0.000001) { return; // true black do nothing } if (hsizeX2 * 2 < LaserSize) { CreateToSmallShape(x, y); return; } Command c = new G00Command(); c.AddVariable('X', ToGCode(x - hsizeX2 + StartLaserDist)); c.AddVariable('Y', ToGCode(y)); Commands.Add(c); LaserOn(); c = new G01Command(); c.AddVariable('X', ToGCode(x - hsizeX2)); c.AddVariable('Y', ToGCode(y)); Commands.Add(c); c = new G01Command(); c.AddVariable('X', ToGCode(x)); c.AddVariable('Y', ToGCode(y - hsizeY2)); Commands.Add(c); c = new G01Command(); c.AddVariable('X', ToGCode(x + hsizeX2)); c.AddVariable('Y', ToGCode(y)); Commands.Add(c); c = new G01Command(); c.AddVariable('X', ToGCode(x)); c.AddVariable('Y', ToGCode(y + hsizeY2)); Commands.Add(c); c = new G01Command(); c.AddVariable('X', ToGCode(x - hsizeX2)); c.AddVariable('Y', ToGCode(y)); Commands.Add(c); }
public override void Load() { PreLoad(); var list = ReadHpglCommandList(); RemoveFirstPenUp(list); RemoveLastPenUp(list); Smooth.CalculateAngles(list, null); if (LoadOptions.AutoScale) { var autoScale = new AutoScale { LoadOptions = LoadOptions, LoadX = this }; autoScale.AutoScaleList(list); } if (LoadOptions.SmoothType != LoadOptions.SmoothTypeEnum.NoSmooth) { var smooth = new Smooth { LoadOptions = LoadOptions, LoadX = this }; list = smooth.SmoothList(list); } if (LoadOptions.ConvertType != LoadOptions.ConvertTypeEnum.NoConvert) { var invert = new InvertLine { LoadOptions = LoadOptions, LoadX = this }; list = invert.ConvertInvert(list); } AddComment("PenMoveType", LoadOptions.PenMoveType.ToString()); switch (LoadOptions.PenMoveType) { case LoadOptions.PenType.CommandString: AddCommentForLaser(); break; case LoadOptions.PenType.ZMove: AddComment("PenDownSpeed", LoadOptions.EngraveDownSpeed); AddComment("PenUpPos", LoadOptions.EngravePosUp); AddComment("PenDownPos", LoadOptions.EngravePosDown); break; } AddComment("Speed", LoadOptions.MoveSpeed.ToString()); if (LoadOptions.PenMoveType == LoadOptions.PenType.ZMove) { AddCommands("M3"); if (LoadOptions.EngravePosInParameter) { Commands.AddCommand( new SetParameterCommand { ParameterNo = 1, GCodeAdd = LoadOptions.EngravePosUp.ToString(CultureInfo.InvariantCulture) }); Commands.AddCommand( new SetParameterCommand { ParameterNo = 2, GCodeAdd = LoadOptions.EngravePosDown.ToString(CultureInfo.InvariantCulture) }); } } if (LoadOptions.MoveSpeed.HasValue) { var setSpeed = new G01Command(); setSpeed.AddVariable('F', LoadOptions.MoveSpeed.Value); Commands.Add(setSpeed); } foreach (var cmd in list) { if (!Command(cmd)) { Commands.Clear(); break; } } if (!_lastIsPenUp) { LoadPenUp(); } if (LoadOptions.PenMoveType == LoadOptions.PenType.ZMove) { AddCommands("M5"); } PostLoad(); }
private void CreateHeart(double x, double y, double hsizeX2, double hsizeY2, bool mirror) { if (hsizeX2 < 0.000001) { return; // true black do nothing } if (hsizeX2 * 2 < LaserSize) { CreateToSmallShape(x, y); return; } hsizeX2 *= 0.9; hsizeY2 = hsizeX2; double mr = mirror ? -1.0 : 1.0; Command c = new G00Command(); c.AddVariable('X', ToGCode(x)); c.AddVariable('Y', ToGCode(y + (hsizeY2 - StartLaserDist) * mr)); Commands.Add(c); LaserOn(); c = new G01Command(); c.AddVariable('X', ToGCode(x)); c.AddVariable('Y', ToGCode(y + hsizeY2 * mr)); Commands.Add(c); if (mirror) { c = new G03Command(); } else { c = new G02Command(); } c.AddVariable('X', ToGCode(x + hsizeX2)); c.AddVariable('Y', ToGCode(y)); c.AddVariable('I', ToGCode(hsizeX2 / 2.0)); c.AddVariable('J', ToGCode(-hsizeY2 / 2.0 * mr)); Commands.Add(c); c = new G01Command(); c.AddVariable('X', ToGCode(x)); c.AddVariable('Y', ToGCode(y - hsizeY2 * mr)); Commands.Add(c); c = new G01Command(); c.AddVariable('X', ToGCode(x - hsizeX2)); c.AddVariable('Y', ToGCode(y)); Commands.Add(c); if (mirror) { c = new G03Command(); } else { c = new G02Command(); } c.AddVariable('X', ToGCode(x)); c.AddVariable('Y', ToGCode(y + hsizeY2 * mr)); c.AddVariable('I', ToGCode(hsizeX2 / 2.0)); c.AddVariable('J', ToGCode(hsizeY2 / 2.0 * mr)); Commands.Add(c); }