Commit f9eb4d86825fa07473d4c7ed16c2654b6d970a22
1 parent
8a7bb4b3
Exists in
master
and in
68 other branches
--no commit message
Showing
1 changed file
with
102 additions
and
1 deletions
Show diff stats
invesalius/data/viewer_volume.py
... | ... | @@ -71,9 +71,96 @@ class Viewer(wx.Panel): |
71 | 71 | |
72 | 72 | self.__bind_events() |
73 | 73 | self.__bind_events_wx() |
74 | + | |
75 | + self.mouse_pressed = 0 | |
76 | + | |
77 | + def SetMode(self, new_mode): | |
78 | + | |
79 | + action = { | |
80 | + 'PAN':{ | |
81 | + "MouseMoveEvent": self.OnPanMove, | |
82 | + "LeftButtonPressEvent": self.OnPanClick, | |
83 | + "LeftButtonReleaseEvent": self.OnReleasePanClick | |
84 | + }, | |
85 | + 'ZOOM':{ | |
86 | + "MouseMoveEvent": self.OnZoomMove, | |
87 | + "LeftButtonPressEvent": self.OnZoomClick, | |
88 | + "LeftButtonReleaseEvent": self.OnReleaseZoomClick, | |
89 | + }, | |
90 | + 'SPIN':{ | |
91 | + "MouseMoveEvent": self.OnSpinMove, | |
92 | + "LeftButtonPressEvent": self.OnSpinClick, | |
93 | + "LeftButtonReleaseEvent": self.OnReleaseSpinClick, | |
94 | + } | |
95 | + } | |
74 | 96 | |
97 | + if (new_mode == 'ZOOMSELECT'): | |
98 | + style = vtk.vtkInteractorStyleRubberBandZoom() | |
99 | + self.interactor.SetInteractorStyle(style) | |
100 | + self.style = style | |
101 | + else: | |
102 | + style = vtk.vtkInteractorStyleTrackballCamera() | |
103 | + self.interactor.SetInteractorStyle(style) | |
104 | + self.style = style | |
105 | + | |
106 | + # Check each event available for each mode | |
107 | + for event in action[new_mode]: | |
108 | + # Bind event | |
109 | + style.AddObserver(event,action[new_mode][event]) | |
75 | 110 | |
111 | + def OnSpinMove(self, evt, obj): | |
112 | + if (self.mouse_pressed): | |
113 | + evt.Spin() | |
114 | + evt.OnRightButtonDown() | |
115 | + | |
116 | + def OnSpinClick(self, evt, obj): | |
117 | + self.mouse_pressed = 1 | |
118 | + evt.StartSpin() | |
119 | + | |
120 | + def OnReleaseSpinClick(self,evt,obj): | |
121 | + self.mouse_pressed = 0 | |
122 | + evt.EndSpin() | |
123 | + | |
124 | + def OnZoomMove(self, evt, obj): | |
125 | + if (self.mouse_pressed): | |
126 | + evt.Dolly() | |
127 | + evt.OnRightButtonDown() | |
128 | + | |
129 | + def OnZoomClick(self, evt, obj): | |
130 | + self.mouse_pressed = 1 | |
131 | + evt.StartDolly() | |
132 | + | |
133 | + def OnReleaseZoomClick(self,evt,obj): | |
134 | + self.mouse_pressed = 0 | |
135 | + evt.EndDolly() | |
136 | + | |
137 | + | |
138 | + def OnPanMove(self, evt, obj): | |
139 | + if (self.mouse_pressed): | |
140 | + evt.Pan() | |
141 | + evt.OnRightButtonDown() | |
142 | + | |
143 | + def OnPanClick(self, evt, obj): | |
144 | + self.mouse_pressed = 1 | |
145 | + evt.StartPan() | |
76 | 146 | |
147 | + def OnReleasePanClick(self,evt,obj): | |
148 | + self.mouse_pressed = 0 | |
149 | + evt.EndPan() | |
150 | + | |
151 | + def SetNewMode(self, pubsub_evt): | |
152 | + print "__________________________" | |
153 | + mode = pubsub_evt.topic[1] | |
154 | + | |
155 | + if (mode == const.MODE_ZOOM_SELECTION): | |
156 | + self.SetMode('ZOOMSELECT') | |
157 | + elif(mode == const.MODE_MOVE): | |
158 | + self.SetMode('PAN') | |
159 | + elif(mode == const.MODE_ZOOM): | |
160 | + self.SetMode('ZOOM') | |
161 | + elif(mode == const.MODE_ROTATE): | |
162 | + self.SetMode('SPIN') | |
163 | + | |
77 | 164 | def OnMove(self, obj, evt): |
78 | 165 | if self.onclick and self.raycasting_volume: |
79 | 166 | mouse_x, mouse_y = self.interactor.GetEventPosition() |
... | ... | @@ -166,7 +253,21 @@ class Viewer(wx.Panel): |
166 | 253 | |
167 | 254 | ps.Publisher().subscribe(self.ResetCamClippingRange, 'Reset cam clipping range') |
168 | 255 | |
256 | + ps.Publisher().subscribe(self.SetNewMode, | |
257 | + ('Set interaction mode', | |
258 | + const.MODE_ZOOM_SELECTION)) | |
259 | + ps.Publisher().subscribe(self.SetNewMode, | |
260 | + ('Set interaction mode', | |
261 | + const.MODE_ZOOM)) | |
169 | 262 | |
263 | + ps.Publisher().subscribe(self.SetNewMode, | |
264 | + ('Set interaction mode', | |
265 | + const.MODE_MOVE)) | |
266 | + | |
267 | + ps.Publisher().subscribe(self.SetNewMode, | |
268 | + ('Set interaction mode', | |
269 | + const.MODE_ROTATE)) | |
270 | + | |
170 | 271 | def ResetCamClippingRange(self, pubsub_evt): |
171 | 272 | self.ren.ResetCamera() |
172 | 273 | self.ren.ResetCameraClippingRange() |
... | ... | @@ -211,7 +312,7 @@ class Viewer(wx.Panel): |
211 | 312 | style = vtk.vtkInteractorStyleTrackballCamera() |
212 | 313 | self.interactor.SetInteractorStyle(style) |
213 | 314 | self.style = style |
214 | - | |
315 | + | |
215 | 316 | |
216 | 317 | def OnSize(self, evt): |
217 | 318 | self.UpdateRender() | ... | ... |