Commit 4f8bc05fa16ee053287be6bfa5bbb7797b00935a
1 parent
897ed709
Exists in
master
and in
68 other branches
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 | 99 | self.ren = ren |
100 | 100 | |
101 | 101 | def append_mode(self, mode): |
102 | + | |
103 | + #TODO: Temporary | |
102 | 104 | self.modes = [] |
105 | + | |
103 | 106 | # Retrieve currently set modes |
104 | 107 | self.modes.append(mode) |
105 | - | |
108 | + | |
106 | 109 | # All modes and bindings |
107 | 110 | action = {'DEFAULT': { |
108 | 111 | "MouseMoveEvent": self.OnCrossMove, |
... | ... | @@ -119,67 +122,90 @@ class Viewer(wx.Panel): |
119 | 122 | 'PAN':{ |
120 | 123 | "MouseMoveEvent": self.OnPanMove, |
121 | 124 | "LeftButtonPressEvent": self.OnPanClick, |
122 | - "LeftButtonReleaseEvent": self.OnPanRelease | |
125 | + "LeftButtonReleaseEvent": self.OnReleaseModes | |
123 | 126 | }, |
124 | 127 | 'SPIN':{ |
125 | 128 | "MouseMoveEvent": self.OnSpinMove, |
126 | 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 | 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 | 152 | self.style = style |
134 | 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 | 155 | def ChangeEditorMode(self, pubsub_evt): |
145 | 156 | self.append_mode('EDITOR') |
146 | - self.mouse_pressed = 0 | |
157 | + self.mouse_pressed = 0 | |
147 | 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 | 170 | def ChangePanMode(self, pubsub_evt): |
150 | 171 | self.append_mode('PAN') |
151 | - self.mouse_pressed = 0 | |
172 | + self.mouse_pressed = 0 | |
152 | 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 | 177 | self.mouse_pressed = 0 |
156 | 178 | |
157 | 179 | def OnPanMove(self, evt, obj): |
158 | 180 | if (self.mouse_pressed): |
159 | 181 | evt.Pan() |
160 | 182 | evt.OnRightButtonDown() |
161 | - | |
183 | + | |
162 | 184 | def OnPanClick(self, evt, obj): |
163 | 185 | self.mouse_pressed = 1 |
164 | 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 | 197 | def OnSpinMove(self, evt, obj): |
175 | 198 | if (self.mouse_pressed): |
176 | 199 | evt.Spin() |
177 | 200 | evt.OnRightButtonDown() |
178 | - | |
201 | + | |
179 | 202 | def OnSpinClick(self, evt, obj): |
180 | 203 | self.mouse_pressed = 1 |
181 | 204 | evt.StartSpin() |
182 | - | |
205 | + | |
206 | + def OnReleaseModes(self, evt, obj): | |
207 | + self.mouse_pressed = 0 | |
208 | + | |
183 | 209 | def OnEnterInteractor(self, obj, evt): |
184 | 210 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_BLANK)) |
185 | 211 | |
... | ... | @@ -417,11 +443,15 @@ class Viewer(wx.Panel): |
417 | 443 | 'Set edition operation') |
418 | 444 | ps.Publisher().subscribe(self.ChangePanMode, |
419 | 445 | 'Set Pan Mode') |
420 | - ps.Publisher().subscribe(self.ChangeEditorMode, | |
446 | + ps.Publisher().subscribe(self.ChangeEditorMode, | |
421 | 447 | 'Set Editor Mode') |
422 | - ps.Publisher().subscribe(self.ChangeSpinMode, | |
448 | + ps.Publisher().subscribe(self.ChangeSpinMode, | |
423 | 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 | 455 | def ChangeBrushOperation(self, pubsub_evt): |
426 | 456 | print pubsub_evt.data |
427 | 457 | self._brush_cursor_op = pubsub_evt.data | ... | ... |