Skip to content

Commit 0aa889c

Browse files
Add perspective SVG output (#1119)
* Added perspective SVG output * Apply suggestion * Change var name * Simplify option handling * Correct my own mistake * One more fix * "Pull" the latest rtd conf --------- Co-authored-by: AU <[email protected]>
1 parent 9c519e6 commit 0aa889c

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

cadquery/occ_impl/exporters/svg.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ def getSVG(shape, opts=None):
144144
strokeColor: Color of the line that visible edges are drawn with.
145145
hiddenColor: Color of the line that hidden edges are drawn with.
146146
showHidden: Whether or not to show hidden lines.
147+
focus: If specified, creates a perspective SVG with the projector
148+
at the distance specified.
147149
"""
148150

149151
# Available options and their defaults
@@ -158,6 +160,7 @@ def getSVG(shape, opts=None):
158160
"strokeColor": (0, 0, 0), # RGB 0-255
159161
"hiddenColor": (160, 160, 160), # RGB 0-255
160162
"showHidden": True,
163+
"focus": None,
161164
}
162165

163166
if opts:
@@ -176,11 +179,17 @@ def getSVG(shape, opts=None):
176179
strokeColor = tuple(d["strokeColor"])
177180
hiddenColor = tuple(d["hiddenColor"])
178181
showHidden = bool(d["showHidden"])
182+
focus = float(d["focus"]) if d.get("focus") else None
179183

180184
hlr = HLRBRep_Algo()
181185
hlr.Add(shape.wrapped)
182186

183-
projector = HLRAlgo_Projector(gp_Ax2(gp_Pnt(), gp_Dir(*projectionDir)))
187+
coordinate_system = gp_Ax2(gp_Pnt(), gp_Dir(*projectionDir))
188+
189+
if focus is not None:
190+
projector = HLRAlgo_Projector(coordinate_system, focus)
191+
else:
192+
projector = HLRAlgo_Projector(coordinate_system)
184193

185194
hlr.Projector(projector)
186195
hlr.Update()
Lines changed: 33 additions & 0 deletions
Loading

doc/importexport.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ options are as follows.
9292
* *strokeColor* - Color of the line that visible edges are drawn with.
9393
* *hiddenColor* - Color of the line that hidden edges are drawn with.
9494
* *showHidden* - Whether or not to show hidden lines.
95+
* *focus* - If specified, creates a perspective SVG with the projector at the distance specified.
9596

9697
The options are passed to the exporter in a dictionary, and can be left out to force the SVG to be created with default options.
9798
Below are examples with and without options set.
@@ -144,6 +145,10 @@ Which results in the following image:
144145

145146
.. image:: _static/importexport/box_custom_options.svg
146147

148+
Exporting with the additional option ``"focus": 25`` results in the following output SVG with perspective:
149+
150+
.. image:: _static/importexport/box_custom_options_perspective.svg
151+
147152
Exporting STL
148153
##############
149154

tests/test_exporters.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ def testSVGOptions(self):
113113
"strokeColor": (255, 0, 0),
114114
"hiddenColor": (0, 0, 255),
115115
"showHidden": True,
116+
"focus": 4,
116117
},
117118
)
118119

0 commit comments

Comments
 (0)