Skip to content

Commit

Permalink
Version 1.7.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
svenhb committed Dec 18, 2023
1 parent 360c51e commit 005f3cf
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 117 deletions.
31 changes: 18 additions & 13 deletions GRBL-Plotter/GCodeCreation/Graphic2GCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
* 2023-03-14 l:610 f:StartPath importGraphicLeadInEnable optional start at GcodeZUp value
* 2023-09-14 f:CreateGCode add CollectionStart /-End Tags
* 2023-11-03 l:357 f:CreateGCode (figure) add proforma figure-tag if not figureEnable
* 2023-11-27 l:465 f:ProcessPathObject call subroutine only if needed
*/

using System;
Expand Down Expand Up @@ -356,9 +356,8 @@ internal static bool CreateGCode(List<Graphic.PathObject> completeGraphic, List<

if (!graphicInfo.FigureEnable) // proforma figure tag
{
string figColor = "", figWidth = "";
figColor = string.Format(" PenColor=\"{0}\"", completeGraphic[0].Info.GroupAttributes[(int)GroupOption.ByColor]);
figWidth = string.Format(" PenWidth=\"{0}\"", completeGraphic[0].Info.GroupAttributes[(int)GroupOption.ByWidth]);
string figColor = string.Format(" PenColor=\"{0}\"", completeGraphic[0].Info.GroupAttributes[(int)GroupOption.ByColor]);
string figWidth = string.Format(" PenWidth=\"{0}\"", completeGraphic[0].Info.GroupAttributes[(int)GroupOption.ByWidth]);
Gcode.Comment(gcodeString, string.Format("{0} Id=\"{1}\" {2} {3}>", XmlMarker.FigureStart, 0, figColor, figWidth));
}

Expand Down Expand Up @@ -443,7 +442,7 @@ private static void ProcessPathObject(PathObject pathObject, Graphic.GraphicInfo
}
else if (graphicInfo.OptionZFromWidth)
{
dotCounter++;
// dotCounter++;
double newZ = CalculateZFromRange(graphicInfo.PenWidthMin, graphicInfo.PenWidthMax, DotData.OptZ);
if (logEnable) Logger.Trace("---Dot OptionZFromWidth: RangeMin:{0:0.00} RangeMax:{1:0.00} DotData.Z:{2:0.00} -> setZ:{3:0.00}", graphicInfo.PenWidthMin, graphicInfo.PenWidthMax, DotData.OptZ, newZ);
newZ = Math.Max(origZ, newZ); // don't go deeper than set Z
Expand All @@ -452,18 +451,19 @@ private static void ProcessPathObject(PathObject pathObject, Graphic.GraphicInfo
}
if (graphicInfo.OptionSFromWidth)
{
dotCounter++;
// dotCounter++;
double newS = CalculateSFromRange(graphicInfo.PenWidthMin, graphicInfo.PenWidthMax, DotData.OptZ);
if (logEnable) Logger.Trace("--ProcessPathObject: penWidth:{0:0.00} -> setS:{1:0.00}", DotData.OptZ, newS);
Gcode.GcodePwmDown = Gcode.GcodeSpindleSpeed = (float)newS; //???
penIsDown = false;
}

dotCounter++;
pathObject.FigureId = StartPath(DotData, toolNr, toolCmt, "PD");
PenDown("PD");
StopPath("PU DOT");

if (dotCounter >= Properties.Settings.Default.importCircleToDotScriptCount)
if (Properties.Settings.Default.importSVGCircleToDot && (Properties.Settings.Default.importCircleToDotScriptCount > 0) && (dotCounter >= Properties.Settings.Default.importCircleToDotScriptCount))
{
dotCounter = 0;
Gcode.CallSubroutine(gcodeString, 95, "refresh stamp");
Expand Down Expand Up @@ -518,12 +518,12 @@ private static void ProcessPathObject(PathObject pathObject, Graphic.GraphicInfo
Gcode.GcodeZDown = (float)newZ;
if (!Properties.Settings.Default.importDepthFromWidthRamp)
penIsDown = false;
if (logEnable) Logger.Trace("--ProcessPathObject: penWidth:{0:0.00} -> setZ:{1:0.00}", entity.Depth, newZ);
if (logEnable) Logger.Trace("--ProcessPathObject-OptionZFromWidth: penWidth:{0:0.00} -> setZ:{1:0.00} min:{2:0.00} max:{3:0.00} orig:{4:0.00}", entity.Depth, newZ, graphicInfo.PenWidthMin, graphicInfo.PenWidthMax, origZ);
}
if (graphicInfo.OptionSFromWidth)
{
newS = CalculateSFromRange(graphicInfo.PenWidthMin, graphicInfo.PenWidthMax, entity.Depth);
if (logEnable) Logger.Trace("--ProcessPathObject: penWidth:{0:0.00} -> setS:{1:0.00}", entity.Depth, newS);
if (logEnable) Logger.Trace("--ProcessPathObject-OptionSFromWidth: penWidth:{0:0.00} -> setS:{1:0.00}", entity.Depth, newS);
Gcode.GcodePwmDown = Gcode.GcodeSpindleSpeed = (float)newS; //???
}

Expand Down Expand Up @@ -643,6 +643,7 @@ private static void SetHalftoneMode(Graphic.GraphicInformationClass graphicInfo)
}
}

/*Input: min, max and actual pen-width value from graphics import*/
public static double CalculateZFromRange(double min, double max, double penWidth)
{
if (logDetailed)
Expand All @@ -658,6 +659,7 @@ public static double CalculateZFromRange(double min, double max, double penWidth
return (double)Properties.Settings.Default.importDepthFromWidthMin;
double nPen = (Math.Abs(penWidth) - penMin) / penDelta;

/*Get desired range, where to transform the pen-width*/
double zMin = Math.Abs((double)Properties.Settings.Default.importDepthFromWidthMin);
double zMax = Math.Abs((double)Properties.Settings.Default.importDepthFromWidthMax);
double zDelta = (zMax - zMin);
Expand All @@ -677,6 +679,7 @@ public static double CalculateZFromRange(double min, double max, double penWidth
return -z;
}

/*Input: min, max and actual pen-width value from graphics import*/
public static double CalculateSFromRange(double min, double max, double penWidth)
{
if (logDetailed)
Expand All @@ -686,12 +689,13 @@ public static double CalculateSFromRange(double min, double max, double penWidth

double penMin = Math.Abs(min);
double penMax = Math.Abs(max);
double penDelta = (penMax - penMin);
double penDelta = Math.Abs(penMax - penMin);

if (penDelta == 0)
return (double)Properties.Settings.Default.importImageSMin;
double nPen = (Math.Abs(penWidth) - penMin) / penDelta;

/*Get desired range, where to transform the pen-width*/
double zMin = Math.Abs((double)Properties.Settings.Default.importImageSMin);
double zMax = Math.Abs((double)Properties.Settings.Default.importImageSMax);
double zDelta = (zMax - zMin);
Expand All @@ -708,7 +712,7 @@ public static double CalculateSFromRange(double min, double max, double penWidth
if (logDetailed)
Logger.Trace("---calculateSFromPenWidth: penWidth:{0:0.00} nPen:{1:0.00} SDelta:{2:0.00} S:{3:0.00}", penWidth, nPen, zDelta, z);

return z;
return Math.Abs(z);
}

private static string GetGroupAttributes(GroupObject groupObject, GraphicInformationClass graphicInfo)
Expand Down Expand Up @@ -934,10 +938,11 @@ private static void MoveTo(Point coordxy, double newZ, double? newS, double tang
Gcode.SetAux2DistanceCommand(setAux2FinalDistance);
if (newS != null) Gcode.SetSValue((double)newS);

//Logger.Trace("MoveTo useAlternitveZ:{0} newZ:{1}", useAlternitveZ, newZ);
if (useAlternitveZ) //Properties.Settings.Default.importDepthFromWidthRamp|| Properties.Settings.Default.importDXFUseZ)
Gcode.Move(gcodeString, 1, coordxy.X, coordxy.Y, (float)newZ, Gcode.ApplyXYFeedRate, cmt);
else if (applyDashPattern)
MoveToDashed(coordxy, cmt);
MoveToDashed(coordxy);
else
Gcode.MoveTo(gcodeString, coordxy, cmt); // note: Gcode.GcodeZDown is may set with newZ

Expand All @@ -946,7 +951,7 @@ private static void MoveTo(Point coordxy, double newZ, double? newS, double tang



private static void MoveToDashed(Point coordxy, string cmt)
private static void MoveToDashed(Point coordxy)
{
if (logCoordinates) Logger.Trace(" MoveToDashed from X:{0:0.000} Y:{1:0.000} to X:{0:0.000} Y:{1:0.000}", lastGC.X, lastGC.Y, coordxy.X, coordxy.Y);

Expand Down
26 changes: 19 additions & 7 deletions GRBL-Plotter/GCodeCreation/Graphic2GCodeRelated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
* 2023-09-05 l:858 f:GetStrGCode allow also 3 digitis
* 2023-09-23 l:1020 f:JobEnd don't send M05 if (PreventSpindle)
* 2023-09-24 l:1500 f:Tool also take care of !PreventSpindle
* 2023-11-27 l:792 f:Setup add script from Properties.Settings.Default.importCircleToDotScript
*/

using System;
Expand Down Expand Up @@ -506,8 +507,8 @@ public static partial class Gcode
private static string gcodeSubroutine = ""; // subroutine

private static int gcodeDownUp = 0; // counter for GCode Pen Down / Up
private static float gcodeTime = 0; // counter for GCode work time
private static float gcodeFigureTime = 0; // counter for GCode work time
private static double gcodeTime = 0; // counter for GCode work time
private static double gcodeFigureTime = 0; // counter for GCode work time
private static int gcodePauseCounter = 0; // counter for GCode pause M0 commands
private static int gcodeToolCounter = 0; // counter for GCode Tools
private static string gcodeToolText = ""; // counter for GCode Tools
Expand Down Expand Up @@ -566,7 +567,7 @@ public static partial class Gcode

private static bool gcodeTangentialEnable = false;
private static string gcodeTangentialName = "C";
private static float gcodeTangentialAngle = 0;
private static double gcodeTangentialAngle = 0;
private static float gcodeTangentialAngleDevi = 0;
// private static float gcodeTangentialAngleLast = 0;
private static string gcodeTangentialCommand = "";
Expand Down Expand Up @@ -756,6 +757,11 @@ public static string GetSettings()
stopwatch = new Stopwatch();
stopwatch.Start();

gcodeSValueCommand = "";
gcodeTangentialCommand = "";
gcodeAuxiliaryValue1Command = "";
gcodeAuxiliaryValue2Command = "";

if ((gcodeInsertSubroutineEnable && gcodeLineSegmentationEnable) || gcodeToolChange || Properties.Settings.Default.ctrlToolChange || (Properties.Settings.Default.importSVGCircleToDot && (Properties.Settings.Default.importCircleToDotScriptCount > 0)))
{
bool insertSubroutine = false;
Expand All @@ -782,6 +788,12 @@ public static string GetSettings()
gcodeSubroutine += "\r\n(subroutine)\r\nO92 (Pen down)\r\n";
gcodeSubroutine += tmp.ToString();
gcodeSubroutine += "M99\r\n";

if (Properties.Settings.Default.importSVGCircleToDot) // && File.Exists(Properties.Settings.Default.importCircleToDotScript))
{
SetSubroutine(Properties.Settings.Default.importCircleToDotScript, 95);
}

lastz = tmp_lastz;

if (GcodePWMEnable)
Expand Down Expand Up @@ -1245,13 +1257,13 @@ public static void MoveToRapid(StringBuilder gcodeValue, Point coord, string cmt
figureStart.X = coord.X; figureStart.Y = coord.Y;
figureStartAlpha = gcodeTangentialCommand;
if (!(GcodeZApply && repeatZ))
{ Move(gcodeValue, 0, (float)coord.X, (float)coord.Y, false, cmt); LastMovewasG0 = true; }
{ Move(gcodeValue, 0, coord.X, coord.Y, false, cmt); LastMovewasG0 = true; }
else
{
lastx = (float)coord.X; lasty = (float)coord.Y; lastg = 0;
lastx = coord.X; lasty = coord.Y; lastg = 0;
}
}
public static void MoveToRapid(StringBuilder gcodeValue, float mx, float my, string cmt)
public static void MoveToRapid(StringBuilder gcodeValue, double mx, double my, string cmt)
{
figureStart.X = mx; figureStart.Y = my;
figureStartAlpha = gcodeTangentialCommand;
Expand Down Expand Up @@ -1598,7 +1610,7 @@ public static void Tool(StringBuilder gcodeValue, int toolnr, int objectCount, s

remainingC = (float)Properties.Settings.Default.importGCLineSegmentLength; // start with full segment length

if (GcodeZApply && !gcodeSpindleToggle && !PreventSpindle)
if (GcodeZApply && !gcodeSpindleToggle && !PreventSpindle)
{ Gcode.SpindleOn(gcodeValue, "Start spindle - Option Z-Axis"); gcodeLines++; }
}

Expand Down
Loading

0 comments on commit 005f3cf

Please sign in to comment.