From 89d8c6172efeec81359417a1943175968701204a Mon Sep 17 00:00:00 2001 From: Thiago Franco de Moraes Date: Tue, 26 Mar 2013 10:25:18 -0300 Subject: [PATCH] Created a new interactor style to change slices with the mouse movement --- invesalius/data/styles.py | 38 ++++++++++++++++++++++++++++++++++++++ invesalius/data/viewer_slice.py | 7 +++++++ 2 files changed, 45 insertions(+), 0 deletions(-) diff --git a/invesalius/data/styles.py b/invesalius/data/styles.py index cfbc000..f8e547c 100644 --- a/invesalius/data/styles.py +++ b/invesalius/data/styles.py @@ -385,6 +385,44 @@ class ZoomSLInteractorStyle(vtk.vtkInteractorStyleRubberBandZoom): #self.Reposition(slice_data) self.viewer.interactor.Render() + +class ChangeSliceInteractorStyle(RightZoomInteractorStyle): + """ + Interactor style responsible for change slice moving the mouse. + """ + def __init__(self, viewer): + RightZoomInteractorStyle.__init__(self) + + self.viewer = viewer + + self.AddObserver("MouseMoveEvent", self.OnChangeSliceMove) + self.AddObserver("LeftButtonPressEvent", self.OnChangeSliceClick) + + def OnChangeSliceMove(self, evt, obj): + if self.left_pressed: + min = 0 + max = self.viewer.slice_.GetMaxSliceNumber(self.viewer.orientation) + + position = self.viewer.interactor.GetLastEventPosition() + scroll_position = self.viewer.scroll.GetThumbPosition() + + if (position[1] > self.last_position) and\ + (self.acum_achange_slice > min): + self.acum_achange_slice -= 1 + elif(position[1] < self.last_position) and\ + (self.acum_achange_slice < max): + self.acum_achange_slice += 1 + self.last_position = position[1] + + self.viewer.scroll.SetThumbPosition(self.acum_achange_slice) + self.viewer.OnScrollBar() + + def OnChangeSliceClick(self, evt, obj): + position = self.viewer.interactor.GetLastEventPosition() + self.acum_achange_slice = self.viewer.scroll.GetThumbPosition() + self.last_position = position[1] + + class ViewerStyle: def __init__(self): self.interactor = None diff --git a/invesalius/data/viewer_slice.py b/invesalius/data/viewer_slice.py index 8b2cb8c..010e940 100755 --- a/invesalius/data/viewer_slice.py +++ b/invesalius/data/viewer_slice.py @@ -245,6 +245,13 @@ class Viewer(wx.Panel): self.interactor.SetInteractorStyle(style) self.interactor.Render() + elif state == const.SLICE_STATE_SCROLL: + style = styles.ChangeSliceInteractorStyle(self) + + self.style = style + self.interactor.SetInteractorStyle(style) + self.interactor.Render() + else: self.state = state action = { -- libgit2 0.21.2