Draft: Discretize projected arcs and ellipses - fixes #1612
This commit is contained in:
parent
f432c42370
commit
00b5dbfa2f
|
@ -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 = '<circle cx="' + str(cen.x)
|
||||
svg += '" cy="' + str(cen.y)
|
||||
svg += '" r="' + str(rad)+'" '
|
||||
if hasattr(FreeCAD,"DraftWorkingPlane"):
|
||||
drawing_plane_normal = FreeCAD.DraftWorkingPlane.axis
|
||||
else:
|
||||
drawing_plane_normal = FreeCAD.Vector(0,0,1)
|
||||
if plane: drawing_plane_normal = plane.axis
|
||||
if round(edge.Curve.Axis.getAngle(drawing_plane_normal),2) == 0:
|
||||
# perpendicular projection: circle
|
||||
svg = '<circle cx="' + str(cen.x)
|
||||
svg += '" cy="' + str(cen.y)
|
||||
svg += '" r="' + str(rad)+'" '
|
||||
else:
|
||||
# any other projection: ellipse
|
||||
svg = '<path d="'
|
||||
svg += getDiscretized(edge)
|
||||
svg += '" '
|
||||
svg += 'stroke="' + stroke + '" '
|
||||
svg += 'stroke-width="' + str(linewidth) + ' px" '
|
||||
svg += 'style="stroke-width:'+ str(linewidth)
|
||||
|
|
|
@ -172,6 +172,52 @@
|
|||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Max segment length for discretized arcs</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring></cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Gui::PrefDoubleSpinBox" name="doubleSpinBox">
|
||||
<property name="toolTip">
|
||||
<string>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.</string>
|
||||
</property>
|
||||
<property name="suffix">
|
||||
<string>mm</string>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>9999.989999999999782</double>
|
||||
</property>
|
||||
<property name="prefEntry" stdset="0">
|
||||
<cstring>svgDiscretization</cstring>
|
||||
</property>
|
||||
<property name="prefPath" stdset="0">
|
||||
<cstring>Mod/Draft</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -203,6 +249,11 @@
|
|||
<extends>QComboBox</extends>
|
||||
<header>Gui/PrefWidgets.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>Gui::PrefDoubleSpinBox</class>
|
||||
<extends>QDoubleSpinBox</extends>
|
||||
<header>Gui/PrefWidgets.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
|
Loading…
Reference in New Issue
Block a user