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 BSpline objects."""
24
## @package make_bspline
26
# \brief Provides functions to create BSpline objects.
28
## \addtogroup draftmake
31
import draftutils.utils as utils
32
import draftutils.gui_utils as gui_utils
34
from draftutils.translate import translate
35
from draftobjects.bspline import BSpline
38
from draftviewproviders.view_bspline import ViewProviderBSpline
41
def make_bspline(pointslist, closed=False, placement=None, face=None, support=None):
42
"""make_bspline(pointslist, [closed], [placement])
44
Creates a B-Spline object from the given list of vectors.
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!
54
If closed is True or first and last points are identical,
55
the created BSpline will be closed.
57
placement : Base.Placement
58
If a placement is given, it is used.
61
If face is False, the rectangle is shown as a wireframe,
67
if not App.ActiveDocument:
68
App.Console.PrintError("No active document. Aborting\n")
70
if not isinstance(pointslist,list):
72
for v in pointslist.Vertexes:
75
if len(pointslist) < 2:
76
_err = "Draft.make_bspline: not enough points"
77
App.Console.PrintError(translate("draft", _err)+"\n")
79
if (pointslist[0] == pointslist[-1]):
80
if len(pointslist) > 2:
83
_err = "Draft.make_bspline: Equal endpoints forced Closed"
84
App.Console.PrintWarning(translate("Draft", _err) + _err + "\n")
86
# len == 2 and first == last GIGO
87
_err = "Draft.make_bspline: Invalid pointslist"
88
App.Console.PrintError(translate("Draft", _err)+"\n")
90
# should have sensible parms from here on
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)
98
obj.Points = pointslist
99
obj.AttachmentSupport = support
102
if placement: obj.Placement = placement
104
ViewProviderBSpline(obj.ViewObject)
105
gui_utils.format_object(obj)
106
gui_utils.select(obj)
111
makeBSpline = make_bspline