/[ray_tracer]/trunk/ray_tracer/ray_tracer_py/nodes_pnl.py
ViewVC logotype

Contents of /trunk/ray_tracer/ray_tracer_py/nodes_pnl.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 115 - (show annotations) (download) (as text)
Sun Jan 8 02:34:23 2012 UTC (6 years, 11 months ago) by jacoblundstrom
File MIME type: text/x-python
File size: 17423 byte(s)
- added an attached object list to python ui for scene nodes


1 import ray_tracer_xrc, wx, wx.aui
2 import ray_tracer_res
3
4
5 class PanelNodes(object):
6 """ Nodes panel. """
7 def __init__(self, parent):
8 """
9 Initialize the node panel.
10 parent - The main frame.
11 """
12 self._parent = parent
13 self._scroll = self._parent.FindWindowById(wx.xrc.XRCID("ID_PANEL_NODES"))
14 scrollUnit = 1
15 panelWidth, panelHeight = self._scroll.Size
16 self._scroll.SetScrollbars(scrollUnit, scrollUnit, panelWidth / scrollUnit, panelHeight / scrollUnit)
17 self._addNodeBtn = self._parent.FindWindowById(wx.xrc.XRCID("ID_BTN_NODE_ADD"))
18 self._addNodeBtn.Bind(wx.EVT_BUTTON, self.onAddNodeClick)
19 self._removeNodeBtn = self._parent.FindWindowById(wx.xrc.XRCID("ID_BTN_NODE_REMOVE"))
20 self._removeNodeBtn.Bind(wx.EVT_BUTTON, self.onRemoveNodeClick)
21 self._editBtn = self._parent.FindWindowById(wx.xrc.XRCID("ID_BTN_NODE_EDIT"))
22 self._editBtn.Bind(wx.EVT_BUTTON, self.onEditNodeClick)
23 # NOTE: Since list data can only hold a long, lets create our own mapping.
24 self._nodesData = {}
25 self._nodes = self._parent.FindWindowById(wx.xrc.XRCID("ID_LIST_NODES"))
26 self._nodes.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.onNodeListItemActivated)
27 self._nodes.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onNodeListItemSelected)
28 self._nodes.InsertColumn(0, "Name")
29 self._name = self._parent.FindWindowById(wx.xrc.XRCID("ID_TEXT_NODE_NAME"))
30 self._name.Bind(wx.EVT_TEXT_ENTER, self.onNameEnter)
31 self._parentName = self._parent.FindWindowById(wx.xrc.XRCID("ID_TEXT_NODE_PARENT"))
32 self._posX = self._parent.FindWindowById(wx.xrc.XRCID("ID_TEXT_NODE_POSX"))
33 self._posX.Bind(wx.EVT_TEXT_ENTER, self.onPosXEnter)
34 self._posY = self._parent.FindWindowById(wx.xrc.XRCID("ID_TEXT_NODE_POSY"))
35 self._posY.Bind(wx.EVT_TEXT_ENTER, self.onPosYEnter)
36 self._posZ = self._parent.FindWindowById(wx.xrc.XRCID("ID_TEXT_NODE_POSZ"))
37 self._posZ.Bind(wx.EVT_TEXT_ENTER, self.onPosZEnter)
38 self._oriX = self._parent.FindWindowById(wx.xrc.XRCID("ID_TEXT_NODE_ORIX"))
39 self._oriX.Bind(wx.EVT_TEXT_ENTER, self.onOriXEnter)
40 self._oriY = self._parent.FindWindowById(wx.xrc.XRCID("ID_TEXT_NODE_ORIY"))
41 self._oriY.Bind(wx.EVT_TEXT_ENTER, self.onOriYEnter)
42 self._oriZ = self._parent.FindWindowById(wx.xrc.XRCID("ID_TEXT_NODE_ORIZ"))
43 self._oriZ.Bind(wx.EVT_TEXT_ENTER, self.onOriZEnter)
44 self._scaleX = self._parent.FindWindowById(wx.xrc.XRCID("ID_TEXT_NODE_SCALEX"))
45 self._scaleX.Bind(wx.EVT_TEXT_ENTER, self.onScaleXEnter)
46 self._scaleY = self._parent.FindWindowById(wx.xrc.XRCID("ID_TEXT_NODE_SCALEY"))
47 self._scaleY.Bind(wx.EVT_TEXT_ENTER, self.onScaleYEnter)
48 self._scaleZ = self._parent.FindWindowById(wx.xrc.XRCID("ID_TEXT_NODE_SCALEZ"))
49 self._scaleZ.Bind(wx.EVT_TEXT_ENTER, self.onScaleZEnter)
50 self._posXComb = self._parent.FindWindowById(wx.xrc.XRCID("ID_TEXT_NODE_POSXCOMB"))
51 self._posYComb = self._parent.FindWindowById(wx.xrc.XRCID("ID_TEXT_NODE_POSYCOMB"))
52 self._posZComb = self._parent.FindWindowById(wx.xrc.XRCID("ID_TEXT_NODE_POSZCOMB"))
53 self._oriXComb = self._parent.FindWindowById(wx.xrc.XRCID("ID_TEXT_NODE_ORIXCOMB"))
54 self._oriYComb = self._parent.FindWindowById(wx.xrc.XRCID("ID_TEXT_NODE_ORIYCOMB"))
55 self._oriZComb = self._parent.FindWindowById(wx.xrc.XRCID("ID_TEXT_NODE_ORIZCOMB"))
56 self._scaleXComb = self._parent.FindWindowById(wx.xrc.XRCID("ID_TEXT_NODE_SCALEXCOMB"))
57 self._scaleYComb = self._parent.FindWindowById(wx.xrc.XRCID("ID_TEXT_NODE_SCALEYCOMB"))
58 self._scaleZComb = self._parent.FindWindowById(wx.xrc.XRCID("ID_TEXT_NODE_SCALEZCOMB"))
59 self._inheritOri = self._parent.FindWindowById(wx.xrc.XRCID("ID_CHECK_NODE_INHERIT_ORIENTATION"))
60 self._inheritOri.Bind(wx.EVT_CHECKBOX, self.onInheritOri)
61 self._inheritScale = self._parent.FindWindowById(wx.xrc.XRCID("ID_CHECK_NODE_INHERIT_SCALE"))
62 self._inheritScale.Bind(wx.EVT_CHECKBOX, self.onInheritScale)
63 self._addObjectBtn = self._parent.FindWindowById(wx.xrc.XRCID("ID_BTN_NODE_ADD_OBJECT"))
64 self._addObjectBtn.Bind(wx.EVT_BUTTON, self.onAddObjectClick)
65 self._removeObjectBtn = self._parent.FindWindowById(wx.xrc.XRCID("ID_BTN_NODE_REMOVE_OBJECT"))
66 self._removeObjectBtn.Bind(wx.EVT_BUTTON, self.onRemoveObjectClick)
67 self._editObjectBtn = self._parent.FindWindowById(wx.xrc.XRCID("ID_BTN_NODE_EDIT_OBJECT"))
68 self._editObjectBtn.Bind(wx.EVT_BUTTON, self.onEditObjectClick)
69 # NOTE: Since list data can only hold a long, lets create our own mapping.
70 self._objectsData = {}
71 self._objects = self._parent.FindWindowById(wx.xrc.XRCID("ID_LIST_NODE_OBJECTS"))
72 self._objects.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.onObjectListItemActivated)
73 self._objects.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onObjectListItemSelected)
74 self._objects.InsertColumn(0, "Name")
75
76 def clear(self):
77 """ Clear control values. """
78 self._nodesData = {}
79 self._nodes.DeleteAllItems()
80 self._parentName.Value = ""
81 self._posX.Value = ""
82 self._posY.Value = ""
83 self._posZ.Value = ""
84 self._oriX.Value = ""
85 self._oriY.Value = ""
86 self._oriZ.Value = ""
87 self._scaleX.Value = ""
88 self._scaleY.Value = ""
89 self._scaleZ.Value = ""
90 self._posXComb.Value = ""
91 self._posYComb.Value = ""
92 self._posZComb.Value = ""
93 self._oriXComb.Value = ""
94 self._oriYComb.Value = ""
95 self._oriZComb.Value = ""
96 self._scaleXComb.Value = ""
97 self._scaleYComb.Value = ""
98 self._scaleZComb.Value = ""
99 self._inheritOri.Value = False
100 self._inheritScale.Value = False
101 self._objectsData = {}
102 self._objects.DeleteAllItems()
103
104 def refresh(self):
105 """ Refresh controls. """
106 self._refreshNodeList(self._parent.sceneMgr.getSceneNodes())
107 self._refreshProperties()
108
109 def onAddNodeClick(self, evt):
110 """ Handle user pressing the add node button. """
111 item = self._getSelectedNode()
112 if item:
113 self._parent.log("add node: {0}".format(item.name))
114
115 def onRemoveNodeClick(self, evt):
116 """ Handle user pressing the remove node button. """
117 item = self._getSelectedNode()
118 if item:
119 self._parent.log("remove node: {0}".format(item.name))
120
121 def onEditNodeClick(self, evt):
122 """ Handle user pressing the edit node button. """
123 item = self._getSelectedNode()
124 if item:
125 self._parent.log("edit node: {0}".format(item.name))
126
127 def onNodeListItemActivated(self, evt):
128 """ Handle node list item activation. """
129 self._parent.log("TODO: offer something based on selection")
130
131 def onNodeListItemSelected(self, evt):
132 """ Handle node list item selection change. """
133 self._refreshProperties()
134
135 def onNameEnter(self, evt):
136 """ Handle user pressing enter on name text control. """
137 item = self._getSelectedNode()
138 if item:
139 # TODO: Need to update the scene manager with new item name.
140 # TODO: Need to refresh list after scene manager update.
141 oldName = item.name
142 item.name = str(evt.String)
143 self._parent.log("set {0} name: {1}".format(oldName, item.name))
144
145 def onPosXEnter(self, evt):
146 """ Handle user pressing enter on position x text control. """
147 item = self._getSelectedNode()
148 if item:
149 try:
150 val = float(evt.String)
151 vec = item.position
152 tmp = vec.value.split(",")
153 tmp[0] = str(val)
154 vec.value = ", ".join(tmp)
155 item.position = vec
156 self._parent.log("set {0} position: {1}".format(item.name, item.position.value))
157 except ValueError:
158 self._parent.log("Error: x position must be floating-point value")
159 self._posX.Value = item.position.value.split(",")[0]
160 self._posX.SetInsertionPointEnd()
161 self._refreshProperties()
162
163 def onPosYEnter(self, evt):
164 """ Handle user pressing enter on position y text control. """
165 item = self._getSelectedNode()
166 if item:
167 try:
168 val = float(evt.String)
169 vec = item.position
170 tmp = vec.value.split(",")
171 tmp[1] = str(val)
172 vec.value = ", ".join(tmp)
173 item.position = vec
174 self._parent.log("set {0} position: {1}".format(item.name, item.position.value))
175 except ValueError:
176 self._parent.log("Error: y position must be floating-point value")
177 self._posY.Value = item.position.value.split(",")[1]
178 self._posY.SetInsertionPointEnd()
179 self._refreshProperties()
180
181 def onPosZEnter(self, evt):
182 """ Handle user pressing enter on position z text control. """
183 item = self._getSelectedNode()
184 if item:
185 try:
186 val = float(evt.String)
187 vec = item.position
188 tmp = vec.value.split(",")
189 tmp[2] = str(val)
190 vec.value = ", ".join(tmp)
191 item.position = vec
192 self._parent.log("set {0} position: {1}".format(item.name, item.position.value))
193 except ValueError:
194 self._parent.log("Error: z position must be floating-point value")
195 self._posZ.Value = item.position.value.split(",")[2]
196 self._posZ.SetInsertionPointEnd()
197 self._refreshProperties()
198
199 def onOriXEnter(self, evt):
200 """ Handle user pressing enter on orientation x text control. """
201 item = self._getSelectedNode()
202 if item:
203 try:
204 val = float(evt.String)
205 vec = item.orientation
206 tmp = vec.value.split(",")
207 tmp[0] = str(val)
208 vec.value = ", ".join(tmp)
209 item.orientation = vec
210 self._parent.log("set {0} orientation: {1}".format(item.name, item.orientation.value))
211 except ValueError:
212 self._parent.log("Error: x orientation must be floating-point value")
213 self._oriX.Value = item.orientation.value.split(",")[0]
214 self._oriX.SetInsertionPointEnd()
215 self._refreshProperties()
216
217 def onOriYEnter(self, evt):
218 """ Handle user pressing enter on orientation y text control. """
219 item = self._getSelectedNode()
220 if item:
221 try:
222 val = float(evt.String)
223 vec = item.orientation
224 tmp = vec.value.split(",")
225 tmp[1] = str(val)
226 vec.value = ", ".join(tmp)
227 item.orientation = vec
228 self._parent.log("set {0} orientation: {1}".format(item.name, item.orientation.value))
229 except ValueError:
230 self._parent.log("Error: y orientation must be floating-point value")
231 self._oriY.Value = item.orientation.value.split(",")[1]
232 self._oriY.SetInsertionPointEnd()
233 self._refreshProperties()
234
235 def onOriZEnter(self, evt):
236 """ Handle user pressing enter on orientation z text control. """
237 item = self._getSelectedNode()
238 if item:
239 try:
240 val = float(evt.String)
241 vec = item.orientation
242 tmp = vec.value.split(",")
243 tmp[2] = str(val)
244 vec.value = ", ".join(tmp)
245 item.orientation = vec
246 self._parent.log("set {0} orientation: {1}".format(item.name, item.orientation.value))
247 except ValueError:
248 self._parent.log("Error: z orientation must be floating-point value")
249 self._oriZ.Value = item.orientation.value.split(",")[2]
250 self._oriZ.SetInsertionPointEnd()
251 self._refreshProperties()
252
253 def onScaleXEnter(self, evt):
254 """ Handle user pressing enter on scale x text control. """
255 item = self._getSelectedNode()
256 if item:
257 try:
258 val = float(evt.String)
259 vec = item.scale
260 tmp = vec.value.split(",")
261 tmp[0] = str(val)
262 vec.value = ", ".join(tmp)
263 item.scale = vec
264 self._parent.log("set {0} scale: {1}".format(item.name, item.scale.value))
265 except ValueError:
266 self._parent.log("Error: x scale must be floating-point value")
267 self._scaleX.Value = item.scale.value.split(",")[0]
268 self._scaleX.SetInsertionPointEnd()
269 self._refreshProperties()
270
271 def onScaleYEnter(self, evt):
272 """ Handle user pressing enter on scale y text control. """
273 item = self._getSelectedNode()
274 if item:
275 try:
276 val = float(evt.String)
277 vec = item.scale
278 tmp = vec.value.split(",")
279 tmp[1] = str(val)
280 vec.value = ", ".join(tmp)
281 item.scale = vec
282 self._parent.log("set {0} scale: {1}".format(item.name, item.scale.value))
283 except ValueError:
284 self._parent.log("Error: y scale must be floating-point value")
285 self._scaleY.Value = item.scale.value.split(",")[1]
286 self._scaleY.SetInsertionPointEnd()
287 self._refreshProperties()
288
289 def onScaleZEnter(self, evt):
290 """ Handle user pressing enter on scale z text control. """
291 item = self._getSelectedNode()
292 if item:
293 try:
294 val = float(evt.String)
295 vec = item.scale
296 tmp = vec.value.split(",")
297 tmp[2] = str(val)
298 vec.value = ", ".join(tmp)
299 item.scale = vec
300 self._parent.log("set {0} scale: {1}".format(item.name, item.scale.value))
301 except ValueError:
302 self._parent.log("Error: z scale must be floating-point value")
303 self._scaleZ.Value = item.scale.value.split(",")[2]
304 self._scaleZ.SetInsertionPointEnd()
305 self._refreshProperties()
306
307 def onInheritOri(self, evt):
308 """ Handler user checking inherit orientation control. """
309 item = self._getSelectedNode()
310 if item:
311 item.inheritOrientation = evt.Checked()
312 prefix = ""
313 if not evt.Checked():
314 prefix = "not"
315 self._parent.log("{0} inheriting parent orientation".format(prefix))
316
317 def onInheritScale(self, evt):
318 """ Handler user checking inherit scale control. """
319 item = self._getSelectedNode()
320 if item:
321 item.inheritScale = evt.Checked()
322 prefix = ""
323 if not evt.Checked():
324 prefix = "not"
325 self._parent.log("{0} inheriting parent scale".format(prefix))
326
327 def onAddObjectClick(self, evt):
328 """ Handle user pressing the add object button. """
329 item = self._getSelectedObject()
330 if item:
331 self._parent.log("add object: {0}".format(item.name))
332
333 def onRemoveObjectClick(self, evt):
334 """ Handle user pressing the remove object button. """
335 item = self._getSelectedObject()
336 if item:
337 self._parent.log("remove object: {0}".format(item.name))
338
339 def onEditObjectClick(self, evt):
340 """ Handle user pressing the edit object button. """
341 item = self._getSelectedObject()
342 if item:
343 self._parent.log("edit object: {0}".format(item.name))
344
345 def onObjectListItemActivated(self, evt):
346 """ Handle object list item activation. """
347 self._parent.log("TODO: offer something based on selection")
348
349 def onObjectListItemSelected(self, evt):
350 """ Handle object list item selection change. """
351 pass
352
353 def _getSelectedNode(self):
354 """ Internal helper to get node from item selection. """
355 sel = self._nodes.GetFirstSelected()
356 if sel == -1:
357 self._parent.log("Error: no node selected")
358 self.clear()
359 return None
360 return self._nodesData[self._nodes.GetItemText(sel)]
361
362 def _getSelectedObject(self):
363 """ Internal helper to get object from item selection. """
364 sel = self._objects.GetFirstSelected()
365 if sel == -1:
366 self._parent.log("Error: no object selected")
367 return None
368 return self._objectsData[self._objects.GetItemText(sel)]
369
370 def _refreshNodeList(self, collection):
371 """ Internal helper for clearing and repopulating the node list control. """
372 # Store previous list selection.
373 name = None
374 sel = self._nodes.GetFirstSelected()
375 if sel != -1:
376 name = self._nodes.GetItemText(sel)
377 # Clear and repopulate list.
378 self._nodesData = {}
379 self._nodes.DeleteAllItems()
380 sel = -1
381 for item in collection:
382 self._nodesData[item.key()] = item.data()
383 tmp = self._nodes.InsertStringItem(self._nodes.ItemCount, item.key())
384 if name != None and name == item.key():
385 sel = tmp
386 # Select best item from list.
387 if self._nodes.ItemCount > 0:
388 if sel == -1:
389 self._nodes.Select(0)
390 else:
391 self._nodes.Select(sel)
392
393 def _refreshObjectList(self, node):
394 """ Internal helper for clearing and repopulating the object list control. """
395 # Store previous list selection.
396 if node:
397 name = None
398 sel = self._objects.GetFirstSelected()
399 if sel != -1:
400 name = self._objects.GetItemText(sel)
401 # Clear and repopulate list.
402 self._objectsData = {}
403 self._objects.DeleteAllItems()
404 sel = -1
405 collection = node.getAttachedObjects()
406 for item in collection:
407 self._objectsData[item.key()] = item.data()
408 tmp = self._objects.InsertStringItem(self._objects.ItemCount, item.key())
409 if name != None and name == item.key():
410 sel = tmp
411 # Select best item from list.
412 if self._objects.ItemCount > 0:
413 if sel == -1:
414 self._objects.Select(0)
415 else:
416 self._objects.Select(sel)
417
418 def _refreshProperties(self):
419 """ Internal helper to refresh property controls. """
420 item = self._getSelectedNode()
421 if not item:
422 self.clear()
423 else:
424 self._name.Value = item.name
425 self._parentName.Value = item.parent.name
426 tmp = item.position.value.split(",")
427 self._posX.Value = tmp[0]
428 self._posY.Value = tmp[1]
429 self._posZ.Value = tmp[2]
430 tmp = item.orientation.value.split(",")
431 self._oriX.Value = tmp[0]
432 self._oriY.Value = tmp[1]
433 self._oriZ.Value = tmp[2]
434 tmp = item.scale.value.split(",")
435 self._scaleX.Value = tmp[0]
436 self._scaleY.Value = tmp[1]
437 self._scaleZ.Value = tmp[2]
438 tmp = item.combinedPosition.value.split(",")
439 self._posXComb.Value = tmp[0]
440 self._posYComb.Value = tmp[1]
441 self._posZComb.Value = tmp[2]
442 tmp = item.combinedOrientation.value.split(",")
443 self._oriXComb.Value = tmp[0]
444 self._oriYComb.Value = tmp[1]
445 self._oriZComb.Value = tmp[2]
446 tmp = item.combinedScale.value.split(",")
447 self._scaleXComb.Value = tmp[0]
448 self._scaleYComb.Value = tmp[1]
449 self._scaleZComb.Value = tmp[2]
450 self._inheritOri.Value = item.inheritOrientation
451 self._inheritScale.Value = item.inheritScale
452 self._refreshObjectList(item)
453

cvs@jdrake.com
ViewVC Help
Powered by ViewVC 1.1.13