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 opts: An options dictionary that influences the SVG that is output. :type opts: Dictionary, keys are as follow
(shape, opts=None)
| 126 | |
| 127 | |
| 128 | def getSVG(shape, opts=None): |
| 129 | """ |
| 130 | Export a shape to SVG text. |
| 131 | |
| 132 | :param shape: A CadQuery shape object to convert to an SVG string. |
| 133 | :type Shape: Vertex, Edge, Wire, Face, Shell, Solid, or Compound. |
| 134 | :param opts: An options dictionary that influences the SVG that is output. |
| 135 | :type opts: Dictionary, keys are as follows: |
| 136 | width: Width of the resulting image (None to fit based on height). |
| 137 | height: Height of the resulting image (None to fit based on width). |
| 138 | marginLeft: Inset margin from the left side of the document. |
| 139 | marginTop: Inset margin from the top side of the document. |
| 140 | projectionDir: Direction the camera will view the shape from. |
| 141 | showAxes: Whether or not to show the axes indicator, which will only be |
| 142 | visible when the projectionDir is also at the default. |
| 143 | strokeWidth: Width of the line that visible edges are drawn with. |
| 144 | strokeColor: Color of the line that visible edges are drawn with. |
| 145 | hiddenColor: Color of the line that hidden edges are drawn with. |
| 146 | showHidden: Whether or not to show hidden lines. |
| 147 | focus: If specified, creates a perspective SVG with the projector |
| 148 | at the distance specified. |
| 149 | """ |
| 150 | |
| 151 | # Available options and their defaults |
| 152 | d = { |
| 153 | "width": 800, |
| 154 | "height": 240, |
| 155 | "marginLeft": 200, |
| 156 | "marginTop": 20, |
| 157 | "projectionDir": (-1.75, 1.1, 5), |
| 158 | "showAxes": True, |
| 159 | "strokeWidth": -1.0, # -1 = calculated based on unitScale |
| 160 | "strokeColor": (0, 0, 0), # RGB 0-255 |
| 161 | "hiddenColor": (160, 160, 160), # RGB 0-255 |
| 162 | "showHidden": True, |
| 163 | "focus": None, |
| 164 | } |
| 165 | |
| 166 | if opts: |
| 167 | d.update(opts) |
| 168 | |
| 169 | # need to guess the scale and the coordinate center |
| 170 | uom = guessUnitOfMeasure(shape) |
| 171 | |
| 172 | # Handle the case where the height or width are None |
| 173 | width = d["width"] |
| 174 | if width != None: |
| 175 | width = float(d["width"]) |
| 176 | height = d["height"] |
| 177 | if d["height"] != None: |
| 178 | height = float(d["height"]) |
| 179 | marginLeft = float(d["marginLeft"]) |
| 180 | marginTop = float(d["marginTop"]) |
| 181 | projectionDir = tuple(d["projectionDir"]) |
| 182 | showAxes = bool(d["showAxes"]) |
| 183 | strokeWidth = float(d["strokeWidth"]) |
| 184 | strokeColor = tuple(d["strokeColor"]) |
| 185 | hiddenColor = tuple(d["hiddenColor"]) |
no test coverage detected