Description
After spending a couple of days studying the SolidPython code I would like to propose an idea which -- I think -- would make the code more maintainable and extendable.
As far as I understand the code, it consists of two major parts:
- solid.*(".core"?):
- is basically everything inobjects.py
andsolidpython.py
- is the actuall "interface" to OpenSCAD and provides everything for a pretty straight forward 1:1 mapping of all OpenSCAD features - solid.utils (or "extensions"?):
- everything else
- these are "libraries" extending the features of OpenSCAD (e.g. extrude_along_path, splines,...)
The actual code structure is the following (as far as I understand it):
-
objects.py
&solidpython.py
contain "solid.core". These files contain:
-[Included]OpenSCADObject
-builtins
(e.g.circle, square, translate, hull,....
)
-import scad
functions (a couple of functions, some in objects.py, some in solidpython.py)
- rendering functions (scad_render*
in solidpython.py) -
everything else in the solid directory are "extensions":
-extrude_along_path.py
-patch_euclid.py
-screw_thread.py
-splines.py
-utils.py
I would suggest the following two changes:
-
move all extensions into a subdirectory (suggestion
solid/extensions
)
- add a newsolid/utils.py
file that only imports everything fromsolid/extensions
to stay backward compatible
- alternatively we could create asolid/utils
package (directory) that contains all the extensions -
break up
objects.py
andsolidpython.py
into several modules, I would suggest the following:
1.helpers.py
- contains common used helper functions
2.object_base.py
- contains [Include]OpenSCADObject - the object tree
3.builtins.py
- contains all the python wrappers for the OpenSCAD builtins
4.scad_render.py
- contains everything for generating *.scad files from the object tree
5.scad_import.py
- contains everything for importing *.scad files
Note: Even though the Part/Hole feature (and maybe BOM too) are -- from my point of view -- technically "extensions" it would be pretty hard to extract them from solid.core and I would suggest to not touch them.
I have a local branch where I've made exactly the described changes. It includes the refactoring to the explained structure but also the usage of py_scadparser and dynamic_builtins.
It's definitely not ready to ship code but the "core" looks pretty good to me even though it was not tested extensively. Some stuff might even be broken atm (e.g. the extensions, tests, examples).
I tried to touch as little code as possible and the branch should not contain any other changes besides the structure, the parser and the builtins.
Are you interested in somehow integrating the "structure change" into SolidPython?
I'll attach the branch to this thread.
Btw: I really appreciate the work you did and I am excited about SolidPython. Great work! (especially to keep it up for such a long time)