@@ -115,8 +115,8 @@ def __init__(
115115        # PyVista plotter 
116116        self ._pl  =  None 
117117
118-         # List  of picked objects in MeshObject format. 
119-         self ._picked_list  =  set () 
118+         # Dictionary  of picked objects in MeshObject format. 
119+         self ._picked_dict  =  {} 
120120
121121        # Map that relates PyVista actors with the added actors by the picker 
122122        self ._picker_added_actors_map  =  {}
@@ -197,7 +197,7 @@ def select_object(self, custom_object: Union[MeshObjectPlot, EdgePlot], pt: np.n
197197        """Select a custom object in the plotter. 
198198
199199        This method highlights the edges of a body and adds a label. It also adds 
200-         the object to the ``_picked_list `` and the actor to the ``_picker_added_actors_map``. 
200+         the object to the ``_picked_dict `` and the actor to the ``_picker_added_actors_map``. 
201201
202202        Parameters 
203203        ---------- 
@@ -234,8 +234,8 @@ def select_object(self, custom_object: Union[MeshObjectPlot, EdgePlot], pt: np.n
234234            )
235235            added_actors .append (label_actor )
236236
237-         if  custom_object  not  in   self ._picked_list :
238-             self ._picked_list . add ( custom_object ) 
237+         if  custom_object . name  not  in   self ._picked_dict :
238+             self ._picked_dict [ custom_object . name ]  =   custom_object 
239239
240240        self ._picker_added_actors_map [custom_object .actor .name ] =  added_actors 
241241
@@ -252,8 +252,8 @@ def unselect_object(self, custom_object: Union[MeshObjectPlot, EdgePlot]) -> Non
252252
253253        """ 
254254        # remove actor from picked list and from scene 
255-         if  custom_object  in  self ._picked_list :
256-             self ._picked_list . remove (custom_object )
255+         if  custom_object . name  in  self ._picked_dict :
256+             self ._picked_dict . pop (custom_object . name )
257257
258258        if  isinstance (custom_object , MeshObjectPlot ) and  custom_object  in  self ._origin_colors :
259259            custom_object .actor .prop .color  =  self ._origin_colors [custom_object ]
@@ -287,15 +287,15 @@ def picker_callback(self, actor: "pv.Actor") -> None:
287287        # if object is a body/component 
288288        if  actor  in  self ._object_to_actors_map :
289289            body_plot  =  self ._object_to_actors_map [actor ]
290-             if  body_plot  not  in   self ._picked_list :
290+             if  body_plot . name  not  in   self ._picked_dict :
291291                self .select_object (body_plot , pt )
292292            else :
293293                self .unselect_object (body_plot )
294294
295295        # if object is an edge 
296296        elif  actor  in  self ._edge_actors_map  and  actor .GetVisibility ():
297297            edge  =  self ._edge_actors_map [actor ]
298-             if  edge  not  in   self ._picked_list :
298+             if  edge . name  not  in   self ._picked_dict :
299299                self .select_object (edge , pt )
300300            else :
301301                self .unselect_object (edge )
@@ -439,12 +439,15 @@ def show(
439439        picked_objects_list  =  []
440440        if  isinstance (plottable_object , list ):
441441            # Keep them ordered based on picking 
442-             for  meshobject  in  self ._picked_list :
442+             for  meshobject  in  self ._picked_dict . values () :
443443                for  elem  in  plottable_object :
444444                    if  hasattr (elem , "name" ) and  elem .name  ==  meshobject .name :
445445                        picked_objects_list .append (elem )
446-         elif  hasattr (plottable_object , "name" ) and  plottable_object  in  self ._picked_list :
446+         elif  hasattr (plottable_object , "name" ) and  plottable_object . name  in  self ._picked_dict :
447447            picked_objects_list  =  [plottable_object ]
448+         else :
449+             # Return the picked objects in the order they were picked 
450+             picked_objects_list  =  list (self ._picked_dict .values ())
448451
449452        return  picked_objects_list 
450453
0 commit comments