use new preferences standard and fixes for various blender changes
[blender-addons-contrib.git] / add_mesh_building_objects / add_mesh_sove.py
1 '''bl_info = {
2     "name": "Sove",
3     "author": "SayPRODUCTIONS",
4     "version": (1, 0),
5     "blender": (2, 59, 0),
6     "api": 33333,
7     "location": "View3D > Add > Mesh > Say3D",
8     "description": "Sove Framema",
9     "warning": "",
10     "wiki_url": "",
11     "tracker_url": "",
12     "category": "Add Mesh"}
13         '''
14 import bpy
15 from bpy.props import *
16 from bpy_extras.object_utils import object_data_add
17 from mathutils import Vector
18 import operator
19 from math import pi, sin, cos, sqrt, atan
20
21 def MSVE():
22     if 'Sove' not in bpy.data.materials:
23         mtl=bpy.data.materials.new('Sove')
24         mtl.diffuse_color     = (0.44,0.52,0.64)
25         mtl.diffuse_shader    = 'LAMBERT' 
26         mtl.diffuse_intensity = 1.0 
27     else:
28         mtl=bpy.data.materials['Sove']
29     return mtl
30 def Prs(self,v1,v2,v3,v4,v5,v6,v7,v8,v9,fg,fh,fd,
31         f0,f1,f2,f3,f4,f5,f6,f7,f8,f9):
32     self.gen=v1;self.knr=v2;self.yuk=v3
33     self.alt=v4;self.ust=v5;self.sdr=v6
34     self.pdr=v7;self.dh =v8;self.dr =v9
35     self.fg =fg;self.fh =fh;self.fd =fd
36     self.f0 =f0;self.f1 =f1;self.f2 =f2;self.f3=f3;self.f4=f4
37     self.f5 =f5;self.f6 =f6;self.f7 =f7;self.f8=f8;self.f9=f9
38 def add_object(self, context):
39     fc=[];vr=[]
40     mx =self.gen/200;my =self.yuk/100;k1=self.knr/100;dh=self.dh/100;fd=self.fd/100;fh=self.fh/100
41     alt=self.alt/100;ust=my-self.ust/100;drn=-self.sdr/100;pdr=self.pdr/100
42     vr.append([-mx-k1,  0,  0]);vr.append([ mx+k1,  0,  0]);vr.append([ mx+k1,  0, my]);vr.append([-mx-k1,  0, my])
43     vr.append([-mx,   pdr,alt]);vr.append([ mx,   pdr,alt]);vr.append([ mx,   pdr,ust]);vr.append([-mx,   pdr,ust])
44     vr.append([-mx-k1,drn,  0]);vr.append([ mx+k1,drn,  0]);vr.append([ mx+k1,drn, my]);vr.append([-mx-k1,drn, my])
45     vr.append([-mx,   drn,alt]);vr.append([ mx,   drn,alt]);vr.append([ mx,   drn,ust]);vr.append([-mx,   drn,ust])
46     fc.append([ 8, 0, 1, 9]);fc.append([ 8, 9,13,12])
47     fc.append([12,13, 5, 4]);fc.append([11,10, 2, 3])
48     if self.fg==0:
49         fc.append([ 0, 8,11, 3]);fc.append([ 8,12,15,11]);fc.append([12, 4, 7,15])
50         fc.append([ 5,13,14, 6]);fc.append([13, 9,10,14]);fc.append([ 9, 1, 2,10])
51     else:
52         fc.append([11, 3,16,17]);fc.append([15,11,17,18]);fc.append([ 7,15,18,24])
53         fc.append([25,19,14, 6]);fc.append([19,20,10,14]);fc.append([20,21, 2,10])
54         ou=self.fg*12
55         fc.append([4,7,12+ou,24+ou]);fc.append([6,5,25+ou,13+ou])
56     z=my
57     for i in range(self.fg):
58         if i==0:z-=self.f0/100
59         if i==1:z-=self.f1/100
60         if i==2:z-=self.f2/100
61         if i==3:z-=self.f3/100
62         if i==4:z-=self.f4/100
63         if i==5:z-=self.f5/100
64         if i==6:z-=self.f6/100
65         if i==7:z-=self.f7/100
66         if i==8:z-=self.f8/100
67         if i==9:z-=self.f9/100
68         vr.append([   -mx-k1,     0,z]);vr.append([   -mx-k1,   drn,z]);vr.append([     -mx,   drn,z])
69         vr.append([       mx,   drn,z]);vr.append([    mx+k1,   drn,z]);vr.append([   mx+k1,     0,z])
70         vr.append([-mx-k1+fd,     0,z]);vr.append([-mx-k1+fd,drn+fd,z]);vr.append([     -mx,drn+fd,z])
71         vr.append([       mx,drn+fd,z]);vr.append([ mx+k1-fd,drn+fd,z]);vr.append([mx+k1-fd,     0,z])
72         z-=fh
73         vr.append([   -mx-k1,     0,z]);vr.append([   -mx-k1,   drn,z]);vr.append([     -mx,   drn,z])
74         vr.append([       mx,   drn,z]);vr.append([    mx+k1,   drn,z]);vr.append([   mx+k1,     0,z])
75         vr.append([-mx-k1+fd,     0,z]);vr.append([-mx-k1+fd,drn+fd,z]);vr.append([     -mx,drn+fd,z])
76         vr.append([       mx,drn+fd,z]);vr.append([ mx+k1-fd,drn+fd,z]);vr.append([mx+k1-fd,     0,z])
77         n=len(vr)
78         fc.append([n- 1,n- 2,n- 8,n- 7]);fc.append([n- 3,n- 9,n- 8,n- 2]);fc.append([n- 2,n- 1,n-13,n-14])
79         fc.append([n- 3,n- 2,n-14,n-15]);fc.append([n-15,n-14,n-20,n-21]);fc.append([n-14,n-13,n-19,n-20])
80         fc.append([n- 4,n- 5,n-11,n-10]);fc.append([n- 5,n- 6,n-12,n-11]);fc.append([n- 5,n- 4,n-16,n-17])
81         fc.append([n- 6,n- 5,n-17,n-18]);fc.append([n-24,n-18,n-17,n-23]);fc.append([n-23,n-17,n-16,n-22])
82         if self.fg>1:
83             if self.fg%2==0:
84                 if i < self.fg/2:fc.append([7,n-16,n-4]);fc.append([6,n-3,n-15])
85                 if i+1<self.fg/2:fc.append([7,n- 4,n+8]);fc.append([6,n+9,n- 3])
86                 if i+1>self.fg/2:fc.append([4,n-16,n-4]);fc.append([5,n-3,n-15])
87                 if i+1>self.fg/2 and i+1<self.fg:fc.append([4,n-4,n+8]);fc.append([5,n+9,n-3])
88             else:
89                 if i<self.fg//2:
90                     fc.append([7,n-16,n-4]);fc.append([6,n-3,n-15])
91                     fc.append([7,n- 4,n+8]);fc.append([6,n+9,n- 3])
92                 if i > self.fg//2:fc.append([4,n-16,n-4]);fc.append([5,n-3,n-15])
93                 if i+1>self.fg//2 and i+1<self.fg:fc.append([4,n- 4,n+8]);fc.append([5,n+9,n-3])
94         if i<self.fg-1 and self.fg>1:
95             fc.append([n- 7,n- 8,n+4,n+5]);fc.append([n- 8,n- 9,n+3,n+4]);fc.append([n-9,n- 3,n+9,n+3])
96             fc.append([n-10,n-11,n+1,n+2]);fc.append([n-11,n-12, n ,n+1]);fc.append([n-4,n-10,n+2,n+8])
97         if i==self.fg-1:
98             fc.append([0, 8,n-11,n-12]);fc.append([ 8,12,n-10,n-11]);fc.append([12,4,n-4,n-10])
99             fc.append([5,13,n- 9,n- 3]);fc.append([13, 9,n- 8,n- 9]);fc.append([ 9,1,n-7,n- 8])
100     SM=[]
101     #Duz----------------
102     if self.dr==False:
103         fc.append([14,10,11,15]);fc.append([6,14,15,7])
104     #Yuvarlak-----------
105     else:        
106         if dh>mx:dh=mx;self.dh=mx*100
107         vr[ 6][2]-=dh;vr[ 7][2]-=dh
108         vr[14][2]-=dh;vr[15][2]-=dh
109         O=mx/dh
110         H1=sqrt(mx**2+dh**2)/2
111         H2=H1*O
112         R=sqrt(H1**2+H2**2)
113         M=ust-R
114         A=pi-atan(O)*2
115         for a in range(1,24):
116             p=(a*A/12)+(pi*1.5)-A
117             vr.append([cos(p)*R,pdr,M-sin(p)*R])
118             vr.append([cos(p)*R,drn,M-sin(p)*R])
119             n=len(vr)
120             if a==1:
121                 fc.append([n-1,15,7,n-2])
122                 SM.append(len(fc))
123                 fc.append([15,n-1,11])
124             elif a<23:
125                 fc.append([n-1,n-3,n-4,n-2])
126                 SM.append(len(fc))
127                 if a<13:   fc.append([n-3,n-1,11])
128                 elif a==13:fc.append([n-3,n-1,10,11])
129                 else:      fc.append([n-3,n-1,10])
130             elif a==23:
131                 fc.append([n-1,n-3,n-4,n-2])
132                 SM.append(len(fc))
133                 fc.append([n-3,n-1,10])
134                 fc.append([14,n-1,n-2,6])
135                 SM.append(len(fc))
136                 fc.append([n-1,14,10])
137 #OBJE -----------------------------------------------------------
138     mesh = bpy.data.meshes.new(name='Sove')
139     bpy.data.objects.new('Sove', mesh)
140     mesh.from_pydata(vr,[],fc)
141  #   for i in SM:
142  #       mesh.faces[i-1].shade_smooth()
143     mesh.materials.append(MSVE())
144     mesh.update(calc_edges=True)
145     object_data_add(context, mesh, operator=None)
146     if bpy.context.mode != 'EDIT_MESH':
147         bpy.ops.object.editmode_toggle()
148         bpy.ops.object.editmode_toggle()
149 #----------------------------------------------------------------
150 class OBJECT_OT_add_object(bpy.types.Operator):
151     bl_idname = "mesh.add_say3d_sove"
152     bl_label = "Sove"
153     bl_description = "Sove Frame"
154     bl_options = {'REGISTER', 'UNDO'}
155
156     prs = EnumProperty(items = (("1","PENCERE 200",""),
157                                 ("2","PENCERE 180",""),
158                                 ("3","PENCERE 160","")),
159                                 name="",description="")
160     son=prs
161     gen=IntProperty(name='Width', min=1,max= 400,default=200,description='Width')
162     knr=IntProperty(name='Thickness', min=1,max= 100,default= 15,description='Thickness')
163     yuk=IntProperty(name='Elevation',min=1,max=3000,default=590,description='Elevation')
164     alt=IntProperty(name='Old Spacing',      min=1,max= 300,default= 44,description='Old Spacing')
165     ust=IntProperty(name='Top margin',      min=1,max= 300,default= 33,description='Top margin')
166     sdr=IntProperty(name='Jamb', min=1,max= 100,default= 15,description='jamb Depth')
167     pdr=IntProperty(name='Wall Thickness',    min=0,max= 100,default= 20,description='Wall Thickness')
168     dh =IntProperty(name='',         min=1,max= 200,default= 30,description='Height')
169     dr=BoolProperty(name='Rounded', default=True,  description='Rounded')
170
171     fg =IntProperty(name='Gap',min=0,max=10,default=1,description='Gap')
172     fh =IntProperty(name='',    min=1,max=10,default=3,description='Height')
173     fd =IntProperty(name='',    min=1,max=10,default=2,description='Depth')
174
175     f0 =IntProperty(name='Interval',min=1,max=3000,default=90,description='Interval')
176     f1 =IntProperty(name='Interval',min=1,max=3000,default=30,description='Interval')
177     f2 =IntProperty(name='Interval',min=1,max=3000,default=30,description='Interval')
178     f3 =IntProperty(name='Interval',min=1,max=3000,default=30,description='Interval')
179     f4 =IntProperty(name='Interval',min=1,max=3000,default=30,description='Interval')
180     f5 =IntProperty(name='Interval',min=1,max=3000,default=30,description='Interval')
181     f6 =IntProperty(name='Interval',min=1,max=3000,default=30,description='Interval')
182     f7 =IntProperty(name='Interval',min=1,max=3000,default=30,description='Interval')
183     f8 =IntProperty(name='Interval',min=1,max=3000,default=30,description='Interval')
184     f9 =IntProperty(name='Interval',min=1,max=3000,default=30,description='Interval')
185     #--------------------------------------------------------------
186     def draw(self, context):
187         layout = self.layout
188         layout.prop(self,'prs')
189         box=layout.box()
190         box.prop(self,'gen');box.prop(self,'yuk')
191         box.prop(self,'knr')
192         row=box.row();row.prop(self,'alt');row.prop(self,'ust')
193         row=box.row();row.prop(self,'sdr');row.prop(self,'pdr')
194         row=box.row();row.prop(self, 'dr');row.prop(self, 'dh')
195         box=layout.box()
196         box.prop(self,'fg')
197         row=box.row();row.prop(self, 'fh');row.prop(self, 'fd')
198         for i in range(self.fg):
199             box.prop(self,'f'+str(i))
200             
201     def execute(self, context):
202         if self.son!=self.prs:
203             if self.prs=='1':Prs(self,200,15,590,44,33,15,20,30,True,1,2,3,90,30,30,30,30,30,30,30,30,30)
204             if self.prs=='2':Prs(self,180,15,590,44,33,15,20,30,True,1,2,3,90,30,30,30,30,30,30,30,30,30)
205             if self.prs=='3':Prs(self,160,15,590,44,33,15,20,30,True,1,2,3,90,30,30,30,30,30,30,30,30,30)
206             self.son=self.prs
207         add_object(self, context)
208         return {'FINISHED'}
209 # Reg--------------------------------
210 def add_object_button(self, context):
211     self.layout.operator(
212         OBJECT_OT_add_object.bl_idname,
213         text="Sove",
214         icon="MOD_MESHDEFORM")
215 def register():
216     bpy.utils.register_class(OBJECT_OT_add_object)
217     bpy.types.INFO_MT_mesh_add.append(add_object_button)
218 def unregister():
219     bpy.utils.unregister_class(OBJECT_OT_add_object)
220     bpy.types.INFO_MT_mesh_add.remove(add_object_button)
221 if __name__ == '__main__':
222     register()