Draft: close task panels on doc close

Related: #17952.

This PR introduces a document observer to close task panels on doc close.

For now it is for the Draft Workbench only. The BIM Workbench will be dealt with in a future PR.

The basic code is simple, but to make things works some additional things were addressed:
* gui_base.py: the GuiCommandBase class was enhanced to handle App.activeDraftCommand, self.doc, self.view and self.planetracker. Strictly speaking only the first 2 are required for this PR.
* gui_base.py: self.command_name was changed to self.featureName for compatibility with gui_base_original.py. Not required for this PR.
* gui_arcs.py, gui_circulararray.py, gui_polararray.py and gui_orthoarray.py: updated in relation to the GuiCommandBase class.
* gui_arcs.py Arc_3Points: The command now has a ui property and shows a plane tracker. Only the first is required for this PR.
* gui_shapestrings.py: This command had two ui attributes: self.ui and self.task. This was problematic. To fix this the base class of the command was changed from gui_base_original.Creator to gui_base.GuiCommandBase. As a result the getStrings method is no longer available meaning that the useSupport parameter is ignored when creating a ShapeString. But since that mechanism does not work properly anyway, I feel that this is acceptable. Should many user complain the functionality can of course be reintroduced.
This commit is contained in:
Roy-043
2025-04-09 12:04:02 +02:00
committed by Chris Hennes
parent 0009ddbd0b
commit ca340da86c
10 changed files with 146 additions and 115 deletions

View File

@@ -142,7 +142,6 @@ class ShapeStringTaskPanelCmd(ShapeStringTaskPanel):
def reject(self):
"""Run when clicking the Cancel button."""
Gui.ActiveDocument.resetEdit()
self.sourceCmd.finish()
self.platWinDialog("Restore")
return True
@@ -160,15 +159,14 @@ class ShapeStringTaskPanelCmd(ShapeStringTaskPanel):
z = App.Units.Quantity(self.form.sbZ.text()).Value
ssBase = App.Vector(x, y, z)
try:
qr, sup, points, fil = self.sourceCmd.getStrings()
Gui.addModule("Draft")
Gui.addModule("WorkingPlane")
self.sourceCmd.commit(translate('draft', 'Create ShapeString'),
['ss = Draft.make_shapestring(String=' + String + ', FontFile=' + FFile + ', Size=' + Size + ', Tracking=' + Tracking + ')',
'plm = FreeCAD.Placement()',
'plm.Base = ' + toString(ssBase),
'plm.Rotation.Q = ' + qr,
'ss.Placement = plm',
'ss.AttachmentSupport = ' + sup,
'pl = FreeCAD.Placement()',
'pl.Base = ' + toString(ssBase),
'pl.Rotation = WorkingPlane.get_working_plane().get_placement().Rotation',
'ss.Placement = pl',
'Draft.autogroup(ss)',
'FreeCAD.ActiveDocument.recompute()'])
except Exception: