bugfix [#23182] Using self.report() inside poll() gives crash
[blender-staging.git] / release / scripts / ui / properties_physics_softbody.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 = bpy.context.user_preferences.view.properties_width_check
23
24
25 from properties_physics_common import point_cache_ui
26 from properties_physics_common import effector_weights_ui
27
28
29 def softbody_panel_enabled(md):
30     return (md.point_cache.baked is False)
31
32
33 class PhysicButtonsPanel():
34     bl_space_type = 'PROPERTIES'
35     bl_region_type = 'WINDOW'
36     bl_context = "physics"
37
38     @staticmethod
39     def poll(context):
40         ob = context.object
41         rd = context.scene.render
42 #        return (ob and ob.type == 'MESH') and (not rd.use_game_engine)
43 # i really hate touching things i do not understand completely .. but i think this should read (bjornmose)
44         return (ob and (ob.type == 'MESH' or ob.type == 'LATTICE'or ob.type == 'CURVE')) and (not rd.use_game_engine)
45
46
47 class PHYSICS_PT_softbody(PhysicButtonsPanel, bpy.types.Panel):
48     bl_label = "Soft Body"
49
50     def draw(self, context):
51         layout = self.layout
52
53         md = context.soft_body
54         ob = context.object
55         wide_ui = context.region.width > narrowui
56
57         split = layout.split()
58
59         if md:
60             # remove modifier + settings
61             split.set_context_pointer("modifier", md)
62             split.operator("object.modifier_remove", text="Remove")
63
64             row = split.row(align=True)
65             row.prop(md, "render", text="")
66             row.prop(md, "realtime", text="")
67         else:
68             # add modifier
69             split.operator("object.modifier_add", text="Add").type = 'SOFT_BODY'
70             if wide_ui:
71                 split.column()
72
73         if md:
74             softbody = md.settings
75
76             # General
77             split = layout.split()
78             split.enabled = softbody_panel_enabled(md)
79
80             col = split.column()
81             col.label(text="Object:")
82             col.prop(softbody, "friction")
83             col.prop(softbody, "mass")
84             col.prop_object(softbody, "mass_vertex_group", ob, "vertex_groups", text="Mass:")
85
86             if wide_ui:
87                 col = split.column()
88             col.label(text="Simulation:")
89             col.prop(softbody, "speed")
90
91
92 class PHYSICS_PT_softbody_cache(PhysicButtonsPanel, bpy.types.Panel):
93     bl_label = "Soft Body Cache"
94     bl_default_closed = True
95
96     @staticmethod
97     def poll(context):
98         return context.soft_body
99
100     def draw(self, context):
101         md = context.soft_body
102         point_cache_ui(self, context, md.point_cache, softbody_panel_enabled(md), 'SOFTBODY')
103
104
105 class PHYSICS_PT_softbody_goal(PhysicButtonsPanel, bpy.types.Panel):
106     bl_label = "Soft Body Goal"
107     bl_default_closed = True
108
109     @staticmethod
110     def poll(context):
111         return context.soft_body
112
113     def draw_header(self, context):
114         softbody = context.soft_body.settings
115
116         self.layout.active = softbody_panel_enabled(context.soft_body)
117         self.layout.prop(softbody, "use_goal", text="")
118
119     def draw(self, context):
120         layout = self.layout
121
122         md = context.soft_body
123         softbody = md.settings
124         ob = context.object
125         wide_ui = context.region.width > narrowui
126
127         layout.active = softbody.use_goal and softbody_panel_enabled(md)
128
129         split = layout.split()
130
131         # Goal
132         split = layout.split()
133
134         col = split.column()
135         col.label(text="Goal Strengths:")
136         col.prop(softbody, "goal_default", text="Default")
137         sub = col.column(align=True)
138         sub.prop(softbody, "goal_min", text="Minimum")
139         sub.prop(softbody, "goal_max", text="Maximum")
140
141         if wide_ui:
142             col = split.column()
143         col.label(text="Goal Settings:")
144         col.prop(softbody, "goal_spring", text="Stiffness")
145         col.prop(softbody, "goal_friction", text="Damping")
146
147         layout.prop_object(softbody, "goal_vertex_group", ob, "vertex_groups", text="Vertex Group")
148
149
150 class PHYSICS_PT_softbody_edge(PhysicButtonsPanel, bpy.types.Panel):
151     bl_label = "Soft Body Edges"
152     bl_default_closed = True
153
154     @staticmethod
155     def poll(context):
156         return context.soft_body
157
158     def draw_header(self, context):
159         softbody = context.soft_body.settings
160
161         self.layout.active = softbody_panel_enabled(context.soft_body)
162         self.layout.prop(softbody, "use_edges", text="")
163
164     def draw(self, context):
165         layout = self.layout
166
167         md = context.soft_body
168         softbody = md.settings
169         ob = context.object
170         wide_ui = context.region.width > narrowui
171
172         layout.active = softbody.use_edges and softbody_panel_enabled(md)
173
174         split = layout.split()
175
176         col = split.column()
177         col.label(text="Springs:")
178         col.prop(softbody, "pull")
179         col.prop(softbody, "push")
180         col.prop(softbody, "damp")
181         col.prop(softbody, "plastic")
182         col.prop(softbody, "bending")
183         col.prop(softbody, "spring_length", text="Length")
184         col.prop_object(softbody, "spring_vertex_group", ob, "vertex_groups", text="Springs:")
185
186         if wide_ui:
187             col = split.column()
188         col.prop(softbody, "stiff_quads")
189         sub = col.column()
190         sub.active = softbody.stiff_quads
191         sub.prop(softbody, "shear")
192
193         col.label(text="Aerodynamics:")
194         col.row().prop(softbody, "aerodynamics_type", expand=True)
195         col.prop(softbody, "aero", text="Factor")
196
197         #sub = col.column()
198         #sub.enabled = softbody.aero > 0
199
200
201         col.label(text="Collision:")
202         col.prop(softbody, "edge_collision", text="Edge")
203         col.prop(softbody, "face_collision", text="Face")
204
205
206 class PHYSICS_PT_softbody_collision(PhysicButtonsPanel, bpy.types.Panel):
207     bl_label = "Soft Body Self Collision"
208     bl_default_closed = True
209
210     @staticmethod
211     def poll(context):
212         return context.soft_body
213
214     def draw_header(self, context):
215         softbody = context.soft_body.settings
216
217         self.layout.active = softbody_panel_enabled(context.soft_body)
218         self.layout.prop(softbody, "self_collision", text="")
219
220     def draw(self, context):
221         layout = self.layout
222
223         md = context.soft_body
224         softbody = md.settings
225         wide_ui = context.region.width > narrowui
226
227         layout.active = softbody.self_collision and softbody_panel_enabled(md)
228
229         layout.label(text="Collision Ball Size Calculation:")
230         if wide_ui:
231             layout.prop(softbody, "collision_type", expand=True)
232         else:
233             layout.prop(softbody, "collision_type", text="")
234
235         col = layout.column(align=True)
236         col.label(text="Ball:")
237         col.prop(softbody, "ball_size", text="Size")
238         col.prop(softbody, "ball_stiff", text="Stiffness")
239         col.prop(softbody, "ball_damp", text="Dampening")
240
241
242 class PHYSICS_PT_softbody_solver(PhysicButtonsPanel, bpy.types.Panel):
243     bl_label = "Soft Body Solver"
244     bl_default_closed = True
245
246     @staticmethod
247     def poll(context):
248         return context.soft_body
249
250     def draw(self, context):
251         layout = self.layout
252
253         md = context.soft_body
254         softbody = md.settings
255         wide_ui = context.region.width > narrowui
256
257         layout.active = softbody_panel_enabled(md)
258
259         # Solver
260         split = layout.split()
261
262         col = split.column(align=True)
263         col.label(text="Step Size:")
264         col.prop(softbody, "minstep")
265         col.prop(softbody, "maxstep")
266         col.prop(softbody, "auto_step", text="Auto-Step")
267
268         if wide_ui:
269             col = split.column()
270         col.prop(softbody, "error_limit")
271         col.label(text="Helpers:")
272         col.prop(softbody, "choke")
273         col.prop(softbody, "fuzzy")
274
275         layout.label(text="Diagnostics:")
276         layout.prop(softbody, "diagnose")
277         layout.prop(softbody, "estimate_matrix")
278
279
280 class PHYSICS_PT_softbody_field_weights(PhysicButtonsPanel, bpy.types.Panel):
281     bl_label = "Soft Body Field Weights"
282     bl_default_closed = True
283
284     @staticmethod
285     def poll(context):
286         return (context.soft_body)
287
288     def draw(self, context):
289         md = context.soft_body
290         softbody = md.settings
291
292         effector_weights_ui(self, context, softbody.effector_weights)
293
294
295 def register():
296     pass
297
298
299 def unregister():
300     pass
301
302 if __name__ == "__main__":
303     register()