@@ -36,6 +36,7 @@ def __init__(
3636 - Vtkwell,
3737 - Perforation,
3838 - InternalWell
39+ - Box
3940
4041 Everything is handle in the method 'update_viewer()' which is trigger when the
4142 'state.object_state' changed (see DeckTree).
@@ -124,7 +125,7 @@ def rendering_menu_extra_items( self ) -> None:
124125 def update_viewer ( self , active_block : BaseModel , path : str , show_obj : bool ) -> None :
125126 """Add from path the dataset given by the user.
126127
127- Supported data type is: Vtkwell, Vtkmesh, InternalWell, Perforation.
128+ Supported data type is: Vtkwell, Vtkmesh, InternalWell, Perforation, Box .
128129
129130 object_state : array used to store path to the data and if we want to show it or not.
130131 """
@@ -141,24 +142,10 @@ def update_viewer( self, active_block: BaseModel, path: str, show_obj: bool ) ->
141142 self ._update_perforation ( active_block , show_obj , path )
142143
143144 if isinstance ( active_block , Box ):
144- if self .region_engine .input .number_of_cells == 0 and show_obj :
145- self .ctrl .on_add_warning (
146- "Can't display " + active_block .name ,
147- "Please display the mesh before creating a well" ,
148- )
149- return
145+ self ._update_box ( active_block , show_obj )
150146
151- if self .box_engine is not None :
152- self .box_engine .reset ( self .plotter )
153-
154- if not show_obj :
155- return
156-
157- box : Box = active_block
158- self .box_engine = BoxViewer ( self .region_engine .input , box )
159- self .box_engine .append_to_plotter ( self .plotter )
160-
161- # make sure that added data in the plot will be rendered with the correct scalar array/lut
147+ # when data is added in the pv.Plotter, we need to refresh the scene to update
148+ # the actor to avoid LUT issue.
162149 self .plotter .update ()
163150
164151 def _on_clip_visibility_change ( self , ** kwargs : Any ) -> None :
@@ -353,6 +340,36 @@ def _add_perforation( self, distance_from_head: float, path: str ) -> None:
353340 cell_id = self .region_engine .input .find_closest_cell ( point_offsetted )
354341 cell = self .region_engine .input .extract_cells ( [ cell_id ] )
355342 cell_actor = self .plotter .add_mesh ( cell )
356- saved_perforation .add_extracted_cell ( cell_actor )
343+ saved_perforation .add_extracted_cells ( cell_actor )
357344
358345 self ._perforations [ path ] = saved_perforation
346+
347+ def _update_box ( self , active_block : Box , show_obj : bool ) -> None :
348+ """Generate and display a Box and inner cell(s) from the mesh."""
349+ if self .region_engine .input .number_of_cells == 0 and show_obj :
350+ self .ctrl .on_add_warning (
351+ "Can't display " + active_block .name ,
352+ "Please display the mesh before creating a well" ,
353+ )
354+ return
355+
356+ if self .box_engine is not None :
357+ box_polydata_actor : pv .Actor = self .box_engine .get_box_polydata_actor ()
358+ extracted_cell_actor : pv .Actor = self .box_engine .get_extracted_cells_actor ()
359+ self .plotter .remove_actor ( box_polydata_actor )
360+ self .plotter .remove_actor ( extracted_cell_actor )
361+
362+ if not show_obj :
363+ return
364+
365+ box : Box = active_block
366+ self .box_engine = BoxViewer ( self .region_engine .input , box )
367+
368+ box_polydata : pv .PolyData = self .box_engine .get_box_polydata ()
369+ extracted_cell : pv .UnstructuredGrid = self .box_engine .get_extracted_cells ()
370+
371+ if box_polydata is not None and extracted_cell is not None :
372+ _box_polydata_actor = self .plotter .add_mesh ( box_polydata , opacity = 0.2 )
373+ _extracted_cells_actor = self .plotter .add_mesh ( extracted_cell , show_edges = True )
374+ self .box_engine .set_box_polydata_actor ( _box_polydata_actor )
375+ self .box_engine .set_extracted_cells_actor ( _extracted_cells_actor )
0 commit comments