Skip to content

Commit

Permalink
Draft: move DisplayMode command to gui_togglemodes module
Browse files Browse the repository at this point in the history
  • Loading branch information
vocx-fc authored and yorikvanhavre committed Apr 16, 2020
1 parent 9758d98 commit 1435267
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 26 deletions.
26 changes: 1 addition & 25 deletions src/Mod/Draft/DraftTools.py
Expand Up @@ -82,6 +82,7 @@
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
Expand Down Expand Up @@ -4198,30 +4199,6 @@ def createDefaultPage(self):
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"""

Expand Down Expand Up @@ -5423,7 +5400,6 @@ def IsActive(self):

# 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())
Expand Down
56 changes: 55 additions & 1 deletion src/Mod/Draft/draftguitools/gui_togglemodes.py
Expand Up @@ -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
Expand Down Expand Up @@ -151,3 +152,56 @@ def Activated(self):


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())

0 comments on commit 1435267

Please sign in to comment.