Repository navigation
Expand file tree
/
Copy pathinception.py
More file actions
105 lines (83 loc) · 3.16 KB
/
Copy pathinception.py
File metadata and controls
105 lines (83 loc) · 3.16 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
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
105
import xml.etree.ElementTree as ET
import PySimpleGUI as sg
import sys
sg.theme('SystemDefault1')
from data import images
layout = [
[sg.Text('Enter getpos:'), sg.InputText()],
[sg.Text(size=(40,1), key='-OUTPUT-')],
[sg.Button('Convert')]
]
window = sg.Window('Inception Cam', layout, icon=images)
if len(sys.argv) < 2:
sys.exit(1)
filename = sys.argv[1]
tree = ET.parse(filename)
root = tree.getroot()
def writeValues(newX, newY, newZ):
prev_x, prev_y, prev_z = None, None, None
xyz_list = []
for point in root.iter('p'):
x, y, z = float(point.get('x')), float(point.get('y')), float(point.get('z'))
qy, qz = float(point.get('qy')), float(point.get('qz'))
test_x, test_y, test_z = x, y, z
if prev_x is not None:
x_diff = test_x - prev_x
point.set('x', str(x_diff))
else:
x_diff = 0
if prev_y is not None:
y_diff = test_y - prev_y
point.set('y', str(y_diff))
else:
y_diff = 0
if prev_z is not None:
z_diff = test_z - prev_z
point.set('z', str(z_diff))
else:
z_diff = 0
point.set('qy', str("{:.6f}".format(-qy)))
point.set('qz', str("{:.6f}".format(-qz)))
xyz_list.append((x_diff, y_diff, z_diff))
prev_x, prev_y, prev_z = x, y, z
for loop, point in enumerate(root.iter('p')):
x_diff, y_diff, z_diff = xyz_list[loop]
if prev_x == 0:
point.set('x', str("{:.6f}".format(newX)))
newX_diff = float(newX)
else:
newX_diff = float(newX) - float(x_diff)
point.set('x', str("{:.6f}".format(newX_diff)))
if prev_y == 0:
point.set('y', str("{:.6f}".format(newY)))
newY_diff = float(newY)
else:
newY_diff = float(newY) - float(y_diff)
point.set('y', str("{:.6f}".format(newY_diff)))
if prev_z == 0:
point.set('z', str("{:.6f}".format(newZ)))
newZ_diff = float(newZ)
else:
newZ_diff = float(newZ) - float(z_diff)
point.set('z', str("{:.6f}".format(newZ_diff)))
newX, newY, newZ = newX_diff, newY_diff, newZ_diff
prev_x, prev_y, prev_z = xyz_list[-1][0], xyz_list[-1][1], xyz_list[-1][2]
tree.write('updated_file.xml', encoding='utf-8')
while True:
event, values = window.read()
if event == sg.WINDOW_CLOSED or event == 'Exit':
break
if event == 'Convert':
input_str = values[0]
parts = input_str.split(';')[0].split()
if len(parts) >= 3:
if parts[0] == 'setpos':
output_str = f'{parts[0]} {parts[1]} {parts[2]} {parts[3]}'
window['-OUTPUT-'].update("Campath converted")
writeValues(parts[1], parts[2], parts[3])
else:
output_str = f'{parts[0]} {parts[1]} {parts[2]}'
window['-OUTPUT-'].update("Campath converted")
writeValues(parts[0], parts[1], parts[2])
window.close()
window.close()