From f66c433e6c7b9853aff517325eaea442ec599128 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Thu, 21 Feb 2013 19:36:24 -0300 Subject: [PATCH] 0000959: Arcs exported to DXF with wrong direction --- src/Mod/Draft/DraftGeomUtils.py | 16 ++++++++++++++++ src/Mod/Draft/importDXF.py | 18 ++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/Mod/Draft/DraftGeomUtils.py b/src/Mod/Draft/DraftGeomUtils.py index 9267d61aa..b1b834cea 100755 --- a/src/Mod/Draft/DraftGeomUtils.py +++ b/src/Mod/Draft/DraftGeomUtils.py @@ -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): ''' diff --git a/src/Mod/Draft/importDXF.py b/src/Mod/Draft/importDXF.py index 4de4a6bb9..27544f699 100644 --- a/src/Mod/Draft/importDXF.py +++ b/src/Mod/Draft/importDXF.py @@ -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):