Skip to content

Commit

Permalink
Merge pull request FreeCAD#12443 from Roy-043/Draft-fix-wrong-selecti…
Browse files Browse the repository at this point in the history
…on-after-commands-improved

Draft: fix wrong selection after commands (improved)
  • Loading branch information
Roy-043 authored Feb 16, 2024
2 parents 43723b6 + ca1a105 commit 6909766
Show file tree
Hide file tree
Showing 32 changed files with 138 additions and 119 deletions.
4 changes: 2 additions & 2 deletions src/Mod/Draft/draftfunctions/offset.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ def getRadius(obj,delta):
print("unsupported object") # TODO
newobj = obj
if copy and params.get_param("selectBaseObjects"):
gui_utils.select(newobj)
else:
gui_utils.select(obj)
else:
gui_utils.select(newobj)
if delete:
App.ActiveDocument.removeObject(delete)
return newobj
Expand Down
5 changes: 3 additions & 2 deletions src/Mod/Draft/draftguitools/gui_arcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,11 @@ def finish(self, cont=False):
Restart (continue) the command if `True`, or if `None` and
`ui.continueMode` is `True`.
"""
super().finish()
self.end_callbacks(self.call)
if self.ui:
self.linetrack.finalize()
self.arctrack.finalize()
super().finish()
if cont or (cont is None and self.ui and self.ui.continueMode):
self.Activated()

Expand Down Expand Up @@ -595,8 +596,8 @@ def finish(self, cont=False):
`ui.continueMode` is `True`.
"""
App.activeDraftCommand = None
super().finish()
self.tracker.finalize()
super().finish()
if cont or (cont is None and Gui.Snapper.ui and Gui.Snapper.ui.continueMode):
self.Activated()

Expand Down
24 changes: 11 additions & 13 deletions src/Mod/Draft/draftguitools/gui_base_original.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ def Activated(self, name="None", is_subtool=False):
_toolmsg("{}".format(16*"-"))
_toolmsg("GuiCommand: {}".format(self.featureName))

def end_callbacks(self, call):
try:
self.view.removeEventCallback("SoEvent", call)
gui_utils.end_all_events()
except RuntimeError:
# the view has been deleted already
pass
call = None

def finish(self, cont=False):
"""Finish the current command.
Expand All @@ -165,22 +174,11 @@ def finish(self, cont=False):
if self.ui:
self.ui.offUi()
self.ui.sourceCmd = None
if hasattr(Gui, "Snapper"):
Gui.Snapper.off()
if self.planetrack:
self.planetrack.finalize()
self.wp._restore()
if hasattr(Gui, "Snapper"):
Gui.Snapper.off()
if self.call:
try:
self.view.removeEventCallback("SoEvent", self.call)
# Next line fixes https://github.com/FreeCAD/FreeCAD/issues/10469:
QtCore.QCoreApplication.processEvents()
# It seems to work in most cases. If it does not, use this instead:
# gui_utils.end_all_events()
except RuntimeError:
# the view has been deleted already
pass
self.call = None
if self.commitList:
last_cmd = self.commitList[-1][1][-1]
if last_cmd.find("recompute") >= 0:
Expand Down
12 changes: 6 additions & 6 deletions src/Mod/Draft/draftguitools/gui_beziers.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ def finish(self, cont=False, closed=False):
closed: bool, optional
Close the curve if `True`.
"""
if self.ui:
if hasattr(self, "bezcurvetrack"):
self.bezcurvetrack.finalize()
self.end_callbacks(self.call)
if self.ui and hasattr(self, "bezcurvetrack"):
self.bezcurvetrack.finalize()
if self.obj:
# remove temporary object, if any
old = self.obj.Name
Expand Down Expand Up @@ -433,9 +433,9 @@ def finish(self, cont=False, closed=False):
"""
params.set_param_view("EnableSelection", self.old_EnableSelection)

if self.ui:
if hasattr(self, "bezcurvetrack"):
self.bezcurvetrack.finalize()
self.end_callbacks(self.call)
if self.ui and hasattr(self, "bezcurvetrack"):
self.bezcurvetrack.finalize()
if self.obj:
# remove temporary object, if any
old = self.obj.Name
Expand Down
9 changes: 5 additions & 4 deletions src/Mod/Draft/draftguitools/gui_circulararray.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
import FreeCADGui as Gui
import Draft
import Draft_rc # include resources, icons, ui files
import draftutils.todo as todo

from draftguitools import gui_base
from draftutils import gui_utils
from draftutils import todo
from draftutils.messages import _log
from draftutils.translate import translate
from draftguitools import gui_base
from drafttaskpanels import task_circulararray

# The module is used to prevent complaints from code checkers (flake8)
Expand All @@ -49,7 +49,7 @@ class CircularArray(gui_base.GuiCommandBase):
"""Gui command for the CircularArray tool."""

def __init__(self):
super(CircularArray, self).__init__()
super().__init__()
self.command_name = "Circular array"
self.location = None
self.mouse_event = None
Expand Down Expand Up @@ -128,6 +128,7 @@ def completed(self):
self.callback_move)
self.view.removeEventCallbackPivy(self.mouse_event,
self.callback_click)
gui_utils.end_all_events()
if Gui.Control.activeDialog():
Gui.Control.closeDialog()
self.finish()
Expand Down
19 changes: 10 additions & 9 deletions src/Mod/Draft/draftguitools/gui_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Clone(gui_base_original.Modifier):
"""Gui Command for the Clone tool."""

def __init__(self):
super(Clone, self).__init__()
super().__init__()
self.moveAfterCloning = False

def GetResources(self):
Expand All @@ -73,14 +73,13 @@ def GetResources(self):

def Activated(self):
"""Execute when the command is called."""
super(Clone, self).Activated(name="Clone")
super().Activated(name="Clone")
if not self.ui:
return
if not Gui.Selection.getSelection():
if self.ui:
self.ui.selectUi(on_close_call=self.finish)
_msg(translate("draft", "Select an object to clone"))
self.call = self.view.addEventCallback(
"SoEvent",
gui_tool_utils.selectObject)
self.ui.selectUi(on_close_call=self.finish)
_msg(translate("draft", "Select an object to clone"))
self.call = self.view.addEventCallback("SoEvent", gui_tool_utils.selectObject)
else:
self.proceed()

Expand Down Expand Up @@ -114,7 +113,9 @@ def proceed(self):

def finish(self):
"""Terminate the operation of the tool."""
super(Clone, self).finish()
if self.call is not None:
self.end_callbacks(self.call)
super().finish()
if self.moveAfterCloning:
todo.ToDo.delay(Gui.runCommand, "Draft_Move")

Expand Down
3 changes: 2 additions & 1 deletion src/Mod/Draft/draftguitools/gui_dimensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,13 @@ def selected_app_measure(self):

def finish(self, cont=False):
"""Terminate the operation."""
self.end_callbacks(self.call)
self.cont = None
self.dir = None
super().finish()
if self.ui:
self.dimtrack.finalize()
self.arctrack.finalize()
super().finish()

def angle_dimension_normal(self, edge1, edge2):
rot = App.Rotation(DraftGeomUtils.vec(edge1),
Expand Down
21 changes: 11 additions & 10 deletions src/Mod/Draft/draftguitools/gui_downgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,20 @@ def GetResources(self):

def Activated(self):
"""Execute when the command is called."""
super(Downgrade, self).Activated(name="Downgrade")
if self.ui:
if not Gui.Selection.getSelection():
self.ui.selectUi(on_close_call=self.finish)
_msg(translate("draft", "Select an object to upgrade"))
self.call = self.view.addEventCallback(
"SoEvent",
gui_tool_utils.selectObject)
else:
self.proceed()
super().Activated(name="Downgrade")
if not self.ui:
return
if not Gui.Selection.getSelection():
self.ui.selectUi(on_close_call=self.finish)
_msg(translate("draft", "Select an object to upgrade"))
self.call = self.view.addEventCallback("SoEvent", gui_tool_utils.selectObject)
else:
self.proceed()

def proceed(self):
"""Proceed with execution of the command after selection."""
if self.call is not None:
self.end_callbacks(self.call)
if Gui.Selection.getSelection():
Gui.addModule("Draft")
_cmd = 'Draft.downgrade'
Expand Down
15 changes: 8 additions & 7 deletions src/Mod/Draft/draftguitools/gui_draft2sketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,20 @@ def GetResources(self):

def Activated(self):
"""Execute when the command is called."""
super(Draft2Sketch, self).Activated(name="Convert Draft/Sketch")
super().Activated(name="Convert Draft/Sketch")
if not self.ui:
return
if not Gui.Selection.getSelection():
if self.ui:
self.ui.selectUi(on_close_call=self.finish)
_msg(translate("draft", "Select an object to convert."))
self.call = self.view.addEventCallback(
"SoEvent",
gui_tool_utils.selectObject)
self.ui.selectUi(on_close_call=self.finish)
_msg(translate("draft", "Select an object to convert."))
self.call = self.view.addEventCallback("SoEvent", gui_tool_utils.selectObject)
else:
self.proceed()

def proceed(self):
"""Proceed with the command if one object was selected."""
if self.call is not None:
self.end_callbacks(self.call)
sel = Gui.Selection.getSelection()
allSketches = True
allDraft = True
Expand Down
3 changes: 2 additions & 1 deletion src/Mod/Draft/draftguitools/gui_ellipses.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ def finish(self, cont=False):
Restart (continue) the command if `True`, or if `None` and
`ui.continueMode` is `True`.
"""
super().finish(self)
self.end_callbacks(self.call)
if self.ui:
self.rect.off()
self.rect.finalize()
super().finish()
if cont or (cont is None and self.ui and self.ui.continueMode):
self.Activated()

Expand Down
14 changes: 7 additions & 7 deletions src/Mod/Draft/draftguitools/gui_facebinders.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,19 @@ def GetResources(self):
def Activated(self):
"""Execute when the command is called."""
super().Activated(name="Facebinder")

if not self.ui:
return
if not Gui.Selection.getSelection():
if self.ui:
self.ui.selectUi(on_close_call=self.finish)
_msg(translate("draft", "Select faces from existing objects"))
self.call = self.view.addEventCallback(
"SoEvent",
gui_tool_utils.selectObject)
self.ui.selectUi(on_close_call=self.finish)
_msg(translate("draft", "Select faces from existing objects"))
self.call = self.view.addEventCallback("SoEvent", gui_tool_utils.selectObject)
else:
self.proceed()

def proceed(self):
"""Proceed when a valid selection has been made."""
if self.call is not None:
self.end_callbacks(self.call)
if Gui.Selection.getSelection():
App.ActiveDocument.openTransaction("Create Facebinder")
Gui.addModule("Draft")
Expand Down
6 changes: 3 additions & 3 deletions src/Mod/Draft/draftguitools/gui_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ def Activated(self):
if not Gui.Selection.getSelection():
self.ui.selectUi(on_close_call=self.finish)
_msg(translate("draft", "Select an object to join"))
self.call = self.view.addEventCallback(
"SoEvent",
gui_tool_utils.selectObject)
self.call = self.view.addEventCallback("SoEvent", gui_tool_utils.selectObject)
else:
self.proceed()

Expand All @@ -75,6 +73,8 @@ def proceed(self):
visually share a point. This is due to the underlying `joinWires`
method not handling the points correctly.
"""
if self.call is not None:
self.end_callbacks(self.call)
if Gui.Selection.getSelection():
self.print_selection()
Gui.addModule("Draft")
Expand Down
3 changes: 2 additions & 1 deletion src/Mod/Draft/draftguitools/gui_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ def setmode(self, i):

def finish(self, cont=False):
"""Finish the command."""
super().finish()
self.end_callbacks(self.call)
if self.ghost:
self.ghost.finalize()
super().finish()

def create(self):
"""Create the actual object."""
Expand Down
1 change: 1 addition & 0 deletions src/Mod/Draft/draftguitools/gui_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def finish(self, cont=False, closed=False):
closed: bool, optional
Close the line if `True`.
"""
self.end_callbacks(self.call)
self.removeTemporaryObject()

if len(self.node) > 1:
Expand Down
5 changes: 3 additions & 2 deletions src/Mod/Draft/draftguitools/gui_mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def GetResources(self):

def Activated(self):
"""Execute when the command is called."""
super(Mirror, self).Activated(name="Mirror")
super().Activated(name="Mirror")
self.ghost = None
if self.ui:
if not Gui.Selection.getSelection():
Expand Down Expand Up @@ -94,9 +94,10 @@ def proceed(self):

def finish(self, cont=False):
"""Terminate the operation of the tool."""
self.end_callbacks(self.call)
if self.ghost:
self.ghost.finalize()
super(Mirror, self).finish()
super().finish()

def mirror(self, p1, p2, copy=False):
"""Mirror the real shapes."""
Expand Down
3 changes: 2 additions & 1 deletion src/Mod/Draft/draftguitools/gui_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ def finish(self, cont=False):
Restart (continue) the command if `True`, or if `None` and
`ui.continueMode` is `True`.
"""
super().finish()
self.end_callbacks(self.call)
for ghost in self.ghosts:
ghost.finalize()
super().finish()
if cont or (cont is None and self.ui and self.ui.continueMode):
todo.ToDo.delayAfter(self.Activated, [])

Expand Down
1 change: 1 addition & 0 deletions src/Mod/Draft/draftguitools/gui_offset.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ def action(self, arg):

def finish(self, cont=False):
"""Finish the offset operation."""
self.end_callbacks(self.call)
if self.running:
if self.linetrack:
self.linetrack.finalize()
Expand Down
Loading

0 comments on commit 6909766

Please sign in to comment.