FreeCAD
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
25TODO: Currently this tool uses the DraftGui widgets. We want to avoid using
26this big module because it creates manually the interface.
27Instead we should provide its own .ui file and task panel,
28similar 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# @{
36import PySide.QtCore as QtCore37from PySide.QtCore import QT_TRANSLATE_NOOP38
39import FreeCADGui as Gui40import Draft41import Draft_rc42import draftutils.utils as utils43import draftguitools.gui_base_original as gui_base_original44import draftguitools.gui_tool_utils as gui_tool_utils45
46from draftmake import make_fillet47from draftutils.messages import _err, _toolmsg48from draftutils.translate import translate49
50# The module is used to prevent complaints from code checkers (flake8)
51True if Draft_rc.__name__ else False52
53
54class Fillet(gui_base_original.Creator):55"""Gui command for the Fillet tool."""56
57def __init__(self):58super(Fillet, self).__init__()59self.featureName = "Fillet"60
61def GetResources(self):62"""Set icon, menu and tooltip."""63return {'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
68def Activated(self, name="Fillet"):69"""Execute when the command is called."""70super(Fillet, self).Activated(name=name)71
72if self.ui:73self.rad = 10074self.chamfer = False75self.delete = False76label = translate("draft", "Fillet radius")77tooltip = translate("draft", "Radius of fillet")78
79# Call the task panel defined in DraftGui to enter a radius.80self.ui.taskUi(title=translate("Draft", "Fillet"), icon="Draft_Fillet")81self.ui.radiusUi()82self.ui.sourceCmd = self83self.ui.labelRadius.setText(label)84self.ui.radiusValue.setToolTip(tooltip)85self.ui.setRadiusValue(self.rad, "Length")86self.ui.check_delete = self.ui._checkbox("isdelete",87self.ui.layout,88checked=self.delete)89self.ui.check_delete.setText(translate("Draft",90"Delete original objects"))91self.ui.check_delete.show()92self.ui.check_chamfer = self.ui._checkbox("ischamfer",93self.ui.layout,94checked=self.chamfer)95self.ui.check_chamfer.setText(translate("Draft",96"Create chamfer"))97self.ui.check_chamfer.show()98
99self.ui.check_delete.stateChanged.connect(self.set_delete)100self.ui.check_chamfer.stateChanged.connect(self.set_chamfer)101
102# TODO: somehow we need to set up the trackers103# 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
110def action(self, arg):111"""Scene event handler. CURRENTLY NOT USED.112
113Here the displaying of the trackers (previews)
114should be implemented by considering the current value of the
115`ui.radiusValue`.
116"""
117if arg["Type"] == "SoKeyboardEvent":118if arg["Key"] == "ESCAPE":119self.finish()120elif arg["Type"] == "SoLocation2Event":121self.point, ctrlPoint, info = gui_tool_utils.getPoint(self, arg)122gui_tool_utils.redraw3DView()123
124def set_delete(self):125"""Execute as a callback when the delete checkbox changes."""126self.delete = self.ui.check_delete.isChecked()127
128def set_chamfer(self):129"""Execute as a callback when the chamfer checkbox changes."""130self.chamfer = self.ui.check_chamfer.isChecked()131
132def numericRadius(self, rad):133"""Validate the entry radius in the user interface.134
135This function is called by the toolbar or taskpanel interface
136when a valid radius has been entered in the input field.
137"""
138self.rad = rad139self.draw_arc(rad, self.chamfer, self.delete)140
141def draw_arc(self, rad, chamfer, delete):142"""Process the selection and draw the actual object."""143objs = Gui.Selection.getSelection()144edges = make_fillet._preprocess(objs, rad, chamfer)145if edges is None:146_err(translate("draft", "Fillet cannot be created"))147return148
149_doc = 'FreeCAD.ActiveDocument.'150
151_objs = '['152_objs += _doc + objs[0].Name + ', '153_objs += _doc + objs[1].Name154_objs += ']'155
156Gui.addModule("Draft")157
158_cmd = 'Draft.make_fillet'159_cmd += '('160_cmd += _objs + ', '161_cmd += 'radius=' + str(rad)162if chamfer:163_cmd += ', chamfer=' + str(chamfer)164if delete:165_cmd += ', delete=' + str(delete)166_cmd += ')'167_cmd_list = ['arc = ' + _cmd,168'Draft.autogroup(arc)',169'FreeCAD.ActiveDocument.recompute()']170
171self.commit(translate("draft", "Create fillet"), _cmd_list)172self.finish()173
174
175Gui.addCommand('Draft_Fillet', Fillet())176
177## @}
178