forked from sofa-framework/SofaPython3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic-useQtGUI.py
More file actions
58 lines (42 loc) · 1.76 KB
/
basic-useQtGUI.py
File metadata and controls
58 lines (42 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Choose in your script to activate or not the GUI
USE_GUI = True
def main():
# Required import for python
import Sofa
# Make sure to load all SOFA libraries
#Create the root node
root = Sofa.Core.Node("root")
# Call the below 'createScene' function to create the scene graph
createScene(root)
Sofa.Simulation.initRoot(root)
if not USE_GUI:
for iteration in range(10):
Sofa.Simulation.animate(root, root.dt.value)
else:
import Sofa.Gui
import SofaQt # specific import for Qt-based GUI
# Find out the supported GUIs
print ("Supported GUIs are: " + Sofa.Gui.GUIManager.ListSupportedGUI(","))
# Launch the GUI (qt or qglviewer)
Sofa.Gui.GUIManager.Init("myscene", "qglviewer")
Sofa.Gui.GUIManager.createGUI(root, __file__)
Sofa.Gui.GUIManager.SetDimension(1080, 1080)
# Initialization of the scene will be done here
Sofa.Gui.GUIManager.MainLoop(root)
Sofa.Gui.GUIManager.closeGUI()
print("GUI was closed")
print("Simulation is done.")
# Function called when the scene graph is being created
def createScene(root):
root.addObject('RequiredPlugin', name='Sofa.Component.StateContainer')
# Scene must now include a AnimationLoop
root.addObject('DefaultAnimationLoop')
# Add new nodes and objects in the scene
node1 = root.addChild("Node1")
node2 = root.addChild("Node2")
node1.addObject("MechanicalObject", template="Rigid3d", position="0 0 0 0 0 0 1", showObject="1")
node2.addObject("MechanicalObject", template="Rigid3d", position="1 1 1 0 0 0 1", showObject="1")
return root
# Function used only if this script is called from a python environment
if __name__ == '__main__':
main()