73f97dec7502b45374407bd6c0aa82b9667c9c4e
[blender.git] / release / ui / space_view3d_toolbar.py
1
2 import bpy
3
4 class View3DPanel(bpy.types.Panel):
5         __space_type__ = 'VIEW_3D'
6         __region_type__ = 'TOOLS'
7
8 # ********** default tools for objectmode ****************
9
10 class VIEW3D_PT_tools_objectmode(View3DPanel):
11         __context__ = "objectmode"
12         __label__ = "Object Tools"
13
14         def draw(self, context):
15                 layout = self.layout
16                 
17                 layout.itemL(text="Transform:")
18                 
19                 col = layout.column(align=True)
20                 col.itemO("tfm.translate")
21                 col.itemO("tfm.rotate")
22                 col.itemO("tfm.resize", text="Scale")
23                 
24                 layout.itemL(text="Object:")
25                 
26                 col = layout.column(align=True)
27                 col.itemO("object.duplicate")
28                 col.itemO("object.delete")
29                 
30                 active_object= context.active_object
31                 if active_object and active_object.type == 'MESH':
32                         layout.itemL(text="Shading:")
33                 
34                         col = layout.column(align=True)
35                         col.itemO("object.shade_smooth", text="Smooth")
36                         col.itemO("object.shade_flat", text="Flat")
37                 
38                 layout.itemL(text="Keyframes:")
39                 
40                 col = layout.column(align=True)
41                 col.itemO("anim.insert_keyframe_menu", text="Insert")
42                 col.itemO("anim.delete_keyframe_v3d", text="Remove")
43
44 # ********** default tools for editmode_mesh ****************
45
46 class VIEW3D_PT_tools_meshedit(View3DPanel):
47         __context__ = "mesh_edit"
48         __label__ = "Mesh Tools"
49
50         def draw(self, context):
51                 layout = self.layout
52                 
53                 layout.itemL(text="Transform:")
54                 
55                 col = layout.column(align=True)
56                 col.itemO("tfm.translate")
57                 col.itemO("tfm.rotate")
58                 col.itemO("tfm.resize", text="Scale")
59                 
60                 layout.itemL(text="Mesh:")
61                 
62                 col = layout.column(align=True)
63                 col.itemO("mesh.duplicate")
64                 col.itemO("mesh.delete")
65                 
66                 layout.itemL(text="Modeling:")
67                 
68                 col = layout.column(align=True)
69                 col.itemO("mesh.extrude")
70                 col.itemO("mesh.subdivide")
71                 col.itemO("mesh.spin")
72                 col.itemO("mesh.screw")
73                 
74                 layout.itemL(text="Shading:")
75                 
76                 col = layout.column(align=True)
77                 col.itemO("mesh.faces_shade_smooth", text="Smooth")
78                 col.itemO("mesh.faces_shade_flat", text="Flat")
79                 
80                 layout.itemL(text="UV Mapping:")
81                 
82                 col = layout.column(align=True)
83                 col.itemO("uv.mapping_menu", text="Unwrap")
84                 col.itemO("mesh.uvs_rotate")
85                 col.itemO("mesh.uvs_mirror")
86
87 # ********** default tools for editmode_curve ****************
88
89 class VIEW3D_PT_tools_curveedit(View3DPanel):
90         __context__ = "curve_edit"
91         __label__ = "Curve Tools"
92
93         def draw(self, context):
94                 layout = self.layout
95                 
96                 layout.itemL(text="Transform:")
97                 
98                 col = layout.column(align=True)
99                 col.itemO("tfm.translate")
100                 col.itemO("tfm.rotate")
101                 col.itemO("tfm.resize", text="Scale")
102                 
103                 layout.itemL(text="Curve:")
104
105                 col = layout.column(align=True)
106                 col.itemO("curve.duplicate")
107                 col.itemO("curve.delete")
108                 col.itemO("curve.cyclic_toggle")
109                 col.itemO("curve.switch_direction")
110                 col.itemO("curve.spline_type_set")
111                 
112                 layout.itemL(text="Modeling:")
113
114                 col = layout.column(align=True)
115                 col.itemO("curve.extrude")
116                 col.itemO("curve.subdivide")
117
118 # ********** default tools for editmode_surface ****************
119
120 class VIEW3D_PT_tools_surfaceedit(View3DPanel):
121         __context__ = "surface_edit"
122         __label__ = "Surface Tools"
123
124         def draw(self, context):
125                 layout = self.layout
126                 
127                 layout.itemL(text="Transform:")
128
129                 col = layout.column(align=True)
130                 col.itemO("tfm.translate")
131                 col.itemO("tfm.rotate")
132                 col.itemO("tfm.resize", text="Scale")
133                 
134                 layout.itemL(text="Curve:")
135
136                 col = layout.column(align=True)
137                 col.itemO("curve.duplicate")
138                 col.itemO("curve.delete")
139                 col.itemO("curve.cyclic_toggle")
140                 col.itemO("curve.switch_direction")
141                 
142                 layout.itemL(text="Modeling:")
143
144                 col = layout.column(align=True)
145                 col.itemO("curve.extrude")
146                 col.itemO("curve.subdivide")
147
148 # ********** default tools for editmode_text ****************
149
150 class VIEW3D_PT_tools_textedit(View3DPanel):
151         __context__ = "text_edit"
152         __label__ = "Text Tools"
153
154         def draw(self, context):
155                 layout = self.layout
156
157                 col = layout.column(align=True)
158                 col.itemO("font.text_copy", text="Copy")
159                 col.itemO("font.text_paste", text="Paste")
160                 
161                 col = layout.column()
162                 col.itemO("font.case_set")
163                 col.itemO("font.style_toggle")
164
165 # ********** default tools for editmode_armature ****************
166
167 class VIEW3D_PT_tools_armatureedit(View3DPanel):
168         __context__ = "armature_edit"
169         __label__ = "Armature Tools"
170
171         def draw(self, context):
172                 layout = self.layout
173                 
174                 layout.itemL(text="Transform:")
175                 
176                 col = layout.column(align=True)
177                 col.itemO("tfm.translate")
178                 col.itemO("tfm.rotate")
179                 col.itemO("tfm.resize", text="Scale")
180                 
181                 layout.itemL(text="Bones:")
182
183                 col = layout.column(align=True)
184                 col.itemO("armature.bone_primitive_add", text="Add")
185                 col.itemO("armature.duplicate", text="Duplicate")
186                 col.itemO("armature.delete", text="Delete")
187                 
188                 layout.itemL(text="Modeling:")
189                 layout.itemO("armature.extrude")
190
191 # ********** default tools for editmode_mball ****************
192
193 class VIEW3D_PT_tools_mballedit(View3DPanel):
194         __context__ = "mball_edit"
195         __label__ = "Meta Tools"
196
197         def draw(self, context):
198                 layout = self.layout
199                 
200                 layout.itemL(text="Transform:")
201                 
202                 col = layout.column(align=True)
203                 col.itemO("tfm.translate")
204                 col.itemO("tfm.rotate")
205                 col.itemO("tfm.resize", text="Scale")
206
207 # ********** default tools for editmode_lattice ****************
208
209 class VIEW3D_PT_tools_latticeedit(View3DPanel):
210         __context__ = "lattice_edit"
211         __label__ = "Lattice Tools"
212
213         def draw(self, context):
214                 layout = self.layout
215                 
216                 layout.itemL(text="Transform:")
217
218                 col = layout.column(align=True)
219                 col.itemO("tfm.translate")
220                 col.itemO("tfm.rotate")
221                 col.itemO("tfm.resize", text="Scale")
222
223 # ********** default tools for posemode ****************
224
225 class VIEW3D_PT_tools_posemode(View3DPanel):
226         __context__ = "posemode"
227         __label__ = "Pose Tools"
228
229         def draw(self, context):
230                 layout = self.layout
231                 
232                 layout.itemL(text="Transform:")
233
234                 col = layout.column(align=True)
235                 col.itemO("tfm.translate")
236                 col.itemO("tfm.rotate")
237                 col.itemO("tfm.resize", text="Scale")
238                 
239                 layout.itemL(text="Bones:")
240
241                 col = layout.column(align=True)
242                 col.itemO("pose.hide", text="Hide")
243                 col.itemO("pose.reveal", text="Reveal")
244                 
245                 layout.itemL(text="Keyframes:")
246                 
247                 col = layout.column(align=True)
248                 col.itemO("anim.insert_keyframe_menu", text="Insert")
249                 col.itemO("anim.delete_keyframe_v3d", text="Remove")
250                 
251                 layout.itemL(text="Pose:")
252                 
253                 col = layout.column(align=True)
254                 col.itemO("pose.copy", text="Copy")
255                 col.itemO("pose.paste", text="Paste")
256                 
257                 layout.itemL(text="Library:")
258                 
259                 col = layout.column(align=True)
260                 col.itemO("poselib.pose_add", text="Add")
261                 col.itemO("poselib.pose_remove", text="Remove")
262
263 # ********** default tools for paint modes ****************
264
265 class PaintPanel(bpy.types.Panel):
266         __space_type__ = 'VIEW_3D'
267         __region_type__ = 'TOOLS'
268
269         def paint_settings(self, context):
270                 ts = context.tool_settings
271
272                 if context.sculpt_object:
273                         return ts.sculpt
274                 elif context.vertex_paint_object:
275                         return ts.vertex_paint
276                 elif context.weight_paint_object:
277                         return ts.weight_paint
278                 elif context.texture_paint_object:
279                         return ts.image_paint
280                 elif context.particle_edit_object:
281                         return ts.particle_edit
282
283                 return False
284
285 class VIEW3D_PT_tools_brush(PaintPanel):
286         __label__ = "Brush"
287
288         def poll(self, context):
289                 return self.paint_settings(context)
290
291         def draw(self, context):
292                 layout = self.layout
293                 
294                 settings = self.paint_settings(context)
295                 brush = settings.brush
296
297                 if not context.particle_edit_object:
298                         col = layout.split().column()
299                         row = col.row()
300                         row.template_list(settings, "brushes", settings, "active_brush_index", rows=2)
301                                 
302                         col.template_ID(settings, "brush", new="brush.add")
303                 
304                 # Particle Mode #
305
306                 # XXX This needs a check if psys is editable.
307                 if context.particle_edit_object:
308                         # XXX Select Particle System
309                         layout.column().itemR(settings, "tool", expand=True)
310                         
311                         if settings.tool != 'NONE':
312                                 col = layout.column()
313                                 col.itemR(brush, "size", slider=True)
314                                 col.itemR(brush, "strength", slider=True)
315                                 
316                         if settings.tool == 'ADD':
317                                 
318                                 col = layout.column()
319                                 col.itemR(settings, "add_interpolate")
320                                 sub = col.column(align=True)
321                                 sub.active = settings.add_interpolate
322                                 sub.itemR(brush, "steps", slider=True)
323                                 sub.itemR(settings, "add_keys", slider=True)
324                         elif settings.tool == 'LENGTH':
325                                 layout.itemR(brush, "length_mode", expand=True)
326                         elif settings.tool == 'PUFF':
327                                 layout.itemR(brush, "puff_mode", expand=True)
328
329                 # Sculpt Mode #
330
331                 elif context.sculpt_object and settings.brush:
332                         col = layout.column()
333                         col.itemS()
334                                 
335                         row = col.row(align=True)
336                         row.itemR(brush, "size", slider=True)
337                         row.itemR(brush, "size_pressure", toggle=True, text="")
338                         
339                         if brush.sculpt_tool != 'GRAB':
340                                 row = col.row(align=True)
341                                 row.itemR(brush, "strength", slider=True)
342                                 row.itemR(brush, "strength_pressure", text="")
343                         
344                                 col = layout.column()
345
346                                 if brush.sculpt_tool in ('DRAW', 'PINCH', 'INFLATE', 'LAYER', 'CLAY'):
347                                         col.itemR(brush, "flip_direction")
348
349                                 if brush.sculpt_tool == 'LAYER':
350                                         col.itemR(brush, "persistent")
351                                         col.itemO("sculpt.set_persistent_base")
352
353                         col.itemR(brush, "sculpt_tool")
354                                 
355                 # Texture Paint Mode #
356                 
357                 elif context.texture_paint_object:
358                         col = layout.column(align=True)
359                         col.item_enumR(settings, "tool", 'DRAW')
360                         col.item_enumR(settings, "tool", 'SOFTEN')
361                         col.item_enumR(settings, "tool", 'CLONE')
362                         col.item_enumR(settings, "tool", 'SMEAR')
363                                 
364                         col = layout.column()
365                         col.itemR(brush, "color", text="")
366
367                         row = col.row(align=True)
368                         row.itemR(brush, "size", slider=True)
369                         row.itemR(brush, "size_pressure", toggle=True, text="")
370                         
371                         row = col.row(align=True)
372                         row.itemR(brush, "strength", slider=True)
373                         row.itemR(brush, "strength_pressure", toggle=True, text="")
374                         
375                         col.itemR(brush, "blend")
376                 
377                 # Weight Paint Mode #
378         
379                 elif context.weight_paint_object:
380                         layout.itemR(context.tool_settings, "vertex_group_weight", text="Weight", slider=True)
381                         
382                         col = layout.column()
383                         row = col.row(align=True)
384                         row.itemR(brush, "size", slider=True)
385                         row.itemR(brush, "size_pressure", toggle=True, text="")
386                         
387                         row = col.row(align=True)
388                         row.itemR(brush, "strength", slider=True)
389                         row.itemR(brush, "strength_pressure", toggle=True, text="")
390                 
391                 # Vertex Paint Mode #
392                 
393                 elif context.vertex_paint_object:
394                         col = layout.column()
395                         col.itemR(brush, "color", text="")
396                         
397                         row = col.row(align=True)
398                         row.itemR(brush, "size", slider=True)
399                         row.itemR(brush, "size_pressure", toggle=True, text="")
400                         
401                         row = col.row(align=True)
402                         row.itemR(brush, "strength", slider=True)
403                         row.itemR(brush, "strength_pressure", toggle=True, text="")
404
405 class VIEW3D_PT_tools_brush_stroke(PaintPanel):
406         __label__ = "Stroke"
407         __default_closed__ = True
408
409         def poll(self, context):
410                 settings = self.paint_settings(context)
411                 return (settings and settings.brush and (context.sculpt_object or
412                                                          context.vertex_paint_object or
413                                                          context.weight_paint_object or
414                                                          context.texture_paint_object))
415
416         def draw(self, context):
417                 layout = self.layout
418                 
419                 settings = self.paint_settings(context)
420                 brush = settings.brush
421                 texture_paint = context.texture_paint_object
422
423                 if context.sculpt_object:
424                         if brush.sculpt_tool != 'LAYER':
425                                 layout.itemR(brush, "anchored")
426                         layout.itemR(brush, "rake")
427
428                 layout.itemR(brush, "airbrush")
429                 col = layout.column()
430                 col.active = brush.airbrush
431                 col.itemR(brush, "rate", slider=True)
432
433                 if not texture_paint:
434                         layout.itemR(brush, "smooth_stroke")
435                         col = layout.column()
436                         col.active = brush.smooth_stroke
437                         col.itemR(brush, "smooth_stroke_radius", text="Radius", slider=True)
438                         col.itemR(brush, "smooth_stroke_factor", text="Factor", slider=True)
439
440                 layout.itemR(brush, "space")
441                 row = layout.row(align=True)
442                 row.active = brush.space
443                 row.itemR(brush, "spacing", text="Distance", slider=True)
444                 if texture_paint:
445                         row.itemR(brush, "spacing_pressure", toggle=True, text="")      
446
447 class VIEW3D_PT_tools_brush_curve(PaintPanel):
448         __label__ = "Curve"
449         __default_closed__ = True
450
451         def poll(self, context):
452                 settings = self.paint_settings(context)
453                 return (settings and settings.brush and settings.brush.curve)
454
455         def draw(self, context):
456                 layout = self.layout
457                 
458                 settings = self.paint_settings(context)
459                 brush = settings.brush
460
461                 layout.template_curve_mapping(brush.curve)
462                 layout.item_menu_enumO("brush.curve_preset", property="shape")
463                 
464 class VIEW3D_PT_sculpt_options(PaintPanel):
465         __label__ = "Options"
466
467         def poll(self, context):
468                 return context.sculpt_object
469
470         def draw(self, context):
471                 layout = self.layout
472                 
473                 sculpt = context.tool_settings.sculpt
474
475                 col = layout.column()
476                 col.itemR(sculpt, "partial_redraw", text="Partial Refresh")
477                 col.itemR(sculpt, "show_brush")
478
479                 split = self.layout.split()
480                 
481                 col = split.column()
482                 col.itemL(text="Symmetry:")
483                 col.itemR(sculpt, "symmetry_x", text="X")
484                 col.itemR(sculpt, "symmetry_y", text="Y")
485                 col.itemR(sculpt, "symmetry_z", text="Z")
486                 
487                 col = split.column()
488                 col.itemL(text="Lock:")
489                 col.itemR(sculpt, "lock_x", text="X")
490                 col.itemR(sculpt, "lock_y", text="Y")
491                 col.itemR(sculpt, "lock_z", text="Z")
492
493 # ********** default tools for weightpaint ****************
494
495 class VIEW3D_PT_tools_weightpaint(View3DPanel):
496         __context__ = "weightpaint"
497         __label__ = "Options"
498
499         def draw(self, context):
500                 layout = self.layout
501                 
502                 wpaint = context.tool_settings.weight_paint
503
504                 col = layout.column()
505                 col.itemL(text="Blend:")
506                 col.itemR(wpaint, "mode", text="")
507                 col.itemR(wpaint, "all_faces")
508                 col.itemR(wpaint, "normals")
509                 col.itemR(wpaint, "spray")
510                 col.itemR(wpaint, "vertex_dist", text="Distance")
511
512 # Commented out because the Apply button isn't an operator yet, making these settings useless
513 #               col.itemL(text="Gamma:")
514 #               col.itemR(wpaint, "gamma", text="")
515 #               col.itemL(text="Multiply:")
516 #               col.itemR(wpaint, "mul", text="")
517
518 # Also missing now:
519 # Soft, Vgroup, X-Mirror and "Clear" Operator.
520
521 # ********** default tools for vertexpaint ****************
522
523 class VIEW3D_PT_tools_vertexpaint(View3DPanel):
524         __context__ = "vertexpaint"
525         __label__ = "Options"
526
527         def draw(self, context):
528                 layout = self.layout
529                 
530                 vpaint = context.tool_settings.vertex_paint
531
532                 col = layout.column()
533                 col.itemL(text="Blend:")
534                 col.itemR(vpaint, "mode", text="")
535                 col.itemR(vpaint, "all_faces")
536                 col.itemR(vpaint, "normals")
537                 col.itemR(vpaint, "spray")
538                 col.itemR(vpaint, "vertex_dist", text="Distance")
539 # Commented out because the Apply button isn't an operator yet, making these settings useless
540 #               col.itemL(text="Gamma:")
541 #               col.itemR(vpaint, "gamma", text="")
542 #               col.itemL(text="Multiply:")
543 #               col.itemR(vpaint, "mul", text="")
544
545
546 # ********** default tools for texturepaint ****************
547
548 class VIEW3D_PT_tools_projectpaint(View3DPanel):
549         __context__ = "projectpaint"
550         __label__ = "Project Paint"
551
552         def poll(self, context):         
553                 return context.tool_settings.image_paint.tool != 'SMEAR'         
554
555         def draw_header(self, context):          
556                 layout = self.layout     
557                 ipaint = context.tool_settings.image_paint       
558                 layout.itemR(ipaint, "use_projection", text="")
559
560         def draw(self, context):
561                 layout = self.layout
562                 
563                 ipaint = context.tool_settings.image_paint
564                 settings = context.tool_settings.image_paint
565                 use_projection= ipaint.use_projection
566                 
567                 col = layout.column()
568                 sub = col.column()
569                 sub.active = use_projection
570                 sub.itemR(ipaint, "use_occlude")
571                 sub.itemR(ipaint, "use_backface_cull")
572                 
573                 split = layout.split()
574                 
575                 col = split.column()
576                 col.active = (use_projection)
577                 col.itemR(ipaint, "use_normal_falloff")
578                 
579                 col = split.column()
580                 col.active = (ipaint.use_normal_falloff and use_projection)
581                 col.itemR(ipaint, "normal_angle", text="")
582
583                 split = layout.split(percentage=0.7)
584                 
585                 col = split.column(align=False)
586                 col.active = (use_projection)
587                 col.itemR(ipaint, "use_stencil_layer")
588                 
589                 col = split.column(align=False)
590                 col.active = (use_projection and ipaint.use_stencil_layer)
591                 col.itemR(ipaint, "invert_stencil", text="Inv")
592
593                 col = layout.column()
594                 sub = col.column()
595                 sub.active = (settings.tool == 'CLONE')
596                 sub.itemR(ipaint, "use_clone_layer")
597                 
598                 sub = col.column()
599                 sub.itemR(ipaint, "seam_bleed")
600                 
601 # ********** default tools for particle mode ****************
602
603 class VIEW3D_PT_tools_particlemode(View3DPanel):
604         __context__ = "particlemode"
605         __label__ = "Options"
606
607         def draw(self, context):
608                 layout = self.layout
609
610                 pe = context.tool_settings.particle_edit
611                 ob = pe.object
612
613                 row = layout.row()
614                 row.itemL(text="Edit:")
615                 row.itemR(pe, "type", text="")
616                 
617                 if pe.type == 'PARTICLES':
618                         if ob.particle_systems:
619                                 if len(ob.particle_systems) > 1:
620                                         layout.template_list(ob, "particle_systems", ob, "active_particle_system_index", type='ICONS')
621                                 
622                                 ptcache = ob.particle_systems[ob.active_particle_system_index].point_cache
623                 else:
624                         for md in ob.modifiers:
625                                 if md.type==pe.type:
626                                         ptcache = md.point_cache
627                                         
628                 if ptcache and len(ptcache.point_cache_list) > 1:
629                         layout.template_list(ptcache, "point_cache_list", ptcache, "active_point_cache_index", type='ICONS')
630                         
631                 
632                 if not pe.editable:
633                         layout.itemL(text="Point cache must be baked")
634                         layout.itemL(text="to enable editing!")
635                 
636                 col = layout.column(align=True)
637                 if pe.hair:
638                         col.active = pe.editable
639                         col.itemR(pe, "emitter_deflect", text="Deflect emitter")
640                         sub = col.row()
641                         sub.active = pe.emitter_deflect
642                         sub.itemR(pe, "emitter_distance", text="Distance")
643                 
644                 col = layout.column(align=True)
645                 col.active = pe.editable
646                 col.itemL(text="Keep:")
647                 col.itemR(pe, "keep_lengths", text="Lenghts")
648                 col.itemR(pe, "keep_root", text="Root")
649                 if not pe.hair:
650                         col.itemL(text="Correct:")
651                         col.itemR(pe, "auto_velocity", text="Velocity")
652                 
653                 col = layout.column(align=True)
654                 col.active = pe.editable
655                 col.itemL(text="Draw:")
656                 col.itemR(pe, "draw_step", text="Path Steps")
657                 if pe.type == 'PARTICLES':
658                         col.itemR(pe, "draw_particles", text="Particles")
659                 col.itemR(pe, "fade_time")
660                 sub = col.row()
661                 sub.active = pe.fade_time
662                 sub.itemR(pe, "fade_frames", slider=True)
663
664 bpy.types.register(VIEW3D_PT_tools_objectmode)
665 bpy.types.register(VIEW3D_PT_tools_meshedit)
666 bpy.types.register(VIEW3D_PT_tools_curveedit)
667 bpy.types.register(VIEW3D_PT_tools_surfaceedit)
668 bpy.types.register(VIEW3D_PT_tools_textedit)
669 bpy.types.register(VIEW3D_PT_tools_armatureedit)
670 bpy.types.register(VIEW3D_PT_tools_mballedit)
671 bpy.types.register(VIEW3D_PT_tools_latticeedit)
672 bpy.types.register(VIEW3D_PT_tools_posemode)
673 bpy.types.register(VIEW3D_PT_tools_brush)
674 bpy.types.register(VIEW3D_PT_tools_brush_stroke)
675 bpy.types.register(VIEW3D_PT_tools_brush_curve)
676 bpy.types.register(VIEW3D_PT_sculpt_options)
677 bpy.types.register(VIEW3D_PT_tools_vertexpaint)
678 bpy.types.register(VIEW3D_PT_tools_weightpaint)
679 bpy.types.register(VIEW3D_PT_tools_projectpaint)
680 bpy.types.register(VIEW3D_PT_tools_particlemode)