From 75560719c4225af28dbc75e55fd9dc16d7493383 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Mon, 8 Apr 2013 17:03:41 -0300 Subject: [PATCH] 0001068: Bug in Draft DXF export --- src/Mod/Draft/DraftGeomUtils.py | 17 ++++++++++++++++- src/Mod/Draft/importDXF.py | 2 ++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Mod/Draft/DraftGeomUtils.py b/src/Mod/Draft/DraftGeomUtils.py index c5fb3e9a0..f378baf26 100755 --- a/src/Mod/Draft/DraftGeomUtils.py +++ b/src/Mod/Draft/DraftGeomUtils.py @@ -419,7 +419,7 @@ def mirror (point, edge): else: return None -def isClockwise(edge): +def isClockwise(edge,ref=None): """Returns True if a circle-based edge has a clockwise direction""" if not geomType(edge) == "Circle": return True @@ -429,11 +429,26 @@ def isClockwise(edge): # 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 that axis points "the wrong way" from the reference, we invert it + if not ref: + ref = Vector(0,0,1) + if n.getAngle(ref) > math.pi/2: + n = DraftVecUtils.neg(n) if DraftVecUtils.angle(v1,v2,n) < 0: return False if n.z < 0: return False return True + +def isWideAngle(edge): + """returns True if the given edge is an arc with angle > 180 degrees""" + if geomType(edge) != "Circle": + return False + r = edge.Curve.Radius + total = 2*r*math.pi + if edge.Length > total/2: + return True + return False def findClosest(basepoint,pointslist): ''' diff --git a/src/Mod/Draft/importDXF.py b/src/Mod/Draft/importDXF.py index 1a9a34865..0cb2656eb 100644 --- a/src/Mod/Draft/importDXF.py +++ b/src/Mod/Draft/importDXF.py @@ -1255,6 +1255,8 @@ def getWire(wire,nospline=False): v2 = edge.Vertexes[-1].Point c = edge.Curve.Center angle = abs(DraftVecUtils.angle(v1.sub(c),v2.sub(c))) + if DraftGeomUtils.isWideAngle(edge): + angle = math.pi*2 - angle # if (DraftVecUtils.angle(v2.sub(c)) < DraftVecUtils.angle(v1.sub(c))): # angle = -angle # polyline bulge -> negative makes the arc go clockwise