1 from scenario.actor import Actor, CustomActor
2 from scenario.datatypes import DataType
3 from scenario.interpolators import Interpolator
4 from SimPy.Simulation import now
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
22
23 - def __init__(self, vi, initialValue = 0, datatype = DataType, interp = Interpolator):
25
26
27
29 director = self._director()
30 if director.needsRedraw:
31
32 self.object.OneRedraw()
33 director.needsRedraw = False
34
35
37 """
38 class for DejaVu actors.
39 initialValue= None - initial value of the object's attribute (object.name),
40 interp = None - interpolator class,
41 setFunction = None - function to set the value on the object,
42 if None, object.Set(name=value) will be used
43 getFunction = None - function that can be called to get the
44 current value of the attribute (object.name)
45 The function and its arguments have to be specified as a
46 3-tuple (func, *args, **kw). It will be called using
47 func(*(object,)+args), **kw) if it is a function
48 or func(*args, **kw) if it is a method;
49 if None, getattr(object, name) will be used to get the value
50 to set the value and getattr(geom, name) to get the value
51 """
52 - def __init__(self, name, object, initialValue=None, datatype=None, interp=None,
53 setFunction=None, getFunction=None):
54
55 assert isinstance(name, str)
56 self.varname = name
57 if not getFunction:
58 if hasattr(object, name):
59 getFunction = (getattr, (name,), {})
60 CustomActor.__init__(self, object.name+"."+name, object,
61 initialValue, datatype, interp, setFunction=setFunction, getFunction=getFunction)
62 if self.hasGetFunction:
63 self.recording = True
64 self.guiVar = None
65
67 if self.setFunction:
68 self.setFunction( *(self, value) )
69 else:
70 self.object.Set( **{self.varname:value} )
71
72
73
74 from interpolators import MaterialInterpolator
75 from scenario.datatypes import FloatType, IntType, BoolType,IntVectorType,\
76 FloatVectorType, IntVarType, FloatVarType, VarVectorType
77
78
80
86
88 object = self.object
89 i=0
90 for v,name in zip(value, ('ambi', 'emis', 'spec', 'shini')):
91
92 object.Set(propName=name, materials=v)
93 i +=1
94
96 mat = self.object.materials[1028].prop
97 return (mat[0], mat[2], mat[3], mat[4])
98
99
100
101 from scenario.interpolators import FloatVectorInterpolator, VarVectorInterpolator
102
104 """ This actor manages resizing of DejaVu object's scissor"""
105
106 - def __init__(self, name, object, initialValue=None, datatype=FloatVectorType,
107 interp=FloatVectorInterpolator):
108 DejaVuActor.__init__(self, name, object, initialValue, datatype, interp, getFunction=self.getValue)
109 self.hasGetFunction = True
110 self.varnames = ['scissorH', 'scissorW', 'scissorX', 'scissorY']
111
112 self.activeVars = ['scissorH', 'scissorW', 'scissorX', 'scissorY']
113
115 object = self.object
116 kw = {}
117 for i, var in enumerate (self.varnames):
118 if var in self.activeVars:
119 kw[var] = value[i]
120 object.Set(**kw)
121
123 obj = self.object
124 return [float(obj.scissorH), float(obj.scissorW),
125 float(obj.scissorX), float(obj.scissorY)]
126
127
128
129 import Numeric
130
132 """ This actor manages the near and far camera's atributes"""
133
134 - def __init__(self, name, object, initialValue=None, datatype=FloatVectorType,
135 interp=FloatVectorInterpolator):
136 DejaVuActor.__init__(self, name, object, initialValue, datatype,
137 interp, getFunction=self.getValue)
138 self.hasGetFunction = True
139 self.varnames = ['near', 'far']
140
141 self.activeVars = ['near', 'far']
142
144 camera = self.object
145 kw = {}
146 for i, var in enumerate (self.varnames):
147 if var in self.activeVars:
148 kw[var] = value[i]
149 camera.Set(**kw)
150 camera.Redraw()
151
153 c = self.object
154 return Numeric.array([c.near, c.far,], "f")
155
156
158 """ This actor manages the near and far camera's atributes"""
159
160 - def __init__(self, name, object, initialValue=None, datatype=FloatVectorType,
161 interp=FloatVectorInterpolator):
162 DejaVuActor.__init__(self, name, object, initialValue, datatype,
163 interp, getFunction=self.getValue)
164 self.hasGetFunction = True
165 self.varnames = ['start', 'end']
166
167 self.activeVars = ['start', 'end']
168
170 camera = self.object
171 kw = {}
172 for i, var in enumerate (self.varnames):
173 if var in self.activeVars:
174 kw[var] = value[i]
175 camera.fog.Set(**kw)
176 camera.Redraw()
177
179 c = self.object
180 return Numeric.array([c.fog.start, c.fog.end,], "f")
181
182
183 from scenario.interpolators import CompositeInterpolator, FloatVarScalarInterpolator
184
186
188 kw = {'interpolators': [VarVectorInterpolator,
189 VarVectorInterpolator,
190 VarVectorInterpolator,
191 ]
192 }
193 interp = (CompositeInterpolator, (), kw)
194 DejaVuActor.__init__(self, name, object, None, DataType, interp,
195 getFunction=self.getValue)
196 self.varnames = ['ambient', 'diffuse', 'specular']
197 self.activeVars = ['ambient', 'diffuse', 'specular']
198 self.hasGetFunction = True
199
201 object = self.object
202 kw = {}
203 for v,name in zip(value, ('ambient', 'diffuse', 'specular')):
204 if name in self.activeVars:
205 kw[name] = v
206 object.Set(**kw)
207
211
213 """ This actor manages the near and far camera's atributes"""
214
215 - def __init__(self, name, object, initialValue=None, datatype=FloatVarType,
216 interp=FloatVarScalarInterpolator):
217
218 DejaVuActor.__init__(self, name, object, initialValue,
219 datatype=datatype, interp=interp,
220 getFunction=self.getValue)
221 self.hasGetFunction = True
222 self.varnames = ['radii']
223 self.activeVars = ['radii']
224
226 object = self.object
227 object.Set(radii=value)
228
230 object = self.object
231 if object.oneRadius:
232 return object.radius
233 else:
234 return object.vertexSet.radii.array.flat
235
236
238
239 bases = klass.__bases__
240 klassList = list(bases)
241 for k in bases:
242 klassList.extend( getAllSubclasses(k) )
243 return klassList
244
245
246 import inspect
247 from actorsDescr import actorsDescr
248 from mglutil.gui.BasicWidgets.Tk.thumbwheel import ThumbWheel
249 from scenario.interpolators import FloatScalarInterpolator, IntScalarInterpolator
251
252
253
254
255
256 d1 = {}
257 for klass, d2 in actorsDescr.items():
258 if isinstance(object, klass):
259 d1.update(d2)
260
261 d2 = {}
262
263 attrs = inspect.getmembers(object, lambda x: isinstance(x, float))
264 for name,value in attrs:
265 if d1.has_key(name): continue
266 d2[name] = {
267 'interp': FloatScalarInterpolator,
268 'interpKw': {'values':[value, value]},
269 'valueWidget': ThumbWheel,
270 'valueWidgetKw': {'type': 'float', 'initialValue':value},
271 }
272
273
274 attrs = inspect.getmembers(object, lambda x: isinstance(x, int))
275 for name,value in attrs:
276 if d1.has_key(name): continue
277 d2[name] = {
278 'interp': IntScalarInterpolator,
279 'interpKw': {'values':[value, value]},
280 'valueWidget': ThumbWheel,
281 'valueWidgetKw': {'type':'int', 'initialValue':value},
282 }
283 return d1, d2
284
285
287
288 baseClasses = [object.__class__]
289 baseClasses.extend( getAllSubclasses(object.__class__) )
290
291 print 'getDejaVuActor', object,attribute
292 for klass in baseClasses:
293 d1 = actorsDescr.get(klass, None)
294 if d1:
295 d2 = d1.get(attribute, None)
296 if d2:
297 actorCalss, args, kw = d2['actor']
298 args = (attribute,object) + args
299 actor = actorCalss( *args, **kw )
300
301 return actor
302
303
304
305
306
307
308
309
310
311
312
313 return None
314