Commit 5c9a305f4c9821327fb47594a4833f0def899be8
1 parent
b557c298
Exists in
interactor_style
Created a protocol to setup and cleanup when a style is setted
Showing
2 changed files
with
46 additions
and
81 deletions
Show diff stats
invesalius/data/styles.py
| ... | ... | @@ -96,6 +96,7 @@ class CrossInteractorStyle(DefaultInteractorStyle): |
| 96 | 96 | def __init__(self, viewer): |
| 97 | 97 | DefaultInteractorStyle.__init__(self, viewer) |
| 98 | 98 | |
| 99 | + self.viewer = viewer | |
| 99 | 100 | self.orientation = viewer.orientation |
| 100 | 101 | self.slice_actor = viewer.slice_data.actor |
| 101 | 102 | self.slice_data = viewer.slice_data |
| ... | ... | @@ -106,6 +107,12 @@ class CrossInteractorStyle(DefaultInteractorStyle): |
| 106 | 107 | self.AddObserver("LeftButtonPressEvent", self.OnCrossMouseClick) |
| 107 | 108 | self.AddObserver("LeftButtonReleaseEvent", self.OnReleaseLeftButton) |
| 108 | 109 | |
| 110 | + def SetUp(self): | |
| 111 | + self.viewer._set_cross_visibility(1) | |
| 112 | + | |
| 113 | + def CleanUp(self): | |
| 114 | + self.viewer._set_cross_visibility(0) | |
| 115 | + | |
| 109 | 116 | def OnCrossMouseClick(self, obj, evt): |
| 110 | 117 | iren = obj.GetInteractor() |
| 111 | 118 | self.ChangeCrossPosition(iren) |
| ... | ... | @@ -214,6 +221,14 @@ class WWWLInteractorStyle(DefaultInteractorStyle): |
| 214 | 221 | self.AddObserver("MouseMoveEvent", self.OnWindowLevelMove) |
| 215 | 222 | self.AddObserver("LeftButtonPressEvent", self.OnWindowLevelClick) |
| 216 | 223 | |
| 224 | + def SetUp(self): | |
| 225 | + self.viewer.on_wl = True | |
| 226 | + self.viewer.wl_text.Show() | |
| 227 | + | |
| 228 | + def CleanUp(self): | |
| 229 | + self.viewer.on_wl = False | |
| 230 | + self.viewer.wl_text.Hide() | |
| 231 | + | |
| 217 | 232 | def OnWindowLevelMove(self, obj, evt): |
| 218 | 233 | if (self.left_pressed): |
| 219 | 234 | iren = obj.GetInteractor() |
| ... | ... | @@ -584,3 +599,20 @@ class EditorInteractorStyle(DefaultInteractorStyle): |
| 584 | 599 | elif bounds[4] == bounds[5]: |
| 585 | 600 | z = bounds[4] |
| 586 | 601 | return x, y, z |
| 602 | + | |
| 603 | + | |
| 604 | +def get_style(style): | |
| 605 | + STYLES = { | |
| 606 | + const.STATE_DEFAULT: DefaultInteractorStyle, | |
| 607 | + const.SLICE_STATE_CROSS: CrossInteractorStyle, | |
| 608 | + const.STATE_WL: WWWLInteractorStyle, | |
| 609 | + const.STATE_MEASURE_DISTANCE: LinearMeasureInteractorStyle, | |
| 610 | + const.STATE_MEASURE_ANGLE: AngularMeasureInteractorStyle, | |
| 611 | + const.STATE_PAN: PanMoveInteractorStyle, | |
| 612 | + const.STATE_SPIN: SpinInteractorStyle, | |
| 613 | + const.STATE_ZOOM: ZoomInteractorStyle, | |
| 614 | + const.STATE_ZOOM_SL: ZoomSLInteractorStyle, | |
| 615 | + const.SLICE_STATE_SCROLL: ChangeSliceInteractorStyle, | |
| 616 | + const.SLICE_STATE_EDITOR: EditorInteractorStyle, | |
| 617 | + } | |
| 618 | + return STYLES[style] | ... | ... |
invesalius/data/viewer_slice.py
| ... | ... | @@ -67,6 +67,7 @@ class Viewer(wx.Panel): |
| 67 | 67 | self.spined_image = False #Use to control to spin |
| 68 | 68 | self.paned_image = False |
| 69 | 69 | |
| 70 | + self.style = None | |
| 70 | 71 | self.last_position_mouse_move = () |
| 71 | 72 | self.state = const.STATE_DEFAULT |
| 72 | 73 | |
| ... | ... | @@ -175,89 +176,21 @@ class Viewer(wx.Panel): |
| 175 | 176 | interactor.SetInteractorStyle(style) |
| 176 | 177 | |
| 177 | 178 | def SetInteractorStyle(self, state): |
| 178 | - self.__set_cross_visibility(0) | |
| 179 | - self.on_wl = False | |
| 180 | - self.wl_text.Hide() | |
| 181 | - self.state = state | |
| 182 | - | |
| 183 | - if state == const.STATE_DEFAULT: | |
| 184 | - style = styles.DefaultInteractorStyle(self) | |
| 185 | - self.style = style | |
| 186 | - self.interactor.SetInteractorStyle(style) | |
| 187 | - self.interactor.Render() | |
| 188 | - | |
| 189 | - elif state == const.SLICE_STATE_CROSS: | |
| 190 | - style = styles.CrossInteractorStyle(self) | |
| 191 | - self.style = style | |
| 192 | - self.interactor.SetInteractorStyle(style) | |
| 193 | - | |
| 194 | - self.__set_cross_visibility(1) | |
| 195 | - Publisher.sendMessage('Activate ball reference') | |
| 196 | - | |
| 197 | - self.interactor.Render() | |
| 198 | - | |
| 199 | - elif state == const.STATE_WL: | |
| 200 | - self.on_wl = True | |
| 201 | - self.wl_text.Show() | |
| 202 | - | |
| 203 | - style = styles.WWWLInteractorStyle(self) | |
| 204 | - self.style = style | |
| 205 | - self.interactor.SetInteractorStyle(style) | |
| 206 | - self.interactor.Render() | |
| 207 | - | |
| 208 | - elif state == const.STATE_MEASURE_DISTANCE: | |
| 209 | - style = styles.LinearMeasureInteractorStyle(self) | |
| 210 | - self.style = style | |
| 211 | - self.interactor.SetInteractorStyle(style) | |
| 212 | - self.interactor.Render() | |
| 213 | - | |
| 214 | - elif state == const.STATE_MEASURE_ANGLE: | |
| 215 | - style = styles.AngularMeasureInteractorStyle(self) | |
| 216 | - self.style = style | |
| 217 | - self.interactor.SetInteractorStyle(style) | |
| 218 | - self.interactor.Render() | |
| 179 | + cleanup = getattr(self.style, 'CleanUp', None) | |
| 180 | + if cleanup: | |
| 181 | + self.style.CleanUp() | |
| 219 | 182 | |
| 220 | - elif state == const.STATE_PAN: | |
| 221 | - style = styles.PanMoveInteractorStyle(self) | |
| 183 | + style = styles.get_style(state)(self) | |
| 222 | 184 | |
| 223 | - self.style = style | |
| 224 | - self.interactor.SetInteractorStyle(style) | |
| 225 | - self.interactor.Render() | |
| 185 | + setup = getattr(style, 'SetUp', None) | |
| 186 | + if setup: | |
| 187 | + style.SetUp() | |
| 226 | 188 | |
| 227 | - elif state == const.STATE_SPIN: | |
| 228 | - style = styles.SpinInteractorStyle(self) | |
| 229 | - | |
| 230 | - self.style = style | |
| 231 | - self.interactor.SetInteractorStyle(style) | |
| 232 | - self.interactor.Render() | |
| 233 | - | |
| 234 | - elif state == const.STATE_ZOOM: | |
| 235 | - style = styles.ZoomInteractorStyle(self) | |
| 236 | - | |
| 237 | - self.style = style | |
| 238 | - self.interactor.SetInteractorStyle(style) | |
| 239 | - self.interactor.Render() | |
| 240 | - | |
| 241 | - elif state == const.STATE_ZOOM_SL: | |
| 242 | - style = styles.ZoomSLInteractorStyle(self) | |
| 243 | - | |
| 244 | - self.style = style | |
| 245 | - self.interactor.SetInteractorStyle(style) | |
| 246 | - self.interactor.Render() | |
| 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 | - | |
| 255 | - elif state == const.SLICE_STATE_EDITOR: | |
| 256 | - style = styles.EditorInteractorStyle(self) | |
| 189 | + self.style = style | |
| 190 | + self.interactor.SetInteractorStyle(style) | |
| 191 | + self.interactor.Render() | |
| 257 | 192 | |
| 258 | - self.style = style | |
| 259 | - self.interactor.SetInteractorStyle(style) | |
| 260 | - self.interactor.Render() | |
| 193 | + self.state = state | |
| 261 | 194 | |
| 262 | 195 | def UpdateWindowLevelValue(self, pubsub_evt): |
| 263 | 196 | window, level = pubsub_evt.data |
| ... | ... | @@ -664,7 +597,7 @@ class Viewer(wx.Panel): |
| 664 | 597 | Publisher.subscribe(self.UpdateWindowLevelValue,\ |
| 665 | 598 | 'Update window level value') |
| 666 | 599 | |
| 667 | - #Publisher.subscribe(self.__set_cross_visibility,\ | |
| 600 | + #Publisher.subscribe(self._set_cross_visibility,\ | |
| 668 | 601 | # 'Set cross visibility') |
| 669 | 602 | ### |
| 670 | 603 | Publisher.subscribe(self.__set_layout, |
| ... | ... | @@ -931,7 +864,7 @@ class Viewer(wx.Panel): |
| 931 | 864 | pos = pubsub_evt.data |
| 932 | 865 | self.cross.SetFocalPoint(pos) |
| 933 | 866 | |
| 934 | - def __set_cross_visibility(self, visibility): | |
| 867 | + def _set_cross_visibility(self, visibility): | |
| 935 | 868 | self.cross_actor.SetVisibility(visibility) |
| 936 | 869 | |
| 937 | 870 | def _set_editor_cursor_visibility(self, visibility): | ... | ... |