Commit 89d8c6172efeec81359417a1943175968701204a
1 parent
88fe930f
Exists in
interactor_style
Created a new interactor style to change slices with the mouse movement
Showing
2 changed files
with
45 additions
and
0 deletions
Show diff stats
invesalius/data/styles.py
... | ... | @@ -385,6 +385,44 @@ class ZoomSLInteractorStyle(vtk.vtkInteractorStyleRubberBandZoom): |
385 | 385 | #self.Reposition(slice_data) |
386 | 386 | self.viewer.interactor.Render() |
387 | 387 | |
388 | + | |
389 | +class ChangeSliceInteractorStyle(RightZoomInteractorStyle): | |
390 | + """ | |
391 | + Interactor style responsible for change slice moving the mouse. | |
392 | + """ | |
393 | + def __init__(self, viewer): | |
394 | + RightZoomInteractorStyle.__init__(self) | |
395 | + | |
396 | + self.viewer = viewer | |
397 | + | |
398 | + self.AddObserver("MouseMoveEvent", self.OnChangeSliceMove) | |
399 | + self.AddObserver("LeftButtonPressEvent", self.OnChangeSliceClick) | |
400 | + | |
401 | + def OnChangeSliceMove(self, evt, obj): | |
402 | + if self.left_pressed: | |
403 | + min = 0 | |
404 | + max = self.viewer.slice_.GetMaxSliceNumber(self.viewer.orientation) | |
405 | + | |
406 | + position = self.viewer.interactor.GetLastEventPosition() | |
407 | + scroll_position = self.viewer.scroll.GetThumbPosition() | |
408 | + | |
409 | + if (position[1] > self.last_position) and\ | |
410 | + (self.acum_achange_slice > min): | |
411 | + self.acum_achange_slice -= 1 | |
412 | + elif(position[1] < self.last_position) and\ | |
413 | + (self.acum_achange_slice < max): | |
414 | + self.acum_achange_slice += 1 | |
415 | + self.last_position = position[1] | |
416 | + | |
417 | + self.viewer.scroll.SetThumbPosition(self.acum_achange_slice) | |
418 | + self.viewer.OnScrollBar() | |
419 | + | |
420 | + def OnChangeSliceClick(self, evt, obj): | |
421 | + position = self.viewer.interactor.GetLastEventPosition() | |
422 | + self.acum_achange_slice = self.viewer.scroll.GetThumbPosition() | |
423 | + self.last_position = position[1] | |
424 | + | |
425 | + | |
388 | 426 | class ViewerStyle: |
389 | 427 | def __init__(self): |
390 | 428 | self.interactor = None | ... | ... |
invesalius/data/viewer_slice.py
... | ... | @@ -245,6 +245,13 @@ class Viewer(wx.Panel): |
245 | 245 | self.interactor.SetInteractorStyle(style) |
246 | 246 | self.interactor.Render() |
247 | 247 | |
248 | + elif state == const.SLICE_STATE_SCROLL: | |
249 | + style = styles.ChangeSliceInteractorStyle(self) | |
250 | + | |
251 | + self.style = style | |
252 | + self.interactor.SetInteractorStyle(style) | |
253 | + self.interactor.Render() | |
254 | + | |
248 | 255 | else: |
249 | 256 | self.state = state |
250 | 257 | action = { | ... | ... |