FreeCAD
93 строки · 4.4 Кб
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 upgrade objects.
26
27Upgrades simple 2D objects to more complex objects until it reaches
28Draft scripted objects. For example, an edge to a wire, and to a Draft Line.
29"""
30## @package gui_upgrade
31# \ingroup draftguitools
32# \brief Provides GUI tools to upgrade objects.
33
34## \addtogroup draftguitools
35# @{
36from PySide.QtCore import QT_TRANSLATE_NOOP
37
38import FreeCADGui as Gui
39import Draft_rc
40import draftguitools.gui_base_original as gui_base_original
41import draftguitools.gui_tool_utils as gui_tool_utils
42
43from draftutils.messages import _msg
44from draftutils.translate import translate
45
46# The module is used to prevent complaints from code checkers (flake8)
47True if Draft_rc.__name__ else False
48
49
50class Upgrade(gui_base_original.Modifier):
51"""Gui Command for the Upgrade tool."""
52
53def GetResources(self):
54"""Set icon, menu and tooltip."""
55
56return {'Pixmap': 'Draft_Upgrade',
57'Accel': "U, P",
58'MenuText': QT_TRANSLATE_NOOP("Draft_Upgrade", "Upgrade"),
59'ToolTip': QT_TRANSLATE_NOOP("Draft_Upgrade", "Upgrades the selected objects into more complex shapes.\nThe result of the operation depends on the types of objects, which may be able to be upgraded several times in a row.\nFor example, it can join the selected objects into one, convert simple edges into parametric polylines,\nconvert closed edges into filled faces and parametric polygons, and merge faces into a single face.")}
60
61def Activated(self):
62"""Execute when the command is called."""
63super().Activated(name="Upgrade")
64if not self.ui:
65return
66if 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.upgrade'
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", "Upgrade"),
87_cmd_list)
88self.finish()
89
90
91Gui.addCommand('Draft_Upgrade', Upgrade())
92
93## @}
94