Draft: More robust method to write DXF arcs

This commit is contained in:
Yorik van Havre 2015-01-18 13:42:17 -02:00
parent 86882eec6a
commit 044c1c0ef1
2 changed files with 39 additions and 10 deletions

View File

@ -653,7 +653,7 @@ class BSpline(Line):
def finish(self,closed=False,cont=False):
"terminates the operation and closes the poly if asked"
if self.ui:
self.bsplinetrack.finalize()
self.bsplinetrack.finalize()
if not Draft.getParam("UiMode",1):
FreeCADGui.Control.closeDialog()
if self.obj:
@ -756,7 +756,7 @@ class BezCurve(Line):
def finish(self,closed=False,cont=False):
"terminates the operation and closes the poly if asked"
if self.ui:
self.bezcurvetrack.finalize()
self.bezcurvetrack.finalize()
if not Draft.getParam("UiMode",1):
FreeCADGui.Control.closeDialog()
if self.obj:
@ -1082,8 +1082,8 @@ class Arc(Creator):
angle = DraftVecUtils.angle(plane.u, self.point.sub(self.center), plane.axis)
else: angle = 0
self.linetrack.p2(DraftVecUtils.scaleTo(self.point.sub(self.center),self.rad).add(self.center))
self.ui.setRadiusValue(math.degrees(angle),unit="Angle")
self.updateAngle(angle)
self.ui.setRadiusValue(math.degrees(self.angle),unit="Angle")
self.arctrack.setApertureAngle(self.angle)
elif arg["Type"] == "SoMouseButtonEvent":
@ -1171,6 +1171,13 @@ class Arc(Creator):
sta = math.degrees(self.firstangle)
end = math.degrees(self.firstangle+self.angle)
if end < sta: sta,end = end,sta
while True:
if sta > 360:
sta = sta - 360
elif end > 360:
end = end - 360
else:
break
try:
if Draft.getParam("UsePartPrimitives",False):
# use primitive

View File

@ -1452,13 +1452,35 @@ def getArcData(edge):
# closed circle
return DraftVecUtils.tup(ce), radius, 0, 0
else:
if round(edge.Curve.Axis.dot(FreeCAD.Vector(0,0,1))) == 1:
ang1,ang2=edge.ParameterRange
# new method: recalculate ourselves - cannot trust edge.Curve.Axis or XAxis
p1 = edge.Vertexes[0].Point
p2 = edge.Vertexes[-1].Point
v1 = p1.sub(ce)
v2 = p2.sub(ce)
print v1.cross(v2)
print edge.Curve.Axis
print p1
print p2
# we can use Z check since arcs getting here will ALWAYS be in XY plane
# Z can be 0 if the arc is 180 deg
if (v1.cross(v2).z >= 0) or (edge.Curve.Axis.z > 0):
#clockwise
ang1 = -DraftVecUtils.angle(v1)
ang2 = -DraftVecUtils.angle(v2)
else:
ang2,ang1=edge.ParameterRange
if edge.Curve.XAxis != FreeCAD.Vector(1,0,0):
ang1 -= DraftVecUtils.angle(edge.Curve.XAxis)
ang2 -= DraftVecUtils.angle(edge.Curve.XAxis)
#counterclockwise
ang2 = -DraftVecUtils.angle(v1)
ang1 = -DraftVecUtils.angle(v2)
# obsolete method - fails a lot
#if round(edge.Curve.Axis.dot(FreeCAD.Vector(0,0,1))) == 1:
# ang1,ang2=edge.ParameterRange
#else:
# ang2,ang1=edge.ParameterRange
#if edge.Curve.XAxis != FreeCAD.Vector(1,0,0):
# ang1 -= DraftVecUtils.angle(edge.Curve.XAxis)
# ang2 -= DraftVecUtils.angle(edge.Curve.XAxis)
return DraftVecUtils.tup(ce), radius, math.degrees(ang1),\
math.degrees(ang2)
@ -1662,7 +1684,7 @@ def export(objectslist,filename,nospline=False,lwPoly=False):
# other cases, treat edges
dxf = dxfLibrary.Drawing()
for ob in exportList:
print("processing ",ob.Name)
print("processing "+str(ob.Name))
if ob.isDerivedFrom("Part::Feature"):
if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").GetBool("dxfmesh"):
sh = None