FreeCAD

Форк
0
/
make_bspline.py 
113 строк · 4.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 BSpline objects."""
24
## @package make_bspline
25
# \ingroup draftmake
26
# \brief Provides functions to create BSpline 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.bspline import BSpline
36

37
if App.GuiUp:
38
    from draftviewproviders.view_bspline import ViewProviderBSpline
39

40

41
def make_bspline(pointslist, closed=False, placement=None, face=None, support=None):
42
    """make_bspline(pointslist, [closed], [placement])
43

44
    Creates a B-Spline object from the given list of vectors.
45

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

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

57
    placement : Base.Placement
58
        If a placement is given, it is used.
59

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

64
    support :
65
        TODO: Describe
66
    """
67
    if not App.ActiveDocument:
68
        App.Console.PrintError("No active document. Aborting\n")
69
        return
70
    if not isinstance(pointslist,list):
71
        nlist = []
72
        for v in pointslist.Vertexes:
73
            nlist.append(v.Point)
74
        pointslist = nlist
75
    if len(pointslist) < 2:
76
        _err = "Draft.make_bspline: not enough points"
77
        App.Console.PrintError(translate("draft", _err)+"\n")
78
        return
79
    if (pointslist[0] == pointslist[-1]):
80
        if len(pointslist) > 2:
81
            closed = True
82
            pointslist.pop()
83
            _err = "Draft.make_bspline: Equal endpoints forced Closed"
84
            App.Console.PrintWarning(translate("Draft", _err) + _err + "\n")
85
        else:
86
            # len == 2 and first == last   GIGO
87
            _err = "Draft.make_bspline: Invalid pointslist"
88
            App.Console.PrintError(translate("Draft", _err)+"\n")
89
            return
90
    # should have sensible parms from here on
91
    if placement:
92
        utils.type_check([(placement,App.Placement)], "make_bspline")
93
    if len(pointslist) == 2: fname = "Line"
94
    else: fname = "BSpline"
95
    obj = App.ActiveDocument.addObject("Part::Part2DObjectPython",fname)
96
    BSpline(obj)
97
    obj.Closed = closed
98
    obj.Points = pointslist
99
    obj.AttachmentSupport = support
100
    if face is not None:
101
        obj.MakeFace = face
102
    if placement: obj.Placement = placement
103
    if App.GuiUp:
104
        ViewProviderBSpline(obj.ViewObject)
105
        gui_utils.format_object(obj)
106
        gui_utils.select(obj)
107

108
    return obj
109

110

111
makeBSpline = make_bspline
112

113
## @}
114

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

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

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

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