File: dejaVuCommands.py

package info (click to toggle)
mgltools-viewerframework 1.5.7-1
  • links: PTS, VCS
  • area: non-free
  • in suites: stretch
  • size: 1,584 kB
  • ctags: 1,271
  • sloc: python: 13,681; sh: 78; makefile: 10
file content (2474 lines) | stat: -rw-r--r-- 89,721 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
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
#############################################################################
#
# Author: Michel F. SANNER
#
# Copyright: M. Sanner TSRI 2000
#
#############################################################################

"""
This module implements classes relative to DejaVu.
"""
# $Header: /opt/cvs/python/packages/share1.5/ViewerFramework/dejaVuCommands.py,v 1.145.2.2 2016/03/02 23:54:46 annao Exp $
#
# $Id: dejaVuCommands.py,v 1.145.2.2 2016/03/02 23:54:46 annao Exp $
#


import numpy
import types
import os
import string
import Tkinter, Pmw
from math import pi, pow
from time import time, sleep
import tkMessageBox

from mglutil.util.callback import CallbackManager, CallBackFunction
from mglutil.math.rotax import rotax
from mglutil.gui.BasicWidgets.Tk.customizedWidgets import ListChooser, SaveButton
from mglutil.gui.InputForm.Tk.gui import InputFormDescr
from mglutil.gui.BasicWidgets.Tk.thumbwheel import ThumbWheel
from mglutil.util.misc import ensureFontCase
from DejaVu.colorMap import ColorMap
from DejaVu.ColormapGui import ColorMapGUI
from DejaVu.colorTool import RGBRamp, RedWhiteBlueRamp,RedWhiteRamp, \
        WhiteBlueRamp,GreyscaleRamp 
from DejaVu.colorTool import RGBARamp, RedWhiteBlueARamp,RedWhiteARamp, \
        WhiteBlueARamp
from DejaVu.Geom import Geom
from DejaVu.Spheres import Spheres

from ViewerFramework.VFCommand import Command, ICOM, CommandGUI
from ViewerFramework.VF import ViewerFramework
from mglutil.gui.BasicWidgets.Tk.colorWidgets import ColorChooser, BackgroundColorChooser
from mglutil.gui.BasicWidgets.Tk.customizedWidgets import ListChooser, \
     kbScrolledListBox
from opengltk.OpenGL import GL
from mglutil.util.packageFilePath import getResourceFolder

class ResetView(Command):

    def doit(self):
        vi = self.vf.GUI.VIEWER
        vi.Reset_cb()
        vi.Normalize_cb()
        vi.Center_cb()
        
    def guiCallback(self, event=None):
        self.doitWrapper()

    def __call__(self, **kw):
        """None <- ResetView( self, **kw)
        resets transformation on root object, translates and scales the scene
        to fit in viewport and sets the center of rotation to be the center of
        the scene
        """
        apply( self.doitWrapper, (), kw )

ResetViewGUI = CommandGUI()
ResetViewGUI.addToolBar('Reset View', icon1='icon-focus.gif', 
                        balloonhelp='Reset view, normalize and center',
                        type='ToolBarButton', index=9)

class ToggleNpr(Command):
    def doit(self, npr=1):
        if npr == 1:
            self.vf.GUI.VIEWER.GUI.contourTk.set(True)
            self.vf.GUI.VIEWER.cameras[0].Set(contours=True,
                                              tagModified=False)
            GL.glFinish()
            self.vf.GUI.VIEWER.GUI.showCurveTool() 
            self.vf.GUI.VIEWER.GUI.continuousRamp()
                        
        else:
            self.vf.GUI.VIEWER.GUI.contourTk.set(False)
            self.vf.GUI.VIEWER.cameras[0].Set(contours=False,
                                              tagModified=False)
            self.vf.GUI.VIEWER.GUI.GraphToolpanel.withdraw()                                  
            
    def guiCallback(self):
        val = self.GUI.menuCheckbuttonVar.get()
        self.doitWrapper( *(val,), **{'redraw':1})


    def __call__(self, npr=1, **kw):
        """None <- toggleNpr( self, npr=1, **kw)
        npr : flag when set to 1 toggle npr mode on when set to 0 turns
                 npr mode off
        """
        self.GUI.menuCheckbuttonVar.set(npr)

        self.doitWrapper( *(npr,), **kw )

toggleNprGuiDescr = {'widgetType':'Button', 'barName':'Toolbar',
                        'buttonName':'photo/cartoon'}
        
ToggleNprGUI = CommandGUI()
ToggleNprGUI.addToolBar('photo_cartoon', icon1 = 'npr.png', 
                         balloonhelp = 'Toggle photo/cartoon modes', index = 9)

ToggleNprMenuGUI = CommandGUI()
ToggleNprMenuGUI.addMenuCommand('menuRoot', 'Display', 'Cartoon',
                                menuEntryType='checkbutton')


class ToggleStereo(Command):
    def doit(self, stereo='MONO'):

        if self.vf.GUI.VIEWER.currentCamera.stereoMode == stereo:
            return

        if self.vf.GUI.VIEWER.activeStereoSupport is True:
            if stereo == 'STEREO_BUFFERS':
                self.vf.GUI.rebuildCamera(stereo='native')
                self.vf.GUI.VIEWER.currentCamera.Set( stereoMode=stereo,
                                                      tagModified=False )
            elif self.vf.GUI.VIEWER.currentCamera.stereoMode == 'STEREO_BUFFERS':
                self.vf.GUI.VIEWER.currentCamera.Set( stereoMode=stereo,
                                                      tagModified=False )
                self.vf.GUI.rebuildCamera(stereo='none')
            else:
                self.vf.GUI.VIEWER.currentCamera.Set( stereoMode=stereo,
                                                      tagModified=False )
        else:
            if stereo == 'STEREO_BUFFERS':
                # that way when we select STEREO_BUFFERS the camera is always rebuilt
                # it is a way to obtain a screen refresh
                self.vf.GUI.rebuildCamera(stereo='none')
                
                msg = """Stereo buffers are not present
or not enabled on this system.

enableStereo must be set to True in:
~/.mgltools/(ver_number)/DejaVu/_dejavurc
"""
                #self.warningMsg(msg)
                tkMessageBox.showerror('Stereo Buffers Error', msg)
                stereo = 'MONO'
                self.vf.GUI.toolbarCheckbuttons['mono_stereo']['Variable'].set(stereo)
            self.vf.GUI.VIEWER.currentCamera.Set( stereoMode=stereo,
                                                  tagModified=False )


    def guiCallback(self):
        val = {}
        val['stereo'] = self.vf.GUI.toolbarCheckbuttons['mono_stereo']['Variable'].get()
        val['redraw'] = 1
        apply( self.doitWrapper, (), val )


    def __call__(self, stereo=1, **kw):
        """None <- toggleStereo( self, stereo=1, **kw)
stereo : flag when set to 1 toggle stereo mode on when set to 0 turns
mono mode on
"""
        self.vf.GUI.toolbarCheckbuttons['mono_stereo']['Variable'].set(stereo)
        if stereo:
            kw['stereo'] = 'STEREO_BUFFERS' # was 'native'
        else:
            kw['stereo'] = 'MONO' # was 'none'
        apply( self.doitWrapper, (), kw )

stereoRadioLabels = [
                'mono (disabled)', 
                'SHUTTER GLASSES (on enabled systems)',
                '3DTV straight side by side',
                'side by side cross',
                'side by side straight',
                'RED ****** CYAN',
                'red       green',
                'red        blue',
                'yellow     blue',
                'cyan        red',
                'green       red',
                'blue        red',
                'blue     yellow',
              ]

stereoRadioValues = [
                'MONO', 
                'STEREO_BUFFERS',
                '3DTV',
                'SIDE_BY_SIDE_CROSS',
                'SIDE_BY_SIDE_STRAIGHT',
                'COLOR_SEPARATION_RED_GREENBLUE',
                'COLOR_SEPARATION_RED_GREEN',
                'COLOR_SEPARATION_RED_BLUE',
                'COLOR_SEPARATION_REDGREEN_BLUE',
                'COLOR_SEPARATION_GREENBLUE_RED',
                'COLOR_SEPARATION_GREEN_RED',
                'COLOR_SEPARATION_BLUE_RED',
                'COLOR_SEPARATION_BLUE_REDGREEN',
              ]

toggleStereoGuiDescr = {'widgetType':'Menu', 'barName':'Toolbar',
                        'buttonName':'mono/stereo'}

ToggleStereoGUI = CommandGUI()
ToggleStereoGUI.addToolBar('mono_stereo', icon1='stereo.gif', 
                           type ='MenuRadiobutton', 
                           radioLabels=stereoRadioLabels,
                           radioValues=stereoRadioValues,
                           radioInitialValue=stereoRadioValues[0],
                           balloonhelp='Toggle mono/stereo', index = 6)



class TransformObject(Command):

    def doit(self, transformation, geomName, matrix):
        # should be
        # geomName, rot = None, trans = None, scale = None, mat = None, set = 1
        if not self.vf.hasGui:
            return
        vi = self.vf.GUI.VIEWER
        geometry = vi.FindObjectByName(geomName)
        
        if not geometry:
            print 'WARNING: geometry name  %s not found'%geomName
            return

        # set the vi.currentObject to be the object to transform
        oldCurrent = vi.currentObject
        vi.SetCurrentObject(geometry)

        # transform only the given geometry.
        if vi.redirectTransformToRoot == 1:
            old = vi.redirectTransformToRoot
            vi.TransformRootOnly(0)
        else:
            old = 0
        
        if transformation[:3]=='rot':
            mat = numpy.reshape(numpy.array(matrix, 'f'), (16,))
            geometry.SetRotation(mat)

        elif transformation[:3]=='tra':
            mat = numpy.reshape(numpy.array(matrix, 'f'), (3,))
            geometry.SetTranslation(mat)

        elif transformation[:3]=='sca':
            mat = numpy.reshape(numpy.array(matrix, 'f'), (3,))
            geometry.SetScale(mat)

        elif transformation[:3]=='piv':
            mat = numpy.reshape(numpy.array(matrix, 'f'), (3,))
            geometry.SetPivot(mat)

        # do not understand those two lines ?????
        if self != vi.rootObject:
            vi.deleteOpenglList()

        # Put everything back like it was before.
        if old == 1:
            vi.TransformRootOnly(1)
        vi.SetCurrentObject(oldCurrent)

    def __call__( self, transformation, object, matrix, **kw):
        """ None <- tranformObject( transformation, object, matrix, **kw)
        transformation   : type of transformation
                           rotation      : 'rot'
                           translation   : 'tra'
                           scaling       : 'sca'
                           pivot         : 'piv'
        object           : the geometry to be transformed
        matrix           : transformation matrix to be applied to the object
        """
        if not kw.has_key('redraw'):
            kw['redraw']=1
        apply(self.doitWrapper, (transformation, object, matrix), kw)


class TransformCamera(Command):

    def doit(self, transformation, matrix, camIndex):
        # should be
        # geomName, rot = None, trans = None, scale = None, mat = None, set = 1
        if not self.vf.hasGui:
            return
        vi = self.vf.GUI.VIEWER
        cam = vi.cameras[camIndex]
        
        if transformation=='fov':
            cam.Set(fov=matrix)
            
        elif transformation[:3]=='rot':
            mat = numpy.reshape(numpy.array(matrix, 'f'), (16,))
            cam.SetRotation(mat)

        elif transformation[:3]=='tra':
            mat = numpy.reshape(numpy.array(matrix, 'f'), (3,))
            cam.SetTranslation(mat)

        elif transformation[:3]=='sca':
            mat = numpy.reshape(numpy.array(matrix, 'f'), (3,))
            cam.SetScale(mat)

        elif transformation[:3]=='piv':
            mat = numpy.reshape(numpy.array(matrix, 'f'), (3,))
            cam.SetPivot(mat)


    def __call__( self, transformation, matrix, camIndex=0, **kw):
        """ None <- tranformCamera( transformation, matrix, camIndex=0, **kw)
        transformation   : type of transformation
                           rotation      : 'rot'
                           translation   : 'tra'
                           scaling       : 'sca'
                           pivot         : 'piv'
                           field of view : 'fov'
        matrix           : transformation matrix to be applied to the object
        camIndex         : index of camera (defaults to 0)
        """
        if not kw.has_key('redraw'):
            kw['redraw']=1
        apply(self.doitWrapper, (transformation, matrix, camIndex), kw)


class SetObject(Command):

    def doit(self, object, **kw):
        if not self.vf.hasGui:
            return
        vi = self.vf.GUI.VIEWER
        viewerObj = vi.FindObjectByName(object)
        if not viewerObj:
            print 'WARNING: object %s not found'%object
            return
        kw['tagModified']=False
        apply( viewerObj.Set, (), kw)


        
class SetCamera(Command):

    def doit(self, camera, **kw):
        if not self.vf.hasGui:
            return
        vi = self.vf.GUI.VIEWER
        viewerCameras = filter(lambda x, name=camera: x.name==name, vi.cameras)
        if len(viewerCameras)==1:
            viewerCamera = viewerCameras[0]
        elif len(viewerCameras)>1:
            print 'WARNING: more than one camera found for the name: %s'%camera
            return
        else:
            print 'WARNING: camera %s not found'%camera
            return
        #print kw
        kw['tagModified']=False
        apply( viewerCamera.Set, (), kw)



class SetLight(Command):

    def doit(self, light, **kw):
        if not self.vf.hasGui:
            return
        vi = self.vf.GUI.VIEWER
        viewerLights = filter(lambda x, name=light: x.name==name, vi.lights)
        if len(viewerLights)==1:
            viewerLight = viewerLights[0]
        elif len(viewerLights)>1:
            print 'WARNING: more than one light found for the num: %d'%lightnum
            return
        else:
            print 'WARNING: light nb: %d not found'%lightnum
            return

        kw['tagModified']=False
        apply( viewerLight.Set, (), kw)



class AddClipPlane(Command):
    def doit(self, object, clip, side=-1, inh=0):
        if not self.vf.hasGui:
            return
        vi = self.vf.GUI.VIEWER
        viewerObj = vi.FindObjectByName(object)
        if not viewerObj:
            print 'WARNING: object %s not found'%object
            return

        viewerClips = filter(lambda x, name=clip: x.name==name, vi.clipP)
        if len(viewerClips)==1:
            viewerClip = viewerClips[0]
        elif len(viewerClips)>1:
            print 'WARNING: more than one clipping plane found for the name: %s'%clip
            return
        else:
            print 'WARNING: camera %s not found'%clip
            return

        viewerObj.AddClipPlane( viewerClip, side, inh )


        
class SetClip(Command):

    def doit(self, clip, **kw):
        if not self.vf.hasGui:
            return
        vi = self.vf.GUI.VIEWER
        viewerClips = filter(lambda x, name=clip: x.name==name, vi.clipP)
        if len(viewerClips)==1:
            viewerClip = viewerClips[0]
        elif len(viewerClips)>1:
            print 'WARNING: more than one clipping plane found for the name: %s'%clip
            return
        else:
            print 'WARNING: camera %s not found'%clip
            return

        kw['tagModified']=False
        apply( viewerClip.Set, (), kw)



class ViewPoints(Command):
    """None <- view(name, mode='save' or 'restore')
    Command to save current transformation of root node
    """

    def __init__(self):
        Command.__init__(self)
        self.views = []
        self.names = []
        self.current = -1


    def doit(self, name=None, index=None, mode='add'):
        if not self.vf: return
        root = self.vf.GUI.VIEWER.rootObject
        if name is None:
            name = 'View'+str(len(self.views))
        if mode=='set':
            self.names = [ name ]
            self.views = [ (root.translation, root.rotation, root.scale,
                            root.pivot) ]
            self.current = 1
            
        elif mode=='add':
            self.names.append( name )
            self.views.append( (root.translation, root.rotation, root.scale,
                                root.pivot) )
            self.current = len(self.views)
            
        elif mode=='previous':
            self.names.append( name )
            self.views.append( (root.translation, root.rotation, root.scale,
                                root.pivot) )
            index = max(self.current-1, 0)
            self.go(index)
                
        elif mode=='next':
            index = min(self.current+1, len(self.views))
            self.go(index)

        elif mode=='go':
            if index>-1 and index<len(self.views):
                self.go(index)

    def go(self, index):
        #print 'going to ',self.names[index]
        tr = self.views[index]
        root = self.vf.GUI.VIEWER.rootObject
        root.translation = tr[0]
        root.rotation = tr[1]
        root.scale = tr[2]
        root.pivot = tr[3]
        self.current=index
        self.vf.GUI.VIEWER.Redraw()

    def __call__(self, name=None, mode='add', **kw):
        """None <- viewerPoint(name=None, mode='add', **kw)
        mode in 'set', 'add', 'go', 'next', previous'
        """
        kw['name'] = name
        kw['mode'] = mode
        apply( self.doitWrapper, (), kw)



class RotateScene(Command):
    """None <- rotateScene(axis=(0,1,0), stepSize=0.0, nbSteps=0, pause=0.0, object=None)
Command to rotate 'object' about an arbitrary 'axis' 'nbSteps' times
object defaults to the root object (i.e. the complete scene)
by default the rotation will be a full turn in increments of 5 degrees.
Specifying a nSteps of -1 will create an endless loop.
The commands stop() method has to be called to break out of the loop
    """

    def __init__(self):
        Command.__init__(self)
        self._redraw = True


    def doit(self, axis=(0,1,0), stepSize=0.0, nbSteps=0, pause=0.0,
             object=None):
        if stepSize is None or stepSize==0.0:
            stepSize = 5*pi/180.
        else:
            stepSize = stepSize*pi/180.

        if nbSteps is None or nbSteps==0:
            nbSteps = pi*2/stepSize
 
        viewer = self.vf.GUI.VIEWER
        if object is None:
            object = viewer.rootObject
            
        self.stopFlag = 0
        step = 0
        matrix = rotax(numpy.zeros(3), numpy.array( axis ), stepSize)
        t1 = time()
        while not self.stopFlag:
            object.ConcatRotation(matrix.ravel())
            if self._redraw:
                viewer.Redraw()
                viewer.cameras[0].update()
            if pause > 0.0:
                sleep(pause)
            step = step+1
            if nbSteps > 0.0 and step >= nbSteps:
                break
        t2 = time()
        #print 'FrameRate = %4.1f'%(step/(t2-t1),), step
        

    def stop(self):
        self.stopFlag = 1

        
    def __call__(self, axis=(0,1,0), stepSize=0.0, nbSteps=0,
                 pause=0.0, object=None, **kw):
        """None <- rotateScene(axis=(0,1,0), stepSize=0.0, nbSteps=0, pause=0.0, object=None)
"""
        self._redraw = kw.get('redraw', True)
        kw['redraw'] = False
        apply( self.doitWrapper, (axis, stepSize, nbSteps, pause), kw )



class CenterScene(Command):
    """None <- centerScene()
    Command to scale and translate the scene to make it fit in the view frustum
    """

    def onAddCmdToViewer(self):
        self.vf.userpref.add('Center Scene','firstObjectOnly',
               validValues=['firstObjectOnly','always', 'never', 'ask'],
               callbackFunc=[self.doit_cb],
               category="DejaVu",
               doc="""the value of this preference defines whether\
the sceen is centered and tranformed to fit into the field\
of view when a new object is loaded""")
        


    def doit_cb(self, name, old_value, new_value):
        if self.vf.hasGui: 
            pass

        
    def doit(self, mode=None):
        choices = self.vf.userpref['Center Scene']['validValues']
        if mode is None: mode=self.vf.userpref['Center Scene']['value']
        else: assert mode in choices
        if mode=='never': return
        if mode==choices[0] and len(self.vf.objects)>1:
            return
        if mode=='ask':
            from SimpleDialog import SimpleDialog
            t= 'Do you want to center scene?'
            d=SimpleDialog(self.vf.GUI.ROOT, text=t,
                buttons=['yes','no'], default=0,
                title='Center Scene?')
            ok=d.go()
            if ok==1: return
        if self.vf.hasGui:
            self.vf.GUI.VIEWER.NormalizeCurrentObject()
            self.vf.GUI.VIEWER.CenterCurrentObject()



class CenterGeom(Command):

    def negateCmdBefore(self, object, point):
        piv = tuple(object.pivot)
        #self.addUndoCall( (object, piv), {}, self.vf.centerGeom.name )
        return ([( self.vf.centerGeom, (object, piv), {})], self.vf.centerGeom.name )

    def doit(self, object, point):
        object.SetPivot( point )

    def __call__(self, object, point, **kw):
        """None <- centerGeom(geom, point3D) set the center of rotation
Geom can be either a tring or an instance of a DejaVu.Geom.Geom
The point3D is given in the global coodinates system.
"""
        if type(object)==types.StringType:
            vi = self.vf.GUI.VIEWER
            object = vi.FindObjectByName(object)
        apply( self.doitWrapper, (object, point), kw)
        

class CenterSceneOnPickedPixel(Command, ICOM):
    """This command allows a user to set the center of rotation of the entire
scene to the picked pixel.
"""
    
##     def onAddCmdToViewer(self):
##         if self.vf.hasGui:
##             sph = Spheres('flashSphere', vertices=((0,0,0),), radii=(0.3,),
##                           visible=0, materials=((0,1,1),))
##             self.vf.GUI.VIEWER.AddObject(sph, parent=self.vf.GUI.miscGeom)
##             self.flashSphere = sph
            
    def __init__(self, func=None):
        Command.__init__(self, func)
        ICOM.__init__(self)


    def getObjects(self, pick):
        # we override this else we get pick.hits but we need pick.even
        return pick


    def negateCmdBefore(self, obj):
        root = self.vf.GUI.VIEWER.rootObject
        piv = tuple(root.pivot)
        #self.addUndoCall( (root, piv), {}, self.vf.centerGeom.name )
        return ([(self.vf.centerGeom, (root, piv), {})], self.vf.centerGeom.name )
        

        
    def doit(self, object):
        g, background = self.vf.GUI.VIEWER.get3DPointFromPick(object)
        #print 'CenterSceneOnPickedVertices', g, background
        if not background:
            self.vf.centerGeom( 'root', g, topCommand=0, log=1)
            self.vf.flashSphere.Set(vertices=(g,))
            self.vf.flashSphere.flashT()


    def __call__(self, pick, **kw):
        """This command allows a user to set the center of rotation of the entire
scene to the a vertex specified by a picking operation.
This command is an interactive picking command and is aware of instance
matrices.
"""
        # we do not want this command to log or undo itself
        kw['topCommand'] = 0
        kw['busyIdle'] = 1
        apply( self.doitWrapper, (pick,), kw )


class CenterSceneOnVertices(Command, ICOM):
    """This command allows a user to set the center of rotation of the entire
scene to the a vertex specified by a picking operation.
This command is an interactive picking command and is aware of instance
matrices.
"""
    
    def __init__(self, func=None):
        Command.__init__(self, func)
        ICOM.__init__(self)


    def negateCmdBefore(self, obj):
        root = self.vf.GUI.VIEWER.rootObject
        piv = tuple(root.pivot)
        #self.addUndoCall( (root, piv), {}, self.vf.centerGeom.name )
        return ([(self.vf.centerGeom,  (root, piv), {})], self.vf.centerGeom.name )

        
    def doit(self, objects):
        # objects is pick.hist = {geom: [(vertexInd, intance),...]}
        vt = ViewerFramework.transformedCoordinatesWithInstances(self.vf,
                                                                 objects)
        g = [0,0,0]
        i = 0
        for v in vt:
            g[0] += v[0]
            g[1] += v[1]
            g[2] += v[2]
            i+=1
        g[0] = g[0]/i
        g[1] = g[1]/i
        g[2] = g[2]/i

        self.vf.centerGeom( 'root', g, topCommand=0, log=1)


    def __call__(self, nodes, **kw):
        """This command allows a user to set the center of rotation of the entire
scene to the a vertex specified by a picking operation.
This command is an interactive picking command and is aware of instance
matrices.
"""
        # we do not want this command to log or undo itself
        kw['topCommand']=0
        kw['busyIdle']=1
        apply( self.doitWrapper, (nodes,), kw )



class AlignGeoms(Command):

    # this is the non-interactive command (see AlignGeomsPCOM) which
    # does log itself
    
        # FIXME: A UNDO METHOD SHOULD BE IMPLEMENTED HERE
        
##      def setupUndoBefore(self, object):
##          geom1 = object[0]
##          t = geom1.translation
##          self.addUndoCall( (geom1.getName(),root, piv), {}, self.vf.centerGeom.name )

    def doit(self, geom1, vertInd1, geom2, vertInd2):
        vi = self.vf.GUI.VIEWER

        # "compute" translation vector
        vert1 = self.getVertex(geom1, vertInd1)
        vert2 = self.getVertex(geom2, vertInd2)
        v = []
        v.append(vert2[0] - vert1[0])
        v.append(vert2[1] - vert1[1])
        v.append(vert2[2] - vert1[2])
        v = numpy.array(v)

        # make sure geom1.Ri is up-to-date by calling FrameTransform()
        # oldCurrent = vi.currentObject
        geom1.FrameTransform()
        if vi.redirectTransformToRoot == 1:
            old = vi.redirectTransformToRoot
            vi.TransformRootOnly(0)
        else:
            old = 0

        # Note: adding the new translation is the
        # same as matrixmultiply Ri & v and then ConcatTranslation
        geom1.translation = geom1.translation + v

##  	d = numpy.array( v )
##  	d = numpy.concatenate( (d, [1.0]) )  # go to homogenous coords
##          rot = numpy.reshape( geom1.Ri, (4,4) )
##          trans =  numpy.dot( rot, d )[:3]

##          # Note to self: if you use SetTranslation instead it only works
##          # the first time!
##          geom1.ConcatTranslation(trans)

        if old == 1:
            vi.TransformRootOnly(1)


    def getVertex(self, geom, index):
        verts = geom.TransformedCoords(geom.LastParentBeforeRoot() )
        pickedVerts = numpy.take(verts, index, axis=0)
        vertex = numpy.sum(pickedVerts, 0)/len(pickedVerts)
        return list(vertex)


    def __call__(self, geom1, vertInd1, geom2, vertInd2, **kw):
        """describe this command for a programmer"""
        if type(geom1) is types.StringType :
            geom1 = self.vf.GUI.VIEWER.FindObjectByName(geom1)
        if type(geom2) is types.StringType :
            geom2 = self.vf.GUI.VIEWER.FindObjectByName(geom2)
        apply( self.doitWrapper, (geom1, vertInd1, geom2, vertInd2), kw )



class AlignGeomsPCOM(Command, ICOM):
    """Pick one or more vertices on geom1 and one or more vertices on geom2.
If more than one vertex is selected, the middle point (point1 and 2) of these
vertices is computed. A translation vector point2-point1 is computed and
applied to geom1. Point1 and point2 are displayed as spheres during this
operation and deleted when finished."""

    # This is the interactive picking command, which does not log itself and
    # will call AlignGeoms, which logs
    
    def __init__(self, func=None):
        Command.__init__(self, func)
        ICOM.__init__(self)
        self.vertInd1 = None # vertex index list of picked geom1
        self.vertInd2 = None # vertex index list of picked geom2
        self.geom1 = None # picked geom1
        self.geom2 = None # picked geom2


#    def onAddCmdToViewer(self):
#        if self.vf.hasGui:
#            if not self.vf.commands.has_key('setICOM'):
                ## FIXME makes ViewerFrameworj depend on PMV ... BAD !
#                self.vf.loadCommand('interactiveCommands', 'setICOM', 'Pmv',
#                                topCommand=0)
#            miscGeom = self.vf.GUI.miscGeom
#            self.masterGeom = Geom('pickSpheresGeom',shape=(0,0),
#                                   pickable=0, protected=True)
#            self.masterGeom.isScalable = 0
#            self.vf.GUI.VIEWER.AddObject(self.masterGeom, parent=miscGeom)
#            self.spheres = Spheres(name='pickSpheres', shape=(0,3),
#                               inheritMaterial=0, radii=0.3, quality=15,
#                               materials = ((0.,1.,0.),), protected=True) 
#
#            self.vf.GUI.VIEWER.AddObject(self.spheres, parent=self.masterGeom)


    def stopICOM(self):
        # Reset everything if ICOM is stopped
        self.vertInd1 = None 
        self.vertInd2 = None
        self.geom1 = None
        self.geom2 = None
#        self.spheres.Set(vertices=[], tagModified=False)
        self.vf.GUI.VIEWER.Redraw()
        
        
    def doit(self, object):
        if len(object)==0:
            return 'ERROR' # prevent logging if nothing picked

        vi = self.vf.GUI.VIEWER
        # first pick event
        if self.vertInd1 is None:
            self.geom1 = object[0]
            self.vertInd1 = self.getVertexIndex()
            vertex = self.getSphereVertex(self.geom1, self.vertInd1)
            self.spheres.Add(vertices=[vertex,])
            vi.Redraw()
        # second pick event
        elif self.vertInd1 is not None:
            self.vertInd2 = self.getVertexIndex()
            self.geom2 = object[0]
            vertex = self.getSphereVertex(self.geom1, self.vertInd1)
            self.spheres.Add(vertices=[vertex,])
            vi.Redraw()
            # reset to first picked  if vertices in same geom were picked
            if self.geom1 == self.geom2:
                self.geom2 = None
                self.vertInd2 = None
                oldspheres = self.spheres.vertexSet.vertices.array
                self.spheres.Set(vertices=oldspheres[:1], tagModified=False)
                vi.Redraw()
                return
                
            # call the non-interactive, logable command
            self.vf.alignGeomsnogui(self.geom1, self.vertInd1,
                                     self.geom2, self.vertInd2,
                                     topCommand=0, log=1)
            # now we are done and can reset everything 
            self.spheres.Set(vertices=[], tagModified=False)
            vi.Redraw()
            self.vertInd1 = None
            self.vertInd2 = None
            self.geom1 = None
            self.geom2 = None


    def getSphereVertex(self, geom, index):
        verts = geom.TransformedCoords( geom.LastParentBeforeRoot() )
        pickedVerts = numpy.take(verts, index, axis=0)
        vertex = numpy.sum(pickedVerts, 0)/len(pickedVerts)
        return list(vertex)
    

    def getVertexIndex(self):
        vi = self.vf.GUI.VIEWER
        pick = vi.lastPick
        geom, vertIndList = pick.hits.items()[0]
        return vertIndList[1]


    def __call__(self, nodes, **kw):
        """describe this command for a programmer"""
        # we do not want this command to log or undo itself
        kw['topCommand']=0
        kw['busyIdle']=1
        apply( self.doitWrapper, (nodes,), kw )



class PrintGeometryName(Command, ICOM):

    def __init__(self, func=None):
        Command.__init__(self, func)
        ICOM.__init__(self)

        
    def doit(self, objects):
        # object is a list of geometries
        for o in objects:
            self.vf.message(o.name)
            

    def __call__(self, objects, topCommand=0, **kw):
        # we do not want this command to log or undo itself
        if not kw.has_key('topCommand'): kw['topCommand'] = topCommand
        apply( self.doitWrapper, (objects,), kw )



class StopContinuousPicking(Command):
    def start(self):	
        #self.vf.GUI.ehm.RemoveCallback("<Motion>", 'motion_cb')
        self.vf.GUI.removeCameraCallback("<Motion>", 'motion_cb')

    def __call__(self, *args):
        self.start()

        
    def guiCallback(self):
        self.start()



class StartContinuousPicking(Command):
    """Start the contiguous selection mode"""

    def __init__(self, delay=100):
        Command.__init__(self)
        self.delay=delay
        self.alarmID = None
        self.cbManager = CallbackManager()

    def onAddCmdToViewer(self):
        self.cbManager.AddCallback(CallBackFunction( self.vf.unsolicitedPick))

    def start(self):	
        self.vf.GUI.addCameraCallback("<Motion>", self.motion_cb)


    def __call__(self, *args):
        self.start()

    def guiCallback(self):
        self.start()

    def _pick(self, event):
        # has to be first transformed in a DejaVu Camera Pick object
        pick = self.vf.DoPick( event.x, event.y, event=event )
        if pick:
            self.cbManager.CallCallbacks(pick)
        
    def motion_cb(self, event=None):
        if (self.alarmID):
            self.vf.GUI.ROOT.after_cancel(self.alarmID)
        self.alarmID = self.vf.GUI.ROOT.after(self.delay, self._pick, event)



class LoadColorMap(Command):
    """
    Command to Load a Color Map 
    """
    def onAddCmdToViewer(self):
        # load the rgb256_map  by default
        import ViewerFramework
        vfpath = ViewerFramework.__path__[0]
        idir = os.path.join(vfpath, 'ColorMaps/')
        cmap = os.path.join(idir, "rgb256_map.py")
        self.vf.loadColorMap(cmap, log=0)

    def guiCallback(self):
        # Update the level if the form exists already.
        import ViewerFramework
        vfpath = ViewerFramework.__path__[0]
        idir = os.path.join(vfpath, 'ColorMaps/')
        filename = self.vf.askFileOpen(idir=idir,
            types=[('color map files:', '*_map.py'),\
                   ('all files:', '*')],\
                title = 'Color Map File:')
        if not filename: return
        apply(self.doitWrapper, (filename,), {})


    def doit(self, filename):
        #colormap can be built from a filename
        name = os.path.splitext(os.path.basename(filename))[0]
        l = {}
        g = {}
        execfile(filename, g, l)
        newColorMap = None
        for name, object in l.items():
            if isinstance(object, ColorMap):
                newColorMap = object
                break
            
        #newColorMap = ColorMap(name, filename=filename)
        if newColorMap:
            #name should be uniq already
            for k in self.vf.colorMaps.keys():
                if k==name:
                    newColorMap.name = name + '_' + str(self.vf.colorMapCt)
                    self.vf.colorMapCt = self.vf.colorMapCt + 1
            self.vf.addColorMap(newColorMap)
            
        return newColorMap

    def __call__(self, filename, **kw):
        """
        None <- loadColorMap(filename)
        filename: file containing colorMap *_map.py
        """
        return apply( self.doitWrapper, (filename,), kw)



LoadColorMapGUIDescr =  {'widgetType':'Menu', 'menuBarName':'menuRoot',
                         'menuButtonName':'File',
                         'menuEntryLabel':'ColorMap'}               
 
LoadColorMapGUI = CommandGUI()
LoadColorMapGUI.addMenuCommand('menuRoot', 'File', 'Color Map', cascadeName='Import')



class SaveColorMap(Command):
    """
    Command to Save a Color Map 
    """

    def logString(self, *args, **kw):
        """return None as log string as we don't want to log this
"""
        pass



    def buildFormDescr(self, formName):
        if formName == 'saveCM':
            ifd = InputFormDescr(title = 'Save Color Map')
            cmNames = map(lambda x: (x, None), self.vf.colorMaps.keys())
            ifd.append({'name':'colorMapName',
                            'widgetType':ListChooser,
                            'wcfg':{'entries': cmNames,
                                    'title':'Choose a color map to save:',
                                    'lbwcfg':{'exportselection':0},
                                    'mode':'single','withComment':0, },
                            'gridcfg':{'sticky':'we', 'rowspan':4, 'padx':5}})
            return ifd



    def guiCallback(self):
        #force a redraw of form
        keys = self.vf.colorMaps.keys()
        if not len(keys):
            self.vf.warningMsg('currently no color maps in viewer')
            return
                
        if self.cmdForms.has_key('saveCM'):
            descr = self.cmdForms['saveCM']

        val = self.showForm('saveCM', force=1)
        if val=={}: return
        if not val: return
        if not len(val['colorMapName']):
            return 
        colorMapName = val['colorMapName'][0]
        import ViewerFramework
        vfpath = ViewerFramework.__path__[0]
        idir = os.path.join(vfpath, 'ColorMaps/')
        filename = self.vf.askFileSave(idir=idir,
            types=[('color map files:', '*_map.py'),\
                   ('all files:', '*')],\
            title = 'Color Map File:')
        if not filename: return
        apply(self.doitWrapper, (colorMapName, filename,), {})


    def doit(self, colorMapName, filename):
        assert colorMapName in self.vf.colorMaps.keys(), 'no colorMap of that name'
        colorMap = self.vf.colorMaps[colorMapName]
        colorMap.write(filename)
            

    def __call__(self, colorMapName, filename, **kw):
        """
        None <- saveColorMap(filename)
        colorMapName: name of colorMap to be written
        filename: file containing colorMap
        """
        apply( self.doitWrapper, (colorMapName, filename,), kw)



SaveColorMapGUIDescr =  {'widgetType':'Menu', 'menuBarName':'menuRoot',
                              'menuButtonName':'File',
                              'menuEntryLabel':'Color map'}               
 
SaveColorMapGUI = CommandGUI()
SaveColorMapGUI.addMenuCommand('menuRoot', 'File', 'Color Map', cascadeName='Save')



class CreateColorMap(Command):
    """
    Command to Create a Color Map 
    NB: colormaps are created from files by LoadColorMap
    """

    def guiCallback(self):
        apply(self.doitWrapper, (), {'viewer':self.vf.GUI.VIEWER, 'log':0})


    def accept_cb(self, event=None):
        #print "accept_cb"
        self.cmg.apply_cb()
        if self.colorMaps.has_key('self.cmg.name') is False:
            self.vf.addColorMap(self.cmg)
            self.cmg.apply.configure(command=self.cmg.apply_cb)


    def doit(self, name='colormap', ramp=None, geoms={},
             legend=None,  mini='not passed', maxi='not passed', viewer=None, log=0):

        if not viewer:
            viewer = self.vf.GUI.VIEWER

        if ramp and type(ramp) is types.StringType:
            #ramp can only be a string
            ramp = eval(ramp + '()')

        if name != 'colormap' and self.vf.colorMaps.has_key(name):
            self.cmg = self.vf.colorMaps[name]
            self.cmg.showColormapSettings_cb()
        else:
            i = 1
            while self.vf.colorMaps.has_key(name):
                name = 'colormap' + str(i)
                i += 1

            self.cmg = ColorMapGUI(name=name, ramp=ramp, viewer=viewer,
                                   mini=mini, maxi=maxi,
                                   allowRename=True, modifyMinMax=True)

        self.cmg.apply.configure(command=self.accept_cb)
        #self.cmg.apply.configure(text='Accept', command=self.accept_cb)
        ##FIX THIS TO BUILD LOG STRING FROM GUI ...???...


    def __call__(self, name='colormap', ramp='RGBARamp', filename=None, **kw):
        """
        None <- createColorMap(name, ramp='RGBARamp', filename=None, **kw)
        name:         identifier 
        ramp:         color ramp string ('RGBARamp', 'RedWhiteARamp',
                      'WhiteBlueARamp' or 'RedWhiteBlueARamp'
        """
        if not kw.has_key('redraw'): kw['redraw'] = 1
        if not kw.has_key('viewer'): kw['viewer'] = self.vf.GUI.VIEWER
        kw['ramp'] = ramp
        kw['name'] = name
        kw['log'] = 0
        apply( self.doitWrapper, (), kw)



CreateColorMapGUIDescr =  {'widgetType':'Menu', 'menuBarName':'menuRoot',
                              'menuButtonName':'Color',
                              'menuEntryLabel':'ColorMap'}               
 
CreateColorMapGUI = CommandGUI()
CreateColorMapGUI.addMenuCommand('menuRoot', 'Color', 'Create', cascadeName='Color Map')



class ColorMapEditor(Command):
    """
    Create a GUI to edit a color map object
    """
        
    def buildFormDescr(self, formName):
        if formName == 'editCM':
            self.interpOn = Tkinter.IntVar()
            #self.id = Tkinter.StringVar()
            self.showLabels = Tkinter.IntVar()
            self.showLabels.set(1)
            ifd = InputFormDescr(title = 'Select Color Map To Edit')
            #cmNames = self.vf.colorMaps.keys()
            cmNames = map(lambda x: (x, None), self.vf.colorMaps.keys())
            #could use this to build a new one
            #self.id.set(cmNames[0])
#            ifd.append({'widgetType':Pmw.ComboBox,
#            'name':'cmap',
#            'wcfg':{'label_text':'Color Maps',
#                    'entryfield_value':self.id.get(),
#                    'labelpos':'w',
#                    'listheight':'80',
#                    'scrolledlist_items': cmNames,
#                    #'selectioncommand': self.update,
#                    },
#            'gridcfg':{'sticky':'w'}})
            ifd.append({'name':'colorMapName',
                            'widgetType':ListChooser,
                            'wcfg':{'entries': cmNames,
                                    'title':'Choose a color map to edit:',
                                    'lbwcfg':{'exportselection':0},
                                    'mode':'single','withComment':0, },
                            'gridcfg':{'sticky':'we', 'rowspan':4, 'padx':5}})
            return ifd



    def guiCallback(self):
        # Update the level if the form exists already.
        if not len(self.vf.colorMaps.keys()):
            print 'no color maps in viewer'
            return
        if self.cmdForms.has_key('editCM'):
            descr = self.cmdForms['editCM'].descr
        val = self.showForm('editCM',force=1)
        if val=={}: return
        if not val: return
        cmap = val['colorMapName'][0]
        vi = self.vf.GUI.VIEWER
        apply(self.doitWrapper, (cmap,), {'viewer':vi, 'log':0})


    def doit(self, cmap, viewer=None):
        
        if type(cmap) is types.StringType:
            if self.vf.colorMaps.has_key(cmap):
                cmap=self.vf.colorMaps[cmap]
            else:
                print 'no such color map'

        assert isinstance(cmap, ColorMap)

        if isinstance(cmap, ColorMapGUI):
            if not cmap.master.winfo_ismapped():
                cmap.showColormapSettings_cb()
                self.cmg = cmap
        else:
            if viewer is None: 
                viewer = self.vf.GUI.VIEWER

            self.cmg = ColorMapGUI(cmap, viewer=viewer, allowRename=False, modifyMinMax=True)
            self.vf.colorMaps[self.cmg.name] = self.cmg


    def __call__(self, cmap, viewer=None, **kw):
        """
        None <- showCMGUI(cmap='cmap', **kw)
        cmap:         ColorMap or its name
        """
        if type(cmap) is types.StringType:
            if cmap not in self.vf.colorMaps.keys():
                print 'unknown color map name: ', cmap
                return 'ERROR'
            else:
                cmap = self.vf.colorMaps[cmap]
        elif not isinstance(cmap, ColorMap):
            print 'specified colormap not a ColorMap instance'
            return 'ERROR'
        if not viewer:
            viewer = self.vf.GUI.VIEWER
        kw['log'] = 0
        kw['viewer'] = viewer

        apply( self.doitWrapper, (cmap,), kw)



ColorMapEditorGUIDescr =  {'widgetType':'Menu', 'menuBarName':'menuRoot',
                           'menuButtonName':'Edit',
                           'menuEntryLabel':'ColorMap'}               
 
ColorMapEditorGUI = CommandGUI()
#EditColorMapGUI.addMenuCommand('menuRoot', 'Edit', 'ColorMap')
ColorMapEditorGUI.addMenuCommand('menuRoot', 'Color', 'Edit', cascadeName='Color Map')



class EditColorMap(Command):
    """
    Command to modify a color map object
    """

    def doit(self, cmap, ramp=None, mini=None, maxi=None):
        cfg = {}
        if ramp:
            cfg['ramp']=ramp
        if mini:
            cfg['mini']=mini
        if maxi:
            cfg['maxi']=maxi 
        apply( cmap.configure, (), cfg)
        
    def __call__(self, cmap, ramp=None, mini=None, maxi=None, **kw):
        """
        None <- editCM(cmap, ramp=None, mini=None,
                 maxi=None, name=None, **kw)
        """
        if type(cmap) is types.StringType:
            if cmap not in self.vf.colorMaps.keys():
                print 'unknown color map name: ', cmap
                return 'ERROR'
            cmap = self.vf.colorMaps[cmap]
        elif not isinstance(cmap, ColorMap):
            print 'specified colormap not a ColorMap instance'
            return 'ERROR'
        kw['ramp']=ramp
        kw['mini']=mini
        kw['maxi']=maxi
        apply( self.doitWrapper, (cmap,), kw)



class RenderLargeImageCommand(Command):
    """
Package : ViewerFramework
Module  : dejaVuCommands
Class   : RenderLargeImageCommand
Command : renderLargeImage

Description:
This command allows the user to enable the rendering of images
larger than the screen.

Synopsis:
None <- renderLargeImage(width=None, height=None, border=0,
                          outputFile='test.jpg', backbuffer=True)
width, height   : to specify either the width or the height.
border          : (default 0) specify the size of a border can be any
                  any small integer between 1 and 20.
outputFile      : path to a output file. Use .tif to avoid compression
backBuffer      : default True, Boolean flag turn to False to see
                  the tiles render.
checkeredBackground: (False)

Keywords : large, image, tile rendering
"""


    def logString(self, *args, **kw):
        """return None as log string as we don't want to log this
"""
        pass


    def doit(self,
             width=None,
             height=None,
             border=0,
             outputFile='test.tif',
             backBuffer=True,
             checkeredBackground=False):
        #print "RenderLargeImageCommand.doit"

        if width is None and height is None:
            self.warningMsg(
                "Please either specify the width or the height of the camera."
            )

        vfgui = self.vf.GUI

#        cam = vfgui.VIEWER.cameras[0]
#        camHeight = cam.height
#        camWidth = cam.width
#        camrootX = cam.master.master.master.winfo_rootx()
#        camrootY = cam.master.master.master.winfo_rooty()
#
#        # We set the camera to the biggest possible size to avoid multiple drawing
#        lLargestWidth = vfgui.screenWidth
#        lLargestHeight = lLargestWidth * float(height)/width
#        if lLargestHeight > vfgui.screenHeight:
#            lLargestHeight = vfgui.screenHeight
#            lLargestWidth = lLargestHeight * float(width)/height
#        status = self.vf.setCameraSize(lLargestWidth,
#                                       lLargestHeight,
#                                       xoffset=0,
#                                       yoffset=0,
#                                       topCommand=0)
#        if status=='ERROR':
#            return 'ERROR'

        vi = vfgui.VIEWER
        vi.stopAutoRedraw()
        vi.update()

        vi.startTileRendering(width=width,
                              height=height,
                              border=border,
                              outputFile=outputFile,
                              backBuffer=backBuffer,
                              checkeredBackground=checkeredBackground)
        vi.OneRedraw()

#        # set camera to its previous size and position
#        self.vf.setCameraSize(camWidth, 
#                              camHeight, 
#                              xoffset=camrootX,
#                              yoffset=camrootY, 
#                              topCommand=0)


    def __call__(self, width=None, height=None, border=0,
                 outputFile='test.jpg', backBuffer=True,
                 checkeredBackground=False, **kw):
        #print "RenderLargeImageCommand.__call__"
        kw['width'] = width
        kw['height'] = height
        kw['border'] = border
        kw['outputFile'] = outputFile
        kw['backBuffer'] = backBuffer
        kw['checkeredBackground'] = checkeredBackground
        kw['redraw'] = True
        apply(self.doitWrapper, (), kw)
        
        
    def guiCallback(self):
        #print "RenderLargeImageCommand.guiCallback"

        # in case we arrive here after a cancel and a resizing
        if self.cmdForms.has_key('tileRendering'):
            self.fixHeight_cb()
        
        val = self.showForm('tileRendering', 
                            okCfg={'text':'Render Image'},
                            cancelCfg={'text':'Cancel', 'command':self.cancel_cb} )
            
        if not val=={}:
            del val['constraint']
            if val.has_key('filebrowse'):
                del val['filebrowse']
            if val.has_key('outputFile') and not val['outputFile']:
                val['outputFile'] = './test.tif'
            val['redraw'] = False
            apply(self.doitWrapper, (), val)


    def getConstrainedWidth(self, mode, height, width):
        #print "RenderLargeImageCommand.getConstrainedWidth"
        # compute val2 as a function of val1
        if mode == 'square':
            return height
        elif mode == 'keep aspect ratio':
            cam = self.vf.GUI.VIEWER.currentCamera
            return round( height * cam.width/float(cam.height) )
        else:
            return width


    def getConstrainedHeight(self, mode, width, height):
        #print "RenderLargeImageCommand.getConstrainedHeight"
        # compute val2 as a function of val1
        if mode == 'square':
            return width
        elif mode == 'keep aspect ratio':
            cam = self.vf.GUI.VIEWER.currentCamera
            return round( width * cam.height/float(cam.width) )
        else:
            return height


    def fixHeight_cb (self, event=None):
        #print "RenderLargeImageCommand.fixHeight_cb"
        # called when width thumbwheel changes
        f = self.cmdForms['tileRendering']
        mode = f.descr.entryByName['constraint']['widget'].get()
        width = f.descr.entryByName['width']['widget'].value
        height = f.descr.entryByName['height']['widget'].value
        cam = self.vf.GUI.VIEWER.currentCamera
        if mode != 'None':
            nheight = self.getConstrainedHeight(mode, width, height)
            f.descr.entryByName['height']['widget'].set(nheight, update=0)
            if (mode == 'square') and (cam.width != cam.height):
                if cam.width < cam.height:
                    tileSize = cam.width
                else:
                    tileSize = cam.height
                self.vf.setCameraSize(tileSize, tileSize, topCommand=0)
        else:
            camWidth = int( cam.height * width/float(height) )
            self.vf.setCameraSize(width=camWidth, height=cam.height, 
                                  topCommand=0)


    def fixWidth_cb (self, event=None):
        #print "RenderLargeImageCommand.fixWidth_cb"
        # called when height thumbwheel changes
        f = self.cmdForms['tileRendering']
        mode = f.descr.entryByName['constraint']['widget'].get()
        width = f.descr.entryByName['width']['widget'].value
        height = f.descr.entryByName['height']['widget'].value
        cam = self.vf.GUI.VIEWER.currentCamera
        if mode != 'None':
            nwidth = self.getConstrainedWidth(mode, height, width)
            f.descr.entryByName['width']['widget'].set(nwidth, update=0)
            if (mode == 'square') and (cam.width != cam.height):
                if cam.width < cam.height:
                    tileSize = cam.width
                else:
                    tileSize = cam.height
                self.vf.setCameraSize(tileSize, tileSize, topCommand=0)
        else:
            camHeight = int( cam.width * height/float(width) )
            self.vf.setCameraSize(width=cam.width, height=camHeight,
                                  topCommand=0)

        
    def buildFormDescr(self, formName):
        #print "RenderLargeImageCommand.buildFormDescr"
        if formName == 'tileRendering':
            idf = InputFormDescr(title="Tile Rendering parameters")
            cam = self.vf.GUI.VIEWER.cameras[0]
            idf.append({'name':'width',
                        'widgetType':ThumbWheel,
                        'wcfg':{ 'labCfg':{'text':'Requested Width: ', 
                                           'font':(ensureFontCase('helvetica'),12,'bold')},
                                 'showLabel':1, 'width':100,
                                 'min':0, 
                                 'callback':self.fixHeight_cb,
                                 'type':int, 'precision':1,
                                 'value':cam.width,'continuous':1,
                                 'oneTurn':500, 'wheelPad':2, 'height':20},
                        'gridcfg':{'sticky':'e'}})
                        
            idf.append({'name':'height',
                        'widgetType':ThumbWheel,
                        'wcfg':{ 'labCfg':{'text':'Requested Height: ', 
                                           'font':(ensureFontCase('helvetica'),12,'bold')},
                                 'showLabel':1, 'width':100,
                                 'min':0, 
                                 'callback':self.fixWidth_cb,
                                 'type':int, 'precision':1,
                                 'value':cam.height,'continuous':1,
                                 'oneTurn':500, 'wheelPad':2, 'height':20},
                        'gridcfg':{'sticky':'e'}})

            idf.append({'name':'constrLab',
                        'widgetType':Tkinter.Label,
                        'wcfg':{ 'text':'Constraints: '},
                        'gridcfg':{'sticky':'wens', 'row':0, 'column':1}})
            
            modes = ['None', 'square', 'keep aspect ratio']
            idf.append({'name':'constraint',
                        'widgetType':Pmw.ComboBox,
                        'wcfg':{ 'scrolledlist_items':modes, 'dropdown':1,
                                 'selectioncommand':self.fixHeight_cb,
                                 'entryfield_entry_width':8},
                        'defaultValue':'keep aspect ratio',
                        'gridcfg':{'sticky':'wens', 'row':1, 'column':1},
                        })

            idf.append({'name':'border',
                        'widgetType':ThumbWheel,
                        'wcfg':{ 'labCfg':{'text':'Border: ', 
                                           'font':(ensureFontCase('helvetica'),12,'bold')},
                                 'showLabel':1, 'width':100,
                                 'min':0, 'max':20, 'type':int,
                                 'precision':1,
                                 'value':0,'continuous':1,
                                 'oneTurn':2, 'wheelPad':2, 'height':20},
                        'gridcfg':{'sticky':'e'}})

            idf.append({'name':'backBuffer',
                        'widgetType':Tkinter.Checkbutton,
                        'defaultValue':1,
                        'wcfg':{'text':'Back Buffer',
                                'variable':Tkinter.IntVar()},
                        'gridcfg':{'sticky':'w', 'columnspan':2}
                        })

            idf.append({'name':'checkeredBackground',
                        'widgetType':Tkinter.Checkbutton,
                        'defaultValue':0,
                        'wcfg':{'text':'Checkered Background',
                                'variable':Tkinter.IntVar()},
                        'gridcfg':{'sticky':'w', 'columnspan':2}
                        })

            # File to create
            idf.append({'name':'outputFile',
                        'widgetType':Pmw.EntryField,
                        'tooltip':'Enter the outputFile',
                        'wcfg':{'label_text':'Output File:',
                                'labelpos':'w',
                                'value':'test.tif'},
                        'gridcfg':{'sticky':'w'},
                        })

            idf.append({'widgetType':SaveButton,
                        'name':'filebrowse',
                        'wcfg':{'buttonType':Tkinter.Button,
                                'title':'Save In File ...',
                                'types':[('TIFF', '*.tif'),
                                         ('JPEG','*.jpg'),
                                         ('All','*.*')],
                                'callback':self.setEntry_cb,
                                'widgetwcfg':{'text':'BROWSE'}},
                        'gridcfg':{'row':-1, 'sticky':'we'}})

            return idf

    ### ##################################################################
    ### CALLBACK FUNCTIONS
    ### ##################################################################
        
    def setEntry_cb(self, filename):
        #print "RenderLargeImageCommand.setEntry_cb"
        ebn = self.cmdForms['tileRendering'].descr.entryByName
        entry = ebn['outputFile']['widget']
        entry.setentry(filename)


    def cancel_cb(self):
        #print "RenderLargeImageCommand.cancel_cb"
        pass
        #cam = self.vf.GUI.VIEWER.cameras[0]
        #self.camHeight = cam.height
        #self.camWidth = cam.width
        #self.camrootX = cam.rootx
        #self.camrootY = cam.rooty
        ##self.vf.showHideGUI('all', 1, topCommand=0)
        #self.vf.setCameraSize(self.camWidth, self.camHeight,
        #                      xoffset=self.camrootX, yoffset=self.camrootY, 
        #                      topCommand=0)
        


RenderLargeImageGUI = CommandGUI()
RenderLargeImageGUI.addMenuCommand('menuRoot', '3D Graphics', 'Render Large Image')


class SpinCommand(Command):
    """
Package : ViewerFramework
Module  : dejaVuCommands
Class   : SpinCommand
Command : spin

Description:
Open the spin gui

Synopsis:

Keywords :
"""

    def logString(self, *args, **kw):
        """return None as log string as we don't want to log this
"""
        pass


    def doit(self):
        self.vf.GUI.VIEWER.currentCamera.trackball.showSpinGui()


spinGUI = CommandGUI()
spinGUI.addMenuCommand('menuRoot', '3D Graphics', 'Spin - Bounce - Oscillate')



class SetCameraSizeCommand(Command):
    """
    Package : ViewerFramework
    Module  : dejaVuCommands
    Class   : SetCameraSizeCommand
    Command : setCameraSize

    Description    
    Command allowing the user to resize the camera to the given width, height, xoffset and yoffset

    Synopsis:
    width, height <- setCameraSize(width, height, xoffset=None, yoffset=None)

    width    : int to specify camera width in pixels
    height   : int to specify camera height in pixels
    xoffset  : int to specify the x position of the left corner of the camera
               relative to the left corner of the camera
    yoffset  : int to specify the y position of the left corner of the camera
               relative to the left corner of the camera
    """

    def doit(self, width, height, xoffset=0, yoffset=0):
        """
width    : int to specify camera width in pixels
height   : int to specify camera height in pixels
xoffset  : int to specify the x position of the left corner of the camera
           relative to the left corner of the camera
yoffset  : int to specify the y position of the left corner of the camera
           relative to the left corner of the camera
"""
        vfgui =self.vf.GUI 
        vi = vfgui.VIEWER
        if not vfgui.isCameraFloating():
            # Camera is docked

            # I was unable to find out how to resize the master such that
            # the camera ends up with the right size, because the message_box
            # expands along with the camera.  So I disable expansion of the
            # message box when the camera size is set for a docked camera

            # disable message box expansion
            mb = vfgui.MESSAGE_BOX
            try:
                opts = mb.pack_info()
                mb.pack_forget()
                opts['expand'] = 0
                apply( mb.pack, (), opts)
                MESSAGE_BOX_reqheight = vfgui.MESSAGE_BOX.winfo_reqheight()
            except: #mb.pack_info() hrows exception
                MESSAGE_BOX_reqheight = 0
            # first set the width as this might add scroll bars under menus and
            # hence add the thir height
            c = vi.cameras[0]
            off = 2*c.frameBorderWidth
            vfgui.setGeom(xoffset, yoffset, width+off, c.height)
            #vi.update()

            # now compute height needed
            #print 'MENU', vfgui.mBarFrame.winfo_reqheight()
            #print 'Info', vfgui.infoBar.winfo_reqheight()
            #print 'MESSAGE', vfgui.MESSAGE_BOX.winfo_reqheight()
            #print 'camera', height+off
            h = vfgui.mBarFrame.winfo_reqheight() + \
                height + off +\
                vfgui.infoBar.winfo_reqheight() + \
                MESSAGE_BOX_reqheight
            #print 'TOTAL', h, width+off, h+off

            # resize the top widget.  At this point only thw camera should
            # expand, and reach the desired size
            vfgui.setGeom(xoffset, yoffset, width+off, h)
            vi.update()

            # now restore the message_box's packing options so that it scales
            # again when the user resizes the app
            
        else:
            # Camera is floating
            toplevel = self.vf.GUI.vwrCanvasFloating
            #geom = '%dx%d+%d+%d' % (width, height, xoffset, yoffset)
            #toplevel.geometry(geom)

            # Need to reposition the camera and the menu
            vi.currentCamera.Set(rootx=xoffset, rooty=yoffset, width=width, height=height)
            #menux, menuy, menuw, menuh = self.vf.GUI.getGeom()
            # give Tk a chance to handle the event
            self.vf.GUI.VIEWER.update()
            
            #nwidth = toplevel.cget('width')
            #nheight = toplevel.cget('height')

            # FIXME not sure why she sets the geometry of the menu window here
            #self.vf.GUI.setGeom(xoffset, yoffset+height+30, width,  menuh)

        #return nwidth, nheight
        if self.vf.GUI.VIEWER.suspendRedraw is False:
            self.vf.GUI.VIEWER.OneRedraw()


    def buildFormDescr(self, formName):
        if formName == 'setCameraSize':
            idf = InputFormDescr(title="Set Camera Size:")
            cam = self.vf.GUI.VIEWER.cameras[0]
            idf.append({'name':'width',
                        'widgetType':ThumbWheel,
                        'wcfg':{ 'labCfg':{'text':'Camera Width: ', 
                                           'font':(ensureFontCase('helvetica'),12,'bold')},
                                 'showLabel':1, 'width':100,
                                 'min':0, 'max':self.vf.GUI.screenWidth,
                                 'type':int, 'precision':1,
                                 'value':cam.width,'continuous':1,
                                 'oneTurn':200, 'wheelPad':2, 'height':20},
                        'gridcfg':{'sticky':'e'}})
                        
            idf.append({'name':'height',
                        'widgetType':ThumbWheel,
                        'wcfg':{ 'labCfg':{'text':'Camera Height: ', 
                                           'font':(ensureFontCase('helvetica'),12,'bold')},
                                 'showLabel':1, 'width':100,
                                 'min':0, 'max':self.vf.GUI.screenHeight,
                                 'type':int, 'precision':1,
                                 'value':cam.height,'continuous':1,
                                 'oneTurn':200, 'wheelPad':2, 'height':20},
                        'gridcfg':{'sticky':'e'}})
            if self.vf.GUI.floatCamVariable.get():
                defRootx = self.vf.GUI.VIEWER.currentCamera.rootx
                defRooty = self.vf.GUI.VIEWER.currentCamera.rooty
            else:
                defRootx = self.vf.GUI.ROOT.winfo_rootx()
                defRooty = self.vf.GUI.ROOT.winfo_rooty()

            idf.append({'name':'xoffset',
                        'widgetType':ThumbWheel,
                        'wcfg':{ 'labCfg':{'text':'Camera X Offset: ', 
                                           'font':(ensureFontCase('helvetica'),12,'bold')},
                                 'showLabel':1, 'width':100,
                                 'min':0, 
                                 'type':int, 'precision':1,
                                 'value':defRootx,'continuous':1,
                                 'oneTurn':50, 'wheelPad':2, 'height':20},
                        'gridcfg':{'sticky':'e'}})

            idf.append({'name':'yoffset',
                        'widgetType':ThumbWheel,
                        'wcfg':{ 'labCfg':{'text':'Camera Y Offset: ', 
                                           'font':(ensureFontCase('helvetica'),12,'bold')},
                                 'showLabel':1, 'width':100,
                                 'min':0, 'max':self.vf.GUI.screenHeight,
                                 'type':int, 'precision':1,
                                 'value':defRooty,'continuous':1,
                                 'oneTurn':50, 'wheelPad':2, 'height':20},
                        'gridcfg':{'sticky':'e'}})
            
            return idf

    def guiCallback(self):
        val = self.showForm('setCameraSize')
        if val:
            width = val['width']
            del val['width']
            height = val['height']
            del val['height']
            apply(self.doitWrapper, (width, height), val)
        
    

    def __call__(self, width, height, xoffset=0, yoffset=0, **kw):
        """
        width, height <-self.setCameraSize(width, height, xoffset=None, yoffset=None, **kw)
        width    : int to specify camera width in pixels
        height   : int to specify camera height in pixels
        xoffset  : int to specify the x position of the left corner of the camera
                   relative to the left corner of the camera
        yoffset  : int to specify the y position of the left corner of the camera
                   relative to the left corner of the camera
       
        """
        kw['xoffset']=xoffset
        kw['yoffset']=yoffset
        kw['redraw']=True
        return apply(self.doitWrapper, (width, height), kw)



SetCamSizeGUI = CommandGUI()
SetCamSizeGUI.addMenuCommand('menuRoot', '3D Graphics', 'Set Camera Size')



class SaveImage(Command):
    """This command allows to save the content of the current frambuffer as
an image into a file. The file format will be defined by the extension used
in the filename. Currently de follwoing foramt are supported:
BMP, EPS, GIF, IM, JPEG, PNG, PPM, TIFF or TIF, PDF.
    \nPackage : ViewerFramework
    \nModule  : dejaVuCommands
    \nClass   : SaveImage
    \nCommand : saveImage
    \nSynopsis:\n
        None <- saveImage(self,filename, **kw)
    \nfilename --- name of the file
    \nDependencies: require the Python Imaging Library
    \nregression test: testdir/testSaveImage.py
"""

#    def logString(self, *args, **kw):
#        """return None as log string as we don't want to log this
#"""
#        pass


    def checkDependencies(self, vf):
        import Image

  
    def doit(self, filename, transparentbg):
        # lift
        self.vf.GUI.ROOT.lift()
        vi = self.vf.GUI.VIEWER
        vi.OneRedraw()
        cam = self.vf.GUI.VIEWER.currentCamera
        if transparentbg:    
            cam.SaveImage(filename, transparentBackground=True)
        else:
            cam.SaveImage(filename)
   

    def buildFormDescr(self, formName):
        
        idf = InputFormDescr(title="SaveImage")
        idf.append({'name':"TB",
                        'widgetType':Tkinter.Checkbutton,
                        'wcfg':{'text':'Transparent Background', 'variable':Tkinter.IntVar()},
                        'command':self.switch_type_cb,
                        'gridcfg':{'sticky':'nw'}})
        
        idf.append({'name':'File',
                        'widgetType':Pmw.EntryField,
                        'tooltip':'Enter the outputFile',
                        'wcfg':{'label_text':'Output File:',
                                'labelpos':'wnse',
                                },
                        'gridcfg':{'sticky':'wnse'},
                        })
    
        idf.append({'widgetType':SaveButton,
                        'name':'filesave',
                        'wcfg':{'buttonType':Tkinter.Button,
                                'title':'Save as File',
                                'types':[('PNG files', '*.png'),
                                         ('TIFF files', '*.tif'),
                                         ('JPEG files', '*.jpg'),
                                         ('GIF files', '*.gif'),
                                         ('PPM files', '*.ppm'),
                                         ('EPS files', '*.eps'),
                                         ('IM files', '*.im'),
                                         ('PDF files', '*.pdf'),
                                         ('all files', '*.*')],
                                'callback':self.setEntry_cb,
                                'widgetwcfg':{'text':'Choose'}},
                        'gridcfg':{'sticky':'we','row':-1}})
        
        
        idf.append({'name':'cite',
                    'widgetType':Tkinter.Button,
                    'wcfg':{'text':'Cite',
                            'command':self.cite_cb,
                           },
                    'gridcfg':{'sticky':'wnse','column':1}})
        idf.append({'name':'Citelab',
                        'widgetType':Tkinter.Label,
                        'wcfg':{ 'text':'If you are going to publish this image'},
                        'gridcfg':{'sticky':'wnse','row':-1,'column':0}})
        idf.append({'name':'ok',
                    'widgetType':Tkinter.Button,
                    'wcfg':{'text':'OK',
                            'command':self.ok_cb,
                           },
                    'gridcfg':{'sticky':'wnse'}})            
        
        idf.append({'name':'dismiss',
                    'widgetType':Tkinter.Button,
                    'wcfg':{'text':'DISMISS',
                            'command':self.dismiss_cb,
                           },
                    'gridcfg':{'sticky':'wnse','row':-1,'column':1}})
        
        return idf     
        
    def cite_cb(self):
        urlcite = "http://www.scripps.edu/~sanner/software/documentation/citationsinfo.html"     
        import webbrowser
        webbrowser.open_new(urlcite)

    def switch_type_cb(self):
        # callback function for transparent background checkbutton
        # when checked configure file browser to show *.png file only
        ebn = self.cmdForms['SaveImage'].descr.entryByName
        if  ebn['TB']['wcfg']['variable'].get()==0:
            saveb = ebn['filesave']['widget']
            wcfg = ebn['filesave']['wcfg']
            from mglutil.util.callback import CallBackFunction
            ftypes = [('PNG files', '*.png'), ('TIFF files', '*.tif'), ('JPEG files', '*.jpg'), ('GIF files', '*.gif'),
                       ('PPM files', '*.ppm'), ('EPS files', '*.eps'),
                      ('IM files', '*.im'), ('PDF files', '*.pdf'), ('all files', '*.*')]
            saveb.configure(title=wcfg['title'], idir=None, ifile=None, types=ftypes, callback=wcfg['callback'])
        else:
            saveb = self.cmdForms['SaveImage'].descr.entryByName['filesave']['widget']
            wcfg = self.cmdForms['SaveImage'].descr.entryByName['filesave']['wcfg']
            ftypes = [('PNG files', '*.png')]
            saveb.configure(idir=None, ifile=None, types=ftypes, title=wcfg['title'], callback=wcfg['callback'])

    
    def setEntry_cb(self, filename):
        ebn = self.cmdForms['SaveImage'].descr.entryByName
        entry = ebn['File']['widget']
        entry.setentry(filename)
        
        
    def ok_cb(self):
        ebn = self.cmdForms['SaveImage'].descr.entryByName
        file = ebn['File']['widget'].get()                
        if file == None or file =='': return
        transparentbg = ebn['TB']['wcfg']['variable'].get()
        if not self.cmdForms.has_key('SaveImage'): return
        f = self.cmdForms['SaveImage']
        if f.root.winfo_ismapped():
            f.root.withdraw()
            f.releaseFocus()

        apply(self.doitWrapper, (file,transparentbg), {})
    
    def dismiss_cb(self):
        if not self.cmdForms.has_key('SaveImage'): return
        f = self.cmdForms['SaveImage']
        if f.root.winfo_ismapped():
            f.root.withdraw()
            f.releaseFocus()


    def guiCallback(self):
        f = self.vf.GUI.VIEWER.currentCamera.frame
        if f.winfo_height() + f.winfo_rooty() < f.winfo_screenheight() - 100:
            posy =  f.winfo_height() + f.winfo_rooty()
            posx = int(f.winfo_width()/2) + f.winfo_rootx() -100
        else:
            posx = None
            posy = None
        val = self.showForm('SaveImage', force=1, blocking=0, modal=0, 
                            master=self.vf.GUI.VIEWER.currentCamera.frame, posx=posx, posy=posy)
                    
 
    def __call__(self, filename, transparentbg=False, **kw):
        """ None <- saveImage(self,filename, **kw)
    \nfilename : name of the file
    transparentbg: true to get a transparent background, works only with .png files"""
        if filename==None: return
        kw['transparentbg'] = transparentbg
        apply(self.doitWrapper, (filename,), kw)



SaveImageGUI = CommandGUI()
SaveImageGUI.addMenuCommand('menuRoot', 'File', 'Save Image As',
                            cascadeName='Save')


class ColorGeomsByName(Command):
    """
    Command to choose color for geometries selected by name 
    """

    def onAddCmdToViewer(self):
        if self.vf.hasGui:
            self.patVar = Tkinter.StringVar()
            self.patVar.set("")

    def hidePalette_cb(self, event=None):
        self.palette.hide()

    def color_cb(self, colors, event=None):
        self.doitWrapper(pat = self.patVar.get(), material = colors)


    def doit(self, pat, material):
        print 'in doit with pat=', pat 
        print 'and material=', material 
        geomsToColor = self.vf.GUI.VIEWER.findGeomsByName(pat)
        print "geomsToColor=", 
        for g in geomsToColor:
            print g.name
        if len(geomsToColor)==0:
            return
        for geom in geomsToColor:
            geom.Set(inheritMaterial=False, materials = [material,])
            if geom.children!=[]:
                for childGeom in geom.children:
                    childGeom.Set(inheritMaterial=False, materials = [material,])
        self.vf.GUI.VIEWER.Redraw()


    def dismiss_cb(self, event=None):
        if hasattr(self, 'form'):
            self.form.withdraw()
        

    def buildForm(self):
        if hasattr(self, 'ifd'):
            return
        from mglutil.gui.BasicWidgets.Tk.colorWidgets import ColorChooser
        self.palette = ColorChooser(commands=self.color_cb,
                            exitFunction = self.hidePalette_cb)
        top = self.palette.ccFrame
        menuBar = self.palette.ccFrame
        ifd = self.ifd = InputFormDescr(title="Color Geometries by Name")
        ifd.append({'name':'patternLab',
                    'widgetType':Tkinter.Label,
                    'parent':top,
                    'text':"pattern:",
                    'gridcfg':{'sticky':'w'}})
        ifd.append({'name':'patternEnt',
                'widgetType':Tkinter.Entry,
                'parent':top,
                'wcfg':{ 'textvariable': self.patVar, },
                'gridcfg':{'sticky':'wens', 'row':-1, 'column':1}})
        self.form = self.vf.getUserInput(self.ifd, modal=0, blocking=0)
        self.label = self.ifd.entryByName['patternLab']['widget']
        self.entry = self.ifd.entryByName['patternEnt']['widget']
        top = self.label.master.master.master
        self.palette.pack(fill='both', expand=True)
        self.form.root.portocol("WM_DELETE_WINDOW", self.dismiss_cb)


    def guiCallback(self):
        if hasattr(self, 'ifd'):
            self.form.deiconify()
        else:
            self.buildForm()


    def __call__(self, pat, material, **kw):
        """
        None <- colorGeomsByName(filename)
        pat: string to match to geometry names
        material: new color 
        """
        apply( self.doitWrapper, (pat, material,), kw)



ColorGeomsByNameGUI = CommandGUI()
ColorGeomsByNameGUI.addMenuCommand('menuRoot', 'Color', 'ColorGeomsByName')



class setAntialiasingCommand(Command):
    """
    Package : ViewerFramework
    \nModule  : dejaVuCommands
    \nClass   : setbackgroundcolorCommand
    \nCommand : SetBackGroundColor

    \nDescription    
    \nCommand allowing the user to set color of the camera 

    \nSynopsis:
    \ncolor : Required color of background
    """
      
    def doit(self,value):
        vfgui = self.vf.GUI
        vi = vfgui.VIEWER
        vi.GUI.nbJitter.set(value)
        camera = vi.currentCamera 
        camera.Set(antialiased = value)
        vi.Redraw()
          
    def buildFormDescr(self, formName):
        if formName == 'setAntialiasing':
            idf = InputFormDescr(title="SetAntialiasing")
            self.vallist = [0,2,3,4,8,15,24,66]
            idf.append({'name':'value',
                'widgetType':kbScrolledListBox,
                'wcfg':{'items':self.vallist,
                            #'defaultValue': 0,
                            'listbox_exportselection':0,
                            'labelpos':'nw',
                            'label_text':'Antialiasing Values',
                            'selectioncommand':self.setJitter_cb,
                            
                            },
                    'gridcfg':{'sticky':'wesn','columnspan':1}})
                
            
            
            
            idf.append({'widgetType':Tkinter.Button,
                        'name':'dismiss',
                        'wcfg':{'text':'DISMISS', 'command':self.dismiss_cb},
                        'gridcfg':{'sticky':'we', 'columnspan':3}})
            
            return idf
    
    def dismiss_cb(self):
        if self.cmdForms.has_key('setAntialiasing'):
            self.cmdForms['setAntialiasing'].withdraw()
    
    def guiCallback(self):
        form = self.showForm('setAntialiasing', modal=0, blocking=0)
        
    def setJitter_cb(self):
        
        self.curselval = self.cmdForms['setAntialiasing'].descr.entryByName['value']['widget'].getcurselection()
        if self.curselval == ():
            self.curselv = 0
        else:
            self.curselv = self.curselval[0]
        
        apply( self.doitWrapper, (self.curselv,),{})
        
    def __call__(self,value, **kw):
        """None <-----setAntialiasing(value)
        \ncolor : background color
        """
        if isinstance(value, types.IntType) is False:
            return
        
        apply( self.doitWrapper, (value,), kw)



setAntialiasingGUI = CommandGUI()
setAntialiasingGUI.addMenuCommand('menuRoot', '3D Graphics','SetAntialiasing')    



class setbackgroundcolorCommand(Command):
    """
    Package : ViewerFramework
    \nModule  : dejaVuCommands
    \nClass   : setbackgroundcolorCommand
    \nCommand : SetBackGroundColor

    \nDescription    
    \nCommand allowing the user to set color of the camera 

    \nSynopsis:
    \ncolor : Required color of background
    """
   
    def hidePalette_cb(self, event=None):
        self.palette.hide()

    def color_cb(self, colors, event=None):
        self.doitWrapper(colors)
        
    def onAddCmdToViewer(self):
        if self.vf.hasGui:
            self.patVar = Tkinter.StringVar()
            self.patVar.set("")
            path = os.path.join(getResourceFolder(),'backgroundColor')
            if os.path.exists(path):
                hcol = open(path).read()
            else:
                return
            rgb = int(hcol[1:3], 16), int(hcol[3:5], 16), int(hcol[5:7], 16)
            col = [x/255. for x in rgb]
            self.vf.GUI.VIEWER.CurrentCameraBackgroundColor(col)
            
    def doit(self,color, **kw):
        vfgui = self.vf.GUI
        vi = vfgui.VIEWER
        vi.CurrentCameraBackgroundColor(color)
        #vi.GUI.CameraColorButton_cb()

        #cam = vi.currentCamera 
        #cc = vi.GUI.colorChooser
        #cc.Set( cam.backgroundColor[:3], 'RGB' )
        
    
    
    def buildFormDescr(self, formName):
        if formName == 'setbackgroundcolor':
            idf = InputFormDescr(title="SetBackGroundColor")
            cam = self.vf.GUI.VIEWER.cameras[0]      
            idf.append({'widgetType':ColorChooser,
                        'name':'colors',
                        'wcfg':{'title':'SetBackGroundColor',
                                'commands':self.color_cb,
                                'immediate':0, 'exitFunction':self.dismiss_cb},
                        'gridcfg':{'sticky':'wens', 'columnspan':3}
                        })
            idf.append({'widgetType':Tkinter.Button,
                        'name':'dismiss',
                        'wcfg':{'text':'DISMISS', 'command':self.dismiss_cb},
                        'gridcfg':{'sticky':'we', 'columnspan':3}})
            
            return idf
    

    def dismiss_cb(self, **kw):
        if self.cmdForms.has_key('setbackgroundcolor'):
            self.cmdForms['setbackgroundcolor'].withdraw()


    def guiCallback(self):
        form = self.showForm('setbackgroundcolor', modal=0, blocking=0)
    

    def __call__(self, color, **kw):
        """
None <-----setbackgroundcolorCommand(color)
\ncolor : background color
"""
        if type(color) == types.StringType:
            return "Error: color type can't be string"
        elif hasattr(color, '__len__') is False:
            return "Error: color should have length"
        elif len(color) != 3:
            return "Error: color length should be 3"
        
        apply( self.doitWrapper, (color,), kw)


setbackgroundcolorGUI = CommandGUI()
setbackgroundcolorGUI.addMenuCommand('menuRoot', '3D Graphics','SetBackGroundColor')



class setNPROutlinesCommand(ToggleNpr,Command):
    
    """
    Package : ViewerFramework
    \nModule  : dejaVuCommands
    \nClass   : setNPROutlinesCommand
    \nCommand : SetNPROutlines

    \nDescription    
    \nCommand allowing the user to set NPR outlines 

    \nSynopsis:
    \ncolor : Required color of background
    """
        
    def doit(self,control_points,sensitivity):
        self.vf.toggleNpr(npr=1)
        vi.GUI.curvetool.setControlPoints(control_points)
        vi.GUI.curvetool.d1scalewheel.set(sensitivity)
        
        #vi.GUI.CameraColorButton_cb()

        #cam = vi.currentCamera 
        #cc = vi.GUI.colorChooser
        #cc.Set( cam.backgroundColor[:3], 'RGB' )
        
    def onAddCmdToViewer(self):
        if self.vf.hasGui:
            self.sensitivityVar = Tkinter.StringVar()
            self.sensitivityVar.set("")
            self.cpVar = Tkinter.StringVar()
            self.cpVar.set("")

    def buildFormDescr(self, formName):
       if formName=="setNprparams":                
        ifd = InputFormDescr(title="Set NPR Params")
        ifd.append({'name':'cpLab',
                    'widgetType':Tkinter.Label,
                    'wcfg':{'text':"Control Points"},
                    
                    'gridcfg':{"row":0,'column':0,'sticky':'w'}})
        ifd.append({'name':'cpEnt',
                'widgetType':Tkinter.Entry,
                'tooltip':'controlpoints must be  a list of tuples with x  value ranging from [50,305] and y from [20,275].',
                'wcfg':{'textvariable':self.cpVar},
                'gridcfg':{'sticky':'wens', 'row':0, 'column':1}})
        ifd.append({'name':'sensitivityLab',
                    'widgetType':Tkinter.Label,
                    'wcfg':{'text':"Sensitivity"},
                    
                    'gridcfg':{"row":1,"column":0,'sticky':'w'}})
        ifd.append({'name':'sensitivityEnt',
                'widgetType':Tkinter.Entry,
                'tooltip':'sensitivity should be in range of 0.0 to 1.0',
                'wcfg':{'textvariable':self.sensitivityVar},
                'gridcfg':{'sticky':'wens', 'row':1, 'column':1}})
       
        ifd.append({'widgetType':Tkinter.Button,
                        'name':'OK',
                        'wcfg':{'text':'OK', 'command':self.ok_cb},
                        'gridcfg':{'sticky':'we', 'row':2,'column':0}})
        ifd.append({'widgetType':Tkinter.Button,
                        'name':'dismiss',
                        'wcfg':{'text':'DISMISS', 'command':self.dismiss_cb},
                        'gridcfg':{'sticky':'we', 'row':2,'column':1}})
        

        return ifd

        
    
    def dismiss_cb(self):
        if self.cmdForms.has_key('setNprparams'):
            self.cmdForms['setNprparams'].withdraw()
    def guiCallback(self):
        form = self.showForm('setNprparams', modal=0, blocking=0)
        
        
    
    def ok_cb(self):
        vfgui = self.vf.GUI
        vi = vfgui.VIEWER
        self.vf.toggleNpr(npr=1)
        if self.cpVar.get() != '':
            vi.GUI.curvetool.setControlPoints(eval(self.cpVar.get()))
        if self.sensitivityVar.get() != '':
            vi.GUI.curvetool.d1scalewheel.set(eval(self.sensitivityVar.get()))
        self.dismiss_cb()
              
        

    def __call__(self,control_points,sensitivity):
        """None <-----setNPROutlines(points,sensitivity)
        points:list of points
        snesitivity:floatvalue(ranging from 0.0 to 1.0)
        \ncolor : background color
        """
        if type(control_points) != types.ListType:
            print "Illegal type for points"
            return
        if type(sensitivity)!=types.FloatType:
            print "Illegal type for sensitivity"
            return
                    
        apply( self.doitWrapper, (control_points,sensitivity),{})


   
setNPROutlinesGUI = CommandGUI()
setNPROutlinesGUI.addMenuCommand('menuRoot', '3D Graphics','SetCartoonOutlines')    


commandList = [
    {'name':'setNPROutlines', 'cmd':setNPROutlinesCommand(),
     'gui':setNPROutlinesGUI},
    {'name':'setAntialiasing', 'cmd':setAntialiasingCommand(),
     'gui':setAntialiasingGUI},
    {'name':'setbackgroundcolor', 'cmd':setbackgroundcolorCommand(),
     'gui':setbackgroundcolorGUI},
    {'name':'setCameraSize', 'cmd':SetCameraSizeCommand(),
     'gui':SetCamSizeGUI},
    {'name':'renderLargeImage', 'cmd':RenderLargeImageCommand(),
     'gui':RenderLargeImageGUI},
    {'name':'spin', 'cmd':SpinCommand(), 'gui':spinGUI},
    {'name':'transformObject', 'cmd':TransformObject(),
     'gui':None},
    {'name':'transformCamera', 'cmd':TransformCamera(),
     'gui':None},
    {'name':'setObject', 'cmd': SetObject(),
     'gui':None},
    {'name':'setCamera', 'cmd':SetCamera(),
     'gui': None},
    {'name':'setLight', 'cmd':SetLight(), 'gui':None},
    {'name':'setClip', 'cmd':SetClip(),'gui':None},
    {'name':'addClipPlane', 'cmd':AddClipPlane(),'gui':None},
    {'name':'centerGeom','cmd':CenterGeom(),'gui':None},
    {'name':'viewPoints', 'cmd': ViewPoints(),'gui':None},
    {'name': 'centerScene', 'cmd':CenterScene(), 'gui':None},
    {'name': 'centerSceneOnVertices', 'cmd':CenterSceneOnVertices(),
     'gui':None},
    {'name':'centerSceneOnPickedPixel','cmd':CenterSceneOnPickedPixel(),
     'gui':None},
    {'name': 'alignGeomsnogui', 'cmd':AlignGeoms(),
     'gui':None},
    {'name': 'alignGeoms', 'cmd':AlignGeomsPCOM(),
     'gui':None},
    {'name': 'rotateScene', 'cmd':RotateScene(), 'gui':None},
    {'name':'printGeometryName', 'cmd':PrintGeometryName(), 'gui':None},
    {'name':'startContinuousPicking', 'cmd':StartContinuousPicking(),
     'gui':None},
    {'name':'stopContinuousPicking', 'cmd':StopContinuousPicking(),
     'gui':None},
#    {'name':'toggleStereo', 'cmd':ToggleStereo(), 'gui':ToggleStereoGUI},
#    {'name':'toggleNpr', 'cmd':ToggleNpr(), 'gui':ToggleNprGUI},
    {'name':'toggleStereo', 'cmd':ToggleStereo(), 'gui':ToggleStereoGUI},
    {'name':'toggleNpr', 'cmd':ToggleNpr(), 'gui':ToggleNprMenuGUI},

    {'name':'ResetView', 'cmd':ResetView(), 'gui':ResetViewGUI},
     
    {'name':'loadColorMap', 'cmd':LoadColorMap(), 'gui':LoadColorMapGUI},
    {'name':'saveColorMap', 'cmd':SaveColorMap(), 'gui':SaveColorMapGUI},
    {'name':'createColorMap', 'cmd':CreateColorMap(), 'gui':CreateColorMapGUI},
    {'name':'showCMGUI', 'cmd':ColorMapEditor(),
     'gui':ColorMapEditorGUI},
    {'name':'editColorMap', 'cmd':EditColorMap(), 'gui':None},
    {'name':'saveImage', 'cmd':SaveImage(), 'gui':SaveImageGUI },
    #{'name':'colorGeomsByName', 'cmd':ColorGeomsByName(), 'gui':ColorGeomsByNameGUI},
    ]



def initModule(viewer):
    for dict in commandList:
        viewer.addCommand(dict['cmd'], dict['name'], dict['gui'])