Commit 985022bdb98e9eb7b095998c0a37ba70a8308095
1 parent
522f098d
Exists in
master
and in
68 other branches
ADD: Tool to change slices with left button
Showing
1 changed file
with
118 additions
and
81 deletions
Show diff stats
invesalius/data/viewer_slice.py
| ... | ... | @@ -47,7 +47,7 @@ class Viewer(wx.Panel): |
| 47 | 47 | self.slice_data_list = [] |
| 48 | 48 | # The layout from slice_data, the first is number of cols, the second |
| 49 | 49 | # is the number of rows |
| 50 | - self.layout = (2, 2) | |
| 50 | + self.layout = (1, 1) | |
| 51 | 51 | |
| 52 | 52 | self.__init_gui() |
| 53 | 53 | |
| ... | ... | @@ -138,7 +138,12 @@ class Viewer(wx.Panel): |
| 138 | 138 | }, |
| 139 | 139 | 'ZOOMSELECT':{ |
| 140 | 140 | "RightButtonReleaseEvent":self.OnUnZoom |
| 141 | - } | |
| 141 | + }, | |
| 142 | + 'CHANGESLICE':{ | |
| 143 | + "MouseMoveEvent": self.OnChangeSliceMove, | |
| 144 | + "LeftButtonPressEvent": self.OnChangeSliceClick, | |
| 145 | + "LeftButtonReleaseEvent": self.OnReleaseModes | |
| 146 | + } | |
| 142 | 147 | } |
| 143 | 148 | |
| 144 | 149 | # Bind method according to current mode |
| ... | ... | @@ -156,8 +161,108 @@ class Viewer(wx.Panel): |
| 156 | 161 | action[mode][event]) |
| 157 | 162 | self.style = style |
| 158 | 163 | self.interactor.SetInteractorStyle(style) |
| 164 | + | |
| 165 | + def EditorMode(self, pubsub_evt): | |
| 166 | + self.append_mode('EDITOR') | |
| 167 | + self.mouse_pressed = 0 | |
| 168 | + self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_BLANK)) | |
| 169 | + | |
| 170 | + def SpinMode(self, pubsub_evt): | |
| 171 | + self.append_mode('SPIN') | |
| 172 | + self.mouse_pressed = 0 | |
| 173 | + self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING)) | |
| 174 | + | |
| 175 | + def ZoomMode(self, pubsub_evt): | |
| 176 | + self.append_mode('ZOOM') | |
| 177 | + self.mouse_pressed = 0 | |
| 178 | + ICON_IMAGE = wx.Image("../icons/tool_zoom.png",wx.BITMAP_TYPE_PNG) | |
| 179 | + self.interactor.SetCursor(wx.CursorFromImage(ICON_IMAGE)) | |
| 180 | + | |
| 181 | + def PanMode(self, pubsub_evt): | |
| 182 | + self.append_mode('PAN') | |
| 183 | + self.mouse_pressed = 0 | |
| 184 | + self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING)) | |
| 185 | + | |
| 186 | + def ZoomSelectMode(self, pubsub_evt): | |
| 187 | + self.append_mode('ZOOMSELECT') | |
| 188 | + ICON_IMAGE = wx.Image("../icons/tool_zoom.png",wx.BITMAP_TYPE_PNG) | |
| 189 | + self.interactor.SetCursor(wx.CursorFromImage(ICON_IMAGE)) | |
| 190 | + | |
| 191 | + def ChangeSliceMode(self, pubsub_evt): | |
| 192 | + self.append_mode('CHANGESLICE') | |
| 193 | + self.mouse_pressed = 0 | |
| 194 | + self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZENS)) | |
| 195 | + | |
| 196 | + def OnChangeSliceMove(self, evt, obj): | |
| 197 | + | |
| 198 | + min = 0 | |
| 199 | + max = self.actor.GetSliceNumberMax() | |
| 200 | + | |
| 201 | + if (self.mouse_pressed): | |
| 202 | + position = self.interactor.GetLastEventPosition() | |
| 203 | + scroll_position = self.scroll.GetThumbPosition() | |
| 204 | + | |
| 205 | + if (position[1] > self.last_position) and\ | |
| 206 | + (self.acum_achange_slice > min): | |
| 207 | + self.acum_achange_slice -= 1 | |
| 208 | + elif(position[1] < self.last_position) and\ | |
| 209 | + (self.acum_achange_slice < max): | |
| 210 | + self.acum_achange_slice += 1 | |
| 211 | + self.last_position = position[1] | |
| 212 | + | |
| 213 | + self.scroll.SetThumbPosition(self.acum_achange_slice) | |
| 214 | + self.OnScrollBar() | |
| 215 | + | |
| 216 | + | |
| 217 | + def OnChangeSliceClick(self, evt, obj): | |
| 218 | + self.mouse_pressed = 1 | |
| 219 | + position = list(self.interactor.GetLastEventPosition()) | |
| 220 | + self.acum_achange_slice = self.scroll.GetThumbPosition() | |
| 221 | + self.last_position = position[1] | |
| 222 | + | |
| 223 | + def OnPanMove(self, evt, obj): | |
| 224 | + if (self.mouse_pressed): | |
| 225 | + evt.Pan() | |
| 226 | + evt.OnRightButtonDown() | |
| 227 | + | |
| 228 | + def OnPanClick(self, evt, obj): | |
| 229 | + self.mouse_pressed = 1 | |
| 230 | + evt.StartPan() | |
| 231 | + | |
| 232 | + def OnZoomMove(self, evt, obj): | |
| 233 | + if (self.mouse_pressed): | |
| 234 | + evt.Dolly() | |
| 235 | + evt.OnRightButtonDown() | |
| 236 | + | |
| 237 | + def OnZoomClick(self, evt, obj): | |
| 238 | + self.mouse_pressed = 1 | |
| 239 | + evt.StartDolly() | |
| 159 | 240 | |
| 241 | + def OnUnZoom(self, evt, obj): | |
| 242 | + self.ren.ResetCamera() | |
| 243 | + self.ren.ResetCameraClippingRange() | |
| 244 | + self.Reposition() | |
| 160 | 245 | |
| 246 | + def OnSpinMove(self, evt, obj): | |
| 247 | + if (self.mouse_pressed): | |
| 248 | + evt.Spin() | |
| 249 | + evt.OnRightButtonDown() | |
| 250 | + | |
| 251 | + def OnSpinClick(self, evt, obj): | |
| 252 | + self.mouse_pressed = 1 | |
| 253 | + evt.StartSpin() | |
| 254 | + | |
| 255 | + def OnReleaseModes(self, evt, obj): | |
| 256 | + self.mouse_pressed = 0 | |
| 257 | + | |
| 258 | + def OnEnterInteractor(self, obj, evt): | |
| 259 | + self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_BLANK)) | |
| 260 | + | |
| 261 | + def OnLeaveInteractor(self, obj, evt): | |
| 262 | + for slice_data in self.slice_data_list: | |
| 263 | + slice_data.cursor.Show(0) | |
| 264 | + self.interactor.Render() | |
| 265 | + | |
| 161 | 266 | def Reposition(self): |
| 162 | 267 | """ |
| 163 | 268 | Based on code of method Zoom in the |
| ... | ... | @@ -224,80 +329,7 @@ class Viewer(wx.Panel): |
| 224 | 329 | cam.Zoom(size[1] / height) |
| 225 | 330 | |
| 226 | 331 | self.interactor.Render() |
| 227 | - | |
| 228 | - | |
| 229 | - def ChangeEditorMode(self, pubsub_evt): | |
| 230 | - self.append_mode('EDITOR') | |
| 231 | - self.mouse_pressed = 0 | |
| 232 | - self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_BLANK)) | |
| 233 | - | |
| 234 | - def ChangeSpinMode(self, pubsub_evt): | |
| 235 | - self.append_mode('SPIN') | |
| 236 | - self.mouse_pressed = 0 | |
| 237 | - self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING)) | |
| 238 | 332 | |
| 239 | - def ChangeZoomMode(self, pubsub_evt): | |
| 240 | - self.append_mode('ZOOM') | |
| 241 | - print "Zoom" | |
| 242 | - self.mouse_pressed = 0 | |
| 243 | - ICON_IMAGE = wx.Image("../icons/tool_zoom.png",wx.BITMAP_TYPE_PNG) | |
| 244 | - ICON_IMAGE.SetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_X, 0) | |
| 245 | - ICON_IMAGE.SetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_Y, 0) | |
| 246 | - wx.SetCursor(wx.CursorFromImage(ICON_IMAGE)) | |
| 247 | - | |
| 248 | - def ChangePanMode(self, pubsub_evt): | |
| 249 | - self.append_mode('PAN') | |
| 250 | - self.mouse_pressed = 0 | |
| 251 | - self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING)) | |
| 252 | - | |
| 253 | - def ChangeZoomSelectMode(self, pubsub_evt): | |
| 254 | - self.append_mode('ZOOMSELECT') | |
| 255 | - ICON_IMAGE = wx.Image("../icons/tool_zoom.png",wx.BITMAP_TYPE_PNG) | |
| 256 | - wx.SetCursor(wx.CursorFromImage(ICON_IMAGE)) | |
| 257 | - | |
| 258 | - def OnPanMove(self, evt, obj): | |
| 259 | - if (self.mouse_pressed): | |
| 260 | - evt.Pan() | |
| 261 | - evt.OnRightButtonDown() | |
| 262 | - | |
| 263 | - def OnPanClick(self, evt, obj): | |
| 264 | - self.mouse_pressed = 1 | |
| 265 | - evt.StartPan() | |
| 266 | - | |
| 267 | - def OnZoomMove(self, evt, obj): | |
| 268 | - if (self.mouse_pressed): | |
| 269 | - evt.Dolly() | |
| 270 | - evt.OnRightButtonDown() | |
| 271 | - | |
| 272 | - def OnZoomClick(self, evt, obj): | |
| 273 | - self.mouse_pressed = 1 | |
| 274 | - evt.StartDolly() | |
| 275 | - | |
| 276 | - def OnUnZoom(self, evt, obj): | |
| 277 | - self.ren.ResetCamera() | |
| 278 | - self.ren.ResetCameraClippingRange() | |
| 279 | - self.Reposition() | |
| 280 | - | |
| 281 | - def OnSpinMove(self, evt, obj): | |
| 282 | - if (self.mouse_pressed): | |
| 283 | - evt.Spin() | |
| 284 | - evt.OnRightButtonDown() | |
| 285 | - | |
| 286 | - def OnSpinClick(self, evt, obj): | |
| 287 | - self.mouse_pressed = 1 | |
| 288 | - evt.StartSpin() | |
| 289 | - | |
| 290 | - def OnReleaseModes(self, evt, obj): | |
| 291 | - self.mouse_pressed = 0 | |
| 292 | - | |
| 293 | - def OnEnterInteractor(self, obj, evt): | |
| 294 | - self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_BLANK)) | |
| 295 | - | |
| 296 | - def OnLeaveInteractor(self, obj, evt): | |
| 297 | - for slice_data in self.slice_data_list: | |
| 298 | - slice_data.cursor.Show(0) | |
| 299 | - self.interactor.Render() | |
| 300 | - | |
| 301 | 333 | def ChangeBrushSize(self, pubsub_evt): |
| 302 | 334 | size = pubsub_evt.data |
| 303 | 335 | self._brush_cursor_size = size |
| ... | ... | @@ -526,17 +558,22 @@ class Viewer(wx.Panel): |
| 526 | 558 | 'Set brush format') |
| 527 | 559 | ps.Publisher().subscribe(self.ChangeBrushOperation, |
| 528 | 560 | 'Set edition operation') |
| 529 | - ps.Publisher().subscribe(self.ChangePanMode, | |
| 561 | + ps.Publisher().subscribe(self.PanMode, | |
| 530 | 562 | 'Set Pan Mode') |
| 531 | - ps.Publisher().subscribe(self.ChangeEditorMode, | |
| 563 | + ps.Publisher().subscribe(self.EditorMode, | |
| 532 | 564 | 'Set Editor Mode') |
| 533 | - ps.Publisher().subscribe(self.ChangeSpinMode, | |
| 565 | + ps.Publisher().subscribe(self.SpinMode, | |
| 534 | 566 | 'Set Spin Mode') |
| 535 | - ps.Publisher().subscribe(self.ChangeZoomMode, | |
| 567 | + ps.Publisher().subscribe(self.ZoomMode, | |
| 536 | 568 | 'Set Zoom Mode') |
| 537 | - ps.Publisher().subscribe(self.ChangeZoomSelectMode, | |
| 569 | + ps.Publisher().subscribe(self.ZoomSelectMode, | |
| 538 | 570 | 'Set Zoom Select Mode') |
| 539 | - | |
| 571 | + ps.Publisher().subscribe(self.ZoomSelectMode, | |
| 572 | + 'Set Zoom Select Mode') | |
| 573 | + | |
| 574 | + ps.Publisher().subscribe(self.ChangeSliceMode, | |
| 575 | + 'Set Change Slice Mode') | |
| 576 | + | |
| 540 | 577 | def ChangeBrushOperation(self, pubsub_evt): |
| 541 | 578 | print pubsub_evt.data |
| 542 | 579 | self._brush_cursor_op = pubsub_evt.data | ... | ... |