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