-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathgl_layer.py
88 lines (64 loc) · 3.17 KB
/
gl_layer.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
from pyqtgraph.Qt import QtGui
from pyqtgraph.opengl.GLGraphicsItem import GLGraphicsItem
from software.thunderscope.gl.helpers.observable_list import Change, ChangeAction
from software.thunderscope.gl.helpers.extended_gl_view_widget import MouseInSceneEvent
from software.thunderscope.gl.helpers.gl_patches import *
class GLLayer(GLGraphicsItem):
"""Represents a layer in the 3D visualization.
A layer is added to the 3D scenegraph and represents a collection of
GLGraphicsItems to be displayed together. GLGraphicsItems should be
added as children of a GLLayer.
GLLayers themselves can also be added as a children of a GLLayer,
enabling us to group together related layers.
"""
def __init__(self, name: str, parent_item: GLGraphicsItem | None = None) -> None:
"""Initialize the GLLayer
:param name: The displayed name of the layer
:param parent_item: The parent GLGraphicsItem of the GLLayer
"""
super().__init__(parent_item)
self.name = name
def refresh_graphics(self) -> None:
"""Updates the GLGraphicsItems in this layer"""
raise NotImplementedError("Subclasses must implement this method!")
def keyPressEvent(self, event: QtGui.QKeyEvent) -> None:
"""Detect when a key has been pressed
:param event: The event
"""
def keyReleaseEvent(self, event: QtGui.QKeyEvent) -> None:
"""Detect when a key has been released
:param event: The event
"""
def mouse_in_scene_pressed(self, event: MouseInSceneEvent) -> None:
"""Detect that the mouse was pressed and picked a point in the 3D scene
:param event: The event
"""
def mouse_in_scene_dragged(self, event: MouseInSceneEvent) -> None:
"""Detect that the mouse was dragged within the 3D scene
:param event: The event
"""
def mouse_in_scene_released(self, event: MouseInSceneEvent) -> None:
"""Detect that the mouse was released after picking a point in the 3D scene
:param event: The event
"""
def mouse_in_scene_moved(self, event: MouseInSceneEvent) -> None:
"""Detect that the mouse was moved within the 3D scene
:param event: The event
"""
def _graphics_changed(self, change: Change) -> None:
"""Called by an ObservableList of GLGraphicsItems to notify
this observer that GLGraphicsItems were added or removed from
the ObservableList.
Subclasses of GLLayer should use ObservableLists to store collections of
GLGraphicsItems. Each ObservableList should register this function as an observer
so that GLGraphicsItems are automatically added/removed as children of this layer
(and thus added/removed to the 3D scenegraph) when they are added/removed from
the ObservableList.
:param change: Change representing the GLGraphicsItems added or removed
"""
if change.action == ChangeAction.ADD:
for graphic in change.elements:
graphic.setParentItem(self)
elif change.action == ChangeAction.REMOVE:
for graphic in change.elements:
graphic.setParentItem(None)