Skip to content

Commit de05d7f

Browse files
authored
Version 1.7.5.3
1 parent 39100f2 commit de05d7f

File tree

4 files changed

+57
-43
lines changed

4 files changed

+57
-43
lines changed

GRBL-Plotter/GCodeCreation/Graphic2GCode.cs

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* GRBL-Plotter. Another GCode sender for GRBL.
22
This file is part of the GRBL-Plotter application.
33
4-
Copyright (C) 2019-2024 Sven Hasemann contact: [email protected]
4+
Copyright (C) 2019-2025 Sven Hasemann contact: [email protected]
55
66
This program is free software: you can redistribute it and/or modify
77
it under the terms of the GNU General Public License as published by
@@ -49,6 +49,7 @@ You should have received a copy of the GNU General Public License
4949
* 2024-03-19 l:970 f:MoveToDashed avoid intermediate G0 coordinates
5050
* 2024-04-13 l:438 f:ProcessPathLength new function
5151
* 2024-06-22 l:1116 f:arc tangential
52+
* 2025-03-30 l:374 f:CreateGCode create code if path is empty
5253
*/
5354

5455
using System;
@@ -128,7 +129,7 @@ public static void Init()
128129

129130
gcodeComments = Properties.Settings.Default.importGCAddComments;
130131

131-
Logger.Trace("▽▽▽Graphic2GCode - Init loggerTrace:{0}", Convert.ToString(logFlags, 2));
132+
Logger.Trace("▽▽▽ Graphic2GCode - Init loggerTrace:{0}", Convert.ToString(logFlags, 2));
132133

133134
pauseBeforePath = Properties.Settings.Default.importPauseElement;
134135
pauseBeforePenDown = Properties.Settings.Default.importPausePenDown;
@@ -301,7 +302,7 @@ internal static bool CreateGCode(List<Graphic.GroupObject> completeGraphic, List
301302
string toolColor = ToolTable.GetToolColor(toolToUse);
302303
double toolWidth = ToolTable.GetToolDiameter(toolToUse); // 2024-01-07 #370
303304
pathObject.Info.GroupAttributes[(int)GroupOption.ByColor] = toolColor;
304-
pathObject.Info.GroupAttributes[(int)GroupOption.ByWidth] = string.Format("{0:0.000}",toolWidth); // 2024-01-07 #370
305+
pathObject.Info.GroupAttributes[(int)GroupOption.ByWidth] = string.Format("{0:0.000}", toolWidth); // 2024-01-07 #370
305306
}
306307
ProcessPathObject(pathObject, graphicInfo, -1, ""); // create Dot or Path GCode, but no tool change
307308
}
@@ -369,7 +370,14 @@ internal static bool CreateGCode(List<Graphic.PathObject> completeGraphic, List<
369370
string toolName;
370371
string toolColor;
371372
double toolWidth;
372-
if (completeGraphic == null) return false;
373+
if ((completeGraphic == null) || (completeGraphic.Count == 0))
374+
{
375+
Gcode.JobStart(finalGcodeString, "StartJob");
376+
Gcode.AddToHeader(" ⚠⚠⚠⚠⚠ No graphics path to export! ⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠");
377+
Gcode.Comment(finalGcodeString, " ⚠⚠⚠⚠⚠ No graphics path to export! ⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠");
378+
Gcode.JobEnd(finalGcodeString, "EndJob"); // Spindle / laser off
379+
return FinalGCode(graphicInfo.Title, graphicInfo.FilePath);
380+
}
373381

374382
if (!graphicInfo.FigureEnable) // proforma figure tag
375383
{
@@ -442,7 +450,7 @@ internal static bool CreateGCode(List<Graphic.PathObject> completeGraphic, List<
442450
private static void ProcessPathLength(double valPD, double valPU)
443451
{
444452
//SetComment(string.Format("Path length: {0:0.00}", val));
445-
Gcode.gcodeDistancePD=valPD;
453+
Gcode.gcodeDistancePD = valPD;
446454
Gcode.gcodeDistancePU = valPU;
447455
Logger.Info("Path length PD:{0:0.00} PU:{0:0.00}", valPD, valPU);
448456
}
@@ -467,15 +475,16 @@ private static void ProcessPathObject(PathObject pathObject, Graphic.GraphicInfo
467475
if (DotData.UseZ)
468476
{
469477
double setZ = CalculateZFromRange(graphicInfo.DotZMin, graphicInfo.DotZMax, DotData.OptZ);//-Math.Abs(DotData.Z); // be sure for right sign
470-
if (logEnable)
471-
Logger.Trace("---Dot DotData.UseZ: RangeMin:{0:0.00} RangeMax:{1:0.00} DotData.Z:{2:0.00} -> setZ:{3:0.00}", graphicInfo.DotZMin, graphicInfo.DotZMax, DotData.OptZ, setZ);
472478
setZ = Math.Max(origZ, setZ); // don't go deeper than set Z
473479
if (logCoordinates) Logger.Trace(" PenDownWithZ z:{0:0.00} setZ:{1:0.00} gcodeZDown:{2:0.00}", DotData.OptZ, setZ, origZ);
474480
Gcode.GcodeZDown = (float)setZ;
475481

476482
double newS = CalculateSFromRange(graphicInfo.DotZMin, graphicInfo.DotZMax, DotData.OptZ);
477483
Gcode.GcodePwmDown = Gcode.GcodeSpindleSpeed = (float)newS; //???
478-
484+
if (logEnable)
485+
{
486+
Logger.Trace("---Dot DotData.UseZ: RangeMin:{0:0.00} RangeMax:{1:0.00} DotData.Z:{2:0.00} -> setZ:{3:0.00} -> setS:{4:0.00}", graphicInfo.DotZMin, graphicInfo.DotZMax, DotData.OptZ, setZ, newS);
487+
}
479488
penIsDown = false;
480489
}
481490
else if (graphicInfo.OptionZFromWidth)
@@ -589,13 +598,13 @@ private static void ProcessPathObject(PathObject pathObject, Graphic.GraphicInfo
589598
/* Create Line */
590599
if (entity is GCodeLine)
591600
{
592-
// Logger.Trace("# MoveTo {0:0.0} Angle:{1:0.0}", entity.MoveTo, (entity.Angle * 180 / Math.PI));
601+
// Logger.Trace("# MoveTo {0:0.0} Angle:{1:0.0}", entity.MoveTo, (entity.Angle * 180 / Math.PI));
593602
MoveTo(entity.MoveTo, newZ, newS, entity.Angle, "");
594603
}
595604
else if (entity is GCodeArc ArcData)
596605
{
597606
/* Create Arc */
598-
// Logger.Trace("# ArcTo {0:0.0} AngleStart:{1:0.0} Angle:{2:0.0}", ArcData.MoveTo, ArcData.AngleStart * 180 / Math.PI, ArcData.Angle * 180 / Math.PI);
607+
// Logger.Trace("# ArcTo {0:0.0} AngleStart:{1:0.0} Angle:{2:0.0}", ArcData.MoveTo, ArcData.AngleStart * 180 / Math.PI, ArcData.Angle * 180 / Math.PI);
599608
Arc(ArcData.IsCW, ArcData.MoveTo, ArcData.CenterIJ, ArcData.AngleStart, ArcData.Angle);//, "");// entity.comment);
600609
}
601610
}
@@ -797,7 +806,7 @@ private static StringBuilder GetFigureAttributes(PathObject pathObject)
797806
private static int StartPath(PathObject pathObject, int toolNr, string toolCmt, string penCmt = "")//string cmt)
798807
{
799808
double lengthPU = GcodeMath.DistancePointToPoint(GlobalPathStart, pathObject.Start);
800-
// Logger.Trace("StartPath Length:{0:0.0} from:{1:0.0} to:{2:0.0}", lengthPU, GlobalPathStart, pathObject.Start);
809+
// Logger.Trace("StartPath Length:{0:0.0} from:{1:0.0} to:{2:0.0}", lengthPU, GlobalPathStart, pathObject.Start);
801810
GlobalPathLengthPU += lengthPU;
802811

803812
Point startRamp = pathObject.Start;
@@ -1012,7 +1021,7 @@ private static void MoveToDashed(Point coordxy)
10121021
double ddx, ddy; // dash distance
10131022
string dashInfo = "";
10141023
Point pNext;
1015-
Point pPenUp = coordxy;
1024+
Point pPenUp = coordxy;
10161025

10171026
while (dToGo > 0)
10181027
{
@@ -1039,9 +1048,9 @@ private static void MoveToDashed(Point coordxy)
10391048
else
10401049
{
10411050
if (logCoordinates) Logger.Trace(" 1 PenDown");
1042-
1043-
if (penUpG1) Gcode.MoveToNoFeed(gcodeString, pPenUp, dashInfo);
1044-
else Gcode.MoveToRapid(gcodeString, pPenUp, dashInfo);
1051+
1052+
if (penUpG1) Gcode.MoveToNoFeed(gcodeString, pPenUp, dashInfo);
1053+
else Gcode.MoveToRapid(gcodeString, pPenUp, dashInfo);
10451054

10461055
PenDown("MoveToDashed"); PathDashArrayPenIsUp = false;
10471056
}
@@ -1074,9 +1083,9 @@ private static void MoveToDashed(Point coordxy)
10741083
{
10751084
if (gcodeComments) dashInfo = "pen-up dash:" + dashInfo;
10761085
if (logCoordinates) Logger.Trace(" 3 MoveTo PenUp x:{0:0.00} y:{1:0.00} dToGo:{2:0.000} PathDashArrayDistance:{3:0.000}", pNext.X, pNext.Y, dToGo, PathDashArrayDistance);
1077-
pPenUp = new Point(pNext.X, pNext.Y);
1078-
// if (penUpG1) Gcode.MoveToNoFeed(gcodeString, pNext, dashInfo);
1079-
// else Gcode.MoveToRapid(gcodeString, pNext, dashInfo);
1086+
pPenUp = new Point(pNext.X, pNext.Y);
1087+
// if (penUpG1) Gcode.MoveToNoFeed(gcodeString, pNext, dashInfo);
1088+
// else Gcode.MoveToRapid(gcodeString, pNext, dashInfo);
10801089
}
10811090
else
10821091
{
@@ -1105,7 +1114,7 @@ private static void Arc(int gnr, double x, double y, double i, double j, double
11051114
Gcode.SetAux1DistanceCommand(setAux1FinalDistance);
11061115
Gcode.SetAux2DistanceCommand(setAux2FinalDistance);
11071116

1108-
if (logCoordinates) Logger.Trace(" Start Arc alpha{0:0.000} offset{1:0.000} ", 180 * tangStartRad / Math.PI, 180 * offset / Math.PI);
1117+
if (logCoordinates) Logger.Trace(" Start Arc alpha{0:0.000} offset{1:0.000} ", 180 * tangStartRad / Math.PI, 180 * offset / Math.PI);
11091118

11101119
PenDown(cmt + " from Arc");
11111120

@@ -1128,7 +1137,7 @@ private static void Arc(int gnr, double x, double y, double i, double j, double
11281137
/// </summary>
11291138
private static bool FinalGCode(string titel, string file)
11301139
{
1131-
Logger.Trace("△△△Graphic2GCode - FinalGCode() ");
1140+
Logger.Trace("△△△ Graphic2GCode - FinalGCode() ");
11321141
StringBuilder header = new StringBuilder();
11331142
StringBuilder footer = new StringBuilder(Gcode.GetFooter());
11341143
StringBuilder output = new StringBuilder();
@@ -1182,6 +1191,7 @@ private static bool FinalGCode(string titel, string file)
11821191
header.Append(String.Join("\n", lines));
11831192
}
11841193
Graphic.GCode = header.Replace(',', '.');
1194+
// Logger.Trace("end Graphic2GCode - FinalGCode() {0}", Graphic.GCode.ToString());
11851195
return true;
11861196
}
11871197

GRBL-Plotter/GCodeCreation/Graphic2GCodeMove.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* GRBL-Plotter. Another GCode sender for GRBL.
22
This file is part of the GRBL-Plotter application.
33
4-
Copyright (C) 2015-2024 Sven Hasemann contact: [email protected]
4+
Copyright (C) 2015-2025 Sven Hasemann contact: [email protected]
55
66
This program is free software: you can redistribute it and/or modify
77
it under the terms of the GNU General Public License as published by
@@ -170,12 +170,12 @@ public static void Move(StringBuilder gcodeValueFinal, int gnr, double mx, doubl
170170

171171
if (GcodeZApply && repeatZ)
172172
{
173-
gcodeFigureTime += delta / GcodeXYFeed; ;
173+
gcodeFigureTime += 60 * delta / GcodeXYFeed; ;
174174
gcodeFigureLines++;
175175
}
176176
else
177177
{
178-
gcodeTime += 0;// delta / GcodeXYFeed;
178+
gcodeExecutionSeconds += 0;// delta / GcodeXYFeed;
179179
gcodeLines++;
180180
}
181181
lastx = mx; lasty = my; lastg = gnr; // lastz = tz;
@@ -217,9 +217,9 @@ private static void MoveArc(StringBuilder gcodeStringFinal, int gnr, double x, d
217217
if (gcodeNoArcs || avoidG23)
218218
{
219219
XyzabcuvwPoint last = new XyzabcuvwPoint();
220-
last.X = lastx;last.Y = lasty;
220+
last.X = lastx; last.Y = lasty;
221221
XyzabcuvwPoint now = new XyzabcuvwPoint();
222-
now.X = x;now.Y = y;
222+
now.X = x; now.Y = y;
223223
SplitArc(gcodeString, gnr, last, now, i, j, cmt);
224224
}
225225
else
@@ -233,12 +233,12 @@ private static void MoveArc(StringBuilder gcodeStringFinal, int gnr, double x, d
233233
}
234234
if (GcodeZApply && repeatZ)
235235
{
236-
gcodeFigureTime += Fdistance(lastx, lasty, x, y) / GcodeXYFeed;
236+
gcodeFigureTime += 60 * Fdistance(lastx, lasty, x, y) / GcodeXYFeed;
237237
gcodeFigureLines++;
238238
}
239239
else
240240
{
241-
gcodeTime += 0;// Fdistance(lastx, lasty, x, y) / GcodeXYFeed;
241+
gcodeExecutionSeconds += 0;// Fdistance(lastx, lasty, x, y) / GcodeXYFeed;
242242
gcodeLines++;
243243
}
244244
lastx = x; lasty = y; lastf = GcodeXYFeed;

0 commit comments

Comments
 (0)