root/trunk/RBRapier/RBRapier/Renderer/Environment/Selection.py

Revision 732, 3.3 kB (checked in by sholloway, 5 years ago)

*** empty log message ***

Line 
1 #!/usr/bin/env python
2 ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 ##~ License
4 ##~
5 ##- The RuneBlade Foundation library is intended to ease some
6 ##- aspects of writing intricate Jabber, XML, and User Interface (wxPython, etc.)
7 ##- applications, while providing the flexibility to modularly change the
8 ##- architecture. Enjoy.
9 ##~
10 ##~ Copyright (C) 2002  TechGame Networks, LLC.
11 ##~
12 ##~ This library is free software; you can redistribute it and/or
13 ##~ modify it under the terms of the BSD style License as found in the
14 ##~ LICENSE file included with this distribution.
15 ##~
16 ##~ TechGame Networks, LLC can be reached at:
17 ##~ 3578 E. Hartsel Drive #211
18 ##~ Colorado Springs, Colorado, USA, 80920
19 ##~
20 ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21
22 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 #~ Imports
24 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25
26 from OpenGL import GL
27
28 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29 #~ Definitions
30 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
31
32 class SelectionBuffer(object):
33     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34     #~ Constants / Variables / Etc.
35     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36
37     SelectBufferSize = 127
38     _selection = []
39
40     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
41     #~ Definitions
42     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
43
44     class SelectionEntry(object):
45         __slots__ = '_z0', '_z1', 'namepath'
46
47         def __init__(self, z0, z1, namepath=()):
48             self._z0 = z0
49             self._z1 = z1
50             self.namepath = namepath
51
52         def __repr__(self):
53             return "<Selection z=%s names=%s>" % (self.GetZRange(), self.namepath)
54
55         def GetName(self):
56             return self.GetNamePath()[-1]
57         def GetNamePath(self):
58             return self.namepath
59
60         def GetZRange(self):
61             maxvalue = 0xffffffffL
62             return float(self._z0)/maxvalue, float(self._z1)/maxvalue
63
64         def Resolve(self, resolver):
65             result = resolver
66             namepath = self.namepath[:]
67             try:
68                 for step in namepath:
69                     result = result[step]
70             except LookupError:
71                 pass
72             return result
73
74     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
75     #~ Public
76     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
77
78     def GLSelect(self, context):
79         del self.Selection
80         GL.glSelectBuffer(self.SelectBufferSize)
81         GL.glRenderMode(GL.GL_SELECT)
82         GL.glInitNames()
83
84     def GLDeselect(self, context):
85         rawselection = GL.glRenderMode(GL.GL_RENDER)
86         self._SetRawSelection(rawselection)
87
88     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
89     #~ Properties
90     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
91
92     def GetSelection(self):
93         return self._selection
94     def SetSelection(self, value=()):
95         self._selection = list(value)
96
97     def DelSelection(self):
98         try: del self._selection
99         except AttributeError: pass
100     def _SetRawSelection(self, rawselection):
101         if rawselection:
102             from itertools import starmap
103             self.SetSelection(starmap(self.SelectionEntry, rawselection))
104         else:
105             self.SetSelection(())
106
107     Selection = property(GetSelection, SetSelection, DelSelection)
108
Note: See TracBrowser for help on using the browser.