svn merge ^/trunk/blender -r41150:41175
[blender.git] / source / blender / editors / space_view3d / view3d_header.c
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2004-2008 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Blender Foundation
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 /** \file blender/editors/space_view3d/view3d_header.c
30  *  \ingroup spview3d
31  */
32
33
34 #include <string.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37
38 #include "DNA_scene_types.h"
39 #include "DNA_object_types.h"
40
41 #include "RNA_access.h"
42
43 #include "MEM_guardedalloc.h"
44
45 #include "BLI_math.h"
46 #include "BLI_blenlib.h"
47 #include "BLI_editVert.h"
48 #include "BLI_utildefines.h"
49
50 #include "BLF_translation.h"
51
52 #include "BKE_context.h"
53 #include "BKE_depsgraph.h"
54 #include "BKE_effect.h"
55 #include "BKE_main.h"
56 #include "BKE_mesh.h"
57 #include "BKE_modifier.h"
58 #include "BKE_paint.h"
59 #include "BKE_screen.h"
60 #include "BKE_tessmesh.h"
61
62 #include "ED_mesh.h"
63 #include "ED_util.h"
64 #include "ED_screen.h"
65 #include "ED_transform.h"
66 #include "ED_types.h"
67
68 #include "WM_api.h"
69 #include "WM_types.h"
70
71 #include "RNA_define.h"
72 #include "RNA_enum_types.h"
73
74 #include "UI_interface.h"
75 #include "UI_resources.h"
76
77 #include "view3d_intern.h"
78
79
80 /* View3d->modeselect 
81  * This is a bit of a dodgy hack to enable a 'mode' menu with icons+labels
82  * rather than those buttons.
83  * I know the implementation's not good - it's an experiment to see if this
84  * approach would work well
85  *
86  * This can be cleaned when I make some new 'mode' icons.
87  */
88
89 #define TEST_EDITMESH   if(obedit==0) return; \
90                                                 if( (v3d->lay & obedit->lay)==0 ) return;
91
92 /* view3d handler codes */
93 #define VIEW3D_HANDLER_BACKGROUND       1
94 #define VIEW3D_HANDLER_PROPERTIES       2
95 #define VIEW3D_HANDLER_OBJECT           3
96 #define VIEW3D_HANDLER_PREVIEW          4
97 #define VIEW3D_HANDLER_MULTIRES         5
98 #define VIEW3D_HANDLER_TRANSFORM        6
99 #define VIEW3D_HANDLER_GREASEPENCIL 7
100 #define VIEW3D_HANDLER_BONESKETCH       8
101
102 /* end XXX ************* */
103
104 static void do_view3d_header_buttons(bContext *C, void *arg, int event);
105
106 #define B_SCENELOCK 101
107 #define B_FULL          102
108 #define B_HOME          103
109 #define B_VIEWBUT       104
110 #define B_PERSP         105
111 #define B_MODESELECT 108
112 #define B_SEL_VERT      110
113 #define B_SEL_EDGE      111
114 #define B_SEL_FACE      112
115 #define B_MAN_TRANS     116
116 #define B_MAN_ROT       117
117 #define B_MAN_SCALE     118
118 #define B_NDOF          119     
119 #define B_MAN_MODE      120
120 #define B_REDR          122
121 #define B_NOP           123
122
123 // XXX quickly ported across
124 static void handle_view3d_lock(bContext *C) 
125 {
126         Main *bmain= CTX_data_main(C);
127         Scene *scene= CTX_data_scene(C);
128         ScrArea *sa= CTX_wm_area(C);
129         View3D *v3d= CTX_wm_view3d(C);
130         
131         if (v3d != NULL && sa != NULL) {
132                 if(v3d->localvd==NULL && v3d->scenelock && sa->spacetype==SPACE_VIEW3D) {
133                         /* copy to scene */
134                         scene->lay= v3d->lay;
135                         scene->layact= v3d->layact;
136                         scene->camera= v3d->camera;
137
138                         /* not through notifiery, listener don't have context
139                            and non-open screens or spaces need to be updated too */
140                         BKE_screen_view3d_main_sync(&bmain->screen, scene);
141                         
142                         /* notifiers for scene update */
143                         WM_event_add_notifier(C, NC_SCENE|ND_LAYER, scene);
144                 }
145         }
146 }
147
148 /* layer code is on three levels actually:
149 - here for operator
150 - uiTemplateLayers in interface/ code for buttons
151 - ED_view3d_scene_layer_set for RNA
152  */
153 static void view3d_layers_editmode_ensure(Scene *scene, View3D *v3d)
154 {
155         /* sanity check - when in editmode disallow switching the editmode layer off since its confusing
156          * an alternative would be to always draw the editmode object. */
157         if(scene->obedit && (scene->obedit->lay & v3d->lay)==0) {
158                 int bit;
159                 for(bit=0; bit<32; bit++) {
160                         if(scene->obedit->lay & (1<<bit)) {
161                                 v3d->lay |= 1<<bit;
162                                 break;
163                         }
164                 }
165         }
166 }
167
168 static int view3d_layers_exec(bContext *C, wmOperator *op)
169 {
170         Scene *scene= CTX_data_scene(C);
171         ScrArea *sa= CTX_wm_area(C);
172         View3D *v3d= sa->spacedata.first;
173         int nr= RNA_int_get(op->ptr, "nr");
174         int toggle= RNA_boolean_get(op->ptr, "toggle");
175         
176         if(nr < 0)
177                 return OPERATOR_CANCELLED;
178
179         if(nr == 0) {
180                 /* all layers */
181                 if(!v3d->layact)
182                         v3d->layact= 1;
183
184                 if (toggle && v3d->lay == ((1<<20)-1)) {
185                         /* return to active layer only */
186                         v3d->lay = v3d->layact;
187
188                         view3d_layers_editmode_ensure(scene, v3d);
189                 }
190                 else {
191                         v3d->lay |= (1<<20)-1;
192                 }               
193         }
194         else {
195                 int bit;
196                 nr--;
197
198                 if(RNA_boolean_get(op->ptr, "extend")) {
199                         if(toggle && v3d->lay & (1<<nr) && (v3d->lay & ~(1<<nr)))
200                                 v3d->lay &= ~(1<<nr);
201                         else
202                                 v3d->lay |= (1<<nr);
203                 } else {
204                         v3d->lay = (1<<nr);
205                 }
206
207                 view3d_layers_editmode_ensure(scene, v3d);
208
209                 /* set active layer, ensure to always have one */
210                 if(v3d->lay & (1<<nr))
211                    v3d->layact= 1<<nr;
212                 else if((v3d->lay & v3d->layact)==0) {
213                         for(bit=0; bit<32; bit++) {
214                                 if(v3d->lay & (1<<bit)) {
215                                         v3d->layact= 1<<bit;
216                                         break;
217                                 }
218                         }
219                 }
220         }
221         
222         if(v3d->scenelock) handle_view3d_lock(C);
223         
224         DAG_on_visible_update(CTX_data_main(C), FALSE);
225
226         ED_area_tag_redraw(sa);
227         
228         return OPERATOR_FINISHED;
229 }
230
231 /* applies shift and alt, lazy coding or ok? :) */
232 /* the local per-keymap-entry keymap will solve it */
233 static int view3d_layers_invoke(bContext *C, wmOperator *op, wmEvent *event)
234 {
235         if(event->ctrl || event->oskey)
236                 return OPERATOR_PASS_THROUGH;
237         
238         if(event->shift)
239                 RNA_boolean_set(op->ptr, "extend", 1);
240         
241         if(event->alt) {
242                 int nr= RNA_int_get(op->ptr, "nr") + 10;
243                 RNA_int_set(op->ptr, "nr", nr);
244         }
245         view3d_layers_exec(C, op);
246         
247         return OPERATOR_FINISHED;
248 }
249
250 static int view3d_layers_poll(bContext *C)
251 {
252         return (ED_operator_view3d_active(C) && CTX_wm_view3d(C)->localvd==NULL);
253 }
254
255 void VIEW3D_OT_layers(wmOperatorType *ot)
256 {
257         /* identifiers */
258         ot->name= "Layers";
259         ot->description= "Toggle layer(s) visibility";
260         ot->idname= "VIEW3D_OT_layers";
261         
262         /* api callbacks */
263         ot->invoke= view3d_layers_invoke;
264         ot->exec= view3d_layers_exec;
265         ot->poll= view3d_layers_poll;
266         
267         /* flags */
268         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
269         
270         RNA_def_int(ot->srna, "nr", 1, 0, 20, "Number", "The layer number to set, zero for all layers", 0, 20);
271         RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Add this layer to the current view layers");
272         RNA_def_boolean(ot->srna, "toggle", 1, "Toggle", "Toggle the layer");
273 }
274
275 static int modeselect_addmode(char *str, const char *title, int id, int icon)
276 {
277         static char formatstr[] = "|%s %%x%d %%i%d";
278
279         return sprintf(str, formatstr, IFACE_(title), id, icon);
280 }
281
282 static char *view3d_modeselect_pup(Scene *scene)
283 {
284         Object *ob= OBACT;
285         static char string[256];
286         const char *title= IFACE_("Mode: %t");
287         char *str = string;
288
289         BLI_strncpy(str, title, sizeof(string));
290
291         str += modeselect_addmode(str, N_("Object Mode"), OB_MODE_OBJECT, ICON_OBJECT_DATA);
292
293         if(ob==NULL || ob->data==NULL) return string;
294         if(ob->id.lib) return string;
295
296         if(!((ID *)ob->data)->lib) {
297                 /* if active object is editable */
298                 if ( ((ob->type == OB_MESH)
299                         || (ob->type == OB_CURVE) || (ob->type == OB_SURF) || (ob->type == OB_FONT)
300                         || (ob->type == OB_MBALL) || (ob->type == OB_LATTICE))) {
301
302                         str += modeselect_addmode(str, N_("Edit Mode"), OB_MODE_EDIT, ICON_EDITMODE_HLT);
303                 }
304                 else if (ob->type == OB_ARMATURE) {
305                         if (ob->mode & OB_MODE_POSE)
306                                 str += modeselect_addmode(str, N_("Edit Mode"), OB_MODE_EDIT|OB_MODE_POSE, ICON_EDITMODE_HLT);
307                         else
308                                 str += modeselect_addmode(str, N_("Edit Mode"), OB_MODE_EDIT, ICON_EDITMODE_HLT);
309                 }
310
311                 if (ob->type == OB_MESH) {
312
313                         str += modeselect_addmode(str, N_("Sculpt Mode"), OB_MODE_SCULPT, ICON_SCULPTMODE_HLT);
314                         str += modeselect_addmode(str, N_("Vertex Paint"), OB_MODE_VERTEX_PAINT, ICON_VPAINT_HLT);
315                         str += modeselect_addmode(str, N_("Texture Paint"), OB_MODE_TEXTURE_PAINT, ICON_TPAINT_HLT);
316                         str += modeselect_addmode(str, N_("Weight Paint"), OB_MODE_WEIGHT_PAINT, ICON_WPAINT_HLT);
317                 }
318         }
319
320         /* if active object is an armature */
321         if (ob->type==OB_ARMATURE) {
322                 str += modeselect_addmode(str, N_("Pose Mode"), OB_MODE_POSE, ICON_POSE_HLT);
323         }
324
325         if (ob->particlesystem.first || modifiers_findByType(ob, eModifierType_Cloth) || modifiers_findByType(ob, eModifierType_Softbody)) {
326                 str += modeselect_addmode(str, N_("Particle Mode"), OB_MODE_PARTICLE_EDIT, ICON_PARTICLEMODE);
327         }
328         (void)str;
329         return (string);
330 }
331
332
333 static void do_view3d_header_buttons(bContext *C, void *UNUSED(arg), int event)
334 {
335         wmWindow *win= CTX_wm_window(C);
336         ToolSettings *ts= CTX_data_tool_settings(C);
337         ScrArea *sa= CTX_wm_area(C);
338         View3D *v3d= sa->spacedata.first;
339         Object *obedit = CTX_data_edit_object(C);
340         BMEditMesh *em= NULL;
341         int ctrl= win->eventstate->ctrl, shift= win->eventstate->shift;
342         PointerRNA props_ptr;
343         
344         if(obedit && obedit->type==OB_MESH) {
345                 em= ((Mesh *)obedit->data)->edit_btmesh;
346         }
347         /* watch it: if sa->win does not exist, check that when calling direct drawing routines */
348
349         switch(event) {
350         case B_REDR:
351                 ED_area_tag_redraw(sa);
352                 break;
353                 
354         case B_MODESELECT:
355                 WM_operator_properties_create(&props_ptr, "OBJECT_OT_mode_set");
356                 RNA_enum_set(&props_ptr, "mode", v3d->modeselect);
357                 WM_operator_name_call(C, "OBJECT_OT_mode_set", WM_OP_EXEC_REGION_WIN, &props_ptr);
358                 WM_operator_properties_free(&props_ptr);
359                 break;          
360                 
361         case B_SEL_VERT:
362                 if(em) {
363                         if(shift==0 || em->selectmode==0)
364                                 em->selectmode= SCE_SELECT_VERTEX;
365                         ts->selectmode= em->selectmode;
366                         EDBM_selectmode_set(em);
367                         WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data);
368                         ED_undo_push(C, "Selectmode Set: Vertex");
369                 }
370                 break;
371         case B_SEL_EDGE:
372                 if(em) {
373                         if(shift==0 || em->selectmode==0){
374                                 if( (em->selectmode ^ SCE_SELECT_EDGE) == SCE_SELECT_VERTEX){
375                                         if(ctrl) EDBM_convertsel(em, SCE_SELECT_VERTEX,SCE_SELECT_EDGE); 
376                                 }
377                                 em->selectmode = SCE_SELECT_EDGE;
378                         }
379                         ts->selectmode= em->selectmode;
380                         EDBM_selectmode_set(em);
381                         WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data);
382                         ED_undo_push(C, "Selectmode Set: Edge");
383                 }
384                 break;
385         case B_SEL_FACE:
386                 if(em) {
387                         if( shift==0 || em->selectmode==0){
388                                 if( ((ts->selectmode ^ SCE_SELECT_FACE) == SCE_SELECT_VERTEX) || ((ts->selectmode ^ SCE_SELECT_FACE) == SCE_SELECT_EDGE)){
389                                         if(ctrl) EDBM_convertsel(em, (ts->selectmode ^ SCE_SELECT_FACE),SCE_SELECT_FACE);
390                                 }
391                                 em->selectmode = SCE_SELECT_FACE;
392                         }
393                         ts->selectmode= em->selectmode;
394                         EDBM_selectmode_set(em);
395                         WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data);
396                         ED_undo_push(C, "Selectmode Set: Face");
397                 }
398                 break;  
399
400         case B_MAN_TRANS:
401                 if( shift==0 || v3d->twtype==0) {
402                         v3d->twtype= V3D_MANIP_TRANSLATE;
403                 }
404                 ED_area_tag_redraw(sa);
405                 break;
406         case B_MAN_ROT:
407                 if( shift==0 || v3d->twtype==0) {
408                         v3d->twtype= V3D_MANIP_ROTATE;
409                 }
410                 ED_area_tag_redraw(sa);
411                 break;
412         case B_MAN_SCALE:
413                 if( shift==0 || v3d->twtype==0) {
414                         v3d->twtype= V3D_MANIP_SCALE;
415                 }
416                 ED_area_tag_redraw(sa);
417                 break;
418         case B_NDOF:
419                 ED_area_tag_redraw(sa);
420                 break;
421         case B_MAN_MODE:
422                 ED_area_tag_redraw(sa);
423                 break;
424         default:
425                 break;
426         }
427 }
428
429 /* Returns the icon associated with an object mode */
430 static int object_mode_icon(int mode)
431 {
432         EnumPropertyItem *item = object_mode_items;
433         
434         while(item->name != NULL) {
435                 if(item->value == mode)
436                         return item->icon;
437                 ++item;
438         }
439
440         return ICON_OBJECT_DATAMODE;
441 }
442
443 void uiTemplateEditModeSelection(uiLayout *layout, struct bContext *C)
444 {
445         Object *obedit = CTX_data_edit_object(C);
446         uiBlock *block= uiLayoutGetBlock(layout);
447
448         uiBlockSetHandleFunc(block, do_view3d_header_buttons, NULL);
449
450         if(obedit && (obedit->type == OB_MESH)) {
451                 BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh;
452                 uiLayout *row;
453
454                 row= uiLayoutRow(layout, 1);
455                 block= uiLayoutGetBlock(row);
456                 uiDefIconButBitS(block, TOG, SCE_SELECT_VERTEX, B_SEL_VERT, ICON_VERTEXSEL, 0,0,UI_UNIT_X,UI_UNIT_Y, &em->selectmode, 1.0, 0.0, 0, 0, "Vertex select mode");
457                 uiDefIconButBitS(block, TOG, SCE_SELECT_EDGE, B_SEL_EDGE, ICON_EDGESEL, 0,0,UI_UNIT_X,UI_UNIT_Y, &em->selectmode, 1.0, 0.0, 0, 0, "Edge select mode");
458                 uiDefIconButBitS(block, TOG, SCE_SELECT_FACE, B_SEL_FACE, ICON_FACESEL, 0,0,UI_UNIT_X,UI_UNIT_Y, &em->selectmode, 1.0, 0.0, 0, 0, "Face select mode");
459         }
460 }
461
462 void uiTemplateHeader3D(uiLayout *layout, struct bContext *C)
463 {
464         bScreen *screen= CTX_wm_screen(C);
465         ScrArea *sa= CTX_wm_area(C);
466         View3D *v3d= sa->spacedata.first;
467         Scene *scene= CTX_data_scene(C);
468         ToolSettings *ts= CTX_data_tool_settings(C);
469         PointerRNA v3dptr, toolsptr, sceneptr;
470         Object *ob= OBACT;
471         Object *obedit = CTX_data_edit_object(C);
472         uiBlock *block;
473         uiBut *but;
474         uiLayout *row;
475         const float dpi_fac= UI_DPI_FAC;
476         
477         RNA_pointer_create(&screen->id, &RNA_SpaceView3D, v3d, &v3dptr);        
478         RNA_pointer_create(&scene->id, &RNA_ToolSettings, ts, &toolsptr);
479         RNA_pointer_create(&scene->id, &RNA_Scene, scene, &sceneptr);
480
481         block= uiLayoutGetBlock(layout);
482         uiBlockSetHandleFunc(block, do_view3d_header_buttons, NULL);
483
484         /* other buttons: */
485         uiBlockSetEmboss(block, UI_EMBOSS);
486         
487         /* mode */
488         if(ob) {
489                 /*sanity point checkpoint, put here to avoid seeding
490                   this same code in 10 different other places.*/
491                 if (!ob->mode)
492                         ob->mode = OB_MODE_OBJECT;
493
494                 v3d->modeselect = ob->mode;
495         } else {
496                 v3d->modeselect = OB_MODE_OBJECT;
497         }
498         
499         uiBlockBeginAlign(block);
500         uiDefIconTextButS(block, MENU, B_MODESELECT, object_mode_icon(v3d->modeselect), view3d_modeselect_pup(scene) , 
501                           0,0,126 * dpi_fac, UI_UNIT_Y, &(v3d->modeselect), 0, 0, 0, 0, TIP_("Mode"));
502         uiBlockEndAlign(block);
503         
504         /* Draw type */
505         uiItemR(layout, &v3dptr, "viewport_shade", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
506
507         if (obedit==NULL && ((ob && ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT)))) {
508                 /* Manipulators aren't used in weight paint mode */
509                 
510                 PointerRNA meshptr;
511
512                 RNA_pointer_create(&ob->id, &RNA_Mesh, ob->data, &meshptr);
513                 if(ob->mode & (OB_MODE_TEXTURE_PAINT|OB_MODE_VERTEX_PAINT)) {
514                         uiItemR(layout, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
515                 }
516                 else {
517                         
518                         row= uiLayoutRow(layout, 1);
519                         uiItemR(row, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
520                         uiItemR(row, &meshptr, "use_paint_mask_vertex", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
521                 }
522         } else {
523                 const char *str_menu;
524
525                 row= uiLayoutRow(layout, 1);
526                 uiItemR(row, &v3dptr, "pivot_point", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
527
528                 /* pose/object only however we want to allow in weight paint mode too
529                  * so dont be totally strict and just check not-editmode for now */
530                 if (obedit == NULL) {
531                         uiItemR(row, &v3dptr, "use_pivot_point_align", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
532                 }
533
534                 /* Transform widget / manipulators */
535                 row= uiLayoutRow(layout, 1);
536                 uiItemR(row, &v3dptr, "show_manipulator", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
537                 block= uiLayoutGetBlock(row);
538                 
539                 if(v3d->twflag & V3D_USE_MANIPULATOR) {
540                         but= uiDefIconButBitC(block, TOG, V3D_MANIP_TRANSLATE, B_MAN_TRANS, ICON_MAN_TRANS, 0,0,UI_UNIT_X,UI_UNIT_Y, &v3d->twtype, 1.0, 0.0, 0, 0, TIP_("Translate manipulator mode"));
541                         uiButClearFlag(but, UI_BUT_UNDO); /* skip undo on screen buttons */
542                         but= uiDefIconButBitC(block, TOG, V3D_MANIP_ROTATE, B_MAN_ROT, ICON_MAN_ROT, 0,0,UI_UNIT_X,UI_UNIT_Y, &v3d->twtype, 1.0, 0.0, 0, 0, TIP_("Rotate manipulator mode"));
543                         uiButClearFlag(but, UI_BUT_UNDO); /* skip undo on screen buttons */
544                         but= uiDefIconButBitC(block, TOG, V3D_MANIP_SCALE, B_MAN_SCALE, ICON_MAN_SCALE, 0,0,UI_UNIT_X,UI_UNIT_Y, &v3d->twtype, 1.0, 0.0, 0, 0, TIP_("Scale manipulator mode"));
545                         uiButClearFlag(but, UI_BUT_UNDO); /* skip undo on screen buttons */
546                 }
547                         
548                 if (v3d->twmode > (BIF_countTransformOrientation(C) - 1) + V3D_MANIP_CUSTOM) {
549                         v3d->twmode = 0;
550                 }
551                         
552                 str_menu = BIF_menustringTransformOrientation(C, "Orientation");
553                 but= uiDefButC(block, MENU, B_MAN_MODE, str_menu,0,0,70 * dpi_fac, UI_UNIT_Y, &v3d->twmode, 0, 0, 0, 0, TIP_("Transform Orientation"));
554                 uiButClearFlag(but, UI_BUT_UNDO); /* skip undo on screen buttons */
555                 MEM_freeN((void *)str_menu);
556         }
557
558         if(obedit==NULL && v3d->localvd==NULL) {
559                 unsigned int ob_lay = ob ? ob->lay : 0;
560                 
561                 /* Layers */
562                 if (v3d->scenelock)
563                         uiTemplateLayers(layout, &sceneptr, "layers", &v3dptr, "layers_used", ob_lay);
564                 else
565                         uiTemplateLayers(layout, &v3dptr, "layers", &v3dptr, "layers_used", ob_lay);
566
567                 /* Scene lock */
568                 uiItemR(layout, &v3dptr, "lock_camera_and_layers", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
569         }
570         
571         uiTemplateEditModeSelection(layout, C);
572 }