@@ -36,6 +36,7 @@ def __init__(
36
36
- Vtkwell,
37
37
- Perforation,
38
38
- InternalWell
39
+ - Box
39
40
40
41
Everything is handle in the method 'update_viewer()' which is trigger when the
41
42
'state.object_state' changed (see DeckTree).
@@ -124,7 +125,7 @@ def rendering_menu_extra_items( self ) -> None:
124
125
def update_viewer ( self , active_block : BaseModel , path : str , show_obj : bool ) -> None :
125
126
"""Add from path the dataset given by the user.
126
127
127
- Supported data type is: Vtkwell, Vtkmesh, InternalWell, Perforation.
128
+ Supported data type is: Vtkwell, Vtkmesh, InternalWell, Perforation, Box .
128
129
129
130
object_state : array used to store path to the data and if we want to show it or not.
130
131
"""
@@ -141,24 +142,10 @@ def update_viewer( self, active_block: BaseModel, path: str, show_obj: bool ) ->
141
142
self ._update_perforation ( active_block , show_obj , path )
142
143
143
144
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 )
150
146
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.
162
149
self .plotter .update ()
163
150
164
151
def _on_clip_visibility_change ( self , ** kwargs : Any ) -> None :
@@ -353,6 +340,36 @@ def _add_perforation( self, distance_from_head: float, path: str ) -> None:
353
340
cell_id = self .region_engine .input .find_closest_cell ( point_offsetted )
354
341
cell = self .region_engine .input .extract_cells ( [ cell_id ] )
355
342
cell_actor = self .plotter .add_mesh ( cell )
356
- saved_perforation .add_extracted_cell ( cell_actor )
343
+ saved_perforation .add_extracted_cells ( cell_actor )
357
344
358
345
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