Commit 8ccb6b70541272b330344f90d0892f5a96c1cd4f

Authored by Thiago Franco de Moraes
1 parent 7af56b45

Created a editorconfig class to store config from editor style

invesalius/data/styles.py
... ... @@ -555,6 +555,14 @@ class ChangeSliceInteractorStyle(DefaultInteractorStyle):
555 555 self.last_position = position[1]
556 556  
557 557  
  558 +class EditorConfig(object):
  559 + __metaclass__= utils.Singleton
  560 + def __init__(self):
  561 + self.operation = const.BRUSH_THRESH
  562 + self.cursor_type = const.BRUSH_CIRCLE
  563 + self.cursor_size = const.BRUSH_SIZE
  564 +
  565 +
558 566 class EditorInteractorStyle(DefaultInteractorStyle):
559 567 def __init__(self, viewer):
560 568 DefaultInteractorStyle.__init__(self, viewer)
... ... @@ -562,6 +570,8 @@ class EditorInteractorStyle(DefaultInteractorStyle):
562 570 self.viewer = viewer
563 571 self.orientation = self.viewer.orientation
564 572  
  573 + self.config = EditorConfig()
  574 +
565 575 self.picker = vtk.vtkWorldPointPicker()
566 576  
567 577 self.AddObserver("EnterEvent", self.OnEnterInteractor)
... ... @@ -576,6 +586,48 @@ class EditorInteractorStyle(DefaultInteractorStyle):
576 586 self.AddObserver("MouseWheelForwardEvent",self.EOnScrollForward)
577 587 self.AddObserver("MouseWheelBackwardEvent", self.EOnScrollBackward)
578 588  
  589 + Publisher.subscribe(self.set_bsize, 'Set edition brush size')
  590 + Publisher.subscribe(self.set_bformat, 'Set brush format')
  591 + Publisher.subscribe(self.set_boperation, 'Set edition operation')
  592 +
  593 + self._set_cursor()
  594 +
  595 + def CleanUp(self):
  596 + Publisher.unsubscribe(self.set_bsize, 'Set edition brush size')
  597 + Publisher.unsubscribe(self.set_bformat, 'Set brush format')
  598 + Publisher.unsubscribe(self.set_boperation, 'Set edition operation')
  599 +
  600 + def set_bsize(self, pubsub_evt):
  601 + size = pubsub_evt.data
  602 + self.config.cursor_size = size
  603 + self.viewer.slice_data.cursor.SetSize(size)
  604 +
  605 + def set_bformat(self, pubsub_evt):
  606 + self.config.cursor_type = pubsub_evt.data
  607 + self._set_cursor()
  608 +
  609 + def set_boperation(self, pubsub_evt):
  610 + self.config.operation = pubsub_evt.data
  611 +
  612 + def _set_cursor(self):
  613 + if self.config.cursor_type == const.BRUSH_SQUARE:
  614 + cursor = ca.CursorRectangle()
  615 + elif self.config.cursor_type == const.BRUSH_CIRCLE:
  616 + cursor = ca.CursorCircle()
  617 +
  618 + cursor.SetOrientation(self.orientation)
  619 + n = self.viewer.slice_data.number
  620 + coordinates = {"SAGITAL": [n, 0, 0],
  621 + "CORONAL": [0, n, 0],
  622 + "AXIAL": [0, 0, n]}
  623 + cursor.SetPosition(coordinates[self.orientation])
  624 + spacing = self.viewer.slice_.spacing
  625 + cursor.SetSpacing(spacing)
  626 + cursor.SetColour(self.viewer._brush_cursor_colour)
  627 + cursor.SetSize(self.config.cursor_size)
  628 + self.viewer.slice_data.SetCursor(cursor)
  629 + self.viewer.interactor.Render()
  630 +
579 631 def OnEnterInteractor(self, obj, evt):
580 632 if (self.viewer.slice_.buffer_slices[self.orientation].mask is None):
581 633 return
... ... @@ -592,11 +644,10 @@ class EditorInteractorStyle(DefaultInteractorStyle):
592 644 if (self.viewer.slice_.buffer_slices[self.orientation].mask is None):
593 645 return
594 646  
595   -
596 647 viewer = self.viewer
597 648 iren = viewer.interactor
598 649  
599   - operation = viewer._brush_cursor_op
  650 + operation = self.config.operation
600 651 if operation == const.BRUSH_THRESH:
601 652 if iren.GetControlKey():
602 653 if iren.GetShiftKey():
... ... @@ -658,7 +709,7 @@ class EditorInteractorStyle(DefaultInteractorStyle):
658 709 render = iren.FindPokedRenderer(mouse_x, mouse_y)
659 710 slice_data = viewer.get_slice_data(render)
660 711  
661   - operation = viewer._brush_cursor_op
  712 + operation = self.config.operation
662 713 if operation == const.BRUSH_THRESH:
663 714 if iren.GetControlKey():
664 715 if iren.GetShiftKey():
... ...
invesalius/data/viewer_slice.py
... ... @@ -525,12 +525,6 @@ class Viewer(wx.Panel):
525 525 ren.GetActiveCamera().Zoom(1.0)
526 526 self.interactor.Render()
527 527  
528   - def ChangeBrushSize(self, pubsub_evt):
529   - size = pubsub_evt.data
530   - self._brush_cursor_size = size
531   - #for slice_data in self.slice_data_list:
532   - self.slice_data.cursor.SetSize(size)
533   -
534 528 def ChangeBrushColour(self, pubsub_evt):
535 529 vtk_colour = pubsub_evt.data[3]
536 530 self._brush_cursor_colour = vtk_colour
... ... @@ -545,27 +539,6 @@ class Viewer(wx.Panel):
545 539 if self.slice_data.cursor:
546 540 self.slice_data.cursor.SetColour(colour_vtk)
547 541  
548   - def ChangeBrushActor(self, pubsub_evt):
549   - brush_type = pubsub_evt.data
550   - slice_data = self.slice_data
551   - self._brush_cursor_type = brush_type
552   -
553   - if brush_type == const.BRUSH_SQUARE:
554   - cursor = ca.CursorRectangle()
555   - elif brush_type == const.BRUSH_CIRCLE:
556   - cursor = ca.CursorCircle()
557   -
558   - cursor.SetOrientation(self.orientation)
559   - coordinates = {"SAGITAL": [slice_data.number, 0, 0],
560   - "CORONAL": [0, slice_data.number, 0],
561   - "AXIAL": [0, 0, slice_data.number]}
562   - cursor.SetPosition(coordinates[self.orientation])
563   - cursor.SetSpacing(self.slice_.spacing)
564   - cursor.SetColour(self._brush_cursor_colour)
565   - cursor.SetSize(self._brush_cursor_size)
566   - slice_data.SetCursor(cursor)
567   - self.interactor.Render()
568   -
569 542 def Navigation(self, pubsub_evt):
570 543 # Get point from base change
571 544 x, y, z = pubsub_evt.data
... ... @@ -700,14 +673,8 @@ class Viewer(wx.Panel):
700 673 Publisher.subscribe(self.Navigation,
701 674 'Co-registered Points')
702 675 ###
703   - Publisher.subscribe(self.ChangeBrushSize,
704   - 'Set edition brush size')
705 676 Publisher.subscribe(self.ChangeBrushColour,
706 677 'Add mask')
707   - Publisher.subscribe(self.ChangeBrushActor,
708   - 'Set brush format')
709   - Publisher.subscribe(self.ChangeBrushOperation,
710   - 'Set edition operation')
711 678  
712 679 Publisher.subscribe(self.UpdateWindowLevelValue,
713 680 'Update window level value')
... ... @@ -833,9 +800,6 @@ class Viewer(wx.Panel):
833 800 if (state != const.SLICE_STATE_EDITOR):
834 801 Publisher.sendMessage('Set interactor default cursor')
835 802  
836   - def ChangeBrushOperation(self, pubsub_evt):
837   - self._brush_cursor_op = pubsub_evt.data
838   -
839 803 def __bind_events_wx(self):
840 804 self.scroll.Bind(wx.EVT_SCROLL, self.OnScrollBar)
841 805 self.scroll.Bind(wx.EVT_SCROLL_THUMBTRACK, self.OnScrollBarRelease)
... ...