diff --git a/cadquery/occ_impl/exporters/svg.py b/cadquery/occ_impl/exporters/svg.py index d2b9c421c..b3f907171 100644 --- a/cadquery/occ_impl/exporters/svg.py +++ b/cadquery/occ_impl/exporters/svg.py @@ -59,28 +59,6 @@ class UNITS: IN = "in" -def guessUnitOfMeasure(shape): - """ - Guess the unit of measure of a shape. - """ - bb = BoundBox._fromTopoDS(shape.wrapped) - - dimList = [bb.xlen, bb.ylen, bb.zlen] - # no real part would likely be bigger than 10 inches on any side - if max(dimList) > 10: - return UNITS.MM - - # no real part would likely be smaller than 0.1 mm on all dimensions - if min(dimList) < 0.1: - return UNITS.IN - - # no real part would have the sum of its dimensions less than about 5mm - if sum(dimList) < 10: - return UNITS.IN - - return UNITS.MM - - def makeSVGedge(e): """ Creates an SVG edge from a OCCT edge. @@ -125,12 +103,14 @@ def getPaths(visibleShapes, hiddenShapes): return (hiddenPaths, visiblePaths) -def getSVG(shape, opts=None): +def getSVG(shape, unitOfMeasure=UNITS.MM, opts=None): """ Export a shape to SVG text. :param shape: A CadQuery shape object to convert to an SVG string. :type Shape: Vertex, Edge, Wire, Face, Shell, Solid, or Compound. + :param unitOfMeasure: The unit of measurement to be used for the svg (mm/inch). + :type UNITS: MM, or INCH. :param opts: An options dictionary that influences the SVG that is output. :type opts: Dictionary, keys are as follows: width: Document width of the resulting image. @@ -167,7 +147,7 @@ def getSVG(shape, opts=None): d.update(opts) # need to guess the scale and the coordinate center - uom = guessUnitOfMeasure(shape) + uom = unitOfMeasure width = float(d["width"]) height = float(d["height"]) @@ -289,14 +269,14 @@ def getSVG(shape, opts=None): return svg -def exportSVG(shape, fileName: str, opts=None): +def exportSVG(shape, fileName: str, unitOfMeasure=UNITS.MM, opts=None): """ Accept a cadquery shape, and export it to the provided file TODO: should use file-like objects, not a fileName, and/or be able to return a string instead export a view of a part to svg """ - svg = getSVG(shape.val(), opts) + svg = getSVG(shape.val(), unitOfMeasure, opts) f = open(fileName, "w") f.write(svg) f.close()