0000959: Arcs exported to DXF with wrong direction

This commit is contained in:
Yorik van Havre 2013-02-21 19:36:24 -03:00
parent 66f6db9e91
commit f66c433e6c
2 changed files with 30 additions and 4 deletions

View File

@ -400,6 +400,22 @@ def mirror (point, edge):
return refl
else:
return None
def isClockwise(edge):
"""Returns True if a circle-based edge has a clockwise direction"""
if not isinstance(edge.Curve,Part.Circle):
return True
v1 = edge.Curve.tangent(edge.ParameterRange[0])[0]
if DraftVecUtils.isNull(v1):
return True
# we take an arbitrary other point on the edge that has little chances to be aligned with the first one...
v2 = edge.Curve.tangent(edge.ParameterRange[0]+0.01)[0]
n = edge.Curve.Axis
if DraftVecUtils.angle(v1,v2,n) < 0:
return False
if n.z < 0:
return False
return True
def findClosest(basepoint,pointslist):
'''

View File

@ -1258,13 +1258,23 @@ def getWire(wire,nospline=False):
# angle = -angle
# polyline bulge -> negative makes the arc go clockwise
bul = math.tan(angle/4)
# OBSOLETE because arcs can have wrong normal
# the next bit of code is for finding the direction of the arc
# a negative cross product means the arc is clockwise
tang1 = edge.Curve.tangent(edge.ParameterRange[0])
tang2 = edge.Curve.tangent(edge.ParameterRange[1])
cross1 = Vector.cross(Vector(tang1[0][0],tang1[0][1],tang1[0][2]),Vector(tang2[0][0],tang2[0][1],tang2[0][2]))
if cross1[2] < 0:
#tang1 = edge.Curve.tangent(edge.ParameterRange[0])
#tang2 = edge.Curve.tangent(edge.ParameterRange[1])
#cross1 = Vector.cross(Vector(tang1[0][0],tang1[0][1],tang1[0][2]),Vector(tang2[0][0],tang2[0][1],tang2[0][2]))
#if DraftVecUtils.isNull(cross1):
# special case, both tangents are opposite, unable to take their cross vector
# we try again with an arbitrary point at a third of the arc length
#tang2 = edge.Curve.tangent(edge.ParameterRange[0]+(edge.ParameterRange[1]-edge.ParameterRange[0]/3))
#cross1 = Vector.cross(Vector(tang1[0][0],tang1[0][1],tang1[0][2]),Vector(tang2[0][0],tang2[0][1],tang2[0][2]))
#if cross1[2] < 0:
# polyline bulge -> negative makes the arc go clockwise
#bul = -bul
if not DraftGeomUtils.isClockwise(edge):
bul = -bul
points.append((v1.x,v1.y,v1.z,None,None,bul))
elif (isinstance(edge.Curve,Part.BSplineCurve)) and (not nospline):