Import Export Vertex Groups rewritten
[blender-addons-contrib.git] / geodesic_domes / third_domes_panel_271.py
1 import bpy
2 import os
3 from geodesic_domes import vefm_271 
4 from geodesic_domes import forms_271
5 from geodesic_domes import geodesic_classes_271
6 from geodesic_domes import add_shape_geodesic
7
8 from bpy.props import EnumProperty, IntProperty, FloatProperty, StringProperty, BoolProperty
9 #PKHG>NEEDED??? import math
10 from math import pi
11 from mathutils import Vector #needed to check vertex.vector values
12 """
13 not in Blender 2.7*???
14 try:
15     breakpoint = bpy.types.bp.bp
16 except:
17     print("add breakpoint addon!")
18 """        
19
20 ########global######
21 last_generated_object = None
22 last_imported_mesh = None
23 basegeodesic = None
24 imported_hubmesh_to_use = None
25 ########global end######
26
27 ########EIND FOR SHAPEKEYS######
28 ### error messages?!
29 bpy.types.Scene.error_message = StringProperty(name="actual error", default = "")    
30
31
32 bpy.types.Scene.geodesic_not_yet_called = BoolProperty(name="geodesic_not_called",default = True)
33
34 bpy.types.Scene.gd_help_text_width = IntProperty(name = "Text Width" , description = "The width above which the text wraps" , default = 60 , max = 180 , min = 20)
35
36 class Geodesic_Domes_Operator_Panel(bpy.types.Panel):
37     """start a GD object here"""
38     bl_label = "Geodesic Domes"
39     bl_region_type = "TOOLS" #UI possible too
40     bl_space_type = "VIEW_3D"
41     bl_options = {'DEFAULT_CLOSED'}
42     bl_context = "objectmode"
43     bl_category = "Addons"
44
45     def draw(self,context):
46         sce = context.scene
47         layout = self.layout
48         col = layout.column()
49         col.label("Geodesic Domes: ")
50         col.operator(GenerateGeodesicDome.bl_idname, "create one!")
51             
52 class GenerateGeodesicDome(bpy.types.Operator):
53     bl_label = "Modify Geodesic Objects"
54     bl_idname = "mesh.generate_geodesic_dome"
55     bl_description = "Create object dependent on selection"
56     bl_options = {'REGISTER', 'UNDO'}
57
58 #PKHG_NEW saving and loading parameters
59     save_parameters = BoolProperty(name = "save params",\
60            description = "activation save */tmp/GD_0.GD", default = False)
61     load_parameters  = BoolProperty(name = "load params",\
62            description = "read */tmp/GD_0.GD", default = False)
63
64     gd_help_text_width = IntProperty(name = "Text Width" , description = "The width above which the text wraps" , default = 60 , max = 180 , min = 20)
65
66     
67     mainpages = EnumProperty(
68     name="Menu",
69     description="Create Faces, Struts & Hubs",
70     items=[("Main", "Main", "Geodesic objects"),
71            ("Faces", "Faces", "Generate Faces"),
72            ("Struts", "Struts", "Generate Struts"),
73            ("Hubs", "Hubs", "Generate Hubs"),
74            ("Help", "Help", "Not implemented"),
75           ],
76     default='Main')
77
78 #for Faces!
79     facetype_menu = EnumProperty(
80     name="Faces",
81     description="choose a facetype",
82     items=[("0", "strip", "strip"),
83            ("1", "open vertical", "vertical"),
84            ("2", "opwn slanted", "slanted"),
85            ("3", "closed point", "closed point"),
86            ("4", "pillow", "pillow"),
87            ("5", "closed vertical", "closed vertical"),
88            ("6", "stepped", "stepped"),
89            ("7", "spikes", "spikes"),
90            ("8", "boxed", "boxed"),
91            ("9", "diamond", "diamond"),
92            ("10", "bar", "bar"),
93           ],
94     default='0')
95
96     facetoggle = BoolProperty(name="Activate: Face Object", description = "Activate Faces for Geodesic object", default = False )
97 #    faceimporttoggle = BoolProperty(name="faceimporttoggle", default = False )
98     face_use_imported_object = BoolProperty(name="Use: Imported Object",\
99                 description = "Activate faces on your Imported object", default = False)
100     facewidth = FloatProperty(name="facewidth", min = -1, soft_min = 0.001,  max = 4, default = .50)
101     fwtog = BoolProperty(name="fwtog", default = False )
102     faceheight = FloatProperty(name="faceheight", min = 0.001, max = 4, default = 1 )
103     fhtog = BoolProperty(name="fhtog", default = False )
104     face_detach = BoolProperty(name="face_detach", default = False )
105     fmeshname = StringProperty(name="fmeshname", default = "defaultface")
106
107
108     geodesic_types = EnumProperty(
109         name="Objects", 
110         description="Choose Geodesic, Grid, Cylinder, Parabola,\
111                      Torus, Sphere, Import your mesh or Superparameters",
112     items=[("Geodesic", "Geodesic", "Generate Geodesic"),
113            ("Grid", "Grid", "Generate Grid"),
114            ("Cylinder", "Cylinder", "Generate Cylinder"),
115            ("Parabola", "Parabola", "Generate Parabola"),
116            ("Torus", "Torus", "Generate Torus"),
117            ("Sphere", "Sphere", "Generate Sphere"),
118            ("Import your mesh", "Import your mesh", "Import Your Mesh"),
119           ],
120     default = 'Geodesic')
121
122     import_mesh_name = StringProperty(name = "mesh to import",\
123             description = "the name has to be the name of a meshobject", default = "None") 
124
125     base_type = EnumProperty(
126     name="Hedron",
127     description="Choose between Tetrahedron, Octahedron, Icosahedron ",\
128         items=[("Tetrahedron", "Tetrahedron", "Generate Tetrahedron"),\
129                ("Octahedron", "Octahedron", "Generate Octahedron"),\
130                ("Icosahedron", "Icosahedron", "Generate Icosahedron"),
131            ],
132     default='Tetrahedron')
133
134     orientation = EnumProperty(
135     name="Point^",
136     description="Point (Vert), Edge or Face pointing upwards",
137     items=[("PointUp", "PointUp", "Point up"),
138            ("EdgeUp", "EdgeUp", "Edge up"),
139            ("FaceUp", "FaceUp", "Face up"),
140            ],
141     default='PointUp')
142
143     geodesic_class = EnumProperty(
144     name="Class",
145     description="Subdivide Basic/Triacon",
146     items=[("Class 1", "Class 1", "class one"),
147            ("Class 2", "Class 2", "class two"),
148            ],
149     default='Class 1')
150
151     tri_hex_star = EnumProperty(
152     name="Shape",
153     description="Choose between tri hex star face types",
154     items=[("tri", "tri", "tri faces"),
155            ("hex", "hex", "hex faces(by tri)"),
156            ("star", "star", "star faces(by tri)"),
157               ],
158     default='tri')
159
160     spherical_flat = EnumProperty(
161     name="Round",
162     description="Choose between spherical or flat ",
163     items=[("spherical", "spherical", "Generate spherical"),
164            ("flat", "flat", "Generate flat"),
165               ],
166     default='spherical')
167
168     use_imported_mesh = BoolProperty(name="use import",\
169                     description = "Use an imported mesh", default = False)
170
171 #Cylinder
172     cyxres= IntProperty(name="Resolution x/y", min = 3, max = 32,\
173               description = "number of faces around x/y", default = 5 )
174     cyyres= IntProperty(name="Resolution z", min = 3, max = 32,\
175               description = "number of faces in z direction", default = 5 )
176     cyxsz= FloatProperty(name="Scale x/y", min = 0.01, max = 10,\
177                   description = "scale in x/y direction", default = 1 )
178     cyysz= FloatProperty(name="Scale z", min = 0.01, max = 10,\
179               description = "scale in z direction", default = 1 )    
180     cyxell= FloatProperty(name="Stretch x",  min = 0.001, max = 4,\
181               description = "stretch in x direction", default = 1 )
182     cygap= FloatProperty(name="Gap",  min = -2, max = 2,\
183               description = "shrink in % around radius", default = 1 )
184     cygphase= FloatProperty(name="Phase", min = -4, max = 4,\
185               description = "rotate around pivot x/y", default = 0 )
186 #Parabola
187     paxres= IntProperty(name="Resolution x/y",  min = 3, max = 32,\
188            description = "number of faces around x/y", default = 5 )
189     payres= IntProperty(name="Resolution z",  min = 3, max = 32,\
190            description = "number of faces in z direction", default = 5 )
191     paxsz= FloatProperty(name="Scale x/y", min = 0.001, max = 10,\
192            description = "scale in x/y direction", default = 0.30)
193     paysz= FloatProperty(name="Scale z", min = 0.001, max = 10,\
194            description = "scale in z direction",        default = 1 )
195     paxell= FloatProperty(name="Stretch x", min = 0.001, max = 4,\
196            description = "stretch in x direction",      default = 1 )
197     pagap= FloatProperty(name="Gap", min = -2, max = 2,\
198            description = "shrink in % around radius",   default = 1 )
199     pagphase= FloatProperty(name="Phase", min = -4, max = 4,\
200            description = "rotate around pivot x/y",     default = 0 )
201 #Torus            
202     ures= IntProperty(name="Resolution x/y",min = 3, max = 32,\
203            description = "number of faces around x/y", default = 8 )
204     vres= IntProperty(name="Resolution z", min = 3, max = 32,\
205             description = "number of faces in z direction", default = 8 )
206     urad= FloatProperty(name="Radius x/y", min = 0.001, max = 10,\
207             description = "radius in x/y plane",        default = 1 )
208     vrad= FloatProperty(name="Radius z", min = 0.001, max = 10,\
209             description = "radius in z plane",  default = 0.250)
210     uellipse= FloatProperty(name="Stretch x", min = 0.001, max = 10,\
211             description = "number of faces in z direction",     default = 1 )
212     vellipse= FloatProperty(name="Stretch z", min = 0.001, max = 10,\
213             description = "number of faces in z direction",     default = 1 )
214     upart= FloatProperty(name="Gap x/y", min = -4, max = 4,\
215             description = "shrink faces around x/y",    default = 1 )
216     vpart= FloatProperty(name="Gap z", min = -4, max = 4,\
217             description = "shrink faces in z direction",        default = 1 )
218     ugap= FloatProperty(name="Phase x/y",  min = -4, max = 4,\
219            description = "rotate around pivot x/y", default = 0 )
220     vgap= FloatProperty(name="Phase z",  min = -4, max = 4,\
221            description = "rotate around pivot z", default = 0 )
222     uphase= FloatProperty(name="uphase", min = -4, max = 4,\
223             description = "number of faces in z direction",     default = 0 )
224     vphase= FloatProperty(name="vphase",  min = -4, max = 4,\
225             description = "number of faces in z direction",     default = 0 )
226     uexp= FloatProperty(name="uexp",  min = -4, max = 4,\
227             description = "number of faces in z direction",     default = 0 )
228     vexp= FloatProperty(name="vexp",  min = -4, max = 4,\
229             description = "number of faces in z direction",     default = 0 )
230     usuper= FloatProperty(name="usuper", min = -4, max = 4,\
231            description = "first set of superform parameters",  default = 2 )
232     vsuper= FloatProperty(name="vsuper",  min = -4, max = 4,\
233             description = "second set of superform parameters", default = 2 )
234     utwist= FloatProperty(name="Twist x/y", min = -4, max = 4,\
235             description = " use with superformular u",  default = 0 )
236     vtwist= FloatProperty(name="Twist z", min = -4, max = 4,\
237             description = "use with superformular v",   default = 0 )
238
239 #Sphere 
240     bures= IntProperty(name="Resolution x/y", min = 3, max = 32,\
241             description = "number of faces around x/y", default = 8 )
242     bvres= IntProperty(name="Resolution z", min = 3, max = 32,\
243             description = "number of faces in z direction",     default = 8 )
244     burad= FloatProperty(name="Radius",  min = -4, max = 4,\
245             description = "overall radius",     default = 1 )
246     bupart= FloatProperty(name="Gap x/y", min = -4, max = 4,\
247             description = "shrink faces around x/y",    default = 1 )
248     bvpart= FloatProperty(name="Gap z", min = -4, max = 4,\
249             description = "shrink faces in z direction",        default = 1 )
250     buphase= FloatProperty(name="Phase x/y",  min = -4, max = 4,
251             description = "rotate around pivot x/y",    default = 0 )
252     bvphase= FloatProperty(name="Phase z", min = -4, max = 4,\
253             description = "rotate around pivot z",      default = 0 )
254     buellipse= FloatProperty(name="Stretch x", min = 0.001, max = 4,\
255             description = "stretch in the x direction", default = 1 )
256     bvellipse= FloatProperty(name="Stretch z", min = 0.001, max = 4,\
257             description = "stretch in the z direction", default = 1 )
258 #Grid    
259     grxres = IntProperty(name="Resolution x", min = 2, soft_max = 10, max = 20,\
260                          description = "number of faces in x direction", default = 5 )
261     gryres = IntProperty(name="Resolution z",min = 2, soft_min = 2, soft_max=10, max = 20,\
262                          description = "number of faces in x direction", default = 2)
263     grxsz = FloatProperty(name = "X size", min = 1, soft_min=0.01, soft_max=5, max = 10,\
264                          description = "x size", default = 2.0)
265     grysz = FloatProperty(name="Y size",min = 1, soft_min=0.01, soft_max=5, max = 10,\
266                          description = "y size", default = 1.0)
267
268 #PKHG_TODO_??? what means cart
269     cart = IntProperty(name = "cart",min = 0, max = 2,  default = 0)
270     frequency = IntProperty(name="Frequency", min = 1, max = 8,\
271                            description ="subdivide base triangles", default = 1 )
272     eccentricity = FloatProperty(name = "Eccentricity",  min = 0.01 , max = 4,\
273                  description = "scaling in x/y dimension", default = 1 )
274     squish = FloatProperty(name = "Squish",min = 0.01, soft_max = 4, max = 10,\
275                  description = "scaling in z dimension",  default = 1 )
276     radius = FloatProperty(name = "Radius",min = 0.01, soft_max = 4, max = 10,\
277                  description = "overall radius",  default = 1 )
278     squareness = FloatProperty(name="Square x/y", min = 0.1, max = 5,\
279                  description = "superelipse action in x/y", default = 2 )
280     squarez = FloatProperty(name="Square z", min = 0.1, soft_max = 5, max = 10,\
281                  description = "superelipse action in z", default = 2 )
282     baselevel = IntProperty(name="baselevel", default = 5 )
283     dual = BoolProperty(name="Dual", description = "faces become verts,\
284                         verts become faces, edges flip", default = False)
285     rotxy = FloatProperty(name="Rotate x/y", min= -4, max = 4,\
286                  description = "rotate superelipse action in x/y", default = 0 )
287     rotz = FloatProperty(name="Rotate z",  min= -4, max = 4,\
288                  description = "rotate superelipse action in z", default = 0 )
289
290 #for choice of superformula
291     uact = BoolProperty(name = 'superformula u (x/y)',\
292                         description = "activate superformula u parameters", default = False)
293     vact = BoolProperty(name = 'superformula v (z)',\
294                         description = "activate superformula v parameters", default = False)
295     um = FloatProperty(name = 'um', min = 0, soft_min=0.1, soft_max=5,max = 10,\
296                  description = "to do", default =  3)
297     un1 = FloatProperty(name = 'un1', min = 0, soft_min=0.1, soft_max=5,max = 20,\
298                  description = "to do", default =  1)
299     un2 = FloatProperty(name = 'un2', min = 0, soft_min=0.1, soft_max=5,max = 10,\
300                  description = "to do", default =  1)
301     un3 = FloatProperty(name = 'un3', min = 0,   soft_min=0.1, soft_max=5,max = 10,\
302                  description = "to do", default =  1)
303     ua = FloatProperty(name = 'ua', min = 0, soft_min=0.1, soft_max=5,max = 10,\
304                  description = "to do", default =  1.0)
305     ub = FloatProperty(name = 'ub', min = 0, soft_min=0.1, soft_max=5,max = 10,\
306                  description = "to do", default =  4.0)
307     vm = FloatProperty(name = 'vm', min = 0, soft_min=0.1, soft_max=5,max = 10,\
308                  description = "to do", default =  1)
309     vn1 = FloatProperty(name = 'vn1', min = 0, soft_min=0.1, soft_max=5,max = 10,\
310                  description = "to do", default =  1)
311     vn2 = FloatProperty(name = 'vn2', min = 0, soft_min=0.1, soft_max=5,max = 10,\
312                  description = "to do", default =  1)
313     vn3 = FloatProperty(name = 'vn3', min = 0, soft_min=0.1, soft_max=5,max = 10,\
314                  description = "to do", default =  1)
315     va = FloatProperty(name = 'va', min = 0, soft_min=0.1, soft_max=5,max = 10,\
316                  description = "to do", default =  1)
317     vb = FloatProperty(name = 'vb', min = 0, soft_min=0.1, soft_max=5,max = 10,\
318                  description = "to do", default =  1)
319
320     uturn = FloatProperty(name = 'uturn', min = 0, soft_min=0.1, soft_max=5,max = 10,\
321                  description = "to do", default =  0)
322     vturn = FloatProperty(name = 'vturn', min = 0, soft_min=0.1, soft_max=5,max = 10,\
323                  description = "to do", default =  0)
324     utwist = FloatProperty(name = 'utwist', min = 0, soft_min=0.1, soft_max=5,max = 10,\
325                  description = "to do", default =  0)
326     vtwist = FloatProperty(name = 'vtwist', min = 0, soft_min=0.1, soft_max=5,max = 10,\
327                  description = "to do", default =  0)
328
329 #Strut
330     struttype= IntProperty(name="struttype", default= 0)
331     struttoggle = BoolProperty(name="struttoggle", default = False )
332     strutimporttoggle= BoolProperty(name="strutimporttoggle", default = False )
333     strutimpmesh= StringProperty(name="strutimpmesh", default = "None")
334     strutwidth= FloatProperty(name="strutwidth", min = -10, soft_min = 5, soft_max = 5,\
335                               max = 10, default = 1 )
336     swtog= BoolProperty(name="swtog", default = False )
337     strutheight= FloatProperty(name="strutheight", min = -5, soft_min = -1, soft_max = 5,\
338                                max = 10, default = 1 )
339     shtog= BoolProperty(name="shtog", default = False )
340     strutshrink= FloatProperty(name="strutshrink", min = 0.001, max = 4, default = 1 )
341     sstog= BoolProperty(name="sstog", default = False )
342     stretch= FloatProperty(name="stretch",  min= -4, max = 4, default = 1.0 )
343     lift= FloatProperty(name="lift", min = 0.001, max = 10, default = 0 )
344     smeshname= StringProperty(name="smeshname", default = "defaultstrut")
345
346 #Hubs
347     hubtype = BoolProperty(name ="hubtype", description = "not used", default = True )
348     hubtoggle = BoolProperty(name ="hubtoggle", default = False )
349     hubimporttoggle = BoolProperty(name="new import", description = "import a mesh",\
350                                    default = False )
351     hubimpmesh = StringProperty(name="hubimpmesh",\
352                  description = "name of mesh to import",  default = "None")
353     hubwidth = FloatProperty(name="hubwidth", min = 0.01, max = 10,\
354                  default = 1 )
355     hwtog = BoolProperty(name="hwtog", default = False )
356     hubheight = FloatProperty(name="hubheight", min = 0.01, max = 10,\
357                  default = 1 )
358     hhtog = BoolProperty(name="hhtog", default = False )
359     hublength = FloatProperty(name ="hublength", min  = 0.1, max  = 10,\
360                  default  = 1 )
361     hstog= BoolProperty(name="hstog", default = False )
362     hmeshname= StringProperty(name="hmeshname",\
363                               description = "Name of an existing mesh needed!", default = "None")
364
365     name_list = ['facetype_menu','facetoggle','face_use_imported_object',
366 'facewidth','fwtog','faceheight','fhtog',
367 'face_detach','fmeshname','geodesic_types','import_mesh_name',
368 'base_type','orientation','geodesic_class','tri_hex_star',
369 'spherical_flat','use_imported_mesh','cyxres','cyyres',
370 'cyxsz','cyysz','cyxell','cygap',
371 'cygphase','paxres','payres','paxsz',
372 'paysz','paxell','pagap','pagphase',
373 'ures','vres','urad','vrad',
374 'uellipse','vellipse','upart','vpart',
375 'ugap','vgap','uphase','vphase',
376 'uexp','vexp','usuper','vsuper',
377 'utwist','vtwist','bures','bvres',
378 'burad','bupart','bvpart','buphase',
379 'bvphase','buellipse','bvellipse','grxres',
380 'gryres','grxsz','grysz',
381 'cart','frequency','eccentricity','squish',
382 'radius','squareness','squarez','baselevel',
383 'dual','rotxy','rotz',
384 'uact','vact','um','un1',
385 'un2','un3','ua','ub',
386 'vm','vn1','vn2','vn3',
387 'va','vb','uturn','vturn',
388 'utwist','vtwist','struttype','struttoggle',
389 'strutimporttoggle','strutimpmesh','strutwidth','swtog',
390 'strutheight','shtog','strutshrink','sstog',
391 'stretch','lift','smeshname','hubtype',
392 'hubtoggle','hubimporttoggle','hubimpmesh','hubwidth',
393 'hwtog','hubheight','hhtog','hublength',
394 'hstog','hmeshname']    
395
396     def write_params(self,filename):
397         file = open(filename, "w", encoding="utf8", newline="\n")
398         fw = file.write
399     #for Faces!
400         for el in self.name_list:
401             fw(el + ", ")
402             fw(repr(getattr(self,el)))
403             fw(",\n")
404         file.close()
405
406     def read_file(self,filename):
407         file = open(filename, "r", newline="\n")
408         result = []
409         line = file.readline()
410         while(line):
411             tmp = line.split(", ")
412             result.append(eval(tmp[1]))
413             line = file.readline()
414         return result
415     
416
417     def draw(self,context):
418         sce = context.scene
419         layout = self.layout
420         row = layout.row()
421         row.prop(self, "save_parameters")
422         row.prop(self, "load_parameters")
423         col = layout.column()
424         col.label(" ")
425         col.prop(self, "mainpages")
426         which_mainpages = self.mainpages
427         if which_mainpages == 'Main':
428             col = layout.column()
429             col.prop(self, "geodesic_types")
430             tmp = self.geodesic_types
431             if tmp == "Geodesic":
432                 col.label(text="Geodesic Object Types:")
433                 col.prop(self, "geodesic_class")                
434                 col.prop(self, "base_type")
435                 col.prop(self, "orientation")
436                 col.prop(self, "tri_hex_star")
437                 col.prop(self, "spherical_flat")
438                 col.label("Geodesic Object Parameters:")
439                 row = layout.row()
440                 row.prop(self, "frequency")
441                 row = layout.row()
442                 row.prop(self, "radius")
443                 row = layout.row()
444                 row.prop(self, "eccentricity")
445                 row = layout.row()
446                 row.prop(self, "squish")
447                 row = layout.row()
448                 row.prop(self, "squareness")
449                 row = layout.row()
450                 row.prop(self, "squarez")
451                 row = layout.row()
452                 row.prop(self, "rotxy")
453                 row = layout.row()
454                 row.prop(self, "rotz")
455                 row = layout.row()
456                 row.prop(self, "dual")
457             elif tmp == 'Torus':
458                 col.label("Torus Parameters")
459                 row = layout.row()
460                 row.prop(self, "ures")
461                 row = layout.row()
462                 row.prop(self, "vres")
463                 row = layout.row()
464                 row.prop(self, "urad")
465                 row = layout.row()
466                 row.prop(self, "vrad")
467                 row = layout.row()
468                 row.prop(self, "uellipse")
469                 row = layout.row()
470                 row.prop(self, "vellipse")
471                 row = layout.row()
472                 row.prop(self, "upart")
473                 row = layout.row()
474                 row.prop(self, "vpart")
475                 row = layout.row()
476                 row.prop(self, "ugap")
477                 row.prop(self, "vgap")
478                 row = layout.row()
479                 row.prop(self, "uphase")
480                 row.prop(self, "vphase")
481                 row = layout.row()
482                 row.prop(self, "uexp")
483                 row.prop(self, "vexp")
484                 row = layout.row()
485                 row.prop(self, "usuper")
486                 row.prop(self, "vsuper")
487                 row = layout.row()
488                 row.prop(self, "vgap")
489                 row = layout.row()
490             elif tmp == 'Sphere':
491                 col.label("Sphere Parameters")
492                 row = layout.row()
493                 row.prop(self, "bures")
494                 row = layout.row()
495                 row.prop(self, "bvres")
496                 row = layout.row()
497                 row.prop(self, "burad")
498                 row = layout.row()                
499                 row.prop(self, "bupart")
500                 row = layout.row()
501                 row.prop(self, "buphase")
502                 row = layout.row()
503                 row.prop(self, "bvpart")
504                 row = layout.row()
505                 row.prop(self, "bvphase")
506                 row = layout.row()
507                 row.prop(self, "buellipse")
508                 row = layout.row()
509                 row.prop(self, "bvellipse")
510             elif tmp == 'Parabola':
511                 col.label("Parabola Parameters")
512                 row = layout.row()
513                 row.prop(self, "paxres")
514                 row = layout.row()
515                 row.prop(self, "payres")
516                 row = layout.row()
517                 row.prop(self, "paxsz")
518                 row = layout.row()
519                 row.prop(self, "paysz")
520                 row = layout.row()
521                 row.prop(self, "paxell")
522                 row = layout.row()
523                 row.prop(self, "pagap")
524                 row = layout.row()
525                 row.prop(self, "pagphase")
526             elif tmp == 'Cylinder':
527                 col.label("Cylinder Parameters")
528                 col.prop(self, "cyxres")
529                 col.prop(self, "cyyres")
530                 col.prop(self, "cyxsz")
531                 col.prop(self, "cyysz")
532                 col.prop(self, "cyxell")
533                 col.prop(self, "cygap")
534                 col.prop(self, "cygphase")
535             elif tmp == 'Grid':
536                 col.label("Grid Parameters")
537                 row = layout.row()
538                 row.prop(self, "grxres")
539                 row = layout.row()
540                 row.prop(self, "gryres")
541                 row = layout.row()
542                 row.prop(self, "grxsz")
543                 row = layout.row()
544                 row.prop(self, "grysz")
545             elif tmp == 'Import your mesh':
546                 col.prop(self, "use_imported_mesh")
547                 col.prop(self, "import_mesh_name")
548 #######superform parameters only where possible
549             row = layout.row()
550             row.prop(self, "uact")
551             row = layout.row()
552             row.prop(self, "vact")                
553             row = layout.row()
554             if not(tmp == 'Import your mesh'):
555                 if (self.uact == False) and (self.vact == False):
556                     row.label("no checkbox active!")
557                 else:
558                     row.label("Superform Parameters")
559                 if self.uact:
560                     row = layout.row()
561                     row.prop(self, "um")
562                     row = layout.row()
563                     row.prop(self, "un1")
564                     row = layout.row()
565                     row.prop(self, "un2")
566                     row = layout.row()
567                     row.prop(self, "un3")
568                     row = layout.row()
569                     row.prop(self, "ua")
570                     row = layout.row()
571                     row.prop(self, "ub")
572                     row = layout.row()
573                     row.prop(self, "uturn")
574                     row = layout.row()
575                     row.prop(self, "utwist")
576                 if self.vact:
577                     row = layout.row()
578                     row.prop(self, "vm")
579                     row = layout.row()
580                     row.prop(self, "vn1")
581                     row = layout.row()
582                     row.prop(self, "vn2")
583                     row = layout.row()
584                     row.prop(self, "vn3")
585                     row = layout.row()
586                     row.prop(self, "va")
587                     row = layout.row()
588                     row.prop(self, "vb")
589                     row = layout.row()
590                     row.prop(self, "vturn")
591                     row = layout.row()
592                     row.prop(self, "vtwist")                
593 ########einde superform
594         elif  which_mainpages == "Hubs":
595             row = layout.row()
596             row.prop(self, "hubtoggle")
597 #PKHG_NOT_USDED_YET_24-11            row.prop(self, "hubtype")
598             row = layout.row()            
599 #25-11 not needed            row.prop(self, "hubimporttoggle")
600             row = layout.row()
601             if self.hubimpmesh == "None":
602                 row = layout.row()
603                 row.label("name of a hub to use")
604                 row = layout.row()
605             row.prop(self, "hubimpmesh")
606             row = layout.row()
607             if self.hmeshname == "None":
608                 row = layout.row()
609                 row.label("name of mesh to be filled in!")
610                 row = layout.row()
611             row.prop(self, "hmeshname")
612             row = layout.row()
613             row.prop(self, "hwtog")
614             if self.hwtog:
615                 row.prop(self, "hubwidth")
616             row = layout.row()
617             row.prop(self, "hhtog")
618             if self.hhtog:
619                 row.prop(self, "hubheight")
620             row = layout.row()
621             row.prop(self, "hublength")                
622         elif which_mainpages == "Struts":
623             row = layout.row()
624             row.prop(self, "struttype")
625             row.prop(self, "struttoggle")
626 #            row = layout.row()            
627 #            row.prop(self, "strutimporttoggle")
628             row = layout.row()            
629             row.prop(self, "strutimpmesh")
630             row = layout.row()
631             row.prop(self, "swtog")
632             if self.swtog:
633                 row.prop(self, "strutwidth")
634             row = layout.row()
635             row.prop(self, "shtog")
636             if self.shtog:
637                 row.prop(self, "strutheight")
638             row = layout.row()
639             row.prop(self, "sstog")
640             if self.sstog:
641                row.prop(self, "strutshrink")
642             row = layout.row()               
643             row.prop(self, "stretch")
644             row = layout.row()            
645             row.prop(self, "lift")
646             row = layout.row()            
647             row.prop(self, "smeshname")
648         elif which_mainpages == "Faces":
649             row = layout.row()
650             row.prop(self, "facetoggle")
651             row = layout.row()
652             row.prop(self, "face_use_imported_object")
653             row = layout.row()
654             row.prop(self, "facetype_menu")
655             row = layout.row()
656             row.prop(self, "fwtog")
657             if self.fwtog:
658                 row.prop(self, "facewidth")
659             row = layout.row()
660             row.prop(self, "fhtog")
661             if self.fhtog:
662                 row.prop(self, "faceheight")
663             row = layout.row()
664             row.prop(self, "face_detach")
665             row = layout.row()
666             row.prop(self, "fmeshname")
667             row = layout.row()
668         
669         #help menu GUI
670         elif which_mainpages == "Help":
671             import textwrap
672
673             # a function that allows for multiple labels with text that wraps
674             # you can allow the user to set where the text wraps with the 
675             # text_width parameter
676             # other parameters are ui : here you usually pass layout
677             # text: is a list with each index representing a line of text
678             
679             def multi_label(text, ui,text_width=120):
680                 for x in range(0,len(text)):
681                     el = textwrap.wrap(text[x], width = text_width )
682             
683                     for y in range(0,len(el)):
684                         ui.label(text=el[y])
685
686             box = layout.box() 
687             help_text = ["NEW!", 
688                 "New facility: save or load (nearly all) parameters",
689                  "A file GD_0.GD will be used, living in:",
690                  "geodesic_domes/tmp",
691                  "--------",
692                  "After loading you have to change a ",
693                  "parameter back and forth"
694                  "to see it"]
695             text_width = self.gd_help_text_width
696             box.prop(self, "gd_help_text_width",slider=True)
697             multi_label(help_text,box, text_width)
698
699     def execute(self, context):
700         global last_generated_object, last_imported_mesh, basegeodesic, imported_hubmesh_to_use 
701         #default superformparam = [3, 10, 10, 10, 1, 1, 4, 10, 10, 10, 1, 1, 0, 0, 0.0, 0.0, 0, 0]]
702         superformparam = [self.um, self.un1, self.un2, self.un3, self.ua,\
703                           self.ub, self.vm, self.vn1, self.vn2, self.vn3,\
704                           self.va, self.vb, self.uact, self.vact,\
705                           self.uturn*pi, self.vturn*pi, \
706                           self.utwist, self.vtwist]
707         context.scene.error_message = "" 
708         if self.mainpages == 'Main':
709             if self.geodesic_types == "Geodesic":
710                 tmp_fs = self.tri_hex_star
711                 faceshape = 0 # tri!
712                 if tmp_fs == "hex":
713                     faceshape = 1
714                 elif tmp_fs == "star":
715                     faceshape = 2
716                 tmp_cl = self.geodesic_class
717                 klass = 0
718                 if tmp_cl == "Class 2":
719                     klass = 1
720                 shape = 0 
721                 parameters = [self.frequency, self.eccentricity, self.squish,\
722                           self.radius, self.squareness, self.squarez, 0,\
723                           shape, self.baselevel, faceshape, self.dual,\
724                           self.rotxy, self.rotz, klass, superformparam]               
725                 basegeodesic =  creategeo(self.base_type,self.orientation,parameters)
726                 basegeodesic.makegeodesic()
727                 basegeodesic.connectivity()
728                 mesh = vefm_271.mesh()                
729                 vefm_271.finalfill(basegeodesic,mesh) #always! for hexifiy etc. necessarry!!!                     
730                 vefm_271.vefm_add_object(mesh)
731                 last_generated_object = context.active_object
732                 last_generated_object.location  = (0,0,0)
733                 context.scene.objects.active = last_generated_object            
734             elif self.geodesic_types == 'Grid':
735                 basegeodesic = forms_271.grid(self.grxres,self.gryres,\
736                        self.grxsz,self.grysz,1.0,1.0,0,0,0,\
737                                       0,1.0,1.0,superformparam)
738                 vefm_271.vefm_add_object(basegeodesic)
739                 bpy.data.objects[-1].location = (0,0,0)
740             elif self.geodesic_types == "Cylinder":
741                 basegeodesic = forms_271.cylinder(self.cyxres, self.cyyres, \
742                                    self.cyxsz, self.cyysz, self.cygap, \
743                                    1.0, self.cygphase, 0, 0, 0, self.cyxell,\
744                                    1.0, superformparam)
745                 vefm_271.vefm_add_object(basegeodesic)
746                 bpy.data.objects[-1].location = (0,0,0)                
747                 
748             elif self.geodesic_types == "Parabola":
749                 basegeodesic=forms_271.parabola(self.paxres, self.payres,\
750                     self.paxsz, self.paysz, self.pagap,1.0, self.pagphase,\
751                     0,0,0, self.paxell,1.0,superformparam)
752                 vefm_271.vefm_add_object(basegeodesic)
753                 bpy.data.objects[-1].location = (0,0,0)                
754             elif self.geodesic_types == "Torus":
755                 basegeodesic = forms_271.torus(self.ures, self.vres,\
756                        self.vrad, self.urad, self.upart, self.vpart,\
757                        self.ugap, self.vgap,0,0, self.uellipse,\
758                        self.vellipse, superformparam)
759                 vefm_271.vefm_add_object(basegeodesic)
760                 bpy.data.objects[-1].location = (0,0,0)
761             elif self.geodesic_types == "Sphere":
762                 basegeodesic=forms_271.sphere(self.bures, self.bvres,\
763                         self.burad,1.0, self.bupart, self.bvpart,\
764                         self.buphase, self.bvphase,0,0, self.buellipse,\
765                         self.bvellipse,superformparam)  
766
767                 vefm_271.vefm_add_object(basegeodesic)
768                 bpy.data.objects[-1].location = (0,0,0)                
769             elif self.geodesic_types == "Import your mesh":
770                 obj_name = self.import_mesh_name
771                 if obj_name == "None":
772                     message = "fill in a name \nof an existing mesh\nto be imported"
773                     context.scene.error_message = message
774                     self.report({"INFO"}, message)
775                     print("***INFO*** you have to fill in the name of an existing mesh")
776                 else:
777 #                    obj_in_scene = context.objects
778                     names = [el.name for el in context.scene.objects]
779                     if obj_name in names and context.scene.objects[obj_name].type == "MESH":
780                         obj = context.scene.objects[obj_name]
781 #                        if obj.type == "MESH":                        
782                         your_obj = vefm_271.importmesh(obj.name,False)
783                         last_imported_mesh = your_obj
784                         vefm_271.vefm_add_object(your_obj)
785                         last_generated_object = bpy.context.active_object
786                         last_generated_object.name ="Imported mesh"
787                         bpy.context.active_object.location = (0,0,0)
788                     else:
789                         message = obj_name +" does not exist \nor is not a MESH"
790                         context.scene.error_message = message                
791                         bpy.ops.object.dialog_operator('INVOKE_DEFAULT')
792                         self.report({'ERROR'}, message)
793                         print("***ERROR***" + obj_name +" does not exist or is not a MESH")
794         elif self.mainpages == "Hubs":
795             hubtype = self.hubtype
796             hubtoggle =  self.hubtoggle
797             hubimporttoggle = self.hubimporttoggle
798             hubimpmesh = self.hubimpmesh
799             hubwidth = self.hubwidth
800             hwtog = self.hwtog
801             hubheight = self.hubheight
802             hhtog = self.hhtog
803             hublength = self.hublength
804             hstog =  self.hstog
805             hmeshname=  self.hmeshname
806 #PKHG_TODO_27-11 better info!??
807             if not (hmeshname == "None") and not (hubimpmesh == "None") and  hubtoggle:                
808                 try:                    
809                     print("\nDBG third_domes L799 hmeshname= ", hmeshname)
810                     hub_obj = vefm_271.importmesh(hmeshname,0)
811                     print("\nDBG third_domes L801 hub_obj = ", hub_obj.faces[:])
812                     hub = vefm_271.hub(hub_obj, True,\
813                             hubwidth, hubheight, hublength,\
814                               hwtog, hhtog, hstog, hubimpmesh)
815                     print("\nDBG third_domes L805 de hub: ", hub)
816                     mesh = vefm_271.mesh("test")
817                     vefm_271.finalfill(hub,mesh)
818                     vefm_271.vefm_add_object(mesh)
819                     bpy.data.objects[-1].location = (0,0,0)
820                 except:
821                     message = "***ERROR third_domes_panel L811 *** \neither no mesh for hub\nor " + hmeshname +  " available"                    
822                     context.scene.error_message = message
823                     bpy.ops.object.dialog_operator('INVOKE_DEFAULT')
824                     print(message)                
825             else:
826                 message = "***INFO***\nuse the hub toggle!"
827                 context.scene.error_message = message
828                 print("\n***INFO*** use the hub toggle!")
829         elif self.mainpages == "Struts":
830             struttype = self.struttype
831             struttoggle = self.struttoggle
832             strutimporttoggle = self.strutimporttoggle
833             strutimpmesh = self.strutimpmesh
834             strutwidth = self.strutwidth
835             swtog = self.swtog
836             strutheight = self.strutheight
837             shtog = self.shtog
838             strutshrink = self.strutshrink
839             sstog = self.sstog
840             stretch = self.stretch
841             lift = self.lift
842             smeshname = self.smeshname
843             if not (strutimpmesh == "None") and struttoggle:
844                 names = [el.name for el in context.scene.objects]
845                 if strutimpmesh in names and context.scene.objects[strutimpmesh].type == "MESH":
846                     strut = vefm_271.strut(basegeodesic, struttype, strutwidth,\
847                                            strutheight, stretch, swtog, shtog, swtog,\
848                                            strutimpmesh, sstog, lift)
849                     strutmesh = vefm_271.mesh()
850                     vefm_271.finalfill(strut,strutmesh)
851                     vefm_271.vefm_add_object(strutmesh)
852                     last_generated_object = context.active_object
853                     last_generated_object.name = smeshname
854                     last_generated_object.location  = (0,0,0)
855                 else:
856                     message = "***ERROR***\n" + strutimpmesh + "\nis not a MESH"
857                     context.scene.error_message = message
858                     bpy.ops.object.dialog_operator('INVOKE_DEFAULT')
859                     print("***ERROR*** strut obj is not a MESH")
860             else:
861                 vefm_271.vefm_add_object(basegeodesic)
862         elif self.mainpages == "Faces":
863             if self.facetoggle:
864                 faceparams=[[self.face_detach,0,[[0.5,0.0]]], #0 strip
865                             [self.face_detach,0,[[0.0,0.5]]], #1 vertical
866                             [self.face_detach,0,[[0.5,0.5]]], #2 slanted
867                             [self.face_detach,1,[[0.25,0.25],[0.5,0.5]]], #3 closed point
868                             [self.face_detach,1,[[0.1,0.03],[0.33,0.06],[0.0,0.1]]], #4 pillow
869                             [self.face_detach,2,[[0.0,0.5]]], #5 closed vertical
870                             [self.face_detach,2,[[0.0,0.25],[0.25,0.25],[0.25,0.5]]], #6 stepped
871                             [self.face_detach,1,[[0.2,0.1],[0.4,0.2],[0.0,1.0]]], #7 spikes
872                             [self.face_detach,3,[[0.25,0.0],[0.25,0.5],[0.0,0.5]]], #8 boxed 
873                             [self.face_detach,3,[[0.25,0.5],[0.5,0.0],[0.25,-0.5]]], #9 diamond
874                             [self.face_detach,4,[[0.5,0.0],[0.5,0.5],[0.0,0.5]]],] #10 bar
875                 facedata = faceparams[int(self.facetype_menu)]
876                 if not self.face_use_imported_object:
877                     faceobject = vefm_271.facetype(basegeodesic, facedata, self.facewidth,\
878                                                    self.faceheight,self.fwtog)
879                 else:
880                     if last_imported_mesh: 
881                         faceobject = vefm_271.facetype(last_imported_mesh, facedata,\
882                                                        self.facewidth, self.faceheight, self.fwtog)
883                     else:
884                         message = "***ERROR***\nno imported message available\n" + "last geodesic used" 
885                         context.scene.error_message = message
886                         bpy.ops.object.dialog_operator('INVOKE_DEFAULT')
887                         print("\n***ERROR*** no imported mesh available")
888                         print("last geodesic used!")
889                         faceobject = vefm_271.facetype(basegeodesic,facedata,\
890                                      self.facewidth,self.faceheight,self.fwtog)
891                 facemesh = vefm_271.mesh()
892                 finalfill(faceobject, facemesh)
893                 vefm_271.vefm_add_object(facemesh)
894                 obj = bpy.data.objects[-1]
895                 obj.name = self.fmeshname
896                 obj.location = (0,0,0)
897 #PKHG save or load (nearly) all parameters                
898         if self.save_parameters:
899             self.save_parameters = False
900             try:
901                 scriptpath = bpy.utils.script_paths()[0]
902                 sep = os.path.sep
903                 tmpdir = os.path.join(scriptpath, "addons", "geodesic_domes" , "tmp")
904 #scriptpath + sep + "addons" + sep + "geodesic_domes" + sep + "tmp"                              
905                 if not os.path.isdir(tmpdir):
906                     message = "***ERROR***\n" + tmpdir + "\nnot (yet) available"  
907                     
908                 filename = tmpdir + sep + "GD_0.GD"
909 #        self.read_file(filename)
910                 try:
911                     self.write_params(filename)
912                     message = "***OK***\nparameters saved in\n" + filename
913                     print(message)
914                 except:
915                     message = "***ERRROR***\n" + "writing " + filename + "\nnot possible"
916                 #bpy.context.scene.instant_filenames = filenames
917                 
918             except:
919                 message = "***ERROR***\n Contakt PKHG, something wrong happened"
920                 
921             context.scene.error_message = message
922             bpy.ops.object.dialog_operator('INVOKE_DEFAULT')
923
924         if self.load_parameters:
925             self.load_parameters = False
926             try:
927                 scriptpath = bpy.utils.script_paths()[0]
928                 sep = os.path.sep
929                 tmpdir = os.path.join(scriptpath, "addons", "geodesic_domes" , "tmp")
930                 #PKHG>NEXT comment????
931                 #scriptpath + sep + "addons" + sep + "geodesic_domes" + sep + "tmp"                              
932                 if not os.path.isdir(tmpdir):
933                     message = "***ERROR***\n" + tmpdir + "\nnot available"  
934                     print(message)
935                 filename = tmpdir + sep + "GD_0.GD"
936 #        self.read_file(filename)
937                 try:
938                     res = self.read_file(filename)
939                     for i,el in enumerate(self.name_list):
940                         setattr(self,el,res[i])
941                     message = "***OK***\nparameters read from\n" + filename
942                     print(message)
943                 except:
944                     message = "***ERRROR***\n" + "writing " + filename + "\nnot possible"
945                     #bpy.context.scene.instant_filenames = filenames
946             except:
947                 message = "***ERROR***\n Contakt PKHG,\nsomething went wrong reading params happened"
948             context.scene.error_message = message
949             bpy.ops.object.dialog_operator('INVOKE_DEFAULT')
950         return {'FINISHED'}
951     
952     def invoke(self, context, event):
953         global basegeodesic
954         bpy.ops.view3d.snap_cursor_to_center()
955         tmp = context.scene.geodesic_not_yet_called
956         if tmp:            
957             context.scene.geodesic_not_yet_called = False
958         self.execute(context)
959         return {'FINISHED'}
960
961 def creategeo(polytype,orientation,parameters):
962     geo = None
963     if polytype == "Tetrahedron":
964         if orientation == "PointUp":
965             geo = geodesic_classes_271.tetrahedron(parameters)
966         elif orientation == "EdgeUp":
967             geo=geodesic_classes_271.tetraedge(parameters)
968         elif orientation == "FaceUp":
969             geo=geodesic_classes_271.tetraface(parameters)
970     elif polytype == "Octahedron": 
971         if orientation == "PointUp":
972             geo=geodesic_classes_271.octahedron(parameters)
973         elif orientation == "EdgeUp":
974             geo=geodesic_classes_271.octaedge(parameters)
975         elif orientation == "FaceUp":
976             geo=geodesic_classes_271.octaface(parameters)
977     elif polytype == "Icosahedron":
978         if orientation == "PointUp":
979             geo=geodesic_classes_271.icosahedron(parameters)
980         elif orientation == "EdgeUp":
981             geo=geodesic_classes_271.icoedge(parameters)
982         elif orientation == "FaceUp":
983             geo=geodesic_classes_271.icoface(parameters)
984     return geo
985     
986 basegeodesic,fmeshname,smeshname,hmeshname,outputmeshname,strutimpmesh,hubimpmesh = [None]*7
987
988 def finalfill(source,target):
989     count=0
990     for point in source.verts:
991         newvert = vefm_271.vertex(point.vector)
992         target.verts.append(newvert)
993         point.index = count
994         count  += 1 
995     for facey in source.faces:
996         row=len(facey.vertices)
997         if row >= 5:
998             newvert = vefm_271.average(facey.vertices).centroid()
999             centre = vefm_271.vertex(newvert.vector)
1000             target.verts.append(centre)
1001             for i in range(row):
1002                 if i == row - 1:
1003                     a = target.verts[facey.vertices[-1].index]
1004                     b = target.verts[facey.vertices[0].index]
1005                 else:
1006                     a = target.verts[facey.vertices[i].index]
1007                     b = target.verts[facey.vertices[i+1].index]
1008                 c = centre
1009                 f = [a,b,c]
1010                 target.faces.append(f)
1011         else:
1012             f = []
1013             for j in range(len(facey.vertices)):
1014
1015                 a = facey.vertices[j]
1016                 f.append(target.verts[a.index])
1017             target.faces.append(f)
1018         
1019 ###for error messages         
1020 class DialogOperator(bpy.types.Operator):
1021     bl_idname = "object.dialog_operator"
1022     bl_label = "INFO"
1023
1024     def draw(self,context):
1025         layout = self.layout
1026         message = context.scene.error_message
1027         col = layout.column()
1028         tmp = message.split("\n")
1029         for el in tmp:
1030             col.label(el)
1031         
1032     def execute(self, context):
1033         return {'FINISHED'}
1034
1035     def invoke(self, context, event):
1036         wm = context.window_manager
1037         return wm.invoke_props_dialog(self)
1038             
1039
1040 ######### register all
1041 def register():
1042     bpy.utils.register_module(__name__)
1043
1044 def unregister():
1045     bpy.utils.unregister_module(__name__)
1046
1047 if __name__ == "__main__":
1048     register()
1049