From 5acb94984fc8d6b9bc1d1b59dbf7e794c31ba8c6 Mon Sep 17 00:00:00 2001 From: vocx-fc Date: Thu, 12 Mar 2020 00:34:16 -0600 Subject: [PATCH] Draft: move DisplayMode command to gui_togglemodes module --- src/Mod/Draft/DraftTools.py | 26 +-------- .../Draft/draftguitools/gui_togglemodes.py | 56 ++++++++++++++++++- 2 files changed, 56 insertions(+), 26 deletions(-) diff --git a/src/Mod/Draft/DraftTools.py b/src/Mod/Draft/DraftTools.py index b59b4dedea..82e0ed2990 100644 --- a/src/Mod/Draft/DraftTools.py +++ b/src/Mod/Draft/DraftTools.py @@ -82,6 +82,7 @@ from draftguitools.gui_lineops import CloseLine from draftguitools.gui_lineops import UndoLine from draftguitools.gui_togglemodes import ToggleConstructionMode from draftguitools.gui_togglemodes import ToggleContinueMode +from draftguitools.gui_togglemodes import ToggleDisplayMode # import DraftFillet import drafttaskpanels.task_shapestring as task_shapestring import drafttaskpanels.task_scale as task_scale @@ -4198,30 +4199,6 @@ class Drawing(Modifier): return page -class ToggleDisplayMode(): - """The ToggleDisplayMode FreeCAD command definition""" - - def GetResources(self): - return {'Pixmap' : 'Draft_SwitchMode', - 'Accel' : "Shift+Space", - 'MenuText': QtCore.QT_TRANSLATE_NOOP("Draft_ToggleDisplayMode", "Toggle display mode"), - 'ToolTip' : QtCore.QT_TRANSLATE_NOOP("Draft_ToggleDisplayMode", "Swaps display mode of selected objects between wireframe and flatlines")} - - def IsActive(self): - if FreeCADGui.Selection.getSelection(): - return True - else: - return False - - def Activated(self): - for obj in FreeCADGui.Selection.getSelection(): - if obj.ViewObject.DisplayMode == "Flat Lines": - if "Wireframe" in obj.ViewObject.listDisplayModes(): - obj.ViewObject.DisplayMode = "Wireframe" - elif obj.ViewObject.DisplayMode == "Wireframe": - if "Flat Lines" in obj.ViewObject.listDisplayModes(): - obj.ViewObject.DisplayMode = "Flat Lines" - class SubelementHighlight(Modifier): """The Draft_SubelementHighlight FreeCAD command definition""" @@ -5423,7 +5400,6 @@ FreeCADGui.addCommand('Draft_Stretch',Stretch()) # context commands FreeCADGui.addCommand('Draft_ApplyStyle',ApplyStyle()) -FreeCADGui.addCommand('Draft_ToggleDisplayMode',ToggleDisplayMode()) FreeCADGui.addCommand('Draft_AddToGroup',AddToGroup()) FreeCADGui.addCommand('Draft_SelectGroup',SelectGroup()) FreeCADGui.addCommand('Draft_Shape2DView',Shape2DView()) diff --git a/src/Mod/Draft/draftguitools/gui_togglemodes.py b/src/Mod/Draft/draftguitools/gui_togglemodes.py index e0eb690ae4..2a6644e5ce 100644 --- a/src/Mod/Draft/draftguitools/gui_togglemodes.py +++ b/src/Mod/Draft/draftguitools/gui_togglemodes.py @@ -24,7 +24,8 @@ # *************************************************************************** """Provides tools to control the mode of other tools in the Draft Workbench. -For example, a construction mode, and a continue mode to repeat commands. +For example, a construction mode, a continue mode to repeat commands, +and to toggle the appearance of certain shapes to wireframe. """ ## @package gui_togglemodes # \ingroup DRAFT @@ -151,3 +152,56 @@ class ToggleContinueMode(BaseMode): Gui.addCommand('Draft_ToggleContinueMode', ToggleContinueMode()) + + +class ToggleDisplayMode(gui_base.GuiCommandNeedsSelection): + """GuiCommand for the Draft_ToggleDisplayMode tool. + + Switches the display mode of selected objects from flatlines + to wireframe and back. + + It inherits `GuiCommandNeedsSelection` to only be availbale + when there is a document and a selection. + See this class for more information. + """ + + def __init__(self): + super().__init__(name=_tr("Toggle display mode")) + + def GetResources(self): + """Set icon, menu and tooltip.""" + _menu = "Toggle normal/wireframe display" + _tip = ("Switches the display mode of selected objects " + "from flatlines to wireframe and back.\n" + "This is helpful to quickly visualize objects " + "that are hidden by other objects.\n" + "This is intended to be used with closed shapes " + "and solids, and doesn't affect open wires.") + + d = {'Pixmap': 'Draft_SwitchMode', + 'Accel': "Shift+Space", + 'MenuText': QT_TRANSLATE_NOOP("Draft_ToggleDisplayMode", + _menu), + 'ToolTip': QT_TRANSLATE_NOOP("Draft_ToggleDisplayMode", + _tip)} + return d + + def Activated(self): + """Execute when the command is called. + + It tests the view provider of the selected objects + and changes their `DisplayMode` from `'Wireframe'` + to `'Flat Lines'`, and the other way around, if possible. + """ + super().Activated() + + for obj in Gui.Selection.getSelection(): + if obj.ViewObject.DisplayMode == "Flat Lines": + if "Wireframe" in obj.ViewObject.listDisplayModes(): + obj.ViewObject.DisplayMode = "Wireframe" + elif obj.ViewObject.DisplayMode == "Wireframe": + if "Flat Lines" in obj.ViewObject.listDisplayModes(): + obj.ViewObject.DisplayMode = "Flat Lines" + + +Gui.addCommand('Draft_ToggleDisplayMode', ToggleDisplayMode())