/
test_tracker.py
81 lines (56 loc) · 2.3 KB
/
test_tracker.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
from pivy import coin
import FreeCADGui as Gui
from DraftGui import todo
class TestTracker():
def __init__(self):
self.node = coin.SoSeparator()
self.coordinate = coin.SoCoordinate3()
self.crosshair_coord = coin.SoCoordinate3()
self.transform = coin.SoTransform()
_selection_node = \
coin.SoType.fromName("SoFCSelection").createInstance()
_selection_node.documentName.setValue('Document')
_selection_node.objectName.setValue('Test Tracker')
_selection_node.subElementName.setValue('NODE-0')
self.node.addChild(_selection_node)
self.node.addChild(self.transform)
self.node.addChild(self.coordinate)
self.node.addChild(coin.SoMarkerSet())
self.coordinate.point.setValue((0.0, 0.0, 0.0))
self.view = Gui.ActiveDocument.ActiveView
self.view.addEventCallback(
'SoLocation2Event', self.mouse_event)
_fn = lambda _x: self.view.getSceneGraph().insertChild(_x, 0)
self.crosshair = self.create_crosshair()
todo.delay(_fn, self.node)
todo.delay(_fn, self.crosshair)
def create_crosshair(self):
_switch = coin.SoSwitch()
_node = coin.SoSeparator()
_coord = coin.SoCoordinate3()
_transform = coin.SoTransform()
self.crosshair_coord.point.setValues(0, 5, [
(1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (-1.0, 0.0, 0.0),
(0.0, -1.0, 0.0), (1.0, 0.0, 0.0)
])
_nodes = [_transform, self.crosshair_coord, coin.SoLineSet()]
for _v in _nodes:
_node.addChild(_v)
_switch.addChild(_node)
_switch.whichChild = -1
return _switch
def mouse_event(self, arg):
pos = self.view.getCursorPos()
info = self.view.getObjectInfo(pos)
coord_1 = self.view.getPoint((0, 0))
coord_2 = self.view.getPoint((100, 0))
delta = abs(coord_2[0] - coord_1[0])
self.crosshair_coord.point.setValues(0, 5, [
(float(delta), 0.0, 0.0), (0.0, float(delta), 0.0),
(float(-delta), 0.0, 0.0), (0.0, float(-delta), 0.0),
(float(delta), 0.0, 0.0)
])
if info and info['Component'] == 'NODE-0':
self.crosshair.whichChild = -3
else:
self.crosshair.whichChild = -1