Commit 713efe05 authored by sumpfralle's avatar sumpfralle

fixed output dimension for SVG export


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@960 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 84ab9bff
...@@ -20,19 +20,27 @@ You should have received a copy of the GNU General Public License ...@@ -20,19 +20,27 @@ You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>. along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
""" """
# Inkscape uses a fixed resolution of 90 dpi
SVG_OUTPUT_DPI = 90
class SVGExporter: class SVGExporter:
def __init__(self, output): def __init__(self, output, unit="mm"):
if isinstance(output, basestring): if isinstance(output, basestring):
# a filename was given # a filename was given
self.output = file(filename,"w") self.output = file(filename,"w")
else: else:
# a stream was given # a stream was given
self.output = output self.output = output
if unit == "mm":
dots_per_px = SVG_OUTPUT_DPI / 25.4
else:
dots_per_px = SVG_OUTPUT_DPI
self.output.write("""<?xml version='1.0'?> self.output.write("""<?xml version='1.0'?>
<svg xmlns='http://www.w3.org/2000/svg' width='640' height='800'> <svg xmlns='http://www.w3.org/2000/svg' width='640' height='800'>
<g transform='translate(320,320) scale(50)' stroke-width='0.01' font-size='0.2'> <g transform='scale(%f)' stroke-width='0.01' font-size='0.2'>
""") """ % dots_per_px)
self._fill = 'none' self._fill = 'none'
self._stroke = 'black' self._stroke = 'black'
...@@ -100,11 +108,12 @@ class SVGExporter: ...@@ -100,11 +108,12 @@ class SVGExporter:
#TODO: we need to create a unified "Exporter" interface and base class #TODO: we need to create a unified "Exporter" interface and base class
class SVGExporterContourModel(object): class SVGExporterContourModel(object):
def __init__(self, model, comment=None): def __init__(self, model, comment=None, unit="mm"):
self.model = model self.model = model
self.unit = unit
def write(self, stream): def write(self, stream):
writer = SVGExporter(stream) writer = SVGExporter(stream, unit=self.unit)
for polygon in self.model.get_polygons(): for polygon in self.model.get_polygons():
points = polygon.get_points() points = polygon.get_points()
if polygon.is_closed: if polygon.is_closed:
......
...@@ -102,9 +102,9 @@ class BaseModel(TransformableContainer): ...@@ -102,9 +102,9 @@ class BaseModel(TransformableContainer):
def is_export_supported(self): def is_export_supported(self):
return not self._export_function is None return not self._export_function is None
def export(self, comment=None): def export(self, **kwargs):
if self.is_export_supported(): if self.is_export_supported():
return self._export_function(self, comment=comment) return self._export_function(self, **kwargs)
else: else:
raise NotImplementedError(("This type of model (%s) does not " \ raise NotImplementedError(("This type of model (%s) does not " \
+ "support the 'export' function.") % str(type(self))) + "support the 'export' function.") % str(type(self)))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment