Draft: split wire related tools from Draft.py
Line Polyline BezCurve BSpline . . .
This commit is contained in:
committed by
Yorik van Havre
parent
4eab0bb787
commit
f1eaa0b93c
107
src/Mod/Draft/draftmake/make_bezcurve.py
Normal file
107
src/Mod/Draft/draftmake/make_bezcurve.py
Normal file
@@ -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
|
||||
111
src/Mod/Draft/draftmake/make_bspline.py
Normal file
111
src/Mod/Draft/draftmake/make_bspline.py
Normal file
@@ -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
|
||||
73
src/Mod/Draft/draftmake/make_line.py
Normal file
73
src/Mod/Draft/draftmake/make_line.py
Normal file
@@ -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
|
||||
123
src/Mod/Draft/draftmake/make_wire.py
Normal file
123
src/Mod/Draft/draftmake/make_wire.py
Normal file
@@ -0,0 +1,123 @@
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2009, 2010 Yorik van Havre <yorik@uncreated.net> *
|
||||
# * Copyright (c) 2009, 2010 Ken Cline <cline@frii.com> *
|
||||
# * *
|
||||
# * 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_wire function.
|
||||
"""
|
||||
## @package make_wire
|
||||
# \ingroup DRAFT
|
||||
# \brief This module provides the code for Draft make_wire function.
|
||||
|
||||
import FreeCAD as App
|
||||
|
||||
import DraftGeomUtils
|
||||
|
||||
from draftutils.gui_utils import format_object
|
||||
from draftutils.gui_utils import select
|
||||
|
||||
from draftutils.utils import type_check
|
||||
|
||||
from draftobjects.wire import Wire
|
||||
if App.GuiUp:
|
||||
from draftviewproviders.view_wire import ViewProviderWire
|
||||
|
||||
|
||||
def make_wire(pointslist, closed=False, placement=None, face=None, support=None, bs2wire=False):
|
||||
"""makeWire(pointslist,[closed],[placement])
|
||||
|
||||
Creates a Wire object from the given list of vectors. If face is
|
||||
true (and wire is closed), the wire will appear filled. Instead of
|
||||
a pointslist, you can also pass a Part Wire.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
pointlist : [Base.Vector]
|
||||
List of points to create the polyline
|
||||
|
||||
closed : bool
|
||||
If closed is True or first and last points are identical,
|
||||
the created polyline 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
|
||||
|
||||
bs2wire : bool
|
||||
TODO: Describe
|
||||
"""
|
||||
if not App.ActiveDocument:
|
||||
App.Console.PrintError("No active document. Aborting\n")
|
||||
return
|
||||
|
||||
import Part
|
||||
|
||||
if not isinstance(pointslist, list):
|
||||
e = pointslist.Wires[0].Edges
|
||||
pointslist = Part.Wire(Part.__sortEdges__(e))
|
||||
nlist = []
|
||||
for v in pointslist.Vertexes:
|
||||
nlist.append(v.Point)
|
||||
if DraftGeomUtils.isReallyClosed(pointslist):
|
||||
closed = True
|
||||
pointslist = nlist
|
||||
|
||||
if len(pointslist) == 0:
|
||||
print("Invalid input points: ", pointslist)
|
||||
#print(pointslist)
|
||||
#print(closed)
|
||||
|
||||
if placement:
|
||||
type_check([(placement, App.Placement)], "make_wire")
|
||||
ipl = placement.inverse()
|
||||
if not bs2wire:
|
||||
pointslist = [ipl.multVec(p) for p in pointslist]
|
||||
|
||||
if len(pointslist) == 2:
|
||||
fname = "Line"
|
||||
else:
|
||||
fname = "Wire"
|
||||
|
||||
obj = App.ActiveDocument.addObject("Part::Part2DObjectPython", fname)
|
||||
Wire(obj)
|
||||
obj.Points = pointslist
|
||||
obj.Closed = closed
|
||||
obj.Support = support
|
||||
|
||||
if face != None:
|
||||
obj.MakeFace = face
|
||||
|
||||
if placement:
|
||||
obj.Placement = placement
|
||||
|
||||
if App.GuiUp:
|
||||
ViewProviderWire(obj.ViewObject)
|
||||
format_object(obj)
|
||||
select(obj)
|
||||
|
||||
return obj
|
||||
|
||||
|
||||
makeWire = make_wire
|
||||
Reference in New Issue
Block a user