Skip to content

Commit

Permalink
Merge pull request #5114 from Roy-043/Daft-fix-cleanProjection
Browse files Browse the repository at this point in the history
Daft: fix cleanProjection (used by Draft_Shape2DView and DXF export)
  • Loading branch information
chennes committed Oct 19, 2021
2 parents ae341e6 + 7da4273 commit cf1a0f7
Showing 1 changed file with 19 additions and 40 deletions.
59 changes: 19 additions & 40 deletions src/Mod/Draft/draftgeoutils/wires.py
Expand Up @@ -354,56 +354,35 @@ def getvec(v1, v2):


def cleanProjection(shape, tessellate=True, seglength=0.05):
"""Return a valid compound of edges, by recreating them.
"""Return a compound of edges, optionally tesselate ellipses, splines
and bezcurves.
This is because the projection algorithm somehow creates wrong shapes.
They display fine, but on loading the file the shape is invalid.
Now with tanderson's fix to `ProjectionAlgos`, that isn't the case,
but this function can be used for tessellating ellipses and splines
for DXF output-DF.
The function was formerly used to workaround bugs in the projection
algorithm. These bugs have since been fixed. Now the function is only
used when tessellation of ellipses, splines and bezcurves is required
(DXF output and Draft_Shape2DView).
"""
oldedges = shape.Edges
newedges = []
for e in oldedges:
typ = geomType(e)
try:
if geomType(e) == "Line":
newedges.append(e.Curve.toShape())

elif geomType(e) == "Circle":
if len(e.Vertexes) > 1:
mp = findMidpoint(e)
a = Part.Arc(e.Vertexes[0].Point,
mp,
e.Vertexes[-1].Point).toShape()
newedges.append(a)
else:
newedges.append(e.Curve.toShape())

elif geomType(e) == "Ellipse":
if typ in ["Line", "Circle"]:
newedges.append(e)
elif typ == "Ellipse":
if tessellate:
newedges.append(Part.Wire(curvetowire(e, seglength)))
else:
if len(e.Vertexes) > 1:
a = Part.Arc(e.Curve,
e.FirstParameter,
e.LastParameter).toShape()
newedges.append(a)
else:
newedges.append(e.Curve.toShape())

elif (geomType(e) == "BSplineCurve"
or geomType(e) == "BezierCurve"):
if tessellate:
newedges.append(e)
elif typ in ["BSplineCurve", "BezierCurve"]:
if isLine(e.Curve):
line = Part.LineSegment(e.Vertexes[0].Point,
e.Vertexes[-1].Point)
newedges.append(line)
elif tessellate:
newedges.append(Part.Wire(curvetowire(e, seglength)))
else:
if isLine(e.Curve):
line = Part.LineSegment(e.Vertexes[0].Point,
e.Vertexes[-1].Point).toShape()
newedges.append(line)
else:
newedges.append(e.Curve.toShape(e.FirstParameter,
e.LastParameter))
newedges.append(e)
else:
newedges.append(e)
except Part.OCCError:
Expand Down Expand Up @@ -527,4 +506,4 @@ def get_extended_wire(wire, offset_start, offset_end):
wire = Part.Wire(wire.OrderedEdges + [new_edge])
return wire

## @}
## @}

0 comments on commit cf1a0f7

Please sign in to comment.