Skip to content
xmarduel edited this page Feb 18, 2022 · 38 revisions

PyCut

Warning: PyCut is still in early stage and rapid development, the software is completely beta (but usable).

PyCut is a clone of jsCut, the excellent (at least for beginners) CAM, web-based programm, that takes as input svg files and generates G-Code. So why this rewrite ?

One reason is: I wanted the spindle control (M3/M5) codes inside the generated g-code. It is worth a rewrite!

So it begins as a "fun" project, in order to understand how a G-code generator works, and how easy (or hard) it is to achieve. Well, it is not so easy (but stealing jsCut code helps). And I learned about jsCut through the CnC Philosophy pages.

By the way,I began to use jsCut because Easel (for beginners too), although free, makes limitations (among others) on the choices of the fonts - which is quite a shame...

So PyCut is written in python, with the GUI with PySide6. I actually use Python-3.9. The toolpaths are calculated with the Shapely library. Shapely had been with no doubt superior than the ClipperLib for separating tabs (line/polygon intersection). But moving from ClipperLib to Shapely has been a (very) tough job. This is due to my inexperience but also to the fact that Shapely is, well, strange. One function may returns different structure type: For example, polygons intersection may return a "Polygon", or a "MultiPolygon", or something else, or even something else again. Ok I understand the principe, but why not return per default a list of "Geometries". Because the user at the end of the day has to check anyway which type of object is returned for further processing. This is maybe the reason why the Shapely doc indeed does not indicate what the functions are actually returning... Further, Shapely may return "invalid" structures, or non-oriented Polygons (when input was "oriented") and so on and so one.

All in all, Shapely is far less forgiving than ClipperLib, and because of this I have certainly introduced in this version a lot of new bugs. But the dependency on ClipperLib is gone, so hopefully more users can discover (the bugs of) PyCut. When running PyCut, please observe the console output for possible exceptions...

Positive thing about Shapely, this has to be said, is that the programmer as control over everything, so things can be fixed/improved, so thank you Shapely in all cases.

Hopefully there will be users that will be able to contribute (and fix problems). There is a developper doc for this purpose (TODO)

The excellent things from jsCut are (among others):

  • a great svg viewer, with an API to add svg path(s) to the viewer content:
    • in black the regions of the geometry that will be affected
    • in green the calculated toolpaths
  • a great gcode simulator -in webgl-
  • the CAM stuff, based on the Clipper library (simple enough for me)

So the idea is the following:

  • MainWindow in PySide DONE
  • in PySide, display the SVG viewer stuff (QGraphicsView with SvgItem) DONE (tabs, geometry previews, toolpaths)
  • in PySide, display the WebGL stuff (QEngineView) DONE
  • Tool paths generation DONE
  • Tabs handling DONE (handled differently than is jsCut)
  • G-Code generation with spindle control (actually absent in jsCut -wow! what a feature!-) DONE
  • G-Code viewer (as in Candle) DONE

After that

  • Migrating WebGL stuff to "native" python ? (QtOpenGL) TODO
  • or using opencamlib (they say its ok but the GUI has to be done by the client app) TODO

Then

It should not be necessary to pass to PyCut svg with only "paths" svg elements. All svg elements

  • <rect> DONE [svgpathtools missing rounded corners]
  • <circle> DONE
  • <ellipse> DONE
  • <polygon> DONE
  • <line> DONE
  • <polyline> DONE

should be loadable (as well as <path> of course) DONE thanks to svgpathtools stuff. The <text> elements still have to be exported as path IN PROGRESS.

Can svgpathtools resolves the transformations ? to check. PyCut needs paths/shapes without transformations.

Inkscake export to paths could also be used internally (transparently to the user), so the "problem" would be resolved. A way to do this is to group/ungroup the items with transformations inside the Inkscape GUI.

Clone this wiki locally