Universal-G-Code-Sender icon indicating copy to clipboard operation
Universal-G-Code-Sender copied to clipboard

PatternRemover Enhancement #1158 and Second Typo #1645

Open AndyCXL opened this issue 3 years ago • 5 comments

Replacer #1158 (PatternRemover enhancement) and Second Typo #1645 (ABC Step Multiply)

PatternRemover has been enhanced to support 'replace with' and %macro% expansion by introducing 'sed' syntax to the preferences/UGS/Contoller Options.

'sed' syntax is "s/regex to match/replacement text". The code splits the regexpr string passed in (as defined by the user in the Controller Options screen) by "/" and acts according to how many sub-strings are found.

If 1 (and default), ie: no "/", treat this as a simple regex to find a match and replace with "" if found in the gcode. If 2 then a half-sed syntax was used but the replacement is not specified, so "" is used. If 3 then first check if the %macro-name% syntax is found in the 'replacement text' string and search the user's macros for a match. If a match is found, the 'replacement text' becomes the 'gcode' content of the macro, if no match, use the replacement text as-is. It is most commonly expected that the "regex to match" will match and thus replace the whole line, however, note that the "regex to match" may match only a portion of the gcode line, and the replace with functionality only changes the matched text, leaving the remainder of the line unaltered.

The following now all work;

M6T1 in code, "M6T[0-9]+" enabled will REMOVE M6T1 as per original functionality M6T1 in code, "s/M6T[0-9]+" enabled will REPLACE M6T1 with "" as no replacement text was specified M6T1 in code, "s/M6T[0-9]+/G21" enabled will REPLACE M6T1 with G21 if that is what the user desires M6T1 in code, "s/M6T[0-9]+/%1%" enabled will REPLACE M6T1 with whatever macro "1" is defined as by the user in the Gcode column. User must be aware that the result from macro "1" will be passed through as-is. M6T1 in code, "s/M6T[0-9]+/%Macro #1%" enabled will REPLACE M6T1 with whatever macro "Macro #1" is defined as by the user in the Gcode column. User must be aware that the result from macro "Macro #1" will be passed through as-is. All REMOVES or REPLACES are logged under INFO to assist user debugging regex and %macro% settings.

Confirmed working (Apple and RPi). Core algorithm re-written to reduce if nesting depths.

Found a typo in jog service.java where getStepSizeZ() was errantly against multiplyABCStepSize(), should have been getStepSizeABC(), which is corrected.

Confirmed working (Apple and RPi).

AndyCXL avatar Aug 24 '21 18:08 AndyCXL

Over to the moderators to accept, critique or reject this so I know what standard is expected.

AndyCXL avatar Aug 24 '21 19:08 AndyCXL

This pull has sat untouched for 4 months, having been asked to make a minor change which was done and re-submitted for review. Are contributions like this really wanted, or not really?

AndyCXL avatar Dec 09 '21 17:12 AndyCXL

Sorry, it is of course nice with contributions. I do however not feel the ownership of what should be merged and what shouldn't, I feel that it is up to Will. I should have been more clear on where I stood.

This is a nice feature, my only concern is how well this plays together with other features. For instance when using macros there is a feature that can popup asking the user for inputs, what will happen if running this in a headless mode.

I know that this feature is more for expert users, so they would probably know what they are doing. So in that sense this PR looks good to me. I'll leave the merging for Will.

breiler avatar Dec 11 '21 08:12 breiler

I can't tell if the Branch Conflict is actually outstanding or not, or what/if I am required to do to fix it.

AndyCXL avatar Jan 11 '22 10:01 AndyCXL

I give up. Changing to a different sender app now.

AndyCXL avatar Jul 04 '22 17:07 AndyCXL