1111from vtkmodules .vtkRenderingCore import vtkActor
1212
1313from geos .trame .app .deck .tree import DeckTree
14+ from geos .trame .app .ui .viewer .boxViewer import BoxViewer
1415from geos .trame .app .ui .viewer .perforationViewer import PerforationViewer
1516from geos .trame .app .ui .viewer .regionViewer import RegionViewer
1617from geos .trame .app .ui .viewer .wellViewer import WellViewer
17- from geos .trame .schema_generated .schema_mod import Vtkmesh , Vtkwell , InternalWell , Perforation
18+ from geos .trame .schema_generated .schema_mod import Box , Vtkmesh , Vtkwell , InternalWell , Perforation
1819
1920pv .OFF_SCREEN = True
2021
@@ -35,6 +36,7 @@ def __init__(
3536 - Vtkwell,
3637 - Perforation,
3738 - InternalWell
39+ - Box
3840
3941 Everything is handle in the method 'update_viewer()' which is trigger when the
4042 'state.object_state' changed (see DeckTree).
@@ -48,6 +50,7 @@ def __init__(
4850 self ._cell_data_array_names : list [ str ] = []
4951 self ._source = source
5052 self ._pl = pv .Plotter ()
53+ self ._pl .iren .initialize ()
5154 self ._mesh_actor : vtkActor | None = None
5255
5356 self .CUT_PLANE = "on_cut_plane_visibility_change"
@@ -59,6 +62,7 @@ def __init__(
5962 self .SELECTED_DATA_ARRAY = "viewer_selected_data_array"
6063 self .state .change ( self .SELECTED_DATA_ARRAY )( self ._update_actor_array )
6164
65+ self .box_engine : BoxViewer | None = None
6266 self .region_engine = region_viewer
6367 self .well_engine = well_viewer
6468 self ._perforations : dict [ str , PerforationViewer ] = {}
@@ -122,7 +126,7 @@ def rendering_menu_extra_items( self ) -> None:
122126 def update_viewer ( self , active_block : BaseModel , path : str , show_obj : bool ) -> None :
123127 """Add from path the dataset given by the user.
124128
125- Supported data type is: Vtkwell, Vtkmesh, InternalWell, Perforation.
129+ Supported data type is: Vtkwell, Vtkmesh, InternalWell, Perforation, Box .
126130
127131 object_state : array used to store path to the data and if we want to show it or not.
128132 """
@@ -138,6 +142,13 @@ def update_viewer( self, active_block: BaseModel, path: str, show_obj: bool ) ->
138142 if isinstance ( active_block , Perforation ):
139143 self ._update_perforation ( active_block , show_obj , path )
140144
145+ if isinstance ( active_block , Box ):
146+ self ._update_box ( active_block , show_obj )
147+
148+ # when data is added in the pv.Plotter, we need to refresh the scene to update
149+ # the actor to avoid LUT issue.
150+ self .plotter .update ()
151+
141152 def _on_clip_visibility_change ( self , ** kwargs : Any ) -> None :
142153 """Toggle cut plane visibility for all actors.
143154
@@ -215,6 +226,7 @@ def _update_internalwell( self, path: str, show: bool ) -> None:
215226 """
216227 if not show :
217228 self .plotter .remove_actor ( self .well_engine .get_actor ( path ) ) # type: ignore
229+ self .well_engine .remove_actor ( path )
218230 return
219231
220232 tube_actor = self .plotter .add_mesh ( self .well_engine .get_tube ( self .well_engine .get_last_mesh_idx () ) )
@@ -229,6 +241,7 @@ def _update_vtkwell( self, path: str, show: bool ) -> None:
229241 """
230242 if not show :
231243 self .plotter .remove_actor ( self .well_engine .get_actor ( path ) ) # type: ignore
244+ self .well_engine .remove_actor ( path )
232245 return
233246
234247 tube_actor = self .plotter .add_mesh ( self .well_engine .get_tube ( self .well_engine .get_last_mesh_idx () ) )
@@ -331,3 +344,33 @@ def _add_perforation( self, distance_from_head: float, path: str ) -> None:
331344 saved_perforation .add_extracted_cell ( cell_actor )
332345
333346 self ._perforations [ path ] = saved_perforation
347+
348+ def _update_box ( self , active_block : Box , show_obj : bool ) -> None :
349+ """Generate and display a Box and inner cell(s) from the mesh."""
350+ if self .region_engine .input .number_of_cells == 0 and show_obj :
351+ self .ctrl .on_add_warning (
352+ "Can't display " + active_block .name ,
353+ "Please display the mesh before creating a well" ,
354+ )
355+ return
356+
357+ if self .box_engine is not None :
358+ box_polydata_actor : pv .Actor = self .box_engine .get_box_polydata_actor ()
359+ extracted_cell_actor : pv .Actor = self .box_engine .get_extracted_cells_actor ()
360+ self .plotter .remove_actor ( box_polydata_actor )
361+ self .plotter .remove_actor ( extracted_cell_actor )
362+
363+ if not show_obj :
364+ return
365+
366+ box : Box = active_block
367+ self .box_engine = BoxViewer ( self .region_engine .input , box )
368+
369+ box_polydata : pv .PolyData = self .box_engine .get_box_polydata ()
370+ extracted_cell : pv .UnstructuredGrid = self .box_engine .get_extracted_cells ()
371+
372+ if box_polydata is not None and extracted_cell is not None :
373+ _box_polydata_actor = self .plotter .add_mesh ( box_polydata , opacity = 0.2 )
374+ _extracted_cells_actor = self .plotter .add_mesh ( extracted_cell , show_edges = True )
375+ self .box_engine .set_box_polydata_actor ( _box_polydata_actor )
376+ self .box_engine .set_extracted_cells_actor ( _extracted_cells_actor )
0 commit comments