@@ -238,16 +238,37 @@ def set_object_visibility(self, object_name, visibility):
238238 def contextMenuEvent (self , event ):
239239 menu = QMenu (self )
240240
241+ zoom_action = menu .addAction ("Zoom to Object" )
241242 export_action = menu .addAction ("Export Object" )
242243 remove_action = menu .addAction ("Remove Object" )
243244
244245 action = menu .exec_ (self .mapToGlobal (event .pos ()))
245246
246- if action == export_action :
247+ if action == zoom_action :
248+ self .zoom_to_selected_object ()
249+ elif action == export_action :
247250 self .export_selected_object ()
248251 elif action == remove_action :
249252 self .remove_selected_object ()
250253
254+ def zoom_to_selected_object (self ):
255+ selected_items = self .treeWidget .selectedItems ()
256+ if not selected_items :
257+ return
258+
259+ item_widget = self .treeWidget .itemWidget (selected_items [0 ], 0 )
260+ object_label = item_widget .findChild (QLabel ).text ()
261+ mesh_dict = self .viewer .meshes .get (object_label , None )
262+ if mesh_dict is None :
263+ return
264+ mesh = mesh_dict .get ('mesh' , None )
265+ if mesh is None or not hasattr (mesh , 'bounds' ):
266+ return
267+ try :
268+ self .viewer .reset_camera (bounds = mesh .bounds )
269+ except Exception as e :
270+ logger .error (f"Failed to zoom to object { object_label } : { e } " )
271+
251272 def export_selected_object (self ):
252273 selected_items = self .treeWidget .selectedItems ()
253274 if not selected_items :
0 commit comments