FreeCAD
91 строка · 3.9 Кб
1# ***************************************************************************
2# * (c) 2009, 2010 Yorik van Havre <yorik@uncreated.net> *
3# * (c) 2009, 2010 Ken Cline <cline@frii.com> *
4# * (c) 2020 Eliud Cabrera Castillo <e.cabrera-castillo@tum.de> *
5# * *
6# * This file is part of the FreeCAD CAx development system. *
7# * *
8# * This program is free software; you can redistribute it and/or modify *
9# * it under the terms of the GNU Lesser General Public License (LGPL) *
10# * as published by the Free Software Foundation; either version 2 of *
11# * the License, or (at your option) any later version. *
12# * for detail see the LICENCE text file. *
13# * *
14# * FreeCAD is distributed in the hope that it will be useful, *
15# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17# * GNU Library General Public License for more details. *
18# * *
19# * You should have received a copy of the GNU Library General Public *
20# * License along with FreeCAD; if not, write to the Free Software *
21# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
22# * USA *
23# * *
24# ***************************************************************************
25"""Provides GUI tools to enable and disable the working plane grid."""
26## @package gui_grid
27# \ingroup draftguitools
28# \brief Provides GUI tools to enable and disable the working plane grid.
29
30## \addtogroup draftguitools
31# @{
32from PySide.QtCore import QT_TRANSLATE_NOOP
33
34import FreeCAD as App
35import FreeCADGui as Gui
36import WorkingPlane
37
38from draftguitools import gui_base
39from draftutils.translate import translate
40
41
42class ToggleGrid(gui_base.GuiCommandSimplest):
43"""The Draft ToggleGrid command definition.
44
45If the grid tracker is invisible (hidden), it makes it visible (shown);
46and if it is visible, it hides it.
47
48It inherits `GuiCommandSimplest` to set up the document
49and other behavior. See this class for more information.
50"""
51
52def __init__(self):
53super().__init__(name=translate("draft", "Toggle grid"))
54
55def GetResources(self):
56"""Set icon, menu and tooltip."""
57
58return {"Pixmap": "Draft_Grid",
59"Accel": "G, R",
60"MenuText": QT_TRANSLATE_NOOP("Draft_ToggleGrid", "Toggle grid"),
61"ToolTip": QT_TRANSLATE_NOOP("Draft_ToggleGrid",
62"Toggles the Draft grid on and off."),
63"CmdType": "ForEdit"}
64
65def Activated(self):
66"""Execute when the command is called."""
67super().Activated()
68
69if not hasattr(Gui, "Snapper"):
70return
71Gui.Snapper.setTrackers(update_grid=False)
72grid = Gui.Snapper.grid
73# This command is never set as App.activeDraftCommand.
74cmdactive = hasattr(App, "activeDraftCommand") and App.activeDraftCommand
75
76if grid.Visible:
77grid.off()
78grid.show_always = False
79if cmdactive:
80grid.show_during_command = False
81elif cmdactive:
82grid.on()
83grid.show_during_command = True
84else:
85grid.on()
86WorkingPlane.get_working_plane()
87grid.show_always = True
88
89Gui.addCommand("Draft_ToggleGrid", ToggleGrid())
90
91## @}
92