Switch¶
sceneplates/switch.py¶
1# © 2024 Autodesk, Inc. All rights reserved.
2#
3# Example to show how to query front plates
4# This example is more complex as simple.py and create.py
5# Please study this first
6#
7# vrSceneplateService is used to query scene plates and set defaults
8# vrdSceneplateNode is used to change scene plate properties
9#
10
11# We introduce this types to make the code more readable
12NodeType = vrSceneplateTypes.NodeType
13ContentType = vrSceneplateTypes.ContentType
14PositionType = vrSceneplateTypes.Position
15
16# An array with all node names. We use this for scene plate creation and query.
17theNodeNames = ["1", "2", "3", "4", "5", "6", "7", "8"]
18
19# The curent shown plate
20thePlate = -1
21
22# This function summarizes all necessary steps to create a scene plate and set its properties.
23# First we have to create a node using the scene plate service and convert this to an plate.
24# Then we set different properties of the new created plate.
25def createPlate(root, index, position):
26 global theNodeNames
27 global theFontColor
28 theName = theNodeNames[index]
29 theNode = vrSceneplateService.createNode(root, NodeType.Frontplate, theName)
30 thePlate = vrdSceneplateNode(theNode)
31 thePlate.setContentType(ContentType.Text)
32 thePlate.setText(theName)
33 thePlate.setPosition(position)
34
35# This function creates all used front plates
36def propagateScene(root):
37 global theSwitch
38
39 createPlate(root, 0, PositionType.TopLeft)
40 createPlate(root, 1, PositionType.Top)
41 createPlate(root, 2, PositionType.TopRight)
42 createPlate(root, 3, PositionType.Right)
43 createPlate(root, 4, PositionType.BottomRight)
44 createPlate(root, 5, PositionType.Bottom)
45 createPlate(root, 6, PositionType.BottomLeft)
46 createPlate(root, 7, PositionType.Left)
47
48 thePlates = vrSceneplateService.getAllSceneplates()
49 theSwitch = vrSceneplateService.createSwitchForNodes(thePlates)
50
51# Step to the next plate
52def nextStep():
53 global thePlate
54 global theSwitch
55 global theNodeNames
56
57 thePlate = thePlate + 1
58 if thePlate >= len(theNodeNames):
59 thePlate = 0
60
61 theSwitch.setChoice(thePlate)
62
63# Query parent object for all scene plate creation
64theRoot = vrSceneplateService.getRootNode()
65
66# Set defaults colors
67vrSceneplateService.setDefaultBackgroundTransparency(1.0)
68vrSceneplateService.setDefaultBackgroundColor(QVector3D(0.6, 0.6, 0.6))
69vrSceneplateService.setDefaultFontColor(QVector3D(0, 0.5, 0.5))
70
71# Create text front plates attached to windows sides
72propagateScene(theRoot)
73
74# Start a timer and make each second the next step in this animation
75timer = vrTimer(1.0)
76timer.connect(nextStep)
77timer.setActive(true)