Updated code. It's in
pull request #2472.
Now
makeFillet() has an optional argument to delete the original objects, or keep them. The default is to keep them.
Code: Select all
Fillet = DraftFillet.makeFillet([L1, L2], radius=200)
Fillet = DraftFillet.makeFillet([L1, L2], radius=200, delete=True)
I don't have circular dependencies anymore. Things just work. I'm not sure if this is the best way to do it, but I'm going to keep looking into it.
In
InitGui.py the new module is added. This is required so the workbench correctly picks up the tool, and adds it to the workbench's toolbar (the button) when the user graphically switches to Draft.
Code: Select all
import os, Draft_rc, DraftTools, DraftGui, DraftFillet
In the implementation of the graphical tool, we actually call the command line tool.
Code: Select all
name = translate("draft", "Create fillet")
args = _wires + ', radius=' + str(rad)
if delete:
args += ', delete=' + str(delete)
func = ['arc = DraftFillet.makeFillet(' + args + ')']
func.append('Draft.autogroup(arc)')
func.append('FreeCAD.ActiveDocument.recompute()')
self.commit(name, func)
The command is
DraftFillet.makeFillet(), and it is in its own module
DraftFillet.py. Originally, I said that this module needed to be imported before calling the function, otherwise it wouldn't work. However, I missed the important instruction
This is normally added before the
self.commit() code above so that functions like
Draft.makeLine() would work. So I just load the appropriate module.
Code: Select all
FreeCADGui.addModule("DraftFillet")
About the graphical interface. Now when pressing the button, a Task panel appears that allows setting the value of the radius of the fillet, and toggle whether to delete the original objects or not.
What I would think would be nice is to show a "tracker", that is, the preview of the new shape, which would be updated when the value of the radius changes. I haven't investigated how this works exactly, so any help is welcome.
I will further investigate separating other tools into their own modules. However, there is still the issue of leaving a reference to the object in the main
Draft.py file. Since a fillet is created from the code in
DraftFillet.py, there is no class in
Draft.py of this type. But for all other objects, a class definitely needs to be in
Draft.py, or old files will fail to load.
Also, I just realized that
DraftGui.py basically defines a huge
DraftToolBar class with basically the Task panel of every single Draft tool. I think it is also important to separate this into smaller classes, so they are more manageable. Each tool should probably have its own
.ui file as well.
----------
I just added the
chamfer option as well. Since the underlying function
DraftGeomUtil.fillet() supports it, it was straight-forward. Also to the Task panel interface.
Code: Select all
Fillet = DraftFillet.makeFillet([L1, L2], radius=200)
Fillet = DraftFillet.makeFillet([L1, L2], radius=300, delete=True)
Fillet = DraftFillet.makeFillet([L1, L2], radius=500, chamfer=True, delete=True)