FreeCAD

Форк
0
/
make_bezcurve.py 
111 строк · 4.2 Кб
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 BezCurve objects."""
24
## @package make_bezcurve
25
# \ingroup draftmake
26
# \brief Provides functions to create BezCurve objects.
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 draftutils.translate import translate
35
from draftobjects.bezcurve import BezCurve
36

37
if App.GuiUp:
38
    from draftviewproviders.view_bezcurve import ViewProviderBezCurve
39

40

41
def make_bezcurve(pointslist,
42
                  closed=False, placement=None, face=None, support=None,
43
                  degree=None):
44
    """make_bezcurve(pointslist, [closed], [placement])
45

46
    Creates a Bezier Curve object from the given list of vectors.
47

48
    Parameters
49
    ----------
50
    pointlist : [Base.Vector]
51
        List of points to create the polyline.
52
        Instead of a pointslist, you can also pass a Part Wire.
53
        TODO: Change the name so!
54

55
    closed : bool
56
        If closed is True or first and last points are identical,
57
        the created BSpline will be closed.
58

59
    placement : Base.Placement
60
        If a placement is given, it is used.
61

62
    face : Bool
63
        If face is False, the rectangle is shown as a wireframe,
64
        otherwise as a face.
65

66
    support :
67
        TODO: Describe
68

69
    degree : int
70
        Degree of the BezCurve
71
    """
72
    if not App.ActiveDocument:
73
        App.Console.PrintError("No active document. Aborting\n")
74
        return
75
    if not isinstance(pointslist,list):
76
        nlist = []
77
        for v in pointslist.Vertexes:
78
            nlist.append(v.Point)
79
        pointslist = nlist
80
    if placement:
81
        utils.type_check([(placement,App.Placement)], "make_bezcurve")
82
    if len(pointslist) == 2: fname = "Line"
83
    else: fname = "BezCurve"
84
    obj = App.ActiveDocument.addObject("Part::Part2DObjectPython",fname)
85
    BezCurve(obj)
86
    obj.Points = pointslist
87
    if degree:
88
        obj.Degree = degree
89
    else:
90
        import Part
91
        obj.Degree = min((len(pointslist)-(1 * (not closed))),
92
                         Part.BezierCurve().MaxDegree)
93
    obj.Closed = closed
94
    obj.AttachmentSupport = support
95
    if face is not None:
96
        obj.MakeFace = face
97
    obj.Proxy.resetcontinuity(obj)
98
    if placement: obj.Placement = placement
99
    if App.GuiUp:
100
        ViewProviderBezCurve(obj.ViewObject)
101
#        if not face: obj.ViewObject.DisplayMode = "Wireframe"
102
#        obj.ViewObject.DisplayMode = "Wireframe"
103
        gui_utils.format_object(obj)
104
        gui_utils.select(obj)
105

106
    return obj
107

108

109
makeBezCurve = make_bezcurve
110

111
## @}
112

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

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

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

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