FreeCAD

Форк
0
/
make_array.py 
155 строк · 6.1 Кб
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) 2020 Eliud Cabrera Castillo <e.cabrera-castillo@tum.de> *
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 functions to create Array objects.
24

25
This includes orthogonal arrays, polar arrays, and circular arrays.
26
"""
27
## @package make_array
28
# \ingroup draftmake
29
# \brief Provides functions to create Array objects.
30

31
## \addtogroup draftmake
32
# @{
33
import FreeCAD as App
34
import draftutils.utils as utils
35
import draftutils.gui_utils as gui_utils
36

37
from draftutils.messages import _wrn, _err
38
from draftutils.translate import translate
39
from draftobjects.array import Array
40

41
if App.GuiUp:
42
    from draftviewproviders.view_array import ViewProviderDraftArray
43
    from draftviewproviders.view_draftlink import ViewProviderDraftLink
44

45

46
def make_array(base_object,
47
               arg1, arg2, arg3,
48
               arg4=None, arg5=None, arg6=None,
49
               use_link=True):
50
    """Create a Draft Array of the given object.
51

52
    Rectangular array
53
    -----------------
54
    make_array(object, xvector, yvector, xnum, ynum)
55
    make_array(object, xvector, yvector, zvector, xnum, ynum, znum)
56

57
    xnum of iterations in the x direction
58
    at xvector distance between iterations, same for y direction
59
    with yvector and ynum, same for z direction with zvector and znum.
60

61
    Polar array
62
    -----------
63
    make_array(object, center, totalangle, totalnum) for polar array, or
64

65
    center is a vector, totalangle is the angle to cover (in degrees)
66
    and totalnum is the number of objects, including the original.
67

68
    Circular array
69
    --------------
70
    make_array(object, rdistance, tdistance, axis, center, ncircles, symmetry)
71

72
    In case of a circular array, rdistance is the distance of the
73
    circles, tdistance is the distance within circles, axis the rotation-axis,
74
    center the center of rotation, ncircles the number of circles
75
    and symmetry the number of symmetry-axis of the distribution.
76

77
    To Do
78
    -----
79
    The `Array` class currently handles three types of arrays,
80
    orthogonal, polar, and circular. In the future, probably they should be
81
    split in separate classes so that they are easier to manage.
82
    """
83
    found, doc = utils.find_doc(App.activeDocument())
84
    if not found:
85
        _err(translate("draft","No active document. Aborting."))
86
        return None
87

88
    if use_link:
89
        # The Array class must be called in this special way
90
        # to make it a LinkArray
91
        new_obj = doc.addObject("Part::FeaturePython", "Array",
92
                                Array(None), None, True)
93
    else:
94
        new_obj = doc.addObject("Part::FeaturePython", "Array")
95
        Array(new_obj)
96

97
    new_obj.Base = base_object
98
    if arg6:
99
        if isinstance(arg1, (int, float, App.Units.Quantity)):
100
            new_obj.ArrayType = "circular"
101
            new_obj.RadialDistance = arg1
102
            new_obj.TangentialDistance = arg2
103
            new_obj.Axis = arg3
104
            new_obj.Center = arg4
105
            new_obj.NumberCircles = arg5
106
            new_obj.Symmetry = arg6
107
        else:
108
            new_obj.ArrayType = "ortho"
109
            new_obj.IntervalX = arg1
110
            new_obj.IntervalY = arg2
111
            new_obj.IntervalZ = arg3
112
            new_obj.NumberX = arg4
113
            new_obj.NumberY = arg5
114
            new_obj.NumberZ = arg6
115
    elif arg4:
116
        new_obj.ArrayType = "ortho"
117
        new_obj.IntervalX = arg1
118
        new_obj.IntervalY = arg2
119
        new_obj.NumberX = arg3
120
        new_obj.NumberY = arg4
121
    else:
122
        new_obj.ArrayType = "polar"
123
        new_obj.Center = arg1
124
        new_obj.Angle = arg2
125
        new_obj.NumberPolar = arg3
126

127
    if App.GuiUp:
128
        if use_link:
129
            ViewProviderDraftLink(new_obj.ViewObject)
130
        else:
131
            if new_obj.ArrayType == "circular":
132
                new_obj.Proxy.execute(new_obj) # Updates Count which is required for correct DiffuseColor.
133
            ViewProviderDraftArray(new_obj.ViewObject)
134
            gui_utils.format_object(new_obj, new_obj.Base)
135
            new_obj.ViewObject.Proxy.resetColors(new_obj.ViewObject)
136
        new_obj.Base.ViewObject.hide()
137
        gui_utils.select(new_obj)
138

139
    return new_obj
140

141

142
def makeArray(baseobject,
143
              arg1, arg2, arg3,
144
              arg4=None, arg5=None, arg6=None,
145
              name="Array", use_link=False):
146
    """Create an Array. DEPRECATED. Use 'make_array'."""
147
    _wrn("Do not use this function directly; instead, use "
148
         "'make_ortho_array', 'make_polar_array', "
149
         "or 'make_circular_array'.")
150

151
    return make_array(baseobject,
152
                      arg1, arg2, arg3,
153
                      arg4, arg5, arg6, use_link)
154

155
## @}
156

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

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

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

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