FreeCAD

Форк
0
/
gui_fillets.py 
177 строк · 7.3 Кб
1
# ***************************************************************************
2
# *   (c) 2020 Eliud Cabrera Castillo <e.cabrera-castillo@tum.de>           *
3
# *                                                                         *
4
# *   This file is part of the FreeCAD CAx development system.              *
5
# *                                                                         *
6
# *   This program is free software; you can redistribute it and/or modify  *
7
# *   it under the terms of the GNU Lesser General Public License (LGPL)    *
8
# *   as published by the Free Software Foundation; either version 2 of     *
9
# *   the License, or (at your option) any later version.                   *
10
# *   for detail see the LICENCE text file.                                 *
11
# *                                                                         *
12
# *   FreeCAD is distributed in the hope that it will be useful,            *
13
# *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
14
# *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
15
# *   GNU Library General Public License for more details.                  *
16
# *                                                                         *
17
# *   You should have received a copy of the GNU Library General Public     *
18
# *   License along with FreeCAD; if not, write to the Free Software        *
19
# *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
20
# *   USA                                                                   *
21
# *                                                                         *
22
# ***************************************************************************
23
"""Provides GUI tools to create Fillet objects between two lines.
24

25
TODO: Currently this tool uses the DraftGui widgets. We want to avoid using
26
this big module because it creates manually the interface.
27
Instead we should provide its own .ui file and task panel,
28
similar to the OrthoArray tool.
29
"""
30
## @package gui_fillet
31
# \ingroup draftguitools
32
# \brief Provides GUI tools to create Fillet objects between two lines.
33

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

39
import FreeCADGui as Gui
40
import Draft
41
import Draft_rc
42
import draftutils.utils as utils
43
import draftguitools.gui_base_original as gui_base_original
44
import draftguitools.gui_tool_utils as gui_tool_utils
45

46
from draftmake import make_fillet
47
from draftutils.messages import _err, _toolmsg
48
from draftutils.translate import translate
49

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

53

54
class Fillet(gui_base_original.Creator):
55
    """Gui command for the Fillet tool."""
56

57
    def __init__(self):
58
        super(Fillet, self).__init__()
59
        self.featureName = "Fillet"
60

61
    def GetResources(self):
62
        """Set icon, menu and tooltip."""
63
        return {'Pixmap': 'Draft_Fillet',
64
                'Accel':'F,I',
65
                'MenuText': QT_TRANSLATE_NOOP("Draft_Fillet", "Fillet"),
66
                'ToolTip': QT_TRANSLATE_NOOP("Draft_Fillet", "Creates a fillet between two selected wires or edges.")}
67

68
    def Activated(self, name="Fillet"):
69
        """Execute when the command is called."""
70
        super(Fillet, self).Activated(name=name)
71

72
        if self.ui:
73
            self.rad = 100
74
            self.chamfer = False
75
            self.delete = False
76
            label = translate("draft", "Fillet radius")
77
            tooltip = translate("draft", "Radius of fillet")
78

79
            # Call the task panel defined in DraftGui to enter a radius.
80
            self.ui.taskUi(title=translate("Draft", "Fillet"), icon="Draft_Fillet")
81
            self.ui.radiusUi()
82
            self.ui.sourceCmd = self
83
            self.ui.labelRadius.setText(label)
84
            self.ui.radiusValue.setToolTip(tooltip)
85
            self.ui.setRadiusValue(self.rad, "Length")
86
            self.ui.check_delete = self.ui._checkbox("isdelete",
87
                                                     self.ui.layout,
88
                                                     checked=self.delete)
89
            self.ui.check_delete.setText(translate("Draft",
90
                                                   "Delete original objects"))
91
            self.ui.check_delete.show()
92
            self.ui.check_chamfer = self.ui._checkbox("ischamfer",
93
                                                      self.ui.layout,
94
                                                      checked=self.chamfer)
95
            self.ui.check_chamfer.setText(translate("Draft",
96
                                                    "Create chamfer"))
97
            self.ui.check_chamfer.show()
98

99
            self.ui.check_delete.stateChanged.connect(self.set_delete)
100
            self.ui.check_chamfer.stateChanged.connect(self.set_chamfer)
101

102
            # TODO: somehow we need to set up the trackers
103
            # to show a preview of the fillet.
104

105
            # self.linetrack = trackers.lineTracker(dotted=True)
106
            # self.arctrack = trackers.arcTracker()
107
            # self.call = self.view.addEventCallback("SoEvent", self.action)
108
            _toolmsg(translate("draft", "Enter radius."))
109

110
    def action(self, arg):
111
        """Scene event handler. CURRENTLY NOT USED.
112

113
        Here the displaying of the trackers (previews)
114
        should be implemented by considering the current value of the
115
        `ui.radiusValue`.
116
        """
117
        if arg["Type"] == "SoKeyboardEvent":
118
            if arg["Key"] == "ESCAPE":
119
                self.finish()
120
        elif arg["Type"] == "SoLocation2Event":
121
            self.point, ctrlPoint, info = gui_tool_utils.getPoint(self, arg)
122
            gui_tool_utils.redraw3DView()
123

124
    def set_delete(self):
125
        """Execute as a callback when the delete checkbox changes."""
126
        self.delete = self.ui.check_delete.isChecked()
127

128
    def set_chamfer(self):
129
        """Execute as a callback when the chamfer checkbox changes."""
130
        self.chamfer = self.ui.check_chamfer.isChecked()
131

132
    def numericRadius(self, rad):
133
        """Validate the entry radius in the user interface.
134

135
        This function is called by the toolbar or taskpanel interface
136
        when a valid radius has been entered in the input field.
137
        """
138
        self.rad = rad
139
        self.draw_arc(rad, self.chamfer, self.delete)
140

141
    def draw_arc(self, rad, chamfer, delete):
142
        """Process the selection and draw the actual object."""
143
        objs = Gui.Selection.getSelection()
144
        edges = make_fillet._preprocess(objs, rad, chamfer)
145
        if edges is None:
146
            _err(translate("draft", "Fillet cannot be created"))
147
            return
148

149
        _doc = 'FreeCAD.ActiveDocument.'
150

151
        _objs = '['
152
        _objs += _doc + objs[0].Name + ', '
153
        _objs += _doc + objs[1].Name
154
        _objs += ']'
155

156
        Gui.addModule("Draft")
157

158
        _cmd = 'Draft.make_fillet'
159
        _cmd += '('
160
        _cmd += _objs + ', '
161
        _cmd += 'radius=' + str(rad)
162
        if chamfer:
163
            _cmd += ', chamfer=' + str(chamfer)
164
        if delete:
165
            _cmd += ', delete=' + str(delete)
166
        _cmd += ')'
167
        _cmd_list = ['arc = ' + _cmd,
168
                     'Draft.autogroup(arc)',
169
                     'FreeCAD.ActiveDocument.recompute()']
170

171
        self.commit(translate("draft", "Create fillet"), _cmd_list)
172
        self.finish()
173

174

175
Gui.addCommand('Draft_Fillet', Fillet())
176

177
## @}
178

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

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

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

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