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 FreeCAD Developers *
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 Rectangle objects."""
24
## @package make_rectangle
26
# \brief This module provides the code for Draft make_rectangle function.
28
## \addtogroup draftmake
31
import draftutils.utils as utils
32
import draftutils.gui_utils as gui_utils
34
from draftobjects.rectangle import Rectangle
37
from draftviewproviders.view_rectangle import ViewProviderRectangle
40
def make_rectangle(length, height=0, placement=None, face=None, support=None):
41
"""make_rectangle(length, width, [placement], [face])
43
Creates a Rectangle object with length in X direction and height in Y
48
length, height : dimensions of the rectangle
50
placement : Base.Placement
51
If a placement is given, it is used.
54
If face is False, the rectangle is shown as a wireframe,
57
Rectangles can also be constructed by giving them a list of four vertices
58
as first argument: make_rectangle(list_of_vertices, face=...)
59
but you are responsible to check yourself that these 4 vertices are ordered
60
and actually form a rectangle, otherwise the result might be wrong. Placement
61
is ignored when constructing a rectangle this way (face argument is kept).
64
if not App.ActiveDocument:
65
App.Console.PrintError("No active document. Aborting\n")
68
if isinstance(length,(list,tuple)) and (len(length) == 4):
70
xv = verts[1].sub(verts[0])
71
yv = verts[3].sub(verts[0])
73
rr = App.Rotation(xv, yv, zv, "XYZ")
74
rp = App.Placement(verts[0], rr)
75
return make_rectangle(xv.Length, yv.Length, rp, face, support)
78
utils.type_check([(placement,App.Placement)], "make_rectangle")
80
obj = App.ActiveDocument.addObject("Part::Part2DObjectPython","Rectangle")
85
obj.AttachmentSupport = support
90
if placement: obj.Placement = placement
93
ViewProviderRectangle(obj.ViewObject)
94
gui_utils.format_object(obj)
100
makeRectangle = make_rectangle