Commit ed898334474abd00a2cbba040d09c0646b571148

Authored by Olli-Pekka Kahilakoski
Committed by GitHub
1 parent 3f9f34c4
Exists in master

ADD: Send 'Set cross focal point' msgs using NeuronavigationApi (#420)

Showing 1 changed file with 16 additions and 0 deletions   Show diff stats
invesalius/net/neuronavigation_api.py
... ... @@ -36,12 +36,28 @@ class NeuronavigationApi(metaclass=Singleton):
36 36 def __init__(self, connection=None):
37 37 if connection is not None:
38 38 assert self._hasmethod(connection, 'update_coil_pose')
  39 + self.__bind_events()
39 40  
40 41 self.connection = connection
41 42  
42 43 def _hasmethod(self, obj, name):
43 44 return hasattr(obj, name) and callable(getattr(obj, name))
44 45  
  46 + def __bind_events(self):
  47 + Publisher.subscribe(self.update_focus, 'Set cross focal point')
  48 +
  49 + # TODO: Not the cleanest API; for an example of a better API, see update_coil_pose
  50 + # below, for which position and orientation are sent separately. Changing this
  51 + # would require changing 'Set cross focal point' publishers and subscribers
  52 + # throughout the code.
  53 + #
  54 + def update_focus(self, position):
  55 + if self.connection is not None:
  56 + self.connection.update_focus(
  57 + position=position[:3],
  58 + orientation=position[3:],
  59 + )
  60 +
45 61 def update_coil_pose(self, position, orientation):
46 62 if self.connection is not None:
47 63 self.connection.update_coil_pose(
... ...