Commit 723af25db2bb44fcf28a95c21a824207e9633afc

Authored by Renan
Committed by Thiago Franco de Moraes
1 parent b8381c75

Remove tracker when InVesalius is closed (#75)

* remove tracker when invesalius is closed

* Fix polhemus connection warning
-added msg for statusbar when try to disconnect tracker

* Standardization
invesalius/data/coordinates.py
@@ -51,7 +51,7 @@ def GetCoordinates(trck_init, trck_id, ref_mode): @@ -51,7 +51,7 @@ def GetCoordinates(trck_init, trck_id, ref_mode):
51 51
52 def ClaronCoord(trck_init, trck_id, ref_mode): 52 def ClaronCoord(trck_init, trck_id, ref_mode):
53 trck = trck_init[0] 53 trck = trck_init[0]
54 - scale = 10. * np.array([1., 1.0, -1.0]) 54 + scale = np.array([1.0, 1.0, -1.0])
55 coord = None 55 coord = None
56 k = 0 56 k = 0
57 # TODO: try to replace while and use some Claron internal computation 57 # TODO: try to replace while and use some Claron internal computation
invesalius/data/trackers.py
@@ -123,6 +123,8 @@ def PlhWrapperConnection(): @@ -123,6 +123,8 @@ def PlhWrapperConnection():
123 if trck_check: 123 if trck_check:
124 # First run is necessary to discard the first coord collection 124 # First run is necessary to discard the first coord collection
125 trck_init.Run() 125 trck_init.Run()
  126 + else:
  127 + trck_init = trck_check
126 except: 128 except:
127 print 'Could not connect to Polhemus via wrapper.' 129 print 'Could not connect to Polhemus via wrapper.'
128 130
@@ -195,6 +197,8 @@ def DisconnectTracker(tracker_id): @@ -195,6 +197,8 @@ def DisconnectTracker(tracker_id):
195 197
196 :param tracker_id: ID of tracking device. 198 :param tracker_id: ID of tracking device.
197 """ 199 """
  200 + from wx.lib.pubsub import pub as Publisher
  201 + Publisher.sendMessage('Update status text in GUI', _("Disconnecting tracker ..."))
198 trck_init = None 202 trck_init = None
199 # TODO: create individual functions to disconnect each other device, e.g. Polhemus. 203 # TODO: create individual functions to disconnect each other device, e.g. Polhemus.
200 if tracker_id == 1: 204 if tracker_id == 1:
@@ -202,6 +206,7 @@ def DisconnectTracker(tracker_id): @@ -202,6 +206,7 @@ def DisconnectTracker(tracker_id):
202 import pyclaron 206 import pyclaron
203 pyclaron.pyclaron().Close() 207 pyclaron.pyclaron().Close()
204 lib_mode = 'wrapper' 208 lib_mode = 'wrapper'
  209 + print 'Claron tracker disconnected.'
205 except ImportError: 210 except ImportError:
206 lib_mode = 'error' 211 lib_mode = 'error'
207 print 'The ClaronTracker library is not installed.' 212 print 'The ClaronTracker library is not installed.'
@@ -211,6 +216,7 @@ def DisconnectTracker(tracker_id): @@ -211,6 +216,7 @@ def DisconnectTracker(tracker_id):
211 import polhemus 216 import polhemus
212 polhemus.polhemus().Close() 217 polhemus.polhemus().Close()
213 lib_mode = 'wrapper' 218 lib_mode = 'wrapper'
  219 + print 'Polhemus tracker disconnected.'
214 except ImportError: 220 except ImportError:
215 lib_mode = 'error' 221 lib_mode = 'error'
216 print 'The polhemus library is not installed.' 222 print 'The polhemus library is not installed.'
@@ -219,4 +225,6 @@ def DisconnectTracker(tracker_id): @@ -219,4 +225,6 @@ def DisconnectTracker(tracker_id):
219 print 'Debug tracker disconnected.' 225 print 'Debug tracker disconnected.'
220 lib_mode = 'debug' 226 lib_mode = 'debug'
221 227
  228 + Publisher.sendMessage('Update status text in GUI', _("Ready"))
  229 +
222 return trck_init, lib_mode 230 return trck_init, lib_mode
223 \ No newline at end of file 231 \ No newline at end of file
invesalius/gui/frame.py
@@ -382,6 +382,7 @@ class Frame(wx.Frame): @@ -382,6 +382,7 @@ class Frame(wx.Frame):
382 Close all project data. 382 Close all project data.
383 """ 383 """
384 Publisher.sendMessage('Close Project') 384 Publisher.sendMessage('Close Project')
  385 + Publisher.sendMessage('Disconnect tracker')
385 s = ses.Session() 386 s = ses.Session()
386 if not s.IsOpen() or not s.project_path: 387 if not s.IsOpen() or not s.project_path:
387 Publisher.sendMessage('Exit') 388 Publisher.sendMessage('Exit')
invesalius/gui/task_navigator.py
@@ -312,6 +312,7 @@ class NeuronavigationPanel(wx.Panel): @@ -312,6 +312,7 @@ class NeuronavigationPanel(wx.Panel):
312 Publisher.subscribe(self.LoadImageFiducials, 'Load image fiducials') 312 Publisher.subscribe(self.LoadImageFiducials, 'Load image fiducials')
313 Publisher.subscribe(self.UpdateTriggerState, 'Update trigger state') 313 Publisher.subscribe(self.UpdateTriggerState, 'Update trigger state')
314 Publisher.subscribe(self.UpdateImageCoordinates, 'Set ball reference position') 314 Publisher.subscribe(self.UpdateImageCoordinates, 'Set ball reference position')
  315 + Publisher.subscribe(self.OnDisconnectTracker, 'Disconnect tracker')
315 316
316 def LoadImageFiducials(self, pubsub_evt): 317 def LoadImageFiducials(self, pubsub_evt):
317 marker_id = pubsub_evt.data[0] 318 marker_id = pubsub_evt.data[0]
@@ -341,6 +342,10 @@ class NeuronavigationPanel(wx.Panel): @@ -341,6 +342,10 @@ class NeuronavigationPanel(wx.Panel):
341 def UpdateTriggerState (self, pubsub_evt): 342 def UpdateTriggerState (self, pubsub_evt):
342 self.trigger_state = pubsub_evt.data 343 self.trigger_state = pubsub_evt.data
343 344
  345 + def OnDisconnectTracker(self, pubsub_evt):
  346 + if self.tracker_id:
  347 + dt.TrackerConnection(self.tracker_id, 'disconnect')
  348 +
344 def OnChoiceTracker(self, evt, ctrl): 349 def OnChoiceTracker(self, evt, ctrl):
345 Publisher.sendMessage('Update status text in GUI', _("Configuring tracker ...")) 350 Publisher.sendMessage('Update status text in GUI', _("Configuring tracker ..."))
346 if evt: 351 if evt: