-
-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathQgsFmvVideoSession.py
More file actions
81 lines (61 loc) · 2.38 KB
/
Copy pathQgsFmvVideoSession.py
File metadata and controls
81 lines (61 loc) · 2.38 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
"""Per-video telemetry / georeferencing session state.
Replaces the former module-global ``gv`` singleton. Callers should prefer
``get_active_session()`` or an injected ``VideoSession`` instance. The
legacy ``QgsFmvUtils.gv`` name remains as a thin alias to the active
session for backward compatibility.
"""
from QGIS_FMV.utils.core.QgsFmvUtilsState import globalVariablesState
from QGIS_FMV.utils.logging import log
# Active session for the currently focused player (single-video default).
_active_session = None
class VideoSession(globalVariablesState):
"""Mutable telemetry state for one open video player."""
def __init__(self, iface=None):
super().__init__()
if iface is not None:
self.iface = iface
def reset_telemetry(self):
"""Clear footprint / sensor / geotransform fields (keep iface + centerMode)."""
iface = self.iface
center = self.centerMode
self.__init__(iface=iface)
self.centerMode = center
def activate(self):
"""Make this the process-wide active session (legacy ``gv`` alias)."""
global _active_session
_active_session = self
_sync_legacy_gv()
return self
def deactivate(self):
"""Clear active session if it is this instance."""
global _active_session
if _active_session is self:
_active_session = None
_sync_legacy_gv()
def get_active_session():
"""Return the active :class:`VideoSession`, or ``None``."""
return _active_session
def ensure_session(iface=None):
"""Return the active session, creating one if needed."""
global _active_session
if _active_session is None:
_active_session = VideoSession(iface=iface)
_sync_legacy_gv()
elif iface is not None:
_active_session.setIface(iface)
return _active_session
def set_active_session(session):
"""Replace the active session (``None`` clears it)."""
global _active_session
_active_session = session
_sync_legacy_gv()
return _active_session
def _sync_legacy_gv():
"""Keep ``QgsFmvUtils.gv`` pointing at the active session."""
try:
import QGIS_FMV.utils.core.QgsFmvUtils as utils
utils.gv = _active_session
except Exception as exc:
log.debug("Failed to sync legacy gv alias: %s", exc)
# Alias kept for readability at call sites / docs.
VideoState = VideoSession