FreeCAD

Форк
0
/
gui_pathtwistedarray.py 
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

25
The copies will be created along a path, like a polyline, B-spline,
26
or Bezier curve.
27
"""
28
## @package gui_pathtwistedarray
29
# \ingroup draftguitools
30
# \brief Provides GUI tools to create PathTwistedArray objects.
31

32
## \addtogroup draftguitools
33
# @{
34
from PySide.QtCore import QT_TRANSLATE_NOOP
35

36
import FreeCADGui as Gui
37
import Draft_rc
38
import draftguitools.gui_base_original as gui_base_original
39

40
from draftutils.messages import _err
41
from draftutils.translate import translate
42

43
# The module is used to prevent complaints from code checkers (flake8)
44
True if Draft_rc.__name__ else False
45

46

47
class PathTwistedArray(gui_base_original.Modifier):
48
    """Gui Command for the Path twisted array tool.
49

50
    Parameters
51
    ----------
52
    use_link: bool, optional
53
        It defaults to `False`. If it is `True`, the created object
54
        will be a `Link array`.
55
    """
56

57
    def __init__(self, use_link=False):
58
        super(PathTwistedArray, self).__init__()
59
        self.use_link = use_link
60
        self.call = None
61

62
    def GetResources(self):
63
        """Set icon, menu and tooltip."""
64

65
        return {'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

69
    def Activated(self, name="Path twisted array"):
70
        """Execute when the command is called."""
71
        super(PathTwistedArray, self).Activated(name=name)
72
        self.name = name
73
        self.proceed()
74

75
    def proceed(self):
76
        """Proceed with the command if one object was selected."""
77
        sel = Gui.Selection.getSelectionEx()
78
        if len(sel) != 2:
79
            _err(translate("draft","Please select exactly two objects, the base object and the path object, before calling this command."))
80
        else:
81
            base_object = sel[0].Object
82
            path_object = sel[1].Object
83

84
            count = 15
85
            rot_factor = 0.25
86
            use_link = self.use_link
87

88
            Gui.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()"]
101
            self.commit(translate("draft","Path twisted array"), _cmd_list)
102

103
        # Commit the transaction and execute the commands
104
        # through the parent class
105
        self.finish()
106

107

108
Gui.addCommand('Draft_PathTwistedArray', PathTwistedArray())
109

110

111
class PathTwistedLinkArray(PathTwistedArray):
112
    """Gui Command for the PathTwistedLinkArray tool."""
113

114
    def __init__(self):
115
        super(PathTwistedLinkArray, self).__init__(use_link=True)
116

117
    def GetResources(self):
118
        """Set icon, menu and tooltip."""
119

120
        return {'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

124
    def Activated(self):
125
        """Execute when the command is called."""
126
        super(PathTwistedLinkArray,
127
              self).Activated(name="Path twisted link array")
128

129

130
Gui.addCommand('Draft_PathTwistedLinkArray', PathTwistedLinkArray())
131

132
## @}
133

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.