FreeCAD
93 строки · 4.3 Кб
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 downgrade objects.
26
27Downgrades 2D objects to simpler objects until it reaches
28simple Edge primitives. For example, a Draft Line to wire, and then
29to a series of edges.
30"""
31## @package gui_downgrade
32# \ingroup draftguitools
33# \brief Provides GUI tools to downgrade objects.
34
35## \addtogroup draftguitools
36# @{
37from PySide.QtCore import QT_TRANSLATE_NOOP38
39import FreeCADGui as Gui40import Draft_rc41import draftguitools.gui_base_original as gui_base_original42import draftguitools.gui_tool_utils as gui_tool_utils43from draftutils.messages import _msg44from draftutils.translate import translate45
46# The module is used to prevent complaints from code checkers (flake8)
47True if Draft_rc.__name__ else False48
49
50class Downgrade(gui_base_original.Modifier):51"""Gui Command for the Downgrade tool."""52
53def GetResources(self):54"""Set icon, menu and tooltip."""55
56return {'Pixmap': 'Draft_Downgrade',57'Accel': "D, N",58'MenuText': QT_TRANSLATE_NOOP("Draft_Downgrade", "Downgrade"),59'ToolTip': QT_TRANSLATE_NOOP("Draft_Downgrade", "Downgrades the selected objects into simpler shapes.\nThe result of the operation depends on the types of objects, which may be able to be downgraded several times in a row.\nFor example, it explodes the selected polylines into simpler faces, wires, and then edges. It can also subtract faces.")}60
61def Activated(self):62"""Execute when the command is called."""63super().Activated(name="Downgrade")64if not self.ui:65return66if not Gui.Selection.getSelection():67self.ui.selectUi(on_close_call=self.finish)68_msg(translate("draft", "Select an object to upgrade"))69self.call = self.view.addEventCallback("SoEvent", gui_tool_utils.selectObject)70else:71self.proceed()72
73def proceed(self):74"""Proceed with execution of the command after selection."""75if self.call is not None:76self.end_callbacks(self.call)77if Gui.Selection.getSelection():78Gui.addModule("Draft")79_cmd = 'Draft.downgrade'80_cmd += '('81_cmd += 'FreeCADGui.Selection.getSelection(), '82_cmd += 'delete=True'83_cmd += ')'84_cmd_list = ['_objs_ = ' + _cmd,85'FreeCAD.ActiveDocument.recompute()']86self.commit(translate("draft", "Downgrade"),87_cmd_list)88self.finish()89
90
91Gui.addCommand('Draft_Downgrade', Downgrade())92
93## @}
94