See pull request #2429. This isn't suitable for merging, I just created it so people can see approximately the code changes that are needed, and the diffs against the current code.
Some of the things that are needed are
- New module to hold the commands, for example, DraftWire.py.
- Remove the makeCommand() from Draft.py, for example, makeLine() and makeWire().
- Remove the object class and its respective view provider, for example, _Wire and _ViewProviderWire, from Draft.py. These two classes are now defined in the new module, for example, DraftWire.py.
- Inside Draft.py the new module DraftWire is imported, and the function makeWire() is made available, as they may be used by other functions, and they also should be available in the Draft namespace.
- The _Wire and _ViewProviderWire class are also imported in Draft.py, as these need to be present in the Draft namespace for compatibility with previous versions. Without these classes, it isn't possible to recreate the shapes when a file is re-opened.
- Remove the Wire class from DraftTools.py. This class is a Gui Command, meaning, the command run when the button in the Draft toolbar is pressed.
- Remove the FreeCADGui.addCommand("Draft_Wire", Wire()) from DraftTools.py, as this is now added in the new module, DraftWire.py.
- Update the CMakeLists.txt file with the new module DraftWire.py so that when FreeCAD is built, the file is installed (moved) to the appropriate directory (it's a Python file, so it isn't compiled like a C++ source).
- In Draft.py auxiliary functions and classes need to be moved to before the import DraftWire instructions. Otherwise, they aren't found. Maybe this isn't needed if new modules with auxiliary functions are created.
Code: Select all
./bin/FreeCAD --run-test TestDraft
Code: Select all
======================================================================
ERROR: TestDraft (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: TestDraft
Traceback (most recent call last):
File "/usr/lib/python3.6/unittest/loader.py", line 153, in loadTestsFromName
module = __import__(module_name)
File "/opt/freecad-build-vocx/Mod/Draft/TestDraft.py", line 26, in <module>
import FreeCAD, os, unittest, FreeCADGui, Draft
File "/opt/freecad-build-vocx/Mod/Draft/Draft.py", line 462, in <module>
import DraftWire
File "/opt/freecad-build-vocx/Mod/Draft/DraftWire.py", line 48, in <module>
from DraftTools import getPoint
File "/opt/freecad-build-vocx/Mod/Draft/DraftTools.py", line 562, in <module>
from DraftWire import Line
ImportError: cannot import name 'Line'
I don't know what the proper solution is but maybe a new module should be created like DraftAuxTools.py that includes all small utilities, but doesn't actually define a working tool like Line, Circle, Ellipse, etc. In similar fashion, another module could be added DraftBaseObjects.py to define the auxiliary classes, like _DraftObject, _ViewProviderDraft, Creator, DraftTool, etc.
I believe this is done in the Arch Workbench, as ArchComponent.py, ArchCommands.py, etc., define auxiliary tools that the other objects need.
I opened this thread to discuss the issue. Obviously, I could get to work and try to hack a solution, moving the tools to new modules. However, since the codebase is massive (Draft.py has 6982 lines and DraftTools.py has 5676, and I need to add about 2000 more lines of documentation) maybe Yorik has a better idea of what can be moved first and how.