FreeCAD

Форк
0
/
make_polygon.py 
89 строк · 3.4 Кб
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 Polygon objects."""
24
## @package make_polygon
25
# \ingroup draftmake
26
# \brief Provides functions to create Polygon objects.
27

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

33
from draftobjects.polygon import Polygon
34
from draftviewproviders.view_base import ViewProviderDraft
35

36

37
def make_polygon(nfaces, radius=1, inscribed=True, placement=None, face=None, support=None):
38
    """makePolgon(edges,[radius],[inscribed],[placement],[face])
39

40
    Creates a polygon object with the given number of edges and radius.
41

42
    Parameters
43
    ----------
44
    edges : int
45
        Number of edges of the polygon.
46

47
    radius :
48
        Radius of the control circle.
49

50
    inscribed : bool
51
        Defines is the polygon is inscribed or not into the control circle.
52

53
    placement : Base.Placement
54
        If placement is given, it is used.
55

56
    face : bool
57
        If face is True, the resulting shape is displayed as a face,
58
        otherwise as a wireframe.
59

60
    support :
61
        TODO: Describe
62
    """
63
    if not App.ActiveDocument:
64
        App.Console.PrintError("No active document. Aborting\n")
65
        return
66
    if nfaces < 3: return None
67
    obj = App.ActiveDocument.addObject("Part::Part2DObjectPython","Polygon")
68
    Polygon(obj)
69
    obj.FacesNumber = nfaces
70
    obj.Radius = radius
71
    if face is not None:
72
        obj.MakeFace = face
73
    if inscribed:
74
        obj.DrawMode = "inscribed"
75
    else:
76
        obj.DrawMode = "circumscribed"
77
    obj.AttachmentSupport = support
78
    if placement: obj.Placement = placement
79
    if App.GuiUp:
80
        ViewProviderDraft(obj.ViewObject)
81
        gui_utils.format_object(obj)
82
        gui_utils.select(obj)
83

84
    return obj
85

86

87
makePolygon = make_polygon
88

89
## @}
90

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

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

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

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