FreeCAD

Форк
0
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
# @{
32
from PySide.QtCore import QT_TRANSLATE_NOOP
33

34
import FreeCAD as App
35
import FreeCADGui as Gui
36
import WorkingPlane
37

38
from draftguitools import gui_base
39
from draftutils.translate import translate
40

41

42
class ToggleGrid(gui_base.GuiCommandSimplest):
43
    """The Draft ToggleGrid command definition.
44

45
    If the grid tracker is invisible (hidden), it makes it visible (shown);
46
    and if it is visible, it hides it.
47

48
    It inherits `GuiCommandSimplest` to set up the document
49
    and other behavior. See this class for more information.
50
    """
51

52
    def __init__(self):
53
        super().__init__(name=translate("draft", "Toggle grid"))
54

55
    def GetResources(self):
56
        """Set icon, menu and tooltip."""
57

58
        return {"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

65
    def Activated(self):
66
        """Execute when the command is called."""
67
        super().Activated()
68

69
        if not hasattr(Gui, "Snapper"):
70
            return
71
        Gui.Snapper.setTrackers(update_grid=False)
72
        grid = Gui.Snapper.grid
73
        # This command is never set as App.activeDraftCommand.
74
        cmdactive = hasattr(App, "activeDraftCommand") and App.activeDraftCommand
75

76
        if grid.Visible:
77
            grid.off()
78
            grid.show_always = False
79
            if cmdactive:
80
                grid.show_during_command = False
81
        elif cmdactive:
82
            grid.on()
83
            grid.show_during_command = True
84
        else:
85
            grid.on()
86
            WorkingPlane.get_working_plane()
87
            grid.show_always = True
88

89
Gui.addCommand("Draft_ToggleGrid", ToggleGrid())
90

91
## @}
92

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.