FreeCAD

Форк
0
/
gui_togglemodes.py 
160 строк · 6.6 Кб
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 set different modes of other tools.
26

27
For example, a construction mode, a continue mode to repeat commands,
28
and to toggle the appearance of certain shapes to wireframe.
29
"""
30
## @package gui_togglemodes
31
# \ingroup draftguitools
32
# \brief Provides GUI tools to set different modes of other tools.
33

34
## \addtogroup draftguitools
35
# @{
36
from PySide.QtCore import QT_TRANSLATE_NOOP
37

38
import FreeCADGui as Gui
39
import Draft_rc
40
import draftguitools.gui_base as gui_base
41

42
from draftutils.messages import _msg
43
from draftutils.translate import translate
44

45
# The module is used to prevent complaints from code checkers (flake8)
46
True if Draft_rc.__name__ else False
47

48

49
class BaseMode(gui_base.GuiCommandSimplest):
50
    """Base class for mode context GuiCommands.
51

52
    This is inherited by the other GuiCommand classes to run
53
    a set of similar actions when changing modes.
54

55
    It inherits `GuiCommandSimplest` to set up the document
56
    and other behavior. See this class for more information.
57
    """
58

59
    def Activated(self, mode="None"):
60
        """Execute when the command is called.
61

62
        Parameters
63
        ----------
64
        action: str
65
            Indicates the type of mode to switch to.
66
            It can be `'construction'` or `'continue'`.
67
        """
68
        super(BaseMode, self).Activated()
69

70
        if hasattr(Gui, "draftToolBar"):
71
            _ui = Gui.draftToolBar
72
        else:
73
            _msg(translate("draft","No active Draft Toolbar."))
74
            return
75

76
        if _ui is not None:
77
            if mode == "construction" and hasattr(_ui, "constrButton"):
78
                _ui.constrButton.toggle()
79
            elif mode == "continue":
80
                _ui.toggleContinue()
81

82

83
class ToggleConstructionMode(BaseMode):
84
    """GuiCommand for the Draft_ToggleConstructionMode tool.
85

86
    When construction mode is active, the following objects created
87
    will be included in the construction group, and will be drawn
88
    with the specified color and properties.
89
    """
90

91
    def __init__(self):
92
        super(ToggleConstructionMode,
93
              self).__init__(name=translate("draft","Construction mode"))
94

95
    def GetResources(self):
96
        """Set icon, menu and tooltip."""
97

98
        d = {'Pixmap': 'Draft_Construction',
99
             'MenuText': QT_TRANSLATE_NOOP("Draft_ToggleConstructionMode","Toggle construction mode"),
100
             'Accel': "C, M",
101
             'ToolTip': QT_TRANSLATE_NOOP("Draft_ToggleConstructionMode","Toggles the Construction mode.\nWhen this is active, the following objects created will be included in the construction group, and will be drawn with the specified color and properties.")}
102
        return d
103

104
    def Activated(self):
105
        """Execute when the command is called.
106

107
        It calls the `toggle()` method of the construction button
108
        in the `DraftToolbar` class.
109
        """
110
        super(ToggleConstructionMode, self).Activated(mode="construction")
111

112

113
Gui.addCommand('Draft_ToggleConstructionMode', ToggleConstructionMode())
114

115

116
class ToggleDisplayMode(gui_base.GuiCommandNeedsSelection):
117
    """GuiCommand for the Draft_ToggleDisplayMode tool.
118

119
    Switches the display mode of selected objects from flatlines
120
    to wireframe and back.
121

122
    It inherits `GuiCommandNeedsSelection` to only be available
123
    when there is a document and a selection.
124
    See this class for more information.
125
    """
126

127
    def __init__(self):
128
        super(ToggleDisplayMode,
129
              self).__init__(name=translate("draft","Toggle display mode"))
130

131
    def GetResources(self):
132
        """Set icon, menu and tooltip."""
133

134
        d = {'Pixmap': 'Draft_SwitchMode',
135
             'Accel': "Shift+Space",
136
             'MenuText': QT_TRANSLATE_NOOP("Draft_ToggleDisplayMode","Toggle normal/wireframe display"),
137
             'ToolTip': QT_TRANSLATE_NOOP("Draft_ToggleDisplayMode","Switches the display mode of selected objects from flatlines to wireframe and back.\nThis is helpful to quickly visualize objects that are hidden by other objects.\nThis is intended to be used with closed shapes and solids, and doesn't affect open wires.")}
138
        return d
139

140
    def Activated(self):
141
        """Execute when the command is called.
142

143
        It tests the view provider of the selected objects
144
        and changes their `DisplayMode` from `'Wireframe'`
145
        to `'Flat Lines'`, and the other way around, if possible.
146
        """
147
        super(ToggleDisplayMode, self).Activated()
148

149
        for obj in Gui.Selection.getSelection():
150
            if obj.ViewObject.DisplayMode == "Flat Lines":
151
                if "Wireframe" in obj.ViewObject.listDisplayModes():
152
                    obj.ViewObject.DisplayMode = "Wireframe"
153
            elif obj.ViewObject.DisplayMode == "Wireframe":
154
                if "Flat Lines" in obj.ViewObject.listDisplayModes():
155
                    obj.ViewObject.DisplayMode = "Flat Lines"
156

157

158
Gui.addCommand('Draft_ToggleDisplayMode', ToggleDisplayMode())
159

160
## @}
161

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

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

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

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