diff --git a/invesalius/data/styles.py b/invesalius/data/styles.py index 1698e2f..3091d91 100644 --- a/invesalius/data/styles.py +++ b/invesalius/data/styles.py @@ -555,6 +555,14 @@ class ChangeSliceInteractorStyle(DefaultInteractorStyle): self.last_position = position[1] +class EditorConfig(object): + __metaclass__= utils.Singleton + def __init__(self): + self.operation = const.BRUSH_THRESH + self.cursor_type = const.BRUSH_CIRCLE + self.cursor_size = const.BRUSH_SIZE + + class EditorInteractorStyle(DefaultInteractorStyle): def __init__(self, viewer): DefaultInteractorStyle.__init__(self, viewer) @@ -562,6 +570,8 @@ class EditorInteractorStyle(DefaultInteractorStyle): self.viewer = viewer self.orientation = self.viewer.orientation + self.config = EditorConfig() + self.picker = vtk.vtkWorldPointPicker() self.AddObserver("EnterEvent", self.OnEnterInteractor) @@ -576,6 +586,48 @@ class EditorInteractorStyle(DefaultInteractorStyle): self.AddObserver("MouseWheelForwardEvent",self.EOnScrollForward) self.AddObserver("MouseWheelBackwardEvent", self.EOnScrollBackward) + Publisher.subscribe(self.set_bsize, 'Set edition brush size') + Publisher.subscribe(self.set_bformat, 'Set brush format') + Publisher.subscribe(self.set_boperation, 'Set edition operation') + + self._set_cursor() + + def CleanUp(self): + Publisher.unsubscribe(self.set_bsize, 'Set edition brush size') + Publisher.unsubscribe(self.set_bformat, 'Set brush format') + Publisher.unsubscribe(self.set_boperation, 'Set edition operation') + + def set_bsize(self, pubsub_evt): + size = pubsub_evt.data + self.config.cursor_size = size + self.viewer.slice_data.cursor.SetSize(size) + + def set_bformat(self, pubsub_evt): + self.config.cursor_type = pubsub_evt.data + self._set_cursor() + + def set_boperation(self, pubsub_evt): + self.config.operation = pubsub_evt.data + + def _set_cursor(self): + if self.config.cursor_type == const.BRUSH_SQUARE: + cursor = ca.CursorRectangle() + elif self.config.cursor_type == const.BRUSH_CIRCLE: + cursor = ca.CursorCircle() + + cursor.SetOrientation(self.orientation) + n = self.viewer.slice_data.number + coordinates = {"SAGITAL": [n, 0, 0], + "CORONAL": [0, n, 0], + "AXIAL": [0, 0, n]} + cursor.SetPosition(coordinates[self.orientation]) + spacing = self.viewer.slice_.spacing + cursor.SetSpacing(spacing) + cursor.SetColour(self.viewer._brush_cursor_colour) + cursor.SetSize(self.config.cursor_size) + self.viewer.slice_data.SetCursor(cursor) + self.viewer.interactor.Render() + def OnEnterInteractor(self, obj, evt): if (self.viewer.slice_.buffer_slices[self.orientation].mask is None): return @@ -592,11 +644,10 @@ class EditorInteractorStyle(DefaultInteractorStyle): if (self.viewer.slice_.buffer_slices[self.orientation].mask is None): return - viewer = self.viewer iren = viewer.interactor - operation = viewer._brush_cursor_op + operation = self.config.operation if operation == const.BRUSH_THRESH: if iren.GetControlKey(): if iren.GetShiftKey(): @@ -658,7 +709,7 @@ class EditorInteractorStyle(DefaultInteractorStyle): render = iren.FindPokedRenderer(mouse_x, mouse_y) slice_data = viewer.get_slice_data(render) - operation = viewer._brush_cursor_op + operation = self.config.operation if operation == const.BRUSH_THRESH: if iren.GetControlKey(): if iren.GetShiftKey(): diff --git a/invesalius/data/viewer_slice.py b/invesalius/data/viewer_slice.py index 6f5497a..d438ae6 100755 --- a/invesalius/data/viewer_slice.py +++ b/invesalius/data/viewer_slice.py @@ -525,12 +525,6 @@ class Viewer(wx.Panel): ren.GetActiveCamera().Zoom(1.0) self.interactor.Render() - def ChangeBrushSize(self, pubsub_evt): - size = pubsub_evt.data - self._brush_cursor_size = size - #for slice_data in self.slice_data_list: - self.slice_data.cursor.SetSize(size) - def ChangeBrushColour(self, pubsub_evt): vtk_colour = pubsub_evt.data[3] self._brush_cursor_colour = vtk_colour @@ -545,27 +539,6 @@ class Viewer(wx.Panel): if self.slice_data.cursor: self.slice_data.cursor.SetColour(colour_vtk) - def ChangeBrushActor(self, pubsub_evt): - brush_type = pubsub_evt.data - slice_data = self.slice_data - self._brush_cursor_type = brush_type - - if brush_type == const.BRUSH_SQUARE: - cursor = ca.CursorRectangle() - elif brush_type == const.BRUSH_CIRCLE: - cursor = ca.CursorCircle() - - cursor.SetOrientation(self.orientation) - coordinates = {"SAGITAL": [slice_data.number, 0, 0], - "CORONAL": [0, slice_data.number, 0], - "AXIAL": [0, 0, slice_data.number]} - cursor.SetPosition(coordinates[self.orientation]) - cursor.SetSpacing(self.slice_.spacing) - cursor.SetColour(self._brush_cursor_colour) - cursor.SetSize(self._brush_cursor_size) - slice_data.SetCursor(cursor) - self.interactor.Render() - def Navigation(self, pubsub_evt): # Get point from base change x, y, z = pubsub_evt.data @@ -700,14 +673,8 @@ class Viewer(wx.Panel): Publisher.subscribe(self.Navigation, 'Co-registered Points') ### - Publisher.subscribe(self.ChangeBrushSize, - 'Set edition brush size') Publisher.subscribe(self.ChangeBrushColour, 'Add mask') - Publisher.subscribe(self.ChangeBrushActor, - 'Set brush format') - Publisher.subscribe(self.ChangeBrushOperation, - 'Set edition operation') Publisher.subscribe(self.UpdateWindowLevelValue, 'Update window level value') @@ -833,9 +800,6 @@ class Viewer(wx.Panel): if (state != const.SLICE_STATE_EDITOR): Publisher.sendMessage('Set interactor default cursor') - def ChangeBrushOperation(self, pubsub_evt): - self._brush_cursor_op = pubsub_evt.data - def __bind_events_wx(self): self.scroll.Bind(wx.EVT_SCROLL, self.OnScrollBar) self.scroll.Bind(wx.EVT_SCROLL_THUMBTRACK, self.OnScrollBarRelease) -- libgit2 0.21.2