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> *
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. *
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. *
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 *
22
# ***************************************************************************
23
"""Provides functions to create Array objects.
25
This includes orthogonal arrays, polar arrays, and circular arrays.
29
# \brief Provides functions to create Array objects.
31
## \addtogroup draftmake
34
import draftutils.utils as utils
35
import draftutils.gui_utils as gui_utils
37
from draftutils.messages import _wrn, _err
38
from draftutils.translate import translate
39
from draftobjects.array import Array
42
from draftviewproviders.view_array import ViewProviderDraftArray
43
from draftviewproviders.view_draftlink import ViewProviderDraftLink
46
def make_array(base_object,
48
arg4=None, arg5=None, arg6=None,
50
"""Create a Draft Array of the given object.
54
make_array(object, xvector, yvector, xnum, ynum)
55
make_array(object, xvector, yvector, zvector, xnum, ynum, znum)
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.
63
make_array(object, center, totalangle, totalnum) for polar array, or
65
center is a vector, totalangle is the angle to cover (in degrees)
66
and totalnum is the number of objects, including the original.
70
make_array(object, rdistance, tdistance, axis, center, ncircles, symmetry)
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.
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.
83
found, doc = utils.find_doc(App.activeDocument())
85
_err(translate("draft","No active document. Aborting."))
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)
94
new_obj = doc.addObject("Part::FeaturePython", "Array")
97
new_obj.Base = base_object
99
if isinstance(arg1, (int, float, App.Units.Quantity)):
100
new_obj.ArrayType = "circular"
101
new_obj.RadialDistance = arg1
102
new_obj.TangentialDistance = arg2
104
new_obj.Center = arg4
105
new_obj.NumberCircles = arg5
106
new_obj.Symmetry = arg6
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
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
122
new_obj.ArrayType = "polar"
123
new_obj.Center = arg1
125
new_obj.NumberPolar = arg3
129
ViewProviderDraftLink(new_obj.ViewObject)
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)
142
def makeArray(baseobject,
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'.")
151
return make_array(baseobject,
153
arg4, arg5, arg6, use_link)