@@ -59,28 +59,6 @@ class UNITS:
59
59
IN = "in"
60
60
61
61
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
-
84
62
def makeSVGedge (e ):
85
63
"""
86
64
Creates an SVG edge from a OCCT edge.
@@ -125,12 +103,14 @@ def getPaths(visibleShapes, hiddenShapes):
125
103
return (hiddenPaths , visiblePaths )
126
104
127
105
128
- def getSVG (shape , opts = None ):
106
+ def getSVG (shape , unitOfMeasure = UNITS . MM , opts = None ):
129
107
"""
130
108
Export a shape to SVG text.
131
109
132
110
:param shape: A CadQuery shape object to convert to an SVG string.
133
111
: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.
134
114
:param opts: An options dictionary that influences the SVG that is output.
135
115
:type opts: Dictionary, keys are as follows:
136
116
width: Document width of the resulting image.
@@ -167,7 +147,7 @@ def getSVG(shape, opts=None):
167
147
d .update (opts )
168
148
169
149
# need to guess the scale and the coordinate center
170
- uom = guessUnitOfMeasure ( shape )
150
+ uom = unitOfMeasure
171
151
172
152
width = float (d ["width" ])
173
153
height = float (d ["height" ])
@@ -289,14 +269,14 @@ def getSVG(shape, opts=None):
289
269
return svg
290
270
291
271
292
- def exportSVG (shape , fileName : str , opts = None ):
272
+ def exportSVG (shape , fileName : str , unitOfMeasure = UNITS . MM , opts = None ):
293
273
"""
294
274
Accept a cadquery shape, and export it to the provided file
295
275
TODO: should use file-like objects, not a fileName, and/or be able to return a string instead
296
276
export a view of a part to svg
297
277
"""
298
278
299
- svg = getSVG (shape .val (), opts )
279
+ svg = getSVG (shape .val (), unitOfMeasure , opts )
300
280
f = open (fileName , "w" )
301
281
f .write (svg )
302
282
f .close ()
0 commit comments