new operator - OBJECT_OT_make_single_user
authorCampbell Barton <ideasman42@gmail.com>
Fri, 16 Oct 2009 10:00:45 +0000 (10:00 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 16 Oct 2009 10:00:45 +0000 (10:00 +0000)
Added keybindings and menu items
- Make Single User, Ukey
- Make Local, Lkey
- Make Duplis real, Ctrl+Shift+A

release/scripts/ui/space_view3d.py
source/blender/blenloader/intern/readfile.c
source/blender/editors/object/object_intern.h
source/blender/editors/object/object_ops.c
source/blender/editors/object/object_relations.c

index cac2b88f39ebf78cd4e6187fe30d740dc944e781..3a596766c89a9a5ddccd9f2fdd758a27ec7b0625 100644 (file)
@@ -409,6 +409,8 @@ class VIEW3D_MT_object(bpy.types.Menu):
                layout.item_booleanO("object.duplicate", "linked", True, text="Duplicate Linked")
                layout.itemO("object.delete", text="Delete...")
                layout.itemO("object.proxy_make", text="Make Proxy...")
+               layout.item_menu_enumO("object.make_local", "type", text="Make Local...")
+               layout.itemM("VIEW3D_MT_make_single_user")
                
                layout.itemS()
                
@@ -449,6 +451,8 @@ class VIEW3D_MT_object_apply(bpy.types.Menu):
                layout.itemO("object.scale_apply", text="Scale")
                layout.itemS()
                layout.itemO("object.visual_transform_apply", text="Visual Transform")
+               layout.itemO("object.duplicates_make_real")
+               
 
 class VIEW3D_MT_object_parent(bpy.types.Menu):
        __label__ = "Parent"
@@ -501,6 +505,27 @@ class VIEW3D_MT_object_showhide(bpy.types.Menu):
                layout.itemO("object.restrictview_set", text="Hide Selected")
                layout.item_booleanO("object.restrictview_set", "unselected", True, text="Hide Unselected")
 
+class VIEW3D_MT_make_single_user(bpy.types.Menu):
+       __label__ = "Make Single User"
+
+       def draw(self, context):
+               layout = self.layout
+               
+               props = layout.itemO("object.make_single_user", properties=True, text="Object")
+               props.object = True
+               
+               props = layout.itemO("object.make_single_user", properties=True, text="Object & ObData")
+               props.object = props.obdata = True
+               
+               props = layout.itemO("object.make_single_user", properties=True, text="Object & ObData & Materials+Tex")
+               props.object = props.obdata = props.material = props.texture = True
+               
+               props = layout.itemO("object.make_single_user", properties=True, text="Materials+Tex")
+               props.material = props.texture = True
+               
+               props = layout.itemO("object.make_single_user", properties=True, text="Animation")
+               props.animation = True
+
 # ********** Vertex paint menu **********      
        
 class VIEW3D_MT_paint_vertex(bpy.types.Menu):
@@ -1416,6 +1441,8 @@ bpy.types.register(VIEW3D_MT_object_track)
 bpy.types.register(VIEW3D_MT_object_group)
 bpy.types.register(VIEW3D_MT_object_constraints)
 bpy.types.register(VIEW3D_MT_object_showhide)
+bpy.types.register(VIEW3D_MT_make_single_user)
+
 
 bpy.types.register(VIEW3D_MT_sculpt) # Sculpt Menu
 
index 0004187b1c6202c7501e5de56b8e7c6f56eea82a..448eb834818a5c01591e4ecaca8f2899b32dcbbc 100644 (file)
@@ -6430,7 +6430,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
        if(main->versionfile <= 140) {
-               /* r-g-b-fac in texure */
+               /* r-g-b-fac in texture */
                Tex *tex = main->tex.first;
                while (tex) {
                        if ((tex->rfac == 0.0) &&
index dc7ae1490fd6158dc7cc55740ab340d65e296dd0..420b6a2194664b228592d0bb961b2e11ec257ad3 100644 (file)
@@ -58,6 +58,7 @@ void OBJECT_OT_track_clear(struct wmOperatorType *ot);
 void OBJECT_OT_slow_parent_set(struct wmOperatorType *ot);
 void OBJECT_OT_slow_parent_clear(struct wmOperatorType *ot);
 void OBJECT_OT_make_local(struct wmOperatorType *ot);
+void OBJECT_OT_make_single_user(struct wmOperatorType *ot);
 void OBJECT_OT_move_to_layer(struct wmOperatorType *ot);
 
 /* object_edit.c */
index 5c53e041f6e711c9ce511e6accb4c8221c70c3fb..1e95eca43867941f2486c4913d478ed343d6b3ac 100644 (file)
@@ -90,6 +90,7 @@ void ED_operatortypes_object(void)
        WM_operatortype_append(OBJECT_OT_slow_parent_set);
        WM_operatortype_append(OBJECT_OT_slow_parent_clear);
        WM_operatortype_append(OBJECT_OT_make_local);
+       WM_operatortype_append(OBJECT_OT_make_single_user);
        WM_operatortype_append(OBJECT_OT_move_to_layer);
 
        WM_operatortype_append(OBJECT_OT_select_inverse);
@@ -249,15 +250,21 @@ void ED_keymap_object(wmKeyConfig *keyconf)
        kmi= WM_keymap_add_item(keymap, "WM_OT_call_menu", AKEY, KM_PRESS, KM_SHIFT, 0);
        RNA_string_set(kmi->ptr, "name", "INFO_MT_add");
 
+       WM_keymap_add_item(keymap, "OBJECT_OT_duplicates_make_real", AKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
+
        kmi= WM_keymap_add_item(keymap, "WM_OT_call_menu", AKEY, KM_PRESS, KM_CTRL, 0);
        RNA_string_set(kmi->ptr, "name", "VIEW3D_MT_object_apply");
 
+       kmi= WM_keymap_add_item(keymap, "WM_OT_call_menu", UKEY, KM_PRESS, 0, 0);
+       RNA_string_set(kmi->ptr, "name", "VIEW3D_MT_make_single_user");
+
        WM_keymap_add_item(keymap, "OBJECT_OT_duplicate_move", DKEY, KM_PRESS, KM_SHIFT, 0);
        RNA_boolean_set(WM_keymap_add_item(keymap, "OBJECT_OT_duplicate", DKEY, KM_PRESS, KM_ALT, 0)->ptr, "linked", 1);
        WM_keymap_add_item(keymap, "OBJECT_OT_join", JKEY, KM_PRESS, KM_CTRL, 0);
        WM_keymap_add_item(keymap, "OBJECT_OT_convert", CKEY, KM_PRESS, KM_ALT, 0);
        WM_keymap_add_item(keymap, "OBJECT_OT_proxy_make", PKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
-       
+       WM_keymap_add_item(keymap, "OBJECT_OT_make_local", LKEY, KM_PRESS, 0, 0);
+
        // XXX this should probably be in screen instead... here for testing purposes in the meantime... - Aligorith
        WM_keymap_verify_item(keymap, "ANIM_OT_insert_keyframe_menu", IKEY, KM_PRESS, 0, 0);
        WM_keymap_verify_item(keymap, "ANIM_OT_delete_keyframe_v3d", IKEY, KM_PRESS, KM_ALT, 0);
index 0c97b94503728700c576d491bc84b4ae7534c428..c2550a6b1e8ea752504f9a228efd80f2867c9c42 100644 (file)
@@ -1456,7 +1456,7 @@ void single_ipo_users(Scene *scene, int flag)
 #endif // XXX old animation system
 }
 
-void single_mat_users(Scene *scene, int flag)
+static void single_mat_users(Scene *scene, int flag, int do_textures)
 {
        Object *ob;
        Base *base;
@@ -1486,17 +1486,17 @@ void single_mat_users(Scene *scene, int flag)
                                                        ipo_idnew(ma->ipo);     /* drivers */
                                                }
 #endif // XXX old animation system
-                                               
-                                               for(b=0; b<MAX_MTEX; b++) {
-                                                       if(ma->mtex[b] && ma->mtex[b]->tex) {
-                                                               tex= ma->mtex[b]->tex;
-                                                               if(tex->id.us>1) {
-                                                                       ma->mtex[b]->tex= copy_texture(tex);
-                                                                       tex->id.us--;
+                                               if(do_textures) {
+                                                       for(b=0; b<MAX_MTEX; b++) {
+                                                               if(ma->mtex[b] && ma->mtex[b]->tex) {
+                                                                       tex= ma->mtex[b]->tex;
+                                                                       if(tex->id.us>1) {
+                                                                               ma->mtex[b]->tex= copy_texture(tex);
+                                                                               tex->id.us--;
+                                                                       }
                                                                }
                                                        }
                                                }
-                                               
                                        }
                                }
                        }
@@ -1599,42 +1599,6 @@ static void single_mat_users_expand(void)
                                        ID_NEW(ma->mtex[a]->object);
 }
 
-void single_user(Scene *scene, View3D *v3d)
-{
-       int nr;
-       
-       if(scene->id.lib) return;
-
-       clear_id_newpoins();
-       
-       nr= pupmenu("Make Single User%t|Object|Object & ObData|Object & ObData & Materials+Tex|Materials+Tex|Ipos");
-       if(nr>0) {
-       
-               if(nr==1) single_object_users(scene, v3d, 1);
-       
-               else if(nr==2) {
-                       single_object_users(scene, v3d, 1);
-                       single_obdata_users(scene, 1);
-               }
-               else if(nr==3) {
-                       single_object_users(scene, v3d, 1);
-                       single_obdata_users(scene, 1);
-                       single_mat_users(scene, 1); /* also tex */
-                       
-               }
-               else if(nr==4) {
-                       single_mat_users(scene, 1);
-               }
-               else if(nr==5) {
-                       single_ipo_users(scene, 1);
-               }
-               
-               
-               clear_id_newpoins();
-
-       }
-}
-
 /* used for copying scenes */
 void ED_object_single_users(Scene *scene, int full)
 {
@@ -1676,7 +1640,7 @@ static int make_local_exec(bContext *C, wmOperator *op)
        Material *ma, ***matarar;
        Lamp *la;
        ID *id;
-       int a, b, mode= RNA_boolean_get(op->ptr, "type");
+       int a, b, mode= RNA_enum_get(op->ptr, "type");;
        
        if(mode==3) {
                all_local(NULL, 0);     /* NULL is all libs */
@@ -1777,3 +1741,59 @@ void OBJECT_OT_make_local(wmOperatorType *ot)
        RNA_def_enum(ot->srna, "type", type_items, 0, "Type", "");
 }
 
+static int make_single_user_exec(bContext *C, wmOperator *op)
+{
+       Scene *scene= CTX_data_scene(C);
+       View3D *v3d= CTX_wm_view3d(C); /* ok if this is NULL */
+       int flag= RNA_enum_get(op->ptr, "type"); /* 0==ALL, SELECTED==selected objecs */
+
+       if(RNA_boolean_get(op->ptr, "object"))
+           single_object_users(scene, v3d, flag);
+
+       if(RNA_boolean_get(op->ptr, "obdata"))
+               single_obdata_users(scene, flag);
+
+       if(RNA_boolean_get(op->ptr, "material"))
+               single_mat_users(scene, flag, FALSE);
+
+       if(RNA_boolean_get(op->ptr, "texture"))
+               single_mat_users(scene, flag, TRUE);
+
+       if(RNA_boolean_get(op->ptr, "animation"))
+               single_ipo_users(scene, flag);
+
+       clear_id_newpoins();
+
+       WM_event_add_notifier(C, NC_WINDOW, NULL);
+       return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_make_single_user(wmOperatorType *ot)
+{
+       static EnumPropertyItem type_items[]= {
+               {SELECT, "SELECTED_OBJECTS", 0, "Selected Objects", ""},
+               {0, "ALL", 0, "All", ""},
+               {0, NULL, 0, NULL, NULL}};
+
+       /* identifiers */
+       ot->name= "Make Single User";
+       ot->description = "Make linked data local to each object.";
+       ot->idname= "OBJECT_OT_make_single_user";
+
+       /* api callbacks */
+       ot->invoke= WM_menu_invoke;
+       ot->exec= make_single_user_exec;
+       ot->poll= ED_operator_scene_editable;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       /* properties */
+       RNA_def_enum(ot->srna, "type", type_items, 0, "Type", "");
+
+       RNA_def_boolean(ot->srna, "object", 0, "Object", "Make single user objects");
+       RNA_def_boolean(ot->srna, "obdata", 0, "Object Data", "Make single user object data");
+       RNA_def_boolean(ot->srna, "material", 0, "Materials", "Make materials local to each datablock");
+       RNA_def_boolean(ot->srna, "texture", 0, "Textures", "Make textures local to each material");
+       RNA_def_boolean(ot->srna, "animation", 0, "Animation Data", "Make animation data local to each object");
+}