Skip to content

Commit

Permalink
Version 1.7.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
svenhb authored Feb 26, 2025
1 parent 6dd9e5c commit 3d7d7a5
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions GRBL-Plotter/GCodeCreation/Graphic2GCodeRelated.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* GRBL-Plotter. Another GCode sender for GRBL.
This file is part of the GRBL-Plotter application.
Copyright (C) 2015-2024 Sven Hasemann contact: svenhb@web.de
Copyright (C) 2015-2025 Sven Hasemann contact: svenhb@web.de
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -62,6 +62,7 @@ You should have received a copy of the GNU General Public License
* 2024-05-28 l:699 f:Setup gcodeAngleStep set min to 0.01
* 2024-07-08 l:2004 f:IntermediateZ - Z-Up at least on final pass
* 2024-11-28 l:1810 f:GetHeader add pen up/down translation info
* 2025-01-02 l:880 f:GetCodeNrFromGCodel replace Convert.ToInt16 by int.TryParse
*/

using System;
Expand Down Expand Up @@ -449,6 +450,7 @@ public static string Get()
{ options.AppendFormat("<li>{0} (S {1} - {2})</li>\r\n", Localization.GetString("importMessageOptionSFromWidth"), Properties.Settings.Default.importImageSMin, Properties.Settings.Default.importImageSMax); }
if (Properties.Settings.Default.importSVGCircleToDot) options.AppendFormat("<li>{0}</li>\r\n", Localization.GetString("importMessageOptionCircleToDot"));
if (Properties.Settings.Default.importSVGCircleToDotZ) options.AppendFormat("<li>{0}</li>\r\n", Localization.GetString("importMessageOptionCircleRadiusToZ"));
if (Properties.Settings.Default.importSVGCircleToDotS) options.AppendFormat("<li>{0}</li>\r\n", Localization.GetString("importMessageOptionCircleRadiusToS"));
if (options.Length > 3)
{
Summary.AppendFormat("<tr><th>{0}</th></tr>\r\n", Localization.GetString("importMessageOption1"));
Expand Down Expand Up @@ -773,18 +775,22 @@ public static string GetSettings()
gcodeAuxiliaryValue1Command = "";
gcodeAuxiliaryValue2Command = "";

if ((gcodeInsertSubroutineEnable && gcodeLineSegmentationEnable) || gcodeToolChange || Properties.Settings.Default.ctrlToolChange || (Properties.Settings.Default.importSVGCircleToDot && (Properties.Settings.Default.importCircleToDotScriptCount > 0)))
if ((gcodeInsertSubroutineEnable && gcodeLineSegmentationEnable) || gcodeToolChange || Properties.Settings.Default.ctrlToolChange ||
(Properties.Settings.Default.importSVGCircleToDot && (Properties.Settings.Default.importCircleToDotScriptCount > 0)))
{
bool insertSubroutine = false;
if (gcodeInsertSubroutineEnable && gcodeLineSegmentationEnable && FileContainsSubroutineCall(Properties.Settings.Default.importGCSubroutine))
{ insertSubroutine = true; }
else if (gcodeToolChange)
if (gcodeToolChange)
{
insertSubroutine = false;
insertSubroutine = insertSubroutine || FileContainsSubroutineCall(Properties.Settings.Default.ctrlToolScriptPut);
insertSubroutine = insertSubroutine || FileContainsSubroutineCall(Properties.Settings.Default.ctrlToolScriptSelect);
insertSubroutine = insertSubroutine || FileContainsSubroutineCall(Properties.Settings.Default.ctrlToolScriptGet);
insertSubroutine = insertSubroutine || FileContainsSubroutineCall(Properties.Settings.Default.ctrlToolScriptProbe);
}
if (gcodeInsertSubroutineEnable && gcodeLineSegmentationEnable && FileContainsSubroutineCall(Properties.Settings.Default.importGCSubroutine))
{ insertSubroutine = true; }
if (Properties.Settings.Default.importSVGCircleToDot && (Properties.Settings.Default.importCircleToDotScriptCount > 0))
{ insertSubroutine = true; }
if (insertSubroutine)
{
double tmp_lastz = lastz;
Expand Down Expand Up @@ -870,7 +876,12 @@ public static int GetCodeNrFromGCode(char code, string tmp)
{
string cmdG = GetStrGCode(code, tmp); // find number string
if (cmdG.Length > 0)
{ return Convert.ToInt16(cmdG.Substring(1)); }
{
int retval = -1;
if (!int.TryParse(cmdG.Substring(1), out retval))
{ Logger.Error("int.TryParse nok: code:'{0}' string:'{1}' convert:'{2}'", code, tmp, cmdG.Substring(1)); }
return retval;
}
return -1;
}
public static string GetStrGCode(char code, string tmp)
Expand All @@ -887,14 +898,6 @@ public static string GetStrGCode(char code, string tmp)
return "";
}

// get value from X,Y,Z F, S etc.
public static int GetParameterValue(char code, string tmp)
{
string cmdG = GetStringValue(code, tmp);
if (cmdG.Length > 0)
{ return Convert.ToInt16(cmdG.Substring(1)); }
return -1;
}
public static string GetStringValue(char code, string tmp)
{
var cmdG = Regex.Matches(tmp, code + "-?\\d+(.\\d+)?");
Expand Down Expand Up @@ -1564,8 +1567,8 @@ internal static void SplitArc(StringBuilder gcodeValue, int gnr, XyzabcuvwPoint
p1.Round(); p2.Round();
arcMove = GcodeMath.GetArcMoveProperties(p1, p2, i1, j2, (gnr == 2)); // 2020-04-14 add round()
double step = Math.Abs(Math.Asin(gcodeAngleStep / arcMove.radius)); // in RAD
if (step <= 0)
step = 0.1;
if (step <= 0)
step = 0.1;
if (step > Math.Abs(arcMove.angleDiff))
step = Math.Abs(arcMove.angleDiff / 2);

Expand Down Expand Up @@ -1808,14 +1811,14 @@ public static string GetHeader(string cmt, string source)
}

if (!(GcodeZApply || GcodePWMEnable || gcodeSpindleToggle || gcodeIndividualTool))
{ header += string.Format("( !!! No Pen up/down translation !!! )\r\n"); }
else
{
header += string.Format("( Pen U/D trans: {0} {1} {2} {3})\r\n", (GcodeZApply? string.Format("Z|{0:0.0}|{1:0.0}",GcodeZUp,GcodeZDown):"noZ"),
(GcodePWMEnable? string.Format("PWM|{0:0}|{1:0}",gcodePwmUp,GcodePwmDown):"noPWM"),
(gcodeSpindleToggle? "SpndTog":"noSpndTog"),
(gcodeUseLasermode? "LsrMd":"noLsrMd"));
}
{ header += string.Format("( !!! No Pen up/down translation !!! )\r\n"); }
else
{
header += string.Format("( Pen U/D trans: {0} {1} {2} {3})\r\n", (GcodeZApply ? string.Format("Z|{0:0.0}|{1:0.0}", GcodeZUp, GcodeZDown) : "noZ"),
(GcodePWMEnable ? string.Format("PWM|{0:0}|{1:0}", gcodePwmUp, GcodePwmDown) : "noPWM"),
(gcodeSpindleToggle ? "SpndTog" : "noSpndTog"),
(gcodeUseLasermode ? "LsrMd" : "noLsrMd"));
}
if (Properties.Settings.Default.importRemoveShortMovesEnable && ((float)Properties.Settings.Default.importRemoveShortMovesLimit > 0.2))
{ header += string.Format("( !!! Remove short moves < {0:0.00} !!! )\r\n", Properties.Settings.Default.importRemoveShortMovesLimit); }
if ((float)Properties.Settings.Default.importAssumeAsEqualDistance > 0.01)
Expand Down

0 comments on commit 3d7d7a5

Please sign in to comment.