14
14
from geos .trame .app .ui .viewer .perforationViewer import PerforationViewer
15
15
from geos .trame .app .ui .viewer .regionViewer import RegionViewer
16
16
from geos .trame .app .ui .viewer .wellViewer import WellViewer
17
- from geos .trame .schema_generated .schema_mod import (
18
- Vtkmesh ,
19
- Vtkwell ,
20
- Perforation ,
21
- InternalWell ,
22
- )
17
+ from geos .trame .schema_generated .schema_mod import Vtkmesh , Vtkwell , InternalWell , Perforation
23
18
24
19
pv .OFF_SCREEN = True
25
20
@@ -49,13 +44,20 @@ def __init__(
49
44
"""
50
45
super ().__init__ ( ** kwargs )
51
46
47
+ self ._point_data_array_names : list [ str ] = []
48
+ self ._cell_data_array_names : list [ str ] = []
52
49
self ._source = source
53
50
self ._pl = pv .Plotter ()
51
+ self ._mesh_actor : vtkActor | None = None
54
52
55
53
self .CUT_PLANE = "on_cut_plane_visibility_change"
56
54
self .ZAMPLIFICATION = "_z_amplification"
57
- self .server .state [ self .CUT_PLANE ] = True
58
- self .server .state [ self .ZAMPLIFICATION ] = 1
55
+ self .state [ self .CUT_PLANE ] = True
56
+ self .state [ self .ZAMPLIFICATION ] = 1
57
+
58
+ self .DATA_ARRAYS = "viewer_data_arrays_items"
59
+ self .SELECTED_DATA_ARRAY = "viewer_selected_data_array"
60
+ self .state .change ( self .SELECTED_DATA_ARRAY )( self ._update_actor_array )
59
61
60
62
self .region_engine = region_viewer
61
63
self .well_engine = well_viewer
@@ -68,8 +70,9 @@ def __init__(
68
70
view = plotter_ui (
69
71
self ._pl ,
70
72
add_menu_items = self .rendering_menu_extra_items ,
71
- style = "position: absolute;" ,
72
73
)
74
+ view .menu .style += "; height: 50px; min-width: 50px;"
75
+ view .menu .children [ 0 ].style += "; justify-content: center;"
73
76
self .ctrl .view_update = view .update
74
77
75
78
@property
@@ -88,21 +91,33 @@ def rendering_menu_extra_items( self ) -> None:
88
91
For now, adding a button to show/hide all widgets.
89
92
"""
90
93
self .state .change ( self .CUT_PLANE )( self ._on_clip_visibility_change )
91
- vuetify .VDivider ( vertical = True , classes = "mr-1" )
92
- with vuetify .VTooltip ( location = "bottom" ):
93
- with (
94
- vuetify .Template ( v_slot_activator = ( "{ props }" , ) ),
95
- html .Div ( v_bind = ( "props" , ) ),
96
- ):
97
- vuetify .VCheckbox (
98
- v_model = ( self .CUT_PLANE , True ),
99
- icon = True ,
100
- true_icon = "mdi-eye" ,
101
- false_icon = "mdi-eye-off" ,
102
- dense = True ,
103
- hide_details = True ,
104
- )
105
- html .Span ( "Show/Hide widgets" )
94
+ with vuetify .VRow (
95
+ classes = 'pa-0 ma-0 align-center fill-height' ,
96
+ style = "flex-wrap: nowrap" ,
97
+ ):
98
+ vuetify .VDivider ( vertical = True , classes = "mr-1" )
99
+ with vuetify .VTooltip ( location = "bottom" ):
100
+ with (
101
+ vuetify .Template ( v_slot_activator = ( "{ props }" , ) ),
102
+ html .Div ( v_bind = ( "props" , ) ),
103
+ ):
104
+ vuetify .VCheckbox (
105
+ v_model = ( self .CUT_PLANE , True ),
106
+ icon = True ,
107
+ true_icon = "mdi-eye" ,
108
+ false_icon = "mdi-eye-off" ,
109
+ dense = True ,
110
+ hide_details = True ,
111
+ )
112
+ html .Span ( "Show/Hide widgets" )
113
+ vuetify .VDivider ( vertical = True , classes = "mr-1" )
114
+ vuetify .VSelect (
115
+ hide_details = True ,
116
+ label = "Data Array" ,
117
+ items = ( self .DATA_ARRAYS , [] ),
118
+ v_model = ( self .SELECTED_DATA_ARRAY , None ),
119
+ min_width = "150px" ,
120
+ )
106
121
107
122
def update_viewer ( self , active_block : BaseModel , path : str , show_obj : bool ) -> None :
108
123
"""Add from path the dataset given by the user.
@@ -205,7 +220,7 @@ def _update_internalwell( self, path: str, show: bool ) -> None:
205
220
tube_actor = self .plotter .add_mesh ( self .well_engine .get_tube ( self .well_engine .get_last_mesh_idx () ) )
206
221
self .well_engine .append_actor ( path , tube_actor )
207
222
208
- self .server . controller .view_update ()
223
+ self .ctrl .view_update ()
209
224
210
225
def _update_vtkwell ( self , path : str , show : bool ) -> None :
211
226
"""Used to control the visibility of the Vtkwell.
@@ -219,7 +234,30 @@ def _update_vtkwell( self, path: str, show: bool ) -> None:
219
234
tube_actor = self .plotter .add_mesh ( self .well_engine .get_tube ( self .well_engine .get_last_mesh_idx () ) )
220
235
self .well_engine .append_actor ( path , tube_actor )
221
236
222
- self .server .controller .view_update ()
237
+ self .ctrl .view_update ()
238
+
239
+ def _clip_mesh ( self , normal : tuple [ float ], origin : tuple [ float ] ) -> None :
240
+ """Plane widget callback to clip the input data."""
241
+ if self ._mesh_actor is None :
242
+ return
243
+ self .region_engine .update_clip ( normal = normal , origin = origin )
244
+ self ._mesh_actor .mapper .SetInputData ( self .region_engine .clip )
245
+ self ._update_actor_array ()
246
+
247
+ def _update_actor_array ( self , ** _ : Any ) -> None :
248
+ """Update the actor scalar array."""
249
+ array_name = self .state [ self .SELECTED_DATA_ARRAY ]
250
+ if array_name is None or self ._mesh_actor is None :
251
+ return
252
+ mapper : pv .DataSetMapper = self ._mesh_actor .mapper
253
+
254
+ mapper .array_name = array_name
255
+ mapper .scalar_range = self .region_engine .clip .get_data_range ( array_name )
256
+ self .region_engine .clip .active_scalars_name = array_name
257
+ mapper .scalar_map_mode = "point" if array_name in self ._point_data_array_names else "cell"
258
+
259
+ self .plotter .scalar_bar .title = array_name
260
+ self .ctrl .view_update ()
223
261
224
262
def _update_vtkmesh ( self , show : bool ) -> None :
225
263
"""Used to control the visibility of the Vtkmesh.
@@ -230,21 +268,22 @@ def _update_vtkmesh( self, show: bool ) -> None:
230
268
"""
231
269
if not show :
232
270
self .plotter .clear_plane_widgets ()
233
- self .plotter .remove_actor ( self ._clip_mesh ) # type: ignore
271
+ self .plotter .remove_actor ( self ._mesh_actor ) # type: ignore
272
+ self ._mesh_actor = None
234
273
return
235
274
236
- active_scalar = self .region_engine .input .active_scalars_name
237
- self ._clip_mesh : vtkActor = self .plotter . add_mesh_clip_plane (
238
- self .region_engine . input ,
239
- origin = self .region_engine .input .center ,
240
- normal = [ - 1 , 0 , 0 ],
241
- crinkle = True ,
242
- show_edges = False ,
243
- cmap = "glasbey_bw" ,
244
- scalars = active_scalar ,
245
- )
246
-
247
- self . server . controller . view_update ( )
275
+ self . _point_data_array_names = list ( self .region_engine .input .point_data . keys () )
276
+ self ._cell_data_array_names = list ( self .region_engine . input . cell_data . keys () )
277
+ self . state [ self . DATA_ARRAYS ] = self ._point_data_array_names + self . _cell_data_array_names
278
+ self . state [ self . SELECTED_DATA_ARRAY ] = self .region_engine .input .active_scalars_name
279
+
280
+ self . _mesh_actor = self . plotter . add_mesh ( self . region_engine . input )
281
+ self . plotter . add_plane_widget ( callback = self . _clip_mesh ,
282
+ normal = [ 1 , 0 , 0 ] ,
283
+ origin = self . region_engine . input . center ,
284
+ assign_to_axis = None ,
285
+ tubing = False ,
286
+ outline_translation = False )
248
287
249
288
def _update_perforation ( self , perforation : Perforation , show : bool , path : str ) -> None :
250
289
"""Generate VTK dataset from a perforation."""
0 commit comments