1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 """The definition of the VTK area.
23 """
24 import vtk
25
26 from mbdyn.interface.renderWindowInteractor import GtkRenderWindowInteractor
27
28
30 """A class that inherits from the John Hunter's work
31 and overrides some of the methods for setting custom actions
32 when GTK signals are emitted.
33 """
34
36 GtkRenderWindowInteractor.__init__(self)
37
38 self.Initialize()
39 self.Start()
40
41 self.AddObserver("ExitEvent", lambda o, e, x=None: x)
42
44 """Callback on the signal 'enter_notify_event' emitted."""
45 self.grab_focus()
46 m = self.get_pointer()
47 ctrl, shift = self._GetCtrlShift(event)
48 self.win_interactor.SetEventInformationFlipY(m[0], m[1], ctrl, shift,
49 chr(0), 0, None)
50 self.win_interactor.EnterEvent()
51 self.speak()
52 return True
53
54
56 """Callback on the signal 'leave_notify_event' emitted."""
57 m = self.get_pointer()
58 ctrl, shift = self._GetCtrlShift(event)
59 self.win_interactor.SetEventInformationFlipY(m[0], m[1], ctrl, shift,
60 chr(0), 0, None)
61 self.win_interactor.LeaveEvent()
62 self.quiet()
63 return True
64
85
87 """Callback when the mouse pointer has moved."""
88 m = self.get_pointer()
89 ctrl, shift = self._GetCtrlShift(event)
90 self._Iren.SetEventInformationFlipY(m[0], m[1], ctrl, shift,
91 chr(0), 0, None)
92 self._Iren.MouseMoveEvent()
93 self.on_motion_notify_event(wid, event)
94 return True
95
96
98 """Return the Python object reference from
99 a VTK actor selected.
100 """
101
105
106 - def add(self, actor, reference):
107 """Add an actor and its corresponding Python reference"""
108 self.actors.append(actor)
109 self.references.append(reference)
110
112 """Remove an actor and its corresponding Python reference"""
113 aid = self.actors.index(actor)
114 self.actors.remove(actor)
115 self.references.remove(self.references[aid])
116
118 """Return the Python reference from the VTK actor one"""
119 return self.references[self.actors.index(actor)]
120
121
123 """The VTK area that can be packed inside GTK.
124 """
125
127 GtkVtkAreaBase.__init__(self)
128
129 self.status_bar = status_bar
130 self.mess_nothing = "No actor selected"
131 self.mess_actor = "Actor selected: %s"
132
133 self.renderer = vtk.vtkRenderer()
134 self.renderer.SetBackground(1., 1., 1.)
135 self.GetRenderWindow().AddRenderer(self.renderer)
136 self.win_interactor = self.GetWindowInteractor()
137 self.actors = []
138
139 self.picker = vtk.vtkPicker()
140 self.picker.PickFromListOn()
141 self.selected_items = []
142 self.has_selected_item = False
143 self.list_store = ListStore()
144
145 self.on_right_click = None
146 self.on_motion_notify_event = None
147
149 """Set by the C{Manager} in L{windSimSuite.interface.manager}"""
150 self.on_right_click = callback
151
153 """Set by the C{Manager} in L{windSimSuite.interface.manager}"""
154 self.on_motion_notify_event = callback
155
157 """Action to perform on 'enter_notify_event'"""
158 pass
159
161 """Action to perform on 'leave_notify_event'"""
162 self.status_bar.write("")
163
165 """Add an actor to the VTK display"""
166 self.renderer.AddActor(actor)
167 self.actors.append(actor)
168
170 """Specify an actor that can be selected"""
171 self.picker.AddPickList(actor)
172 self.list_store.add(actor, reference)
173
175 """Remove an actor from the VTK display"""
176 self.renderer.RemoveActor(actor)
177 self.actors.remove(actor)
178
180 """Remove an actor that could be selected"""
181 self.picker.DeletePickList(actor)
182 self.list_store.remove(actor)
183
185 """Return an VTK actor reference from the mouse pointer position
186 or None"""
187 xpos, ypos = self.win_interactor.GetEventPosition()
188 self.picker.Pick(xpos, ypos, 0., self.renderer)
189 actor = self.picker.GetActor()
190 return actor
191
193 """Return a Python instance reference or None
194 when the mouse pointer has moved. Note: C{event} is
195 not used for VTK, because the event is got from the
196 C{win_interactor} in that case."""
197 actor = self.get_actor()
198 if actor == None:
199 return None
200 else:
201 return self.list_store.get_from(actor)
202
204 """Clean the VTK area"""
205 for actor in self.actors:
206 self.renderer.RemoveActor(actor)
207 for actor in self.list_store.actors:
208 self.picker.DeletePickList(actor)
209
211 """Remove the selected items by moving the mouse pointer"""
212 self.status_bar.write(self.mess_nothing)
213 self.clean_selected_items()
214
216 """Remove the selected items from the list"""
217 if self.has_selected_item:
218 for idx in range(len(self.selected_items)):
219 item = self.selected_items.pop()
220 item.set_unselected()
221 self.has_selected_item = False
222
224 """Add a selected item by the mouse pointer to the list"""
225 item.set_selected()
226 self.selected_items.append(item)
227 self.has_selected_item = True
228 self.status_bar.write(self.mess_actor % item.name)
229