export SVG as either 'Translated' or 'Raw'

There are two things a user might want when exporting to SVG:

    1. A pretty picture, to put on paper or on the screen and show
       to humans.

    2. An accurate representation of their part, for feeding to CAM
       software.

This commit adds a mechanism that lets the user select which of those
two options they want.

A new choice is added to the Draft Preferences.  The two options are:

    * "Translated (for print and display)", which acts just like before.
      The sketch is translated so it fits neatly in the display area.
      of the cartesian plane.  This is usually what you want if you're
      going to display the SVG to humans.

    * "Raw (for CAM)", which does not translate the sketch at all.
      All sketch coordinates are preserved exactly.  This is useful for
      feeding the SVG to a CAM program (like PyCAM).

The SVG export function is modified to check this new Preference setting,
and write either "Translated" or "Raw" SVGs as appropriate.
This commit is contained in:
Sebastian Kuzminsky 2012-02-09 20:08:23 -07:00
parent 5ac5814369
commit ff157cf94d
3 changed files with 51087 additions and 12970 deletions

File diff suppressed because it is too large Load Diff

View File

@ -356,6 +356,43 @@ If color mapping is choosed, you must choose a color mapping file containing a t
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Export Style</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefComboBox" name="svg_export_style_combobox">
<property name="toolTip">
<string>Style of SVG file to write when exporting a Sketch.</string>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<property name="prefEntry" stdset="0">
<cstring>svg_export_style</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
<item>
<property name="text">
<string>Translated (for print &amp; display)</string>
</property>
</item>
<item>
<property name="text">
<string>Raw (for CAM)</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>

View File

@ -938,6 +938,11 @@ def insert(filename,docname):
def export(exportList,filename):
"called when freecad exports a file"
svg_export_style = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").GetInt("svg_export_style")
if svg_export_style != 0 and svg_export_style != 1:
print "unknown svg export style, switching to Translated"
svg_export_style = 0
# finding sheet size
minx = 10000
miny = 10000
@ -950,7 +955,13 @@ def export(exportList,filename):
if v.Point.x > maxx: maxx = v.Point.x
if v.Point.y < miny: miny = v.Point.y
if v.Point.y > maxy: maxy = v.Point.y
margin = (maxx-minx)*.01
if svg_export_style == 0:
# translated-style exports get a bit of a margin
margin = (maxx-minx)*.01
else:
# raw-style exports get no margin
margin = 0
minx -= margin
maxx += margin
miny -= margin
@ -969,13 +980,25 @@ def export(exportList,filename):
svg.write(' "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n')
svg.write('<svg')
svg.write(' width="' + str(sizex) + 'mm" height="' + str(sizey) + 'mm"')
svg.write(' viewBox="0 0 ' + str(sizex) + ' ' + str(sizey) + '"')
if svg_export_style == 0:
# translated-style exports have the viewbox starting at X=0, Y=0
svg.write(' viewBox="0 0 ' + str(sizex) + ' ' + str(sizey) + '"')
else:
# raw-style exports have the viewbox starting at X=0, Y=-height
# we need the funny Y here because SVG is upside down, and we
# flip the sketch right-way up with a scale later
svg.write(' viewBox="0 ' + str(sizey * -1.0) + ' ' + str(sizex) + ' ' + str(sizey) + '"')
svg.write(' xmlns="http://www.w3.org/2000/svg" version="1.1"')
svg.write('>\n')
# writing paths
for ob in exportList:
svg.write('<g transform="translate('+str(-minx)+','+str(-miny+(2*margin))+') scale(1,-1)">\n')
if svg_export_style == 0:
# translated-style exports have the entire sketch translated to fit in the X>0, Y>0 quadrant
svg.write('<g transform="translate('+str(-minx)+','+str(-miny+(2*margin))+') scale(1,-1)">\n')
else:
# raw-style exports do not translate the sketch
svg.write('<g transform="scale(1,-1)">\n')
svg.write(Draft.getSVG(ob))
svg.write('</g>\n')