Fix [#22120] Physics modifiers can't be removed
[blender-staging.git] / release / scripts / ui / properties_physics_smoke.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21
22 narrowui = 180
23
24
25 from properties_physics_common import point_cache_ui
26 from properties_physics_common import effector_weights_ui
27
28
29 class PhysicButtonsPanel(bpy.types.Panel):
30     bl_space_type = 'PROPERTIES'
31     bl_region_type = 'WINDOW'
32     bl_context = "physics"
33
34     def poll(self, context):
35         ob = context.object
36         rd = context.scene.render
37         return (ob and ob.type == 'MESH') and (not rd.use_game_engine)
38
39
40 class PHYSICS_PT_smoke(PhysicButtonsPanel):
41     bl_label = "Smoke"
42
43     def draw(self, context):
44         layout = self.layout
45
46         md = context.smoke
47         ob = context.object
48         wide_ui = context.region.width > narrowui
49
50         split = layout.split()
51
52         if md:
53             # remove modifier + settings
54             split.set_context_pointer("modifier", md)
55             split.operator("object.modifier_remove", text="Remove")
56
57             row = split.row(align=True)
58             row.prop(md, "render", text="")
59             row.prop(md, "realtime", text="")
60
61         else:
62             # add modifier
63             split.operator("object.modifier_add", text="Add").type = 'SMOKE'
64             if wide_ui:
65                 split.label()
66
67         if md:
68             if wide_ui:
69                 layout.prop(md, "smoke_type", expand=True)
70             else:
71                 layout.prop(md, "smoke_type", text="")
72
73             if md.smoke_type == 'TYPE_DOMAIN':
74
75                 domain = md.domain_settings
76
77                 split = layout.split()
78
79                 col = split.column()
80                 col.label(text="Resolution:")
81                 col.prop(domain, "maxres", text="Divisions")
82                 col.label(text="Particle:")
83                 col.prop(domain, "initial_velocity", text="Initial Velocity")
84
85                 if wide_ui:
86                     col = split.column()
87                 col.label(text="Behavior:")
88                 col.prop(domain, "alpha")
89                 col.prop(domain, "beta")
90                 col.prop(domain, "dissolve_smoke", text="Dissolve")
91                 sub = col.column()
92                 sub.active = domain.dissolve_smoke
93                 sub.prop(domain, "dissolve_speed", text="Time")
94                 sub.prop(domain, "dissolve_smoke_log", text="Slow")
95
96             elif md.smoke_type == 'TYPE_FLOW':
97
98                 flow = md.flow_settings
99
100                 split = layout.split()
101
102                 col = split.column()
103                 col.prop(flow, "outflow")
104                 col.label(text="Particle System:")
105                 col.prop_object(flow, "psys", ob, "particle_systems", text="")
106
107                 if md.flow_settings.outflow:
108                     if wide_ui:
109                         col = split.column()
110                 else:
111                     if wide_ui:
112                         col = split.column()
113                     col.label(text="Behavior:")
114                     col.prop(flow, "temperature")
115                     col.prop(flow, "density")
116
117             #elif md.smoke_type == 'TYPE_COLL':
118             #   layout.separator()
119
120
121 class PHYSICS_PT_smoke_groups(PhysicButtonsPanel):
122     bl_label = "Smoke Groups"
123     bl_default_closed = True
124
125     def poll(self, context):
126         md = context.smoke
127         return md and (md.smoke_type == 'TYPE_DOMAIN')
128
129     def draw(self, context):
130         layout = self.layout
131
132         group = context.smoke.domain_settings
133         wide_ui = context.region.width > narrowui
134
135         split = layout.split()
136
137         col = split.column()
138         col.label(text="Flow Group:")
139         col.prop(group, "fluid_group", text="")
140
141         #col.label(text="Effector Group:")
142         #col.prop(group, "eff_group", text="")
143
144         if wide_ui:
145             col = split.column()
146         col.label(text="Collision Group:")
147         col.prop(group, "coll_group", text="")
148
149
150 class PHYSICS_PT_smoke_cache(PhysicButtonsPanel):
151     bl_label = "Smoke Cache"
152     bl_default_closed = True
153
154     def poll(self, context):
155         md = context.smoke
156         return md and (md.smoke_type == 'TYPE_DOMAIN')
157
158     def draw(self, context):
159         layout = self.layout
160
161         domain = context.smoke.domain_settings
162
163         layout.label(text="Compression:")
164         layout.prop(domain, "smoke_cache_comp", expand=True)
165
166         md = context.smoke.domain_settings
167         cache = md.point_cache_low
168
169         point_cache_ui(self, context, cache, (cache.baked is False), 0, 1)
170
171
172 class PHYSICS_PT_smoke_highres(PhysicButtonsPanel):
173     bl_label = "Smoke High Resolution"
174     bl_default_closed = True
175
176     def poll(self, context):
177         md = context.smoke
178         return md and (md.smoke_type == 'TYPE_DOMAIN')
179
180     def draw_header(self, context):
181         high = context.smoke.domain_settings
182
183         self.layout.prop(high, "highres", text="")
184
185     def draw(self, context):
186         layout = self.layout
187
188         md = context.smoke.domain_settings
189         wide_ui = context.region.width > narrowui
190
191         split = layout.split()
192
193         col = split.column()
194         col.label(text="Resolution:")
195         col.prop(md, "amplify", text="Divisions")
196         col.prop(md, "viewhighres")
197
198         if wide_ui:
199             col = split.column()
200         col.label(text="Noise Method:")
201         col.row().prop(md, "noise_type", text="")
202         col.prop(md, "strength")
203
204
205 class PHYSICS_PT_smoke_cache_highres(PhysicButtonsPanel):
206     bl_label = "Smoke High Resolution Cache"
207     bl_default_closed = True
208
209     def poll(self, context):
210         md = context.smoke
211         return md and (md.smoke_type == 'TYPE_DOMAIN') and md.domain_settings.highres
212
213     def draw(self, context):
214         layout = self.layout
215
216         domain = context.smoke.domain_settings
217
218         layout.label(text="Compression:")
219         layout.prop(domain, "smoke_cache_high_comp", expand=True)
220
221
222         md = context.smoke.domain_settings
223         cache = md.point_cache_high
224
225         point_cache_ui(self, context, cache, (cache.baked is False), 0, 1)
226
227
228 class PHYSICS_PT_smoke_field_weights(PhysicButtonsPanel):
229     bl_label = "Smoke Field Weights"
230     bl_default_closed = True
231
232     def poll(self, context):
233         smoke = context.smoke
234         return (smoke and smoke.smoke_type == 'TYPE_DOMAIN')
235
236     def draw(self, context):
237         domain = context.smoke.domain_settings
238         effector_weights_ui(self, context, domain.effector_weights)
239
240
241 classes = [
242     PHYSICS_PT_smoke,
243     PHYSICS_PT_smoke_field_weights,
244     PHYSICS_PT_smoke_cache,
245     PHYSICS_PT_smoke_highres,
246     PHYSICS_PT_smoke_groups,
247     PHYSICS_PT_smoke_cache_highres]
248
249
250 def register():
251     register = bpy.types.register
252     for cls in classes:
253         register(cls)
254
255
256 def unregister():
257     unregister = bpy.types.unregister
258     for cls in classes:
259         unregister(cls)
260
261 if __name__ == "__main__":
262     register()