Skip to content

Commit c25d0eb

Browse files
committed
Add example to keep the Qt GUI example
1 parent 5831817 commit c25d0eb

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

examples/basic-useQtGUI.py

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

0 commit comments

Comments
 (0)