Commit 159f813aab3f1ef69e07347b4608c549198a19e5

Authored by tatiana
1 parent 0c6c3676

ENH: Inserted multiple modes option inside slice viewer, for user style selection

invesalius/data/viewer_slice.py
... ... @@ -28,26 +28,25 @@ import constants as const
28 28 import project
29 29  
30 30 class Viewer(wx.Panel):
31   -
  31 +
32 32 def __init__(self, prnt, orientation='AXIAL'):
33 33 wx.Panel.__init__(self, prnt, size=wx.Size(320, 300))
34 34  
35 35 colour = [255*c for c in const.ORIENTATION_COLOUR[orientation]]
36 36 self.SetBackgroundColour(colour)
37 37  
  38 + # Interactor aditional style
  39 + self.modes = []
  40 + self.mouse_pressed = 0
  41 +
38 42 self.__init_gui()
39 43  
40 44 self.orientation = orientation
41 45 self.slice_number = 0
42   -
43   - # Interactor aditional style
44   - self.mode = 'DEFAULT'
45   - self.mouse_pressed = 0
46 46  
47 47 # VTK pipeline and actors
48 48 self.__config_interactor()
49 49 self.pick = vtk.vtkCellPicker()
50   - #self.cursor =
51 50  
52 51 self.__bind_events()
53 52 self.__bind_events_wx()
... ... @@ -75,23 +74,22 @@ class Viewer(wx.Panel):
75 74 self.interactor = interactor
76 75  
77 76 def __config_interactor(self):
78   -
79   - style = vtk.vtkInteractorStyleImage()
80   - self.style = style
81   -
  77 +
82 78 ren = vtk.vtkRenderer()
83 79  
84 80 interactor = self.interactor
85   - interactor.SetInteractorStyle(style)
86 81 interactor.GetRenderWindow().AddRenderer(ren)
87 82  
88 83 self.cam = ren.GetActiveCamera()
89 84 self.ren = ren
90 85  
91   - self.SetMode(self.mode)
  86 + self.AppendMode('DEFAULT')
  87 +
  88 + def AppendMode(self, mode):
  89 +
  90 + # Retrieve currently set modes
  91 + self.modes.append(mode)
92 92  
93   - def SetMode(self, mode):
94   - self.mode = mode
95 93 # All modes and bindings
96 94 action = {'DEFAULT': {
97 95 "MouseMoveEvent": self.OnCrossMove,
... ... @@ -106,11 +104,17 @@ class Viewer(wx.Panel):
106 104 }
107 105  
108 106 # Bind method according to current mode
109   - style = self.style
  107 + style = vtk.vtkInteractorStyleImage()
  108 + self.style = style
  109 + self.interactor.SetInteractorStyle(style)
110 110  
111   - for event in action[mode]:
112   - style.AddObserver(event,
113   - action[mode][event])
  111 + # Check all modes set by user
  112 + for mode in self.modes:
  113 + # Check each event available for each mode
  114 + for event in action[mode]:
  115 + # Bind event
  116 + style.AddObserver(event,
  117 + action[mode][event])
114 118  
115 119  
116 120 def OnMouseClick(self, obj, evt_vtk):
... ... @@ -133,10 +137,14 @@ class Viewer(wx.Panel):
133 137 coord = self.GetCoordinate()
134 138 # Update position in other slices
135 139 if self.mouse_pressed:
136   - ps.Publisher().sendMessage('Update cursor position in slice', coord)
137   - ps.Publisher().sendMessage(('Set scroll position', 'SAGITAL'), coord[0])
138   - ps.Publisher().sendMessage(('Set scroll position', 'CORONAL'), coord[1])
139   - ps.Publisher().sendMessage(('Set scroll position', 'AXIAL'), coord[2])
  140 + ps.Publisher().sendMessage('Update cursor position in slice',
  141 + coord)
  142 + ps.Publisher().sendMessage(('Set scroll position', 'SAGITAL'),
  143 + coord[0])
  144 + ps.Publisher().sendMessage(('Set scroll position', 'CORONAL'),
  145 + coord[1])
  146 + ps.Publisher().sendMessage(('Set scroll position', 'AXIAL'),
  147 + coord[2])
140 148  
141 149  
142 150 def GetCoordinate(self):
... ...
invesalius/data/viewer_volume.py
... ... @@ -78,7 +78,6 @@ class Viewer(wx.Panel):
78 78 self.UpdateRender()
79 79 self.Refresh()
80 80 print dir(self.iren)
81   - self.UpdateRender()
82 81 self.iren.UpdateWindowUI()
83 82 self.iren.Update()
84 83 evt.Skip()
... ...