This repository has been archived by the owner on Jun 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_inputs.py
104 lines (96 loc) · 4.6 KB
/
user_inputs.py
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import statistics as stat
import analogy.vpython_drawings as vpython_drawings
def select_object(vpython_scene):
picked_vpython_obj = None
def pick_obj():
nonlocal picked_vpython_obj
picked_vpython_obj = vpython_scene.mouse.pick
vpython_scene.unbind('mousedown', pick_obj)
while picked_vpython_obj is None:
vpython_scene.bind('mousedown', pick_obj)
vpython_scene.title = 'To select the target object, please click on it.'
vpython_scene.waitfor('mousedown')
if picked_vpython_obj is not None:
picked_vpython_obj.opacity = 0.8
user_input = input(
'Now you should see the the selected object as highlighted. Is that a correct object? yes/no: '
)
if user_input.lower() != 'yes' and user_input.lower() != 'y':
print('OK try again!')
picked_vpython_obj.opacity = 0.4
user_input = None
picked_vpython_obj = None
vpython_scene.bind('mousedown', pick_obj)
picked_vpython_obj.opacity = 0.8
vpython_scene.center = picked_vpython_obj.pos
return picked_vpython_obj
def get_point(vpython_scene, picked_obj, picked_vpython_obj, operation):
vpython_scene.title = 'Follow instructions in the terminal window.'
user_message = ['\nSelect manipulation point for ' + operation + '.']
user_message.append('It has to be in form of "X, Y, Z"')
user_message.append('Notice that the coordinates are separated by comma.')
user_message.append('the object has half size: ' +
str(picked_obj.aabb.half_size))
user_message.append('and XYZ coordinates of the middle point: : ' +
str(picked_obj.aabb.pos))
user_message.append(operation + ' manipulation point X,Y,Z or none: ')
user_input = None
while user_input == None:
user_input = input("\n".join(user_message))
point_list = user_input.split(',')
if len(point_list) == 3:
picked_obj.aabb.manipulation_points[operation] = [
float(point_list[0].strip()),
float(point_list[1].strip()),
float(point_list[2].strip())
]
radius = stat.mean(picked_obj.aabb.half_size) / 10
vpython_point = vpython_drawings.draw_point(
picked_obj.aabb.manipulation_points[operation], radius)
picked_vpython_obj.opacity = 0.4
user_input = input(
'Now you should see the point. Is that correct location? yes/no: '
)
if user_input.lower() != 'yes' and user_input.lower() != 'y':
print('OK try again!')
vpython_point.visible = False
del vpython_point
user_input = None
elif user_input.lower() == 'none':
picked_obj.aabb.manipulation_points[operation] = [None, None, None]
else:
user_input = None
print('\nWrong input. Try again!')
def get_vector(vpython_scene, picked_obj, picked_vpython_obj, operation):
if picked_obj.aabb.manipulation_points[operation][0] is not None:
# get force vector for pushing
user_message = ['\nSelect force vector for ' + operation + '.']
user_message.append('It has to be in form of "X, Y, Z"')
user_message.append(operation + ' force vector X,Y,Z: ')
user_input = None
while user_input == None:
user_input = input("\n".join(user_message))
force_vec = user_input.split(',')
if len(force_vec) == 3:
picked_obj.aabb.manipulation_vectors[operation] = [
float(force_vec[0].strip()),
float(force_vec[1].strip()),
float(force_vec[2].strip())
]
length = stat.mean(picked_obj.aabb.half_size)
vpython_arrow = vpython_drawings.draw_arrow(
picked_obj.aabb.manipulation_points[operation],
picked_obj.aabb.manipulation_vectors[operation], length)
user_input = input(
'Now you should see the force arrow. Is that correct ? yes/no: '
)
if user_input.lower() != 'yes' and user_input.lower() != 'y':
print('OK try again!')
vpython_arrow.visible = False
del vpython_arrow
user_input = None
else:
user_input = None
print('Wrong input. Try again!')
else:
picked_obj.aabb.manipulation_vectors[operation] = [None, None, None]