From 00b5dbfa2fb056223b41f08e8febec6a0c4a17af Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Tue, 8 Nov 2016 15:28:33 -0200 Subject: [PATCH] Draft: Discretize projected arcs and ellipses - fixes #1612 --- src/Mod/Draft/Draft.py | 39 ++++++++++---- src/Mod/Draft/Resources/ui/preferences-svg.ui | 51 +++++++++++++++++++ 2 files changed, 81 insertions(+), 9 deletions(-) diff --git a/src/Mod/Draft/Draft.py b/src/Mod/Draft/Draft.py index 032607697..347b5ccef 100644 --- a/src/Mod/Draft/Draft.py +++ b/src/Mod/Draft/Draft.py @@ -1811,6 +1811,18 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct if techdraw: ly = -ly return Vector(lx,ly,0) + + def getDiscretized(edge): + ml = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").GetFloat("svgDiscretization",10.0) + d = int(edge.Length/ml) + edata = "" + for i in range(d+1): + v = getProj(edge.valueAt(edge.FirstParameter+(float(i)/d*(edge.LastParameter-edge.FirstParameter)))) + if not edata: + edata += 'M ' + str(v.x) +' '+ str(v.y) + ' ' + else: + edata += 'L ' + str(v.x) +' '+ str(v.y) + ' ' + return edata def getPattern(pat): if pat in svgpatterns(): @@ -1859,11 +1871,7 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct drawing_plane_normal = FreeCAD.Vector(0,0,1) if plane: drawing_plane_normal = plane.axis c = e.Curve - if round(c.Axis.getAngle(drawing_plane_normal),2) == 1.57: - # arc is perpendicular to view direction: represent as a line - v = getProj(vs[-1].Point) - edata += 'L '+ str(v.x) +' '+ str(v.y) + ' ' - else: + if round(c.Axis.getAngle(drawing_plane_normal),2) == 0: if len(e.Vertexes) == 1 and iscircle: #complete curve svg = getCircle(e) return svg @@ -1875,7 +1883,6 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct getProj(vs[-1].Point)) else: endpoints = (getProj(vs[-1].Point),) - # arc if iscircle: rx = ry = c.Radius @@ -1904,6 +1911,8 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct (str(rx),str(ry),str(rot),\ str(int(flag_large_arc)),\ str(int(flag_sweep)),str(v.x),str(v.y)) + else: + edata += getDiscretized(e) elif DraftGeomUtils.geomType(e) == "Line": v = getProj(vs[-1].Point) edata += 'L '+ str(v.x) +' '+ str(v.y) + ' ' @@ -1955,9 +1964,21 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct def getCircle(edge): cen = getProj(edge.Curve.Center) rad = edge.Curve.Radius - svg = ' + + + + + + Max segment length for discretized arcs + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + When arcs are projected, if your version of OpenCasCade doesn't support arc projection, these arcs will be discretized into small line segments. This value is the maximum segment length. + + + mm + + + 9999.989999999999782 + + + svgDiscretization + + + Mod/Draft + + + + + @@ -203,6 +249,11 @@ QComboBox
Gui/PrefWidgets.h
+ + Gui::PrefDoubleSpinBox + QDoubleSpinBox +
Gui/PrefWidgets.h
+