FreeCAD
132 строки · 5.6 Кб
1# ***************************************************************************
2# * Copyright (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# * This program 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 this program; 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 PathTwistedArray objects.
24
25The copies will be created along a path, like a polyline, B-spline,
26or Bezier curve.
27"""
28## @package gui_pathtwistedarray
29# \ingroup draftguitools
30# \brief Provides GUI tools to create PathTwistedArray objects.
31
32## \addtogroup draftguitools
33# @{
34from PySide.QtCore import QT_TRANSLATE_NOOP
35
36import FreeCADGui as Gui
37import Draft_rc
38import draftguitools.gui_base_original as gui_base_original
39
40from draftutils.messages import _err
41from draftutils.translate import translate
42
43# The module is used to prevent complaints from code checkers (flake8)
44True if Draft_rc.__name__ else False
45
46
47class PathTwistedArray(gui_base_original.Modifier):
48"""Gui Command for the Path twisted array tool.
49
50Parameters
51----------
52use_link: bool, optional
53It defaults to `False`. If it is `True`, the created object
54will be a `Link array`.
55"""
56
57def __init__(self, use_link=False):
58super(PathTwistedArray, self).__init__()
59self.use_link = use_link
60self.call = None
61
62def GetResources(self):
63"""Set icon, menu and tooltip."""
64
65return {'Pixmap': 'Draft_PathTwistedArray',
66'MenuText': QT_TRANSLATE_NOOP("Draft_PathTwistedArray", "Path twisted array"),
67'ToolTip': QT_TRANSLATE_NOOP("Draft_PathTwistedArray", "Creates copies of the selected object along a selected path, and twists the copies.\nFirst select the object, and then select the path.\nThe path can be a polyline, B-spline, Bezier curve, or even edges from other objects.")}
68
69def Activated(self, name="Path twisted array"):
70"""Execute when the command is called."""
71super(PathTwistedArray, self).Activated(name=name)
72self.name = name
73self.proceed()
74
75def proceed(self):
76"""Proceed with the command if one object was selected."""
77sel = Gui.Selection.getSelectionEx()
78if len(sel) != 2:
79_err(translate("draft","Please select exactly two objects, the base object and the path object, before calling this command."))
80else:
81base_object = sel[0].Object
82path_object = sel[1].Object
83
84count = 15
85rot_factor = 0.25
86use_link = self.use_link
87
88Gui.addModule("Draft")
89_cmd = "Draft.make_path_twisted_array"
90_cmd += "("
91_cmd += "App.ActiveDocument." + base_object.Name + ", "
92_cmd += "App.ActiveDocument." + path_object.Name + ", "
93_cmd += "count=" + str(count) + ", "
94_cmd += "rot_factor=" + str(rot_factor) + ", "
95_cmd += "use_link=" + str(use_link)
96_cmd += ")"
97
98_cmd_list = ["_obj_ = " + _cmd,
99"Draft.autogroup(_obj_)",
100"App.ActiveDocument.recompute()"]
101self.commit(translate("draft","Path twisted array"), _cmd_list)
102
103# Commit the transaction and execute the commands
104# through the parent class
105self.finish()
106
107
108Gui.addCommand('Draft_PathTwistedArray', PathTwistedArray())
109
110
111class PathTwistedLinkArray(PathTwistedArray):
112"""Gui Command for the PathTwistedLinkArray tool."""
113
114def __init__(self):
115super(PathTwistedLinkArray, self).__init__(use_link=True)
116
117def GetResources(self):
118"""Set icon, menu and tooltip."""
119
120return {'Pixmap': 'Draft_PathTwistedLinkArray',
121'MenuText': QT_TRANSLATE_NOOP("Draft_PathTwistedLinkArray","Path twisted link array"),
122'ToolTip': QT_TRANSLATE_NOOP("Draft_PathTwistedLinkArray","Like the PathTwistedArray tool, but creates a 'Link array' instead.\nA 'Link array' is more efficient when handling many copies but the 'Fuse' option cannot be used.")}
123
124def Activated(self):
125"""Execute when the command is called."""
126super(PathTwistedLinkArray,
127self).Activated(name="Path twisted link array")
128
129
130Gui.addCommand('Draft_PathTwistedLinkArray', PathTwistedLinkArray())
131
132## @}
133