Skip to content

Commit

Permalink
Draft: split wire related tools from Draft.py
Browse files Browse the repository at this point in the history
Line Polyline BezCurve BSpline
.


.


.
  • Loading branch information
carlopav authored and yorikvanhavre committed Apr 29, 2020
1 parent 4eab0bb commit f1eaa0b
Show file tree
Hide file tree
Showing 10 changed files with 1,185 additions and 572 deletions.
8 changes: 8 additions & 0 deletions src/Mod/Draft/CMakeLists.txt
Expand Up @@ -64,14 +64,20 @@ SET(Draft_functions

SET(Draft_make_functions
draftmake/__init__.py
draftmake/make_bezcurve.py
draftmake/make_bspline.py
draftmake/make_circle.py
draftmake/make_line.py
draftmake/make_polygon.py
draftmake/make_rectangle.py
draftmake/make_wire.py
)

SET(Draft_objects
draftobjects/__init__.py
draftobjects/base.py
draftobjects/bezcurve.py
draftobjects/bspline.py
draftobjects/circulararray.py
draftobjects/circle.py
draftobjects/orthoarray.py
Expand All @@ -83,6 +89,7 @@ SET(Draft_objects
draftobjects/polygon.py
draftobjects/rectangle.py
draftobjects/text.py
draftobjects/wire.py
draftobjects/README.md
)

Expand All @@ -97,6 +104,7 @@ SET(Draft_view_providers
draftviewproviders/view_dimension.py
draftviewproviders/view_rectangle.py
draftviewproviders/view_text.py
draftviewproviders/view_wire.py
draftviewproviders/README.md
)

Expand Down
592 changes: 20 additions & 572 deletions src/Mod/Draft/Draft.py

Large diffs are not rendered by default.

107 changes: 107 additions & 0 deletions src/Mod/Draft/draftmake/make_bezcurve.py
@@ -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 changes: 111 additions & 0 deletions src/Mod/Draft/draftmake/make_bspline.py
@@ -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 changes: 73 additions & 0 deletions src/Mod/Draft/draftmake/make_line.py
@@ -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

0 comments on commit f1eaa0b

Please sign in to comment.