FreeCAD

Форк
0
/
make_rectangle.py 
102 строки · 4.0 Кб
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                                 *
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 Rectangle objects."""
24
## @package make_rectangle
25
# \ingroup draftmake
26
# \brief This module provides the code for Draft make_rectangle function.
27

28
## \addtogroup draftmake
29
# @{
30
import FreeCAD as App
31
import draftutils.utils as utils
32
import draftutils.gui_utils as gui_utils
33

34
from draftobjects.rectangle import Rectangle
35

36
if App.GuiUp:
37
    from draftviewproviders.view_rectangle import ViewProviderRectangle
38

39

40
def make_rectangle(length, height=0, placement=None, face=None, support=None):
41
    """make_rectangle(length, width, [placement], [face])
42

43
    Creates a Rectangle object with length in X direction and height in Y
44
    direction.
45

46
    Parameters
47
    ----------
48
    length, height : dimensions of the rectangle
49

50
    placement : Base.Placement
51
        If a placement is given, it is used.
52

53
    face : Bool
54
        If face is False, the rectangle is shown as a wireframe,
55
        otherwise as a face.
56

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).
62
    """
63

64
    if not App.ActiveDocument:
65
        App.Console.PrintError("No active document. Aborting\n")
66
        return
67

68
    if isinstance(length,(list,tuple)) and (len(length) == 4):
69
        verts = length
70
        xv = verts[1].sub(verts[0])
71
        yv = verts[3].sub(verts[0])
72
        zv = xv.cross(yv)
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)
76

77
    if placement:
78
        utils.type_check([(placement,App.Placement)], "make_rectangle")
79

80
    obj = App.ActiveDocument.addObject("Part::Part2DObjectPython","Rectangle")
81
    Rectangle(obj)
82

83
    obj.Length = length
84
    obj.Height = height
85
    obj.AttachmentSupport = support
86

87
    if face is not None:
88
        obj.MakeFace = face
89

90
    if placement: obj.Placement = placement
91

92
    if App.GuiUp:
93
        ViewProviderRectangle(obj.ViewObject)
94
        gui_utils.format_object(obj)
95
        gui_utils.select(obj)
96

97
    return obj
98

99

100
makeRectangle = make_rectangle
101

102
## @}
103

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

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

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

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