Draft: fixes in DXF exporter - fixes #1590, #1653

* Fixed arc directions
* Turned max spline segment length preference option into a float
* Fixed ellipses export
This commit is contained in:
Yorik van Havre 2014-08-28 13:32:45 -03:00
parent a1fab61ed6
commit 16ede0e55c
3 changed files with 44 additions and 39 deletions

File diff suppressed because one or more lines are too long

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>496</width> <width>521</width>
<height>524</height> <height>528</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -367,10 +367,23 @@
</property> </property>
</widget> </widget>
</item> </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> <item>
<widget class="QLabel" name="label_7"> <widget class="QLabel" name="label_7">
<property name="text"> <property name="text">
<string>Max Spline Segment: </string> <string>Max Spline Segment (mm): </string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@ -378,21 +391,21 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="Gui::PrefSpinBox" name="gui::prefspinbox_2"> <widget class="Gui::PrefDoubleSpinBox" name="doubleSpinBox">
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip"> <property name="toolTip">
<string>When exporting splines to DXF, they are transformed in polylines. This value is the maximum length of each of the polyline segments. If 0, then the whole spline is treated as a straight segment.</string> <string>When exporting splines to DXF, they are transformed in polylines. This value is the maximum length of each of the polyline segments. If 0, then the whole spline is treated as a straight segment.</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="maximum">
<double>9999.989999999999782</double>
</property>
<property name="value"> <property name="value">
<number>5</number> <double>5.000000000000000</double>
</property> </property>
<property name="prefEntry" stdset="0"> <property name="prefEntry" stdset="0">
<cstring>maxsplinesegment</cstring> <cstring>maxsegmentlength</cstring>
</property> </property>
<property name="prefPath" stdset="0"> <property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring> <cstring>Mod/Draft</cstring>
@ -465,11 +478,6 @@
<extends>Gui::FileChooser</extends> <extends>Gui::FileChooser</extends>
<header>Gui/PrefWidgets.h</header> <header>Gui/PrefWidgets.h</header>
</customwidget> </customwidget>
<customwidget>
<class>Gui::PrefSpinBox</class>
<extends>QSpinBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget> <customwidget>
<class>Gui::PrefRadioButton</class> <class>Gui::PrefRadioButton</class>
<extends>QRadioButton</extends> <extends>QRadioButton</extends>
@ -480,6 +488,11 @@
<extends>QCheckBox</extends> <extends>QCheckBox</extends>
<header>Gui/PrefWidgets.h</header> <header>Gui/PrefWidgets.h</header>
</customwidget> </customwidget>
<customwidget>
<class>Gui::PrefDoubleSpinBox</class>
<extends>QDoubleSpinBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
</customwidgets> </customwidgets>
<resources/> <resources/>
<connections/> <connections/>

View File

@ -1348,14 +1348,12 @@ def getArcData(edge):
ve2 = edge.Vertexes[-1].Point ve2 = edge.Vertexes[-1].Point
ang1 = -math.degrees(DraftVecUtils.angle(ve1.sub(ce))) ang1 = -math.degrees(DraftVecUtils.angle(ve1.sub(ce)))
ang2 = -math.degrees(DraftVecUtils.angle(ve2.sub(ce))) ang2 = -math.degrees(DraftVecUtils.angle(ve2.sub(ce)))
a1 = -DraftVecUtils.angle(ve1.sub(ce)) if round(ang1,Draft.precision()) == round(ang2,Draft.precision()):
a2 = -DraftVecUtils.angle(ve2.sub(ce))
if round(a1,Draft.precision()) == round(a2,Draft.precision()):
return None,None, None, None return None,None, None, None
if edge.Curve.Axis.z < 0.0: if edge.Curve.Axis.z < 0.0:
ang1, ang2 = ang2, ang1 ang1, ang2 = ang2, ang1
pseudoarc = Part.ArcOfCircle(edge.Curve,a1,a2).toShape() pseudoarc = Part.ArcOfCircle(edge.Curve,math.radians(ang1),math.radians(ang2)).toShape()
if round(pseudoarc.Length,Draft.precision()) != round(edge.Length,Draft.precision()): if round(pseudoarc.Length,Draft.precision()) != round(edge.Length,Draft.precision()):
ang1, ang2 = ang2, ang1 ang1, ang2 = ang2, ang1
@ -1377,25 +1375,21 @@ def getArcData(edge):
def getSplineSegs(edge): def getSplineSegs(edge):
"returns an array of vectors from a Spline or Bezier edge" "returns an array of vectors from a Spline or Bezier edge"
params = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft") params = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
seglength = params.GetInt("maxsplinesegment") seglength = params.GetFloat("maxsegmentlength",5.0)
points = [] points = []
if seglength == 0: if seglength == 0:
points.append(edge.Vertexes[0].Point) points.append(edge.Vertexes[0].Point)
points.append(edge.Vertexes[-1].Point) points.append(edge.Vertexes[-1].Point)
else: else:
if DraftGeomUtils.geomType(edge) == "BezierCurve": points.append(edge.valueAt(edge.FirstParameter))
l = 1.0
else:
l = edge.Length
points.append(edge.valueAt(0))
if (edge.Length > seglength): if (edge.Length > seglength):
nbsegs = int(math.ceil(edge.Length/seglength)) nbsegs = int(math.ceil(edge.Length/seglength))
step = l/nbsegs step = (edge.LastParameter-edge.FirstParameter)/nbsegs
for nv in range(1,nbsegs): for nv in range(1,nbsegs):
#print "value at",nv*step,"=",edge.valueAt(nv*step) #print "value at",nv*step,"=",edge.valueAt(nv*step)
v = edge.valueAt(nv*step) v = edge.valueAt(edge.FirstParameter+(nv*step))
points.append(v) points.append(v)
points.append(edge.valueAt(l)) points.append(edge.valueAt(edge.LastParameter))
return points return points
def getWire(wire,nospline=False,lw=True): def getWire(wire,nospline=False,lw=True):
@ -1412,9 +1406,7 @@ def getWire(wire,nospline=False,lw=True):
# print "processing wire ",wire.Edges # print "processing wire ",wire.Edges
for edge in edges: for edge in edges:
v1 = edge.Vertexes[0].Point v1 = edge.Vertexes[0].Point
if len(edge.Vertexes) < 2: if DraftGeomUtils.geomType(edge) == "Circle":
points.append(fmt(v1))
elif DraftGeomUtils.geomType(edge) == "Circle":
mp = DraftGeomUtils.findMidpoint(edge) mp = DraftGeomUtils.findMidpoint(edge)
v2 = edge.Vertexes[-1].Point v2 = edge.Vertexes[-1].Point
c = edge.Curve.Center c = edge.Curve.Center
@ -1445,7 +1437,7 @@ def getWire(wire,nospline=False,lw=True):
if not DraftGeomUtils.isClockwise(edge): if not DraftGeomUtils.isClockwise(edge):
bul = -bul bul = -bul
points.append(fmt(v1,bul)) points.append(fmt(v1,bul))
elif (DraftGeomUtils.geomType(edge) in ["BSplineCurve","BezierCurve"]) and (not nospline): elif (DraftGeomUtils.geomType(edge) in ["BSplineCurve","BezierCurve","Ellipse"]) and (not nospline):
spline = getSplineSegs(edge) spline = getSplineSegs(edge)
spline.pop() spline.pop()
for p in spline: for p in spline:
@ -1499,7 +1491,7 @@ def writeShape(sh,ob,dxfobject,nospline=False,lwPoly=False):
if not(e.hashCode() in processededges): loneedges.append(e) if not(e.hashCode() in processededges): loneedges.append(e)
# print "lone edges ",loneedges # print "lone edges ",loneedges
for edge in loneedges: for edge in loneedges:
if (DraftGeomUtils.geomType(edge) in ["BSplineCurve","BezierCurve"]) and ((not nospline) or (len(edge.Vertexes) == 1)): # splines if (DraftGeomUtils.geomType(edge) in ["BSplineCurve","BezierCurve"]): # splines
if (len(edge.Vertexes) == 1) and (edge.Curve.isClosed()): if (len(edge.Vertexes) == 1) and (edge.Curve.isClosed()):
# special case: 1-vert closed spline, approximate as a circle # special case: 1-vert closed spline, approximate as a circle
c = DraftGeomUtils.getCircleFromSpline(edge) c = DraftGeomUtils.getCircleFromSpline(edge)