Commit 4f8bc05fa16ee053287be6bfa5bbb7797b00935a

Authored by Paulo Henrique Junqueira Amorim
1 parent 897ed709

ADD: Zoom function

Showing 1 changed file with 60 additions and 30 deletions   Show diff stats
invesalius/data/viewer_slice.py
@@ -99,10 +99,13 @@ class Viewer(wx.Panel): @@ -99,10 +99,13 @@ class Viewer(wx.Panel):
99 self.ren = ren 99 self.ren = ren
100 100
101 def append_mode(self, mode): 101 def append_mode(self, mode):
  102 +
  103 + #TODO: Temporary
102 self.modes = [] 104 self.modes = []
  105 +
103 # Retrieve currently set modes 106 # Retrieve currently set modes
104 self.modes.append(mode) 107 self.modes.append(mode)
105 - 108 +
106 # All modes and bindings 109 # All modes and bindings
107 action = {'DEFAULT': { 110 action = {'DEFAULT': {
108 "MouseMoveEvent": self.OnCrossMove, 111 "MouseMoveEvent": self.OnCrossMove,
@@ -119,67 +122,90 @@ class Viewer(wx.Panel): @@ -119,67 +122,90 @@ class Viewer(wx.Panel):
119 'PAN':{ 122 'PAN':{
120 "MouseMoveEvent": self.OnPanMove, 123 "MouseMoveEvent": self.OnPanMove,
121 "LeftButtonPressEvent": self.OnPanClick, 124 "LeftButtonPressEvent": self.OnPanClick,
122 - "LeftButtonReleaseEvent": self.OnPanRelease 125 + "LeftButtonReleaseEvent": self.OnReleaseModes
123 }, 126 },
124 'SPIN':{ 127 'SPIN':{
125 "MouseMoveEvent": self.OnSpinMove, 128 "MouseMoveEvent": self.OnSpinMove,
126 "LeftButtonPressEvent": self.OnSpinClick, 129 "LeftButtonPressEvent": self.OnSpinClick,
127 - "LeftButtonReleaseEvent": self.OnSpinRelease 130 + "LeftButtonReleaseEvent": self.OnReleaseModes
  131 + },
  132 + 'ZOOM':{
  133 + "MouseMoveEvent": self.OnZoomMove,
  134 + "LeftButtonPressEvent": self.OnZoomClick,
  135 + "LeftButtonReleaseEvent": self.OnReleaseModes
128 } 136 }
129 } 137 }
130 138
131 # Bind method according to current mode 139 # Bind method according to current mode
132 - style = vtk.vtkInteractorStyleImage() 140 + if(mode == 'ZOOMSELECT'):
  141 + style = vtk.vtkInteractorStyleRubberBandZoom()
  142 + else:
  143 + style = vtk.vtkInteractorStyleImage()
  144 +
  145 + # Check all modes set by user
  146 + for mode in self.modes:
  147 + # Check each event available for each mode
  148 + for event in action[mode]:
  149 + # Bind event
  150 + style.AddObserver(event,
  151 + action[mode][event])
133 self.style = style 152 self.style = style
134 self.interactor.SetInteractorStyle(style) 153 self.interactor.SetInteractorStyle(style)
135 154
136 - # Check all modes set by user  
137 - for mode in self.modes:  
138 - # Check each event available for each mode  
139 - for event in action[mode]:  
140 - # Bind event  
141 - style.AddObserver(event,  
142 - action[mode][event])  
143 -  
144 def ChangeEditorMode(self, pubsub_evt): 155 def ChangeEditorMode(self, pubsub_evt):
145 self.append_mode('EDITOR') 156 self.append_mode('EDITOR')
146 - self.mouse_pressed = 0 157 + self.mouse_pressed = 0
147 self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_BLANK)) 158 self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_BLANK))
148 - 159 +
  160 + def ChangeSpinMode(self, pubsub_evt):
  161 + self.append_mode('SPIN')
  162 + self.mouse_pressed = 0
  163 + self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING))
  164 +
  165 + def ChangeZoomMode(self, pubsub_evt):
  166 + self.append_mode('ZOOM')
  167 + self.mouse_pressed = 0
  168 + self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZENS))
  169 +
149 def ChangePanMode(self, pubsub_evt): 170 def ChangePanMode(self, pubsub_evt):
150 self.append_mode('PAN') 171 self.append_mode('PAN')
151 - self.mouse_pressed = 0 172 + self.mouse_pressed = 0
152 self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING)) 173 self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING))
153 -  
154 - def OnPanRelease(self, evt, obj): 174 +
  175 + def ChangeZoomSelectMode(self, pubsub_evt):
  176 + self.append_mode('ZOOMSELECT')
155 self.mouse_pressed = 0 177 self.mouse_pressed = 0
156 178
157 def OnPanMove(self, evt, obj): 179 def OnPanMove(self, evt, obj):
158 if (self.mouse_pressed): 180 if (self.mouse_pressed):
159 evt.Pan() 181 evt.Pan()
160 evt.OnRightButtonDown() 182 evt.OnRightButtonDown()
161 - 183 +
162 def OnPanClick(self, evt, obj): 184 def OnPanClick(self, evt, obj):
163 self.mouse_pressed = 1 185 self.mouse_pressed = 1
164 evt.StartPan() 186 evt.StartPan()
165 187
166 - def ChangeSpinMode(self, pubsub_evt):  
167 - self.append_mode('SPIN')  
168 - self.mouse_pressed = 0  
169 - self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING))  
170 -  
171 - def OnSpinRelease(self, evt, obj):  
172 - self.mouse_pressed = 0 188 + def OnZoomMove(self, evt, obj):
  189 + if (self.mouse_pressed):
  190 + evt.Dolly()
  191 + evt.OnRightButtonDown()
  192 +
  193 + def OnZoomClick(self, evt, obj):
  194 + self.mouse_pressed = 1
  195 + evt.StartDolly()
173 196
174 def OnSpinMove(self, evt, obj): 197 def OnSpinMove(self, evt, obj):
175 if (self.mouse_pressed): 198 if (self.mouse_pressed):
176 evt.Spin() 199 evt.Spin()
177 evt.OnRightButtonDown() 200 evt.OnRightButtonDown()
178 - 201 +
179 def OnSpinClick(self, evt, obj): 202 def OnSpinClick(self, evt, obj):
180 self.mouse_pressed = 1 203 self.mouse_pressed = 1
181 evt.StartSpin() 204 evt.StartSpin()
182 - 205 +
  206 + def OnReleaseModes(self, evt, obj):
  207 + self.mouse_pressed = 0
  208 +
183 def OnEnterInteractor(self, obj, evt): 209 def OnEnterInteractor(self, obj, evt):
184 self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_BLANK)) 210 self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_BLANK))
185 211
@@ -417,11 +443,15 @@ class Viewer(wx.Panel): @@ -417,11 +443,15 @@ class Viewer(wx.Panel):
417 'Set edition operation') 443 'Set edition operation')
418 ps.Publisher().subscribe(self.ChangePanMode, 444 ps.Publisher().subscribe(self.ChangePanMode,
419 'Set Pan Mode') 445 'Set Pan Mode')
420 - ps.Publisher().subscribe(self.ChangeEditorMode, 446 + ps.Publisher().subscribe(self.ChangeEditorMode,
421 'Set Editor Mode') 447 'Set Editor Mode')
422 - ps.Publisher().subscribe(self.ChangeSpinMode, 448 + ps.Publisher().subscribe(self.ChangeSpinMode,
423 'Set Spin Mode') 449 'Set Spin Mode')
424 - 450 + ps.Publisher().subscribe(self.ChangeZoomMode,
  451 + 'Set Zoom Mode')
  452 + ps.Publisher().subscribe(self.ChangeZoomSelectMode,
  453 + 'Set Zoom Select Mode')
  454 +
425 def ChangeBrushOperation(self, pubsub_evt): 455 def ChangeBrushOperation(self, pubsub_evt):
426 print pubsub_evt.data 456 print pubsub_evt.data
427 self._brush_cursor_op = pubsub_evt.data 457 self._brush_cursor_op = pubsub_evt.data