FreeCAD
72 строки · 3.4 Кб
1# ***************************************************************************
2# * (c) 2009 Yorik van Havre <yorik@uncreated.net> *
3# * (c) 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 apply styles to objects."""
26## @package gui_styles
27# \ingroup draftguitools
28# \brief Provides GUI tools to apply styles to objects.
29
30## \addtogroup draftguitools
31# @{
32from PySide.QtCore import QT_TRANSLATE_NOOP
33
34import FreeCADGui as Gui
35
36from draftguitools import gui_base_original
37from draftutils.translate import translate
38from draftutils import groups
39
40class ApplyStyle(gui_base_original.Modifier):
41"""Gui Command for the ApplyStyle tool."""
42
43def GetResources(self):
44"""Set icon, menu and tooltip."""
45return {
46"Pixmap": "Draft_Apply",
47"MenuText": QT_TRANSLATE_NOOP("Draft_ApplyStyle", "Apply current style"),
48"ToolTip": QT_TRANSLATE_NOOP("Draft_ApplyStyle", "Applies the current style defined in the toolbar (line width and colors) to the selected objects and groups.")
49}
50
51def IsActive(self):
52return bool(Gui.ActiveDocument and Gui.Selection.getSelection())
53
54def Activated(self):
55"""Execute when the command is called."""
56super().Activated(name="Apply style")
57objs = Gui.Selection.getSelection()
58if objs:
59objs = groups.get_group_contents(objs, addgroups=True, spaces=True, noarchchild=True)
60Gui.addModule("Draft")
61cmd_list = [
62"doc = FreeCAD.ActiveDocument",
63"Draft.apply_current_style([" + ", ".join(["doc." + obj.Name for obj in objs]) + "])",
64"doc.recompute()"
65]
66self.commit(translate("draft", "Change Style"), cmd_list)
67self.finish()
68
69
70Gui.addCommand("Draft_ApplyStyle", ApplyStyle())
71
72## @}
73