FreeCAD

Форк
0
172 строки · 6.5 Кб
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 create simple Text objects.
26

27
The textual block can consist of multiple lines.
28
"""
29
## @package gui_texts
30
# \ingroup draftguitools
31
# \brief Provides GUI tools to create simple Text objects.
32

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

38
import FreeCAD as App
39
import FreeCADGui as Gui
40
import Draft_rc
41
import DraftVecUtils
42
import draftguitools.gui_base_original as gui_base_original
43
import draftguitools.gui_tool_utils as gui_tool_utils
44

45
from draftutils.translate import translate
46
from draftutils.messages import _toolmsg
47

48
# The module is used to prevent complaints from code checkers (flake8)
49
True if Draft_rc.__name__ else False
50

51

52
class Text(gui_base_original.Creator):
53
    """Gui command for the Text tool."""
54

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

58
        return {'Pixmap': 'Draft_Text',
59
                'Accel': "T, E",
60
                'MenuText': QT_TRANSLATE_NOOP("Draft_Text", "Text"),
61
                'ToolTip': QT_TRANSLATE_NOOP("Draft_Text", "Creates a multi-line annotation. CTRL to snap.")}
62

63
    def Activated(self):
64
        """Execute when the command is called."""
65
        super().Activated(name="Text")
66
        if self.ui:
67
            self.text = ''
68
            self.ui.sourceCmd = self
69
            self.ui.pointUi(title=translate("draft", self.featureName), icon="Draft_Text")
70
            self.ui.isRelative.hide()
71
            self.ui.continueCmd.show()
72
            self.call = self.view.addEventCallback("SoEvent", self.action)
73
            self.active = True
74
            self.ui.xValue.setFocus()
75
            self.ui.xValue.selectAll()
76
            _toolmsg(translate("draft", "Pick location point"))
77

78
    def finish(self, cont=False):
79
        """Terminate the operation.
80

81
        Parameters
82
        ----------
83
        cont: bool or None, optional
84
            Restart (continue) the command if `True`, or if `None` and
85
            `ui.continueMode` is `True`.
86
        """
87
        self.end_callbacks(self.call)
88
        super().finish(self)
89
        if cont or (cont is None and self.ui and self.ui.continueMode):
90
            self.Activated()
91

92
    def createObject(self):
93
        """Create the actual object in the current document."""
94
        rot, sup, pts, fil = self.getStrings()
95
        base = pts[1:-1]
96

97
        text_list = self.text
98

99
        if not text_list:
100
            self.finish()
101
            return None
102

103
        # If the last element is an empty string "" we remove it
104
        if not text_list[-1]:
105
            text_list.pop()
106

107
        t_list = ['"' + line + '"' for line in text_list]
108

109
        list_as_text = ", ".join(t_list)
110

111
        string = '[' + list_as_text + ']'
112

113
        Gui.addModule("Draft")
114
        _cmd = 'Draft.make_text'
115
        _cmd += '('
116
        _cmd += string + ', '
117
        _cmd += 'placement=pl, '
118
        _cmd += 'screen=None, height=None, line_spacing=None'
119
        _cmd += ')'
120
        _cmd_list = ['pl = FreeCAD.Placement()',
121
                     'pl.Rotation.Q = ' + rot,
122
                     'pl.Base = ' + base,
123
                     '_text_ = ' + _cmd,
124
                     'Draft.autogroup(_text_)',
125
                     'FreeCAD.ActiveDocument.recompute()']
126
        self.commit(translate("draft", "Create Text"),
127
                    _cmd_list)
128
        self.finish(cont=None)
129

130
    def action(self, arg):
131
        """Handle the 3D scene events.
132

133
        This is installed as an EventCallback in the Inventor view.
134

135
        Parameters
136
        ----------
137
        arg: dict
138
            Dictionary with strings that indicates the type of event received
139
            from the 3D view.
140
        """
141
        if arg["Type"] == "SoKeyboardEvent":
142
            if arg["Key"] == "ESCAPE":
143
                self.finish()
144
        elif arg["Type"] == "SoLocation2Event":  # mouse movement detection
145
            if self.active:
146
                (self.point,
147
                 ctrlPoint, info) = gui_tool_utils.getPoint(self, arg)
148
            gui_tool_utils.redraw3DView()
149
        elif arg["Type"] == "SoMouseButtonEvent":
150
            if arg["State"] == "DOWN" and arg["Button"] == "BUTTON1":
151
                if self.point:
152
                    self.active = False
153
                    Gui.Snapper.off()
154
                    self.node.append(self.point)
155
                    self.ui.textUi()
156
                    self.ui.textValue.setFocus()
157

158
    def numericInput(self, numx, numy, numz):
159
        """Validate the entry fields in the user interface.
160

161
        This function is called by the toolbar or taskpanel interface
162
        when valid x, y, and z have been entered in the input fields.
163
        """
164
        self.point = App.Vector(numx, numy, numz)
165
        self.node.append(self.point)
166
        self.ui.textUi()
167
        self.ui.textValue.setFocus()
168

169

170
Gui.addCommand('Draft_Text', Text())
171

172
## @}
173

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

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

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

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