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

@@ -470,19 +470,19 @@ Gui.addCommand('Draft_Arc', Arc())
class Arc_3Points(gui_base.GuiCommandBase):
"""GuiCommand for the Draft_Arc_3Points tool."""
def __init__(self):
super().__init__(name="Arc_3Points")
def GetResources(self):
"""Set icon, menu and tooltip."""
return {"Pixmap": "Draft_Arc_3Points",
"Accel": "A,T",
"Accel": "A, T",
"MenuText": QT_TRANSLATE_NOOP("Draft_Arc_3Points", "Arc by 3 points"),
"ToolTip": QT_TRANSLATE_NOOP("Draft_Arc_3Points", "Creates a circular arc by picking 3 points.\nCTRL to snap, SHIFT to constrain.")}
def Activated(self):
"""Execute when the command is called."""
if App.activeDraftCommand:
App.activeDraftCommand.finish()
App.activeDraftCommand = self
self.featureName = "Arc_3Points"
super().Activated()
# Reset the values
self.points = []
@@ -498,10 +498,11 @@ class Arc_3Points(gui_base.GuiCommandBase):
Gui.Snapper.getPoint(callback=self.getPoint,
movecallback=self.drawArc)
Gui.Snapper.ui.sourceCmd = self
Gui.Snapper.ui.setTitle(title=translate("draft", "Arc by 3 points"),
icon="Draft_Arc_3Points")
Gui.Snapper.ui.continueCmd.show()
self.ui = Gui.Snapper.ui ## self must have a ui for _finish_command_on_doc_close in doc_observer.py.
self.ui.sourceCmd = self
self.ui.setTitle(title=translate("draft", "Arc by 3 points"),
icon="Draft_Arc_3Points")
self.ui.continueCmd.show()
def getPoint(self, point, info):
"""Get the point by clicking on the 3D view.
@@ -527,6 +528,8 @@ class Arc_3Points(gui_base.GuiCommandBase):
# Avoid adding the same point twice
if point not in self.points:
self.points.append(point)
if self.planetrack and len(self.points) == 1:
self.planetrack.set(point)
if len(self.points) < 3:
# If one or two points were picked, set up again the Snapper
@@ -540,10 +543,11 @@ class Arc_3Points(gui_base.GuiCommandBase):
Gui.Snapper.getPoint(last=self.points[-1],
callback=self.getPoint,
movecallback=self.drawArc)
Gui.Snapper.ui.sourceCmd = self
Gui.Snapper.ui.setTitle(title=translate("draft", "Arc by 3 points"),
icon="Draft_Arc_3Points")
Gui.Snapper.ui.continueCmd.show()
self.ui = Gui.Snapper.ui
self.ui.sourceCmd = self
self.ui.setTitle(title=translate("draft", "Arc by 3 points"),
icon="Draft_Arc_3Points")
self.ui.continueCmd.show()
else:
# If three points were already picked in the 3D view
@@ -592,7 +596,6 @@ class Arc_3Points(gui_base.GuiCommandBase):
Restart (continue) the command if `True`, or if `None` and
`ui.continueMode` is `True`.
"""
App.activeDraftCommand = None
self.tracker.finalize()
super().finish()
if cont or (cont is None and Gui.Snapper.ui and Gui.Snapper.ui.continueMode):