Skip to content

Commit 0cb5d02

Browse files
committed
add test on reassigment
1 parent 3dd543e commit 0cb5d02

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import Sofa
2+
3+
g_nb_controllers = 3
4+
g_controllers = []
5+
6+
class TestReassignmentController(Sofa.Core.Controller):
7+
8+
def __init__(self, *args, **kwargs):
9+
Sofa.Core.Controller.__init__(self, *args, **kwargs)
10+
11+
def onAnimateBeginEvent(self, event):
12+
print(f"{self.name.value} : onAnimateBeginEvent")
13+
pass
14+
15+
def modifiedAnimateBeginEvent(self, event):
16+
print(f"{self.name.value} : modifiedAnimateBeginEvent")
17+
pass
18+
19+
def createScene(root):
20+
root.dt = 0.01
21+
root.bbox = [[-1, -1, -1], [1, 1, 1]]
22+
root.addObject('DefaultVisualManagerLoop')
23+
root.addObject('DefaultAnimationLoop')
24+
25+
for i in range(g_nb_controllers):
26+
controller = root.addObject(TestReassignmentController(name=f"Controller{i}"))
27+
g_controllers.append(controller)
28+
29+
30+
def main():
31+
root = Sofa.Core.Node("root")
32+
createScene(root)
33+
Sofa.Simulation.initRoot(root)
34+
35+
# one step with the "fixed" implementation of onAnimateBeginEvent
36+
Sofa.Simulation.animate(root, root.dt.value) # should print "ControllerX : onAnimateBeginEvent"
37+
38+
# reassign onAnimateBeginEvent method
39+
for controller in g_controllers:
40+
controller.onAnimateBeginEvent = controller.modifiedAnimateBeginEvent
41+
42+
Sofa.Simulation.animate(root, root.dt.value) # should print "ControllerX : modifiedAnimateBeginEvent"
43+
44+
45+
if __name__ == '__main__':
46+
main()

0 commit comments

Comments
 (0)