avisocncgcodewriter.pas 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. {
  2. Writes AvisoCNC G-Code
  3. License: The same modified LGPL as the Free Pascal RTL
  4. See the file COPYING.modifiedLGPL for more details
  5. AUTHORS: Felipe Monteiro de Carvalho
  6. Pedro Sol Pegorini L de Lima
  7. }
  8. unit avisocncgcodewriter;
  9. {$mode objfpc}{$H+}
  10. interface
  11. uses
  12. Classes, SysUtils,
  13. fpvectorial;
  14. type
  15. { TvAvisoCNCGCodeWriter }
  16. TvAvisoCNCGCodeWriter = class(TvCustomVectorialWriter)
  17. public
  18. { General reading methods }
  19. procedure WriteToStrings(AStrings: TStrings; AData: TvVectorialDocument); override;
  20. end;
  21. implementation
  22. { TvGCodeVectorialWriter }
  23. procedure TvAvisoCNCGCodeWriter.WriteToStrings(AStrings: TStrings;
  24. AData: TvVectorialDocument);
  25. var
  26. i, j: Integer;
  27. Str: string;
  28. APath: TPath;
  29. begin
  30. AStrings.Clear;
  31. AStrings.Add('M216 // Ligar monitor de carga');
  32. AStrings.Add('G28 // Ir rapidamente para posição inicial');
  33. AStrings.Add('G00');
  34. // itera por todos os itens
  35. for i := 0 to AData.GetPathCount - 1 do
  36. begin
  37. APath := AData.GetPath(i);
  38. // levanta a broca
  39. AStrings.Add('P01 // Sobe a cabeça de gravação');
  40. // vai para o ponto inicial
  41. AStrings.Add(Format('G01 X%f Y%f',
  42. [APath.Points[0].X, APath.Points[0].Y]));
  43. AStrings.Add('P02 // Abaixa a cabeça de gravação');
  44. for j := 1 to APath.Len - 1 do
  45. begin
  46. case APath.Points[j].SegmentType of
  47. st2DLine: AStrings.Add(Format('G01 X%f Y%f',
  48. [APath.Points[j].X, APath.Points[j].Y]));
  49. st3DLine: AStrings.Add(Format('G01 X%f Y%f Z%f',
  50. [APath.Points[j].X, APath.Points[j].Y, APath.Points[j].Z]));
  51. st2DBezier: AStrings.Add(Format('B02 X%f Y%f X%f Y%f X%f Y%f',
  52. [APath.Points[j].X2, APath.Points[j].Y2,
  53. APath.Points[j].X3, APath.Points[j].Y3,
  54. APath.Points[j].X, APath.Points[j].Y]));
  55. st3DBezier: AStrings.Add(Format('B03 X%f Y%f Z%f X%f Y%f Z%f X%f Y%f Z%f',
  56. [APath.Points[j].X2, APath.Points[j].Y2, APath.Points[j].Z2,
  57. APath.Points[j].X3, APath.Points[j].Y3, APath.Points[j].Z3,
  58. APath.Points[j].X, APath.Points[j].Y, APath.Points[j].Z]));
  59. end;
  60. end;
  61. end;
  62. AStrings.Add('P01 // Sobe a cabeça de gravação');
  63. AStrings.Add('M30 // Parar o programa e retornar para posição inicial');
  64. AStrings.Add('M215 // Desligar monitor de carga');
  65. end;
  66. initialization
  67. RegisterVectorialWriter(TvAvisoCNCGCodeWriter, vfGCodeAvisoCNCPrototipoV5);
  68. end.