gcodeplot icon indicating copy to clipboard operation
gcodeplot copied to clipboard

Refactor code to use Argparse instead of GetOpt for improved readability + flexibility

Open Iridium-IO opened this issue 1 year ago • 0 comments

Argparse

  • Commandline parameters now use argparse() instead of getopt(). This reduces the need to provide separate help/default/variable assignments and makes it easier to manage new parameters. This change is almost entirely feature-equal to the old getopt version, the only real difference being that config files are passed into the script using python gcodeplot.py $config.txt instead of python gcodeplot.py --config-file config.txt.
  • Custom argparse definitions and functions have been allocated to gcodeplotutils/argparse_c. This mainly has custom extensions to handle features requires for parity with the old system (comments in config files, --no prefixes, etc)

Inkscape

  • GCode can now be exported using File > Export in Inkscape. This allows you to keep a degree of separation between the SVG and exported GCode (plus it's fewer clicks when rapidly testing, as you can keep the Export window open in a tab. Saving normally still works as expected.
  • The layout for the GCodePlot dialog has been improved with better grouping of related variables
  • Extract only one color from drawing now uses the new Color selector in Inkscape instead of passing RGB values as a string

1 3 2

General

  • Simplified __main__ to reduce nesting and make code easier to read
  • Added comments to __main__ describing different sections

Note This PR also includes the changes from #42 adding Moonraker support. Sorry, I didn't quite know how to separate the changes without deleting all the Moonraker stuff, creating this PR, then re-adding the Moonraker stuff. I don't want to clog up your repo with changes and un-changes, but if you're more happy with this PR (as it's more testable since you don't have Moonraker), I can do the following steps:

  • Remove Moonraker support from within this branch (IridiumIO/GcodePlot/argparse) which will automatically update this PR
  • Merge this PR into your base repository if accepted
  • Pull these changes into the Moonraker PR which can then sit open until someone else tests it.

Thoughts? I've tested the generated GCode using my own tests (complex overlapped shapes with variable shading/cutting) as well as running the included mpcnc and cutter config files to check that the output gcode is identical. There is some variation in both the new and old files due to non-deterministic choosing of which shapes to draw first (e.g. one time it will draw star > circle > square then the next time you run the script it will draw circle > star > square

Iridium-IO avatar Dec 30 '23 11:12 Iridium-IO