Skip to content

Commit c85154e

Browse files
authored
Merge f63eccf into 3b9ead1
2 parents 3b9ead1 + f63eccf commit c85154e

File tree

1 file changed

+6
-26
lines changed
  • cadquery/occ_impl/exporters

1 file changed

+6
-26
lines changed

cadquery/occ_impl/exporters/svg.py

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -59,28 +59,6 @@ class UNITS:
5959
IN = "in"
6060

6161

62-
def guessUnitOfMeasure(shape):
63-
"""
64-
Guess the unit of measure of a shape.
65-
"""
66-
bb = BoundBox._fromTopoDS(shape.wrapped)
67-
68-
dimList = [bb.xlen, bb.ylen, bb.zlen]
69-
# no real part would likely be bigger than 10 inches on any side
70-
if max(dimList) > 10:
71-
return UNITS.MM
72-
73-
# no real part would likely be smaller than 0.1 mm on all dimensions
74-
if min(dimList) < 0.1:
75-
return UNITS.IN
76-
77-
# no real part would have the sum of its dimensions less than about 5mm
78-
if sum(dimList) < 10:
79-
return UNITS.IN
80-
81-
return UNITS.MM
82-
83-
8462
def makeSVGedge(e):
8563
"""
8664
Creates an SVG edge from a OCCT edge.
@@ -125,12 +103,14 @@ def getPaths(visibleShapes, hiddenShapes):
125103
return (hiddenPaths, visiblePaths)
126104

127105

128-
def getSVG(shape, opts=None):
106+
def getSVG(shape, unitOfMeasure=UNITS.MM, opts=None):
129107
"""
130108
Export a shape to SVG text.
131109
132110
:param shape: A CadQuery shape object to convert to an SVG string.
133111
:type Shape: Vertex, Edge, Wire, Face, Shell, Solid, or Compound.
112+
:param unitOfMeasure: The unit of measurement to be used for the svg (mm/inch).
113+
:type UNITS: MM, or INCH.
134114
:param opts: An options dictionary that influences the SVG that is output.
135115
:type opts: Dictionary, keys are as follows:
136116
width: Document width of the resulting image.
@@ -167,7 +147,7 @@ def getSVG(shape, opts=None):
167147
d.update(opts)
168148

169149
# need to guess the scale and the coordinate center
170-
uom = guessUnitOfMeasure(shape)
150+
uom = unitOfMeasure
171151

172152
width = float(d["width"])
173153
height = float(d["height"])
@@ -289,14 +269,14 @@ def getSVG(shape, opts=None):
289269
return svg
290270

291271

292-
def exportSVG(shape, fileName: str, opts=None):
272+
def exportSVG(shape, fileName: str, unitOfMeasure=UNITS.MM, opts=None):
293273
"""
294274
Accept a cadquery shape, and export it to the provided file
295275
TODO: should use file-like objects, not a fileName, and/or be able to return a string instead
296276
export a view of a part to svg
297277
"""
298278

299-
svg = getSVG(shape.val(), opts)
279+
svg = getSVG(shape.val(), unitOfMeasure, opts)
300280
f = open(fileName, "w")
301281
f.write(svg)
302282
f.close()

0 commit comments

Comments
 (0)