1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 from opengltk.OpenGL import GL
19
20 from geomutils.geomalgorithms import TriangleNormals
21
22 import Numeric, math, string, warnings
23 from mglutil.math import rotax
24 from DejaVu.Geom import Geom
25 from DejaVu.IndexedGeom import IndexedGeom
26 from DejaVu.Transformable import Transformable
27 from DejaVu.IndexedPolylines import IndexedPolylines
28 from DejaVu.IndexedPolygons import IndexedPolygons
29 from DejaVu.Spheres import Spheres
30 from DejaVu.Cylinders import Cylinders
31 from DejaVu import viewerConst
32 from DejaVu.colorTool import glMaterialWithCheck
33 from DejaVu.GleObjects import GleExtrude
34 from DejaVu.glfLabels import GlfLabels
35
36 import Tkinter, Pmw
37 from mglutil.gui.InputForm.Tk.gui import InputFormDescr, InputForm
38
39
40
41
42
43
44
45
46
47
48
49
50
51
53 """listOfStrings <-- IndexedPolgonsAsSMFString(geometry)
54 For a given IndexedPolygons geoemtry this function generates the textual SMF
55 description. Currently supports vertices (v), faces (f), normals(n) and
56 colors (c). Normals and color binding mstring are generated automatically.
57 Texture indices (r) are not used yet but could be used to store any integer
58 property.
59 """
60 assert isinstance(geometry, IndexedPolygons)
61
62 assert geometry.faceSet.faces.array.shape[1] in [3,4]
63
64 lines = []
65 lines.append('begin\n')
66
67 verts = geometry.vertexSet.vertices.array
68 lines.extend( map(lambda x: ('v %f %f %f\n'%tuple(x)), verts) )
69
70
71 tri = geometry.faceSet.faces.array
72 lines.extend( map(lambda x:
73 ('f %d %d %d\n'%(x[0]+1,x[1]+1,x[2]+1)), tri) )
74
75
76 normals = geometry.normals
77 if len(normals)==len(verts):
78 lines.append('bind n vertex\n')
79 elif len(normals)==len(tri):
80 lines.append('bind n face\n')
81 else:
82 normals = None
83 if normals:
84 lines.extend( map(lambda x:
85 ('n %f %f %f\n'%tuple(x)), normals) )
86
87
88 if geometry.materials[1028].binding[1]==11:
89 lines.append('bind c vertex\n')
90 cols = geometry.materials[1028].prop[1]
91 lines.extend( map(lambda x:
92 ('c %f %f %f\n'%tuple(x[:3])), cols) )
93 lines.append('end\n')
94 return lines
95
96
103
104
106 """v,f,n,c,r <-- ParseSMFString(stringList)
107 Parse an ascii SMF file and returnes a list of 3D vertices, triangular faces
108 (0-based indices, faces with more edges generate warnings), normals, colors
109 and 2D texture coordinates.
110 """
111
112 vertices = []
113 faces = []
114 normals = []
115 colors = []
116 textures = []
117 fi = 0
118 for l in stringList:
119 w = l.split()
120 if w[0]=='v':
121 vertices.append( [float(w[1]),float(w[2]),float(w[3])] )
122 elif w[0]=='f':
123 if len(w) > 4:
124 warnings.warn("face %d has more than 3 edges"%fi);
125 faces.append( [int(w[1])-1,int(w[2])-1,int(w[3])-1] )
126 fi += 1
127 if w[0]=='n':
128 normals.append( [float(w[1]),float(w[2]),float(w[3])] )
129 if w[0]=='c':
130 colors.append( [float(w[1]),float(w[2]),float(w[3])] )
131 if w[0]=='r':
132 textures.append( [float(w[1]),float(w[2])] )
133 return vertices, faces, normals, colors, textures
134
135
137 """Read an SMF ascii file and return an IndexedPolygons geometry"""
138
139 f = open(filename)
140 data = f.readlines()
141 f.close()
142 v, f, n, c, t = ParseSMFString(data)
143 return v, f, n, c, t
144
145
147
148 """This base class recursively loops over a given DejaVu geom tree and
149 computes the transformation matrices at each level."""
150
152 self.output = []
153 self.lenGeoms = 0
154
155
157
158 pass
159
160
162
163 pass
164
165
167 for child in obj.children:
168 if child.visible:
169 check = self.checkGeom(child)
170 if check:
171 self.lenGeoms = self.lenGeoms + 1
172 self.countGeoms(child)
173
174
176 """ this calls the recursive method """
177
178
179
180
181
182
183
184
185 self.lenGeoms = 0
186 self.countGeoms(obj)
187 self.lenGeoms = self.lenGeoms + 1
188
189 self.configureProgressBar(init=1, mode='increment',
190 granularity=1,
191 progressformat='ratio',
192 labeltext='parse geoms to vrml2',
193 max=self.lenGeoms)
194 GL.glPushMatrix()
195 GL.glLoadIdentity()
196 self._loopGeomsRec(obj)
197 GL.glPopMatrix()
198
199
200
201
202
203
204
206 """ recursive method """
207
208 GL.glPushMatrix()
209
210
211 if obj is not obj.viewer.rootObject:
212 obj.MakeMat()
213
214 obj.VRML2CreatedPROTOForThisGeom = 0
215
216 for i in range(len(obj.instanceMatrices)):
217 GL.glPushMatrix()
218 GL.glMultMatrixf(obj.instanceMatrices[i])
219 obj.instanceMatricesIndex = i
220
221 matrix = GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX)
222 self.NodeRepr(obj, matrix)
223
224 for child in obj.children:
225
226 if child.visible:
227 self._loopGeomsRec(child)
228
229 GL.glPopMatrix()
230
231 GL.glPopMatrix()
232 del obj.instanceMatricesIndex
233 del obj.VRML2CreatedPROTOForThisGeom
234
235
237 """ This method, to be implemented by sublcass, should generate
238 stl, vrml2 etc descriptions of DejaVu geoms"""
239 pass
240
241
243
244 if geom is None:
245 return 0
246 elif not isinstance(geom, Geom):
247 return 0
248 elif not geom.visible:
249 return 0
250 elif len(geom.vertexSet)==0:
251 return 0
252 elif isinstance(geom, IndexedGeom) and len(geom.faceSet) == 0:
253 return 0
254 else: return 1
255
256
258 """ generates a list of strings describing DejaVu geoms in STL
259 (stereolithography) format (don't mix this with standard template
260 library).
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
320
321
322 - def getSTL(self, root, filename, sphereQuality=2,
323 cylinderQuality=10):
324
325 self.sphereQuality = sphereQuality
326 self.cylinderQuality = cylinderQuality
327 self.output = []
328 self.output.append("solid %s\n"%filename)
329 self.loopGeoms(root)
330 self.output.append("endsolid %s\n"%filename)
331 return self.output
332
333
353
354
356
357
358 vert = geom.getVertices()
359 faces = geom.getFaces()
360
361 if faces.shape[1]==3:
362 fn = TriangleNormals( vert, faces, 'PER_FACE')
363 else:
364 fn = TriangleNormals( vert, faces[:,:3], 'PER_FACE')
365
366
367 if faces.shape[1] > 3:
368 newfaces=[]
369 newfn = []
370 n=0
371 for face in faces:
372
373 for i in range(len(face)):
374
375
376 if face[i] == -1:
377 break
378 newfaces.append( [face[0],face[i-1],face[i]])
379 newfn.append(fn[n])
380
381
382 n = n + 1
383
384
385 faces = newfaces
386 fn = Numeric.array(newfn).astype('f')
387
388 self.doit(vert, faces, fn, matrix, invertNormals=geom.invertNormals)
389
390
397
398
405
406
407 - def doit(self, vert, faces, fn, matrix, invertNormals=False):
408 if invertNormals:
409 fn = -1.0*fn
410 l=[]
411 for face in faces:
412 l.append([face[0],face[2],face[1]])
413 faces = Numeric.array(l)
414
415 coords = Numeric.array(vert).astype('f')
416 matrix = Numeric.array(matrix).astype('f')
417 matrix.shape = (4,4)
418 one = Numeric.ones( (coords.shape[0], 1), \
419 coords.typecode() )
420 c = Numeric.concatenate( (coords, one), 1 )
421
422
423 newCoords = Numeric.matrixmultiply(c, \
424 Numeric.transpose(matrix))[:, :3]
425
426 self.output.extend(self.makestl(newCoords, faces, fn))
427
428
429 - def makestl(self, vert, faces, fn):
430 stl = []
431
432 for i in xrange(len(faces)):
433 stl.append(" facet normal %f %f %f\n"%tuple(fn[i]))
434 stl.append(" outer loop\n")
435 fa = faces[i]
436 stl.append(" vertex %f %f %f\n"%tuple(vert[fa[0]]))
437 stl.append(" vertex %f %f %f\n"%tuple(vert[fa[1]]))
438 stl.append(" vertex %f %f %f\n"%tuple(vert[fa[2]]))
439 stl.append(" endloop\n")
440 stl.append(" endfacet\n")
441
442 return stl
443
444
446 """ generates a list of strings describing DejaVu geoms in VRML 2.0
447 format. Usage: OutputVRML2.getVRML2(geom, complete=0/1, normals=0/1)
448 geom represents the geoms to be converted
449 complete=1 will add vrml2 header and footer
450 normals=1 will add normals
451 """
452
454 OutputNode.__init__(self)
455 self.geomName = None
456 self.Transformable = Transformable()
457 self.completeFlag = 1
458 self.saveNormalsFlag = 0
459 self.colorPerVertexFlag = True
460 self.usePROTOFlag = 0
461
462 self.sphereQuality = 2
463 self.cylinderQuality = 10
464
465
466 - def getVRML2(self, root, complete=1, normals=0,
467 colorPerVertex=True,
468 usePROTO=0, sphereQuality=2, cylinderQuality=10):
469 """ this method returns a list of strings describing DejaVu Geoms in
470 VRML2 format """
471
472
473
474 self.completeFlag = complete
475 self.saveNormalsFlag = normals
476 self.colorPerVertexFlag = colorPerVertex
477 self.usePROTOFlag = usePROTO
478
479
480
481
482 self.sphereQuality = sphereQuality
483 self.cylinderQuality = cylinderQuality
484
485 self.output = []
486
487 if self.completeFlag:
488 self.output.extend(self.getFileHeader1())
489 self.output.extend(self.getCopyright())
490 self.output.extend(self.getFileHeader2())
491
492 self.loopGeoms(root)
493
494 if self.completeFlag:
495 self.output.extend(self.getFileTrailer())
496
497 return self.output
498
499
501
502 if not self.checkGeom(geom): return
503
504
505 self.configureProgressBar(labeltext='parse '+geom.name)
506 self.updateProgressBar()
507
508
509 if isinstance(geom, IndexedPolygons) or \
510 isinstance(geom, IndexedPolylines):
511 self.output.extend( self.doit(geom, matrix) )
512
513 elif isinstance(geom, Spheres):
514
515 sphGeom = geom.asIndexedPolygons(quality=self.sphereQuality)
516 sphGeom.viewer = geom.viewer
517 sphGeom.parent = geom.parent
518 sphGeom.name = geom.name
519 sphGeom.fullName = geom.fullName
520 sphGeom.instanceMatrices = geom.instanceMatrices
521 sphGeom.instanceMatricesIndex = geom.instanceMatricesIndex
522 sphGeom.VRML2CreatedPROTOForThisGeom = 0
523 self.output.extend( self.doit(sphGeom, matrix) )
524
525 elif isinstance(geom, Cylinders):
526
527 cylGeom = geom.asIndexedPolygons(quality=self.cylinderQuality)
528 cylGeom.viewer = geom.viewer
529 cylGeom.parent = geom.parent
530 cylGeom.name = geom.name
531 cylGeom.fullName = geom.fullName
532 cylGeom.instanceMatrices = geom.instanceMatrices
533 cylGeom.instanceMatricesIndex = geom.instanceMatricesIndex
534 cylGeom.VRML2CreatedPROTOForThisGeom = 0
535 self.output.extend( self.doit(cylGeom, matrix) )
536
537 elif isinstance(geom, GlfLabels):
538
539 glfGeom = geom.asIndexedPolygons()
540 glfGeom.viewer = geom.viewer
541 glfGeom.parent = geom.parent
542 glfGeom.name = geom.name
543 glfGeom.fullName = geom.fullName
544 glfGeom.instanceMatrices = geom.instanceMatrices
545 glfGeom.instanceMatricesIndex = geom.instanceMatricesIndex
546 glfGeom.VRML2CreatedPROTOForThisGeom = 0
547 self.output.extend( self.doit(glfGeom, matrix) )
548
549
550 - def doit(self, geom, matrix):
551
552 vrml2 = []
553
554
555
556 if self.usePROTOFlag:
557
558
559 if geom.VRML2CreatedPROTOForThisGeom == 0:
560 name = self.getGeomName(geom)
561 vrml2.append("PROTO "+name+" [ ] {\n")
562 identityMatrix = Numeric.identity(4).astype('f')
563 vrml2.extend( self.doitReally(geom, identityMatrix) )
564 vrml2.append("}\n")
565
566
567 for i in range(len(vrml2)):
568 self.output.insert(i+1,vrml2[i])
569 geom.VRML2CreatedPROTOForThisGeom = 1
570
571
572
573
574 vrml2 = []
575 vrml2.extend( self.doitUsePROTO(geom, matrix) )
576 return vrml2
577
578 else:
579
580 return self.doitReally(geom, matrix)
581
582
629
630
632
633
634
635
636 vrml2 = []
637
638 geom.instanceMatricesIndex = 0
639 name = string.split(self.getGeomHeader(geom)[0])[1]
640 vrml2.append(" Transform {\n")
641 vrml2.append(" children "+name+" { }\n")
642
643
644 vrml2.extend( self.getTransforms(matrix) )
645
646
647 vrml2.append(" }\n")
648 return vrml2
649
650
651
653 vrml2=[]
654 vrml2.append("#VRML V2.0 utf8 Python Molecular Viewer Geom\n")
655 vrml2.append("\n")
656 return vrml2
657
658
660 vrml2=[]
661 vrml2.append("WorldInfo {\n")
662
663 vrml2.append(' title ""\n')
664 vrml2.append(" info [\n")
665 vrml2.append(' "Copyright (c) 2002 D. Stoffler, M.F. Sanner and A.J. Olson"\n')
666 vrml2.append(' "Molecular Graphics Lab"\n')
667 vrml2.append(' "The Scripps Research Institute, La Jolla, CA"\n')
668 vrml2.append(' "VRML2 file generated with the Python Molecular Viewer:"\n')
669 vrml2.append(' "http://www.scripps.edu/~sanner/python/pmv/"\n')
670 vrml2.append(" ]\n")
671 vrml2.append("}\n")
672 return vrml2
673
674
676 vrml2=[]
677 vrml2.append("Group {\n")
678 vrml2.append(" children [\n")
679 return vrml2
680
681
683 vrml2=[]
684 vrml2.append(" ]\n")
685 vrml2.append("}\n")
686 return vrml2
687
688
702
703
711
712
714 vrml2=[]
715 vrml2.append(" children Shape {\n")
716 return vrml2
717
718
720 vrml2=[]
721 vrml2.append(" appearance Appearance {\n")
722 return vrml2
723
724
726 vrml2=[]
727
728 mat = geom.materials[GL.GL_FRONT].prop[:]
729 geom.materials[GL.GL_FRONT].colorIndex = None
730 colors = None
731
732
733
734 if len(mat[1])> 1:
735 colors = mat[1]
736
737
738
739
740
741
742
743
744 if isinstance(geom, GleExtrude):
745 faces = geom.faceSet.faces.array
746 ifaces = geom.getFaces()
747
748
749 if self.colorPerVertexFlag is True:
750 colorIndex = Numeric.zeros( (ifaces.shape[0], \
751 ifaces.shape[1]) )
752 c = 0
753 cc = 0
754 for face in faces:
755 for j in range(len(face)-2):
756 colorIndex[cc] = c
757 cc = cc + 1
758 c = c + 1
759 geom.materials[GL.GL_FRONT].colorIndex = colorIndex
760
761 elif isinstance(geom, IndexedPolygons):
762 mat[1]=[mat[1][0]]
763 vertices = geom.getVertices()
764 faces = geom.getFaces()
765
766
767 if len(colors) != len(vertices) and len(colors) == len(faces):
768
769 if self.colorPerVertexFlag is True:
770 colorIndex = Numeric.zeros( (faces.shape[0], \
771 faces.shape[1]) )
772 c = 0
773 for face in faces:
774 for f in face:
775 colorIndex[c] = c
776 c = c + 1
777 geom.materials[GL.GL_FRONT].colorIndex = colorIndex
778
779
780 else:
781
782 if self.colorPerVertexFlag is False:
783
784 vcol = geom.materials[1028].prop[1]
785 tri = geom.faceSet.faces.array
786 verts= geom.vertexSet.vertices.array
787 colors = []
788 for t in tri:
789 s1,s2,s3 = t
790 col = ( (vcol[s1][0]+vcol[s2][0]+vcol[s3][0])/3.,
791 (vcol[s1][1]+vcol[s2][1]+vcol[s3][1])/3.,
792 (vcol[s1][2]+vcol[s2][2]+vcol[s3][2])/3. )
793 colors.append( col)
794
795
796
797 ambInt = '%.5f'%mat[0][0][0]
798 difCol = '%.5f'%mat[1][0][0]+" "+'%.5f'%mat[1][0][1]+" "+\
799 '%.5f'%mat[1][0][2]
800 emCol = '%.5f'%mat[2][0][0]+" "+'%.5f'%mat[2][0][1]+" "+\
801 '%.5f'%mat[2][0][2]
802 specCol = '%.5f'%mat[3][0][0]+" "+'%.5f'%mat[3][0][1]+" "+\
803 '%.5f'%mat[3][0][2]
804 shin = '%.5f'%mat[4][0]
805 trans = `1-mat[5][0]`
806
807 vrml2.append(" material Material {\n")
808 vrml2.append(" ambientIntensity "+ambInt+"\n")
809 vrml2.append(" diffuseColor "+difCol+"\n")
810 vrml2.append(" emissiveColor "+emCol+"\n")
811 vrml2.append(" specularColor "+specCol+"\n")
812 vrml2.append(" shininess "+shin+"\n")
813 vrml2.append(" transparency "+trans+"\n")
814 vrml2.append(" }\n")
815 return vrml2, colors
816
817
839
840
841
842 - def getTexture(self,geom):
843 """ return PixelTexture Node
844 PixelTexture {
845 image 0 0 0 # exposedField SFImage
846 repeatS True # field SFBool
847 repeatT True # field SFBool
848 }
849
850 the value of the image field specifies image size and pixel values
851 for a texture image
852 width (in pixel)
853 height (in pixel)
854 number of 8-bit bytes for each pixel
855 recognize values are:
856 0 disable texturing for shape
857 1 Grayscale
858 2 Grayscale with alpha
859 3 RGB
860 4 RGB with alpha
861 (Info taken from Book " VRML 2.0 source book by Andrea L. Ames,
862 David R. Nadeau and John L. Moreland ")
863
864 """
865
866
867 vrml2=[]
868 tex = geom.texture
869 dims = tex.image.shape
870
871 vrml2.append("\n")
872 vrml2.append(" texture PixelTexture {\n")
873 width = dims[0]
874 if len(dims) == 3:
875 height = dims[1]
876 num_byte = dims[2]
877 elif len(dims)==1:
878 height = 1
879 num_byte = len(tex.image[0])
880 elif len(dims)==2:
881 height = 1
882 num_byte = dims[1]
883
884 vrml2.append(" image "+`width`+" "+`height`+" "+`num_byte`+"\n")
885
886 if len(dims) == 3:
887
888 countW =0
889 for r in tex.image:
890 for c in r:
891 istring = "0x"
892 for i in range(3):
893 hexa = "%X"%c[i]
894 if len(hexa)==1: hexa = "0"+hexa
895 istring = istring+ hexa
896 istring = istring + " "
897 vrml2.append(istring)
898 vrml2.append("\n")
899 vrml2.append(" }\n")
900
901 else:
902
903 for line in tex.image:
904 istring = "0x"
905 for i in range(len(line)):
906 hexa = "%X"%line[i]
907 if len(hexa)==1: hexa = "0"+hexa
908 istring = istring+ hexa
909 istring = istring + "\n"
910 vrml2.append(istring)
911 vrml2.append(" }\n")
912 return vrml2
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
940 vrml2=[]
941 vertices = geom.getVertices()
942 vrml2.append(" coord Coordinate {\n")
943 vrml2.append(" point [\n")
944 for vert in vertices:
945 vstring = " "+'%.5f'%vert[0]+" "+\
946 '%.5f'%vert[1]+" "+'%.5f'%vert[2]+",\n"
947 vrml2.append(vstring)
948 vrml2.append(" ]\n")
949 vrml2.append(" }\n")
950 return vrml2
951
952
954
955 vrml2=[]
956 faces = geom.getFaces()
957 vrml2.append(" coordIndex [\n")
958
959 for face in faces:
960 facestring = " "
961 if geom.invertNormals:
962 facestring = facestring + `face[0]` + ", "
963 for i in range(len(face)-1,0,-1):
964 facestring = facestring + `face[i]` + ", "
965 else:
966 for f in face:
967 facestring = facestring + `f` + ", "
968
969 facestring = facestring + "-1,\n"
970 vrml2.append(facestring)
971 vrml2.append(" ]\n")
972 return vrml2
973
974
976
977 vrml2 = []
978 colorIndex = geom.materials[GL.GL_FRONT].colorIndex
979 vrml2.append(" colorIndex [\n")
980 for cI in colorIndex:
981 cIstring = " "
982 for c in cI:
983 cIstring = cIstring + `c` +", "
984 cIstring = cIstring + "-1,\n"
985 vrml2.append(cIstring)
986 vrml2.append(" ]\n")
987
988 del geom.materials[GL.GL_FRONT].colorIndex
989 return vrml2
990
991
993 if geom.invertNormals:
994 fn = -1.0 * geom.normals
995 else:
996 fn = geom.normals
997
998 vrml2=[]
999 vrml2.append(" normal Normal {\n")
1000 vrml2.append(" vector [\n")
1001 for n in fn:
1002 vrml2.append(" %.5f"%n[0]+" %.5f"%n[1]+\
1003 " %.5f"%n[2]+" \n")
1004 vrml2.append(" ]\n")
1005 vrml2.append(" }\n")
1006 return vrml2
1007
1008
1010 vrml2=[]
1011 vrml2.append("\n")
1012 vrml2.append(" texCoord TextureCoordinate {\n")
1013 vrml2.append(" point [\n")
1014 for p in geom.vertexSet.texCoords.array:
1015 if len(p) == 1:
1016 vrml2.append(" "+`p[0]`+" 0,\n")
1017 else:
1018 vrml2.append(" "+`p[0]`+" "+`p[1]`+",\n")
1019 vrml2.append(" ]\n")
1020 vrml2.append(" }\n")
1021 return vrml2
1022
1024 vrml2=[]
1025 texCoordsIndex = geom.vertexSet.texCoordsIndex.array
1026 vrml2.append(" texCoordIndex [\n")
1027
1028 for face in texCoordsIndex:
1029 indexstring = " "
1030 for i in face:
1031 indexstring = indexstring + `i` + ", "
1032
1033 indexstring = indexstring + "-1,\n"
1034 vrml2.append(indexstring)
1035 vrml2.append(" ]\n")
1036 return vrml2
1037
1038
1040 vrml2=[]
1041 vrml2.append("\n")
1042 vrml2.append(" colorPerVertex %s\n"%string.upper(
1043 str(self.colorPerVertexFlag)))
1044 vrml2.append(" color Color {\n")
1045 vrml2.append(" color [\n")
1046 for c in colors:
1047 cstring = ' %.3f'%c[0]+" "+'%.3f'%c[1]+\
1048 " "+'%.3f'%c[2]+",\n"
1049 vrml2.append(cstring)
1050 vrml2.append(" ]\n")
1051 vrml2.append(" }\n")
1052 return vrml2
1053
1054
1074
1075
1077 """ basic gui for DataOutput """
1078
1079 - def __init__(self, master=None, title=None):
1080 self.master = master
1081 self.root = None
1082 self.title = title
1083 if self.title is None:
1084 self.title = 'Options Panel'
1085
1086 if self.master is None:
1087 self.master = Tkinter.Frame()
1088 self.master.pack()
1089
1090 self.sphInput = Tkinter.StringVar()
1091 self.cylInput = Tkinter.StringVar()
1092
1093 self.sphereQuality = 2
1094 self.cylinderQuality = 10
1095
1096 self.readyToRun = 0
1097
1098 self.idf = InputFormDescr(title=self.title)
1099
1100
1102 val = self.sphInput.get()
1103 if len(val) == 0 or val is None:
1104 val = self.sphereQuality
1105 try:
1106 val = int(val)
1107 if val < 0:
1108 val = 0
1109 self.sphereQuality = val
1110 self.sphInput.set(str(self.sphereQuality))
1111 except ValueError:
1112 self.sphInput.set(str(self.sphereQuality))
1113
1114
1116 val = self.cylInput.get()
1117 if len(val) == 0 or val is None:
1118 val = self.cylinderQuality
1119 try:
1120 val = int(val)
1121 if val < 3:
1122 val = 3
1123 self.cylinderQuality = val
1124 self.cylInput.set(str(self.cylinderQuality))
1125 except ValueError:
1126 self.sphInput.set(str(self.cylinderQuality))
1127
1128
1136
1137
1143
1144
1146 self.readyToRun = 0
1147 if create == 0:
1148 self.optionsForm.deiconify()
1149 else:
1150 self.optionsForm = InputForm(self.master, self.root,
1151 descr=self.idf,okcancel=0)
1152
1153 self.master.grab_set()
1154 self.master.mainloop()
1155
1156
1158 vals = {}
1159 vals['sphereQuality'] = self.sphereQuality
1160 vals['cylinderQuality'] = self.cylinderQuality
1161 return vals
1162
1163
1165 """ this is the gui for OutputSTL
1166 - Save normals adds normals to all geoms to be saved as vrml2
1167 - Invert normals inverts the normals for all geoms to be saved as vrml2
1168 - Sphere quality is the subsampling of the spheres. Default value is 2
1169 lowest allowed value is 0. Higher values increase the file size
1170 significantly.
1171 - Cylinder quality is the subsampling of cylinders. Default value is 10
1172 lowest allowed value is 3."""
1173
1174 - def __init__(self, master=None, title=None):
1178
1236
1237
1239 pass
1240
1241
1243 """This is the gui for OutputVRML2:
1244 - Save normals adds normals to all geoms to be saved as vrml2
1245 - Invert normals inverts the normals for all geoms to be saved as vrml2
1246 - colorPerVertex: True by default. If set to False, color per face is used
1247 - Using PROTO will define a prototype geom which can be reused. This
1248 is usefull to lower the file size when instanceMatrices are applied.
1249 - Sphere quality is the subsampling of the spheres. Default value is 2
1250 lowest allowed value is 0. Higher values increase the file size
1251 significantly.
1252 - Cylinder quality is the subsampling of cylinders. Default value is 10
1253 lowest allowed value is 3.
1254 """
1255
1256 - def __init__(self, master=None, title=None):
1265
1364
1365
1366
1368 pass
1369
1370
1372 pass
1373
1374
1376 pass
1377
1378
1380 vals = {}
1381 vals['saveNormals'] = self.saveNormals.get()
1382 co = self.colorPerVertex.get()
1383 if co == 1:
1384 co = True
1385 else:
1386 co = False
1387 vals['colorPerVertex'] = co
1388 vals['usePROTO'] = self.usePROTO.get()
1389 vals['sphereQuality'] = self.sphereQuality
1390 vals['cylinderQuality'] = self.cylinderQuality
1391 return vals
1392