File: Displayable.py

package info (click to toggle)
mgltools-dejavu 1.5.7-1
  • links: PTS, VCS
  • area: non-free
  • in suites: stretch
  • size: 5,144 kB
  • ctags: 4,112
  • sloc: python: 51,144; sh: 78; makefile: 12
file content (675 lines) | stat: -rw-r--r-- 21,510 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
#############################################################################
#
# Author: Michel F. SANNER
#
# Copyright: M. Sanner TSRI 2000
#
#############################################################################

#
# $Header: /opt/cvs/python/packages/share1.5/DejaVu/Displayable.py,v 1.57.6.1 2016/02/11 01:25:20 annao Exp $
#
# $Id: Displayable.py,v 1.57.6.1 2016/02/11 01:25:20 annao Exp $
#
from math import pi, exp, sin
from time import time

from opengltk.OpenGL import GL
import types
import numpy
import Materials, viewerConst
from viewerFns import getkw
from colorTool import OneColor, glMaterialWithCheck, resetMaterialMemory
from mglutil.util.callback import CallbackFunction

import DejaVu

class OutLine:
    """Base class for wire frame used for outlined polygons"""

    def Reset(self):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
	"""Reset members to default values"""

	self.factor = 1.5
	self.unit = 0.000001
	self.lineWidth = 1
	self.color = [0., 0., 0., .3]
        self.colorAsMaterial = False # set to True to use Object's material
                                     # to color lines
	self.dpyList = None
        self.lighting = False

        
    def Set(self, redo=0,**kw):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
	"""Set members"""

	val = getkw(kw, 'factor')
	if val is not None:
	    assert type(val).__name__ == 'float'
	    self.factor = val

	val = getkw(kw, 'unit')
	if val is not None:
	    assert type(val).__name__ == 'float'
	    self.unit = val

	val = getkw(kw, 'lineWidth')
	if val is not None:
	    assert val >= 1
	    self.lineWidth = int(val)

	val = getkw(kw, 'color')
	if val is not None:
	    color = OneColor( val )
	    if color: self.color = color

	val = getkw(kw, 'lighting')
	if val is not None:
	    assert val in [False, True]
	    self.lighting = val

	val = getkw(kw, 'colorAsMaterial')
	if val is not None:
	    assert val in [False,True]
	    self.colorAsMaterial = val

        if self.geom.viewer is not None:
            #self.geom.RedoDisplayList()
            self.geom.viewer.deleteOpenglList()
        
	if len(kw):
	    print 'WARNING2: Keyword(s) %s not used' % kw.keys()


    def __init__(self, geom, **kw):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()

        self.geom = geom
	self.Reset()
	self.Set( factor = getkw(kw, 'factor'),
		  unit = getkw(kw, 'unit'),
		  lineWidth = getkw(kw, 'lineWidth'),
		  color = getkw(kw, 'color') )

	if len(kw):
	    print 'WARNING3: Keyword(s) %s not used' % kw.keys()


    def __repr__(self):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
	return '<%s> factor=%5.2f unit=%5.2f lineWidth=%5.2f color=%s' % \
	       (self.__class__, self.factor, self.unit, self.lineWidth,
		str(self.color) )


class LineStipple:
    """Base class for line stippling information"""

    def Reset(self):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
	"""Reset members to default values"""

	self.factor = 1
	self.pattern = 0x7878

    
    def Set(self, **kw):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
	"""Set members"""

	val = getkw(kw, 'factor')
	if val:
	    assert type(val).__name__ == 'int' and val > 0
	    self.factor = val

	val = getkw(kw, 'pattern')
	if val:
	    assert val > 0x0000 and val < 0xFFFF
	    self.pattern = val

	if len(kw):
	    print 'WARNING4: Keyword(s) %s not used' % kw.keys()


    def __init__(self, **kw):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()

	self.Reset()
	self.Set( factor = getkw(kw, 'factor'),
		  pattern = getkw(kw, 'pattern'))

	if len(kw):
	    print 'WARNING5: Keyword(s) %s not used' % kw.keys()


    def __repr__(self):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
	return '<%s> factor=%f pattern=%s' % ( self.__class__,
		self.factor, hex(self.pattern) )


class PolygonStipple:
    """Base class for polygon stippling information"""

    def Reset(self):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
	"""Reset members to default values"""

	self.pattern = numpy.ones( (128,)) * 0xFF
	self.pattern = self.pattern.astype('B')
    
    def Set(self, **kw):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
	"""Set members"""

	val = getkw(kw, 'pattern')
	if val is not None:
	    assert type(val).__name__ == 'ndarray'
	    assert val.shape[0] == 128
	    assert val.dtype.char == 'B'
	    self.pattern = val

	if len(kw):
	    print 'WARNING6: Keyword(s) %s not used' % kw.keys()


    def __init__(self, **kw):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()

	self.Reset()
	self.Set( pattern = getkw(kw, 'pattern'))

	if len(kw):
	    print 'WARNING7: Keyword(s) %s not used' % kw.keys()


    def __repr__(self):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
	return '<%s>\n pattern=%s' % ( self.__class__, map(hex,self.pattern) )


class Displayable:
    """Base class for all object that can be viewed"""

    def Set(self, **kw):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
        """set data for this object"""

        # currently all these attributs are in GEOM
        # they should move here
        pass


    def __init__(self):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()

        self.materials = { GL.GL_FRONT:Materials.Materials(),
        		   GL.GL_BACK:Materials.Materials() }
        self.texture = None
        
        self.frontPolyMode = GL.GL_FILL
        self.backPolyMode = GL.GL_FILL
        self.frontAndBack = viewerConst.NO
        self.shading = GL.GL_SMOOTH
        self.lighting = viewerConst.NO
        self.culling = GL.GL_BACK
        #self.antiAliased = 0
        #self.antialiased = viewerConst.NO
        self.primitiveType = None
        
        self.inheritMaterial = viewerConst.YES
        self.inheritFrontPolyMode = viewerConst.YES
        self.inheritBackPolyMode = viewerConst.YES
        self.inheritShading = viewerConst.YES
        self.inheritLighting = viewerConst.YES
        self.inheritCulling = viewerConst.YES
        self.inheritPointWidth = viewerConst.YES
        self.inheritLineWidth = viewerConst.YES
        self.inheritStippleLines = viewerConst.YES
        self.inheritStipplePolygons = viewerConst.YES
        
        self.dpyList = None     # OpenGL display list used to draw this object
        self.lineWidth = 2
        self.pointWidth = 2

        from DejaVu.Transformable import Transformable
        if isinstance(self, Transformable):
        	self.drawOutline = (False, False)
        	self.outline = OutLine(self)
        	self.linestipple = LineStipple()
        	self.stippleLines = viewerConst.NO
        	self.polygonstipple = PolygonStipple()
        	self.stipplePolygons = viewerConst.NO

        self.transparent = viewerConst.NO

        self.depthMask = 1 # 0: zbuffer is readOnly for transparent objects
                           # 1: zbuffer is read write for transparent objects
        self.srcBlendFunc = GL.GL_SRC_ALPHA
        #self.dstBlendFunc = GL.GL_ONE #GL.GL_ONE_MINUS_SRC_COLOR
        # ONE_MINUS_SRC_ALPHA works for colorMapEditor
        self.dstBlendFunc = GL.GL_ONE_MINUS_SRC_ALPHA 

        # attribute used for flashing geometry
        self.flashInDuration = .5  # length of flash in seconds
        self.flashSolidDuration = .2  # length of flash in seconds
        self.flashOutDuration = .8  # length of flash in seconds
        self.flashIntervalTime = 10 # in ms
        self.flashStartTime = None # will be set when flash start

    ## version of flashing using after(ms, func)
    def _fadeOutT(self):
        dtime = time() - self.flashStartTime
        fraction = min(1.0, dtime/self.flashOutDuration)
        val =  exp(1.)/exp(1.+2*fraction)
        print fraction, val
        self.Set(opacity=val)
        self._setTransparent('implicit')
        vi = self.viewer
        vi.OneRedraw()
        if fraction<1.0:
            vi.master.after(self.flashIntervalTime, self._fadeOutT)
        else:
            self.Set(visible=0)

            
    def fadeOutT(self, duration=1.5, interval=10):
        self.flashOutDuration = duration
        self.flashIntervalTime = interval
        self.Set(visible=1)
        self.flashStartTime = time()
        self._fadeOutT()


    def _fadeInT(self):
        dtime = time() - self.flashStartTime
        fraction = min(1.0, dtime/self.flashInDuration)
        val = fraction*pi*.5
        vi = self.viewer
        #print fraction, val
        self.Set(opacity=val)
        self._setTransparent('implicit')
        vi.OneRedraw()
        if fraction<1.0:
            vi.master.after(self.flashIntervalTime, self._fadeInT)


    def fadeInT(self, duration=.5, interval=10):
        self.flashInDuration = duration
        self.flashIntervalTime = interval
        self.Set(visible=1, opacity=0.01, transparent=1, inheritMaterial=0)
        self._setTransparent('implicit')
        vi = self.viewer
        vi.OneRedraw()
        self.flashStartTime = time()
        self._fadeInT()


    def _flashT(self):
        dtime = time() - self.flashStartTime
        fraction = dtime/self.flashInDuration
        if fraction < 1.0: # we are in fade in mode
            val = fraction*pi*.5
            
        else: # We are in fade out mode
            dtime -= self.flashInDuration
            fraction = dtime/self.flashSolidDuration
            if fraction < 1.0: # we are in solid mode
                val = 1.0
            else: # we are in fade out mode
                
               dtime -= self.flashSolidDuration
               fraction = min(1., dtime/self.flashOutDuration)
               val =  exp(1.)/exp(1.+2*fraction)

        vi = self.viewer
        #print fraction, val
        self.Set(opacity=val)
        self._setTransparent('implicit')
        vi.OneRedraw()
        if fraction<1.0:
            vi.master.after(self.flashIntervalTime, self._flashT)
        else:
            self.Set(visible=0)
            vi.OneRedraw()
            if self.after_cb:
                self.after_cb()


    def flashT(self, durationIn=.5, duration=.2, durationOut=.8, interval=10,
               after_cb=None):
        self.flashInDuration = durationIn
        self.flashOutDuration = durationOut
        self.flashSolidDuration = duration
        self.flashIntervalTime = interval
        self.after_cb = after_cb
        self.flashStartTime = time()
        self.Set(visible=1, opacity=0.01, transparent=1, inheritMaterial=0)
        self._flashT()

        
    ## version of flashing without using after(ms, func)
    def fadeOut(self, nbf=25):
        vi = self.viewer
        for i in numpy.arange(1., 3., 2./nbf):
            val = exp(1.)/exp(i)
            self.Set(opacity=val)
            self._setTransparent('implicit')
            vi.OneRedraw()
        self.Set(visible=0)
        vi.OneRedraw()


    def fadeIn(self, nbf=15):
        self.Set(visible=1, opacity=0.01, transparent=1, inheritMaterial=0)
        self._setTransparent('implicit')
        self.viewer.OneRedraw()
        vi = self.viewer
        for i in numpy.arange(0, pi*.5, (pi*.5)/nbf):
            val = sin(i)
            self.Set(opacity=val)
            self._setTransparent('implicit')
            vi.OneRedraw()


    def flash(self, nbfIn=5, nbfOut=25, fullPause=200):
        self.fadeIn(nbf=nbfIn)
        cb = CallbackFunction(self.fadeOut, nbf=nbfOut)
        self.viewer.master.after(fullPause, self.fadeOut)


    def InitMaterial(self, num=0):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
	"""Setup GL material
only sets the material if binding mode is OVERALL or PER_INSTANCE (i.e. per
instance matrix) which are the 2 only material bindngs for which the material
is not set in the display list"""

        #import traceback
        #traceback.print_stack()
        #print 'InitMaterial', self.name
	prop = self.materials[GL.GL_FRONT]
	if self.frontAndBack: f = GL.GL_FRONT_AND_BACK
	else: f = GL.GL_FRONT
        resetMaterialMemory()
        
        b, p = prop.GetProperty(0)
        if prop.binding[0] == viewerConst.OVERALL:
	    glMaterialWithCheck(f, GL.GL_AMBIENT, p[0])
        elif prop.binding[0] == viewerConst.PER_INSTANCE:
	    glMaterialWithCheck(f, GL.GL_AMBIENT, p[num])

        b, p = prop.GetProperty(1)
	if prop.binding[1] == viewerConst.OVERALL:
	    glMaterialWithCheck(f, GL.GL_DIFFUSE, p[0])
        elif prop.binding[1] == viewerConst.PER_INSTANCE:
	    glMaterialWithCheck(f, GL.GL_DIFFUSE, p[num])
		
        b, p = prop.GetProperty(2)
	if prop.binding[2] == viewerConst.OVERALL:
	    glMaterialWithCheck(f, GL.GL_EMISSION, p[0])
        elif prop.binding[3] == viewerConst.PER_INSTANCE:
	    glMaterialWithCheck(f, GL.GL_EMISSION, p[num])

        b, p = prop.GetProperty(3)
	if prop.binding[2] == viewerConst.OVERALL:
	    glMaterialWithCheck(f, GL.GL_SPECULAR, p[0])
	elif prop.binding[2] == viewerConst.PER_INSTANCE:
	    glMaterialWithCheck(f, GL.GL_SPECULAR, p[num])

	if prop.binding[4] == viewerConst.OVERALL:
	    glMaterialWithCheck(f, GL.GL_SHININESS, float(prop.prop[4][0]))
	    #GL.glMaterialf(f, GL.GL_SHININESS, float(prop.prop[4][0]))
        elif prop.binding[4] == viewerConst.PER_INSTANCE:
	    glMaterialWithCheck(f, GL.GL_SHININESS, float(prop.prop[4][num]))
	    #GL.glMaterialf(f, GL.GL_SHININESS, float(prop.prop[4][num]))
            
	if not self.frontAndBack:
	    prop = self.materials[GL.GL_BACK]
	    f = GL.GL_BACK
            if prop.binding[0] == viewerConst.OVERALL:
		glMaterialWithCheck(f, GL.GL_AMBIENT, prop.prop[0][0])
            elif prop.binding[0] == viewerConst.PER_INSTANCE:
		glMaterialWithCheck(f, GL.GL_AMBIENT, prop.prop[0][num])
                
	    if prop.binding[1] == viewerConst.OVERALL:
		glMaterialWithCheck(f, GL.GL_DIFFUSE, prop.prop[1][0])
            elif prop.binding[1] == viewerConst.PER_INSTANCE:
		glMaterialWithCheck(f, GL.GL_DIFFUSE, prop.prop[1][num])
                
	    if prop.binding[2] == viewerConst.OVERALL:
		glMaterialWithCheck(f, GL.GL_SPECULAR, prop.prop[3][0])
            elif prop.binding[2] == viewerConst.PER_INSTANCE:
		glMaterialWithCheck(f, GL.GL_SPECULAR, prop.prop[3][num])

            if prop.binding[3] == viewerConst.OVERALL:
		glMaterialWithCheck(f, GL.GL_EMISSION, prop.prop[2][0])
            elif prop.binding[3] == viewerConst.PER_INSTANCE:
		glMaterialWithCheck(f, GL.GL_EMISSION, prop.prop[2][num])

	    if prop.binding[4] == viewerConst.OVERALL:
		glMaterialWithCheck(f, GL.GL_SHININESS, float(prop.prop[4][0]))
		#GL.glMaterialf(f, GL.GL_SHININESS, float(prop.prop[4][0]))
            elif prop.binding[4] == viewerConst.PER_INSTANCE:
                glMaterialWithCheck(f, GL.GL_SHININESS, float(prop.prop[4][num]))
                #GL.glMaterialf(f, GL.GL_SHININESS, float(prop.prop[4][num]))

    def InitColor(self, num=0):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
	"""Setup GL color (used when lighting is turned off)
only sets the color if binding mode is OVERALL or PER_INSTANCE (i.e. per
instance matrix) which are the 2 only colors which are not set in the
display list"""

        
        prop = self.materials[GL.GL_FRONT]
        if prop.binding[1] == viewerConst.OVERALL:
            material = prop.prop[prop.diff][0]
            if not material.flags.contiguous:
                material = numpy.array(material,copy=1)
            GL.glColor4fv ( material.tolist() )
        elif prop.binding[1] == viewerConst.PER_INSTANCE:
            material = prop.prop[prop.diff][num]
            if not material.flags.contiguous:
                material = numpy.array(material,copy=1)
            GL.glColor4fv ( material.tolist() )
## =======

##         mat = self.materials[GL.GL_FRONT]
##         # without tolist() we hang if array is not contiguous !
## 	GL.glColor4fv ( mat.prop[mat.diff][0].tolist() )
## >>>>>>> 1.8.2.1


    def _WidthAndStipple(self):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
        """Set the line or points width
"""
        #print "_WidthAndStipple", self.stippleLines , self.inheritStippleLines , self

        GL.glPointSize(self.getPointWidth())

        GL.glLineWidth(self.getLineWidth())

        if self.getStippleLines() in (True, 1):
            GL.glEnable(GL.GL_LINE_STIPPLE)
            ls = self.linestipple
            GL.glLineStipple(ls.factor, ls.pattern)
        else:
            GL.glDisable(GL.GL_LINE_STIPPLE)

        if self.getStipplePolygons() in (True, 1):
            GL.glEnable(GL.GL_POLYGON_STIPPLE)
            ps = self.polygonstipple
            GL.glPolygonStipple(self.polygonstipple.pattern)
        else:
            GL.glDisable(GL.GL_POLYGON_STIPPLE)


    def getPointWidth(self):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
        #print "getPointWidth", self.name
        obj = self
        while obj.inheritPointWidth:
            if obj.parent:
                obj = obj.parent
            else:
                break
        return obj.pointWidth


    def getLineWidth(self):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
        #print "getLineWidth", self.name
        obj = self
        while obj.inheritLineWidth:
            if obj.parent:
                obj = obj.parent
            else:
                break
        return obj.lineWidth


    def getStippleLines(self):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
        #print "getStippleLines", self.name
        obj = self
        while obj.inheritStippleLines:
            if obj.parent:
                obj = obj.parent
            else:
                break
        return obj.stippleLines


    def getStipplePolygons(self):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
        #print "getStipplePolygons", self.name
        obj = self
        while obj.inheritStipplePolygons:
            if obj.parent:
                obj = obj.parent
            else:
                break
        return obj.stipplePolygons


#    def _AntiAliasing(self):
#	"""Turn line or points antialiasing on or of"""
#
#	if self.antialiased==viewerConst.YES:
#	    if self.primitiveType == GL.GL_POINTS or \
#	       self.frontPolyMode == GL.GL_POINT or \
#	       self.backPolyMode == GL.GL_POINT:
#		GL.glEnable(GL.GL_POINT_SMOOTH)
#
#	    elif self.primitiveType in viewerConst.LINES_PRIMITIVES or \
#		 self.frontPolyMode == GL.GL_LINE or \
#		 self.backPolyMode == GL.GL_LINE:
#		GL.glEnable(GL.GL_LINE_SMOOTH)
#
#	    GL.glEnable(GL.GL_BLEND)
#	else:
#	    GL.glDisable(GL.GL_LINE_SMOOTH)
#	    GL.glDisable(GL.GL_BLEND)


    def SetupGL(self):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
        """Setup OpenGL rendering state for this object
"""
        #print "SetupGL", self

        if not self.inheritMaterial:
            self.InitMaterial()
            self.InitColor()

        if self.GetLighting():
            #glEnable(GL_LIGHTING)
            if self.viewer is not None:
                self.viewer.enableOpenglLighting()

            shading = self.GetShading()

	    if shading != GL.GL_NONE:
                if self.normals is not None:
                    if (shading==GL.GL_SMOOTH and \
                        len(self.normals)!=len(self.vertexSet)) or \
                        (shading==GL.GL_FLAT and \
                         len(self.normals)!=len(self.faceSet)):
                        self.GetNormals()
                        self.viewer.objectsNeedingRedo[self] = None

		GL.glShadeModel(shading)

	else: # no lighting
	    GL.glDisable(GL.GL_LIGHTING)

	if not self.inheritCulling:
	    if self.culling in (GL.GL_BACK, GL.GL_FRONT, GL.GL_FRONT_AND_BACK):
		GL.glCullFace(self.culling)
		GL.glEnable(GL.GL_CULL_FACE)
	    else: GL.glDisable(GL.GL_CULL_FACE)

	if not self.inheritFrontPolyMode:
            mode =self.frontPolyMode
            if self.frontPolyMode==viewerConst.OUTLINED:
                mode = GL.GL_FILL
	    if self.frontAndBack:
		GL.glPolygonMode(GL.GL_FRONT_AND_BACK, mode)
	    else:
		GL.glPolygonMode(GL.GL_FRONT, mode)

	if not self.inheritBackPolyMode:
            mode = self.backPolyMode
            if self.backPolyMode==viewerConst.OUTLINED:
                mode = GL.GL_FILL
	    GL.glPolygonMode(GL.GL_BACK, mode)

	#self._AntiAliasing()
	self._WidthAndStipple()


    def showOwnGui(self):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
        #print "showOwnGui", self
        if self.ownGui is None:
            self.createOwnGui()
        if self.ownGui.winfo_ismapped() == 0:
            self.ownGui.deiconify()
        self.ownGui.lift()


    def hideOwnGui(self):
        if __debug__:
         if hasattr(DejaVu, 'functionName'): DejaVu.functionName()
        #print "hideOwnGui", self
        if (self.ownGui is not None) and (self.ownGui.winfo_ismapped() == 0):
            self.ownGui.withdraw()