Skip to content

Commit 56878ff

Browse files
committed
fix: well actor wasn't remove correctly
1 parent 6b5d57c commit 56878ff

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

geos-trame/src/geos/trame/app/ui/viewer/viewer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ def _update_internalwell( self, path: str, show: bool ) -> None:
235235
"""
236236
if not show:
237237
self.plotter.remove_actor( self.well_engine.get_actor( path ) ) # type: ignore
238+
self.well_engine.remove_actor( path )
238239
return
239240

240241
tube_actor = self.plotter.add_mesh( self.well_engine.get_tube( self.well_engine.get_last_mesh_idx() ) )
@@ -249,6 +250,7 @@ def _update_vtkwell( self, path: str, show: bool ) -> None:
249250
"""
250251
if not show:
251252
self.plotter.remove_actor( self.well_engine.get_actor( path ) ) # type: ignore
253+
self.well_engine.remove_actor( path )
252254
return
253255

254256
tube_actor = self.plotter.add_mesh( self.well_engine.get_tube( self.well_engine.get_last_mesh_idx() ) )

geos-trame/src/geos/trame/app/ui/viewer/wellViewer.py

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ class Well:
1717
well_path: str
1818
polyline: pv.PolyData
1919
tube: pv.PolyData
20+
21+
22+
@dataclass
23+
class WellActor:
24+
"""A WellActor stores the VTK Actor representing a well."""
25+
well_path: str
2026
actor: pv.Actor
2127

2228

@@ -28,6 +34,7 @@ def __init__( self, size: float, amplification: float ) -> None:
2834
A Well in GEOS could a InternalWell or a Vtkwell.
2935
"""
3036
self._wells: list[ Well ] = []
37+
self._wells_actors: list[ WellActor ] = []
3138

3239
self.size: float = size
3340
self.amplification: float = amplification
@@ -51,7 +58,8 @@ def add_mesh( self, mesh: pv.PolyData, mesh_path: str ) -> int:
5158
radius = self.size * ( self.STARTING_VALUE / 100 )
5259
tube = mesh.tube( radius=radius, n_sides=50 )
5360

54-
self._wells.append( Well( mesh_path, mesh, tube, pv.Actor() ) )
61+
self._wells.append( Well( mesh_path, mesh, tube ) )
62+
self._wells_actors.append( WellActor( mesh_path, pv.Actor() ) )
5563

5664
return len( self._wells ) - 1
5765

@@ -78,21 +86,21 @@ def get_tube_size( self ) -> float:
7886

7987
def append_actor( self, perforation_path: str, tube_actor: pv.Actor ) -> None:
8088
"""Append a given actor, typically the Actor returned by the pv.Plotter() when a given mes is added."""
81-
index = self._get_index_from_perforation( perforation_path )
89+
index = self._get_actor_index_from_perforation( perforation_path )
8290
if index == -1:
8391
print( "Cannot found the well to remove from path: ", perforation_path )
8492
return
8593

86-
self._wells[ index ].actor = tube_actor
94+
self._wells_actors[ index ].actor = tube_actor
8795

8896
def get_actor( self, perforation_path: str ) -> pv.Actor | None:
8997
"""Retrieve the polyline linked to a given perforation path."""
90-
index = self._get_index_from_perforation( perforation_path )
98+
index = self._get_actor_index_from_perforation( perforation_path )
9199
if index == -1:
92100
print( "Cannot found the well to remove from path: ", perforation_path )
93101
return None
94102

95-
return self._wells[ index ].actor
103+
return self._wells_actors[ index ].actor
96104

97105
def update( self, value: float ) -> None:
98106
"""Update the radius of the tubes."""
@@ -108,6 +116,14 @@ def remove( self, perforation_path: str ) -> None:
108116

109117
self._wells.remove( self._wells[ index ] )
110118

119+
def remove_actor( self, perforation_path: str ) -> None:
120+
"""Clear all data stored in this class."""
121+
index = self._get_actor_index_from_perforation( perforation_path )
122+
if index == -1:
123+
print( "Cannot found the well to remove from path: ", perforation_path )
124+
125+
self._wells_actors.remove( self._wells_actors[ index ] )
126+
111127
def _get_index_from_perforation( self, perforation_path: str ) -> int:
112128
"""Retrieve the well associated to a given perforation, otherwise return -1."""
113129
index = -1
@@ -121,6 +137,19 @@ def _get_index_from_perforation( self, perforation_path: str ) -> int:
121137

122138
return index
123139

140+
def _get_actor_index_from_perforation( self, perforation_path: str ) -> int:
141+
"""Retrieve the well actor associated to a given perforation, otherwise return -1."""
142+
index = -1
143+
if len( self._wells_actors ) == 0:
144+
return index
145+
146+
for i in range( 0, len( self._wells_actors ) ):
147+
if self._wells_actors[ i ].well_path in perforation_path:
148+
index = i
149+
break
150+
151+
return index
152+
124153
def get_number_of_wells( self ) -> int:
125154
"""Get the number of wells in the viewer."""
126155
return len( self._wells )

0 commit comments

Comments
 (0)