Merge pull request #4216 from marioalexis84/draft-draftify
Draft: Replace Part.getSortedClusters by Part.sortEdges in draftify function
This commit is contained in:
@@ -27,12 +27,21 @@
|
||||
|
||||
## \addtogroup draftfuctions
|
||||
# @{
|
||||
|
||||
import lazy_loader.lazy_loader as lz
|
||||
|
||||
import FreeCAD as App
|
||||
import draftutils.gui_utils as gui_utils
|
||||
import draftmake.make_block as make_block
|
||||
import draftmake.make_wire as make_wire
|
||||
import draftmake.make_circle as make_circle
|
||||
import draftmake.make_bspline as make_bspline
|
||||
import draftmake.make_bezcurve as make_bezcurve
|
||||
import draftmake.make_arc_3points as make_arc_3points
|
||||
|
||||
# Delay import of module until first use because it is heavy
|
||||
Part = lz.LazyLoader("Part", globals(), "Part")
|
||||
DraftGeomUtils = lz.LazyLoader("DraftGeomUtils", globals(), "DraftGeomUtils")
|
||||
|
||||
def draftify(objectslist, makeblock=False, delete=True):
|
||||
"""draftify(objectslist,[makeblock],[delete])
|
||||
@@ -52,24 +61,18 @@ def draftify(objectslist, makeblock=False, delete=True):
|
||||
delete : bool
|
||||
If delete = False, old objects are not deleted
|
||||
"""
|
||||
import Part
|
||||
import DraftGeomUtils
|
||||
|
||||
if not isinstance(objectslist,list):
|
||||
objectslist = [objectslist]
|
||||
newobjlist = []
|
||||
for obj in objectslist:
|
||||
if hasattr(obj,'Shape'):
|
||||
for cluster in Part.getSortedClusters(obj.Shape.Edges):
|
||||
for cluster in Part.sortEdges(obj.Shape.Edges):
|
||||
w = Part.Wire(cluster)
|
||||
if DraftGeomUtils.hasCurves(w):
|
||||
if (len(w.Edges) == 1) and (DraftGeomUtils.geomType(w.Edges[0]) == "Circle"):
|
||||
nobj = make_circle.make_circle(w.Edges[0])
|
||||
else:
|
||||
nobj = App.ActiveDocument.addObject("Part::Feature", obj.Name)
|
||||
nobj.Shape = w
|
||||
else:
|
||||
nobj = make_wire.make_wire(w)
|
||||
nobj = draftify_shape(w)
|
||||
if nobj == None:
|
||||
nobj = App.ActiveDocument.addObject("Part::Feature", obj.Name)
|
||||
nobj.Shape = w
|
||||
newobjlist.append(nobj)
|
||||
gui_utils.format_object(nobj, obj)
|
||||
# sketches are always in wireframe mode. In Draft we don't like that!
|
||||
@@ -85,4 +88,34 @@ def draftify(objectslist, makeblock=False, delete=True):
|
||||
return newobjlist[0]
|
||||
return newobjlist
|
||||
|
||||
def draftify_shape(shape):
|
||||
|
||||
nobj = None
|
||||
if DraftGeomUtils.hasCurves(shape):
|
||||
if (len(shape.Edges) == 1):
|
||||
edge = shape.Edges[0]
|
||||
edge_type = DraftGeomUtils.geomType(edge)
|
||||
if edge_type == "Circle":
|
||||
if edge.isClosed():
|
||||
nobj = make_circle.make_circle(edge)
|
||||
else:
|
||||
first_parameter = edge.FirstParameter
|
||||
last_parameter = edge.LastParameter
|
||||
points = [edge.Curve.value(first_parameter),
|
||||
edge.Curve.value((first_parameter + last_parameter)/2),
|
||||
edge.Curve.value(last_parameter)]
|
||||
nobj = make_arc_3points.make_arc_3points(points)
|
||||
# TODO: take into consideration trimmed curves and capture the specific
|
||||
# type of BSpline and Bezier that can be converted to a draft object.
|
||||
# elif edge_type == "BSplineCurve":
|
||||
# knots = [edge.Curve.value(p) for p in edge.Curve.getKnots()]
|
||||
# nobj = make_bspline.make_bspline(knots, closed=edge.isClosed())
|
||||
# elif edge_type == "BezierCurve":
|
||||
# nobj = make_bezcurve.make_bezcurve(edge.Curve.getPoles(),
|
||||
# closed=edge.isClosed())
|
||||
else:
|
||||
nobj = make_wire.make_wire(shape)
|
||||
|
||||
return nobj
|
||||
|
||||
## @}
|
||||
|
||||
@@ -504,18 +504,10 @@ def upgrade(objects, delete=False, force=None):
|
||||
if result:
|
||||
_msg(_tr("Found closed wires: creating faces"))
|
||||
# wires or edges: we try to join them
|
||||
elif len(wires) > 1 or len(loneedges) > 1:
|
||||
elif len(objects) > 1 and len(edges) > 1:
|
||||
result = makeWires(objects)
|
||||
if result:
|
||||
_msg(_tr("Found several wires or edges: wiring them"))
|
||||
# TODO: improve draftify function
|
||||
# only one object: if not parametric, we "draftify" it
|
||||
# elif (len(objects) == 1
|
||||
# and not objects[0].isDerivedFrom("Part::Part2DObjectPython")):
|
||||
# result = ext_draftify.draftify(objects[0])
|
||||
# if result:
|
||||
# _msg(_tr("Found 1 non-parametric objects: "
|
||||
# "draftifying it"))
|
||||
# special case, we have only one open wire. We close it,
|
||||
# unless it has only 1 edge!
|
||||
elif len(objects) == 1 and len(openwires) == 1:
|
||||
@@ -524,14 +516,23 @@ def upgrade(objects, delete=False, force=None):
|
||||
if result:
|
||||
_msg(_tr("Found 1 open wire: closing it"))
|
||||
# we have only one object that contains one edge
|
||||
# TODO: this case should be considered in draftify
|
||||
elif len(objects) == 1 and len(edges) == 1:
|
||||
# turn to Draft Line
|
||||
# TODO: improve draftify function
|
||||
# only one object: if not parametric, we "draftify" it
|
||||
# elif (len(objects) == 1
|
||||
# and not objects[0].isDerivedFrom("Part::Part2DObjectPython")):
|
||||
# result = ext_draftify.draftify(objects[0])
|
||||
# if result:
|
||||
# _msg(_tr("Found 1 non-parametric objects: "
|
||||
# "draftifying it"))
|
||||
elif (len(objects) == 1 and len(edges) == 1
|
||||
and not objects[0].isDerivedFrom("Part::Part2DObjectPython")):
|
||||
e = objects[0].Shape.Edges[0]
|
||||
if isinstance(e.Curve, (Part.LineSegment, Part.Line)):
|
||||
result = turnToLine(objects[0])
|
||||
edge_type = DraftGeomUtils.geomType(e)
|
||||
# currently only support Line and Circle
|
||||
if edge_type in ("Line", "Circle"):
|
||||
result = ext_draftify.draftify(objects[0])
|
||||
if result:
|
||||
_msg(_tr("Found 1 linear object: converting to line"))
|
||||
_msg(_tr("Found 1 object: draftifying it"))
|
||||
# only points, no edges
|
||||
elif not edges and len(objects) > 1:
|
||||
result = makeCompound(objects)
|
||||
|
||||
Reference in New Issue
Block a user