@@ -79,6 +79,7 @@ def set_scene(self, plotter):
7979 # Define controller methods for tools
8080 @self .ctrl .set ("toggle_measure" )
8181 def toggle_measure ():
82+ """Toggle measurement tool from PyVista"""
8283 if self .plotter :
8384 self .state .measure_active = not self .state .measure_active
8485 if not self .state .measure_active :
@@ -94,6 +95,7 @@ def toggle_measure():
9495
9596 @self .ctrl .set ("toggle_mesh_slider" )
9697 def toggle_mesh_slider ():
98+ """Toggle mesh slider PyVista widget."""
9799 if self .plotter :
98100 self .state .mesh_slider_active = not self .state .mesh_slider_active
99101 if not self .state .mesh_slider_active :
@@ -160,29 +162,27 @@ def toggle_ruler():
160162 except Exception as e :
161163 print (f"Error toggling ruler: { e } " )
162164
163- @self .ctrl .set ("toggle_pick_rotation_center" )
164- def toggle_pick_rotation_center ():
165- """Toggle pick rotation center mode."""
166- try :
167- self .state .pick_rotation_center_active = not getattr (self .state , 'pick_rotation_center_active' , False )
168- if not self .state .pick_rotation_center_active :
169- # Disable pick rotation center mode
170- if hasattr (self , '_rotation_text_actor' ) and self ._rotation_text_actor :
171- self ._rotation_text_actor .SetVisibility (0 )
172- # Re-enable default interaction
173- # Note: This is a simplified implementation
174- else :
175- # Enable pick rotation center mode
176- self ._rotation_text_actor = self .plotter .scene .add_text (
177- "Select a point to set the rotation center with right click" ,
178- position = "upper_edge" ,
179- font_size = 14 ,
180- color = "grey" ,
181- shadow = True
182- )
183- self .ctrl .view_update ()
184- except Exception as e :
185- print (f"Error toggling pick rotation center: { e } " )
165+ @self .ctrl .set ("take_screenshot" )
166+ def take_screenshot ():
167+ """Take a screenshot of the current scene."""
168+ if self .plotter :
169+ try :
170+ # Take screenshot of the scene
171+ self .plotter .scene .screenshot ("screenshot.png" )
172+ print ("Screenshot saved as 'screenshot.png'" )
173+ except Exception as e :
174+ print (f"Error taking screenshot: { e } " )
175+
176+ @self .ctrl .set ("download_html" )
177+ def download_html ():
178+ """Export the scene as an HTML file."""
179+ if self .plotter :
180+ try :
181+ # Use PyVista's export_html functionality
182+ self .plotter .scene .export_html ("scene.html" )
183+ print ("Scene exported as 'scene.html'" )
184+ except Exception as e :
185+ print (f"Error exporting HTML: { e } " )
186186
187187 @self .ctrl .set ("toggle_dark_mode" )
188188 def toggle_dark_mode ():
@@ -197,66 +197,6 @@ def toggle_dark_mode():
197197 except Exception as e :
198198 print (f"Error toggling dark mode: { e } " )
199199
200- @self .ctrl .set ("toggle_wireframe" )
201- def toggle_wireframe ():
202- if self .plotter :
203- self .state .wireframe_mode = not self .state .wireframe_mode
204- for actor in self .plotter .actors .values ():
205- if hasattr (actor , 'prop' ):
206- if self .state .wireframe_mode :
207- actor .prop .representation = 'wireframe'
208- else :
209- actor .prop .representation = 'surface'
210- self .ctrl .view_update ()
211-
212- @self .ctrl .set ("toggle_edges" )
213- def toggle_edges ():
214- if self .plotter :
215- self .state .show_edges = not self .state .show_edges
216- for actor in self .plotter .actors .values ():
217- if hasattr (actor , 'prop' ):
218- actor .prop .edge_visibility = self .state .show_edges
219- self .ctrl .view_update ()
220-
221- @self .ctrl .set ("toggle_point_mode" )
222- def toggle_point_mode ():
223- if self .plotter :
224- self .state .point_mode = not self .state .point_mode
225- for actor in self .plotter .actors .values ():
226- if hasattr (actor , 'prop' ):
227- if self .state .point_mode :
228- actor .prop .representation = 'points'
229- else :
230- actor .prop .representation = 'surface'
231- self .ctrl .view_update ()
232-
233- @self .ctrl .set ("toggle_background" )
234- def toggle_background ():
235- if self .plotter :
236- self .state .dark_background = not self .state .dark_background
237- if self .state .dark_background :
238- self .plotter .scene .set_background ('black' )
239- else :
240- self .plotter .scene .set_background ('white' )
241- self .ctrl .view_update ()
242-
243- @self .ctrl .set ("toggle_axes" )
244- def toggle_axes ():
245- if self .plotter :
246- self .state .show_axes = not self .state .show_axes
247- if self .state .show_axes :
248- self .plotter .scene .show_axes ()
249- else :
250- self .plotter .scene .hide_axes ()
251- self .ctrl .view_update ()
252-
253- @self .ctrl .set ("toggle_local_rendering" )
254- def toggle_local_rendering ():
255- self .state .local_rendering = not self .state .local_rendering
256- # The mode_local parameter should automatically sync with the state variable
257- # Force a view update to apply the change
258- self .ctrl .view_update ()
259-
260200 @self .ctrl .set ("displace_camera_x_up" )
261201 def displace_camera_x_up ():
262202 """Move camera in X+ direction."""
@@ -398,14 +338,6 @@ def view_isometric():
398338 except Exception as e :
399339 print (f"Error setting isometric view: { e } " )
400340
401- @self .ctrl .set ("view_reset_camera" )
402- def view_reset_camera ():
403- """Reset camera view."""
404- try :
405- self .plotter .scene .reset_camera ()
406- self .ctrl .view_update ()
407- except Exception as e :
408- print (f"Error resetting camera: { e } " )
409341
410342 with SinglePageWithDrawerLayout (self .server ) as layout :
411343 layout .title .set_text ("Ansys Visualization Tool" )
@@ -448,6 +380,18 @@ def view_reset_camera():
448380 v3 .VIcon ("mdi-ruler" )
449381 with v3 .VListItemContent ():
450382 v3 .VListItemTitle ("Ruler" )
383+
384+ with v3 .VListItem (click = self .ctrl .take_screenshot ):
385+ with v3 .VListItemIcon ():
386+ v3 .VIcon ("mdi-camera" )
387+ with v3 .VListItemContent ():
388+ v3 .VListItemTitle ("Take Screenshot" )
389+
390+ with v3 .VListItem (click = self .ctrl .download_html ):
391+ with v3 .VListItemIcon ():
392+ v3 .VIcon ("mdi-download" )
393+ with v3 .VListItemContent ():
394+ v3 .VListItemTitle ("Download HTML" )
451395
452396 # Camera Movement Section
453397 with v3 .VListGroup (value = ("true" ,)):
0 commit comments