FreeCAD

Форк
0
/
gui_patharray.py 
177 строк · 7.7 Кб
1
# ***************************************************************************
2
# *   Copyright (c) 2009, 2010 Yorik van Havre <yorik@uncreated.net>        *
3
# *   Copyright (c) 2009, 2010 Ken Cline <cline@frii.com>                   *
4
# *   Copyright (c) 2013 WandererFan <wandererfan@gmail.com>                *
5
# *   Copyright (c) 2019 Zheng, Lei (realthunder)<realthunder.dev@gmail.com>*
6
# *   Copyright (c) 2020 Carlo Pavan <carlopav@gmail.com>                   *
7
# *   Copyright (c) 2020 Eliud Cabrera Castillo <e.cabrera-castillo@tum.de> *
8
# *                                                                         *
9
# *   This file is part of the FreeCAD CAx development system.              *
10
# *                                                                         *
11
# *   This program is free software; you can redistribute it and/or modify  *
12
# *   it under the terms of the GNU Lesser General Public License (LGPL)    *
13
# *   as published by the Free Software Foundation; either version 2 of     *
14
# *   the License, or (at your option) any later version.                   *
15
# *   for detail see the LICENCE text file.                                 *
16
# *                                                                         *
17
# *   This program is distributed in the hope that it will be useful,       *
18
# *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
19
# *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
20
# *   GNU Library General Public License for more details.                  *
21
# *                                                                         *
22
# *   You should have received a copy of the GNU Library General Public     *
23
# *   License along with this program; if not, write to the Free Software   *
24
# *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
25
# *   USA                                                                   *
26
# *                                                                         *
27
# ***************************************************************************
28
"""Provides GUI tools to create PathArray objects.
29

30
The copies will be created along a path, like a polyline, B-spline,
31
or Bezier curve.
32
"""
33
## @package gui_patharray
34
# \ingroup draftguitools
35
# \brief Provides GUI tools to create PathArray objects.
36

37
## \addtogroup draftguitools
38
# @{
39
from PySide.QtCore import QT_TRANSLATE_NOOP
40

41
import FreeCAD as App
42
import FreeCADGui as Gui
43
import Draft_rc
44
import DraftVecUtils
45
import draftguitools.gui_base_original as gui_base_original
46

47
from draftutils.messages import _err
48
from draftutils.translate import translate
49

50
# The module is used to prevent complaints from code checkers (flake8)
51
True if Draft_rc.__name__ else False
52

53

54
class PathArray(gui_base_original.Modifier):
55
    """Gui Command for the Path array tool.
56

57
    Parameters
58
    ----------
59
    use_link: bool, optional
60
        It defaults to `False`. If it is `True`, the created object
61
        will be a `Link array`.
62
    """
63

64
    def __init__(self, use_link=False):
65
        super(PathArray, self).__init__()
66
        self.use_link = use_link
67
        self.call = None
68

69
    def GetResources(self):
70
        """Set icon, menu and tooltip."""
71

72
        return {'Pixmap': 'Draft_PathArray',
73
                'MenuText': QT_TRANSLATE_NOOP("Draft_PathArray", "Path array"),
74
                'ToolTip': QT_TRANSLATE_NOOP("Draft_PathArray", "Creates copies of the selected object along a selected path.\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.")}
75

76
    def Activated(self, name="Path array"):
77
        """Execute when the command is called."""
78
        super(PathArray, self).Activated(name=name)
79
        self.name = name
80
        # This was deactivated because it doesn't work correctly;
81
        # the selection needs to be made on two objects, but currently
82
        # it only selects one.
83

84
        # if not Gui.Selection.getSelectionEx():
85
        #     if self.ui:
86
        #         self.ui.selectUi()
87
        #         _msg(translate("draft",
88
        #                        "Please select exactly two objects, "
89
        #                        "the base object and the path object, "
90
        #                        "before calling this command."))
91
        #         self.call = \
92
        #             self.view.addEventCallback("SoEvent",
93
        #                                        gui_tool_utils.selectObject)
94
        # else:
95
        #     self.proceed()
96
        self.proceed()
97

98
    def proceed(self):
99
        """Proceed with the command if one object was selected."""
100
        sel = Gui.Selection.getSelectionEx()
101
        if len(sel) != 2:
102
            _err(translate("draft","Please select exactly two objects, the base object and the path object, before calling this command."))
103
        else:
104
            base_object = sel[0].Object
105
            path_object = sel[1].Object
106

107
            count = 4
108
            extra = App.Vector(0, 0, 0)
109
            subelements = list(sel[1].SubElementNames)
110
            align = False
111
            align_mode = "Original"
112
            tan_vector = App.Vector(1, 0, 0)
113
            force_vertical = False
114
            vertical_vector = App.Vector(0, 0, 1)
115
            start_offset = 0.0
116
            end_offset = 0.0
117
            use_link = self.use_link
118

119
            _edge_list_str = list()
120
            _edge_list_str = ["'" + edge + "'" for edge in subelements]
121
            _sub_str = ", ".join(_edge_list_str)
122
            subelements_list_str = "[" + _sub_str + "]"
123

124
            vertical_vector_str = DraftVecUtils.toString(vertical_vector)
125

126
            Gui.addModule("Draft")
127
            _cmd = "Draft.make_path_array"
128
            _cmd += "("
129
            _cmd += "App.ActiveDocument." + base_object.Name + ", "
130
            _cmd += "App.ActiveDocument." + path_object.Name + ", "
131
            _cmd += "count=" + str(count) + ", "
132
            _cmd += "extra=" + DraftVecUtils.toString(extra) + ", "
133
            _cmd += "subelements=" + subelements_list_str + ", "
134
            _cmd += "align=" + str(align) + ", "
135
            _cmd += "align_mode=" + "'" + align_mode + "', "
136
            _cmd += "tan_vector=" + DraftVecUtils.toString(tan_vector) + ", "
137
            _cmd += "force_vertical=" + str(force_vertical) + ", "
138
            _cmd += "vertical_vector=" + vertical_vector_str + ", "
139
            _cmd += "start_offset=" + str(start_offset) + ", "
140
            _cmd += "end_offset=" + str(end_offset) + ", "
141
            _cmd += "use_link=" + str(use_link)
142
            _cmd += ")"
143

144
            _cmd_list = ["_obj_ = " + _cmd,
145
                         "Draft.autogroup(_obj_)",
146
                         "App.ActiveDocument.recompute()"]
147
            self.commit(translate("draft","Path array"), _cmd_list)
148

149
        # Commit the transaction and execute the commands
150
        # through the parent class
151
        self.finish()
152

153

154
Gui.addCommand('Draft_PathArray', PathArray())
155

156

157
class PathLinkArray(PathArray):
158
    """Gui Command for the PathLinkArray tool based on the PathArray tool."""
159

160
    def __init__(self):
161
        super(PathLinkArray, self).__init__(use_link=True)
162

163
    def GetResources(self):
164
        """Set icon, menu and tooltip."""
165

166
        return {'Pixmap': 'Draft_PathLinkArray',
167
                'MenuText': QT_TRANSLATE_NOOP("Draft_PathLinkArray", "Path link array"),
168
                'ToolTip': QT_TRANSLATE_NOOP("Draft_PathLinkArray", "Like the PathArray tool, but creates a 'Link array' instead.\nA 'Link array' is more efficient when handling many copies but the 'Fuse' option cannot be used.")}
169

170
    def Activated(self):
171
        """Execute when the command is called."""
172
        super(PathLinkArray, self).Activated(name="Path link array")
173

174

175
Gui.addCommand('Draft_PathLinkArray', PathLinkArray())
176

177
## @}
178

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

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

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

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