Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Draft: split wire related tools from Draft.py
Line Polyline BezCurve BSpline . . .
- Loading branch information
1 parent
4eab0bb
commit f1eaa0b
Showing
10 changed files
with
1,185 additions
and
572 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# *************************************************************************** | ||
# * Copyright (c) 2009, 2010 Yorik van Havre <yorik@uncreated.net> * | ||
# * Copyright (c) 2009, 2010 Ken Cline <cline@frii.com> * | ||
# * Copyright (c) 2020 FreeCAD Developers * | ||
# * * | ||
# * This program is free software; you can redistribute it and/or modify * | ||
# * it under the terms of the GNU Lesser General Public License (LGPL) * | ||
# * as published by the Free Software Foundation; either version 2 of * | ||
# * the License, or (at your option) any later version. * | ||
# * for detail see the LICENCE text file. * | ||
# * * | ||
# * This program is distributed in the hope that it will be useful, * | ||
# * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
# * GNU Library General Public License for more details. * | ||
# * * | ||
# * You should have received a copy of the GNU Library General Public * | ||
# * License along with this program; if not, write to the Free Software * | ||
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * | ||
# * USA * | ||
# * * | ||
# *************************************************************************** | ||
"""This module provides the code for Draft make_bezcurve function. | ||
""" | ||
## @package make_bezcurve | ||
# \ingroup DRAFT | ||
# \brief This module provides the code for Draft make_bezcurve function. | ||
|
||
import FreeCAD as App | ||
|
||
from draftutils.gui_utils import format_object | ||
from draftutils.gui_utils import select | ||
|
||
from draftutils.utils import type_check | ||
from draftutils.translate import translate | ||
|
||
from draftobjects.bezcurve import BezCurve | ||
if App.GuiUp: | ||
from draftviewproviders.view_bezcurve import ViewProviderBezCurve | ||
|
||
|
||
def make_bezcurve(pointslist, closed=False, placement=None, face=None, support=None, degree=None): | ||
"""make_bezcurve(pointslist, [closed], [placement]) | ||
Creates a Bezier Curve object from the given list of vectors. | ||
Parameters | ||
---------- | ||
pointlist : [Base.Vector] | ||
List of points to create the polyline. | ||
Instead of a pointslist, you can also pass a Part Wire. | ||
TODO: Change the name so! | ||
closed : bool | ||
If closed is True or first and last points are identical, | ||
the created BSpline will be closed. | ||
placement : Base.Placement | ||
If a placement is given, it is used. | ||
face : Bool | ||
If face is False, the rectangle is shown as a wireframe, | ||
otherwise as a face. | ||
support : | ||
TODO: Describe | ||
degree : int | ||
Degree of the BezCurve | ||
""" | ||
if not App.ActiveDocument: | ||
App.Console.PrintError("No active document. Aborting\n") | ||
return | ||
if not isinstance(pointslist,list): | ||
nlist = [] | ||
for v in pointslist.Vertexes: | ||
nlist.append(v.Point) | ||
pointslist = nlist | ||
if placement: type_check([(placement,App.Placement)], "make_bezcurve") | ||
if len(pointslist) == 2: fname = "Line" | ||
else: fname = "BezCurve" | ||
obj = App.ActiveDocument.addObject("Part::Part2DObjectPython",fname) | ||
BezCurve(obj) | ||
obj.Points = pointslist | ||
if degree: | ||
obj.Degree = degree | ||
else: | ||
import Part | ||
obj.Degree = min((len(pointslist)-(1 * (not closed))), | ||
Part.BezierCurve().MaxDegree) | ||
obj.Closed = closed | ||
obj.Support = support | ||
if face != None: | ||
obj.MakeFace = face | ||
obj.Proxy.resetcontinuity(obj) | ||
if placement: obj.Placement = placement | ||
if App.GuiUp: | ||
ViewProviderBezCurve(obj.ViewObject) | ||
# if not face: obj.ViewObject.DisplayMode = "Wireframe" | ||
# obj.ViewObject.DisplayMode = "Wireframe" | ||
format_object(obj) | ||
select(obj) | ||
|
||
return obj | ||
|
||
|
||
makeBezCurve = make_bezcurve |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
# *************************************************************************** | ||
# * Copyright (c) 2009, 2010 Yorik van Havre <yorik@uncreated.net> * | ||
# * Copyright (c) 2009, 2010 Ken Cline <cline@frii.com> * | ||
# * Copyright (c) 2020 FreeCAD Developers * | ||
# * * | ||
# * This program is free software; you can redistribute it and/or modify * | ||
# * it under the terms of the GNU Lesser General Public License (LGPL) * | ||
# * as published by the Free Software Foundation; either version 2 of * | ||
# * the License, or (at your option) any later version. * | ||
# * for detail see the LICENCE text file. * | ||
# * * | ||
# * This program is distributed in the hope that it will be useful, * | ||
# * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
# * GNU Library General Public License for more details. * | ||
# * * | ||
# * You should have received a copy of the GNU Library General Public * | ||
# * License along with this program; if not, write to the Free Software * | ||
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * | ||
# * USA * | ||
# * * | ||
# *************************************************************************** | ||
"""This module provides the code for Draft make_bspline function. | ||
""" | ||
## @package make_bspline | ||
# \ingroup DRAFT | ||
# \brief This module provides the code for Draft make_bspline function. | ||
|
||
import FreeCAD as App | ||
|
||
from draftutils.gui_utils import format_object | ||
from draftutils.gui_utils import select | ||
|
||
from draftutils.utils import type_check | ||
from draftutils.translate import translate | ||
|
||
from draftobjects.bspline import BSpline | ||
if App.GuiUp: | ||
from draftviewproviders.view_bspline import ViewProviderBSpline | ||
|
||
|
||
def make_bspline(pointslist, closed=False, placement=None, face=None, support=None): | ||
"""make_bspline(pointslist, [closed], [placement]) | ||
Creates a B-Spline object from the given list of vectors. | ||
Parameters | ||
---------- | ||
pointlist : [Base.Vector] | ||
List of points to create the polyline. | ||
Instead of a pointslist, you can also pass a Part Wire. | ||
TODO: Change the name so! | ||
closed : bool | ||
If closed is True or first and last points are identical, | ||
the created BSpline will be closed. | ||
placement : Base.Placement | ||
If a placement is given, it is used. | ||
face : Bool | ||
If face is False, the rectangle is shown as a wireframe, | ||
otherwise as a face. | ||
support : | ||
TODO: Describe | ||
""" | ||
if not App.ActiveDocument: | ||
App.Console.PrintError("No active document. Aborting\n") | ||
return | ||
if not isinstance(pointslist,list): | ||
nlist = [] | ||
for v in pointslist.Vertexes: | ||
nlist.append(v.Point) | ||
pointslist = nlist | ||
if len(pointslist) < 2: | ||
_err = "Draft.makeBSpline: not enough points" | ||
App.Console.PrintError(translate("draft", _err)+"\n") | ||
return | ||
if (pointslist[0] == pointslist[-1]): | ||
if len(pointslist) > 2: | ||
closed = True | ||
pointslist.pop() | ||
_err = "Draft.makeBSpline: Equal endpoints forced Closed" | ||
App.Console.PrintWarning(translate("Draft", _err) + _err + "\n") | ||
else: | ||
# len == 2 and first == last GIGO | ||
_err = "Draft.makeBSpline: Invalid pointslist" | ||
App.Console.PrintError(translate("Draft", _err)+"\n") | ||
return | ||
# should have sensible parms from here on | ||
if placement: type_check([(placement,App.Placement)], "make_bspline") | ||
if len(pointslist) == 2: fname = "Line" | ||
else: fname = "BSpline" | ||
obj = App.ActiveDocument.addObject("Part::Part2DObjectPython",fname) | ||
BSpline(obj) | ||
obj.Closed = closed | ||
obj.Points = pointslist | ||
obj.Support = support | ||
if face != None: | ||
obj.MakeFace = face | ||
if placement: obj.Placement = placement | ||
if App.GuiUp: | ||
ViewProviderBSpline(obj.ViewObject) | ||
format_object(obj) | ||
select(obj) | ||
|
||
return obj | ||
|
||
|
||
makeBSpline = make_bspline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# *************************************************************************** | ||
# * Copyright (c) 2009, 2010 Yorik van Havre <yorik@uncreated.net> * | ||
# * Copyright (c) 2009, 2010 Ken Cline <cline@frii.com> * | ||
# * Copyright (c) 2020 FreeCAD Developers * | ||
# * * | ||
# * This program is free software; you can redistribute it and/or modify * | ||
# * it under the terms of the GNU Lesser General Public License (LGPL) * | ||
# * as published by the Free Software Foundation; either version 2 of * | ||
# * the License, or (at your option) any later version. * | ||
# * for detail see the LICENCE text file. * | ||
# * * | ||
# * This program is distributed in the hope that it will be useful, * | ||
# * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
# * GNU Library General Public License for more details. * | ||
# * * | ||
# * You should have received a copy of the GNU Library General Public * | ||
# * License along with this program; if not, write to the Free Software * | ||
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * | ||
# * USA * | ||
# * * | ||
# *************************************************************************** | ||
"""This module provides the code for Draft make_line function. | ||
""" | ||
## @package make_line | ||
# \ingroup DRAFT | ||
# \brief This module provides the code for Draft make_line function. | ||
|
||
import FreeCAD as App | ||
|
||
from draftutils.gui_utils import format_object | ||
from draftutils.gui_utils import select | ||
|
||
from draftmake.make_wire import make_wire | ||
|
||
|
||
def make_line(first_param, last_param=None): | ||
"""makeLine(first_param, p2) | ||
Creates a line from 2 points or from a given object. | ||
Parameters | ||
---------- | ||
first_param : | ||
Base.Vector -> First point of the line (if p2 == None) | ||
Part.LineSegment -> Line is created from the given Linesegment | ||
Shape -> Line is created from the give Shape | ||
last_param : Base.Vector | ||
Second point of the line, if not set the function evaluates | ||
the first_param to look for a Part.LineSegment or a Shape | ||
""" | ||
if last_param: | ||
p1 = first_param | ||
p2 = last_param | ||
else: | ||
if hasattr(first_param, "StartPoint") and hasattr(first_param, "EndPoint"): | ||
p2 = first_param.EndPoint | ||
p1 = first_param.StartPoint | ||
elif hasattr(p1,"Vertexes"): | ||
p2 = first_param.Vertexes[-1].Point | ||
p1 = first_param.Vertexes[0].Point | ||
else: | ||
_err = "Unable to create a line from the given parameters" | ||
App.Console.PrintError(_err + "\n") | ||
return | ||
|
||
obj = make_wire([p1,p2]) | ||
|
||
return obj | ||
|
||
|
||
makeLine = make_line |
Oops, something went wrong.