2.5 3DView Header:
[blender-staging.git] / release / ui / space_view3d.py
1
2 import bpy
3
4 # ********** Header **********
5
6 class VIEW3D_HT_header(bpy.types.Header):
7         __space_type__ = "VIEW_3D"
8
9         def draw(self, context):
10                 layout = self.layout
11                 
12                 view = context.space_data
13                 mode_string = context.mode
14
15                 layout.template_header()
16                 
17                 # Menus
18                 if context.area.show_menus:
19                         row = layout.row()
20
21                         row.itemM("VIEW3D_MT_view")
22                         
23                         # Select Menu
24                         if mode_string not in ('EDIT_TEXT', 'SCULPT', 'PAINT_WEIGHT', 'PAINT_VERTEX', 'PAINT_TEXTURE', 'PARTICLE'):
25                                 # XXX: Particle Mode has Select Menu.
26                                 row.itemM("VIEW3D_MT_select_%s" % mode_string)
27                         
28                         if mode_string == 'OBJECT':
29                                 row.itemM("VIEW3D_MT_object")
30                         elif mode_string == 'SCULPT':
31                                 row.itemM("VIEW3D_MT_sculpt")
32
33                 layout.template_header_3D()
34
35 # ********** Menu **********
36
37 # ********** View menus **********
38
39 class VIEW3D_MT_view(bpy.types.Menu):
40         __space_type__ = "VIEW_3D"
41         __label__ = "View"
42
43         def draw(self, context):
44                 layout = self.layout
45
46                 layout.itemO("view3d.properties", icon="ICON_MENU_PANEL")
47                 layout.itemO("view3d.toolbar", icon="ICON_MENU_PANEL")
48                 
49                 layout.itemS()
50                 
51                 layout.item_enumO("view3d.viewnumpad", "type", 'CAMERA')
52                 layout.item_enumO("view3d.viewnumpad", "type", 'TOP')
53                 layout.item_enumO("view3d.viewnumpad", "type", 'FRONT')
54                 layout.item_enumO("view3d.viewnumpad", "type", 'RIGHT')
55                 
56                 # layout.itemM("VIEW3D_MT_view_cameras", text="Cameras")
57                 
58                 layout.itemS()
59
60                 layout.itemO("view3d.view_persportho")
61                 
62                 layout.itemS()
63                 
64                 # layout.itemO("view3d.view_show_all_layers")
65                 
66                 # layout.itemS()
67                 
68                 # layout.itemO("view3d.view_local_view")
69                 # layout.itemO("view3d.view_global_view")
70                 
71                 # layout.itemS()
72                 
73                 layout.itemM("VIEW3D_MT_view_navigation")
74                 # layout.itemM("VIEW3D_MT_view_align", text="Align View")
75                 
76                 layout.itemS()
77
78                 layout.operator_context = "INVOKE_REGION_WIN"
79
80                 layout.itemO("view3d.clip_border")
81                 layout.itemO("view3d.zoom_border")
82                 
83                 layout.itemS()
84                 
85                 layout.itemO("view3d.view_center")
86                 layout.itemO("view3d.view_all")
87                 
88                 layout.itemS()
89                 
90                 layout.itemO("screen.region_foursplit", text="Toggle Quad View")
91                 layout.itemO("screen.screen_full_area", text="Toggle Full Screen")
92                 
93 class VIEW3D_MT_view_navigation(bpy.types.Menu):
94         __space_type__ = "VIEW_3D"
95         __label__ = "Navigation"
96
97         def draw(self, context):
98                 layout = self.layout
99
100                 # layout.itemO("view3d.view_fly_mode")
101                 # layout.itemS()
102                 
103                 layout.items_enumO("view3d.view_orbit", "type")
104                 
105                 layout.itemS()
106                 
107                 layout.items_enumO("view3d.view_pan", "type")
108                 
109                 layout.itemS()
110                 
111                 layout.item_floatO("view3d.zoom", "delta", 1.0, text="Zoom In")
112                 layout.item_floatO("view3d.zoom", "delta", -1.0, text="Zoom Out")
113
114 # ********** Select menus, suffix from context.mode **********
115
116 class VIEW3D_MT_select_OBJECT(bpy.types.Menu):
117         __space_type__ = "VIEW_3D"
118         __label__ = "Select"
119
120         def draw(self, context):
121                 layout = self.layout
122
123                 layout.itemO("view3d.select_border")
124
125                 layout.itemS()
126
127                 layout.itemO("object.select_all_toggle", text="Select/Deselect All")
128                 layout.itemO("object.select_inverse", text="Inverse")
129                 layout.itemO("object.select_random", text="Random")
130                 layout.itemO("object.select_by_layer", text="Select All by Layer")
131                 layout.item_enumO("object.select_by_type", "type", "", text="Select All by Type")
132                 layout.itemO("object.select_grouped", text="Select Grouped")
133
134 class VIEW3D_MT_select_POSE(bpy.types.Menu):
135         __space_type__ = "VIEW_3D"
136         __label__ = "Select"
137
138         def draw(self, context):
139                 layout = self.layout
140
141                 layout.itemO("view3d.select_border")
142
143                 layout.itemS()
144                 
145                 layout.itemO("pose.select_all_toggle", text="Select/Deselect All")
146                 layout.itemO("pose.select_inverse", text="Inverse")
147                 layout.itemO("pose.select_constraint_target", text="Constraint Target")
148                 
149                 layout.itemS()
150                 
151                 layout.item_enumO("pose.select_hierarchy", "direction", 'PARENT')
152                 layout.item_enumO("pose.select_hierarchy", "direction", 'CHILD')
153                 
154                 layout.itemS()
155                 
156                 layout.view3d_select_posemenu()
157
158 class VIEW3D_MT_select_PARTICLE(bpy.types.Menu):
159         __space_type__ = "VIEW_3D"
160         __label__ = "Select"
161
162         def draw(self, context):
163                 layout = self.layout
164
165                 layout.itemO("view3d.select_border")
166
167                 layout.itemS()
168                 
169                 layout.itemO("particle.select_all_toggle", text="Select/Deselect All")
170                 layout.itemO("particle.select_linked")
171                 
172                 layout.itemS()
173                 
174                 #layout.itemO("particle.select_last")
175                 #layout.itemO("particle.select_first")
176                 
177                 layout.itemO("particle.select_more")
178                 layout.itemO("particle.select_less")
179
180 class VIEW3D_MT_select_EDIT_MESH(bpy.types.Menu):
181         __space_type__ = "VIEW_3D"
182         __label__ = "Select"
183
184         def draw(self, context):
185                 layout = self.layout
186
187                 layout.itemO("view3d.select_border")
188
189                 layout.itemS()
190
191                 layout.itemO("mesh.select_all_toggle", text="Select/Deselect All")
192                 layout.itemO("mesh.select_inverse", text="Inverse")
193
194                 layout.itemS()
195
196                 layout.itemO("mesh.select_random", text="Random...")
197                 layout.itemO("mesh.edges_select_sharp", text="Sharp Edges")
198                 layout.itemO("mesh.faces_select_linked_flat", text="Linked Flat Faces")
199
200                 layout.itemS()
201
202                 layout.item_enumO("mesh.select_by_number_vertices", "type", 'TRIANGLES', text="Triangles")
203                 layout.item_enumO("mesh.select_by_number_vertices", "type", 'QUADS', text="Quads")
204                 layout.item_enumO("mesh.select_by_number_vertices", "type", 'OTHER', text="Loose Verts/Edges")
205                 layout.itemO("mesh.select_similar", text="Similar...")
206
207                 layout.itemS()
208
209                 layout.itemO("mesh.select_less", text="Less")
210                 layout.itemO("mesh.select_more", text="More")
211
212                 layout.itemS()
213
214                 layout.itemO("mesh.select_linked", text="Linked")
215                 layout.itemO("mesh.select_vertex_path", text="Vertex Path")
216                 layout.itemO("mesh.loop_multi_select", text="Edge Loop")
217                 layout.item_booleanO("mesh.loop_multi_select", "ring", True, text="Edge Ring")
218
219                 layout.itemS()
220
221                 layout.itemO("mesh.loop_to_region")
222                 layout.itemO("mesh.region_to_loop")
223
224 class VIEW3D_MT_select_EDIT_CURVE(bpy.types.Menu):
225         __space_type__ = "VIEW_3D"
226         __label__ = "Select"
227
228         def draw(self, context):
229                 layout = self.layout
230
231                 layout.itemO("view3d.select_border")
232                 layout.itemO("view3d.select_circle")
233
234                 layout.itemS()
235                 
236                 layout.itemO("curve.select_all_toggle", text="Select/Deselect All")
237                 layout.itemO("curve.select_inverse")
238                 layout.itemO("curve.select_random")
239                 layout.itemO("curve.select_every_nth")
240
241                 layout.itemS()
242                 
243                 layout.itemO("curve.de_select_first")
244                 layout.itemO("curve.de_select_last")
245                 layout.itemO("curve.select_next")
246                 layout.itemO("curve.select_previous")
247
248                 layout.itemS()
249                 
250                 layout.itemO("curve.select_more")
251                 layout.itemO("curve.select_less")
252
253 class VIEW3D_MT_select_EDIT_SURFACE(bpy.types.Menu):
254         __space_type__ = "VIEW_3D"
255         __label__ = "Select"
256
257         def draw(self, context):
258                 layout = self.layout
259
260                 layout.itemO("view3d.select_border")
261                 layout.itemO("view3d.select_circle")
262
263                 layout.itemS()
264                 
265                 layout.itemO("curve.select_all_toggle", text="Select/Deselect All")
266                 layout.itemO("curve.select_inverse")
267                 layout.itemO("curve.select_random")
268                 layout.itemO("curve.select_every_nth")
269
270                 layout.itemS()
271                 
272                 layout.itemO("curve.select_row")
273
274                 layout.itemS()
275                 
276                 layout.itemO("curve.select_more")
277                 layout.itemO("curve.select_less")
278
279 class VIEW3D_MT_select_EDIT_METABALL(bpy.types.Menu):
280         __space_type__ = "VIEW_3D"
281         __label__ = "Select"
282
283         def draw(self, context):
284                 layout = self.layout
285
286                 layout.itemO("view3d.select_border")
287                 
288                 layout.itemS()
289                 
290                 layout.itemL(text="Select/Deselect All")
291                 layout.itemL(text="Inverse")
292                 
293                 layout.itemS()
294                 
295                 layout.itemL(text="Random")
296
297 class VIEW3D_MT_select_EDIT_LATTICE(bpy.types.Menu):
298         __space_type__ = "VIEW_3D"
299         __label__ = "Select"
300
301         def draw(self, context):
302                 layout = self.layout
303
304                 layout.itemO("view3d.select_border")
305
306                 layout.itemS()
307                 
308                 layout.itemO("lattice.select_all_toggle", text="Select/Deselect All")
309
310 class VIEW3D_MT_select_EDIT_ARMATURE(bpy.types.Menu):
311         __space_type__ = "VIEW_3D"
312         __label__ = "Select"
313
314         def draw(self, context):
315                 layout = self.layout
316
317                 layout.itemO("view3d.select_border")
318
319                 layout.itemS()
320                 
321                 layout.itemO("armature.select_all_toggle", text="Select/Deselect All")
322                 layout.itemO("armature.select_inverse", text="Inverse")
323
324                 layout.itemS()
325                 
326                 layout.item_enumO("armature.select_hierarchy", "direction", 'PARENT')
327                 layout.item_enumO("armature.select_hierarchy", "direction", 'CHILD')
328                 
329                 layout.itemS()
330                 
331                 layout.view3d_select_armaturemenu()
332
333 class VIEW3D_MT_select_FACE(bpy.types.Menu):# XXX no matching enum
334         __space_type__ = "VIEW_3D"
335         __label__ = "Select"
336
337         def draw(self, context):
338                 layout = self.layout
339
340                 layout.view3d_select_faceselmenu()
341
342 # ********** Object menu **********
343
344 class VIEW3D_MT_object(bpy.types.Menu):
345         __space_type__ = "VIEW_3D"
346         __context__ = "objectmode"
347         __label__ = "Object"
348
349         def draw(self, context):
350                 layout = self.layout
351
352                 layout.itemM("VIEW3D_MT_object_clear")
353                 layout.itemM("VIEW3D_MT_object_snap")
354                 
355                 layout.itemS()
356                 
357                 layout.itemO("anim.insert_keyframe_menu")
358                 layout.itemO("anim.delete_keyframe_v3d")
359                 
360                 layout.itemS()
361                 
362                 layout.itemO("object.duplicate")
363                 layout.item_booleanO("object.duplicate", "linked", True, text="Duplicate Linked")
364                 layout.itemO("object.delete")
365                 layout.itemO("object.proxy_make")
366                 
367                 layout.itemS()
368                 
369                 layout.itemM("VIEW3D_MT_object_parent")
370                 layout.itemM("VIEW3D_MT_object_track")
371                 layout.itemM("VIEW3D_MT_object_group")
372                 layout.itemM("VIEW3D_MT_object_constraints")
373                 
374                 layout.itemS()
375                 
376                 layout.itemO("object.join")
377                 
378                 layout.itemS()
379                 
380                 layout.itemM("VIEW3D_MT_object_show")
381                 
382 class VIEW3D_MT_object_clear(bpy.types.Menu):
383         __space_type__ = "VIEW_3D"
384         __label__ = "Clear"
385
386         def draw(self, context):
387                 layout = self.layout
388                 
389                 layout.itemO("object.location_clear")
390                 layout.itemO("object.rotation_clear")
391                 layout.itemO("object.scale_clear")
392                 layout.itemO("object.origin_clear")
393                 
394 class VIEW3D_MT_object_snap(bpy.types.Menu):
395         __space_type__ = "VIEW_3D"
396         __label__ = "Snap"
397
398         def draw(self, context):
399                 layout = self.layout
400                 
401                 layout.itemO("view3d.snap_selected_to_grid")
402                 layout.itemO("view3d.snap_selected_to_cursor")
403                 layout.itemO("view3d.snap_selected_to_center")
404                 
405                 layout.itemS()
406                 
407                 layout.itemO("view3d.snap_cursor_to_selected")
408                 layout.itemO("view3d.snap_cursor_to_grid")
409                 layout.itemO("view3d.snap_cursor_to_active")
410                 
411 class VIEW3D_MT_object_parent(bpy.types.Menu):
412         __space_type__ = "VIEW_3D"
413         __label__ = "Parent"
414
415         def draw(self, context):
416                 layout = self.layout
417                 
418                 layout.itemO("object.parent_set")
419                 layout.itemO("object.parent_clear")
420                 
421 class VIEW3D_MT_object_track(bpy.types.Menu):
422         __space_type__ = "VIEW_3D"
423         __label__ = "Track"
424
425         def draw(self, context):
426                 layout = self.layout
427                 
428                 layout.itemO("object.track_set")
429                 layout.itemO("object.track_clear")
430                 
431 class VIEW3D_MT_object_group(bpy.types.Menu):
432         __space_type__ = "VIEW_3D"
433         __label__ = "Group"
434
435         def draw(self, context):
436                 layout = self.layout
437                 
438                 layout.itemO("group.group_create")
439                 layout.itemO("group.objects_remove")
440                 
441                 layout.itemS()
442                 
443                 layout.itemO("group.objects_add_active")
444                 layout.itemO("group.objects_remove_active")
445                 
446 class VIEW3D_MT_object_constraints(bpy.types.Menu):
447         __space_type__ = "VIEW_3D"
448         __label__ = "Constraints"
449
450         def draw(self, context):
451                 layout = self.layout
452                 
453                 layout.itemO("object.constraint_add_with_targets")
454                 layout.itemO("object.constraints_clear")
455                 
456 class VIEW3D_MT_object_show(bpy.types.Menu):
457         __space_type__ = "VIEW_3D"
458         __label__ = "Show/Hide"
459
460         def draw(self, context):
461                 layout = self.layout
462                 
463                 layout.itemO("object.restrictview_clear")
464                 layout.itemO("object.restrictview_set")
465                 layout.item_booleanO("object.restrictview_set", "unselected", True, text="Hide Unselected")
466
467 # ********** Sculpt menu **********     
468         
469 class VIEW3D_MT_sculpt(bpy.types.Menu):
470         __space_type__ = "VIEW_3D"
471         __label__ = "Sculpt"
472
473         def draw(self, context):
474                 layout = self.layout
475                 
476                 sculpt = context.tool_settings.sculpt
477                 brush = context.tool_settings.sculpt.brush
478                 
479                 layout.itemR(sculpt, "symmetry_x")
480                 layout.itemR(sculpt, "symmetry_y")
481                 layout.itemR(sculpt, "symmetry_z")
482                 layout.itemS()
483                 layout.itemR(sculpt, "lock_x")
484                 layout.itemR(sculpt, "lock_y")
485                 layout.itemR(sculpt, "lock_z")
486                 layout.itemS()
487                 layout.item_menu_enumO("brush.curve_preset", property="shape")
488                 layout.itemS()
489                 
490                 if brush.sculpt_tool != 'GRAB':
491                         layout.itemR(brush, "airbrush")
492                         
493                         if brush.sculpt_tool != 'LAYER':
494                                 layout.itemR(brush, "anchored")
495                         
496                         if brush.sculpt_tool in ('DRAW', 'PINCH', 'INFLATE', 'LAYER', 'CLAY'):
497                                 layout.itemR(brush, "flip_direction")
498
499                         if brush.sculpt_tool == 'LAYER':
500                                 layout.itemR(brush, "persistent")
501                                 layout.itemO("sculpt.set_persistent_base")
502
503 # ********** Panel **********
504
505 class VIEW3D_PT_3dview_properties(bpy.types.Panel):
506         __space_type__ = "VIEW_3D"
507         __region_type__ = "UI"
508         __label__ = "View"
509
510         def poll(self, context):
511                 view = context.space_data
512                 return (view)
513
514         def draw(self, context):
515                 layout = self.layout
516                 
517                 view = context.space_data
518                 scene = context.scene
519                 
520                 col = layout.column()
521                 col.itemR(view, "camera")
522                 col.itemR(view, "lens")
523                 
524                 layout.itemL(text="Clip:")
525                 col = layout.column(align=True)
526                 col.itemR(view, "clip_start", text="Start")
527                 col.itemR(view, "clip_end", text="End")
528                 
529                 layout.itemL(text="Grid:")
530                 col = layout.column(align=True)
531                 col.itemR(view, "grid_lines", text="Lines")
532                 col.itemR(view, "grid_spacing", text="Spacing")
533                 col.itemR(view, "grid_subdivisions", text="Subdivisions")
534                 
535                 layout.column().itemR(scene, "cursor_location", text="3D Cursor:")
536                 
537 class VIEW3D_PT_3dview_display(bpy.types.Panel):
538         __space_type__ = "VIEW_3D"
539         __region_type__ = "UI"
540         __label__ = "Display"
541
542         def poll(self, context):
543                 view = context.space_data
544                 return (view)
545
546         def draw(self, context):
547                 layout = self.layout
548                 view = context.space_data
549                 
550                 col = layout.column()
551                 col.itemR(view, "display_floor", text="Grid Floor")
552                 col.itemR(view, "display_x_axis", text="X Axis")
553                 col.itemR(view, "display_y_axis", text="Y Axis")
554                 col.itemR(view, "display_z_axis", text="Z Axis")
555                 col.itemR(view, "outline_selected")
556                 col.itemR(view, "all_object_centers")
557                 col.itemR(view, "relationship_lines")
558                 col.itemR(view, "textured_solid")
559                 
560                 layout.itemS()
561                 
562                 layout.itemO("screen.region_foursplit")
563                 
564                 col = layout.column()
565                 col.itemR(view, "lock_rotation")
566                 col.itemR(view, "box_preview")
567                 col.itemR(view, "box_clip")
568         
569 class VIEW3D_PT_background_image(bpy.types.Panel):
570         __space_type__ = "VIEW_3D"
571         __region_type__ = "UI"
572         __label__ = "Background Image"
573         __default_closed__ = True
574
575         def poll(self, context):
576                 view = context.space_data
577                 bg = context.space_data.background_image
578                 return (view)
579
580         def draw_header(self, context):
581                 layout = self.layout
582                 view = context.space_data
583
584                 layout.itemR(view, "display_background_image", text="")
585
586         def draw(self, context):
587                 layout = self.layout
588                 
589                 view = context.space_data
590                 bg = view.background_image
591
592                 if bg:
593                         layout.active = view.display_background_image
594
595                         col = layout.column()
596                         col.itemR(bg, "image", text="")
597                         #col.itemR(bg, "image_user")
598                         col.itemR(bg, "size")
599                         col.itemR(bg, "transparency", slider=True)
600                         col.itemL(text="Offset:")
601                         
602                         col = layout.column(align=True)
603                         col.itemR(bg, "x_offset", text="X")
604                         col.itemR(bg, "y_offset", text="Y")
605
606 bpy.types.register(VIEW3D_HT_header) # Header
607
608 bpy.types.register(VIEW3D_MT_view) #View Menus
609 bpy.types.register(VIEW3D_MT_view_navigation)
610
611 bpy.types.register(VIEW3D_MT_select_OBJECT) # Select Menus
612 bpy.types.register(VIEW3D_MT_select_POSE)
613 bpy.types.register(VIEW3D_MT_select_PARTICLE)
614 bpy.types.register(VIEW3D_MT_select_EDIT_MESH)
615 bpy.types.register(VIEW3D_MT_select_EDIT_CURVE)
616 bpy.types.register(VIEW3D_MT_select_EDIT_SURFACE)
617 bpy.types.register(VIEW3D_MT_select_EDIT_METABALL)
618 bpy.types.register(VIEW3D_MT_select_EDIT_LATTICE)
619 bpy.types.register(VIEW3D_MT_select_EDIT_ARMATURE)
620 bpy.types.register(VIEW3D_MT_select_FACE) # XXX todo
621
622 bpy.types.register(VIEW3D_MT_object) # Object Menu
623 bpy.types.register(VIEW3D_MT_object_clear)
624 bpy.types.register(VIEW3D_MT_object_snap)
625 bpy.types.register(VIEW3D_MT_object_parent)
626 bpy.types.register(VIEW3D_MT_object_track)
627 bpy.types.register(VIEW3D_MT_object_group)
628 bpy.types.register(VIEW3D_MT_object_constraints)
629 bpy.types.register(VIEW3D_MT_object_show)
630
631 bpy.types.register(VIEW3D_MT_sculpt) # Sculpt Menu
632
633 bpy.types.register(VIEW3D_PT_3dview_properties) # Panels
634 bpy.types.register(VIEW3D_PT_3dview_display)
635 bpy.types.register(VIEW3D_PT_background_image)