FreeCAD
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# @{
30import FreeCAD as App31import draftutils.utils as utils32import draftutils.gui_utils as gui_utils33
34from draftutils.translate import translate35from draftobjects.bezcurve import BezCurve36
37if App.GuiUp:38from draftviewproviders.view_bezcurve import ViewProviderBezCurve39
40
41def make_bezcurve(pointslist,42closed=False, placement=None, face=None, support=None,43degree=None):44"""make_bezcurve(pointslist, [closed], [placement])45
46Creates a Bezier Curve object from the given list of vectors.
47
48Parameters
49----------
50pointlist : [Base.Vector]
51List of points to create the polyline.
52Instead of a pointslist, you can also pass a Part Wire.
53TODO: Change the name so!
54
55closed : bool
56If closed is True or first and last points are identical,
57the created BSpline will be closed.
58
59placement : Base.Placement
60If a placement is given, it is used.
61
62face : Bool
63If face is False, the rectangle is shown as a wireframe,
64otherwise as a face.
65
66support :
67TODO: Describe
68
69degree : int
70Degree of the BezCurve
71"""
72if not App.ActiveDocument:73App.Console.PrintError("No active document. Aborting\n")74return75if not isinstance(pointslist,list):76nlist = []77for v in pointslist.Vertexes:78nlist.append(v.Point)79pointslist = nlist80if placement:81utils.type_check([(placement,App.Placement)], "make_bezcurve")82if len(pointslist) == 2: fname = "Line"83else: fname = "BezCurve"84obj = App.ActiveDocument.addObject("Part::Part2DObjectPython",fname)85BezCurve(obj)86obj.Points = pointslist87if degree:88obj.Degree = degree89else:90import Part91obj.Degree = min((len(pointslist)-(1 * (not closed))),92Part.BezierCurve().MaxDegree)93obj.Closed = closed94obj.AttachmentSupport = support95if face is not None:96obj.MakeFace = face97obj.Proxy.resetcontinuity(obj)98if placement: obj.Placement = placement99if App.GuiUp:100ViewProviderBezCurve(obj.ViewObject)101# if not face: obj.ViewObject.DisplayMode = "Wireframe"
102# obj.ViewObject.DisplayMode = "Wireframe"
103gui_utils.format_object(obj)104gui_utils.select(obj)105
106return obj107
108
109makeBezCurve = make_bezcurve110
111## @}
112